author | drw <drw> | 2002-04-26 00:51:19 (UTC) |
---|---|---|
committer | drw <drw> | 2002-04-26 00:51:19 (UTC) |
commit | 97e07ec8e7345d90913791edba813d4b72aa33a9 (patch) (side-by-side diff) | |
tree | 468906df1cbe3db449c771071482d9a79d3f39f0 | |
parent | a111f57eedcf27623e9bff2816c83d3287272aff (diff) | |
download | opie-97e07ec8e7345d90913791edba813d4b72aa33a9.zip opie-97e07ec8e7345d90913791edba813d4b72aa33a9.tar.gz opie-97e07ec8e7345d90913791edba813d4b72aa33a9.tar.bz2 |
Use new ColorPopupMenu and ColorDialog found in libopie
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 77 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.pro | 10 |
3 files changed, 43 insertions, 48 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 7e6fc53..77fee98 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp @@ -1,99 +1,101 @@ /*************************************************************************** * * * DrawPad - a drawing program for Opie Environment * * * * (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 "colordialog.h" +//#include "colorpanel.h" #include "drawpadcanvas.h" #include "ellipsetool.h" #include "erasetool.h" #include "exportdialog.h" #include "filledellipsetool.h" #include "filledrectangletool.h" #include "filltool.h" #include "importdialog.h" #include "linetool.h" #include "pointtool.h" #include "rectangletool.h" #include "texttool.h" #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/resource.h> +#include <opie/colordialog.h> +#include <opie/colorpopupmenu.h> #include <qaction.h> #include <qfile.h> #include <qpainter.h> #include <qspinbox.h> #include <qtoolbutton.h> #include <qtooltip.h> DrawPad::DrawPad(QWidget* parent, const char* name) : QMainWindow(parent, name) { // init members m_pDrawPadCanvas = new DrawPadCanvas(this, this); connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); setCentralWidget(m_pDrawPadCanvas); // init menu setToolBarsMovable(false); QPEToolBar* menuToolBar = new QPEToolBar(this); QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); connect(deleteAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deleteAll())); deleteAllAction->addTo(toolsPopupMenu); toolsPopupMenu->insertSeparator(); QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); importPageAction->addTo(toolsPopupMenu); QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); exportPageAction->addTo(toolsPopupMenu); menuBar->insertItem(tr("Tools"), toolsPopupMenu); // init page toolbar QPEToolBar* pageToolBar = new QPEToolBar(this); QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); newPageAction->addTo(pageToolBar); QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); clearPageAction->addTo(pageToolBar); QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); deletePageAction->addTo(pageToolBar); QPEToolBar* emptyToolBar = new QPEToolBar(this); emptyToolBar->setHorizontalStretchable(true); @@ -155,166 +157,177 @@ DrawPad::DrawPad(QWidget* parent, const char* name) connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool())); m_pRectangleToolAction->addTo(rectanglePopupMenu); m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadIconSet("drawpad/filledrectangle.png"), "", 0, this); connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool())); m_pFilledRectangleToolAction->addTo(rectanglePopupMenu); m_pRectangleToolButton->setPopup(rectanglePopupMenu); m_pRectangleToolButton->setPopupDelay(0); m_pEllipseToolButton = new QToolButton(drawModeToolBar); m_pEllipseToolButton->setToggleButton(true); QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton); m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), "", 0, this); connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool())); m_pEllipseToolAction->addTo(ellipsePopupMenu); m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadIconSet("drawpad/filledellipse.png"), "", 0, this); connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool())); m_pFilledEllipseToolAction->addTo(ellipsePopupMenu); m_pEllipseToolButton->setPopup(ellipsePopupMenu); m_pEllipseToolButton->setPopupDelay(0); m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadIconSet("drawpad/text.png"), QString::null, 0, this); m_pTextToolAction->setToggleAction(true); connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool())); m_pTextToolAction->addTo(drawModeToolBar); m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); m_pFillToolAction->setToggleAction(true); connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); m_pFillToolAction->addTo(drawModeToolBar); m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); m_pEraseToolAction->setToggleAction(true); connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); m_pEraseToolAction->addTo(drawModeToolBar); m_pTool = 0; setRectangleTool(); setEllipseTool(); setPointTool(); emptyToolBar = new QPEToolBar(this); emptyToolBar->setHorizontalStretchable(true); emptyToolBar->addSeparator(); // init draw parameters toolbar QPEToolBar* drawParametersToolBar = new QPEToolBar(this); QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); QToolTip::add(penWidthSpinBox, tr("Pen Width")); penWidthSpinBox->setValue(1); penWidthSpinBox->setFocusPolicy(QWidget::NoFocus); m_pPenColorToolButton = new QToolButton(drawParametersToolBar); m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); - QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); + ColorPopupMenu* colorPopupMenu = new ColorPopupMenu( Qt::black, m_pPenColorToolButton ); + m_pPenColorToolButton->setPopup( colorPopupMenu ); + m_pPenColorToolButton->setPopupDelay( 0 ); + QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); + connect( colorPopupMenu, SIGNAL( colorSelected( const QColor& ) ), this, SLOT( changePenColor( const QColor& ) ) ); - ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); - connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); +// QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); - penColorPopupMenu->insertItem(penColorPanel); - penColorPopupMenu->insertSeparator(); +// ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); +// connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); - QAction* choosePenColorAction = new QAction(tr("More"), tr("More..."), 0, this); - connect(choosePenColorAction, SIGNAL(activated()), this, SLOT(choosePenColor())); - choosePenColorAction->addTo(penColorPopupMenu); +// penColorPopupMenu->insertItem(penColorPanel); +// penColorPopupMenu->insertSeparator(); - QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); - m_pPenColorToolButton->setPopup(penColorPopupMenu); - m_pPenColorToolButton->setPopupDelay(0); +// QAction* choosePenColorAction = new QAction(tr("More"), tr("More..."), 0, this); +// connect(choosePenColorAction, SIGNAL(activated()), this, SLOT(choosePenColor())); +// choosePenColorAction->addTo(penColorPopupMenu); - penColorPanel->buttonSelected(Qt::black); +// m_pPenColorToolButton->setPopup(colorPopupMenu); +// m_pPenColorToolButton->setPopupDelay(0); + +// penColorPanel->buttonSelected(Qt::black); m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); - QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); - ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu); - connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); + colorPopupMenu = new ColorPopupMenu( Qt::white, m_pBrushColorToolButton ); + m_pBrushColorToolButton->setPopup( colorPopupMenu ); + m_pBrushColorToolButton->setPopupDelay( 0 ); + QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); + connect( colorPopupMenu, SIGNAL( colorSelected( const QColor& ) ), this, SLOT( changeeBrushColor( const QColor& ) ) ); - brushColorPopupMenu->insertItem(brushColorPanel); - brushColorPopupMenu->insertSeparator(); +// QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); - QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this); - connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor())); - chooseBrushColorAction->addTo(brushColorPopupMenu); +// ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu); +// connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); - QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); - m_pBrushColorToolButton->setPopup(brushColorPopupMenu); - m_pBrushColorToolButton->setPopupDelay(0); +// brushColorPopupMenu->insertItem(brushColorPanel); +// brushColorPopupMenu->insertSeparator(); + +// QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this); +// connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor())); +// chooseBrushColorAction->addTo(brushColorPopupMenu); + +// m_pBrushColorToolButton->setPopup(brushColorPopupMenu); +// m_pBrushColorToolButton->setPopupDelay(0); - brushColorPanel->buttonSelected(Qt::white); +// brushColorPanel->buttonSelected(Qt::white); // init pages QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); if (file.open(IO_ReadOnly)) { m_pDrawPadCanvas->load(&file); file.close(); } else { m_pDrawPadCanvas->initialPage(); } } DrawPad::~DrawPad() { QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); if (file.open(IO_WriteOnly)) { m_pDrawPadCanvas->save(&file); file.close(); } } void DrawPad::setPointTool() { if (m_pTool) { delete m_pTool; } m_pTool = new PointTool(this, m_pDrawPadCanvas); m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated())); m_pLineToolButton->setOn(true); m_pRectangleToolButton->setOn(false); m_pEllipseToolButton->setOn(false); m_pTextToolAction->setOn(false); m_pFillToolAction->setOn(false); m_pEraseToolAction->setOn(false); } void DrawPad::setLineTool() { if (m_pTool) { delete m_pTool; } m_pTool = new LineTool(this, m_pDrawPadCanvas); m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet()); QToolTip::add(m_pLineToolButton, m_pLineToolAction->text()); disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated())); m_pLineToolButton->setOn(true); m_pRectangleToolButton->setOn(false); m_pEllipseToolButton->setOn(false); m_pTextToolAction->setOn(false); m_pFillToolAction->setOn(false); @@ -425,126 +438,114 @@ void DrawPad::setTextTool() m_pEraseToolAction->setOn(false); } void DrawPad::setFillTool() { if (m_pTool) { delete m_pTool; } m_pTool = new FillTool(this, m_pDrawPadCanvas); m_pLineToolButton->setOn(false); m_pRectangleToolButton->setOn(false); m_pEllipseToolButton->setOn(false); m_pTextToolAction->setOn(false); m_pFillToolAction->setOn(true); m_pEraseToolAction->setOn(false); } void DrawPad::setEraseTool() { if (m_pTool) { delete m_pTool; } m_pTool = new EraseTool(this, m_pDrawPadCanvas); m_pLineToolButton->setOn(false); m_pRectangleToolButton->setOn(false); m_pEllipseToolButton->setOn(false); m_pTextToolAction->setOn(false); m_pFillToolAction->setOn(false); m_pEraseToolAction->setOn(true); } void DrawPad::changePenWidth(int value) { m_pen.setWidth(value); } void DrawPad::changePenColor(const QColor& color) { 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(const QColor& color) { 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()); m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); } void DrawPad::updateCaption() { uint pagePosition = m_pDrawPadCanvas->pagePosition(); uint pageCount = m_pDrawPadCanvas->pageCount(); setCaption(tr("DrawPad") + " - " + tr("Page") + " " + QString::number(pagePosition) + "/" + QString::number(pageCount)); } void DrawPad::importPage() { ImportDialog importDialog(this); importDialog.showMaximized(); if (importDialog.exec() == QDialog::Accepted) { const DocLnk* docLnk = importDialog.selected(); if (docLnk) { m_pDrawPadCanvas->importPage(docLnk->file()); delete docLnk; } } } void DrawPad::exportPage() { ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); exportDialog.showMaximized(); if (exportDialog.exec() == QDialog::Accepted) { m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), exportDialog.selectedName(), exportDialog.selectedFormat()); } } diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index e4fd831..0dcd5c9 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h @@ -1,97 +1,95 @@ /*************************************************************************** * * * DrawPad - a drawing program for Opie Environment * * * * (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. * * * ***************************************************************************/ #ifndef DRAWPAD_H #define DRAWPAD_H #include <qmainwindow.h> #include <qpen.h> class DrawPadCanvas; class Tool; class QAction; class QColor; class QToolButton; class QWidgetStack; class DrawPad : public QMainWindow -{ +{ Q_OBJECT public: DrawPad(QWidget* parent = 0, const char* name = 0); ~DrawPad(); Tool* tool() { return m_pTool; } QPen pen() { return m_pen; } QBrush brush() { return m_brush; } private slots: void setPointTool(); void setLineTool(); void setRectangleTool(); void setFilledRectangleTool(); void setEllipseTool(); void setFilledEllipseTool(); void setTextTool(); void setFillTool(); void setEraseTool(); void changePenWidth(int value); void changePenColor(const QColor& color); void changeBrushColor(const QColor& color); - void choosePenColor(); - void chooseBrushColor(); void updateUndoRedoToolButtons(); void updateNavigationToolButtons(); void updateCaption(); void importPage(); void exportPage(); private: DrawPadCanvas* m_pDrawPadCanvas; Tool* m_pTool; QPen m_pen; QBrush m_brush; QAction* m_pUndoAction; QAction* m_pRedoAction; QAction* m_pFirstPageAction; QAction* m_pPreviousPageAction; QAction* m_pNextPageAction; QAction* m_pLastPageAction; QAction* m_pPointToolAction; QAction* m_pLineToolAction; QAction* m_pRectangleToolAction; QAction* m_pFilledRectangleToolAction; QAction* m_pEllipseToolAction; QAction* m_pFilledEllipseToolAction; QAction* m_pTextToolAction; QAction* m_pFillToolAction; QAction* m_pEraseToolAction; QToolButton* m_pLineToolButton; QToolButton* m_pRectangleToolButton; QToolButton* m_pEllipseToolButton; QToolButton* m_pPenColorToolButton; QToolButton* m_pBrushColorToolButton; }; #endif // DRAWPAD_H diff --git a/noncore/graphics/drawpad/drawpad.pro b/noncore/graphics/drawpad/drawpad.pro index 00eb00d..3b120c9 100644 --- a/noncore/graphics/drawpad/drawpad.pro +++ b/noncore/graphics/drawpad/drawpad.pro @@ -1,58 +1,54 @@ TEMPLATE = app CONFIG = qt warn_on release -HEADERS = colordialog.h \ - colorpanel.h \ - drawpad.h \ +HEADERS = drawpad.h \ drawpadcanvas.h \ ellipsetool.h \ erasetool.h \ exportdialog.h \ filltool.h \ filledellipsetool.h \ filledrectangletool.h \ importdialog.h \ linetool.h \ newpagedialog.h \ pointtool.h \ rectangletool.h \ shapetool.h \ texttool.h \ tool.h -SOURCES = colordialog.cpp \ - colorpanel.cpp \ - drawpad.cpp \ +SOURCES = drawpad.cpp \ drawpadcanvas.cpp \ ellipsetool.cpp \ erasetool.cpp \ exportdialog.cpp \ filltool.cpp \ filledellipsetool.cpp \ filledrectangletool.cpp \ importdialog.cpp \ linetool.cpp \ main.cpp \ newpagedialog.cpp \ pointtool.cpp \ rectangletool.cpp \ shapetool.cpp \ texttool.cpp \ tool.cpp INCLUDEPATH += $(OPIEDIR)/include \ $(QTDIR)/src/3rdparty/zlib DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe +LIBS += -lqpe -lopie DESTDIR = $(OPIEDIR)/bin TARGET = drawpad TRANSLATIONS = ../../i18n/pt_BR/drawpad.ts TRANSLATIONS += ../../i18n/de/drawpad.ts TRANSLATIONS += ../../i18n/en/drawpad.ts TRANSLATIONS += ../../i18n/hu/drawpad.ts TRANSLATIONS += ../../i18n/pl/drawpad.ts TRANSLATIONS += ../../i18n/ja/drawpad.ts TRANSLATIONS += ../../i18n/sl/drawpad.ts TRANSLATIONS += ../../i18n/fr/drawpad.ts TRANSLATIONS += ../../i18n/ko/drawpad.ts TRANSLATIONS += ../../i18n/no/drawpad.ts TRANSLATIONS += ../../i18n/zh_CN/drawpad.ts TRANSLATIONS += ../../i18n/zh_TW/drawpad.ts |