forked from frankyeh/DSI-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qcolorcombobox.cpp
53 lines (45 loc) · 1.29 KB
/
qcolorcombobox.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <QColorDialog>
#include <QPainter>
#include "qcolorcombobox.h"
QColor QColorComboBox::color() const
{
return itemData(currentIndex(), Qt::DecorationRole).value<QColor>();
}
void QColorComboBox::setColor(QColor color)
{
setCurrentIndex(findData(color, int(Qt::DecorationRole)));
}
void QColorComboBox::populateList()
{
QStringList colorNames = QColor::colorNames();
for (int i = 0; i < colorNames.size(); ++i) {
QColor color(colorNames[i]);
insertItem(i, colorNames[i]);
setItemData(i, color, Qt::DecorationRole);
}
}
QColor QColorToolButton::color() const
{
return selected_color;
}
void QColorToolButton::setColor(QColor color)
{
selected_color = color;
QPixmap pixmap(22,22);
QPainter painter(&pixmap);
painter.setPen(color);
painter.setBrush(color);
painter.drawRect(0,0,22,22);
QIcon icon;
icon.addPixmap(pixmap);
setIcon(icon);
setToolButtonStyle(Qt::ToolButtonIconOnly);
}
void QColorToolButton::mouseReleaseEvent ( QMouseEvent * e )
{
QColor c = QColorDialog::getColor(selected_color,(QWidget*)parent(),"Select color",QColorDialog::ShowAlphaChannel);
if(!c.isValid())
return;
setColor(c);
QToolButton::mouseReleaseEvent(e);
}