diff --git a/app/data/layouticondata.cpp b/app/data/layouticondata.cpp index 4be401c03..f72ef080f 100644 --- a/app/data/layouticondata.cpp +++ b/app/data/layouticondata.cpp @@ -41,6 +41,11 @@ LayoutIcon::LayoutIcon(const LayoutIcon &o) { } +bool LayoutIcon::isEmpty() const +{ + return (id.isEmpty() && name.isEmpty()); +} + LayoutIcon &LayoutIcon::operator=(LayoutIcon &&rhs) { id = rhs.id; diff --git a/app/data/layouticondata.h b/app/data/layouticondata.h index 294edd9e3..328766842 100644 --- a/app/data/layouticondata.h +++ b/app/data/layouticondata.h @@ -41,6 +41,8 @@ public: //! Layout data bool isBackgroundFile{true}; + bool isEmpty() const; + //! Operators LayoutIcon &operator=(const LayoutIcon &rhs); LayoutIcon &operator=(LayoutIcon &&rhs); diff --git a/app/settings/settingsdialog/delegates/backgrounddelegate.cpp b/app/settings/settingsdialog/delegates/backgrounddelegate.cpp index e13ecec12..6d36852b6 100644 --- a/app/settings/settingsdialog/delegates/backgrounddelegate.cpp +++ b/app/settings/settingsdialog/delegates/backgrounddelegate.cpp @@ -51,9 +51,9 @@ void BackgroundDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op //! draw underlying background QStyledItemDelegate::paint(painter, myOptions, index.model()->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN)); - QList icons = index.data(Qt::UserRole).value>(); + Latte::Data::LayoutIcon icon = index.data(Qt::UserRole).value(); - if (icons.count() > 0) { + if (!icon.isEmpty()) { int localMargin = MARGIN-1;// icons[0].isBackgroundFile && icons.count() == 1 ? qMin(option.rect.height()/4,MARGIN+5) : MARGIN-1; int aY = option.rect.y() + localMargin; @@ -61,53 +61,17 @@ void BackgroundDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op int centerX = option.rect.x() + (option.rect.width() / 2); int step = thick; - int total_icons_width = (thick-step) + icons.count() * step; + int total_icons_width = (thick-step) + step; if (total_icons_width > option.rect.width()){ step = thick/2; - total_icons_width = (thick-step) + icons.count() * step; + total_icons_width = (thick-step) + step; } int startX = centerX - (total_icons_width/2); - for (int i=0; isetRenderHint(QPainter::Antialiasing, true); - - if (icon.isBackgroundFile) { - int backImageMargin = qMin(option.rect.height()/4, MARGIN+2); - QRect backTarget(target.x() + backImageMargin, target.y() + backImageMargin, target.width() - 2*backImageMargin, target.height() - 2*backImageMargin); - - QPixmap backImage(icon.name); - backImage = backImage.copy(backTarget); - - QPalette::ColorRole textColorRole = selected ? QPalette::HighlightedText : QPalette::Text; - - QBrush imageBrush(backImage); - QPen pen; pen.setWidth(1); - pen.setColor(option.palette.color(Latte::colorGroup(option), textColorRole)); - - painter->setBrush(imageBrush); - painter->setPen(pen); - - painter->drawEllipse(backTarget); - } else { - QIcon::Mode mode = ((active && (selected || focused)) ? QIcon::Selected : QIcon::Normal); - - painter->drawPixmap(target, QIcon::fromTheme(icon.name).pixmap(target.height(), target.height(), mode)); + Latte::drawLayoutIcon(painter, option, QRect(startX, aY, thick, thick), icon); } - } } diff --git a/app/settings/settingsdialog/delegates/backgrounddelegate.h b/app/settings/settingsdialog/delegates/backgrounddelegate.h index df20fce92..95be02b40 100644 --- a/app/settings/settingsdialog/delegates/backgrounddelegate.h +++ b/app/settings/settingsdialog/delegates/backgrounddelegate.h @@ -42,9 +42,6 @@ public: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; -private: - void drawIcon(QPainter *painter, const QStyleOptionViewItem &option, const QRect &target, const Latte::Data::LayoutIcon &icon) const; - }; } diff --git a/app/settings/settingsdialog/delegates/layoutcmbitemdelegate.cpp b/app/settings/settingsdialog/delegates/layoutcmbitemdelegate.cpp index 93b41105d..471e2466a 100644 --- a/app/settings/settingsdialog/delegates/layoutcmbitemdelegate.cpp +++ b/app/settings/settingsdialog/delegates/layoutcmbitemdelegate.cpp @@ -51,11 +51,11 @@ void LayoutCmbItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem //! draw underlying background QStyledItemDelegate::paint(painter, myOptions, index.model()->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN)); - QList icons = index.data(Model::Layouts::BACKGROUNDUSERROLE).value>(); + Latte::Data::LayoutIcon icon = index.data(Model::Layouts::BACKGROUNDUSERROLE).value(); int iconsLength = (option.rect.height() + 4 * MARGIN); - if (icons.count() > 0) { + if (!icon.isEmpty()) { int localMargin = MARGIN-1; int aY = option.rect.y() + localMargin; @@ -63,19 +63,15 @@ void LayoutCmbItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem int centerX = option.rect.x() + iconsLength / 2; int step = thick; - int total_icons_width = (thick-step) + icons.count() * step; + int total_icons_width = (thick-step) + step; if (total_icons_width > option.rect.width()){ step = thick/2; - total_icons_width = (thick-step) + icons.count() * step; + total_icons_width = (thick-step) + step; } int startX = centerX - (total_icons_width/2); - - for (int i=0; i Layouts::iconsForCentralLayout(const int &row) const +Latte::Data::LayoutIcon Layouts::iconForCentralLayout(const int &row) const { - QList icons; + Latte::Data::LayoutIcon _icon; if (!m_layoutsTable[row].icon.isEmpty()) { //! if there is specific icon set from the user for this layout we draw only that icon - Latte::Data::LayoutIcon icon; - icon.name = m_layoutsTable[row].icon; - icon.isBackgroundFile = false; - icons << icon; - return icons; + _icon.name = m_layoutsTable[row].icon; + _icon.isBackgroundFile = false; + return _icon; } if (inMultipleMode()) { if (m_layoutsTable[row].activities.contains(Latte::Data::Layout::ALLACTIVITIESID)) { - Latte::Data::LayoutIcon icon; - icon.name = m_activitiesTable[Latte::Data::Layout::ALLACTIVITIESID].icon; - icon.isBackgroundFile = false; - icons << icon; + _icon.name = m_activitiesTable[Latte::Data::Layout::ALLACTIVITIESID].icon; + _icon.isBackgroundFile = false; + return _icon; } else if (m_layoutsTable[row].activities.contains(Latte::Data::Layout::FREEACTIVITIESID)) { - Latte::Data::LayoutIcon icon; - icon.name = m_activitiesTable[Latte::Data::Layout::FREEACTIVITIESID].icon; - icon.isBackgroundFile = false; - icons << icon; + _icon.name = m_activitiesTable[Latte::Data::Layout::FREEACTIVITIESID].icon; + _icon.isBackgroundFile = false; + return _icon; } else { QStringList activitiesIds = m_layoutsTable[row].activities; for(int i=0; i Layouts::iconsForCentralLayout(const int &row) co } if (QFileInfo(colorPath).exists()) { - Latte::Data::LayoutIcon icon; - icon.isBackgroundFile = true; - icon.name = colorPath; - icons << icon; + _icon.isBackgroundFile = true; + _icon.name = colorPath; + return _icon; } } - return icons; + return Latte::Data::LayoutIcon(); } -QList Layouts::icons(const int &row) const +Latte::Data::LayoutIcon Layouts::icon(const int &row) const { - return iconsForCentralLayout(row); + return iconForCentralLayout(row); } const Latte::Data::LayoutIcon Layouts::currentLayoutIcon(const QString &id) const { int row = rowForId(id); - QList iconsList; if (row >= 0) { - iconsList = icons(row); + return icon(row); } - return iconsList.count() > 0 ? iconsList[0] : Latte::Data::LayoutIcon(); + return Latte::Data::LayoutIcon(); } QString Layouts::sortableText(const int &priority, const int &row) const @@ -564,10 +556,10 @@ QVariant Layouts::data(const QModelIndex &index, int role) const } else if (role == LAYOUTHASCHANGESROLE) { return isNewLayout ? true : (original != m_layoutsTable[row]); } else if (role == BACKGROUNDUSERROLE) { - QList iconsList = icons(row); - QVariant iconsVariant; - iconsVariant.setValue>(iconsList); - return iconsVariant; + Latte::Data::LayoutIcon _icon = icon(row); + QVariant iconVariant; + iconVariant.setValue(_icon); + return iconVariant; } switch (column) { @@ -586,10 +578,10 @@ QVariant Layouts::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { return m_layoutsTable[row].background; } else if (role == Qt::UserRole) { - QList iconsList = icons(row); - QVariant iconsVariant; - iconsVariant.setValue>(iconsList); - return iconsVariant; + Latte::Data::LayoutIcon _icon = icon(row); + QVariant iconVariant; + iconVariant.setValue(_icon); + return iconVariant; } break; case NAMECOLUMN: diff --git a/app/settings/settingsdialog/layoutsmodel.h b/app/settings/settingsdialog/layoutsmodel.h index bd5a3e552..5f6e292f4 100644 --- a/app/settings/settingsdialog/layoutsmodel.h +++ b/app/settings/settingsdialog/layoutsmodel.h @@ -177,8 +177,8 @@ private: QStringList cleanStrings(const QStringList &original, const QStringList &occupied); - QList icons(const int &row) const; - QList iconsForCentralLayout(const int &row) const; + Latte::Data::LayoutIcon icon(const int &row) const; + Latte::Data::LayoutIcon iconForCentralLayout(const int &row) const; private: QString m_iconsPath;