-
Notifications
You must be signed in to change notification settings - Fork 0
/
colordelegate.cpp
33 lines (26 loc) · 1.06 KB
/
colordelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "colordelegate.h"
#include "color_wheel.hpp"
ColorDelegate::ColorDelegate(QObject *parent) : QStyledItemDelegate(parent)
{
}
QWidget *ColorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
color_widgets::ColorWheel *edit = new color_widgets::ColorWheel(parent);
return edit;
}
void ColorDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QString value = index.data().toString();
color_widgets::ColorWheel *editt = static_cast<color_widgets::ColorWheel*>(editor);
editt->setColor(QColor(value));
}
void ColorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
color_widgets::ColorWheel *spinBox = static_cast<color_widgets::ColorWheel*>(editor);
QString value = spinBox->color().toRgb().name();
model->setData(index, value, Qt::EditRole);
}
void ColorDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
{
editor->setGeometry(option.rect);
}