author | leseb <leseb> | 2002-03-19 12:58:43 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-19 12:58:43 (UTC) |
commit | f298cb9f5557d88b9ff38feb4b5e090e5c164ec2 (patch) (unidiff) | |
tree | a27f4d18cf3a0b62987cc37238e78d7269b2504e /noncore/graphics/drawpad/colorpanel.cpp | |
parent | 58a456b92ba8986d4ea2375ddcfd6dd1d84c8fe5 (diff) | |
download | opie-f298cb9f5557d88b9ff38feb4b5e090e5c164ec2.zip opie-f298cb9f5557d88b9ff38feb4b5e090e5c164ec2.tar.gz opie-f298cb9f5557d88b9ff38feb4b5e090e5c164ec2.tar.bz2 |
Better color selection
Diffstat (limited to 'noncore/graphics/drawpad/colorpanel.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/colorpanel.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/colorpanel.cpp b/noncore/graphics/drawpad/colorpanel.cpp new file mode 100644 index 0000000..1db0d7b --- a/dev/null +++ b/noncore/graphics/drawpad/colorpanel.cpp | |||
@@ -0,0 +1,134 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * DrawPad - a drawing program for Opie Environment * | ||
4 | * * | ||
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | ||
6 | * * | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | * * | ||
12 | ***************************************************************************/ | ||
13 | |||
14 | #include "colorpanel.h" | ||
15 | |||
16 | #include <qlayout.h> | ||
17 | #include <qpainter.h> | ||
18 | |||
19 | ColorPanelButton::ColorPanelButton(const QColor& color, QWidget* parent, const char* name) | ||
20 | : QFrame(parent, name) | ||
21 | { | ||
22 | m_color = color; | ||
23 | |||
24 | setFixedSize(16, 16); | ||
25 | setActive(false); | ||
26 | } | ||
27 | |||
28 | ColorPanelButton::~ColorPanelButton() | ||
29 | { | ||
30 | } | ||
31 | |||
32 | void ColorPanelButton::setActive(bool active) | ||
33 | { | ||
34 | m_active = active; | ||
35 | |||
36 | if (m_active) { | ||
37 | setFrameStyle(Panel | Sunken); | ||
38 | } else { | ||
39 | setFrameStyle(NoFrame); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | void ColorPanelButton::enterEvent(QEvent* e) | ||
44 | { | ||
45 | Q_UNUSED(e) | ||
46 | |||
47 | if (!m_active) { | ||
48 | setFrameStyle(Panel | Sunken); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void ColorPanelButton::leaveEvent(QEvent* e) | ||
53 | { | ||
54 | Q_UNUSED(e) | ||
55 | |||
56 | if (!m_active) { | ||
57 | setFrameStyle(NoFrame); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | void ColorPanelButton::paintEvent(QPaintEvent* e) | ||
62 | { | ||
63 | QFrame::paintEvent(e); | ||
64 | |||
65 | QPainter painter; | ||
66 | painter.begin(this); | ||
67 | painter.fillRect(2, 2, 12, 12, m_color); | ||
68 | painter.setPen(Qt::black); | ||
69 | painter.drawRect(2, 2, 12, 12); | ||
70 | painter.end(); | ||
71 | } | ||
72 | |||
73 | void ColorPanelButton::mouseReleaseEvent(QMouseEvent* e) | ||
74 | { | ||
75 | Q_UNUSED(e) | ||
76 | |||
77 | emit selected(m_color); | ||
78 | } | ||
79 | |||
80 | ColorPanel::ColorPanel(QWidget* parent, const char* name) | ||
81 | : QWidget(parent, name) | ||
82 | { | ||
83 | m_pGridLayout = new QGridLayout(this, 5, 6); | ||
84 | |||
85 | addColor(QColor(255, 255, 255), 0, 1); | ||
86 | addColor(QColor(192, 192, 192), 0, 2); | ||
87 | addColor(QColor(128, 128, 128), 0, 3); | ||
88 | addColor(QColor(64, 64, 64), 0, 4); | ||
89 | addColor(QColor(0, 0, 0), 0, 5); | ||
90 | |||
91 | addColor(QColor(255, 0, 0), 1, 0); | ||
92 | addColor(QColor(255, 128, 0), 1, 1); | ||
93 | addColor(QColor(255, 255, 0), 1, 2); | ||
94 | addColor(QColor(128, 255, 0), 1, 3); | ||
95 | addColor(QColor(0, 255, 0), 1, 4); | ||
96 | addColor(QColor(0, 255, 128), 1, 5); | ||
97 | |||
98 | addColor(QColor(128, 0, 0), 2, 0); | ||
99 | addColor(QColor(128, 64, 0), 2, 1); | ||
100 | addColor(QColor(128, 128, 0), 2, 2); | ||
101 | addColor(QColor(64, 128, 0), 2, 3); | ||
102 | addColor(QColor(0, 128, 0), 2, 4); | ||
103 | addColor(QColor(0, 128, 64), 2, 5); | ||
104 | |||
105 | addColor(QColor(0, 255, 255), 3, 0); | ||
106 | addColor(QColor(0, 128, 255), 3, 1); | ||
107 | addColor(QColor(0, 0, 255), 3, 2); | ||
108 | addColor(QColor(128, 0, 255), 3, 3); | ||
109 | addColor(QColor(255, 0, 255), 3, 4); | ||
110 | addColor(QColor(255, 0, 128), 3, 5); | ||
111 | |||
112 | addColor(QColor(0, 128, 128), 4, 0); | ||
113 | addColor(QColor(0, 64, 128), 4, 1); | ||
114 | addColor(QColor(0, 0, 128), 4, 2); | ||
115 | addColor(QColor(64, 0, 128), 4, 3); | ||
116 | addColor(QColor(128, 0, 128), 4, 4); | ||
117 | addColor(QColor(128, 0, 64), 4, 5); | ||
118 | } | ||
119 | |||
120 | ColorPanel::~ColorPanel() | ||
121 | { | ||
122 | } | ||
123 | |||
124 | void ColorPanel::addColor(const QColor& color, int row, int col) | ||
125 | { | ||
126 | ColorPanelButton* panelButton = new ColorPanelButton(color, this); | ||
127 | connect(panelButton, SIGNAL(selected(const QColor&)), this, SLOT(buttonSelected(const QColor&))); | ||
128 | m_pGridLayout->addWidget(panelButton, row, col); | ||
129 | } | ||
130 | |||
131 | void ColorPanel::buttonSelected(const QColor& color) | ||
132 | { | ||
133 | emit colorSelected(color); | ||
134 | } | ||