author | leseb <leseb> | 2002-03-19 12:58:43 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-19 12:58:43 (UTC) |
commit | f298cb9f5557d88b9ff38feb4b5e090e5c164ec2 (patch) (side-by-side diff) | |
tree | a27f4d18cf3a0b62987cc37238e78d7269b2504e /noncore/graphics/drawpad/drawpad.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/drawpad.cpp') (more/less context) (show 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 @@ -4,24 +4,26 @@ * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "drawpad.h" +#include "colordialog.h" +#include "colorpanel.h" #include "drawpadcanvas.h" #include "ellipsedrawmode.h" #include "erasedrawmode.h" #include "filldrawmode.h" #include "linedrawmode.h" #include "pointdrawmode.h" #include "rectangledrawmode.h" #include <qpe/global.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/resource.h> @@ -44,34 +46,24 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); if (file.open(IO_ReadOnly)) { m_pDrawPadCanvas->load(&file); file.close(); } setCentralWidget(m_pDrawPadCanvas); - m_colors.resize(8); - m_colors.at(0) = Qt::black; - m_colors.at(1) = Qt::white; - m_colors.at(2) = Qt::red; - m_colors.at(3) = Qt::green; - m_colors.at(4) = Qt::blue; - m_colors.at(5) = Qt::cyan; - m_colors.at(6) = Qt::magenta; - m_colors.at(7) = Qt::yellow; - // init menu setToolBarsMovable(false); QPEToolBar* menuToolBar = new QPEToolBar(this); QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll())); clearAllAction->addTo(toolsPopupMenu); @@ -179,51 +171,55 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) QPEToolBar* drawParametersToolBar = new QPEToolBar(this); QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); penWidthSpinBox->setValue(1); m_pPenColorToolButton = new QToolButton(drawParametersToolBar); m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); - connect(penColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changePenColor(int))); - QPixmap penColorPixmap(14, 14); + ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); + connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); + penColorPopupMenu->insertItem(penColorPanel); - for (uint i = 0; i < m_colors.size(); i++) { - penColorPixmap.fill(m_colors.at(i)); - penColorPopupMenu->insertItem(penColorPixmap, i); - } + penColorPopupMenu->insertSeparator(); + + QAction* choosePenColorAction = new QAction(tr("More"), tr("More..."), 0, this); + connect(choosePenColorAction, SIGNAL(activated()), this, SLOT(choosePenColor())); + choosePenColorAction->addTo(penColorPopupMenu); QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); m_pPenColorToolButton->setPopup(penColorPopupMenu); m_pPenColorToolButton->setPopupDelay(0); penColorPopupMenu->activateItemAt(0); m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); - connect(brushColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changeBrushColor(int))); - QPixmap brushColorPixmap(14, 14); + ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu); + connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); + brushColorPopupMenu->insertItem(brushColorPanel); - for (uint i = 0; i < m_colors.size(); i++) { - brushColorPixmap.fill(m_colors.at(i)); - brushColorPopupMenu->insertItem(brushColorPixmap, i); - } + brushColorPopupMenu->insertSeparator(); + + QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this); + connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor())); + chooseBrushColorAction->addTo(brushColorPopupMenu); QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); m_pBrushColorToolButton->setPopup(brushColorPopupMenu); m_pBrushColorToolButton->setPopupDelay(0); brushColorPopupMenu->activateItemAt(1); } DrawPad::~DrawPad() { QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); @@ -325,42 +321,58 @@ void DrawPad::setEraseDrawMode() m_pLineDrawModeAction->setOn(false); m_pRectangleDrawModeAction->setOn(false); m_pEllipseDrawModeAction->setOn(false); m_pFillDrawModeAction->setOn(false); m_pEraseDrawModeAction->setOn(true); } void DrawPad::changePenWidth(int value) { m_pen.setWidth(value); } -void DrawPad::changePenColor(int index) +void DrawPad::changePenColor(const QColor& color) { - m_pen.setColor(m_colors.at(index)); + m_pen.setColor(color); QPainter painter; painter.begin(m_pPenColorToolButton->pixmap()); painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); painter.end(); + + m_pPenColorToolButton->popup()->hide(); } -void DrawPad::changeBrushColor(int index) +void DrawPad::changeBrushColor(const QColor& color) { - m_brush = QBrush(m_colors.at(index)); + m_brush = QBrush(color); QPainter painter; painter.begin(m_pBrushColorToolButton->pixmap()); painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); painter.end(); + + m_pBrushColorToolButton->popup()->hide(); +} + +void DrawPad::choosePenColor() +{ + QColor newPenColor = QColorDialog::getColor(m_pen.color()); + changePenColor(newPenColor); +} + +void DrawPad::chooseBrushColor() +{ + QColor newBrushColor = QColorDialog::getColor(m_brush.color()); + changeBrushColor(newBrushColor); } void DrawPad::updateUndoRedoToolButtons() { m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); } void DrawPad::updateNavigationToolButtons() { m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |