1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-22 06:03:55 +03:00

add shared icon for layouts to be identified

This commit is contained in:
Michail Vourlakos 2019-05-04 19:43:41 +03:00
parent 4c0a3f5523
commit cff6436a74
4 changed files with 52 additions and 9 deletions

View File

@ -19,6 +19,9 @@
#include "layoutnamedelegate.h"
// local
#include "../settingsdialog.h"
// Qt
#include <QApplication>
#include <QBitmap>
@ -34,17 +37,25 @@ const int HIDDENTEXTCOLUMN = 1;
LayoutNameDelegate::LayoutNameDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
auto *settingsDialog = qobject_cast<Latte::SettingsDialog *>(parent);
if (settingsDialog) {
m_settingsDialog = settingsDialog;
}
}
void LayoutNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
bool isLocked = index.data(Qt::UserRole).toBool();
bool isShared = m_settingsDialog->isShared(index.row());
bool showTwoIcons = isLocked && isShared;
QStyleOptionViewItem adjustedOption = option;
//! Remove the focus dotted lines
adjustedOption.state = (adjustedOption.state & ~QStyle::State_HasFocus);
if (isLocked) {
if (isLocked || isShared) {
QStandardItemModel *model = (QStandardItemModel *) index.model();
QString nameText = index.data(Qt::DisplayRole).toString();
bool selected = ((option.state & QStyle::State_Active) && (option.state & QStyle::State_Selected));
@ -53,11 +64,13 @@ void LayoutNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QFontMetrics fm(option.font);
int textWidth = fm.width(nameText);
int thick = option.rect.height();
int startWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? thick : qBound(0, option.rect.width() - textWidth - thick, thick);
int endWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? qBound(0, option.rect.width() - textWidth - thick, thick) : thick;
int length = showTwoIcons ? (2 * thick + 2) : thick;
int startWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? length : qBound(0, option.rect.width() - textWidth - length, length);
int endWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? qBound(0, option.rect.width() - textWidth - length, length) : length;
QRect destinationS(option.rect.x(), option.rect.y(), startWidth, thick);
QRect destinationE(option.rect.x() + option.rect.width() - thick, option.rect.y(), endWidth, thick);
QRect destinationE(option.rect.x() + option.rect.width() - endWidth, option.rect.y(), endWidth, thick);
QStyleOptionViewItem myOptionS = adjustedOption;
QStyleOptionViewItem myOptionE = adjustedOption;
@ -75,14 +88,23 @@ void LayoutNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QStyledItemDelegate::paint(painter, myOptionE, model->index(index.row(), HIDDENTEXTCOLUMN));
//! Lock Icon
QIcon lockIcon = QIcon::fromTheme("object-locked");
QIcon firstIcon = isLocked && !showTwoIcons ? QIcon::fromTheme("object-locked") : QIcon::fromTheme("document-share");
QIcon::Mode mode = selected ? QIcon::Selected : QIcon::Normal;
if (qApp->layoutDirection() == Qt::RightToLeft) {
painter->drawPixmap(destinationS, lockIcon.pixmap(thick, thick, mode));
painter->drawPixmap(QRect(option.rect.x(), option.rect.y(), thick, thick), firstIcon.pixmap(thick, thick, mode));
if (showTwoIcons) {
QIcon secondIcon = QIcon::fromTheme("object-locked");
painter->drawPixmap(QRect(option.rect.x() + thick + 2, option.rect.y(), thick, thick), secondIcon.pixmap(thick, thick, mode));
}
} else {
painter->drawPixmap(destinationE, lockIcon.pixmap(thick, thick, mode));
painter->drawPixmap(QRect(option.rect.x() + option.rect.width() - endWidth, option.rect.y(), thick, thick), firstIcon.pixmap(thick, thick, mode));
if (showTwoIcons) {
QIcon secondIcon = QIcon::fromTheme("object-locked");
painter->drawPixmap(QRect(option.rect.x() + option.rect.width() - thick, option.rect.y(), thick, thick), secondIcon.pixmap(thick, thick, mode));
}
}
return;

View File

@ -23,12 +23,19 @@
// Qt
#include <QStyledItemDelegate>
namespace Latte {
class SettingsDialog;
}
class LayoutNameDelegate : public QStyledItemDelegate
{
public:
LayoutNameDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
Latte::SettingsDialog *m_settingsDialog{nullptr};
};
#endif

View File

@ -1630,6 +1630,18 @@ bool SettingsDialog::nameExistsInModel(QString name)
return false;
}
bool SettingsDialog::isShared(int row) const
{
if (row >=0 ) {
QStringList shares = m_model->data(m_model->index(row, SHAREDCOLUMN), Qt::UserRole).toStringList();
if (!shares.isEmpty()) {
return true;
}
}
return false;
}
int SettingsDialog::ascendingRowFor(QString name)
{
for (int i = 0; i < m_model->rowCount(); ++i) {

View File

@ -57,6 +57,8 @@ public:
void setCurrentPage(Types::LatteConfigPage page);
bool isShared(int row) const;
QStringList activities();
QStringList availableActivities();
QStringList availableSharesFor(int row);
@ -102,7 +104,7 @@ private:
bool idExistsInModel(QString id);
bool importLayoutsFromV1ConfigFile(QString file);
bool nameExistsInModel(QString name);
bool saveAllChanges();
bool saveAllChanges();
int rowForId(QString id);
int rowForName(QString layoutName);