From 20c38f6f220bfcf53d4852c728e3e5bf5307f760 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 16 Apr 2018 15:53:11 +0300 Subject: [PATCH] improvements in layouts editor painting --- .../activitycmbboxdelegate.cpp | 15 +++- app/layoutsDelegates/checkboxdelegate.cpp | 23 ++----- .../colorcmbboxitemdelegate.cpp | 2 + app/layoutsDelegates/layoutnamedelegate.cpp | 69 ++++++++++++++++++- 4 files changed, 88 insertions(+), 21 deletions(-) diff --git a/app/layoutsDelegates/activitycmbboxdelegate.cpp b/app/layoutsDelegates/activitycmbboxdelegate.cpp index 7d9248c07..eabc5901d 100644 --- a/app/layoutsDelegates/activitycmbboxdelegate.cpp +++ b/app/layoutsDelegates/activitycmbboxdelegate.cpp @@ -126,7 +126,19 @@ void ActivityCmbBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem myOptions.text = assignedActivitiesText(index); QTextDocument doc; - doc.setHtml(myOptions.text); + QString css; + + QBrush nBrush; + + if ((option.state & QStyle::State_Active) && (option.state & QStyle::State_Selected)) { + nBrush = option.palette.brush(QPalette::Active, QPalette::HighlightedText); + } else { + nBrush = option.palette.brush(QPalette::Inactive, QPalette::Text); + } + + css = QString("body { color : %1; }").arg(nBrush.color().name()); + doc.setDefaultStyleSheet(css); + doc.setHtml("" + myOptions.text + ""); myOptions.text = ""; myOptions.widget->style()->drawControl(QStyle::CE_ItemViewItem, &myOptions, painter); @@ -136,6 +148,7 @@ void ActivityCmbBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem painter->translate(myOptions.rect.left(), myOptions.rect.top() + offsetY); QRect clip(0, 0, myOptions.rect.width(), myOptions.rect.height()); + doc.drawContents(painter, clip); } else { QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOptions, painter); diff --git a/app/layoutsDelegates/checkboxdelegate.cpp b/app/layoutsDelegates/checkboxdelegate.cpp index ea67b8c89..76876af1a 100644 --- a/app/layoutsDelegates/checkboxdelegate.cpp +++ b/app/layoutsDelegates/checkboxdelegate.cpp @@ -25,6 +25,9 @@ #include #include #include +#include + +const int HIDDENTEXTCOLUMN = 1; CheckBoxDelegate::CheckBoxDelegate(QObject *parent) : QStyledItemDelegate(parent) @@ -33,24 +36,8 @@ CheckBoxDelegate::CheckBoxDelegate(QObject *parent) void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - if (option.state & QStyle::State_Selected) { - QPen nPen; - QBrush nBrush; - - if (option.state & QStyle::State_Active) { - nBrush = option.palette.highlight(); - } else if (option.state & QStyle::State_MouseOver) { - nBrush = option.palette.brush(QPalette::Inactive, QPalette::Highlight); - } else { - nBrush = option.palette.brush(QPalette::Inactive, QPalette::Highlight); - } - - painter->setBrush(nBrush); - nPen.setColor(nBrush.color()); - - painter->setPen(nPen); - painter->drawRect(option.rect); - } + QStandardItemModel *model = (QStandardItemModel *) index.model(); + QStyledItemDelegate::paint(painter, option, model->index(index.row(), HIDDENTEXTCOLUMN)); QStyledItemDelegate::paint(painter, option, index); } diff --git a/app/layoutsDelegates/colorcmbboxitemdelegate.cpp b/app/layoutsDelegates/colorcmbboxitemdelegate.cpp index 392e30d77..8a0d9936e 100644 --- a/app/layoutsDelegates/colorcmbboxitemdelegate.cpp +++ b/app/layoutsDelegates/colorcmbboxitemdelegate.cpp @@ -60,5 +60,7 @@ void ColorCmbBoxItemDelegate::paint(QPainter *painter, const QStyleOptionViewIte painter->drawRect(option.rect - QMargins(5, 5, 5, 5)); } } + + painter->restore(); } diff --git a/app/layoutsDelegates/layoutnamedelegate.cpp b/app/layoutsDelegates/layoutnamedelegate.cpp index 1400ce954..b0c60a36c 100644 --- a/app/layoutsDelegates/layoutnamedelegate.cpp +++ b/app/layoutsDelegates/layoutnamedelegate.cpp @@ -20,6 +20,7 @@ #include "layoutnamedelegate.h" #include +#include #include #include #include @@ -60,14 +61,78 @@ void LayoutNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op myOptionMain.rect.setWidth(option.rect.width() - startWidth - thick); QStyledItemDelegate::paint(painter, myOptionMain, index); - //! draw background + + //! draw background at edges QStyledItemDelegate::paint(painter, myOptionS, model->index(index.row(), HIDDENTEXTCOLUMN)); + + //! Lock Icon 1: Unicode character attempt + /*QString s = QChar(0x2318); + QString s = QChar(0x2757); + myOptionE.text = s;*/ QStyledItemDelegate::paint(painter, myOptionE, model->index(index.row(), HIDDENTEXTCOLUMN)); - //! draw icon + //! Lock Icon 2: QIcon attempt that doesnt change color QIcon lockIcon = QIcon::fromTheme("object-locked"); painter->drawPixmap(destinationE, lockIcon.pixmap(thick, thick)); + //! Lock Icon 3: QIcon and change colors attempt + /*QIcon lockIcon = QIcon::fromTheme("object-locked"); + QPixmap origPixmap = lockIcon.pixmap(thick, thick); + QPixmap lockPixmap = origPixmap; + + QBrush nBrush; + + if ((option.state & QStyle::State_Active) && (option.state & QStyle::State_Selected)) { + nBrush = option.palette.brush(QPalette::Active, QPalette::HighlightedText); + } else { + nBrush = option.palette.brush(QPalette::Inactive, QPalette::Text); + } + + lockPixmap.fill(nBrush.color()); + lockPixmap.setMask(origPixmap.createMaskFromColor(Qt::transparent)); + + painter->drawPixmap(destinationE, lockPixmap);*/ + + //! Lock Icon 4: Plasma::Svg and change color group attempt + /*Plasma::Svg svgIcon; + + svgIcon.setStatus(Plasma::Svg::Normal); + svgIcon.setUsingRenderingCache(false); + svgIcon.setDevicePixelRatio(qApp->devicePixelRatio()); + + //! find path + //try to load from iconloader an svg with Plasma::Svg + const auto *iconTheme = KIconLoader::global()->theme(); + QString iconPath; + + if (iconTheme) { + iconPath = iconTheme->iconPath("object-locked" + QLatin1String(".svg") + , thick + , KIconLoader::MatchBest); + + if (iconPath.isEmpty()) { + iconPath = iconTheme->iconPath("object-locked" + QLatin1String(".svgz") + , thick + , KIconLoader::MatchBest); + } + } else { + qWarning() << "KIconLoader has no theme set"; + } + + if (!iconPath.isEmpty()) { + svgIcon.setImagePath(iconPath); + + if ((option.state & QStyle::State_Active) && (option.state & QStyle::State_Selected)) { + svgIcon.setColorGroup(Plasma::Theme::ComplementaryColorGroup); + } else { + svgIcon.setColorGroup(Plasma::Theme::NormalColorGroup); + } + + svgIcon.resize(thick, thick); + } + + painter->drawPixmap(destinationE, svgIcon.pixmap());*/ + return; }