-rw-r--r-- | noncore/graphics/drawpad/drawmode.h | 6 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 81 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 17 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 135 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 12 |
5 files changed, 159 insertions, 92 deletions
diff --git a/noncore/graphics/drawpad/drawmode.h b/noncore/graphics/drawpad/drawmode.h index d4ecadd..4e80fe2 100644 --- a/noncore/graphics/drawpad/drawmode.h +++ b/noncore/graphics/drawpad/drawmode.h | |||
@@ -1,37 +1,39 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #ifndef DRAWMODE_H | 14 | #ifndef DRAWMODE_H |
15 | #define DRAWMODE_H | 15 | #define DRAWMODE_H |
16 | 16 | ||
17 | #include <qobject.h> | 17 | #include <qobject.h> |
18 | 18 | ||
19 | class DrawPad; | 19 | class DrawPad; |
20 | class DrawPadCanvas; | 20 | class DrawPadCanvas; |
21 | 21 | ||
22 | class DrawMode : QObject | 22 | class DrawMode : QObject |
23 | { | 23 | { |
24 | public: | 24 | protected: |
25 | DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 25 | DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
26 | ~DrawMode(); | 26 | |
27 | public: | ||
28 | virtual ~DrawMode(); | ||
27 | 29 | ||
28 | virtual void mousePressEvent(QMouseEvent* e) = 0; | 30 | virtual void mousePressEvent(QMouseEvent* e) = 0; |
29 | virtual void mouseReleaseEvent(QMouseEvent* e) = 0; | 31 | virtual void mouseReleaseEvent(QMouseEvent* e) = 0; |
30 | virtual void mouseMoveEvent(QMouseEvent* e) = 0; | 32 | virtual void mouseMoveEvent(QMouseEvent* e) = 0; |
31 | 33 | ||
32 | protected: | 34 | protected: |
33 | DrawPad* m_pDrawPad; | 35 | DrawPad* m_pDrawPad; |
34 | DrawPadCanvas* m_pDrawPadCanvas; | 36 | DrawPadCanvas* m_pDrawPadCanvas; |
35 | }; | 37 | }; |
36 | 38 | ||
37 | #endif // DRAWMODE_H | 39 | #endif // DRAWMODE_H |
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 3c593b6..5cc2197 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -1,390 +1,369 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "drawpad.h" | 14 | #include "drawpad.h" |
15 | 15 | ||
16 | #include "drawpadcanvas.h" | 16 | #include "drawpadcanvas.h" |
17 | #include "ellipsedrawmode.h" | 17 | #include "ellipsedrawmode.h" |
18 | #include "erasedrawmode.h" | 18 | #include "erasedrawmode.h" |
19 | #include "filldrawmode.h" | 19 | #include "filldrawmode.h" |
20 | #include "linedrawmode.h" | 20 | #include "linedrawmode.h" |
21 | #include "pointdrawmode.h" | 21 | #include "pointdrawmode.h" |
22 | #include "rectangledrawmode.h" | 22 | #include "rectangledrawmode.h" |
23 | 23 | ||
24 | #include <qpe/global.h> | 24 | #include <qpe/global.h> |
25 | #include <qpe/qpemenubar.h> | 25 | #include <qpe/qpemenubar.h> |
26 | #include <qpe/qpetoolbar.h> | 26 | #include <qpe/qpetoolbar.h> |
27 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
28 | 28 | ||
29 | #include <qaction.h> | 29 | #include <qaction.h> |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qpainter.h> | 31 | #include <qpainter.h> |
32 | #include <qspinbox.h> | 32 | #include <qspinbox.h> |
33 | #include <qtoolbutton.h> | 33 | #include <qtoolbutton.h> |
34 | #include <qtooltip.h> | 34 | #include <qtooltip.h> |
35 | 35 | ||
36 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | 36 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) |
37 | : QMainWindow(parent, name, f) | 37 | : QMainWindow(parent, name, f) |
38 | { | 38 | { |
39 | setCaption(tr("DrawPad")); | 39 | setCaption(tr("DrawPad")); |
40 | 40 | ||
41 | // init members | 41 | // init members |
42 | 42 | ||
43 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 43 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
44 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); | ||
45 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); | ||
44 | 46 | ||
45 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 47 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
46 | 48 | ||
47 | if (file.open(IO_ReadOnly)) { | 49 | if (file.open(IO_ReadOnly)) { |
48 | m_pDrawPadCanvas->load(&file); | 50 | m_pDrawPadCanvas->load(&file); |
49 | file.close(); | 51 | file.close(); |
50 | } | 52 | } |
51 | 53 | ||
52 | setCentralWidget(m_pDrawPadCanvas); | 54 | setCentralWidget(m_pDrawPadCanvas); |
53 | 55 | ||
54 | m_colors.resize(8); | 56 | m_colors.resize(8); |
55 | m_colors.at(0) = Qt::black; | 57 | m_colors.at(0) = Qt::black; |
56 | m_colors.at(1) = Qt::white; | 58 | m_colors.at(1) = Qt::white; |
57 | m_colors.at(2) = Qt::red; | 59 | m_colors.at(2) = Qt::red; |
58 | m_colors.at(3) = Qt::green; | 60 | m_colors.at(3) = Qt::green; |
59 | m_colors.at(4) = Qt::blue; | 61 | m_colors.at(4) = Qt::blue; |
60 | m_colors.at(5) = Qt::cyan; | 62 | m_colors.at(5) = Qt::cyan; |
61 | m_colors.at(6) = Qt::magenta; | 63 | m_colors.at(6) = Qt::magenta; |
62 | m_colors.at(7) = Qt::yellow; | 64 | m_colors.at(7) = Qt::yellow; |
63 | 65 | ||
64 | // init menu | 66 | // init menu |
65 | 67 | ||
66 | setToolBarsMovable(false); | 68 | setToolBarsMovable(false); |
67 | 69 | ||
68 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 70 | QPEToolBar* menuToolBar = new QPEToolBar(this); |
69 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); | 71 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); |
70 | 72 | ||
71 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); | 73 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); |
72 | 74 | ||
73 | QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); | 75 | QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); |
74 | connect(clearAllAction, SIGNAL(activated()), this, SLOT(clearAll())); | 76 | connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll())); |
75 | clearAllAction->addTo(toolsPopupMenu); | 77 | clearAllAction->addTo(toolsPopupMenu); |
76 | 78 | ||
77 | toolsPopupMenu->insertSeparator(); | 79 | toolsPopupMenu->insertSeparator(); |
78 | 80 | ||
79 | QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this); | 81 | QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this); |
80 | setOptionsAction->addTo(toolsPopupMenu); | 82 | setOptionsAction->addTo(toolsPopupMenu); |
81 | 83 | ||
82 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); | 84 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); |
83 | 85 | ||
84 | // init page toolbar | 86 | // init page toolbar |
85 | 87 | ||
86 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 88 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
87 | 89 | ||
88 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); | 90 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); |
89 | connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage())); | 91 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); |
90 | newPageAction->addTo(pageToolBar); | 92 | newPageAction->addTo(pageToolBar); |
91 | 93 | ||
92 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); | 94 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); |
93 | connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); | 95 | connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); |
94 | clearPageAction->addTo(pageToolBar); | 96 | clearPageAction->addTo(pageToolBar); |
95 | 97 | ||
96 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); | 98 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); |
97 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); | 99 | connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); |
98 | deletePageAction->addTo(pageToolBar); | 100 | deletePageAction->addTo(pageToolBar); |
99 | 101 | ||
100 | QPEToolBar* emptyToolBar = new QPEToolBar(this); | 102 | QPEToolBar* emptyToolBar = new QPEToolBar(this); |
101 | emptyToolBar->setHorizontalStretchable(true); | 103 | emptyToolBar->setHorizontalStretchable(true); |
102 | 104 | ||
103 | // init navigation toolbar | 105 | // init navigation toolbar |
104 | 106 | ||
105 | QPEToolBar* navigationToolBar = new QPEToolBar(this); | 107 | QPEToolBar* navigationToolBar = new QPEToolBar(this); |
106 | 108 | ||
109 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); | ||
110 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); | ||
111 | m_pUndoAction->addTo(navigationToolBar); | ||
112 | |||
113 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); | ||
114 | connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); | ||
115 | m_pRedoAction->addTo(navigationToolBar); | ||
116 | |||
117 | updateUndoRedoToolButtons(); | ||
118 | |||
107 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); | 119 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); |
108 | connect(m_pFirstPageAction, SIGNAL(activated()), this, SLOT(goFirstPage())); | 120 | connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); |
109 | m_pFirstPageAction->addTo(navigationToolBar); | 121 | m_pFirstPageAction->addTo(navigationToolBar); |
110 | 122 | ||
111 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); | 123 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); |
112 | connect(m_pPreviousPageAction, SIGNAL(activated()), this, SLOT(goPreviousPage())); | 124 | connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); |
113 | m_pPreviousPageAction->addTo(navigationToolBar); | 125 | m_pPreviousPageAction->addTo(navigationToolBar); |
114 | 126 | ||
115 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); | 127 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); |
116 | connect(m_pNextPageAction, SIGNAL(activated()), this, SLOT(goNextPage())); | 128 | connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); |
117 | m_pNextPageAction->addTo(navigationToolBar); | 129 | m_pNextPageAction->addTo(navigationToolBar); |
118 | 130 | ||
119 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); | 131 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); |
120 | connect(m_pLastPageAction, SIGNAL(activated()), this, SLOT(goLastPage())); | 132 | connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); |
121 | m_pLastPageAction->addTo(navigationToolBar); | 133 | m_pLastPageAction->addTo(navigationToolBar); |
122 | 134 | ||
123 | updateNavigationToolBar(); | 135 | updateNavigationToolButtons(); |
124 | 136 | ||
125 | // init draw mode toolbar | 137 | // init draw mode toolbar |
126 | 138 | ||
127 | QPEToolBar* drawModeToolBar = new QPEToolBar(this); | 139 | QPEToolBar* drawModeToolBar = new QPEToolBar(this); |
128 | 140 | ||
129 | m_pPointDrawModeAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this); | 141 | m_pPointDrawModeAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this); |
130 | m_pPointDrawModeAction->setToggleAction(true); | 142 | m_pPointDrawModeAction->setToggleAction(true); |
131 | connect(m_pPointDrawModeAction, SIGNAL(activated()), this, SLOT(setPointDrawMode())); | 143 | connect(m_pPointDrawModeAction, SIGNAL(activated()), this, SLOT(setPointDrawMode())); |
132 | m_pPointDrawModeAction->addTo(drawModeToolBar); | 144 | m_pPointDrawModeAction->addTo(drawModeToolBar); |
133 | 145 | ||
134 | m_pLineDrawModeAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this); | 146 | m_pLineDrawModeAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this); |
135 | m_pLineDrawModeAction->setToggleAction(true); | 147 | m_pLineDrawModeAction->setToggleAction(true); |
136 | connect(m_pLineDrawModeAction, SIGNAL(activated()), this, SLOT(setLineDrawMode())); | 148 | connect(m_pLineDrawModeAction, SIGNAL(activated()), this, SLOT(setLineDrawMode())); |
137 | m_pLineDrawModeAction->addTo(drawModeToolBar); | 149 | m_pLineDrawModeAction->addTo(drawModeToolBar); |
138 | 150 | ||
139 | m_pRectangleDrawModeAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), QString::null, 0, this); | 151 | m_pRectangleDrawModeAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), QString::null, 0, this); |
140 | m_pRectangleDrawModeAction->setToggleAction(true); | 152 | m_pRectangleDrawModeAction->setToggleAction(true); |
141 | connect(m_pRectangleDrawModeAction, SIGNAL(activated()), this, SLOT(setRectangleDrawMode())); | 153 | connect(m_pRectangleDrawModeAction, SIGNAL(activated()), this, SLOT(setRectangleDrawMode())); |
142 | m_pRectangleDrawModeAction->addTo(drawModeToolBar); | 154 | m_pRectangleDrawModeAction->addTo(drawModeToolBar); |
143 | 155 | ||
144 | m_pEllipseDrawModeAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), QString::null, 0, this); | 156 | m_pEllipseDrawModeAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), QString::null, 0, this); |
145 | m_pEllipseDrawModeAction->setToggleAction(true); | 157 | m_pEllipseDrawModeAction->setToggleAction(true); |
146 | connect(m_pEllipseDrawModeAction, SIGNAL(activated()), this, SLOT(setEllipseDrawMode())); | 158 | connect(m_pEllipseDrawModeAction, SIGNAL(activated()), this, SLOT(setEllipseDrawMode())); |
147 | m_pEllipseDrawModeAction->addTo(drawModeToolBar); | 159 | m_pEllipseDrawModeAction->addTo(drawModeToolBar); |
148 | 160 | ||
149 | m_pFillDrawModeAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); | 161 | m_pFillDrawModeAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); |
150 | m_pFillDrawModeAction->setToggleAction(true); | 162 | m_pFillDrawModeAction->setToggleAction(true); |
151 | connect(m_pFillDrawModeAction, SIGNAL(activated()), this, SLOT(setFillDrawMode())); | 163 | connect(m_pFillDrawModeAction, SIGNAL(activated()), this, SLOT(setFillDrawMode())); |
152 | m_pFillDrawModeAction->addTo(drawModeToolBar); | 164 | m_pFillDrawModeAction->addTo(drawModeToolBar); |
153 | 165 | ||
154 | m_pEraseDrawModeAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); | 166 | m_pEraseDrawModeAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); |
155 | m_pEraseDrawModeAction->setToggleAction(true); | 167 | m_pEraseDrawModeAction->setToggleAction(true); |
156 | connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode())); | 168 | connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode())); |
157 | m_pEraseDrawModeAction->addTo(drawModeToolBar); | 169 | m_pEraseDrawModeAction->addTo(drawModeToolBar); |
158 | 170 | ||
159 | m_pDrawMode = 0; | 171 | m_pDrawMode = 0; |
160 | setPointDrawMode(); | 172 | setPointDrawMode(); |
161 | 173 | ||
162 | emptyToolBar = new QPEToolBar(this); | 174 | emptyToolBar = new QPEToolBar(this); |
163 | emptyToolBar->setHorizontalStretchable(true); | 175 | emptyToolBar->setHorizontalStretchable(true); |
176 | emptyToolBar->addSeparator(); | ||
177 | |||
178 | // init draw parameters toolbar | ||
164 | 179 | ||
165 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); | 180 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); |
166 | 181 | ||
167 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); | 182 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); |
168 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); | 183 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); |
169 | 184 | ||
170 | penWidthSpinBox->setValue(1); | 185 | penWidthSpinBox->setValue(1); |
171 | 186 | ||
172 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); | 187 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); |
173 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); | 188 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); |
174 | 189 | ||
175 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); | 190 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); |
176 | connect(penColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changePenColor(int))); | 191 | connect(penColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changePenColor(int))); |
177 | 192 | ||
178 | QPixmap penColorPixmap(14, 14); | 193 | QPixmap penColorPixmap(14, 14); |
179 | 194 | ||
180 | for (uint i = 0; i < m_colors.size(); i++) { | 195 | for (uint i = 0; i < m_colors.size(); i++) { |
181 | penColorPixmap.fill(m_colors.at(i)); | 196 | penColorPixmap.fill(m_colors.at(i)); |
182 | penColorPopupMenu->insertItem(penColorPixmap, i); | 197 | penColorPopupMenu->insertItem(penColorPixmap, i); |
183 | } | 198 | } |
184 | 199 | ||
185 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); | 200 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); |
186 | m_pPenColorToolButton->setPopup(penColorPopupMenu); | 201 | m_pPenColorToolButton->setPopup(penColorPopupMenu); |
187 | m_pPenColorToolButton->setPopupDelay(0); | 202 | m_pPenColorToolButton->setPopupDelay(0); |
188 | 203 | ||
189 | penColorPopupMenu->activateItemAt(0); | 204 | penColorPopupMenu->activateItemAt(0); |
190 | 205 | ||
191 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); | 206 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); |
192 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); | 207 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); |
193 | 208 | ||
194 | QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); | 209 | QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); |
195 | connect(brushColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changeBrushColor(int))); | 210 | connect(brushColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changeBrushColor(int))); |
196 | 211 | ||
197 | QPixmap brushColorPixmap(14, 14); | 212 | QPixmap brushColorPixmap(14, 14); |
198 | 213 | ||
199 | for (uint i = 0; i < m_colors.size(); i++) { | 214 | for (uint i = 0; i < m_colors.size(); i++) { |
200 | brushColorPixmap.fill(m_colors.at(i)); | 215 | brushColorPixmap.fill(m_colors.at(i)); |
201 | brushColorPopupMenu->insertItem(brushColorPixmap, i); | 216 | brushColorPopupMenu->insertItem(brushColorPixmap, i); |
202 | } | 217 | } |
203 | 218 | ||
204 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); | 219 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); |
205 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); | 220 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); |
206 | m_pBrushColorToolButton->setPopupDelay(0); | 221 | m_pBrushColorToolButton->setPopupDelay(0); |
207 | 222 | ||
208 | brushColorPopupMenu->activateItemAt(1); | 223 | brushColorPopupMenu->activateItemAt(1); |
209 | } | 224 | } |
210 | 225 | ||
211 | DrawPad::~DrawPad() | 226 | DrawPad::~DrawPad() |
212 | { | 227 | { |
213 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 228 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
214 | 229 | ||
215 | if (file.open(IO_WriteOnly)) { | 230 | if (file.open(IO_WriteOnly)) { |
216 | m_pDrawPadCanvas->save(&file); | 231 | m_pDrawPadCanvas->save(&file); |
217 | file.close(); | 232 | file.close(); |
218 | } | 233 | } |
219 | } | 234 | } |
220 | 235 | ||
221 | void DrawPad::clearAll() | ||
222 | { | ||
223 | m_pDrawPadCanvas->clearAll(); | ||
224 | updateNavigationToolBar(); | ||
225 | } | ||
226 | |||
227 | void DrawPad::newPage() | ||
228 | { | ||
229 | m_pDrawPadCanvas->newPage(); | ||
230 | updateNavigationToolBar(); | ||
231 | } | ||
232 | |||
233 | void DrawPad::deletePage() | ||
234 | { | ||
235 | m_pDrawPadCanvas->deletePage(); | ||
236 | updateNavigationToolBar(); | ||
237 | } | ||
238 | |||
239 | void DrawPad::goFirstPage() | ||
240 | { | ||
241 | m_pDrawPadCanvas->goFirstPage(); | ||
242 | updateNavigationToolBar(); | ||
243 | } | ||
244 | |||
245 | void DrawPad::goPreviousPage() | ||
246 | { | ||
247 | m_pDrawPadCanvas->goPreviousPage(); | ||
248 | updateNavigationToolBar(); | ||
249 | } | ||
250 | |||
251 | void DrawPad::goNextPage() | ||
252 | { | ||
253 | m_pDrawPadCanvas->goNextPage(); | ||
254 | updateNavigationToolBar(); | ||
255 | } | ||
256 | |||
257 | void DrawPad::goLastPage() | ||
258 | { | ||
259 | m_pDrawPadCanvas->goLastPage(); | ||
260 | updateNavigationToolBar(); | ||
261 | } | ||
262 | |||
263 | void DrawPad::setPointDrawMode() | 236 | void DrawPad::setPointDrawMode() |
264 | { | 237 | { |
265 | if (m_pDrawMode) { | 238 | if (m_pDrawMode) { |
266 | delete m_pDrawMode; | 239 | delete m_pDrawMode; |
267 | } | 240 | } |
268 | 241 | ||
269 | m_pDrawMode = new PointDrawMode(this, m_pDrawPadCanvas); | 242 | m_pDrawMode = new PointDrawMode(this, m_pDrawPadCanvas); |
270 | 243 | ||
271 | m_pPointDrawModeAction->setOn(true); | 244 | m_pPointDrawModeAction->setOn(true); |
272 | m_pLineDrawModeAction->setOn(false); | 245 | m_pLineDrawModeAction->setOn(false); |
273 | m_pRectangleDrawModeAction->setOn(false); | 246 | m_pRectangleDrawModeAction->setOn(false); |
274 | m_pEllipseDrawModeAction->setOn(false); | 247 | m_pEllipseDrawModeAction->setOn(false); |
275 | m_pFillDrawModeAction->setOn(false); | 248 | m_pFillDrawModeAction->setOn(false); |
276 | m_pEraseDrawModeAction->setOn(false); | 249 | m_pEraseDrawModeAction->setOn(false); |
277 | } | 250 | } |
278 | 251 | ||
279 | void DrawPad::setLineDrawMode() | 252 | void DrawPad::setLineDrawMode() |
280 | { | 253 | { |
281 | if (m_pDrawMode) { | 254 | if (m_pDrawMode) { |
282 | delete m_pDrawMode; | 255 | delete m_pDrawMode; |
283 | } | 256 | } |
284 | 257 | ||
285 | m_pDrawMode = new LineDrawMode(this, m_pDrawPadCanvas); | 258 | m_pDrawMode = new LineDrawMode(this, m_pDrawPadCanvas); |
286 | 259 | ||
287 | m_pPointDrawModeAction->setOn(false); | 260 | m_pPointDrawModeAction->setOn(false); |
288 | m_pLineDrawModeAction->setOn(true); | 261 | m_pLineDrawModeAction->setOn(true); |
289 | m_pRectangleDrawModeAction->setOn(false); | 262 | m_pRectangleDrawModeAction->setOn(false); |
290 | m_pEllipseDrawModeAction->setOn(false); | 263 | m_pEllipseDrawModeAction->setOn(false); |
291 | m_pFillDrawModeAction->setOn(false); | 264 | m_pFillDrawModeAction->setOn(false); |
292 | m_pEraseDrawModeAction->setOn(false); | 265 | m_pEraseDrawModeAction->setOn(false); |
293 | } | 266 | } |
294 | 267 | ||
295 | void DrawPad::setRectangleDrawMode() | 268 | void DrawPad::setRectangleDrawMode() |
296 | { | 269 | { |
297 | if (m_pDrawMode) { | 270 | if (m_pDrawMode) { |
298 | delete m_pDrawMode; | 271 | delete m_pDrawMode; |
299 | } | 272 | } |
300 | 273 | ||
301 | m_pDrawMode = new RectangleDrawMode(this, m_pDrawPadCanvas); | 274 | m_pDrawMode = new RectangleDrawMode(this, m_pDrawPadCanvas); |
302 | 275 | ||
303 | m_pPointDrawModeAction->setOn(false); | 276 | m_pPointDrawModeAction->setOn(false); |
304 | m_pLineDrawModeAction->setOn(false); | 277 | m_pLineDrawModeAction->setOn(false); |
305 | m_pRectangleDrawModeAction->setOn(true); | 278 | m_pRectangleDrawModeAction->setOn(true); |
306 | m_pEllipseDrawModeAction->setOn(false); | 279 | m_pEllipseDrawModeAction->setOn(false); |
307 | m_pFillDrawModeAction->setOn(false); | 280 | m_pFillDrawModeAction->setOn(false); |
308 | m_pEraseDrawModeAction->setOn(false); | 281 | m_pEraseDrawModeAction->setOn(false); |
309 | } | 282 | } |
310 | 283 | ||
311 | void DrawPad::setEllipseDrawMode() | 284 | void DrawPad::setEllipseDrawMode() |
312 | { | 285 | { |
313 | if (m_pDrawMode) { | 286 | if (m_pDrawMode) { |
314 | delete m_pDrawMode; | 287 | delete m_pDrawMode; |
315 | } | 288 | } |
316 | 289 | ||
317 | m_pDrawMode = new EllipseDrawMode(this, m_pDrawPadCanvas); | 290 | m_pDrawMode = new EllipseDrawMode(this, m_pDrawPadCanvas); |
318 | 291 | ||
319 | m_pPointDrawModeAction->setOn(false); | 292 | m_pPointDrawModeAction->setOn(false); |
320 | m_pLineDrawModeAction->setOn(false); | 293 | m_pLineDrawModeAction->setOn(false); |
321 | m_pRectangleDrawModeAction->setOn(false); | 294 | m_pRectangleDrawModeAction->setOn(false); |
322 | m_pEllipseDrawModeAction->setOn(true); | 295 | m_pEllipseDrawModeAction->setOn(true); |
323 | m_pFillDrawModeAction->setOn(false); | 296 | m_pFillDrawModeAction->setOn(false); |
324 | m_pEraseDrawModeAction->setOn(false); | 297 | m_pEraseDrawModeAction->setOn(false); |
325 | } | 298 | } |
326 | 299 | ||
327 | void DrawPad::setFillDrawMode() | 300 | void DrawPad::setFillDrawMode() |
328 | { | 301 | { |
329 | if (m_pDrawMode) { | 302 | if (m_pDrawMode) { |
330 | delete m_pDrawMode; | 303 | delete m_pDrawMode; |
331 | } | 304 | } |
332 | 305 | ||
333 | m_pDrawMode = new FillDrawMode(this, m_pDrawPadCanvas); | 306 | m_pDrawMode = new FillDrawMode(this, m_pDrawPadCanvas); |
334 | 307 | ||
335 | m_pPointDrawModeAction->setOn(false); | 308 | m_pPointDrawModeAction->setOn(false); |
336 | m_pLineDrawModeAction->setOn(false); | 309 | m_pLineDrawModeAction->setOn(false); |
337 | m_pRectangleDrawModeAction->setOn(false); | 310 | m_pRectangleDrawModeAction->setOn(false); |
338 | m_pEllipseDrawModeAction->setOn(false); | 311 | m_pEllipseDrawModeAction->setOn(false); |
339 | m_pFillDrawModeAction->setOn(true); | 312 | m_pFillDrawModeAction->setOn(true); |
340 | m_pEraseDrawModeAction->setOn(false); | 313 | m_pEraseDrawModeAction->setOn(false); |
341 | } | 314 | } |
342 | 315 | ||
343 | void DrawPad::setEraseDrawMode() | 316 | void DrawPad::setEraseDrawMode() |
344 | { | 317 | { |
345 | if (m_pDrawMode) { | 318 | if (m_pDrawMode) { |
346 | delete m_pDrawMode; | 319 | delete m_pDrawMode; |
347 | } | 320 | } |
348 | 321 | ||
349 | m_pDrawMode = new EraseDrawMode(this, m_pDrawPadCanvas); | 322 | m_pDrawMode = new EraseDrawMode(this, m_pDrawPadCanvas); |
350 | 323 | ||
351 | m_pPointDrawModeAction->setOn(false); | 324 | m_pPointDrawModeAction->setOn(false); |
352 | m_pLineDrawModeAction->setOn(false); | 325 | m_pLineDrawModeAction->setOn(false); |
353 | m_pRectangleDrawModeAction->setOn(false); | 326 | m_pRectangleDrawModeAction->setOn(false); |
354 | m_pEllipseDrawModeAction->setOn(false); | 327 | m_pEllipseDrawModeAction->setOn(false); |
355 | m_pFillDrawModeAction->setOn(false); | 328 | m_pFillDrawModeAction->setOn(false); |
356 | m_pEraseDrawModeAction->setOn(true); | 329 | m_pEraseDrawModeAction->setOn(true); |
357 | } | 330 | } |
358 | 331 | ||
359 | void DrawPad::changePenWidth(int value) | 332 | void DrawPad::changePenWidth(int value) |
360 | { | 333 | { |
361 | m_pen.setWidth(value); | 334 | m_pen.setWidth(value); |
362 | } | 335 | } |
363 | 336 | ||
364 | void DrawPad::changePenColor(int index) | 337 | void DrawPad::changePenColor(int index) |
365 | { | 338 | { |
366 | m_pen.setColor(m_colors.at(index)); | 339 | m_pen.setColor(m_colors.at(index)); |
367 | 340 | ||
368 | QPainter painter; | 341 | QPainter painter; |
369 | painter.begin(m_pPenColorToolButton->pixmap()); | 342 | painter.begin(m_pPenColorToolButton->pixmap()); |
370 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); | 343 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); |
371 | painter.end(); | 344 | painter.end(); |
372 | } | 345 | } |
373 | 346 | ||
374 | void DrawPad::changeBrushColor(int index) | 347 | void DrawPad::changeBrushColor(int index) |
375 | { | 348 | { |
376 | m_brush = QBrush(m_colors.at(index)); | 349 | m_brush = QBrush(m_colors.at(index)); |
377 | 350 | ||
378 | QPainter painter; | 351 | QPainter painter; |
379 | painter.begin(m_pBrushColorToolButton->pixmap()); | 352 | painter.begin(m_pBrushColorToolButton->pixmap()); |
380 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); | 353 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); |
381 | painter.end(); | 354 | painter.end(); |
382 | } | 355 | } |
383 | 356 | ||
384 | void DrawPad::updateNavigationToolBar() | 357 | void DrawPad::updateUndoRedoToolButtons() |
358 | { | ||
359 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); | ||
360 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); | ||
361 | } | ||
362 | |||
363 | void DrawPad::updateNavigationToolButtons() | ||
385 | { | 364 | { |
386 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 365 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
387 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 366 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
388 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 367 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
389 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 368 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
390 | } | 369 | } |
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index 0ece408..ee81ddf 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h | |||
@@ -1,88 +1,83 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #ifndef DRAWPAD_H | 14 | #ifndef DRAWPAD_H |
15 | #define DRAWPAD_H | 15 | #define DRAWPAD_H |
16 | 16 | ||
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | 18 | ||
19 | #include <qpen.h> | 19 | #include <qpen.h> |
20 | 20 | ||
21 | class DrawMode; | 21 | class DrawMode; |
22 | class DrawPadCanvas; | 22 | class DrawPadCanvas; |
23 | 23 | ||
24 | class QAction; | 24 | class QAction; |
25 | class QColor; | 25 | class QColor; |
26 | class QToolButton; | 26 | class QToolButton; |
27 | class QWidgetStack; | 27 | class QWidgetStack; |
28 | 28 | ||
29 | class DrawPad : public QMainWindow | 29 | class DrawPad : public QMainWindow |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | 32 | ||
33 | public: | 33 | public: |
34 | DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel); | 34 | DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel); |
35 | ~DrawPad(); | 35 | ~DrawPad(); |
36 | 36 | ||
37 | DrawMode* drawMode() { return m_pDrawMode; } | 37 | DrawMode* drawMode() { return m_pDrawMode; } |
38 | QPen pen() { return m_pen; } | 38 | QPen pen() { return m_pen; } |
39 | QBrush brush() { return m_brush; } | 39 | QBrush brush() { return m_brush; } |
40 | 40 | ||
41 | private slots: | 41 | private slots: |
42 | void clearAll(); | ||
43 | void newPage(); | ||
44 | void deletePage(); | ||
45 | |||
46 | void goFirstPage(); | ||
47 | void goPreviousPage(); | ||
48 | void goNextPage(); | ||
49 | void goLastPage(); | ||
50 | |||
51 | void setPointDrawMode(); | 42 | void setPointDrawMode(); |
52 | void setLineDrawMode(); | 43 | void setLineDrawMode(); |
53 | void setRectangleDrawMode(); | 44 | void setRectangleDrawMode(); |
54 | void setEllipseDrawMode(); | 45 | void setEllipseDrawMode(); |
55 | void setFillDrawMode(); | 46 | void setFillDrawMode(); |
56 | void setEraseDrawMode(); | 47 | void setEraseDrawMode(); |
57 | 48 | ||
58 | void changePenWidth(int value); | 49 | void changePenWidth(int value); |
59 | void changePenColor(int index); | 50 | void changePenColor(int index); |
60 | void changeBrushColor(int index); | 51 | void changeBrushColor(int index); |
61 | 52 | ||
62 | private: | 53 | void updateUndoRedoToolButtons(); |
63 | void updateNavigationToolBar(); | 54 | void updateNavigationToolButtons(); |
64 | 55 | ||
56 | private: | ||
65 | DrawPadCanvas* m_pDrawPadCanvas; | 57 | DrawPadCanvas* m_pDrawPadCanvas; |
66 | QArray<QColor> m_colors; | 58 | QArray<QColor> m_colors; |
67 | 59 | ||
68 | DrawMode* m_pDrawMode; | 60 | DrawMode* m_pDrawMode; |
69 | QPen m_pen; | 61 | QPen m_pen; |
70 | QBrush m_brush; | 62 | QBrush m_brush; |
71 | 63 | ||
64 | QAction* m_pUndoAction; | ||
65 | QAction* m_pRedoAction; | ||
66 | |||
72 | QAction* m_pFirstPageAction; | 67 | QAction* m_pFirstPageAction; |
73 | QAction* m_pPreviousPageAction; | 68 | QAction* m_pPreviousPageAction; |
74 | QAction* m_pNextPageAction; | 69 | QAction* m_pNextPageAction; |
75 | QAction* m_pLastPageAction; | 70 | QAction* m_pLastPageAction; |
76 | 71 | ||
77 | QAction* m_pPointDrawModeAction; | 72 | QAction* m_pPointDrawModeAction; |
78 | QAction* m_pLineDrawModeAction; | 73 | QAction* m_pLineDrawModeAction; |
79 | QAction* m_pRectangleDrawModeAction; | 74 | QAction* m_pRectangleDrawModeAction; |
80 | QAction* m_pEllipseDrawModeAction; | 75 | QAction* m_pEllipseDrawModeAction; |
81 | QAction* m_pFillDrawModeAction; | 76 | QAction* m_pFillDrawModeAction; |
82 | QAction* m_pEraseDrawModeAction; | 77 | QAction* m_pEraseDrawModeAction; |
83 | 78 | ||
84 | QToolButton* m_pPenColorToolButton; | 79 | QToolButton* m_pPenColorToolButton; |
85 | QToolButton* m_pBrushColorToolButton; | 80 | QToolButton* m_pBrushColorToolButton; |
86 | }; | 81 | }; |
87 | 82 | ||
88 | #endif // DRAWPAD_H | 83 | #endif // DRAWPAD_H |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index f02f478..08f7b66 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -1,339 +1,420 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "drawpadcanvas.h" | 14 | #include "drawpadcanvas.h" |
15 | 15 | ||
16 | #include "drawmode.h" | 16 | #include "drawmode.h" |
17 | #include "drawpad.h" | 17 | #include "drawpad.h" |
18 | 18 | ||
19 | #include <qbuffer.h> | 19 | #include <qbuffer.h> |
20 | #include <qimage.h> | 20 | #include <qimage.h> |
21 | #include <qpainter.h> | 21 | #include <qpainter.h> |
22 | #include <qpixmap.h> | 22 | #include <qpixmap.h> |
23 | #include <qtextcodec.h> | 23 | #include <qtextcodec.h> |
24 | #include <qtextstream.h> | 24 | #include <qtextstream.h> |
25 | #include <qxml.h> | 25 | #include <qxml.h> |
26 | 26 | ||
27 | #include <zlib.h> | 27 | #include <zlib.h> |
28 | 28 | ||
29 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 29 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
30 | { | 30 | { |
31 | public: | 31 | public: |
32 | DrawPadCanvasXmlHandler(); | 32 | DrawPadCanvasXmlHandler(); |
33 | ~DrawPadCanvasXmlHandler(); | 33 | ~DrawPadCanvasXmlHandler(); |
34 | 34 | ||
35 | QList<QPixmap> pixmaps(); | 35 | QList<QPixmap> pixmaps(); |
36 | 36 | ||
37 | bool startElement(const QString& namespaceURI, const QString& localName, | 37 | bool startElement(const QString& namespaceURI, const QString& localName, |
38 | const QString& qName, const QXmlAttributes& atts); | 38 | const QString& qName, const QXmlAttributes& atts); |
39 | bool endElement(const QString& namespaceURI, const QString& localName, | 39 | bool endElement(const QString& namespaceURI, const QString& localName, |
40 | const QString& qName); | 40 | const QString& qName); |
41 | bool characters(const QString& ch); | 41 | bool characters(const QString& ch); |
42 | 42 | ||
43 | private: | 43 | private: |
44 | enum State { | 44 | enum State { |
45 | Unknown, | 45 | Unknown, |
46 | InData | 46 | InData |
47 | }; | 47 | }; |
48 | 48 | ||
49 | State m_state; | 49 | State m_state; |
50 | ulong m_dataLenght; | 50 | ulong m_dataLenght; |
51 | QList<QPixmap> m_pixmaps; | 51 | QList<QPixmap> m_pixmaps; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() | 54 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() |
55 | { | 55 | { |
56 | m_state = Unknown; | 56 | m_state = Unknown; |
57 | } | 57 | } |
58 | 58 | ||
59 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() | 59 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() |
60 | { | 60 | { |
61 | } | 61 | } |
62 | 62 | ||
63 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() | 63 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() |
64 | { | 64 | { |
65 | return m_pixmaps; | 65 | return m_pixmaps; |
66 | } | 66 | } |
67 | 67 | ||
68 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, | 68 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, |
69 | const QString& qName, const QXmlAttributes& atts) | 69 | const QString& qName, const QXmlAttributes& atts) |
70 | { | 70 | { |
71 | Q_CONST_UNUSED(namespaceURI) | 71 | Q_CONST_UNUSED(namespaceURI) |
72 | Q_CONST_UNUSED(localName) | 72 | Q_CONST_UNUSED(localName) |
73 | 73 | ||
74 | if (qName.compare("data") == 0) { | 74 | if (qName.compare("data") == 0) { |
75 | m_state = InData; | 75 | m_state = InData; |
76 | m_dataLenght = atts.value("length").toULong(); | 76 | m_dataLenght = atts.value("length").toULong(); |
77 | } | 77 | } |
78 | 78 | ||
79 | return true; | 79 | return true; |
80 | } | 80 | } |
81 | 81 | ||
82 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, | 82 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, |
83 | const QString& qName) | 83 | const QString& qName) |
84 | { | 84 | { |
85 | Q_CONST_UNUSED(namespaceURI) | 85 | Q_CONST_UNUSED(namespaceURI) |
86 | Q_CONST_UNUSED(localName) | 86 | Q_CONST_UNUSED(localName) |
87 | 87 | ||
88 | if (qName.compare("data") == 0) { | 88 | if (qName.compare("data") == 0) { |
89 | m_state = Unknown; | 89 | m_state = Unknown; |
90 | } | 90 | } |
91 | 91 | ||
92 | return true; | 92 | return true; |
93 | } | 93 | } |
94 | 94 | ||
95 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) | 95 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) |
96 | { | 96 | { |
97 | if (m_state == InData) { | 97 | if (m_state == InData) { |
98 | QByteArray byteArray(ch.length() / 2); | 98 | QByteArray byteArray(ch.length() / 2); |
99 | 99 | ||
100 | for (int i = 0; i < (int)ch.length() / 2; i++) { | 100 | for (int i = 0; i < (int)ch.length() / 2; i++) { |
101 | char h = ch[2 * i].latin1(); | 101 | char h = ch[2 * i].latin1(); |
102 | char l = ch[2 * i + 1].latin1(); | 102 | char l = ch[2 * i + 1].latin1(); |
103 | uchar r = 0; | 103 | uchar r = 0; |
104 | 104 | ||
105 | if (h <= '9') { | 105 | if (h <= '9') { |
106 | r += h - '0'; | 106 | r += h - '0'; |
107 | } else { | 107 | } else { |
108 | r += h - 'a' + 10; | 108 | r += h - 'a' + 10; |
109 | } | 109 | } |
110 | 110 | ||
111 | r = r << 4; | 111 | r = r << 4; |
112 | 112 | ||
113 | if (l <= '9') { | 113 | if (l <= '9') { |
114 | r += l - '0'; | 114 | r += l - '0'; |
115 | } else { | 115 | } else { |
116 | r += l - 'a' + 10; | 116 | r += l - 'a' + 10; |
117 | } | 117 | } |
118 | 118 | ||
119 | byteArray[i] = r; | 119 | byteArray[i] = r; |
120 | } | 120 | } |
121 | 121 | ||
122 | if (m_dataLenght < ch.length() * 5) { | 122 | if (m_dataLenght < ch.length() * 5) { |
123 | m_dataLenght = ch.length() * 5; | 123 | m_dataLenght = ch.length() * 5; |
124 | } | 124 | } |
125 | 125 | ||
126 | QByteArray byteArrayUnzipped(m_dataLenght); | 126 | QByteArray byteArrayUnzipped(m_dataLenght); |
127 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); | 127 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); |
128 | 128 | ||
129 | QImage image; | 129 | QImage image; |
130 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM"); | 130 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM"); |
131 | 131 | ||
132 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); | 132 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); |
133 | pixmap->convertFromImage(image); | 133 | pixmap->convertFromImage(image); |
134 | m_pixmaps.append(pixmap); | 134 | m_pixmaps.append(pixmap); |
135 | } | 135 | } |
136 | 136 | ||
137 | return true; | 137 | return true; |
138 | } | 138 | } |
139 | 139 | ||
140 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f) | 140 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f) |
141 | : QWidget(parent, name, f) | 141 | : QWidget(parent, name, f) |
142 | { | 142 | { |
143 | setBackgroundMode(QWidget::PaletteBase); | 143 | setBackgroundMode(QWidget::PaletteBase); |
144 | 144 | ||
145 | m_pDrawPad = drawPad; | 145 | m_pDrawPad = drawPad; |
146 | m_buffers.setAutoDelete(true); | 146 | m_pages.setAutoDelete(true); |
147 | m_buffers.append(new QPixmap(width(), height())); | 147 | m_pages.append(new QPixmap(width(), height())); |
148 | m_buffers.current()->fill(Qt::white); | 148 | m_pages.current()->fill(Qt::white); |
149 | m_pageBackups.setAutoDelete(true); | ||
150 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
149 | } | 151 | } |
150 | 152 | ||
151 | DrawPadCanvas::~DrawPadCanvas() | 153 | DrawPadCanvas::~DrawPadCanvas() |
152 | { | 154 | { |
153 | } | 155 | } |
154 | 156 | ||
155 | void DrawPadCanvas::load(QIODevice* ioDevice) | 157 | void DrawPadCanvas::load(QIODevice* ioDevice) |
156 | { | 158 | { |
157 | QTextStream textStream(ioDevice); | 159 | QTextStream textStream(ioDevice); |
158 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 160 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
159 | 161 | ||
160 | QXmlInputSource xmlInputSource(textStream); | 162 | QXmlInputSource xmlInputSource(textStream); |
161 | QXmlSimpleReader xmlSimpleReader; | 163 | QXmlSimpleReader xmlSimpleReader; |
162 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; | 164 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; |
163 | 165 | ||
164 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); | 166 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); |
165 | xmlSimpleReader.parse(xmlInputSource); | 167 | xmlSimpleReader.parse(xmlInputSource); |
166 | 168 | ||
167 | m_buffers = drawPadCanvasXmlHandler.pixmaps(); | 169 | m_pages = drawPadCanvasXmlHandler.pixmaps(); |
168 | 170 | ||
169 | if (m_buffers.isEmpty()) { | 171 | if (m_pages.isEmpty()) { |
170 | m_buffers.append(new QPixmap(width(), height())); | 172 | m_pages.append(new QPixmap(width(), height())); |
171 | m_buffers.current()->fill(Qt::white); | 173 | m_pages.current()->fill(Qt::white); |
172 | } | 174 | } |
173 | 175 | ||
176 | m_pageBackups.clear(); | ||
177 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
178 | |||
174 | repaint(); | 179 | repaint(); |
175 | } | 180 | } |
176 | 181 | ||
177 | void DrawPadCanvas::save(QIODevice* ioDevice) | 182 | void DrawPadCanvas::save(QIODevice* ioDevice) |
178 | { | 183 | { |
179 | QTextStream textStream(ioDevice); | 184 | QTextStream textStream(ioDevice); |
180 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 185 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
181 | 186 | ||
182 | textStream << "<drawpad>" << endl; | 187 | textStream << "<drawpad>" << endl; |
183 | textStream << " <images>" << endl; | 188 | textStream << " <images>" << endl; |
184 | 189 | ||
185 | QListIterator<QPixmap> bufferIterator(m_buffers); | 190 | QListIterator<QPixmap> bufferIterator(m_pages); |
186 | 191 | ||
187 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 192 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
188 | textStream << " <image>" << endl; | 193 | textStream << " <image>" << endl; |
189 | 194 | ||
190 | QImage image = bufferIterator.current()->convertToImage(); | 195 | QImage image = bufferIterator.current()->convertToImage(); |
191 | QByteArray byteArray; | 196 | QByteArray byteArray; |
192 | QBuffer buffer(byteArray); | 197 | QBuffer buffer(byteArray); |
193 | QImageIO imageIO(&buffer, "XPM"); | 198 | QImageIO imageIO(&buffer, "XPM"); |
194 | 199 | ||
195 | buffer.open(IO_WriteOnly); | 200 | buffer.open(IO_WriteOnly); |
196 | imageIO.setImage(image); | 201 | imageIO.setImage(image); |
197 | imageIO.write(); | 202 | imageIO.write(); |
198 | buffer.close(); | 203 | buffer.close(); |
199 | 204 | ||
200 | ulong size = byteArray.size() * 2; | 205 | ulong size = byteArray.size() * 2; |
201 | QByteArray byteArrayZipped(size); | 206 | QByteArray byteArrayZipped(size); |
202 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); | 207 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); |
203 | 208 | ||
204 | textStream << " <data length=\"" << byteArray.size() << "\">"; | 209 | textStream << " <data length=\"" << byteArray.size() << "\">"; |
205 | 210 | ||
206 | static const char hexchars[] = "0123456789abcdef"; | 211 | static const char hexchars[] = "0123456789abcdef"; |
207 | 212 | ||
208 | for (int i = 0; i < (int)size; i++ ) { | 213 | for (int i = 0; i < (int)size; i++ ) { |
209 | uchar s = (uchar)byteArrayZipped[i]; | 214 | uchar s = (uchar)byteArrayZipped[i]; |
210 | textStream << hexchars[s >> 4]; | 215 | textStream << hexchars[s >> 4]; |
211 | textStream << hexchars[s & 0x0f]; | 216 | textStream << hexchars[s & 0x0f]; |
212 | } | 217 | } |
213 | 218 | ||
214 | textStream << "</data>" << endl; | 219 | textStream << "</data>" << endl; |
215 | textStream << " </image>" << endl; | 220 | textStream << " </image>" << endl; |
216 | } | 221 | } |
217 | 222 | ||
218 | textStream << " </images>" << endl; | 223 | textStream << " </images>" << endl; |
219 | textStream << "</drawpad>"; | 224 | textStream << "</drawpad>"; |
220 | } | 225 | } |
221 | 226 | ||
222 | QPixmap* DrawPadCanvas::currentPage() | 227 | QPixmap* DrawPadCanvas::currentPage() |
223 | { | 228 | { |
224 | return m_buffers.current(); | 229 | return m_pages.current(); |
225 | } | 230 | } |
226 | 231 | ||
227 | void DrawPadCanvas::clearAll() | 232 | void DrawPadCanvas::clearAll() |
228 | { | 233 | { |
229 | m_buffers.clear(); | 234 | m_pages.clear(); |
235 | |||
236 | m_pages.append(new QPixmap(width(), height())); | ||
237 | m_pages.current()->fill(Qt::white); | ||
230 | 238 | ||
231 | m_buffers.append(new QPixmap(width(), height())); | 239 | m_pageBackups.clear(); |
232 | m_buffers.current()->fill(Qt::white); | 240 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); |
233 | 241 | ||
234 | repaint(); | 242 | repaint(); |
243 | |||
244 | emit pagesChanged(); | ||
245 | emit pageBackupsChanged(); | ||
235 | } | 246 | } |
236 | 247 | ||
237 | void DrawPadCanvas::newPage() | 248 | void DrawPadCanvas::newPage() |
238 | { | 249 | { |
239 | m_buffers.insert(m_buffers.at() + 1, new QPixmap(width(), height())); | 250 | m_pages.insert(m_pages.at() + 1, new QPixmap(width(), height())); |
240 | m_buffers.current()->fill(Qt::white); | 251 | m_pages.current()->fill(Qt::white); |
252 | m_pageBackups.clear(); | ||
253 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
241 | repaint(); | 254 | repaint(); |
255 | |||
256 | emit pagesChanged(); | ||
257 | emit pageBackupsChanged(); | ||
242 | } | 258 | } |
243 | 259 | ||
244 | void DrawPadCanvas::clearPage() | 260 | void DrawPadCanvas::clearPage() |
245 | { | 261 | { |
246 | m_buffers.current()->fill(Qt::white); | 262 | m_pages.current()->fill(Qt::white); |
247 | repaint(); | 263 | repaint(); |
248 | } | 264 | } |
249 | 265 | ||
250 | void DrawPadCanvas::deletePage() | 266 | void DrawPadCanvas::deletePage() |
251 | { | 267 | { |
252 | m_buffers.remove(m_buffers.current()); | 268 | m_pages.remove(m_pages.current()); |
253 | 269 | ||
254 | if (m_buffers.isEmpty()) { | 270 | if (m_pages.isEmpty()) { |
255 | m_buffers.append(new QPixmap(width(), height())); | 271 | m_pages.append(new QPixmap(width(), height())); |
256 | m_buffers.current()->fill(Qt::white); | 272 | m_pages.current()->fill(Qt::white); |
257 | } | 273 | } |
258 | 274 | ||
275 | m_pageBackups.clear(); | ||
276 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
277 | |||
259 | repaint(); | 278 | repaint(); |
279 | |||
280 | emit pagesChanged(); | ||
281 | emit pageBackupsChanged(); | ||
282 | } | ||
283 | |||
284 | bool DrawPadCanvas::undoEnabled() | ||
285 | { | ||
286 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | ||
287 | } | ||
288 | |||
289 | bool DrawPadCanvas::redoEnabled() | ||
290 | { | ||
291 | return (m_pageBackups.current() != m_pageBackups.getLast()); | ||
260 | } | 292 | } |
261 | 293 | ||
262 | bool DrawPadCanvas::goPreviousPageEnabled() | 294 | bool DrawPadCanvas::goPreviousPageEnabled() |
263 | { | 295 | { |
264 | return (m_buffers.current() != m_buffers.getFirst()); | 296 | return (m_pages.current() != m_pages.getFirst()); |
265 | } | 297 | } |
266 | 298 | ||
267 | bool DrawPadCanvas::goNextPageEnabled() | 299 | bool DrawPadCanvas::goNextPageEnabled() |
268 | { | 300 | { |
269 | return (m_buffers.current() != m_buffers.getLast()); | 301 | return (m_pages.current() != m_pages.getLast()); |
302 | } | ||
303 | |||
304 | void DrawPadCanvas::undo() | ||
305 | { | ||
306 | *(m_pages.current()) = *(m_pageBackups.prev()); | ||
307 | repaint(); | ||
308 | |||
309 | emit pageBackupsChanged(); | ||
310 | } | ||
311 | |||
312 | void DrawPadCanvas::redo() | ||
313 | { | ||
314 | *(m_pages.current()) = *(m_pageBackups.next()); | ||
315 | repaint(); | ||
316 | |||
317 | emit pageBackupsChanged(); | ||
270 | } | 318 | } |
271 | 319 | ||
272 | void DrawPadCanvas::goFirstPage() | 320 | void DrawPadCanvas::goFirstPage() |
273 | { | 321 | { |
274 | m_buffers.first(); | 322 | m_pages.first(); |
323 | m_pageBackups.clear(); | ||
324 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
275 | repaint(); | 325 | repaint(); |
326 | |||
327 | emit pagesChanged(); | ||
328 | emit pageBackupsChanged(); | ||
276 | } | 329 | } |
277 | 330 | ||
278 | void DrawPadCanvas::goPreviousPage() | 331 | void DrawPadCanvas::goPreviousPage() |
279 | { | 332 | { |
280 | m_buffers.prev(); | 333 | m_pages.prev(); |
334 | m_pageBackups.clear(); | ||
335 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
281 | repaint(); | 336 | repaint(); |
337 | |||
338 | emit pagesChanged(); | ||
339 | emit pageBackupsChanged(); | ||
282 | } | 340 | } |
283 | 341 | ||
284 | void DrawPadCanvas::goNextPage() | 342 | void DrawPadCanvas::goNextPage() |
285 | { | 343 | { |
286 | m_buffers.next(); | 344 | m_pages.next(); |
345 | m_pageBackups.clear(); | ||
346 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
287 | repaint(); | 347 | repaint(); |
348 | |||
349 | emit pagesChanged(); | ||
350 | emit pageBackupsChanged(); | ||
288 | } | 351 | } |
289 | 352 | ||
290 | void DrawPadCanvas::goLastPage() | 353 | void DrawPadCanvas::goLastPage() |
291 | { | 354 | { |
292 | m_buffers.last(); | 355 | m_pages.last(); |
356 | m_pageBackups.clear(); | ||
357 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
293 | repaint(); | 358 | repaint(); |
359 | |||
360 | emit pagesChanged(); | ||
361 | emit pageBackupsChanged(); | ||
294 | } | 362 | } |
295 | 363 | ||
296 | void DrawPadCanvas::mousePressEvent(QMouseEvent* e) | 364 | void DrawPadCanvas::mousePressEvent(QMouseEvent* e) |
297 | { | 365 | { |
298 | m_pDrawPad->drawMode()->mousePressEvent(e); | 366 | m_pDrawPad->drawMode()->mousePressEvent(e); |
299 | } | 367 | } |
300 | 368 | ||
301 | void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) | 369 | void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) |
302 | { | 370 | { |
303 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); | 371 | m_pDrawPad->drawMode()->mouseReleaseEvent(e); |
372 | |||
373 | QPixmap* currentBackup = m_pageBackups.current(); | ||
374 | while (m_pageBackups.last() != currentBackup) { | ||
375 | m_pageBackups.removeLast(); | ||
376 | } | ||
377 | |||
378 | while (m_pageBackups.count() >= (5 + 1)) { | ||
379 | m_pageBackups.removeFirst(); | ||
380 | } | ||
381 | |||
382 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | ||
383 | |||
384 | emit pageBackupsChanged(); | ||
304 | } | 385 | } |
305 | 386 | ||
306 | void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) | 387 | void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) |
307 | { | 388 | { |
308 | m_pDrawPad->drawMode()->mouseMoveEvent(e); | 389 | m_pDrawPad->drawMode()->mouseMoveEvent(e); |
309 | } | 390 | } |
310 | 391 | ||
311 | void DrawPadCanvas::resizeEvent(QResizeEvent* e) | 392 | void DrawPadCanvas::resizeEvent(QResizeEvent* e) |
312 | { | 393 | { |
313 | QWidget::resizeEvent(e); | 394 | QWidget::resizeEvent(e); |
314 | 395 | ||
315 | QListIterator<QPixmap> bufferIterator(m_buffers); | 396 | QListIterator<QPixmap> bufferIterator(m_pages); |
316 | 397 | ||
317 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 398 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
318 | int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width(); | 399 | int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width(); |
319 | int h = height() > bufferIterator.current()->height() ? height() : bufferIterator.current()->height(); | 400 | int h = height() > bufferIterator.current()->height() ? height() : bufferIterator.current()->height(); |
320 | 401 | ||
321 | QPixmap tmpPixmap(*(bufferIterator.current())); | 402 | QPixmap tmpPixmap(*(bufferIterator.current())); |
322 | bufferIterator.current()->resize(w, h); | 403 | bufferIterator.current()->resize(w, h); |
323 | bufferIterator.current()->fill(Qt::white); | 404 | bufferIterator.current()->fill(Qt::white); |
324 | 405 | ||
325 | bitBlt(bufferIterator.current(), 0, 0, &tmpPixmap, 0, 0, tmpPixmap.width(), tmpPixmap.height()); | 406 | bitBlt(bufferIterator.current(), 0, 0, &tmpPixmap, 0, 0, tmpPixmap.width(), tmpPixmap.height()); |
326 | } | 407 | } |
327 | } | 408 | } |
328 | 409 | ||
329 | void DrawPadCanvas::paintEvent(QPaintEvent* e) | 410 | void DrawPadCanvas::paintEvent(QPaintEvent* e) |
330 | { | 411 | { |
331 | QWidget::paintEvent(e); | 412 | QWidget::paintEvent(e); |
332 | 413 | ||
333 | QArray<QRect> rects = e->region().rects(); | 414 | QArray<QRect> rects = e->region().rects(); |
334 | 415 | ||
335 | for (uint i = 0; i < rects.count(); i++) { | 416 | for (uint i = 0; i < rects.count(); i++) { |
336 | QRect r = rects[i]; | 417 | QRect r = rects[i]; |
337 | bitBlt(this, r.x(), r.y(), m_buffers.current(), r.x(), r.y(), r.width(), r.height()); | 418 | bitBlt(this, r.x(), r.y(), m_pages.current(), r.x(), r.y(), r.width(), r.height()); |
338 | } | 419 | } |
339 | } | 420 | } |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index 2ec9298..eddcb43 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h | |||
@@ -1,65 +1,75 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #ifndef DRAWPADCANVAS_H | 14 | #ifndef DRAWPADCANVAS_H |
15 | #define DRAWPADCANVAS_H | 15 | #define DRAWPADCANVAS_H |
16 | 16 | ||
17 | #include <qwidget.h> | 17 | #include <qwidget.h> |
18 | 18 | ||
19 | #include <qlist.h> | 19 | #include <qlist.h> |
20 | #include <qpointarray.h> | 20 | #include <qpointarray.h> |
21 | 21 | ||
22 | class DrawPad; | 22 | class DrawPad; |
23 | 23 | ||
24 | class QPixmap; | 24 | class QPixmap; |
25 | 25 | ||
26 | class DrawPadCanvas : public QWidget | 26 | class DrawPadCanvas : public QWidget |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | 29 | ||
30 | public: | 30 | public: |
31 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0, WFlags f = 0); | 31 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0, WFlags f = 0); |
32 | ~DrawPadCanvas(); | 32 | ~DrawPadCanvas(); |
33 | 33 | ||
34 | void load(QIODevice* ioDevice); | 34 | void load(QIODevice* ioDevice); |
35 | void save(QIODevice* ioDevice); | 35 | void save(QIODevice* ioDevice); |
36 | 36 | ||
37 | bool undoEnabled(); | ||
38 | bool redoEnabled(); | ||
37 | bool goPreviousPageEnabled(); | 39 | bool goPreviousPageEnabled(); |
38 | bool goNextPageEnabled(); | 40 | bool goNextPageEnabled(); |
39 | 41 | ||
40 | QPixmap* currentPage(); | 42 | QPixmap* currentPage(); |
41 | 43 | ||
42 | public slots: | 44 | public slots: |
43 | void clearAll(); | 45 | void clearAll(); |
44 | void newPage(); | 46 | void newPage(); |
45 | void clearPage(); | 47 | void clearPage(); |
46 | void deletePage(); | 48 | void deletePage(); |
47 | 49 | ||
50 | void undo(); | ||
51 | void redo(); | ||
52 | |||
48 | void goFirstPage(); | 53 | void goFirstPage(); |
49 | void goPreviousPage(); | 54 | void goPreviousPage(); |
50 | void goNextPage(); | 55 | void goNextPage(); |
51 | void goLastPage(); | 56 | void goLastPage(); |
52 | 57 | ||
58 | signals: | ||
59 | void pagesChanged(); | ||
60 | void pageBackupsChanged(); | ||
61 | |||
53 | protected: | 62 | protected: |
54 | void mousePressEvent(QMouseEvent* e); | 63 | void mousePressEvent(QMouseEvent* e); |
55 | void mouseReleaseEvent(QMouseEvent* e); | 64 | void mouseReleaseEvent(QMouseEvent* e); |
56 | void mouseMoveEvent(QMouseEvent* e); | 65 | void mouseMoveEvent(QMouseEvent* e); |
57 | void resizeEvent(QResizeEvent* e); | 66 | void resizeEvent(QResizeEvent* e); |
58 | void paintEvent(QPaintEvent* e); | 67 | void paintEvent(QPaintEvent* e); |
59 | 68 | ||
60 | private: | 69 | private: |
61 | DrawPad* m_pDrawPad; | 70 | DrawPad* m_pDrawPad; |
62 | QList<QPixmap> m_buffers; | 71 | QList<QPixmap> m_pages; |
72 | QList<QPixmap> m_pageBackups; | ||
63 | }; | 73 | }; |
64 | 74 | ||
65 | #endif // DRAWPADCANVAS_H | 75 | #endif // DRAWPADCANVAS_H |