diff --git a/app/layoutsDelegates/colorcmbboxdelegate.cpp b/app/layoutsDelegates/colorcmbboxdelegate.cpp index 50e176cb9..00d594429 100644 --- a/app/layoutsDelegates/colorcmbboxdelegate.cpp +++ b/app/layoutsDelegates/colorcmbboxdelegate.cpp @@ -1,4 +1,5 @@ #include "colorcmbboxdelegate.h" +#include "colorcmbboxitemdelegate.h" #include #include @@ -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; diff --git a/app/layoutsDelegates/colorcmbboxitemdelegate.cpp b/app/layoutsDelegates/colorcmbboxitemdelegate.cpp index 6ba082bc7..029863a89 100644 --- a/app/layoutsDelegates/colorcmbboxitemdelegate.cpp +++ b/app/layoutsDelegates/colorcmbboxitemdelegate.cpp @@ -6,29 +6,33 @@ #include -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); + } diff --git a/app/layoutsDelegates/colorcmbboxitemdelegate.h b/app/layoutsDelegates/colorcmbboxitemdelegate.h index 2db41c7a3..53aaee589 100644 --- a/app/layoutsDelegates/colorcmbboxitemdelegate.h +++ b/app/layoutsDelegates/colorcmbboxitemdelegate.h @@ -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