From 1113f942b1ef4affb6a2eaa0f2320e07ad63f894 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 20 Mar 2020 18:19:29 +0200 Subject: [PATCH] provide feedback to the user in layouts view --provide feedback to the user for which layout options have been altered. This is achievable by providing italicness to these options. --- .../controllers/layoutscontroller.cpp | 2 +- app/settings/delegates/activitiesdelegate.cpp | 27 ++++----- app/settings/delegates/activitiesdelegate.h | 2 +- .../delegates/backgroundcmbdelegate.cpp | 2 +- app/settings/delegates/checkboxdelegate.cpp | 34 +++++++++++- app/settings/delegates/layoutnamedelegate.cpp | 21 +++++-- app/settings/delegates/shareddelegate.cpp | 25 ++++++--- app/settings/delegates/shareddelegate.h | 2 +- app/settings/models/layoutsmodel.cpp | 55 ++++++++++++------- app/settings/models/layoutsmodel.h | 16 ++++-- 10 files changed, 126 insertions(+), 60 deletions(-) diff --git a/app/settings/controllers/layoutscontroller.cpp b/app/settings/controllers/layoutscontroller.cpp index 2ea86498b..f35ee507b 100644 --- a/app/settings/controllers/layoutscontroller.cpp +++ b/app/settings/controllers/layoutscontroller.cpp @@ -284,7 +284,7 @@ void Layouts::toggleLockedForSelected() Data::Layout selected = selectedLayoutCurrentData(); - m_proxyModel->setData(m_proxyModel->index(m_view->currentIndex().row(), Model::Layouts::NAMECOLUMN), !selected.isLocked, Settings::Model::Layouts::LAYOUTISLOCKEDROLE); + m_proxyModel->setData(m_proxyModel->index(m_view->currentIndex().row(), Model::Layouts::NAMECOLUMN), !selected.isLocked, Settings::Model::Layouts::ISLOCKEDROLE); } void Layouts::toggleSharedForSelected() diff --git a/app/settings/delegates/activitiesdelegate.cpp b/app/settings/delegates/activitiesdelegate.cpp index 4bbeced95..6ea1e3c0e 100644 --- a/app/settings/delegates/activitiesdelegate.cpp +++ b/app/settings/delegates/activitiesdelegate.cpp @@ -56,7 +56,7 @@ QWidget *Activities::createEditor(QWidget *parent, const QStyleOptionViewItem &o button->setMenu(menu); menu->setMinimumWidth(option.rect.width()); - bool isLayoutActive = index.data(Model::Layouts::LAYOUTISACTIVEROLE).toBool(); + bool isLayoutActive = index.data(Model::Layouts::ISACTIVEROLE).toBool(); QStringList allActivities = index.data(Model::Layouts::ALLACTIVITIESSORTEDROLE).toStringList(); Data::ActivitiesMap allActivitiesData = index.data(Model::Layouts::ALLACTIVITIESDATAROLE).value(); @@ -176,7 +176,7 @@ bool Activities::editorEvent(QEvent *event, QAbstractItemModel *model, const QSt Q_ASSERT(event); Q_ASSERT(model); - bool isSharedCapable = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); + bool isSharedCapable = index.data(Model::Layouts::ISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); if (isSharedCapable) { return false; @@ -191,14 +191,15 @@ void Activities::paint(QPainter *painter, const QStyleOptionViewItem &option, co //! Remove the focus dotted lines myOptions.state = (myOptions.state & ~QStyle::State_HasFocus); - bool isLayoutActive = index.data(Model::Layouts::LAYOUTISACTIVEROLE).toBool(); - bool isSharedCapable = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); + bool isLayoutActive = index.data(Model::Layouts::ISACTIVEROLE).toBool(); + bool isSharedCapable = index.data(Model::Layouts::ISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); if (!isSharedCapable) { painter->save(); QList assignedActivities; QStringList assignedIds = index.model()->data(index, Qt::UserRole).toStringList(); + QStringList assignedOriginalIds = index.model()->data(index, Model::Layouts::ORIGINALASSIGNEDACTIVITIESROLE).toStringList(); Data::ActivitiesMap allActivitiesData = index.data(Model::Layouts::ALLACTIVITIESDATAROLE).value(); @@ -207,7 +208,7 @@ void Activities::paint(QPainter *painter, const QStyleOptionViewItem &option, co } if (assignedActivities.count() > 0) { - myOptions.text = joinedActivities(assignedActivities, isLayoutActive); + myOptions.text = joinedActivities(assignedActivities, assignedOriginalIds, isLayoutActive); QTextDocument doc; QString css; @@ -301,7 +302,7 @@ void Activities::paint(QPainter *painter, const QStyleOptionViewItem &option, co } } -QString Activities::joinedActivities(const QList &activities, bool isActive, bool formatText) const +QString Activities::joinedActivities(const QList &activities, const QStringList &originalIds, bool isActive, bool formatText) const { QString finalText; @@ -309,24 +310,18 @@ QString Activities::joinedActivities(const QList &activities, bo for (int i=0; i 0) { finalText += ", "; } - QString styledText = activities[i].name; if (bold && formatText) { @@ -358,7 +353,7 @@ void Activities::updateButton(QWidget *editor, const Data::ActivitiesMap &allAct } } - button->setText(joinedActivities(assignedActivities, false, false)); + button->setText(joinedActivities(assignedActivities, QStringList(), false, false)); } } diff --git a/app/settings/delegates/activitiesdelegate.h b/app/settings/delegates/activitiesdelegate.h index f7bd9923f..519e39690 100644 --- a/app/settings/delegates/activitiesdelegate.h +++ b/app/settings/delegates/activitiesdelegate.h @@ -51,7 +51,7 @@ public: private: void updateButton(QWidget *editor, const Data::ActivitiesMap &allActivitiesData) const; - QString joinedActivities(const QList &activities, bool isActive = false, bool formatText = true) const; + QString joinedActivities(const QList &activities, const QStringList &originalIds, bool isActive = false, bool formatText = true) const; }; } diff --git a/app/settings/delegates/backgroundcmbdelegate.cpp b/app/settings/delegates/backgroundcmbdelegate.cpp index 177b9d42b..539d4326a 100644 --- a/app/settings/delegates/backgroundcmbdelegate.cpp +++ b/app/settings/delegates/backgroundcmbdelegate.cpp @@ -125,7 +125,7 @@ void BackgroundCmbBox::paint(QPainter *painter, const QStyleOptionViewItem &opti //! activities icons Data::ActivitiesMap allActivitiesData = index.data(Model::Layouts::ALLACTIVITIESDATAROLE).value(); - bool isShared = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); + bool isShared = index.data(Model::Layouts::ISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); QStringList assignedIds = isShared ? index.data(Model::Layouts::ASSIGNEDACTIVITIESFROMSHAREDROLE).toStringList() : index.data(Model::Layouts::ASSIGNEDACTIVITIESROLE).toStringList(); diff --git a/app/settings/delegates/checkboxdelegate.cpp b/app/settings/delegates/checkboxdelegate.cpp index 75325ecd0..c7c56ebf0 100644 --- a/app/settings/delegates/checkboxdelegate.cpp +++ b/app/settings/delegates/checkboxdelegate.cpp @@ -37,6 +37,9 @@ namespace Settings { namespace Layout { namespace Delegate { +const QChar HeavyCheckMark{0x2714}; +const QChar CheckMark{0x2713}; + CheckBox::CheckBox(QObject *parent) : QStyledItemDelegate(parent) { @@ -49,9 +52,36 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionViewItem &option, cons adjustedOption.state = (adjustedOption.state & ~QStyle::State_HasFocus); adjustedOption.displayAlignment = Qt::AlignHCenter | Qt::AlignVCenter; - bool isSharedCapable = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); + bool isSharedCapable = index.data(Model::Layouts::ISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); if (!isSharedCapable) { + bool originalChecked{false}; + bool currentChecked = index.data(Qt::UserRole).toBool(); + + if (index.column() == Model::Layouts::MENUCOLUMN) { + originalChecked = index.data(Model::Layouts::ORIGINALISSHOWNINMENUROLE).toBool(); + } else if (index.column() == Model::Layouts::BORDERSCOLUMN) { + originalChecked = index.data(Model::Layouts::ORIGINALHASBORDERSROLE).toBool(); + } else { + originalChecked = currentChecked; + } + + bool isChanged = (originalChecked != currentChecked); + + if (isChanged) { + adjustedOption.font.setPointSize(adjustedOption.font.pointSize() + 2); + adjustedOption.font.setBold(true); + } else { + // normal appearance + } + + if (currentChecked) { + adjustedOption.text = isChanged ? HeavyCheckMark : CheckMark; + } else { + adjustedOption.text = ""; + } + + QStyledItemDelegate::paint(painter, adjustedOption, index); } else { // Disabled @@ -110,7 +140,7 @@ bool CheckBox::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyl Q_ASSERT(event); Q_ASSERT(model); - bool isSharedCapable = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); + bool isSharedCapable = index.data(Model::Layouts::ISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); if (isSharedCapable) { return false; diff --git a/app/settings/delegates/layoutnamedelegate.cpp b/app/settings/delegates/layoutnamedelegate.cpp index ec2cf3558..744b0b6bf 100644 --- a/app/settings/delegates/layoutnamedelegate.cpp +++ b/app/settings/delegates/layoutnamedelegate.cpp @@ -73,10 +73,18 @@ void LayoutName::setModelData(QWidget *editor, QAbstractItemModel *model, const void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - bool isLocked = index.data(Model::Layouts::LAYOUTISLOCKEDROLE).toBool(); - bool isShared = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); - bool isActive = index.data(Model::Layouts::LAYOUTISACTIVEROLE).toBool(); - bool isChanged = index.data(Model::Layouts::LAYOUTNAMEWASEDITEDROLE).toBool(); + bool inMultiple = index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); + + bool isLocked = index.data(Model::Layouts::ISLOCKEDROLE).toBool(); + bool isShared = inMultiple && index.data(Model::Layouts::ISSHAREDROLE).toBool(); + bool isActive = index.data(Model::Layouts::ISACTIVEROLE).toBool(); + + bool isNewLayout = index.data(Model::Layouts::ISNEWLAYOUTROLE).toBool(); + bool hasChanges = index.data(Model::Layouts::LAYOUTHASCHANGESROLE).toBool(); + + QString name = index.data(Qt::UserRole).toString(); + + bool isChanged = (isNewLayout || hasChanges); bool showTwoIcons = isLocked && isShared; @@ -90,7 +98,7 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co if (isLocked || isShared) { QStandardItemModel *model = (QStandardItemModel *) index.model(); - QString nameText = index.data(Qt::UserRole).toString(); + bool active = Latte::isActive(option); bool enabled = Latte::isEnabled(option); @@ -100,7 +108,7 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co //! font metrics QFontMetrics fm(option.font); - int textWidth = fm.boundingRect(nameText).width(); + int textWidth = fm.boundingRect(name).width(); int thick = option.rect.height(); int length = showTwoIcons ? (2 * thick + 2) : thick; @@ -115,6 +123,7 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co QStyleOptionViewItem myOptionMain = adjustedOption; myOptionMain.font.setBold(isActive); + myOptionMain.font.setItalic(isChanged); myOptionS.rect = destinationS; myOptionE.rect = destinationE; diff --git a/app/settings/delegates/shareddelegate.cpp b/app/settings/delegates/shareddelegate.cpp index fd20dcda0..b0d161674 100644 --- a/app/settings/delegates/shareddelegate.cpp +++ b/app/settings/delegates/shareddelegate.cpp @@ -55,6 +55,7 @@ QWidget *Shared::createEditor(QWidget *parent, const QStyleOptionViewItem &optio { bool inMultiple = index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); + QString layoutId = index.data(Model::Layouts::IDROLE).toString(); Data::LayoutsTable allLayouts = qvariant_cast(index.data(Model::Layouts::ALLLAYOUTSROLE)); QStringList assignedShares = index.data(Qt::UserRole).toStringList(); @@ -65,7 +66,7 @@ QWidget *Shared::createEditor(QWidget *parent, const QStyleOptionViewItem &optio menu->setMinimumWidth(option.rect.width()); for (int i = 0; i < allLayouts.rowCount(); ++i) { - if (inMultiple && allLayouts[i].isShared()) { + if ((inMultiple && allLayouts[i].isShared()) || (allLayouts[i].id == layoutId)) { continue; } @@ -128,6 +129,7 @@ void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const bool sharedInEdit = index.data(Model::Layouts::SHAREDTOINEDIT).toBool(); Data::LayoutsTable allLayouts = qvariant_cast(index.data(Model::Layouts::ALLLAYOUTSROLE)); QStringList assignedIds = index.data(Qt::UserRole).toStringList(); + QStringList originalIds = index.data(Model::Layouts::ORIGINALSHARESROLE).toStringList(); Data::LayoutsTable assignedLayouts; @@ -149,7 +151,7 @@ void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const } //! Text code - myOptions.text = joined(assignedLayouts); + myOptions.text = joined(assignedLayouts, originalIds); int thick = option.rect.height(); @@ -274,10 +276,10 @@ void Shared::updateButtonText(QWidget *editor, const QModelIndex &index) const } } - button->setText(joined(assignedLayouts, false)); + button->setText(joined(assignedLayouts, QStringList(), false)); } -QString Shared::joined(const Data::LayoutsTable &layouts, bool formatText) const +QString Shared::joined(const Data::LayoutsTable &layouts, const QStringList &originalIds, bool formatText) const { QString finalText; @@ -286,13 +288,20 @@ QString Shared::joined(const Data::LayoutsTable &layouts, bool formatText) const finalText += ", "; } - bool bold {false}; + bool bold = layouts[i].isActive; + bool italic = !originalIds.contains(layouts[i].id); - if (formatText && layouts[i].isActive) { - bold = true; + QString name = layouts[i].name; + + if (bold && formatText) { + name = "" + name + ""; + } + + if (italic && formatText) { + name = "" + name + ""; } - finalText += bold ? "" + layouts[i].name + "" : layouts[i].name; + finalText += name; } return finalText; diff --git a/app/settings/delegates/shareddelegate.h b/app/settings/delegates/shareddelegate.h index 8820bd57d..ef87d4daa 100644 --- a/app/settings/delegates/shareddelegate.h +++ b/app/settings/delegates/shareddelegate.h @@ -51,7 +51,7 @@ private: void paintSharedToIndicator(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void updateButtonText(QWidget *editor, const QModelIndex &index) const; - QString joined(const Data::LayoutsTable &layouts, bool formatText = true) const; + QString joined(const Data::LayoutsTable &layouts, const QStringList &originalIds, bool formatText = true) const; private: // we need it in order to send to the model the information when the SHARETO cell is edited diff --git a/app/settings/models/layoutsmodel.cpp b/app/settings/models/layoutsmodel.cpp index ee32a4145..8660777a9 100644 --- a/app/settings/models/layoutsmodel.cpp +++ b/app/settings/models/layoutsmodel.cpp @@ -38,8 +38,6 @@ #include #include -const QChar CheckMark{0x2714}; - namespace Latte { namespace Settings { namespace Model { @@ -54,7 +52,7 @@ Layouts::Layouts(QObject *parent, Latte::Corona *corona) QVector roles; roles << Qt::DisplayRole; roles << Qt::UserRole; - roles << LAYOUTISSHAREDROLE; + roles << ISSHAREDROLE; roles << INMULTIPLELAYOUTSROLE; emit dataChanged(index(0, NAMECOLUMN), index(rowCount()-1, SHAREDCOLUMN), roles); @@ -400,23 +398,22 @@ QVariant Layouts::data(const QModelIndex &index, int role) const { const int row = index.row(); int column = index.column(); + bool isNewLayout = !o_layoutsTable.containsId(m_layoutsTable[row].id); if (!m_layoutsTable.rowExists(row)) { return QVariant{}; } - if (role == LAYOUTISACTIVEROLE) { + if (role == IDROLE) { + return m_layoutsTable[row].id; + } else if (role == ISACTIVEROLE) { return m_layoutsTable[row].isActive; - } else if (role == LAYOUTISLOCKEDROLE) { + } else if (role == ISLOCKEDROLE) { return m_layoutsTable[row].isLocked; - } else if (role == LAYOUTISSHAREDROLE) { + } else if (role == ISSHAREDROLE) { return m_layoutsTable[row].isShared(); } else if (role == INMULTIPLELAYOUTSROLE) { return inMultipleMode(); - } else if (role == LAYOUTNAMEWASEDITEDROLE) { - QString id = m_layoutsTable[row].id; - bool edited = !o_layoutsTable.containsId(id) || o_layoutsTable[id].name != m_layoutsTable[row].name; - return edited; } else if (role == ASSIGNEDACTIVITIESROLE) { return m_layoutsTable[row].activities; } else if (role == ASSIGNEDACTIVITIESFROMSHAREDROLE) { @@ -436,6 +433,10 @@ QVariant Layouts::data(const QModelIndex &index, int role) const return layouts; } else if (role == SHAREDTOINEDIT) { return (m_sharedToInEditRow == row); + } else if (role == ISNEWLAYOUTROLE) { + return isNewLayout; + } else if (role == LAYOUTHASCHANGESROLE) { + return (isNewLayout ? true : o_layoutsTable[m_layoutsTable[row].id] != m_layoutsTable[row]); } switch (column) { @@ -475,9 +476,11 @@ QVariant Layouts::data(const QModelIndex &index, int role) const return 0; } - if (role == Qt::DisplayRole) { - return m_layoutsTable[row].isShownInMenu ? CheckMark : QVariant{}; - } else if (role == Qt::UserRole) { + if (role == ORIGINALISSHOWNINMENUROLE) { + return isNewLayout ? false : o_layoutsTable[row].isShownInMenu; + } + + if (role == Qt::UserRole) { return m_layoutsTable[row].isShownInMenu; } break; @@ -492,9 +495,11 @@ QVariant Layouts::data(const QModelIndex &index, int role) const return 0; } - if (role == Qt::DisplayRole) { - return m_layoutsTable[row].hasDisabledBorders ? CheckMark : QVariant{}; - } else if (role == Qt::UserRole) { + if (role == ORIGINALHASBORDERSROLE) { + return isNewLayout ? false : o_layoutsTable[row].hasDisabledBorders; + } + + if (role == Qt::UserRole) { return m_layoutsTable[row].hasDisabledBorders; } break; @@ -516,6 +521,10 @@ QVariant Layouts::data(const QModelIndex &index, int role) const return 0; } + if (role == ORIGINALASSIGNEDACTIVITIESROLE) { + return isNewLayout ? QStringList() : o_layoutsTable[row].activities; + } + if (role == Qt::UserRole) { return m_layoutsTable[row].activities; } @@ -535,6 +544,10 @@ QVariant Layouts::data(const QModelIndex &index, int role) const return 0; } + if (role == ORIGINALSHARESROLE) { + return isNewLayout ? QStringList() : o_layoutsTable[row].shares; + } + if (role == Qt::UserRole) { return m_layoutsTable[row].shares; } @@ -738,7 +751,7 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role) roles << role; //! common roles for all row cells - if (role == LAYOUTISLOCKEDROLE) { + if (role == ISLOCKEDROLE) { m_layoutsTable[row].isLocked = value.toBool(); emit dataChanged(this->index(row,0), this->index(row,SHAREDCOLUMN), roles); return true; @@ -789,6 +802,7 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role) if (role == Qt::UserRole) { m_layoutsTable[row].isShownInMenu = value.toBool(); emit dataChanged(index, index, roles); + emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles); return true; } break; @@ -796,18 +810,21 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role) if (role == Qt::UserRole) { m_layoutsTable[row].hasDisabledBorders = value.toBool(); emit dataChanged(index, index, roles); + emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles); return true; } break; case ACTIVITYCOLUMN: if (role == Qt::UserRole) { setActivities(row, value.toStringList()); + emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles); return true; } break; case SHAREDCOLUMN: if (role == Qt::UserRole) { setShares(row, value.toStringList()); + emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles); return true; } else if (role == SHAREDTOINEDIT) { bool inEdit = value.toBool(); @@ -815,7 +832,7 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role) roles << Qt::DisplayRole; roles << Qt::UserRole; emit dataChanged(this->index(row, ACTIVITYCOLUMN), this->index(row, SHAREDCOLUMN), roles); - + emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles); return true; } break; @@ -829,7 +846,7 @@ void Layouts::updateActiveStates() QVector roles; roles << Qt::DisplayRole; roles << Qt::UserRole; - roles << LAYOUTISACTIVEROLE; + roles << ISACTIVEROLE; for(int i=0; i