mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-28 19:21:50 +03:00
provide correct color combobox in layouts manager
This commit is contained in:
parent
0762e57bab
commit
3bbfeced5f
@ -1,4 +1,5 @@
|
||||
#include "colorcmbboxdelegate.h"
|
||||
#include "colorcmbboxitemdelegate.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
@ -19,9 +20,16 @@ ColorCmbBoxDelegate::ColorCmbBoxDelegate(QObject *parent, QString iconsPath, QSt
|
||||
QWidget *ColorCmbBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *editor = new QComboBox(parent);
|
||||
editor->setItemDelegate(new ColorCmbBoxItemDelegate(editor, m_iconsPath));
|
||||
|
||||
for (unsigned int i = 0; i < Colors.count(); ++i) {
|
||||
editor->addItem(Colors[i]);
|
||||
if (Colors[i] != "sepia") {
|
||||
QPixmap pixmap(50, 50);
|
||||
pixmap.fill(QColor(Colors[i]));
|
||||
QIcon icon(pixmap);
|
||||
|
||||
editor->addItem(icon, Colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return editor;
|
||||
|
@ -6,29 +6,33 @@
|
||||
#include <QString>
|
||||
|
||||
|
||||
ColorCmbBoxItemDelegate::ColorCmbBoxItemDelegate(QObject *parent)
|
||||
: QAbstractItemDelegate(parent)
|
||||
ColorCmbBoxItemDelegate::ColorCmbBoxItemDelegate(QObject *parent, QString iconsPath)
|
||||
: QAbstractItemDelegate(parent),
|
||||
m_iconsPath(iconsPath)
|
||||
{
|
||||
}
|
||||
|
||||
QSize ColorCmbBoxItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QSize(option.rect.width(), 50);
|
||||
}
|
||||
|
||||
void ColorCmbBoxItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QStyleOptionViewItem myOption = option;
|
||||
//QString text = Items[index.row()].c_str();
|
||||
//myOption.text = text;
|
||||
QVariant value = index.data(Qt::DisplayRole);
|
||||
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter);
|
||||
|
||||
if (value.isValid()) {
|
||||
qDebug() << value.toString();
|
||||
/*QString colorPath = m_iconsPath + value.toString() + "print.jpg";
|
||||
QString colorPath = m_iconsPath + value.toString() + "print.jpg";
|
||||
QBrush colorBrush;
|
||||
colorBrush.setTextureImage(QImage(colorPath).scaled(QSize(50, 50)));
|
||||
|
||||
painter->setBrush(colorBrush);
|
||||
painter->drawRect(QRect(option.rect.x(), option.rect.y(),
|
||||
option.rect.width(), option.rect.height()));*/
|
||||
painter->drawRect(option.rect - QMargins(5, 5, 5, 5));
|
||||
}
|
||||
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter);
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,14 @@
|
||||
class ColorCmbBoxItemDelegate : public QAbstractItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ColorCmbBoxItemDelegate(QObject *parent = 0);
|
||||
ColorCmbBoxItemDelegate(QObject *parent = 0, QString iconsPath = QString());
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
QString m_iconsPath;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user