33 files changed, 1654 insertions, 190 deletions
diff --git a/noncore/graphics/drawpad/colorpanel.cpp b/noncore/graphics/drawpad/colorpanel.cpp index 1db0d7b..9327012 100644 --- a/noncore/graphics/drawpad/colorpanel.cpp +++ b/noncore/graphics/drawpad/colorpanel.cpp @@ -1,134 +1,120 @@ /*************************************************************************** * * * 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 "colorpanel.h" #include <qlayout.h> #include <qpainter.h> ColorPanelButton::ColorPanelButton(const QColor& color, QWidget* parent, const char* name) : QFrame(parent, name) { m_color = color; setFixedSize(16, 16); - setActive(false); + setFrameStyle(NoFrame); } ColorPanelButton::~ColorPanelButton() { } -void ColorPanelButton::setActive(bool active) -{ - m_active = active; - - if (m_active) { - setFrameStyle(Panel | Sunken); - } else { - setFrameStyle(NoFrame); - } -} - void ColorPanelButton::enterEvent(QEvent* e) { Q_UNUSED(e) - if (!m_active) { setFrameStyle(Panel | Sunken); } -} void ColorPanelButton::leaveEvent(QEvent* e) { Q_UNUSED(e) - if (!m_active) { setFrameStyle(NoFrame); } -} void ColorPanelButton::paintEvent(QPaintEvent* e) { QFrame::paintEvent(e); QPainter painter; painter.begin(this); painter.fillRect(2, 2, 12, 12, m_color); painter.setPen(Qt::black); painter.drawRect(2, 2, 12, 12); painter.end(); } void ColorPanelButton::mouseReleaseEvent(QMouseEvent* e) { Q_UNUSED(e) emit selected(m_color); } ColorPanel::ColorPanel(QWidget* parent, const char* name) : QWidget(parent, name) { m_pGridLayout = new QGridLayout(this, 5, 6); addColor(QColor(255, 255, 255), 0, 1); addColor(QColor(192, 192, 192), 0, 2); addColor(QColor(128, 128, 128), 0, 3); addColor(QColor(64, 64, 64), 0, 4); addColor(QColor(0, 0, 0), 0, 5); addColor(QColor(255, 0, 0), 1, 0); addColor(QColor(255, 128, 0), 1, 1); addColor(QColor(255, 255, 0), 1, 2); addColor(QColor(128, 255, 0), 1, 3); addColor(QColor(0, 255, 0), 1, 4); addColor(QColor(0, 255, 128), 1, 5); addColor(QColor(128, 0, 0), 2, 0); addColor(QColor(128, 64, 0), 2, 1); addColor(QColor(128, 128, 0), 2, 2); addColor(QColor(64, 128, 0), 2, 3); addColor(QColor(0, 128, 0), 2, 4); addColor(QColor(0, 128, 64), 2, 5); addColor(QColor(0, 255, 255), 3, 0); addColor(QColor(0, 128, 255), 3, 1); addColor(QColor(0, 0, 255), 3, 2); addColor(QColor(128, 0, 255), 3, 3); addColor(QColor(255, 0, 255), 3, 4); addColor(QColor(255, 0, 128), 3, 5); addColor(QColor(0, 128, 128), 4, 0); addColor(QColor(0, 64, 128), 4, 1); addColor(QColor(0, 0, 128), 4, 2); addColor(QColor(64, 0, 128), 4, 3); addColor(QColor(128, 0, 128), 4, 4); addColor(QColor(128, 0, 64), 4, 5); } ColorPanel::~ColorPanel() { } void ColorPanel::addColor(const QColor& color, int row, int col) { ColorPanelButton* panelButton = new ColorPanelButton(color, this); connect(panelButton, SIGNAL(selected(const QColor&)), this, SLOT(buttonSelected(const QColor&))); + m_pGridLayout->addWidget(panelButton, row, col); } void ColorPanel::buttonSelected(const QColor& color) { emit colorSelected(color); } diff --git a/noncore/graphics/drawpad/colorpanel.h b/noncore/graphics/drawpad/colorpanel.h index 05364c1..4664879 100644 --- a/noncore/graphics/drawpad/colorpanel.h +++ b/noncore/graphics/drawpad/colorpanel.h @@ -1,65 +1,62 @@ /*************************************************************************** * * * 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 COLORPANEL_H #define COLORPANEL_H #include <qframe.h> #include <qwidget.h> class QGridLayout; class ColorPanelButton : public QFrame { Q_OBJECT public: ColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0); ~ColorPanelButton(); - void setActive(bool active); - void enterEvent(QEvent* e); void leaveEvent(QEvent* e); void paintEvent(QPaintEvent* e); void mouseReleaseEvent(QMouseEvent* e); signals: void selected(const QColor&); private: QColor m_color; - bool m_active; }; class ColorPanel : public QWidget { Q_OBJECT public: ColorPanel(QWidget* parent = 0, const char* name = 0); ~ColorPanel(); void addColor(const QColor& color, int row, int col); public slots: void buttonSelected(const QColor& color); signals: void colorSelected(const QColor&); private: QGridLayout* m_pGridLayout; }; #endif // COLORPANEL_H diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index e94187f..5c7e541 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp @@ -1,390 +1,503 @@ /*************************************************************************** * * * 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 "drawpadcanvas.h" -#include "ellipsedrawmode.h" -#include "erasedrawmode.h" -#include "filldrawmode.h" -#include "linedrawmode.h" -#include "pointdrawmode.h" -#include "rectangledrawmode.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 <qpe/applnk.h> #include <qpe/global.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/resource.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* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); - connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll())); - clearAllAction->addTo(toolsPopupMenu); + 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* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this); - setOptionsAction->addTo(toolsPopupMenu); + 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); // init navigation toolbar QPEToolBar* navigationToolBar = new QPEToolBar(this); m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); m_pUndoAction->addTo(navigationToolBar); m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); m_pRedoAction->addTo(navigationToolBar); m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); m_pFirstPageAction->addTo(navigationToolBar); m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); m_pPreviousPageAction->addTo(navigationToolBar); m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); m_pNextPageAction->addTo(navigationToolBar); m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); m_pLastPageAction->addTo(navigationToolBar); // init draw mode toolbar QPEToolBar* drawModeToolBar = new QPEToolBar(this); - m_pPointDrawModeAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this); - m_pPointDrawModeAction->setToggleAction(true); - connect(m_pPointDrawModeAction, SIGNAL(activated()), this, SLOT(setPointDrawMode())); - m_pPointDrawModeAction->addTo(drawModeToolBar); + m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this); + m_pPointToolAction->setToggleAction(true); + connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool())); + m_pPointToolAction->addTo(drawModeToolBar); + + m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this); + m_pLineToolAction->setToggleAction(true); + connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool())); + m_pLineToolAction->addTo(drawModeToolBar); + + m_pRectangleToolButton = new QToolButton(drawModeToolBar); + m_pRectangleToolButton->setToggleButton(true); + + QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton); + + m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), "", 0, this); + connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool())); + m_pRectangleToolAction->addTo(rectanglePopupMenu); - m_pLineDrawModeAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this); - m_pLineDrawModeAction->setToggleAction(true); - connect(m_pLineDrawModeAction, SIGNAL(activated()), this, SLOT(setLineDrawMode())); - m_pLineDrawModeAction->addTo(drawModeToolBar); + 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_pRectangleDrawModeAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), QString::null, 0, this); - m_pRectangleDrawModeAction->setToggleAction(true); - connect(m_pRectangleDrawModeAction, SIGNAL(activated()), this, SLOT(setRectangleDrawMode())); - m_pRectangleDrawModeAction->addTo(drawModeToolBar); + m_pRectangleToolButton->setPopup(rectanglePopupMenu); - m_pEllipseDrawModeAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), QString::null, 0, this); - m_pEllipseDrawModeAction->setToggleAction(true); - connect(m_pEllipseDrawModeAction, SIGNAL(activated()), this, SLOT(setEllipseDrawMode())); - m_pEllipseDrawModeAction->addTo(drawModeToolBar); + m_pEllipseToolButton = new QToolButton(drawModeToolBar); + m_pEllipseToolButton->setToggleButton(true); - m_pFillDrawModeAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); - m_pFillDrawModeAction->setToggleAction(true); - connect(m_pFillDrawModeAction, SIGNAL(activated()), this, SLOT(setFillDrawMode())); - m_pFillDrawModeAction->addTo(drawModeToolBar); + QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton); - m_pEraseDrawModeAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); - m_pEraseDrawModeAction->setToggleAction(true); - connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode())); - m_pEraseDrawModeAction->addTo(drawModeToolBar); + 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_pDrawMode = 0; - setPointDrawMode(); + 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_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); ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); - penColorPopupMenu->insertItem(penColorPanel); + penColorPopupMenu->insertItem(penColorPanel); 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); + 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&))); - brushColorPopupMenu->insertItem(brushColorPanel); + 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); QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); m_pBrushColorToolButton->setPopup(brushColorPopupMenu); m_pBrushColorToolButton->setPopupDelay(0); - brushColorPopupMenu->activateItemAt(1); + 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::setPointDrawMode() +void DrawPad::setPointTool() +{ + if (m_pTool) { + delete m_pTool; + } + + m_pTool = new PointTool(this, m_pDrawPadCanvas); + + m_pPointToolAction->setOn(true); + m_pLineToolAction->setOn(false); + m_pRectangleToolButton->setOn(false); + m_pEllipseToolButton->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_pPointToolAction->setOn(false); + m_pLineToolAction->setOn(true); + m_pRectangleToolButton->setOn(false); + m_pEllipseToolButton->setOn(false); + m_pFillToolAction->setOn(false); + m_pEraseToolAction->setOn(false); +} + +void DrawPad::setRectangleTool() { - if (m_pDrawMode) { - delete m_pDrawMode; + if (m_pTool) { + delete m_pTool; } - m_pDrawMode = new PointDrawMode(this, m_pDrawPadCanvas); + m_pTool = new RectangleTool(this, m_pDrawPadCanvas); - m_pPointDrawModeAction->setOn(true); - m_pLineDrawModeAction->setOn(false); - m_pRectangleDrawModeAction->setOn(false); - m_pEllipseDrawModeAction->setOn(false); - m_pFillDrawModeAction->setOn(false); - m_pEraseDrawModeAction->setOn(false); + m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet()); + QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text()); + + disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); + connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated())); + + m_pPointToolAction->setOn(false); + m_pLineToolAction->setOn(false); + m_pRectangleToolButton->setOn(true); + m_pEllipseToolButton->setOn(false); + m_pFillToolAction->setOn(false); + m_pEraseToolAction->setOn(false); } -void DrawPad::setLineDrawMode() +void DrawPad::setFilledRectangleTool() { - if (m_pDrawMode) { - delete m_pDrawMode; + if (m_pTool) { + delete m_pTool; } - m_pDrawMode = new LineDrawMode(this, m_pDrawPadCanvas); + m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas); + + m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet()); + QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text()); - m_pPointDrawModeAction->setOn(false); - m_pLineDrawModeAction->setOn(true); - m_pRectangleDrawModeAction->setOn(false); - m_pEllipseDrawModeAction->setOn(false); - m_pFillDrawModeAction->setOn(false); - m_pEraseDrawModeAction->setOn(false); + disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); + connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated())); + + m_pPointToolAction->setOn(false); + m_pLineToolAction->setOn(false); + m_pRectangleToolButton->setOn(true); + m_pEllipseToolButton->setOn(false); + m_pFillToolAction->setOn(false); + m_pEraseToolAction->setOn(false); } -void DrawPad::setRectangleDrawMode() +void DrawPad::setEllipseTool() { - if (m_pDrawMode) { - delete m_pDrawMode; + if (m_pTool) { + delete m_pTool; } - m_pDrawMode = new RectangleDrawMode(this, m_pDrawPadCanvas); + m_pTool = new EllipseTool(this, m_pDrawPadCanvas); + + m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet()); + QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text()); + + disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); + connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated())); - m_pPointDrawModeAction->setOn(false); - m_pLineDrawModeAction->setOn(false); - m_pRectangleDrawModeAction->setOn(true); - m_pEllipseDrawModeAction->setOn(false); - m_pFillDrawModeAction->setOn(false); - m_pEraseDrawModeAction->setOn(false); + m_pPointToolAction->setOn(false); + m_pLineToolAction->setOn(false); + m_pRectangleToolButton->setOn(false); + m_pEllipseToolButton->setOn(true); + m_pFillToolAction->setOn(false); + m_pEraseToolAction->setOn(false); } -void DrawPad::setEllipseDrawMode() +void DrawPad::setFilledEllipseTool() { - if (m_pDrawMode) { - delete m_pDrawMode; + if (m_pTool) { + delete m_pTool; } - m_pDrawMode = new EllipseDrawMode(this, m_pDrawPadCanvas); + m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas); - m_pPointDrawModeAction->setOn(false); - m_pLineDrawModeAction->setOn(false); - m_pRectangleDrawModeAction->setOn(false); - m_pEllipseDrawModeAction->setOn(true); - m_pFillDrawModeAction->setOn(false); - m_pEraseDrawModeAction->setOn(false); + m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet()); + QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text()); + + disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); + connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated())); + + m_pPointToolAction->setOn(false); + m_pLineToolAction->setOn(false); + m_pRectangleToolButton->setOn(false); + m_pEllipseToolButton->setOn(true); + m_pFillToolAction->setOn(false); + m_pEraseToolAction->setOn(false); } -void DrawPad::setFillDrawMode() +void DrawPad::setFillTool() { - if (m_pDrawMode) { - delete m_pDrawMode; + if (m_pTool) { + delete m_pTool; } - m_pDrawMode = new FillDrawMode(this, m_pDrawPadCanvas); + m_pTool = new FillTool(this, m_pDrawPadCanvas); - m_pPointDrawModeAction->setOn(false); - m_pLineDrawModeAction->setOn(false); - m_pRectangleDrawModeAction->setOn(false); - m_pEllipseDrawModeAction->setOn(false); - m_pFillDrawModeAction->setOn(true); - m_pEraseDrawModeAction->setOn(false); + m_pPointToolAction->setOn(false); + m_pLineToolAction->setOn(false); + m_pRectangleToolButton->setOn(false); + m_pEllipseToolButton->setOn(false); + m_pFillToolAction->setOn(true); + m_pEraseToolAction->setOn(false); } -void DrawPad::setEraseDrawMode() +void DrawPad::setEraseTool() { - if (m_pDrawMode) { - delete m_pDrawMode; + if (m_pTool) { + delete m_pTool; } - m_pDrawMode = new EraseDrawMode(this, m_pDrawPadCanvas); + m_pTool = new EraseTool(this, m_pDrawPadCanvas); - m_pPointDrawModeAction->setOn(false); - m_pLineDrawModeAction->setOn(false); - m_pRectangleDrawModeAction->setOn(false); - m_pEllipseDrawModeAction->setOn(false); - m_pFillDrawModeAction->setOn(false); - m_pEraseDrawModeAction->setOn(true); + m_pPointToolAction->setOn(false); + m_pLineToolAction->setOn(false); + m_pRectangleToolButton->setOn(false); + m_pEllipseToolButton->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) { + m_pDrawPadCanvas->importPage(importDialog.selected()->file()); + } +} + +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 c49a559..fbe67b8 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h @@ -1,85 +1,94 @@ /*************************************************************************** * * * 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 DrawMode; +class Tool; class DrawPadCanvas; class QAction; class QColor; class QToolButton; class QWidgetStack; class DrawPad : public QMainWindow { Q_OBJECT public: DrawPad(QWidget* parent = 0, const char* name = 0); ~DrawPad(); - DrawMode* drawMode() { return m_pDrawMode; } + Tool* tool() { return m_pTool; } QPen pen() { return m_pen; } QBrush brush() { return m_brush; } private slots: - void setPointDrawMode(); - void setLineDrawMode(); - void setRectangleDrawMode(); - void setEllipseDrawMode(); - void setFillDrawMode(); - void setEraseDrawMode(); + void setPointTool(); + void setLineTool(); + void setRectangleTool(); + void setFilledRectangleTool(); + void setEllipseTool(); + void setFilledEllipseTool(); + 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; - DrawMode* m_pDrawMode; + 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_pPointDrawModeAction; - QAction* m_pLineDrawModeAction; - QAction* m_pRectangleDrawModeAction; - QAction* m_pEllipseDrawModeAction; - QAction* m_pFillDrawModeAction; - QAction* m_pEraseDrawModeAction; - + QAction* m_pPointToolAction; + QAction* m_pLineToolAction; + QAction* m_pRectangleToolAction; + QAction* m_pFilledRectangleToolAction; + QAction* m_pEllipseToolAction; + QAction* m_pFilledEllipseToolAction; + QAction* m_pFillToolAction; + QAction* m_pEraseToolAction; + + 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 b0eb009..5f14515 100644 --- a/noncore/graphics/drawpad/drawpad.pro +++ b/noncore/graphics/drawpad/drawpad.pro @@ -1,35 +1,43 @@ TEMPLATE = app CONFIG = qt warn_on release HEADERS = colordialog.h \ colorpanel.h \ - drawmode.h \ drawpad.h \ drawpadcanvas.h \ - ellipsedrawmode.h \ - erasedrawmode.h \ - filldrawmode.h \ - linedrawmode.h \ + ellipsetool.h \ + erasetool.h \ + exportdialog.h \ + filltool.h \ + filledellipsetool.h \ + filledrectangletool.h \ + importdialog.h \ + linetool.h \ newpagedialog.h \ - pointdrawmode.h \ - rectangledrawmode.h \ - shapedrawmode.h + pointtool.h \ + rectangletool.h \ + shapetool.h \ + tool.h SOURCES = colordialog.cpp \ colorpanel.cpp \ - drawmode.cpp \ drawpad.cpp \ drawpadcanvas.cpp \ - ellipsedrawmode.cpp \ - erasedrawmode.cpp \ - filldrawmode.cpp \ - linedrawmode.cpp \ + ellipsetool.cpp \ + erasetool.cpp \ + exportdialog.cpp \ + filltool.cpp \ + filledellipsetool.cpp \ + filledrectangletool.cpp \ + importdialog.cpp \ + linetool.cpp \ main.cpp \ newpagedialog.cpp \ - pointdrawmode.cpp \ - rectangledrawmode.cpp \ - shapedrawmode.cpp + pointtool.cpp \ + rectangletool.cpp \ + shapetool.cpp \ + tool.cpp INCLUDEPATH += $(OPIEDIR)/include \ $(QTDIR)/src/3rdparty/zlib DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe DESTDIR = $(OPIEDIR)/bin TARGET = drawpad diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 40c27b5..8818c03 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp @@ -1,117 +1,122 @@ /*************************************************************************** * * * 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 "drawpadcanvas.h" -#include "drawmode.h" #include "drawpad.h" #include "newpagedialog.h" +#include "tool.h" + +#include <qpe/applnk.h> +#include <qpe/filemanager.h> +#include <qpe/mimetype.h> #include <qbuffer.h> #include <qimage.h> +#include <qmessagebox.h> #include <qpainter.h> #include <qpixmap.h> #include <qtextcodec.h> #include <qtextstream.h> #include <qxml.h> #include <zlib.h> class DrawPadCanvasXmlHandler: public QXmlDefaultHandler { public: DrawPadCanvasXmlHandler(); ~DrawPadCanvasXmlHandler(); QList<QPixmap> pixmaps(); bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts); bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName); bool characters(const QString& ch); private: enum State { Unknown, InData }; State m_state; ulong m_dataLenght; QList<QPixmap> m_pixmaps; }; DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() { m_state = Unknown; } DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() { } QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() { return m_pixmaps; } bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) { Q_CONST_UNUSED(namespaceURI) Q_CONST_UNUSED(localName) if (qName.compare("data") == 0) { m_state = InData; m_dataLenght = atts.value("length").toULong(); } return true; } bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, const QString& qName) { Q_CONST_UNUSED(namespaceURI) Q_CONST_UNUSED(localName) if (qName.compare("data") == 0) { m_state = Unknown; } return true; } bool DrawPadCanvasXmlHandler::characters(const QString& ch) { if (m_state == InData) { QByteArray byteArray(ch.length() / 2); for (int i = 0; i < (int)ch.length() / 2; i++) { char h = ch[2 * i].latin1(); char l = ch[2 * i + 1].latin1(); uchar r = 0; if (h <= '9') { r += h - '0'; } else { r += h - 'a' + 10; } r = r << 4; if (l <= '9') { r += l - '0'; } else { r += l - 'a' + 10; @@ -146,301 +151,376 @@ DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name m_pageBackups.setAutoDelete(true); } DrawPadCanvas::~DrawPadCanvas() { } void DrawPadCanvas::load(QIODevice* ioDevice) { QTextStream textStream(ioDevice); textStream.setCodec(QTextCodec::codecForName("UTF-8")); QXmlInputSource xmlInputSource(textStream); QXmlSimpleReader xmlSimpleReader; DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); xmlSimpleReader.parse(xmlInputSource); m_pages = drawPadCanvasXmlHandler.pixmaps(); if (m_pages.isEmpty()) { m_pages.append(new QPixmap(contentsRect().size())); m_pages.current()->fill(Qt::white); } m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::initialPage() { m_pages.append(new QPixmap(234, 233)); m_pages.current()->fill(Qt::white); m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::save(QIODevice* ioDevice) { QTextStream textStream(ioDevice); textStream.setCodec(QTextCodec::codecForName("UTF-8")); textStream << "<drawpad>" << endl; textStream << " <images>" << endl; QListIterator<QPixmap> bufferIterator(m_pages); for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { textStream << " <image>" << endl; QImage image = bufferIterator.current()->convertToImage(); QByteArray byteArray; QBuffer buffer(byteArray); QImageIO imageIO(&buffer, "XPM"); buffer.open(IO_WriteOnly); imageIO.setImage(image); imageIO.write(); buffer.close(); ulong size = byteArray.size() * 2; QByteArray byteArrayZipped(size); ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); textStream << " <data length=\"" << byteArray.size() << "\">"; static const char hexchars[] = "0123456789abcdef"; for (int i = 0; i < (int)size; i++ ) { uchar s = (uchar)byteArrayZipped[i]; textStream << hexchars[s >> 4]; textStream << hexchars[s & 0x0f]; } textStream << "</data>" << endl; textStream << " </image>" << endl; } textStream << " </images>" << endl; textStream << "</drawpad>"; } +void DrawPadCanvas::importPage(const QString& fileName) +{ + QPixmap* importedPixmap = new QPixmap(); + + importedPixmap->load(fileName); + m_pages.insert(m_pages.at() + 1, importedPixmap); + + m_pageBackups.clear(); + m_pageBackups.append(new QPixmap(*(m_pages.current()))); + + resizeContents(m_pages.current()->width(), m_pages.current()->height()); + viewport()->update(); + + emit pagesChanged(); + emit pageBackupsChanged(); +} + +void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) +{ + if (fromPage == toPage) { + DocLnk docLnk; + MimeType mimeType(format); + + docLnk.setName(name); + docLnk.setType(mimeType.id()); + + FileManager fileManager; + QIODevice* ioDevice = fileManager.saveFile(docLnk); + QImageIO imageIO(ioDevice, format); + + QImage image = m_pages.current()->convertToImage(); + imageIO.setImage(image); + imageIO.write(); + delete ioDevice; + } else { + for (uint i = fromPage; i <= toPage; i++) { + DocLnk docLnk; + MimeType mimeType(format); + + docLnk.setName(name + QString::number(i)); + docLnk.setType(mimeType.id()); + + FileManager fileManager; + QIODevice* ioDevice = fileManager.saveFile(docLnk); + QImageIO imageIO(ioDevice, format); + + QImage image = m_pages.at(i - 1)->convertToImage(); + imageIO.setImage(image); + imageIO.write(); + delete ioDevice; + } + } +} + QPixmap* DrawPadCanvas::currentPage() { return m_pages.current(); } uint DrawPadCanvas::pagePosition() { return (m_pages.at() + 1); } uint DrawPadCanvas::pageCount() { return m_pages.count(); } -void DrawPadCanvas::clearAll() +void DrawPadCanvas::deleteAll() { + QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), + QMessageBox::Information, QMessageBox::Yes, + QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, + QMessageBox::NoButton, this); + + if (messageBox.exec() == QMessageBox::Yes) { m_pages.clear(); m_pages.append(new QPixmap(contentsRect().size())); m_pages.current()->fill(Qt::white); m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } +} void DrawPadCanvas::newPage() { QRect rect = contentsRect(); - NewPageDialog newPageDialog(this); - newPageDialog.setWidth(rect.width()); - newPageDialog.setHeight(rect.height()); + NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), + m_pDrawPad->brush().color(), this); if (newPageDialog.exec() == QDialog::Accepted) { - m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.width(), newPageDialog.height())); - m_pages.current()->fill(Qt::white); + m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.selectedWidth(), + newPageDialog.selectedHeight())); + m_pages.current()->fill(newPageDialog.selectedColor()); m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } } void DrawPadCanvas::clearPage() { + QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), + QMessageBox::Information, QMessageBox::Yes, + QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, + QMessageBox::NoButton, this); + + if (messageBox.exec() == QMessageBox::Yes) { m_pages.current()->fill(Qt::white); viewport()->update(); } +} void DrawPadCanvas::deletePage() { + QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), + QMessageBox::Information, QMessageBox::Yes, + QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, + QMessageBox::NoButton, this); + + if (messageBox.exec() == QMessageBox::Yes) { m_pages.remove(m_pages.current()); if (m_pages.isEmpty()) { m_pages.append(new QPixmap(contentsRect().size())); m_pages.current()->fill(Qt::white); } m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } +} bool DrawPadCanvas::undoEnabled() { return (m_pageBackups.current() != m_pageBackups.getFirst()); } bool DrawPadCanvas::redoEnabled() { return (m_pageBackups.current() != m_pageBackups.getLast()); } bool DrawPadCanvas::goPreviousPageEnabled() { return (m_pages.current() != m_pages.getFirst()); } bool DrawPadCanvas::goNextPageEnabled() { return (m_pages.current() != m_pages.getLast()); } void DrawPadCanvas::undo() { *(m_pages.current()) = *(m_pageBackups.prev()); viewport()->update(); emit pageBackupsChanged(); } void DrawPadCanvas::redo() { *(m_pages.current()) = *(m_pageBackups.next()); viewport()->update(); emit pageBackupsChanged(); } void DrawPadCanvas::goFirstPage() { m_pages.first(); m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::goPreviousPage() { m_pages.prev(); m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::goNextPage() { m_pages.next(); m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::goLastPage() { m_pages.last(); m_pageBackups.clear(); m_pageBackups.append(new QPixmap(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) { - m_pDrawPad->drawMode()->mousePressEvent(e); + m_pDrawPad->tool()->mousePressEvent(e); } void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) { - m_pDrawPad->drawMode()->mouseReleaseEvent(e); + m_pDrawPad->tool()->mouseReleaseEvent(e); QPixmap* currentBackup = m_pageBackups.current(); while (m_pageBackups.last() != currentBackup) { m_pageBackups.removeLast(); } while (m_pageBackups.count() >= (5 + 1)) { m_pageBackups.removeFirst(); } m_pageBackups.append(new QPixmap(*(m_pages.current()))); emit pageBackupsChanged(); } void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) { - m_pDrawPad->drawMode()->mouseMoveEvent(e); + m_pDrawPad->tool()->mouseMoveEvent(e); } void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) { QRect clipRect(cx, cy, cw, ch); p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect); } diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index 4836a3f..90dd951 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h @@ -1,77 +1,80 @@ /*************************************************************************** * * * 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 DRAWPADCANVAS_H #define DRAWPADCANVAS_H #include <qscrollview.h> #include <qlist.h> #include <qpointarray.h> class DrawPad; class QPixmap; class DrawPadCanvas : public QScrollView { Q_OBJECT public: DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); ~DrawPadCanvas(); void load(QIODevice* ioDevice); void initialPage(); void save(QIODevice* ioDevice); + void importPage(const QString& fileName); + void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); + bool undoEnabled(); bool redoEnabled(); bool goPreviousPageEnabled(); bool goNextPageEnabled(); QPixmap* currentPage(); uint pagePosition(); uint pageCount(); public slots: - void clearAll(); + void deleteAll(); void newPage(); void clearPage(); void deletePage(); void undo(); void redo(); void goFirstPage(); void goPreviousPage(); void goNextPage(); void goLastPage(); signals: void pagesChanged(); void pageBackupsChanged(); protected: void contentsMousePressEvent(QMouseEvent* e); void contentsMouseReleaseEvent(QMouseEvent* e); void contentsMouseMoveEvent(QMouseEvent* e); void drawContents(QPainter* p, int cx, int cy, int cw, int ch); private: DrawPad* m_pDrawPad; QList<QPixmap> m_pages; QList<QPixmap> m_pageBackups; }; #endif // DRAWPADCANVAS_H diff --git a/noncore/graphics/drawpad/ellipsetool.cpp b/noncore/graphics/drawpad/ellipsetool.cpp new file mode 100644 index 0000000..c3badc3 --- a/dev/null +++ b/noncore/graphics/drawpad/ellipsetool.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * * + * 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 "ellipsetool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +#include <qpainter.h> +#include <qpixmap.h> + +EllipseTool::EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : ShapeTool(drawPad, drawPadCanvas) +{ +} + +EllipseTool::~EllipseTool() +{ +} + +void EllipseTool::drawFinalShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); + p.setPen(m_pDrawPad->pen()); + p.setRasterOp(Qt::CopyROP); + p.drawEllipse(QRect(m_polyline[2], m_polyline[0])); +} + +void EllipseTool::drawTemporaryShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[1])); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); +} diff --git a/noncore/graphics/drawpad/ellipsetool.h b/noncore/graphics/drawpad/ellipsetool.h new file mode 100644 index 0000000..1f48b39 --- a/dev/null +++ b/noncore/graphics/drawpad/ellipsetool.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * * + * 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 ELLIPSETOOL_H +#define ELLIPSETOOL_H + +#include "shapetool.h" + +class EllipseTool : public ShapeTool +{ +public: + EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~EllipseTool(); + +protected: + void drawFinalShape(QPainter& p); + void drawTemporaryShape(QPainter& p); +}; + +#endif // ELLIPSETOOL_H diff --git a/noncore/graphics/drawpad/erasetool.cpp b/noncore/graphics/drawpad/erasetool.cpp new file mode 100644 index 0000000..d37c901 --- a/dev/null +++ b/noncore/graphics/drawpad/erasetool.cpp @@ -0,0 +1,74 @@ +/*************************************************************************** + * * + * 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 "erasetool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +#include <qpainter.h> +#include <qpixmap.h> + +EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : Tool(drawPad, drawPadCanvas) +{ + m_mousePressed = false; + m_polyline.resize(3); +} + +EraseTool::~EraseTool() +{ +} + +void EraseTool::mousePressEvent(QMouseEvent* e) +{ + m_mousePressed = true; + m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); +} + +void EraseTool::mouseReleaseEvent(QMouseEvent* e) +{ + Q_UNUSED(e) + + m_mousePressed = false; +} + +void EraseTool::mouseMoveEvent(QMouseEvent* e) +{ + if (m_mousePressed) { + QPainter painter; + QPen pen(Qt::white, m_pDrawPad->pen().width()); + painter.begin(m_pDrawPadCanvas->currentPage()); + painter.setPen(pen); + m_polyline[2] = m_polyline[1]; + m_polyline[1] = m_polyline[0]; + m_polyline[0] = e->pos(); + painter.drawPolyline(m_polyline); + painter.end(); + + QRect r = m_polyline.boundingRect(); + r = r.normalize(); + r.setLeft(r.left() - m_pDrawPad->pen().width()); + r.setTop(r.top() - m_pDrawPad->pen().width()); + r.setRight(r.right() + m_pDrawPad->pen().width()); + r.setBottom(r.bottom() + m_pDrawPad->pen().width()); + + QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), + m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); + + bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), + m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + + m_pDrawPadCanvas->viewport()->update(viewportRect); + } +} diff --git a/noncore/graphics/drawpad/erasetool.h b/noncore/graphics/drawpad/erasetool.h new file mode 100644 index 0000000..3871404 --- a/dev/null +++ b/noncore/graphics/drawpad/erasetool.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * * + * 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 ERASETOOL_H +#define ERASEPOINTTOOL_H + +#include "tool.h" + +#include <qpointarray.h> + +class EraseTool : public Tool +{ +public: + EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~EraseTool(); + + void mousePressEvent(QMouseEvent* e); + void mouseReleaseEvent(QMouseEvent* e); + void mouseMoveEvent(QMouseEvent* e); + +private: + bool m_mousePressed; + QPointArray m_polyline; +}; + +#endif // ERASETOOL_H diff --git a/noncore/graphics/drawpad/exportdialog.cpp b/noncore/graphics/drawpad/exportdialog.cpp new file mode 100644 index 0000000..0a980fc --- a/dev/null +++ b/noncore/graphics/drawpad/exportdialog.cpp @@ -0,0 +1,173 @@ +/*************************************************************************** + * * + * 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 "exportdialog.h" + +#include <qpe/fileselector.h> + +#include <qbuttongroup.h> +#include <qcombobox.h> +#include <qgroupbox.h> +#include <qimage.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qradiobutton.h> +#include <qspinbox.h> + +#include <stdlib.h> + +ExportDialog::ExportDialog(uint pageAt, uint pageCount, QWidget* parent, const char* name) + : QDialog(parent, name, true) +{ + setCaption(tr("Export")); + + m_pageAt = pageAt; + m_pageCount = pageCount; + + QButtonGroup* selectionButtonGroup = new QButtonGroup(0, Qt::Vertical, tr("Page Selection"), this); + connect(selectionButtonGroup, SIGNAL(pressed(int)), this, SLOT(selectionChanged(int))); + + QRadioButton* selectAllRadioButton = new QRadioButton(tr("All"), selectionButtonGroup); + QRadioButton* selectCurrentRadioButton = new QRadioButton(tr("Current"), selectionButtonGroup); + QRadioButton* selectRangeRadioButton = new QRadioButton(tr("Range"), selectionButtonGroup); + + QLabel* toLabel = new QLabel(tr("To:"), selectionButtonGroup); + + m_pFromPageSpinBox = new QSpinBox(1, m_pageCount, 1, selectionButtonGroup); + connect(m_pFromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(fromPageChanged(int))); + + m_pToPageSpinBox = new QSpinBox(1, m_pageCount, 1, selectionButtonGroup); + connect(m_pToPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(toPageChanged(int))); + + selectionButtonGroup->setButton(1); + selectionChanged(1); + + m_pFromPageSpinBox->setValue(pageAt); + m_pToPageSpinBox->setValue(pageAt); + + QGroupBox* exportGroupBox = new QGroupBox(0, Qt::Vertical, tr("Export As"), this); + + QLabel* nameLabel = new QLabel(tr("Name:"), exportGroupBox); + QLabel* formatLabel = new QLabel(tr("Format:"), exportGroupBox); + + m_pNameLineEdit = new QLineEdit(exportGroupBox); + + m_pFormatComboBox = new QComboBox(exportGroupBox); + m_pFormatComboBox->insertStrList(QImageIO::outputFormats()); + + FileSelector* fileSelector = new FileSelector("image/*", this, "fileselector"); + fileSelector->setNewVisible(false); + fileSelector->setCloseVisible(false); + + QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); + selectionButtonGroup->layout()->setSpacing(4); + exportGroupBox->layout()->setSpacing(4); + QGridLayout* selectionLayout = new QGridLayout(selectionButtonGroup->layout(), 2, 2); + QHBoxLayout* rangeLayout = new QHBoxLayout(); + QGridLayout* exportLayout = new QGridLayout(exportGroupBox->layout(), 2, 2); + + selectionLayout->addWidget(selectAllRadioButton, 0, 0); + selectionLayout->addWidget(selectCurrentRadioButton, 1, 0); + selectionLayout->addWidget(selectRangeRadioButton, 0, 1); + selectionLayout->addLayout(rangeLayout, 1, 1); + + rangeLayout->addWidget(m_pFromPageSpinBox); + rangeLayout->addWidget(toLabel); + rangeLayout->addWidget(m_pToPageSpinBox); + + exportLayout->addWidget(nameLabel, 0, 0); + exportLayout->addWidget(formatLabel, 1, 0); + + exportLayout->addWidget(m_pNameLineEdit, 0, 1); + exportLayout->addWidget(m_pFormatComboBox, 1, 1); + + exportLayout->setColStretch(1, 1); + + mainLayout->addWidget(selectionButtonGroup); + mainLayout->addWidget(exportGroupBox); + mainLayout->addWidget(fileSelector); + + m_pNameLineEdit->setFocus(); +} + +ExportDialog::~ExportDialog() +{ +} + +uint ExportDialog::selectedFromPage() +{ + return (m_pFromPageSpinBox->value()); +} + +uint ExportDialog::selectedToPage() +{ + return (m_pToPageSpinBox->value()); +} + +QString ExportDialog::selectedName() +{ + return (m_pNameLineEdit->text()); +} + +QString ExportDialog::selectedFormat() +{ + return (m_pFormatComboBox->currentText()); +} + +void ExportDialog::accept() +{ + if (!(m_pNameLineEdit->text().isEmpty())) { + QDialog::accept(); + } +} + +void ExportDialog::selectionChanged(int id) +{ + switch (id) { + case 0: + m_pFromPageSpinBox->setValue(1); + m_pToPageSpinBox->setValue(m_pageCount); + + m_pFromPageSpinBox->setEnabled(false); + m_pToPageSpinBox->setEnabled(false); + break; + case 1: + m_pFromPageSpinBox->setValue(m_pageAt); + m_pToPageSpinBox->setValue(m_pageAt); + + m_pFromPageSpinBox->setEnabled(false); + m_pToPageSpinBox->setEnabled(false); + break; + case 2: + m_pFromPageSpinBox->setEnabled(true); + m_pToPageSpinBox->setEnabled(true); + break; + default: + break; + } +} + +void ExportDialog::fromPageChanged(int value) +{ + if (m_pToPageSpinBox->value() < value) { + m_pToPageSpinBox->setValue(value); + } +} + +void ExportDialog::toPageChanged(int value) +{ + if (m_pFromPageSpinBox->value() > value) { + m_pFromPageSpinBox->setValue(value); + } +} diff --git a/noncore/graphics/drawpad/exportdialog.h b/noncore/graphics/drawpad/exportdialog.h new file mode 100644 index 0000000..7379f6d --- a/dev/null +++ b/noncore/graphics/drawpad/exportdialog.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * * + * 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 EXPORTDIALOG_H +#define EXPORTDIALOG_H + +#include <qdialog.h> + +#include <qstrlist.h> + +class QComboBox; +class QLineEdit; +class QSpinBox; + +class ExportDialog : public QDialog +{ + Q_OBJECT + +public: + ExportDialog(uint pageAt, uint pageCount, QWidget* parent = 0, const char* name = 0); + ~ExportDialog(); + + uint selectedFromPage(); + uint selectedToPage(); + + QString selectedName(); + QString selectedFormat(); + +public slots: + void accept(); + +private slots: + void selectionChanged(int id); + void fromPageChanged(int value); + void toPageChanged(int value); + +private: + uint m_pageAt; + uint m_pageCount; + + QSpinBox* m_pFromPageSpinBox; + QSpinBox* m_pToPageSpinBox; + + QLineEdit* m_pNameLineEdit; + QComboBox* m_pFormatComboBox; +}; + +#endif // EXPORTDIALOG_H diff --git a/noncore/graphics/drawpad/filledellipsetool.cpp b/noncore/graphics/drawpad/filledellipsetool.cpp new file mode 100644 index 0000000..b446000 --- a/dev/null +++ b/noncore/graphics/drawpad/filledellipsetool.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + * * + * 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 "filledellipsetool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +#include <qpainter.h> +#include <qpixmap.h> + +FilledEllipseTool::FilledEllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : ShapeTool(drawPad, drawPadCanvas) +{ +} + +FilledEllipseTool::~FilledEllipseTool() +{ +} + +void FilledEllipseTool::drawFinalShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); + p.setPen(m_pDrawPad->pen()); + p.setBrush(m_pDrawPad->brush()); + p.setRasterOp(Qt::CopyROP); + p.drawEllipse(QRect(m_polyline[2], m_polyline[0])); +} + +void FilledEllipseTool::drawTemporaryShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[1])); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); +} diff --git a/noncore/graphics/drawpad/filledellipsetool.h b/noncore/graphics/drawpad/filledellipsetool.h new file mode 100644 index 0000000..b29be20 --- a/dev/null +++ b/noncore/graphics/drawpad/filledellipsetool.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * * + * 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 FILLEDELLIPSETOOL_H +#define FILLEDELLIPSETOOL_H + +#include "shapetool.h" + +class FilledEllipseTool : public ShapeTool +{ +public: + FilledEllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~FilledEllipseTool(); + +protected: + void drawFinalShape(QPainter& p); + void drawTemporaryShape(QPainter& p); +}; + +#endif // FILLEDELLIPSETOOL_H diff --git a/noncore/graphics/drawpad/filledrectangletool.cpp b/noncore/graphics/drawpad/filledrectangletool.cpp new file mode 100644 index 0000000..388acbd --- a/dev/null +++ b/noncore/graphics/drawpad/filledrectangletool.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * * + * 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 "filledrectangletool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +FilledRectangleTool::FilledRectangleTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : ShapeTool(drawPad, drawPadCanvas) +{ +} + +FilledRectangleTool::~FilledRectangleTool() +{ +} + +void FilledRectangleTool::drawFinalShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); + p.setRasterOp(Qt::CopyROP); + p.fillRect(QRect(m_polyline[2], m_polyline[0]), m_pDrawPad->brush()); + p.setPen(m_pDrawPad->pen()); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); +} + +void FilledRectangleTool::drawTemporaryShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[1])); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); +} diff --git a/noncore/graphics/drawpad/filledrectangletool.h b/noncore/graphics/drawpad/filledrectangletool.h new file mode 100644 index 0000000..7364911 --- a/dev/null +++ b/noncore/graphics/drawpad/filledrectangletool.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * * + * 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 FILLEDRECTANGLETOOL_H +#define FILLEDRECTANGLETOOL_H + +#include "shapetool.h" + +class FilledRectangleTool : public ShapeTool +{ +public: + FilledRectangleTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~FilledRectangleTool(); + +protected: + void drawFinalShape(QPainter& p); + void drawTemporaryShape(QPainter& p); +}; + +#endif // FILLEDRECTANGLETOOL_H diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp new file mode 100644 index 0000000..3297d21 --- a/dev/null +++ b/noncore/graphics/drawpad/filltool.cpp @@ -0,0 +1,88 @@ +/*************************************************************************** + * * + * 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 "filltool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +#include <qimage.h> +#include <qpixmap.h> + +FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : Tool(drawPad, drawPadCanvas) +{ +} + +FillTool::~FillTool() +{ +} + +void FillTool::mousePressEvent(QMouseEvent* e) +{ + int x = e->x(); + int y = e->y(); + + m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); + m_fillRgb = m_pDrawPad->brush().color().rgb(); + m_oldRgb = m_image.pixel(x, y); + + if (m_oldRgb != m_fillRgb) { + fillLine(x, y); + + m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); + m_pDrawPadCanvas->viewport()->update(); + } +} + +void FillTool::mouseReleaseEvent(QMouseEvent* e) +{ + Q_UNUSED(e) +} + +void FillTool::mouseMoveEvent(QMouseEvent* e) +{ + Q_UNUSED(e) +} + +void FillTool::fillLine(int x, int y) +{ + if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { + if (m_image.pixel(x, y) == m_oldRgb) { + int x1, x2; + + x1 = x - 1; + x2 = x + 1; + + while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) { + x1--; + } + + while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) { + x2++; + } + + for (int i = x1 + 1; i < x2; i++) { + m_image.setPixel(i, y, m_fillRgb); + } + + for (int i = x1 + 1; i < x2; i++) { + fillLine(i, y - 1); + } + + for (int i = x1 + 1; i < x2; i++) { + fillLine(i, y + 1); + } + } + } +} diff --git a/noncore/graphics/drawpad/filltool.h b/noncore/graphics/drawpad/filltool.h new file mode 100644 index 0000000..eaf9a27 --- a/dev/null +++ b/noncore/graphics/drawpad/filltool.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * * + * 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 FILLTOOL_H +#define FILLTOOL_H + +#include "tool.h" + +#include <qimage.h> + +class FillTool : public Tool +{ +public: + FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~FillTool(); + + void mousePressEvent(QMouseEvent* e); + void mouseReleaseEvent(QMouseEvent* e); + void mouseMoveEvent(QMouseEvent* e); + +private: + void fillLine(int x, int y); + + QImage m_image; + QRgb m_fillRgb; + QRgb m_oldRgb; +}; + +#endif // FILLTOOL_H diff --git a/noncore/graphics/drawpad/importdialog.cpp b/noncore/graphics/drawpad/importdialog.cpp new file mode 100644 index 0000000..7722417 --- a/dev/null +++ b/noncore/graphics/drawpad/importdialog.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** + * * + * 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 "importdialog.h" + +#include <qpe/applnk.h> +#include <qpe/fileselector.h> + +#include <qlayout.h> + +ImportDialog::ImportDialog(QWidget* parent, const char* name) + : QDialog(parent, name, true) +{ + setCaption(tr("Import")); + + m_pFileSelector = new FileSelector("image/*", this, "fileselector"); + m_pFileSelector->setNewVisible(false); + m_pFileSelector->setCloseVisible(false); + + QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); + mainLayout->addWidget(m_pFileSelector); +} + +ImportDialog::~ImportDialog() +{ +} + +const DocLnk* ImportDialog::selected() +{ + return m_pFileSelector->selected(); +} diff --git a/noncore/graphics/drawpad/importdialog.h b/noncore/graphics/drawpad/importdialog.h new file mode 100644 index 0000000..1c67145 --- a/dev/null +++ b/noncore/graphics/drawpad/importdialog.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * * + * 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 IMPORTDIALOG_H +#define IMPORTDIALOG_H + +#include <qdialog.h> + +class DocLnk; +class FileSelector; + +class ImportDialog : public QDialog +{ + Q_OBJECT + +public: + ImportDialog(QWidget* parent = 0, const char* name = 0); + ~ImportDialog(); + + const DocLnk* selected(); + +private: + FileSelector* m_pFileSelector; +}; + +#endif // IMPORTDIALOG_H diff --git a/noncore/graphics/drawpad/linetool.cpp b/noncore/graphics/drawpad/linetool.cpp new file mode 100644 index 0000000..94ca165 --- a/dev/null +++ b/noncore/graphics/drawpad/linetool.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * * + * 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 "linetool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +LineTool::LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : ShapeTool(drawPad, drawPadCanvas) +{ +} + +LineTool::~LineTool() +{ +} + +void LineTool::drawFinalShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawLine(m_polyline[2], m_polyline[0]); + p.setPen(m_pDrawPad->pen()); + p.setRasterOp(Qt::CopyROP); + p.drawLine(m_polyline[2], m_polyline[0]); +} + +void LineTool::drawTemporaryShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawLine(m_polyline[2], m_polyline[1]); + p.drawLine(m_polyline[2], m_polyline[0]); +} diff --git a/noncore/graphics/drawpad/linetool.h b/noncore/graphics/drawpad/linetool.h new file mode 100644 index 0000000..6108b5a --- a/dev/null +++ b/noncore/graphics/drawpad/linetool.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * * + * 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 LINETOOL_H +#define LINETOOL_H + +#include "shapetool.h" + +class LineTool : public ShapeTool +{ +public: + LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~LineTool(); + +protected: + void drawFinalShape(QPainter& p); + void drawTemporaryShape(QPainter& p); +}; + +#endif // LINETOOL_H diff --git a/noncore/graphics/drawpad/newpagedialog.cpp b/noncore/graphics/drawpad/newpagedialog.cpp index c11d977..b1b26ef 100644 --- a/noncore/graphics/drawpad/newpagedialog.cpp +++ b/noncore/graphics/drawpad/newpagedialog.cpp @@ -1,61 +1,102 @@ /*************************************************************************** * * * 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 "newpagedialog.h" +#include <qbuttongroup.h> +#include <qgroupbox.h> #include <qlabel.h> #include <qlayout.h> +#include <qradiobutton.h> #include <qspinbox.h> -NewPageDialog::NewPageDialog(QWidget* parent, const char* name) +NewPageDialog::NewPageDialog(uint width, uint height, const QColor& foregroundColor, + const QColor& backgroundColor, QWidget* parent, const char* name) : QDialog(parent, name, true) { setCaption(tr("New Page")); - QLabel* widthLabel = new QLabel(tr("Width :"), this); - QLabel* heightLabel = new QLabel(tr("Height :"), this); + m_foregroundColor = foregroundColor; + m_backgroundColor = backgroundColor; - m_pWidthSpinBox = new QSpinBox(1, 1024, 1, this); - m_pHeightSpinBox = new QSpinBox(1, 1024, 1, this); + QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Page Size"), this); - QGridLayout* gridLayout = new QGridLayout(this, 2, 2, 2, 2); + QLabel* widthLabel = new QLabel(tr("Width :"), sizeGroupBox); + QLabel* heightLabel = new QLabel(tr("Height :"), sizeGroupBox); - gridLayout->addWidget(widthLabel, 0, 0); - gridLayout->addWidget(heightLabel, 1, 0); - gridLayout->addWidget(m_pWidthSpinBox, 0, 1); - gridLayout->addWidget(m_pHeightSpinBox, 1, 1); + m_pWidthSpinBox = new QSpinBox(1, 1024, 1, sizeGroupBox); + m_pHeightSpinBox = new QSpinBox(1, 1024, 1, sizeGroupBox); + + m_pWidthSpinBox->setValue(width); + m_pHeightSpinBox->setValue(height); + + m_pContentButtonGroup = new QButtonGroup(0, Qt::Vertical, tr("Contents"), this); + + QRadioButton* whiteColorRadioButton = new QRadioButton(tr("White"), m_pContentButtonGroup); + QRadioButton* foregroundColorRadioButton = new QRadioButton(tr("Foreground Color"), m_pContentButtonGroup); + QRadioButton* backgroundColorRadioButton = new QRadioButton(tr("Background Color"), m_pContentButtonGroup); + + m_pContentButtonGroup->setButton(0); + + QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); + sizeGroupBox->layout()->setSpacing(4); + m_pContentButtonGroup->layout()->setSpacing(4); + QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2); + QVBoxLayout* contentLayout = new QVBoxLayout(m_pContentButtonGroup->layout()); + + sizeLayout->addWidget(widthLabel, 0, 0); + sizeLayout->addWidget(heightLabel, 1, 0); + sizeLayout->addWidget(m_pWidthSpinBox, 0, 1); + sizeLayout->addWidget(m_pHeightSpinBox, 1, 1); + + sizeLayout->setColStretch(1, 1); + + contentLayout->addWidget(whiteColorRadioButton); + contentLayout->addWidget(foregroundColorRadioButton); + contentLayout->addWidget(backgroundColorRadioButton); + + mainLayout->addWidget(sizeGroupBox); + mainLayout->addWidget(m_pContentButtonGroup); } NewPageDialog::~NewPageDialog() { } -void NewPageDialog::setWidth(int width) +uint NewPageDialog::selectedWidth() { - m_pWidthSpinBox->setValue(width); + return (m_pWidthSpinBox->value()); } -void NewPageDialog::setHeight(int height) +uint NewPageDialog::selectedHeight() { - m_pHeightSpinBox->setValue(height); + return (m_pHeightSpinBox->value()); } -int NewPageDialog::width() +const QColor& NewPageDialog::selectedColor() { - return m_pWidthSpinBox->value(); + switch (m_pContentButtonGroup->id(m_pContentButtonGroup->selected())) { + case 0: + return (Qt::white); + break; + case 1: + return (m_foregroundColor); + break; + case 2: + return (m_backgroundColor); + break; + default: + return (Qt::white); + break; } - -int NewPageDialog::height() -{ - return m_pHeightSpinBox->value(); } diff --git a/noncore/graphics/drawpad/newpagedialog.h b/noncore/graphics/drawpad/newpagedialog.h index a2b6b87..f418340 100644 --- a/noncore/graphics/drawpad/newpagedialog.h +++ b/noncore/graphics/drawpad/newpagedialog.h @@ -1,40 +1,45 @@ /*************************************************************************** * * * 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 NEWPAGEDIALOG_H #define NEWPAGEDIALOG_H #include <qdialog.h> +class QButtonGroup; class QSpinBox; class NewPageDialog : public QDialog { Q_OBJECT public: - NewPageDialog(QWidget* parent = 0, const char* name = 0); + NewPageDialog(uint width, uint height, const QColor& foregroundColor, + const QColor& backgroundColor, QWidget* parent = 0, const char* name = 0); ~NewPageDialog(); - void setWidth(int width); - void setHeight(int height); - - int width(); - int height(); + uint selectedWidth(); + uint selectedHeight(); + const QColor& selectedColor(); private: QSpinBox* m_pWidthSpinBox; QSpinBox* m_pHeightSpinBox; + + QColor m_foregroundColor; + QColor m_backgroundColor; + + QButtonGroup* m_pContentButtonGroup; }; #endif // NEWPAGEDIALOG_H diff --git a/noncore/graphics/drawpad/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp new file mode 100644 index 0000000..5661b03 --- a/dev/null +++ b/noncore/graphics/drawpad/pointtool.cpp @@ -0,0 +1,73 @@ +/*************************************************************************** + * * + * 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 "pointtool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +#include <qpainter.h> +#include <qpixmap.h> + +PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : Tool(drawPad, drawPadCanvas) +{ + m_mousePressed = false; + m_polyline.resize(3); +} + +PointTool::~PointTool() +{ +} + +void PointTool::mousePressEvent(QMouseEvent* e) +{ + m_mousePressed = true; + m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); +} + +void PointTool::mouseReleaseEvent(QMouseEvent* e) +{ + Q_UNUSED(e) + + m_mousePressed = false; +} + +void PointTool::mouseMoveEvent(QMouseEvent* e) +{ + if (m_mousePressed) { + QPainter painter; + painter.begin(m_pDrawPadCanvas->currentPage()); + painter.setPen(m_pDrawPad->pen()); + m_polyline[2] = m_polyline[1]; + m_polyline[1] = m_polyline[0]; + m_polyline[0] = e->pos(); + painter.drawPolyline(m_polyline); + painter.end(); + + QRect r = m_polyline.boundingRect(); + r = r.normalize(); + r.setLeft(r.left() - m_pDrawPad->pen().width()); + r.setTop(r.top() - m_pDrawPad->pen().width()); + r.setRight(r.right() + m_pDrawPad->pen().width()); + r.setBottom(r.bottom() + m_pDrawPad->pen().width()); + + QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), + m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); + + bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), + m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + + m_pDrawPadCanvas->viewport()->update(viewportRect); + } +} diff --git a/noncore/graphics/drawpad/pointtool.h b/noncore/graphics/drawpad/pointtool.h new file mode 100644 index 0000000..4bbbac2 --- a/dev/null +++ b/noncore/graphics/drawpad/pointtool.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * * + * 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 POINTTOOL_H +#define POINTTOOL_H + +#include "tool.h" + +#include <qpointarray.h> + +class PointTool : public Tool +{ +public: + PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~PointTool(); + + void mousePressEvent(QMouseEvent* e); + void mouseReleaseEvent(QMouseEvent* e); + void mouseMoveEvent(QMouseEvent* e); + +private: + bool m_mousePressed; + QPointArray m_polyline; +}; + +#endif // POINTTOOL_H diff --git a/noncore/graphics/drawpad/rectangletool.cpp b/noncore/graphics/drawpad/rectangletool.cpp new file mode 100644 index 0000000..a2f6026 --- a/dev/null +++ b/noncore/graphics/drawpad/rectangletool.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * * + * 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 "rectangletool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +RectangleTool::RectangleTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : ShapeTool(drawPad, drawPadCanvas) +{ +} + +RectangleTool::~RectangleTool() +{ +} + +void RectangleTool::drawFinalShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); + p.setPen(m_pDrawPad->pen()); + p.setRasterOp(Qt::CopyROP); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); +} + +void RectangleTool::drawTemporaryShape(QPainter& p) +{ + p.setRasterOp(Qt::NotROP); + p.drawRect(QRect(m_polyline[2], m_polyline[1])); + p.drawRect(QRect(m_polyline[2], m_polyline[0])); +} diff --git a/noncore/graphics/drawpad/rectangletool.h b/noncore/graphics/drawpad/rectangletool.h new file mode 100644 index 0000000..b5164dc --- a/dev/null +++ b/noncore/graphics/drawpad/rectangletool.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * * + * 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 RECTANGLETOOL_H +#define RECTANGLETOOL_H + +#include "shapetool.h" + +class RectangleTool : public ShapeTool +{ +public: + RectangleTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~RectangleTool(); + +protected: + void drawFinalShape(QPainter& p); + void drawTemporaryShape(QPainter& p); +}; + +#endif // RECTANGLETOOL_H diff --git a/noncore/graphics/drawpad/shapetool.cpp b/noncore/graphics/drawpad/shapetool.cpp new file mode 100644 index 0000000..3c99370 --- a/dev/null +++ b/noncore/graphics/drawpad/shapetool.cpp @@ -0,0 +1,92 @@ +/*************************************************************************** + * * + * 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 "shapetool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +#include <qpainter.h> +#include <qpixmap.h> + +ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : Tool(drawPad, drawPadCanvas) +{ + m_mousePressed = false; + m_polyline.resize(3); +} + +ShapeTool::~ShapeTool() +{ +} + +void ShapeTool::mousePressEvent(QMouseEvent* e) +{ + m_mousePressed = true; + m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); +} + +void ShapeTool::mouseReleaseEvent(QMouseEvent* e) +{ + Q_UNUSED(e) + + QPainter painter; + painter.begin(m_pDrawPadCanvas->currentPage()); + drawFinalShape(painter); + painter.end(); + + QRect r = m_polyline.boundingRect(); + r = r.normalize(); + r.setLeft(r.left() - m_pDrawPad->pen().width()); + r.setTop(r.top() - m_pDrawPad->pen().width()); + r.setRight(r.right() + m_pDrawPad->pen().width()); + r.setBottom(r.bottom() + m_pDrawPad->pen().width()); + + QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), + m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); + + bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), + m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + + m_pDrawPadCanvas->viewport()->update(viewportRect); + + m_mousePressed = false; +} + +void ShapeTool::mouseMoveEvent(QMouseEvent* e) +{ + if (m_mousePressed) { + m_polyline[0] = e->pos(); + QPainter painter; + painter.begin(m_pDrawPadCanvas->currentPage()); + drawTemporaryShape(painter); + painter.end(); + + QRect r = m_polyline.boundingRect(); + r = r.normalize(); + r.setLeft(r.left() - m_pDrawPad->pen().width()); + r.setTop(r.top() - m_pDrawPad->pen().width()); + r.setRight(r.right() + m_pDrawPad->pen().width()); + r.setBottom(r.bottom() + m_pDrawPad->pen().width()); + + QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), + m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); + + bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), + m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); + + m_pDrawPadCanvas->viewport()->update(viewportRect); + + m_polyline[1] = m_polyline[0]; + } +} diff --git a/noncore/graphics/drawpad/shapetool.h b/noncore/graphics/drawpad/shapetool.h new file mode 100644 index 0000000..3f2f7a9 --- a/dev/null +++ b/noncore/graphics/drawpad/shapetool.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * * + * 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 SHAPETOOL_H +#define SHAPETOOL_H + +#include "tool.h" + +#include <qpointarray.h> + +class ShapeTool : public Tool +{ +public: + ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~ShapeTool(); + + void mousePressEvent(QMouseEvent* e); + void mouseReleaseEvent(QMouseEvent* e); + void mouseMoveEvent(QMouseEvent* e); + +protected: + virtual void drawFinalShape(QPainter& p) = 0; + virtual void drawTemporaryShape(QPainter& p) = 0; + + QPointArray m_polyline; + +private: + bool m_mousePressed; +}; + +#endif // SHAPETOOL_H diff --git a/noncore/graphics/drawpad/tool.cpp b/noncore/graphics/drawpad/tool.cpp new file mode 100644 index 0000000..0d36912 --- a/dev/null +++ b/noncore/graphics/drawpad/tool.cpp @@ -0,0 +1,28 @@ +/*************************************************************************** + * * + * 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 "tool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +Tool::Tool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : QObject() +{ + m_pDrawPad = drawPad; + m_pDrawPadCanvas = drawPadCanvas; +} + +Tool::~Tool() +{ +} diff --git a/noncore/graphics/drawpad/tool.h b/noncore/graphics/drawpad/tool.h new file mode 100644 index 0000000..5848215 --- a/dev/null +++ b/noncore/graphics/drawpad/tool.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * * + * 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 TOOL_H +#define TOOL_H + +#include <qobject.h> + +class DrawPad; +class DrawPadCanvas; + +class Tool : public QObject +{ +protected: + Tool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + +public: + virtual ~Tool(); + + virtual void mousePressEvent(QMouseEvent* e) = 0; + virtual void mouseReleaseEvent(QMouseEvent* e) = 0; + virtual void mouseMoveEvent(QMouseEvent* e) = 0; + +protected: + DrawPad* m_pDrawPad; + DrawPadCanvas* m_pDrawPadCanvas; +}; + +#endif // TOOL_H |