1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-11 13:18:13 +03:00

visual improvements for settings delegates

This commit is contained in:
Michail Vourlakos 2020-03-15 17:58:13 +02:00
parent 7dbfb1184b
commit c0d8116e7b
6 changed files with 37 additions and 14 deletions

View File

@ -21,6 +21,8 @@
// local
#include "backgroundcmbitemdelegate.h"
#include "../models/layoutsmodel.h"
#include "../tools/settingstools.h"
// Qt
#include <QComboBox>
@ -40,7 +42,7 @@ namespace Layout {
namespace Delegate {
BackgroundCmbBox::BackgroundCmbBox(QObject *parent, QString iconsPath, QStringList colors)
: QItemDelegate(parent),
: QStyledItemDelegate(parent),
m_iconsPath(iconsPath),
Colors(colors)
{
@ -105,22 +107,36 @@ void BackgroundCmbBox::updateEditorGeometry(QWidget *editor, const QStyleOptionV
void BackgroundCmbBox::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem myOption = option;
QStyleOptionViewItem myOptions = option;
//! Remove the focus dotted lines
myOptions.state = (myOptions.state & ~QStyle::State_HasFocus);
QVariant background = index.data(Qt::BackgroundRole);
//! draw underlying background
QStyledItemDelegate::paint(painter, myOptions, index);
if (background.isValid()) {
QString backgroundStr = background.toString();
QString colorPath = backgroundStr.startsWith("/") ? backgroundStr : m_iconsPath + backgroundStr + "print.jpg";
if (QFileInfo(colorPath).exists()) {
QBrush colorBrush;
colorBrush.setTextureImage(QImage(colorPath).scaled(QSize(50, 50)));
colorBrush.setColor("black");
QPen pen;
QBrush colorBrush;
colorBrush.setTextureImage(QImage(colorPath));
pen.setColor("black");
painter->setPen(pen);
painter->setBrush(colorBrush);
painter->drawRect(QRect(option.rect.x(), option.rect.y(),
option.rect.width(), option.rect.height()));
int cX = option.rect.x() + (option.rect.width() / 2);
int cY = option.rect.y() + (option.rect.height() / 2);
int radius = (option.rect.height() - 4) / 2;
painter->drawEllipse(QPointF(cX, cY), radius, radius);
}
}
}

View File

@ -21,7 +21,7 @@
#define BACKGROUNDCMBBOXDELEGATE_H
// Qt
#include <QItemDelegate>
#include <QStyledItemDelegate>
class QModelIndex;
class QWidget;
@ -31,7 +31,7 @@ namespace Settings {
namespace Layout {
namespace Delegate {
class BackgroundCmbBox : public QItemDelegate
class BackgroundCmbBox : public QStyledItemDelegate
{
Q_OBJECT
public:

View File

@ -52,9 +52,6 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
bool isSharedCapable = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool();
if (!isSharedCapable) {
QStandardItemModel *model = (QStandardItemModel *) index.model();
QStyledItemDelegate::paint(painter, adjustedOption, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
QStyledItemDelegate::paint(painter, adjustedOption, index);
} else {
// Disabled

View File

@ -175,9 +175,9 @@ QVariant Layouts::headerData(int section, Qt::Orientation orientation, int role)
break;
case BACKGROUNDCOLUMN:
if (role == Qt::DisplayRole) {
return QString(i18nc("column for layout background", "Background"));
return QString("#");//(i18nc("column for layout background", "Background"));
} else if (role == Qt::DecorationRole) {
return QIcon::fromTheme("games-config-background");
return QString();//QIcon::fromTheme("games-config-background");
}
break;
case NAMECOLUMN:

View File

@ -34,6 +34,15 @@ bool isSelected(const QStyleOptionViewItem &option)
return false;
}
bool isHovered(const QStyleOptionViewItem &option)
{
if (option.state & QStyle::State_MouseOver) {
return true;
}
return false;
}
QPalette::ColorGroup colorGroup(const QStyleOptionViewItem &option)
{
if (option.state & QStyle::State_Active) {

View File

@ -28,6 +28,7 @@
namespace Latte {
bool isSelected(const QStyleOptionViewItem &option);
bool isHovered(const QStyleOptionViewItem &option);
QPalette::ColorGroup colorGroup(const QStyleOptionViewItem &option);
//! strings that even though they were initially at original list