Diffstat (limited to 'noncore/graphics/drawpad/drawpad.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 5cc2197..f67bef8 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -13,6 +13,8 @@ | |||
13 | 13 | ||
14 | #include "drawpad.h" | 14 | #include "drawpad.h" |
15 | 15 | ||
16 | #include "colordialog.h" | ||
17 | #include "colorpanel.h" | ||
16 | #include "drawpadcanvas.h" | 18 | #include "drawpadcanvas.h" |
17 | #include "ellipsedrawmode.h" | 19 | #include "ellipsedrawmode.h" |
18 | #include "erasedrawmode.h" | 20 | #include "erasedrawmode.h" |
@@ -53,16 +55,6 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
53 | 55 | ||
54 | setCentralWidget(m_pDrawPadCanvas); | 56 | setCentralWidget(m_pDrawPadCanvas); |
55 | 57 | ||
56 | m_colors.resize(8); | ||
57 | m_colors.at(0) = Qt::black; | ||
58 | m_colors.at(1) = Qt::white; | ||
59 | m_colors.at(2) = Qt::red; | ||
60 | m_colors.at(3) = Qt::green; | ||
61 | m_colors.at(4) = Qt::blue; | ||
62 | m_colors.at(5) = Qt::cyan; | ||
63 | m_colors.at(6) = Qt::magenta; | ||
64 | m_colors.at(7) = Qt::yellow; | ||
65 | |||
66 | // init menu | 58 | // init menu |
67 | 59 | ||
68 | setToolBarsMovable(false); | 60 | setToolBarsMovable(false); |
@@ -188,14 +180,16 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
188 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); | 180 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); |
189 | 181 | ||
190 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); | 182 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); |
191 | connect(penColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changePenColor(int))); | ||
192 | 183 | ||
193 | QPixmap penColorPixmap(14, 14); | 184 | ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); |
185 | connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); | ||
186 | penColorPopupMenu->insertItem(penColorPanel); | ||
194 | 187 | ||
195 | for (uint i = 0; i < m_colors.size(); i++) { | 188 | penColorPopupMenu->insertSeparator(); |
196 | penColorPixmap.fill(m_colors.at(i)); | 189 | |
197 | penColorPopupMenu->insertItem(penColorPixmap, i); | 190 | QAction* choosePenColorAction = new QAction(tr("More"), tr("More..."), 0, this); |
198 | } | 191 | connect(choosePenColorAction, SIGNAL(activated()), this, SLOT(choosePenColor())); |
192 | choosePenColorAction->addTo(penColorPopupMenu); | ||
199 | 193 | ||
200 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); | 194 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); |
201 | m_pPenColorToolButton->setPopup(penColorPopupMenu); | 195 | m_pPenColorToolButton->setPopup(penColorPopupMenu); |
@@ -207,14 +201,16 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
207 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); | 201 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); |
208 | 202 | ||
209 | QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); | 203 | QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); |
210 | connect(brushColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changeBrushColor(int))); | ||
211 | 204 | ||
212 | QPixmap brushColorPixmap(14, 14); | 205 | ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu); |
206 | connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); | ||
207 | brushColorPopupMenu->insertItem(brushColorPanel); | ||
213 | 208 | ||
214 | for (uint i = 0; i < m_colors.size(); i++) { | 209 | brushColorPopupMenu->insertSeparator(); |
215 | brushColorPixmap.fill(m_colors.at(i)); | 210 | |
216 | brushColorPopupMenu->insertItem(brushColorPixmap, i); | 211 | QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this); |
217 | } | 212 | connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor())); |
213 | chooseBrushColorAction->addTo(brushColorPopupMenu); | ||
218 | 214 | ||
219 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); | 215 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); |
220 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); | 216 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); |
@@ -334,24 +330,40 @@ void DrawPad::changePenWidth(int value) | |||
334 | m_pen.setWidth(value); | 330 | m_pen.setWidth(value); |
335 | } | 331 | } |
336 | 332 | ||
337 | void DrawPad::changePenColor(int index) | 333 | void DrawPad::changePenColor(const QColor& color) |
338 | { | 334 | { |
339 | m_pen.setColor(m_colors.at(index)); | 335 | m_pen.setColor(color); |
340 | 336 | ||
341 | QPainter painter; | 337 | QPainter painter; |
342 | painter.begin(m_pPenColorToolButton->pixmap()); | 338 | painter.begin(m_pPenColorToolButton->pixmap()); |
343 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); | 339 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); |
344 | painter.end(); | 340 | painter.end(); |
341 | |||
342 | m_pPenColorToolButton->popup()->hide(); | ||
345 | } | 343 | } |
346 | 344 | ||
347 | void DrawPad::changeBrushColor(int index) | 345 | void DrawPad::changeBrushColor(const QColor& color) |
348 | { | 346 | { |
349 | m_brush = QBrush(m_colors.at(index)); | 347 | m_brush = QBrush(color); |
350 | 348 | ||
351 | QPainter painter; | 349 | QPainter painter; |
352 | painter.begin(m_pBrushColorToolButton->pixmap()); | 350 | painter.begin(m_pBrushColorToolButton->pixmap()); |
353 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); | 351 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); |
354 | painter.end(); | 352 | painter.end(); |
353 | |||
354 | m_pBrushColorToolButton->popup()->hide(); | ||
355 | } | ||
356 | |||
357 | void DrawPad::choosePenColor() | ||
358 | { | ||
359 | QColor newPenColor = QColorDialog::getColor(m_pen.color()); | ||
360 | changePenColor(newPenColor); | ||
361 | } | ||
362 | |||
363 | void DrawPad::chooseBrushColor() | ||
364 | { | ||
365 | QColor newBrushColor = QColorDialog::getColor(m_brush.color()); | ||
366 | changeBrushColor(newBrushColor); | ||
355 | } | 367 | } |
356 | 368 | ||
357 | void DrawPad::updateUndoRedoToolButtons() | 369 | void DrawPad::updateUndoRedoToolButtons() |