create colorcombobox for layouts

--create a new delegate for the combobox of layouts
color
pull/1/head
Michail Vourlakos 8 years ago
parent a247170c61
commit ef8e587672

@ -21,6 +21,7 @@ set(lattedock-app_SRCS
layoutconfigdialog.cpp
importer.cpp
layoutsDelegates/checkboxdelegate.cpp
layoutsDelegates/colorcmbboxdelegate.cpp
main.cpp
)

@ -23,6 +23,7 @@
#include "layoutconfigdialog.h"
#include "layoutsettings.h"
#include "layoutsDelegates/checkboxdelegate.h"
#include "layoutsDelegates/colorcmbboxdelegate.h"
#include <QDir>
#include <QStandardItem>
@ -67,6 +68,8 @@ LayoutConfigDialog::LayoutConfigDialog(QWidget *parent, LayoutManager *manager)
loadLayouts();
ui->layoutsView->setItemDelegateForColumn(3, new CheckBoxDelegate(this));
QString iconsPath(m_manager->corona()->kPackage().path() + "../../plasmoids/org.kde.latte.containment/contents/icons/");
ui->layoutsView->setItemDelegateForColumn(1, new ColorCmbBoxDelegate(this, iconsPath));
}
LayoutConfigDialog::~LayoutConfigDialog()
@ -140,18 +143,15 @@ void LayoutConfigDialog::loadLayouts()
m_model->setItem(i - 1, 0, id);
QStandardItem *color = new QStandardItem();
color->setEditable(false);
QString colorPath = m_manager->corona()->kPackage().path() + "../../plasmoids/org.kde.latte.containment/contents/icons/" + layoutSets.color() + "print.jpg";
qDebug() << "coloring path :::: " << colorPath;
//color->setEditable(false);
/*QString colorPath = m_manager->corona()->kPackage().path() + "../../plasmoids/org.kde.latte.containment/contents/icons/" + layoutSets.color() + "print.jpg";
QBrush colorBrush;
colorBrush.setTextureImage(QImage(colorPath).scaled(QSize(50, 50)));
color->setBackground(colorBrush);
color->setBackground(colorBrush);*/
color->setSelectable(false);
m_model->setItem(i - 1, 1, color);
//m_model->setData(m_model->index(i - 1, 1), QColor(layoutSets.color()), Qt::BackgroundRole);
m_model->setData(m_model->index(i - 1, 1), layoutSets.color(), Qt::BackgroundRole);
QStandardItem *name = new QStandardItem(layoutSets.name());

@ -0,0 +1,100 @@
#include "colorcmbboxdelegate.h"
#include <QComboBox>
#include <QDebug>
#include <QWidget>
#include <QModelIndex>
#include <QApplication>
#include <QPainter>
#include <QString>
#include <iostream>
ColorCmbBoxDelegate::ColorCmbBoxDelegate(QObject *parent, QString iconsPath)
: QItemDelegate(parent),
m_iconsPath(iconsPath)
{
Items.push_back("Test0");
Items.push_back("Test1");
Items.push_back("Test2");
Items.push_back("Test3");
Items.push_back("Test4");
Items.push_back("Test5");
Items.push_back("Test6");
Items.push_back("Test7");
Items.push_back("Test8");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
Items.push_back("Test...");
}
QWidget *ColorCmbBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QComboBox *editor = new QComboBox(parent);
//QString colorPath = "/usr/share/plasma/plasmoids/org.kde.latte.containment/contents/icons/blueprint.jpg";
for (unsigned int i = 0; i < Items.size(); ++i) {
editor->addItem(Items[i].c_str());
}
return editor;
}
void ColorCmbBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QComboBox *comboBox = static_cast<QComboBox *>(editor);
int value = index.model()->data(index, Qt::EditRole).toUInt();
comboBox->setCurrentIndex(value);
}
void ColorCmbBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QComboBox *comboBox = static_cast<QComboBox *>(editor);
model->setData(index, comboBox->currentIndex(), Qt::EditRole);
}
void ColorCmbBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}
void ColorCmbBoxDelegate::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::BackgroundRole);
if (value.isValid()) {
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()));
}
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter);
}

@ -0,0 +1,29 @@
#ifndef COLORCMBBOXDELEGATE_H
#define COLORCMBBOXDELEGATE_H
#include <string>
#include <vector>
#include <QItemDelegate>
class QModelIndex;
class QWidget;
class QVariant;
class ColorCmbBoxDelegate : public QItemDelegate {
Q_OBJECT
public:
ColorCmbBoxDelegate(QObject *parent = 0, QString iconsPath = QString());
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
std::vector<std::string> Items;
QString m_iconsPath;
};
#endif
Loading…
Cancel
Save