author | leseb <leseb> | 2002-04-17 20:43:39 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-04-17 20:43:39 (UTC) |
commit | 106073977316103f057930daf45f3a083114d48d (patch) (side-by-side diff) | |
tree | eede3bce7915e473d1204ecc93efb61946022447 | |
parent | c2c343110573bd8b4d59fbff577969ff23d5c544 (diff) | |
download | opie-106073977316103f057930daf45f3a083114d48d.zip opie-106073977316103f057930daf45f3a083114d48d.tar.gz opie-106073977316103f057930daf45f3a083114d48d.tar.bz2 |
Add text tool
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 84 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 3 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.pro | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 29 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasetool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filltool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pointtool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/shapetool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/texttool.cpp | 79 | ||||
-rw-r--r-- | noncore/graphics/drawpad/texttool.h | 46 | ||||
-rw-r--r-- | pics/drawpad/text.png | bin | 0 -> 142 bytes |
12 files changed, 218 insertions, 35 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 1375792..7e6fc53 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp @@ -5,48 +5,49 @@ * (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 "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 <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())); @@ -108,90 +109,101 @@ DrawPad::DrawPad(QWidget* parent, const char* name) 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_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this); - m_pPointToolAction->setToggleAction(true); + m_pLineToolButton = new QToolButton(drawModeToolBar); + m_pLineToolButton->setToggleButton(true); + + QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton); + + m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), "", 0, this); connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool())); - m_pPointToolAction->addTo(drawModeToolBar); + m_pPointToolAction->addTo(linePopupMenu); - m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this); - m_pLineToolAction->setToggleAction(true); + m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), "", 0, this); connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool())); - m_pLineToolAction->addTo(drawModeToolBar); + m_pLineToolAction->addTo(linePopupMenu); + + m_pLineToolButton->setPopup(linePopupMenu); + m_pLineToolButton->setPopupDelay(0); 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_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); @@ -252,188 +264,216 @@ DrawPad::DrawPad(QWidget* parent, const char* name) 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_pPointToolAction->setOn(true); - m_pLineToolAction->setOn(false); + 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_pPointToolAction->setOn(false); - m_pLineToolAction->setOn(true); + 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); m_pEraseToolAction->setOn(false); } void DrawPad::setRectangleTool() { if (m_pTool) { delete m_pTool; } m_pTool = new RectangleTool(this, m_pDrawPadCanvas); 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_pLineToolButton->setOn(false); m_pRectangleToolButton->setOn(true); m_pEllipseToolButton->setOn(false); + m_pTextToolAction->setOn(false); m_pFillToolAction->setOn(false); m_pEraseToolAction->setOn(false); } void DrawPad::setFilledRectangleTool() { if (m_pTool) { delete m_pTool; } m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas); m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet()); QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text()); 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_pLineToolButton->setOn(false); m_pRectangleToolButton->setOn(true); m_pEllipseToolButton->setOn(false); + m_pTextToolAction->setOn(false); m_pFillToolAction->setOn(false); m_pEraseToolAction->setOn(false); } void DrawPad::setEllipseTool() { if (m_pTool) { delete m_pTool; } 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_pPointToolAction->setOn(false); - m_pLineToolAction->setOn(false); + m_pLineToolButton->setOn(false); m_pRectangleToolButton->setOn(false); m_pEllipseToolButton->setOn(true); + m_pTextToolAction->setOn(false); m_pFillToolAction->setOn(false); m_pEraseToolAction->setOn(false); } void DrawPad::setFilledEllipseTool() { if (m_pTool) { delete m_pTool; } m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas); 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_pLineToolButton->setOn(false); m_pRectangleToolButton->setOn(false); m_pEllipseToolButton->setOn(true); + m_pTextToolAction->setOn(false); + m_pFillToolAction->setOn(false); + m_pEraseToolAction->setOn(false); +} + +void DrawPad::setTextTool() +{ + if (m_pTool) { + delete m_pTool; + } + + m_pTool = new TextTool(this, m_pDrawPadCanvas); + + m_pLineToolButton->setOn(false); + m_pRectangleToolButton->setOn(false); + m_pEllipseToolButton->setOn(false); + m_pTextToolAction->setOn(true); m_pFillToolAction->setOn(false); m_pEraseToolAction->setOn(false); } void DrawPad::setFillTool() { if (m_pTool) { delete m_pTool; } m_pTool = new FillTool(this, m_pDrawPadCanvas); - m_pPointToolAction->setOn(false); - m_pLineToolAction->setOn(false); + 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_pPointToolAction->setOn(false); - m_pLineToolAction->setOn(false); + 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); diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index 62a73c9..e4fd831 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h @@ -24,71 +24,74 @@ 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 fce0701..00eb00d 100644 --- a/noncore/graphics/drawpad/drawpad.pro +++ b/noncore/graphics/drawpad/drawpad.pro @@ -1,56 +1,58 @@ TEMPLATE = app CONFIG = qt warn_on release HEADERS = colordialog.h \ colorpanel.h \ 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 \ 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 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 diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index db6288f..b39a633 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp @@ -307,48 +307,64 @@ void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,c } } } QPixmap* DrawPadCanvas::currentPage() { return m_pages.current(); } QList<QPixmap> DrawPadCanvas::pages() { return m_pages; } uint DrawPadCanvas::pagePosition() { return (m_pages.at() + 1); } uint DrawPadCanvas::pageCount() { return m_pages.count(); } +void DrawPadCanvas::backupPage() +{ + 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::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(); } } @@ -492,50 +508,37 @@ void DrawPadCanvas::goNextPage() 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->tool()->mousePressEvent(e); } void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* 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->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 a1a9466..e05ce8a 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h @@ -27,48 +27,50 @@ 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(); QList<QPixmap> pages(); uint pagePosition(); uint pageCount(); + void backupPage(); + public slots: 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); diff --git a/noncore/graphics/drawpad/erasetool.cpp b/noncore/graphics/drawpad/erasetool.cpp index d37c901..828994b 100644 --- a/noncore/graphics/drawpad/erasetool.cpp +++ b/noncore/graphics/drawpad/erasetool.cpp @@ -20,48 +20,50 @@ #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; + + m_pDrawPadCanvas->backupPage(); } 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())); diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp index 3297d21..004da02 100644 --- a/noncore/graphics/drawpad/filltool.cpp +++ b/noncore/graphics/drawpad/filltool.cpp @@ -21,48 +21,50 @@ 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(); + + m_pDrawPadCanvas->backupPage(); } } 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--; diff --git a/noncore/graphics/drawpad/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp index 5661b03..e281284 100644 --- a/noncore/graphics/drawpad/pointtool.cpp +++ b/noncore/graphics/drawpad/pointtool.cpp @@ -20,48 +20,50 @@ #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; + + m_pDrawPadCanvas->backupPage(); } 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())); diff --git a/noncore/graphics/drawpad/shapetool.cpp b/noncore/graphics/drawpad/shapetool.cpp index 3c99370..bc5d9c0 100644 --- a/noncore/graphics/drawpad/shapetool.cpp +++ b/noncore/graphics/drawpad/shapetool.cpp @@ -40,48 +40,50 @@ 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; + + m_pDrawPadCanvas->backupPage(); } 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()); diff --git a/noncore/graphics/drawpad/texttool.cpp b/noncore/graphics/drawpad/texttool.cpp new file mode 100644 index 0000000..37b4801 --- a/dev/null +++ b/noncore/graphics/drawpad/texttool.cpp @@ -0,0 +1,79 @@ +/*************************************************************************** + * * + * 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 "texttool.h" + +#include "drawpad.h" +#include "drawpadcanvas.h" + +#include <qlayout.h> +#include <qlineedit.h> +#include <qpainter.h> +#include <qpixmap.h> + +TextToolDialog::TextToolDialog(QWidget* parent, const char* name) + : QDialog(parent, name, true) +{ + setCaption(tr("Insert Text")); + + m_pLineEdit = new QLineEdit(this); + + QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); + + mainLayout->addWidget(m_pLineEdit); +} + +TextToolDialog::~TextToolDialog() +{ +} + +QString TextToolDialog::text() +{ + return m_pLineEdit->text(); +} + +TextTool::TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) + : Tool(drawPad, drawPadCanvas) +{ +} + +TextTool::~TextTool() +{ +} + +void TextTool::mousePressEvent(QMouseEvent* e) +{ + TextToolDialog textToolDialog(m_pDrawPad); + + if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) { + QPainter painter; + painter.begin(m_pDrawPadCanvas->currentPage()); + painter.setPen(m_pDrawPad->pen()); + painter.drawText(e->x(), e->y(), textToolDialog.text()); + painter.end(); + + m_pDrawPadCanvas->viewport()->update(); + + m_pDrawPadCanvas->backupPage(); + } +} + +void TextTool::mouseReleaseEvent(QMouseEvent* e) +{ + Q_UNUSED(e) +} + +void TextTool::mouseMoveEvent(QMouseEvent* e) +{ + Q_UNUSED(e) +} diff --git a/noncore/graphics/drawpad/texttool.h b/noncore/graphics/drawpad/texttool.h new file mode 100644 index 0000000..3187675 --- a/dev/null +++ b/noncore/graphics/drawpad/texttool.h @@ -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. * + * * + ***************************************************************************/ + +#ifndef TEXTTOOL_H +#define TEXTTOOL_H + +#include "tool.h" + +#include <qdialog.h> + +class QLineEdit; + +class TextToolDialog : public QDialog +{ +public: + TextToolDialog(QWidget* parent = 0, const char* name = 0); + ~TextToolDialog(); + + QString text(); + +private: + QLineEdit* m_pLineEdit; +}; + +class TextTool : public Tool +{ +public: + TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); + ~TextTool(); + + void mousePressEvent(QMouseEvent* e); + void mouseReleaseEvent(QMouseEvent* e); + void mouseMoveEvent(QMouseEvent* e); +}; + +#endif // TEXTTOOL_H diff --git a/pics/drawpad/text.png b/pics/drawpad/text.png Binary files differnew file mode 100644 index 0000000..230d72b --- a/dev/null +++ b/pics/drawpad/text.png |