summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp39
-rw-r--r--noncore/graphics/drawpad/drawpad.h3
-rw-r--r--noncore/graphics/drawpad/drawpad.pro8
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp138
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h18
-rw-r--r--noncore/graphics/drawpad/ellipsedrawmode.cpp63
-rw-r--r--noncore/graphics/drawpad/ellipsedrawmode.h16
-rw-r--r--noncore/graphics/drawpad/erasedrawmode.cpp8
-rw-r--r--noncore/graphics/drawpad/filldrawmode.cpp2
-rw-r--r--noncore/graphics/drawpad/linedrawmode.cpp60
-rw-r--r--noncore/graphics/drawpad/linedrawmode.h16
-rw-r--r--noncore/graphics/drawpad/newpagedialog.cpp61
-rw-r--r--noncore/graphics/drawpad/newpagedialog.h40
-rw-r--r--noncore/graphics/drawpad/pointdrawmode.cpp8
-rw-r--r--noncore/graphics/drawpad/rectangledrawmode.cpp60
-rw-r--r--noncore/graphics/drawpad/rectangledrawmode.h16
-rw-r--r--noncore/graphics/drawpad/shapedrawmode.cpp92
-rw-r--r--noncore/graphics/drawpad/shapedrawmode.h41
18 files changed, 415 insertions, 274 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index f67bef8..e94187f 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -14,66 +14,59 @@
14#include "drawpad.h" 14#include "drawpad.h"
15 15
16#include "colordialog.h" 16#include "colordialog.h"
17#include "colorpanel.h" 17#include "colorpanel.h"
18#include "drawpadcanvas.h" 18#include "drawpadcanvas.h"
19#include "ellipsedrawmode.h" 19#include "ellipsedrawmode.h"
20#include "erasedrawmode.h" 20#include "erasedrawmode.h"
21#include "filldrawmode.h" 21#include "filldrawmode.h"
22#include "linedrawmode.h" 22#include "linedrawmode.h"
23#include "pointdrawmode.h" 23#include "pointdrawmode.h"
24#include "rectangledrawmode.h" 24#include "rectangledrawmode.h"
25 25
26#include <qpe/global.h> 26#include <qpe/global.h>
27#include <qpe/qpemenubar.h> 27#include <qpe/qpemenubar.h>
28#include <qpe/qpetoolbar.h> 28#include <qpe/qpetoolbar.h>
29#include <qpe/resource.h> 29#include <qpe/resource.h>
30 30
31#include <qaction.h> 31#include <qaction.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qspinbox.h> 34#include <qspinbox.h>
35#include <qtoolbutton.h> 35#include <qtoolbutton.h>
36#include <qtooltip.h> 36#include <qtooltip.h>
37 37
38DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) 38DrawPad::DrawPad(QWidget* parent, const char* name)
39 : QMainWindow(parent, name, f) 39 : QMainWindow(parent, name)
40{ 40{
41 setCaption(tr("DrawPad"));
42
43 // init members 41 // init members
44 42
45 m_pDrawPadCanvas = new DrawPadCanvas(this, this); 43 m_pDrawPadCanvas = new DrawPadCanvas(this, this);
44
46 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); 45 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons()));
46 connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption()));
47 connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); 47 connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons()));
48 48
49 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
50
51 if (file.open(IO_ReadOnly)) {
52 m_pDrawPadCanvas->load(&file);
53 file.close();
54 }
55
56 setCentralWidget(m_pDrawPadCanvas); 49 setCentralWidget(m_pDrawPadCanvas);
57 50
58 // init menu 51 // init menu
59 52
60 setToolBarsMovable(false); 53 setToolBarsMovable(false);
61 54
62 QPEToolBar* menuToolBar = new QPEToolBar(this); 55 QPEToolBar* menuToolBar = new QPEToolBar(this);
63 QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); 56 QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar);
64 57
65 QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); 58 QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar);
66 59
67 QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); 60 QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this);
68 connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll())); 61 connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll()));
69 clearAllAction->addTo(toolsPopupMenu); 62 clearAllAction->addTo(toolsPopupMenu);
70 63
71 toolsPopupMenu->insertSeparator(); 64 toolsPopupMenu->insertSeparator();
72 65
73 QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this); 66 QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this);
74 setOptionsAction->addTo(toolsPopupMenu); 67 setOptionsAction->addTo(toolsPopupMenu);
75 68
76 menuBar->insertItem(tr("Tools"), toolsPopupMenu); 69 menuBar->insertItem(tr("Tools"), toolsPopupMenu);
77 70
78 // init page toolbar 71 // init page toolbar
79 72
@@ -85,68 +78,64 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
85 78
86 QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); 79 QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
87 connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); 80 connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage()));
88 clearPageAction->addTo(pageToolBar); 81 clearPageAction->addTo(pageToolBar);
89 82
90 QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); 83 QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this);
91 connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); 84 connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage()));
92 deletePageAction->addTo(pageToolBar); 85 deletePageAction->addTo(pageToolBar);
93 86
94 QPEToolBar* emptyToolBar = new QPEToolBar(this); 87 QPEToolBar* emptyToolBar = new QPEToolBar(this);
95 emptyToolBar->setHorizontalStretchable(true); 88 emptyToolBar->setHorizontalStretchable(true);
96 89
97 // init navigation toolbar 90 // init navigation toolbar
98 91
99 QPEToolBar* navigationToolBar = new QPEToolBar(this); 92 QPEToolBar* navigationToolBar = new QPEToolBar(this);
100 93
101 m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); 94 m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this);
102 connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); 95 connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
103 m_pUndoAction->addTo(navigationToolBar); 96 m_pUndoAction->addTo(navigationToolBar);
104 97
105 m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); 98 m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this);
106 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); 99 connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
107 m_pRedoAction->addTo(navigationToolBar); 100 m_pRedoAction->addTo(navigationToolBar);
108 101
109 updateUndoRedoToolButtons();
110
111 m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); 102 m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
112 connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); 103 connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage()));
113 m_pFirstPageAction->addTo(navigationToolBar); 104 m_pFirstPageAction->addTo(navigationToolBar);
114 105
115 m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); 106 m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this);
116 connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); 107 connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage()));
117 m_pPreviousPageAction->addTo(navigationToolBar); 108 m_pPreviousPageAction->addTo(navigationToolBar);
118 109
119 m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); 110 m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this);
120 connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); 111 connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage()));
121 m_pNextPageAction->addTo(navigationToolBar); 112 m_pNextPageAction->addTo(navigationToolBar);
122 113
123 m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); 114 m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this);
124 connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); 115 connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage()));
125 m_pLastPageAction->addTo(navigationToolBar); 116 m_pLastPageAction->addTo(navigationToolBar);
126 117
127 updateNavigationToolButtons();
128
129 // init draw mode toolbar 118 // init draw mode toolbar
130 119
131 QPEToolBar* drawModeToolBar = new QPEToolBar(this); 120 QPEToolBar* drawModeToolBar = new QPEToolBar(this);
132 121
133 m_pPointDrawModeAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this); 122 m_pPointDrawModeAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), QString::null, 0, this);
134 m_pPointDrawModeAction->setToggleAction(true); 123 m_pPointDrawModeAction->setToggleAction(true);
135 connect(m_pPointDrawModeAction, SIGNAL(activated()), this, SLOT(setPointDrawMode())); 124 connect(m_pPointDrawModeAction, SIGNAL(activated()), this, SLOT(setPointDrawMode()));
136 m_pPointDrawModeAction->addTo(drawModeToolBar); 125 m_pPointDrawModeAction->addTo(drawModeToolBar);
137 126
138 m_pLineDrawModeAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this); 127 m_pLineDrawModeAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), QString::null, 0, this);
139 m_pLineDrawModeAction->setToggleAction(true); 128 m_pLineDrawModeAction->setToggleAction(true);
140 connect(m_pLineDrawModeAction, SIGNAL(activated()), this, SLOT(setLineDrawMode())); 129 connect(m_pLineDrawModeAction, SIGNAL(activated()), this, SLOT(setLineDrawMode()));
141 m_pLineDrawModeAction->addTo(drawModeToolBar); 130 m_pLineDrawModeAction->addTo(drawModeToolBar);
142 131
143 m_pRectangleDrawModeAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), QString::null, 0, this); 132 m_pRectangleDrawModeAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), QString::null, 0, this);
144 m_pRectangleDrawModeAction->setToggleAction(true); 133 m_pRectangleDrawModeAction->setToggleAction(true);
145 connect(m_pRectangleDrawModeAction, SIGNAL(activated()), this, SLOT(setRectangleDrawMode())); 134 connect(m_pRectangleDrawModeAction, SIGNAL(activated()), this, SLOT(setRectangleDrawMode()));
146 m_pRectangleDrawModeAction->addTo(drawModeToolBar); 135 m_pRectangleDrawModeAction->addTo(drawModeToolBar);
147 136
148 m_pEllipseDrawModeAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), QString::null, 0, this); 137 m_pEllipseDrawModeAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), QString::null, 0, this);
149 m_pEllipseDrawModeAction->setToggleAction(true); 138 m_pEllipseDrawModeAction->setToggleAction(true);
150 connect(m_pEllipseDrawModeAction, SIGNAL(activated()), this, SLOT(setEllipseDrawMode())); 139 connect(m_pEllipseDrawModeAction, SIGNAL(activated()), this, SLOT(setEllipseDrawMode()));
151 m_pEllipseDrawModeAction->addTo(drawModeToolBar); 140 m_pEllipseDrawModeAction->addTo(drawModeToolBar);
152 141
@@ -196,48 +185,59 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f)
196 m_pPenColorToolButton->setPopupDelay(0); 185 m_pPenColorToolButton->setPopupDelay(0);
197 186
198 penColorPopupMenu->activateItemAt(0); 187 penColorPopupMenu->activateItemAt(0);
199 188
200 m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); 189 m_pBrushColorToolButton = new QToolButton(drawParametersToolBar);
201 m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); 190 m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png"));
202 191
203 QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); 192 QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton);
204 193
205 ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu); 194 ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu);
206 connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); 195 connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&)));
207 brushColorPopupMenu->insertItem(brushColorPanel); 196 brushColorPopupMenu->insertItem(brushColorPanel);
208 197
209 brushColorPopupMenu->insertSeparator(); 198 brushColorPopupMenu->insertSeparator();
210 199
211 QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this); 200 QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this);
212 connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor())); 201 connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor()));
213 chooseBrushColorAction->addTo(brushColorPopupMenu); 202 chooseBrushColorAction->addTo(brushColorPopupMenu);
214 203
215 QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); 204 QToolTip::add(m_pBrushColorToolButton, tr("Fill Color"));
216 m_pBrushColorToolButton->setPopup(brushColorPopupMenu); 205 m_pBrushColorToolButton->setPopup(brushColorPopupMenu);
217 m_pBrushColorToolButton->setPopupDelay(0); 206 m_pBrushColorToolButton->setPopupDelay(0);
218 207
219 brushColorPopupMenu->activateItemAt(1); 208 brushColorPopupMenu->activateItemAt(1);
209
210 // init pages
211
212 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
213
214 if (file.open(IO_ReadOnly)) {
215 m_pDrawPadCanvas->load(&file);
216 file.close();
217 } else {
218 m_pDrawPadCanvas->initialPage();
219 }
220} 220}
221 221
222DrawPad::~DrawPad() 222DrawPad::~DrawPad()
223{ 223{
224 QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); 224 QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
225 225
226 if (file.open(IO_WriteOnly)) { 226 if (file.open(IO_WriteOnly)) {
227 m_pDrawPadCanvas->save(&file); 227 m_pDrawPadCanvas->save(&file);
228 file.close(); 228 file.close();
229 } 229 }
230} 230}
231 231
232void DrawPad::setPointDrawMode() 232void DrawPad::setPointDrawMode()
233{ 233{
234 if (m_pDrawMode) { 234 if (m_pDrawMode) {
235 delete m_pDrawMode; 235 delete m_pDrawMode;
236 } 236 }
237 237
238 m_pDrawMode = new PointDrawMode(this, m_pDrawPadCanvas); 238 m_pDrawMode = new PointDrawMode(this, m_pDrawPadCanvas);
239 239
240 m_pPointDrawModeAction->setOn(true); 240 m_pPointDrawModeAction->setOn(true);
241 m_pLineDrawModeAction->setOn(false); 241 m_pLineDrawModeAction->setOn(false);
242 m_pRectangleDrawModeAction->setOn(false); 242 m_pRectangleDrawModeAction->setOn(false);
243 m_pEllipseDrawModeAction->setOn(false); 243 m_pEllipseDrawModeAction->setOn(false);
@@ -358,24 +358,33 @@ void DrawPad::choosePenColor()
358{ 358{
359 QColor newPenColor = QColorDialog::getColor(m_pen.color()); 359 QColor newPenColor = QColorDialog::getColor(m_pen.color());
360 changePenColor(newPenColor); 360 changePenColor(newPenColor);
361} 361}
362 362
363void DrawPad::chooseBrushColor() 363void DrawPad::chooseBrushColor()
364{ 364{
365 QColor newBrushColor = QColorDialog::getColor(m_brush.color()); 365 QColor newBrushColor = QColorDialog::getColor(m_brush.color());
366 changeBrushColor(newBrushColor); 366 changeBrushColor(newBrushColor);
367} 367}
368 368
369void DrawPad::updateUndoRedoToolButtons() 369void DrawPad::updateUndoRedoToolButtons()
370{ 370{
371 m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); 371 m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled());
372 m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); 372 m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled());
373} 373}
374 374
375void DrawPad::updateNavigationToolButtons() 375void DrawPad::updateNavigationToolButtons()
376{ 376{
377 m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); 377 m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
378 m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); 378 m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
379 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); 379 m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
380 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); 380 m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
381} 381}
382
383void DrawPad::updateCaption()
384{
385 uint pagePosition = m_pDrawPadCanvas->pagePosition();
386 uint pageCount = m_pDrawPadCanvas->pageCount();
387
388 setCaption(tr("DrawPad") + " - " + tr("Page") + " "
389 + QString::number(pagePosition) + "/" + QString::number(pageCount));
390}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index 35b3be4..c49a559 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -10,71 +10,72 @@
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
21class DrawMode; 21class DrawMode;
22class DrawPadCanvas; 22class DrawPadCanvas;
23 23
24class QAction; 24class QAction;
25class QColor; 25class QColor;
26class QToolButton; 26class QToolButton;
27class QWidgetStack; 27class QWidgetStack;
28 28
29class DrawPad : public QMainWindow 29class DrawPad : public QMainWindow
30{ 30{
31 Q_OBJECT 31 Q_OBJECT
32 32
33public: 33public:
34 DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel); 34 DrawPad(QWidget* parent = 0, const char* name = 0);
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
41private slots: 41private slots:
42 void setPointDrawMode(); 42 void setPointDrawMode();
43 void setLineDrawMode(); 43 void setLineDrawMode();
44 void setRectangleDrawMode(); 44 void setRectangleDrawMode();
45 void setEllipseDrawMode(); 45 void setEllipseDrawMode();
46 void setFillDrawMode(); 46 void setFillDrawMode();
47 void setEraseDrawMode(); 47 void setEraseDrawMode();
48 48
49 void changePenWidth(int value); 49 void changePenWidth(int value);
50 void changePenColor(const QColor& color); 50 void changePenColor(const QColor& color);
51 void changeBrushColor(const QColor& color); 51 void changeBrushColor(const QColor& color);
52 void choosePenColor(); 52 void choosePenColor();
53 void chooseBrushColor(); 53 void chooseBrushColor();
54 54
55 void updateUndoRedoToolButtons(); 55 void updateUndoRedoToolButtons();
56 void updateNavigationToolButtons(); 56 void updateNavigationToolButtons();
57 void updateCaption();
57 58
58private: 59private:
59 DrawPadCanvas* m_pDrawPadCanvas; 60 DrawPadCanvas* m_pDrawPadCanvas;
60 61
61 DrawMode* m_pDrawMode; 62 DrawMode* m_pDrawMode;
62 QPen m_pen; 63 QPen m_pen;
63 QBrush m_brush; 64 QBrush m_brush;
64 65
65 QAction* m_pUndoAction; 66 QAction* m_pUndoAction;
66 QAction* m_pRedoAction; 67 QAction* m_pRedoAction;
67 68
68 QAction* m_pFirstPageAction; 69 QAction* m_pFirstPageAction;
69 QAction* m_pPreviousPageAction; 70 QAction* m_pPreviousPageAction;
70 QAction* m_pNextPageAction; 71 QAction* m_pNextPageAction;
71 QAction* m_pLastPageAction; 72 QAction* m_pLastPageAction;
72 73
73 QAction* m_pPointDrawModeAction; 74 QAction* m_pPointDrawModeAction;
74 QAction* m_pLineDrawModeAction; 75 QAction* m_pLineDrawModeAction;
75 QAction* m_pRectangleDrawModeAction; 76 QAction* m_pRectangleDrawModeAction;
76 QAction* m_pEllipseDrawModeAction; 77 QAction* m_pEllipseDrawModeAction;
77 QAction* m_pFillDrawModeAction; 78 QAction* m_pFillDrawModeAction;
78 QAction* m_pEraseDrawModeAction; 79 QAction* m_pEraseDrawModeAction;
79 80
80 QToolButton* m_pPenColorToolButton; 81 QToolButton* m_pPenColorToolButton;
diff --git a/noncore/graphics/drawpad/drawpad.pro b/noncore/graphics/drawpad/drawpad.pro
index 407a039..b0eb009 100644
--- a/noncore/graphics/drawpad/drawpad.pro
+++ b/noncore/graphics/drawpad/drawpad.pro
@@ -1,31 +1,35 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 HEADERS = colordialog.h \ 3 HEADERS = colordialog.h \
4 colorpanel.h \ 4 colorpanel.h \
5 drawmode.h \ 5 drawmode.h \
6 drawpad.h \ 6 drawpad.h \
7 drawpadcanvas.h \ 7 drawpadcanvas.h \
8 ellipsedrawmode.h \ 8 ellipsedrawmode.h \
9 erasedrawmode.h \ 9 erasedrawmode.h \
10 filldrawmode.h \ 10 filldrawmode.h \
11 linedrawmode.h \ 11 linedrawmode.h \
12 newpagedialog.h \
12 pointdrawmode.h \ 13 pointdrawmode.h \
13 rectangledrawmode.h 14 rectangledrawmode.h \
15 shapedrawmode.h
14 SOURCES = colordialog.cpp \ 16 SOURCES = colordialog.cpp \
15 colorpanel.cpp \ 17 colorpanel.cpp \
16 drawmode.cpp \ 18 drawmode.cpp \
17 drawpad.cpp \ 19 drawpad.cpp \
18 drawpadcanvas.cpp \ 20 drawpadcanvas.cpp \
19 ellipsedrawmode.cpp \ 21 ellipsedrawmode.cpp \
20 erasedrawmode.cpp \ 22 erasedrawmode.cpp \
21 filldrawmode.cpp \ 23 filldrawmode.cpp \
22 linedrawmode.cpp \ 24 linedrawmode.cpp \
23 main.cpp \ 25 main.cpp \
26 newpagedialog.cpp \
24 pointdrawmode.cpp \ 27 pointdrawmode.cpp \
25 rectangledrawmode.cpp 28 rectangledrawmode.cpp \
29 shapedrawmode.cpp
26 INCLUDEPATH+= $(OPIEDIR)/include \ 30 INCLUDEPATH+= $(OPIEDIR)/include \
27 $(QTDIR)/src/3rdparty/zlib 31 $(QTDIR)/src/3rdparty/zlib
28 DEPENDPATH+= $(OPIEDIR)/include 32 DEPENDPATH+= $(OPIEDIR)/include
29 LIBS += -lqpe 33 LIBS += -lqpe
30 DESTDIR = $(OPIEDIR)/bin 34 DESTDIR = $(OPIEDIR)/bin
31 TARGET = drawpad 35 TARGET = drawpad
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 08f7b66..49a8cf0 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -1,41 +1,42 @@
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#include "newpagedialog.h"
18 19
19#include <qbuffer.h> 20#include <qbuffer.h>
20#include <qimage.h> 21#include <qimage.h>
21#include <qpainter.h> 22#include <qpainter.h>
22#include <qpixmap.h> 23#include <qpixmap.h>
23#include <qtextcodec.h> 24#include <qtextcodec.h>
24#include <qtextstream.h> 25#include <qtextstream.h>
25#include <qxml.h> 26#include <qxml.h>
26 27
27#include <zlib.h> 28#include <zlib.h>
28 29
29class DrawPadCanvasXmlHandler: public QXmlDefaultHandler 30class DrawPadCanvasXmlHandler: public QXmlDefaultHandler
30{ 31{
31public: 32public:
32 DrawPadCanvasXmlHandler(); 33 DrawPadCanvasXmlHandler();
33 ~DrawPadCanvasXmlHandler(); 34 ~DrawPadCanvasXmlHandler();
34 35
35 QList<QPixmap> pixmaps(); 36 QList<QPixmap> pixmaps();
36 37
37 bool startElement(const QString& namespaceURI, const QString& localName, 38 bool startElement(const QString& namespaceURI, const QString& localName,
38 const QString& qName, const QXmlAttributes& atts); 39 const QString& qName, const QXmlAttributes& atts);
39 bool endElement(const QString& namespaceURI, const QString& localName, 40 bool endElement(const QString& namespaceURI, const QString& localName,
40 const QString& qName); 41 const QString& qName);
41 bool characters(const QString& ch); 42 bool characters(const QString& ch);
@@ -116,88 +117,102 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch)
116 r += l - 'a' + 10; 117 r += l - 'a' + 10;
117 } 118 }
118 119
119 byteArray[i] = r; 120 byteArray[i] = r;
120 } 121 }
121 122
122 if (m_dataLenght < ch.length() * 5) { 123 if (m_dataLenght < ch.length() * 5) {
123 m_dataLenght = ch.length() * 5; 124 m_dataLenght = ch.length() * 5;
124 } 125 }
125 126
126 QByteArray byteArrayUnzipped(m_dataLenght); 127 QByteArray byteArrayUnzipped(m_dataLenght);
127 ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); 128 ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size());
128 129
129 QImage image; 130 QImage image;
130 image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM"); 131 image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, "XPM");
131 132
132 QPixmap* pixmap = new QPixmap(image.width(), image.height()); 133 QPixmap* pixmap = new QPixmap(image.width(), image.height());
133 pixmap->convertFromImage(image); 134 pixmap->convertFromImage(image);
134 m_pixmaps.append(pixmap); 135 m_pixmaps.append(pixmap);
135 } 136 }
136 137
137 return true; 138 return true;
138} 139}
139 140
140DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f) 141DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name)
141 : QWidget(parent, name, f) 142 : QScrollView(parent, name)
142{ 143{
143 setBackgroundMode(QWidget::PaletteBase);
144
145 m_pDrawPad = drawPad; 144 m_pDrawPad = drawPad;
146 m_pages.setAutoDelete(true); 145 m_pages.setAutoDelete(true);
147 m_pages.append(new QPixmap(width(), height()));
148 m_pages.current()->fill(Qt::white);
149 m_pageBackups.setAutoDelete(true); 146 m_pageBackups.setAutoDelete(true);
150 m_pageBackups.append(new QPixmap(*(m_pages.current())));
151} 147}
152 148
153DrawPadCanvas::~DrawPadCanvas() 149DrawPadCanvas::~DrawPadCanvas()
154{ 150{
155} 151}
156 152
157void DrawPadCanvas::load(QIODevice* ioDevice) 153void DrawPadCanvas::load(QIODevice* ioDevice)
158{ 154{
159 QTextStream textStream(ioDevice); 155 QTextStream textStream(ioDevice);
160 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 156 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
161 157
162 QXmlInputSource xmlInputSource(textStream); 158 QXmlInputSource xmlInputSource(textStream);
163 QXmlSimpleReader xmlSimpleReader; 159 QXmlSimpleReader xmlSimpleReader;
164 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; 160 DrawPadCanvasXmlHandler drawPadCanvasXmlHandler;
165 161
166 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); 162 xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler);
167 xmlSimpleReader.parse(xmlInputSource); 163 xmlSimpleReader.parse(xmlInputSource);
168 164
169 m_pages = drawPadCanvasXmlHandler.pixmaps(); 165 m_pages = drawPadCanvasXmlHandler.pixmaps();
170 166
171 if (m_pages.isEmpty()) { 167 if (m_pages.isEmpty()) {
172 m_pages.append(new QPixmap(width(), height())); 168 m_pages.append(new QPixmap(contentsRect().size()));
173 m_pages.current()->fill(Qt::white); 169 m_pages.current()->fill(Qt::white);
174 } 170 }
175 171
176 m_pageBackups.clear(); 172 m_pageBackups.clear();
177 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 173 m_pageBackups.append(new QPixmap(*(m_pages.current())));
178 174
179 repaint(); 175 resizeContents(m_pages.current()->width(), m_pages.current()->height());
176 viewport()->update();
177
178 emit pagesChanged();
179 emit pageBackupsChanged();
180}
181
182void DrawPadCanvas::initialPage()
183{
184 m_pages.append(new QPixmap(234, 252));
185 m_pages.current()->fill(Qt::white);
186
187 m_pageBackups.clear();
188 m_pageBackups.append(new QPixmap(*(m_pages.current())));
189
190 resizeContents(m_pages.current()->width(), m_pages.current()->height());
191 viewport()->update();
192
193 emit pagesChanged();
194 emit pageBackupsChanged();
180} 195}
181 196
182void DrawPadCanvas::save(QIODevice* ioDevice) 197void DrawPadCanvas::save(QIODevice* ioDevice)
183{ 198{
184 QTextStream textStream(ioDevice); 199 QTextStream textStream(ioDevice);
185 textStream.setCodec(QTextCodec::codecForName("UTF-8")); 200 textStream.setCodec(QTextCodec::codecForName("UTF-8"));
186 201
187 textStream << "<drawpad>" << endl; 202 textStream << "<drawpad>" << endl;
188 textStream << " <images>" << endl; 203 textStream << " <images>" << endl;
189 204
190 QListIterator<QPixmap> bufferIterator(m_pages); 205 QListIterator<QPixmap> bufferIterator(m_pages);
191 206
192 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { 207 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) {
193 textStream << " <image>" << endl; 208 textStream << " <image>" << endl;
194 209
195 QImage image = bufferIterator.current()->convertToImage(); 210 QImage image = bufferIterator.current()->convertToImage();
196 QByteArray byteArray; 211 QByteArray byteArray;
197 QBuffer buffer(byteArray); 212 QBuffer buffer(byteArray);
198 QImageIO imageIO(&buffer, "XPM"); 213 QImageIO imageIO(&buffer, "XPM");
199 214
200 buffer.open(IO_WriteOnly); 215 buffer.open(IO_WriteOnly);
201 imageIO.setImage(image); 216 imageIO.setImage(image);
202 imageIO.write(); 217 imageIO.write();
203 buffer.close(); 218 buffer.close();
@@ -208,213 +223,224 @@ void DrawPadCanvas::save(QIODevice* ioDevice)
208 223
209 textStream << " <data length=\"" << byteArray.size() << "\">"; 224 textStream << " <data length=\"" << byteArray.size() << "\">";
210 225
211 static const char hexchars[] = "0123456789abcdef"; 226 static const char hexchars[] = "0123456789abcdef";
212 227
213 for (int i = 0; i < (int)size; i++ ) { 228 for (int i = 0; i < (int)size; i++ ) {
214 uchar s = (uchar)byteArrayZipped[i]; 229 uchar s = (uchar)byteArrayZipped[i];
215 textStream << hexchars[s >> 4]; 230 textStream << hexchars[s >> 4];
216 textStream << hexchars[s & 0x0f]; 231 textStream << hexchars[s & 0x0f];
217 } 232 }
218 233
219 textStream << "</data>" << endl; 234 textStream << "</data>" << endl;
220 textStream << " </image>" << endl; 235 textStream << " </image>" << endl;
221 } 236 }
222 237
223 textStream << " </images>" << endl; 238 textStream << " </images>" << endl;
224 textStream << "</drawpad>"; 239 textStream << "</drawpad>";
225} 240}
226 241
227QPixmap* DrawPadCanvas::currentPage() 242QPixmap* DrawPadCanvas::currentPage()
228{ 243{
229 return m_pages.current(); 244 return m_pages.current();
230} 245}
231 246
247uint DrawPadCanvas::pagePosition()
248{
249 return (m_pages.at() + 1);
250}
251
252uint DrawPadCanvas::pageCount()
253{
254 return m_pages.count();
255}
256
232void DrawPadCanvas::clearAll() 257void DrawPadCanvas::clearAll()
233{ 258{
234 m_pages.clear(); 259 m_pages.clear();
235 260
236 m_pages.append(new QPixmap(width(), height())); 261 m_pages.append(new QPixmap(contentsRect().size()));
237 m_pages.current()->fill(Qt::white); 262 m_pages.current()->fill(Qt::white);
238 263
239 m_pageBackups.clear(); 264 m_pageBackups.clear();
240 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 265 m_pageBackups.append(new QPixmap(*(m_pages.current())));
241 266
242 repaint(); 267 resizeContents(m_pages.current()->width(), m_pages.current()->height());
268 viewport()->update();
243 269
244 emit pagesChanged(); 270 emit pagesChanged();
245 emit pageBackupsChanged(); 271 emit pageBackupsChanged();
246} 272}
247 273
248void DrawPadCanvas::newPage() 274void DrawPadCanvas::newPage()
249{ 275{
250 m_pages.insert(m_pages.at() + 1, new QPixmap(width(), height())); 276 QRect rect = contentsRect();
251 m_pages.current()->fill(Qt::white);
252 m_pageBackups.clear();
253 m_pageBackups.append(new QPixmap(*(m_pages.current())));
254 repaint();
255 277
256 emit pagesChanged(); 278 NewPageDialog newPageDialog(this);
257 emit pageBackupsChanged(); 279 newPageDialog.setWidth(rect.width());
280 newPageDialog.setHeight(rect.height());
281
282 if (newPageDialog.exec() == QDialog::Accepted) {
283 m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.width(), newPageDialog.height()));
284 m_pages.current()->fill(Qt::white);
285
286 m_pageBackups.clear();
287 m_pageBackups.append(new QPixmap(*(m_pages.current())));
288
289 resizeContents(m_pages.current()->width(), m_pages.current()->height());
290 viewport()->update();
291
292 emit pagesChanged();
293 emit pageBackupsChanged();
294 }
258} 295}
259 296
260void DrawPadCanvas::clearPage() 297void DrawPadCanvas::clearPage()
261{ 298{
262 m_pages.current()->fill(Qt::white); 299 m_pages.current()->fill(Qt::white);
263 repaint(); 300
301 viewport()->update();
264} 302}
265 303
266void DrawPadCanvas::deletePage() 304void DrawPadCanvas::deletePage()
267{ 305{
268 m_pages.remove(m_pages.current()); 306 m_pages.remove(m_pages.current());
269 307
270 if (m_pages.isEmpty()) { 308 if (m_pages.isEmpty()) {
271 m_pages.append(new QPixmap(width(), height())); 309 m_pages.append(new QPixmap(contentsRect().size()));
272 m_pages.current()->fill(Qt::white); 310 m_pages.current()->fill(Qt::white);
273 } 311 }
274 312
275 m_pageBackups.clear(); 313 m_pageBackups.clear();
276 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 314 m_pageBackups.append(new QPixmap(*(m_pages.current())));
277 315
278 repaint(); 316 resizeContents(m_pages.current()->width(), m_pages.current()->height());
317 viewport()->update();
279 318
280 emit pagesChanged(); 319 emit pagesChanged();
281 emit pageBackupsChanged(); 320 emit pageBackupsChanged();
282} 321}
283 322
284bool DrawPadCanvas::undoEnabled() 323bool DrawPadCanvas::undoEnabled()
285{ 324{
286 return (m_pageBackups.current() != m_pageBackups.getFirst()); 325 return (m_pageBackups.current() != m_pageBackups.getFirst());
287} 326}
288 327
289bool DrawPadCanvas::redoEnabled() 328bool DrawPadCanvas::redoEnabled()
290{ 329{
291 return (m_pageBackups.current() != m_pageBackups.getLast()); 330 return (m_pageBackups.current() != m_pageBackups.getLast());
292} 331}
293 332
294bool DrawPadCanvas::goPreviousPageEnabled() 333bool DrawPadCanvas::goPreviousPageEnabled()
295{ 334{
296 return (m_pages.current() != m_pages.getFirst()); 335 return (m_pages.current() != m_pages.getFirst());
297} 336}
298 337
299bool DrawPadCanvas::goNextPageEnabled() 338bool DrawPadCanvas::goNextPageEnabled()
300{ 339{
301 return (m_pages.current() != m_pages.getLast()); 340 return (m_pages.current() != m_pages.getLast());
302} 341}
303 342
304void DrawPadCanvas::undo() 343void DrawPadCanvas::undo()
305{ 344{
306 *(m_pages.current()) = *(m_pageBackups.prev()); 345 *(m_pages.current()) = *(m_pageBackups.prev());
307 repaint(); 346
347 viewport()->update();
308 348
309 emit pageBackupsChanged(); 349 emit pageBackupsChanged();
310} 350}
311 351
312void DrawPadCanvas::redo() 352void DrawPadCanvas::redo()
313{ 353{
314 *(m_pages.current()) = *(m_pageBackups.next()); 354 *(m_pages.current()) = *(m_pageBackups.next());
315 repaint(); 355
356 viewport()->update();
316 357
317 emit pageBackupsChanged(); 358 emit pageBackupsChanged();
318} 359}
319 360
320void DrawPadCanvas::goFirstPage() 361void DrawPadCanvas::goFirstPage()
321{ 362{
322 m_pages.first(); 363 m_pages.first();
323 m_pageBackups.clear(); 364 m_pageBackups.clear();
324 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 365 m_pageBackups.append(new QPixmap(*(m_pages.current())));
325 repaint(); 366
367 resizeContents(m_pages.current()->width(), m_pages.current()->height());
368 viewport()->update();
326 369
327 emit pagesChanged(); 370 emit pagesChanged();
328 emit pageBackupsChanged(); 371 emit pageBackupsChanged();
329} 372}
330 373
331void DrawPadCanvas::goPreviousPage() 374void DrawPadCanvas::goPreviousPage()
332{ 375{
333 m_pages.prev(); 376 m_pages.prev();
334 m_pageBackups.clear(); 377 m_pageBackups.clear();
335 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 378 m_pageBackups.append(new QPixmap(*(m_pages.current())));
336 repaint(); 379
380 resizeContents(m_pages.current()->width(), m_pages.current()->height());
381 viewport()->update();
337 382
338 emit pagesChanged(); 383 emit pagesChanged();
339 emit pageBackupsChanged(); 384 emit pageBackupsChanged();
340} 385}
341 386
342void DrawPadCanvas::goNextPage() 387void DrawPadCanvas::goNextPage()
343{ 388{
344 m_pages.next(); 389 m_pages.next();
345 m_pageBackups.clear(); 390 m_pageBackups.clear();
346 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 391 m_pageBackups.append(new QPixmap(*(m_pages.current())));
347 repaint(); 392
393 resizeContents(m_pages.current()->width(), m_pages.current()->height());
394 viewport()->update();
348 395
349 emit pagesChanged(); 396 emit pagesChanged();
350 emit pageBackupsChanged(); 397 emit pageBackupsChanged();
351} 398}
352 399
353void DrawPadCanvas::goLastPage() 400void DrawPadCanvas::goLastPage()
354{ 401{
355 m_pages.last(); 402 m_pages.last();
356 m_pageBackups.clear(); 403 m_pageBackups.clear();
357 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 404 m_pageBackups.append(new QPixmap(*(m_pages.current())));
358 repaint(); 405
406 resizeContents(m_pages.current()->width(), m_pages.current()->height());
407 viewport()->update();
359 408
360 emit pagesChanged(); 409 emit pagesChanged();
361 emit pageBackupsChanged(); 410 emit pageBackupsChanged();
362} 411}
363 412
364void DrawPadCanvas::mousePressEvent(QMouseEvent* e) 413void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e)
365{ 414{
366 m_pDrawPad->drawMode()->mousePressEvent(e); 415 m_pDrawPad->drawMode()->mousePressEvent(e);
367} 416}
368 417
369void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) 418void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
370{ 419{
371 m_pDrawPad->drawMode()->mouseReleaseEvent(e); 420 m_pDrawPad->drawMode()->mouseReleaseEvent(e);
372 421
373 QPixmap* currentBackup = m_pageBackups.current(); 422 QPixmap* currentBackup = m_pageBackups.current();
374 while (m_pageBackups.last() != currentBackup) { 423 while (m_pageBackups.last() != currentBackup) {
375 m_pageBackups.removeLast(); 424 m_pageBackups.removeLast();
376 } 425 }
377 426
378 while (m_pageBackups.count() >= (5 + 1)) { 427 while (m_pageBackups.count() >= (5 + 1)) {
379 m_pageBackups.removeFirst(); 428 m_pageBackups.removeFirst();
380 } 429 }
381 430
382 m_pageBackups.append(new QPixmap(*(m_pages.current()))); 431 m_pageBackups.append(new QPixmap(*(m_pages.current())));
383 432
384 emit pageBackupsChanged(); 433 emit pageBackupsChanged();
385} 434}
386 435
387void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) 436void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e)
388{ 437{
389 m_pDrawPad->drawMode()->mouseMoveEvent(e); 438 m_pDrawPad->drawMode()->mouseMoveEvent(e);
390} 439}
391 440
392void DrawPadCanvas::resizeEvent(QResizeEvent* e) 441void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
393{ 442{
394 QWidget::resizeEvent(e); 443 QRect clipRect(cx, cy, cw, ch);
395
396 QListIterator<QPixmap> bufferIterator(m_pages);
397 444
398 for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { 445 p->drawPixmap(clipRect.topLeft(), *(m_pages.current()), clipRect);
399 int w = width() > bufferIterator.current()->width() ? width() : bufferIterator.current()->width();
400 int h = height() > bufferIterator.current()->height() ? height() : bufferIterator.current()->height();
401
402 QPixmap tmpPixmap(*(bufferIterator.current()));
403 bufferIterator.current()->resize(w, h);
404 bufferIterator.current()->fill(Qt::white);
405
406 bitBlt(bufferIterator.current(), 0, 0, &tmpPixmap, 0, 0, tmpPixmap.width(), tmpPixmap.height());
407 }
408}
409
410void DrawPadCanvas::paintEvent(QPaintEvent* e)
411{
412 QWidget::paintEvent(e);
413
414 QArray<QRect> rects = e->region().rects();
415
416 for (uint i = 0; i < rects.count(); i++) {
417 QRect r = rects[i];
418 bitBlt(this, r.x(), r.y(), m_pages.current(), r.x(), r.y(), r.width(), r.height());
419 }
420} 446}
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index eddcb43..4836a3f 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.h
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -1,75 +1,77 @@
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 <qscrollview.h>
18 18
19#include <qlist.h> 19#include <qlist.h>
20#include <qpointarray.h> 20#include <qpointarray.h>
21 21
22class DrawPad; 22class DrawPad;
23 23
24class QPixmap; 24class QPixmap;
25 25
26class DrawPadCanvas : public QWidget 26class DrawPadCanvas : public QScrollView
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29 29
30public: 30public:
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);
32 ~DrawPadCanvas(); 32 ~DrawPadCanvas();
33 33
34 void load(QIODevice* ioDevice); 34 void load(QIODevice* ioDevice);
35 void initialPage();
35 void save(QIODevice* ioDevice); 36 void save(QIODevice* ioDevice);
36 37
37 bool undoEnabled(); 38 bool undoEnabled();
38 bool redoEnabled(); 39 bool redoEnabled();
39 bool goPreviousPageEnabled(); 40 bool goPreviousPageEnabled();
40 bool goNextPageEnabled(); 41 bool goNextPageEnabled();
41 42
42 QPixmap* currentPage(); 43 QPixmap* currentPage();
44 uint pagePosition();
45 uint pageCount();
43 46
44public slots: 47public slots:
45 void clearAll(); 48 void clearAll();
46 void newPage(); 49 void newPage();
47 void clearPage(); 50 void clearPage();
48 void deletePage(); 51 void deletePage();
49 52
50 void undo(); 53 void undo();
51 void redo(); 54 void redo();
52 55
53 void goFirstPage(); 56 void goFirstPage();
54 void goPreviousPage(); 57 void goPreviousPage();
55 void goNextPage(); 58 void goNextPage();
56 void goLastPage(); 59 void goLastPage();
57 60
58signals: 61signals:
59 void pagesChanged(); 62 void pagesChanged();
60 void pageBackupsChanged(); 63 void pageBackupsChanged();
61 64
62protected: 65protected:
63 void mousePressEvent(QMouseEvent* e); 66 void contentsMousePressEvent(QMouseEvent* e);
64 void mouseReleaseEvent(QMouseEvent* e); 67 void contentsMouseReleaseEvent(QMouseEvent* e);
65 void mouseMoveEvent(QMouseEvent* e); 68 void contentsMouseMoveEvent(QMouseEvent* e);
66 void resizeEvent(QResizeEvent* e); 69 void drawContents(QPainter* p, int cx, int cy, int cw, int ch);
67 void paintEvent(QPaintEvent* e);
68 70
69private: 71private:
70 DrawPad* m_pDrawPad; 72 DrawPad* m_pDrawPad;
71 QList<QPixmap> m_pages; 73 QList<QPixmap> m_pages;
72 QList<QPixmap> m_pageBackups; 74 QList<QPixmap> m_pageBackups;
73}; 75};
74 76
75#endif // DRAWPADCANVAS_H 77#endif // DRAWPADCANVAS_H
diff --git a/noncore/graphics/drawpad/ellipsedrawmode.cpp b/noncore/graphics/drawpad/ellipsedrawmode.cpp
index 12a1113..f9cfa73 100644
--- a/noncore/graphics/drawpad/ellipsedrawmode.cpp
+++ b/noncore/graphics/drawpad/ellipsedrawmode.cpp
@@ -1,86 +1,45 @@
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 "ellipsedrawmode.h" 14#include "ellipsedrawmode.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18 18
19#include <qpainter.h> 19#include <qpainter.h>
20#include <qpixmap.h> 20#include <qpixmap.h>
21 21
22EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 22EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas) 23 : ShapeDrawMode(drawPad, drawPadCanvas)
24{ 24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27} 25}
28 26
29EllipseDrawMode::~EllipseDrawMode() 27EllipseDrawMode::~EllipseDrawMode()
30{ 28{
31} 29}
32 30
33void EllipseDrawMode::mousePressEvent(QMouseEvent* e) 31void EllipseDrawMode::drawFinalShape(QPainter& p)
34{ 32{
35 m_mousePressed = true; 33 p.setRasterOp(Qt::NotROP);
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 34 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
35 p.setPen(m_pDrawPad->pen());
36 p.setRasterOp(Qt::CopyROP);
37 p.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
37} 38}
38 39
39void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e) 40void EllipseDrawMode::drawTemporaryShape(QPainter& p)
40{ 41{
41 Q_UNUSED(e) 42 p.setRasterOp(Qt::NotROP);
42 43 p.drawRect(QRect(m_polyline[2], m_polyline[1]));
43 QPainter painter; 44 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 painter.setRasterOp(Qt::NotROP);
46 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
47 painter.setPen(m_pDrawPad->pen());
48 painter.setRasterOp(Qt::CopyROP);
49 painter.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
50 painter.end();
51
52 QRect r = m_polyline.boundingRect();
53 r = r.normalize();
54 r.setLeft(r.left() - m_pDrawPad->pen().width());
55 r.setTop(r.top() - m_pDrawPad->pen().width());
56 r.setRight(r.right() + m_pDrawPad->pen().width());
57 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
58
59 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
60
61 m_mousePressed = false;
62}
63
64void EllipseDrawMode::mouseMoveEvent(QMouseEvent* e)
65{
66 if (m_mousePressed) {
67 QPainter painter;
68 painter.begin(m_pDrawPadCanvas->currentPage());
69 painter.setRasterOp(Qt::NotROP);
70 m_polyline[0] = e->pos();
71 painter.drawRect(QRect(m_polyline[2], m_polyline[1]));
72 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
73 painter.end();
74
75 QRect r = m_polyline.boundingRect();
76 r = r.normalize();
77 r.setLeft(r.left() - m_pDrawPad->pen().width());
78 r.setTop(r.top() - m_pDrawPad->pen().width());
79 r.setRight(r.right() + m_pDrawPad->pen().width());
80 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
81
82 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
83
84 m_polyline[1] = m_polyline[0];
85 }
86} 45}
diff --git a/noncore/graphics/drawpad/ellipsedrawmode.h b/noncore/graphics/drawpad/ellipsedrawmode.h
index 4787518..0246caa 100644
--- a/noncore/graphics/drawpad/ellipsedrawmode.h
+++ b/noncore/graphics/drawpad/ellipsedrawmode.h
@@ -1,36 +1,30 @@
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 ELLIPSEDRAWMODE_H 14#ifndef ELLIPSEDRAWMODE_H
15#define ELLIPSEDRAWMODE_H 15#define ELLIPSEDRAWMODE_H
16 16
17#include "drawmode.h" 17#include "shapedrawmode.h"
18 18
19#include <qpointarray.h> 19class EllipseDrawMode : public ShapeDrawMode
20
21class EllipseDrawMode : public DrawMode
22{ 20{
23public: 21public:
24 EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); 22 EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~EllipseDrawMode(); 23 ~EllipseDrawMode();
26 24
27 void mousePressEvent(QMouseEvent* e); 25protected:
28 void mouseReleaseEvent(QMouseEvent* e); 26 void drawFinalShape(QPainter& p);
29 void mouseMoveEvent(QMouseEvent* e); 27 void drawTemporaryShape(QPainter& p);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34}; 28};
35 29
36#endif // ELLIPSEDRAWMODE_H 30#endif // ELLIPSEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/erasedrawmode.cpp b/noncore/graphics/drawpad/erasedrawmode.cpp
index 990cecb..0e585cc 100644
--- a/noncore/graphics/drawpad/erasedrawmode.cpp
+++ b/noncore/graphics/drawpad/erasedrawmode.cpp
@@ -42,27 +42,33 @@ void EraseDrawMode::mouseReleaseEvent(QMouseEvent* e)
42 42
43 m_mousePressed = false; 43 m_mousePressed = false;
44} 44}
45 45
46void EraseDrawMode::mouseMoveEvent(QMouseEvent* e) 46void EraseDrawMode::mouseMoveEvent(QMouseEvent* e)
47{ 47{
48 if (m_mousePressed) { 48 if (m_mousePressed) {
49 QPainter painter; 49 QPainter painter;
50 QPen pen(Qt::white, m_pDrawPad->pen().width()); 50 QPen pen(Qt::white, m_pDrawPad->pen().width());
51 painter.begin(m_pDrawPadCanvas->currentPage()); 51 painter.begin(m_pDrawPadCanvas->currentPage());
52 painter.setPen(pen); 52 painter.setPen(pen);
53 m_polyline[2] = m_polyline[1]; 53 m_polyline[2] = m_polyline[1];
54 m_polyline[1] = m_polyline[0]; 54 m_polyline[1] = m_polyline[0];
55 m_polyline[0] = e->pos(); 55 m_polyline[0] = e->pos();
56 painter.drawPolyline(m_polyline); 56 painter.drawPolyline(m_polyline);
57 painter.end(); 57 painter.end();
58 58
59 QRect r = m_polyline.boundingRect(); 59 QRect r = m_polyline.boundingRect();
60 r = r.normalize(); 60 r = r.normalize();
61 r.setLeft(r.left() - m_pDrawPad->pen().width()); 61 r.setLeft(r.left() - m_pDrawPad->pen().width());
62 r.setTop(r.top() - m_pDrawPad->pen().width()); 62 r.setTop(r.top() - m_pDrawPad->pen().width());
63 r.setRight(r.right() + m_pDrawPad->pen().width()); 63 r.setRight(r.right() + m_pDrawPad->pen().width());
64 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 64 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
65 65
66 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 66 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
67 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
68
69 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
70 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
71
72 m_pDrawPadCanvas->viewport()->update(viewportRect);
67 } 73 }
68} 74}
diff --git a/noncore/graphics/drawpad/filldrawmode.cpp b/noncore/graphics/drawpad/filldrawmode.cpp
index 8f68550..1f81cd5 100644
--- a/noncore/graphics/drawpad/filldrawmode.cpp
+++ b/noncore/graphics/drawpad/filldrawmode.cpp
@@ -24,49 +24,49 @@ FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
24{ 24{
25} 25}
26 26
27FillDrawMode::~FillDrawMode() 27FillDrawMode::~FillDrawMode()
28{ 28{
29} 29}
30 30
31void FillDrawMode::mousePressEvent(QMouseEvent* e) 31void FillDrawMode::mousePressEvent(QMouseEvent* e)
32{ 32{
33 int x = e->x(); 33 int x = e->x();
34 int y = e->y(); 34 int y = e->y();
35 35
36 m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); 36 m_image = m_pDrawPadCanvas->currentPage()->convertToImage();
37 m_fillRgb = m_pDrawPad->brush().color().rgb(); 37 m_fillRgb = m_pDrawPad->brush().color().rgb();
38 m_oldRgb = m_image.pixel(x, y); 38 m_oldRgb = m_image.pixel(x, y);
39 39
40 if (m_oldRgb != m_fillRgb) { 40 if (m_oldRgb != m_fillRgb) {
41 m_image.setPixel(x, y, m_fillRgb); 41 m_image.setPixel(x, y, m_fillRgb);
42 fillEast(x + 1, y); 42 fillEast(x + 1, y);
43 fillSouth(x, y + 1); 43 fillSouth(x, y + 1);
44 fillWest(x - 1, y); 44 fillWest(x - 1, y);
45 fillNorth(x, y - 1); 45 fillNorth(x, y - 1);
46 46
47 m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); 47 m_pDrawPadCanvas->currentPage()->convertFromImage(m_image);
48 m_pDrawPadCanvas->repaint(); 48 m_pDrawPadCanvas->viewport()->update();
49 } 49 }
50} 50}
51 51
52void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) 52void FillDrawMode::mouseReleaseEvent(QMouseEvent* e)
53{ 53{
54 Q_UNUSED(e) 54 Q_UNUSED(e)
55} 55}
56 56
57void FillDrawMode::mouseMoveEvent(QMouseEvent* e) 57void FillDrawMode::mouseMoveEvent(QMouseEvent* e)
58{ 58{
59 Q_UNUSED(e) 59 Q_UNUSED(e)
60} 60}
61 61
62void FillDrawMode::fillEast(int x, int y) 62void FillDrawMode::fillEast(int x, int y)
63{ 63{
64 if (x < m_image.width()) { 64 if (x < m_image.width()) {
65 if (m_image.pixel(x, y) == m_oldRgb) { 65 if (m_image.pixel(x, y) == m_oldRgb) {
66 m_image.setPixel(x, y, m_fillRgb); 66 m_image.setPixel(x, y, m_fillRgb);
67 fillEast(x + 1, y); 67 fillEast(x + 1, y);
68 fillSouth(x, y + 1); 68 fillSouth(x, y + 1);
69 fillNorth(x, y - 1); 69 fillNorth(x, y - 1);
70 } 70 }
71 } 71 }
72} 72}
diff --git a/noncore/graphics/drawpad/linedrawmode.cpp b/noncore/graphics/drawpad/linedrawmode.cpp
index 15445fc..d432fad 100644
--- a/noncore/graphics/drawpad/linedrawmode.cpp
+++ b/noncore/graphics/drawpad/linedrawmode.cpp
@@ -1,83 +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#include "linedrawmode.h" 14#include "linedrawmode.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18 18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 19LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas) 20 : ShapeDrawMode(drawPad, drawPadCanvas)
24{ 21{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27} 22}
28 23
29LineDrawMode::~LineDrawMode() 24LineDrawMode::~LineDrawMode()
30{ 25{
31} 26}
32 27
33void LineDrawMode::mousePressEvent(QMouseEvent* e) 28void LineDrawMode::drawFinalShape(QPainter& p)
34{ 29{
35 m_mousePressed = true; 30 p.setPen(m_pDrawPad->pen());
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 31 p.drawLine(m_polyline[2], m_polyline[0]);
37} 32}
38 33
39void LineDrawMode::mouseReleaseEvent(QMouseEvent* e) 34void LineDrawMode::drawTemporaryShape(QPainter& p)
40{ 35{
41 Q_UNUSED(e) 36 p.setRasterOp(Qt::NotROP);
42 37 p.drawLine(m_polyline[2], m_polyline[1]);
43 QPainter painter; 38 p.drawLine(m_polyline[2], m_polyline[0]);
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 painter.setPen(m_pDrawPad->pen());
46 painter.drawLine(m_polyline[2], m_polyline[0]);
47 painter.end();
48
49 QRect r = m_polyline.boundingRect();
50 r = r.normalize();
51 r.setLeft(r.left() - m_pDrawPad->pen().width());
52 r.setTop(r.top() - m_pDrawPad->pen().width());
53 r.setRight(r.right() + m_pDrawPad->pen().width());
54 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
55
56 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
57
58 m_mousePressed = false;
59}
60
61void LineDrawMode::mouseMoveEvent(QMouseEvent* e)
62{
63 if (m_mousePressed) {
64 QPainter painter;
65 painter.begin(m_pDrawPadCanvas->currentPage());
66 painter.setRasterOp(Qt::NotROP);
67 m_polyline[0] = e->pos();
68 painter.drawLine(m_polyline[2], m_polyline[1]);
69 painter.drawLine(m_polyline[2], m_polyline[0]);
70 painter.end();
71
72 QRect r = m_polyline.boundingRect();
73 r = r.normalize();
74 r.setLeft(r.left() - m_pDrawPad->pen().width());
75 r.setTop(r.top() - m_pDrawPad->pen().width());
76 r.setRight(r.right() + m_pDrawPad->pen().width());
77 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
78
79 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
80
81 m_polyline[1] = m_polyline[0];
82 }
83} 39}
diff --git a/noncore/graphics/drawpad/linedrawmode.h b/noncore/graphics/drawpad/linedrawmode.h
index 25ae2cf..0ddd0ad 100644
--- a/noncore/graphics/drawpad/linedrawmode.h
+++ b/noncore/graphics/drawpad/linedrawmode.h
@@ -1,36 +1,30 @@
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 LINEDRAWMODE_H 14#ifndef LINEDRAWMODE_H
15#define LINEDRAWMODE_H 15#define LINEDRAWMODE_H
16 16
17#include "drawmode.h" 17#include "shapedrawmode.h"
18 18
19#include <qpointarray.h> 19class LineDrawMode : public ShapeDrawMode
20
21class LineDrawMode : public DrawMode
22{ 20{
23public: 21public:
24 LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); 22 LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~LineDrawMode(); 23 ~LineDrawMode();
26 24
27 void mousePressEvent(QMouseEvent* e); 25protected:
28 void mouseReleaseEvent(QMouseEvent* e); 26 void drawFinalShape(QPainter& p);
29 void mouseMoveEvent(QMouseEvent* e); 27 void drawTemporaryShape(QPainter& p);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34}; 28};
35 29
36#endif // LINEDRAWMODE_H 30#endif // LINEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/newpagedialog.cpp b/noncore/graphics/drawpad/newpagedialog.cpp
new file mode 100644
index 0000000..c11d977
--- a/dev/null
+++ b/noncore/graphics/drawpad/newpagedialog.cpp
@@ -0,0 +1,61 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
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 *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "newpagedialog.h"
15
16#include <qlabel.h>
17#include <qlayout.h>
18#include <qspinbox.h>
19
20NewPageDialog::NewPageDialog(QWidget* parent, const char* name)
21 : QDialog(parent, name, true)
22{
23 setCaption(tr("New Page"));
24
25 QLabel* widthLabel = new QLabel(tr("Width :"), this);
26 QLabel* heightLabel = new QLabel(tr("Height :"), this);
27
28 m_pWidthSpinBox = new QSpinBox(1, 1024, 1, this);
29 m_pHeightSpinBox = new QSpinBox(1, 1024, 1, this);
30
31 QGridLayout* gridLayout = new QGridLayout(this, 2, 2, 2, 2);
32
33 gridLayout->addWidget(widthLabel, 0, 0);
34 gridLayout->addWidget(heightLabel, 1, 0);
35 gridLayout->addWidget(m_pWidthSpinBox, 0, 1);
36 gridLayout->addWidget(m_pHeightSpinBox, 1, 1);
37}
38
39NewPageDialog::~NewPageDialog()
40{
41}
42
43void NewPageDialog::setWidth(int width)
44{
45 m_pWidthSpinBox->setValue(width);
46}
47
48void NewPageDialog::setHeight(int height)
49{
50 m_pHeightSpinBox->setValue(height);
51}
52
53int NewPageDialog::width()
54{
55 return m_pWidthSpinBox->value();
56}
57
58int NewPageDialog::height()
59{
60 return m_pHeightSpinBox->value();
61}
diff --git a/noncore/graphics/drawpad/newpagedialog.h b/noncore/graphics/drawpad/newpagedialog.h
new file mode 100644
index 0000000..a2b6b87
--- a/dev/null
+++ b/noncore/graphics/drawpad/newpagedialog.h
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
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 *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#ifndef NEWPAGEDIALOG_H
15#define NEWPAGEDIALOG_H
16
17#include <qdialog.h>
18
19class QSpinBox;
20
21class NewPageDialog : public QDialog
22{
23 Q_OBJECT
24
25public:
26 NewPageDialog(QWidget* parent = 0, const char* name = 0);
27 ~NewPageDialog();
28
29 void setWidth(int width);
30 void setHeight(int height);
31
32 int width();
33 int height();
34
35private:
36 QSpinBox* m_pWidthSpinBox;
37 QSpinBox* m_pHeightSpinBox;
38};
39
40#endif // NEWPAGEDIALOG_H
diff --git a/noncore/graphics/drawpad/pointdrawmode.cpp b/noncore/graphics/drawpad/pointdrawmode.cpp
index 30753d6..e251f1b 100644
--- a/noncore/graphics/drawpad/pointdrawmode.cpp
+++ b/noncore/graphics/drawpad/pointdrawmode.cpp
@@ -41,27 +41,33 @@ void PointDrawMode::mouseReleaseEvent(QMouseEvent* e)
41 Q_UNUSED(e) 41 Q_UNUSED(e)
42 42
43 m_mousePressed = false; 43 m_mousePressed = false;
44} 44}
45 45
46void PointDrawMode::mouseMoveEvent(QMouseEvent* e) 46void PointDrawMode::mouseMoveEvent(QMouseEvent* e)
47{ 47{
48 if (m_mousePressed) { 48 if (m_mousePressed) {
49 QPainter painter; 49 QPainter painter;
50 painter.begin(m_pDrawPadCanvas->currentPage()); 50 painter.begin(m_pDrawPadCanvas->currentPage());
51 painter.setPen(m_pDrawPad->pen()); 51 painter.setPen(m_pDrawPad->pen());
52 m_polyline[2] = m_polyline[1]; 52 m_polyline[2] = m_polyline[1];
53 m_polyline[1] = m_polyline[0]; 53 m_polyline[1] = m_polyline[0];
54 m_polyline[0] = e->pos(); 54 m_polyline[0] = e->pos();
55 painter.drawPolyline(m_polyline); 55 painter.drawPolyline(m_polyline);
56 painter.end(); 56 painter.end();
57 57
58 QRect r = m_polyline.boundingRect(); 58 QRect r = m_polyline.boundingRect();
59 r = r.normalize(); 59 r = r.normalize();
60 r.setLeft(r.left() - m_pDrawPad->pen().width()); 60 r.setLeft(r.left() - m_pDrawPad->pen().width());
61 r.setTop(r.top() - m_pDrawPad->pen().width()); 61 r.setTop(r.top() - m_pDrawPad->pen().width());
62 r.setRight(r.right() + m_pDrawPad->pen().width()); 62 r.setRight(r.right() + m_pDrawPad->pen().width());
63 r.setBottom(r.bottom() + m_pDrawPad->pen().width()); 63 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
64 64
65 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); 65 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
66 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
67
68 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
69 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
70
71 m_pDrawPadCanvas->viewport()->update(viewportRect);
66 } 72 }
67} 73}
diff --git a/noncore/graphics/drawpad/rectangledrawmode.cpp b/noncore/graphics/drawpad/rectangledrawmode.cpp
index 60d7cea..0226544 100644
--- a/noncore/graphics/drawpad/rectangledrawmode.cpp
+++ b/noncore/graphics/drawpad/rectangledrawmode.cpp
@@ -1,83 +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#include "rectangledrawmode.h" 14#include "rectangledrawmode.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18 18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 19RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas) 20 : ShapeDrawMode(drawPad, drawPadCanvas)
24{ 21{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27} 22}
28 23
29RectangleDrawMode::~RectangleDrawMode() 24RectangleDrawMode::~RectangleDrawMode()
30{ 25{
31} 26}
32 27
33void RectangleDrawMode::mousePressEvent(QMouseEvent* e) 28void RectangleDrawMode::drawFinalShape(QPainter& p)
34{ 29{
35 m_mousePressed = true; 30 p.setPen(m_pDrawPad->pen());
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); 31 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
37} 32}
38 33
39void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e) 34void RectangleDrawMode::drawTemporaryShape(QPainter& p)
40{ 35{
41 Q_UNUSED(e) 36 p.setRasterOp(Qt::NotROP);
42 37 p.drawRect(QRect(m_polyline[2], m_polyline[1]));
43 QPainter painter; 38 p.drawRect(QRect(m_polyline[2], m_polyline[0]));
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 painter.setPen(m_pDrawPad->pen());
46 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
47 painter.end();
48
49 QRect r = m_polyline.boundingRect();
50 r = r.normalize();
51 r.setLeft(r.left() - m_pDrawPad->pen().width());
52 r.setTop(r.top() - m_pDrawPad->pen().width());
53 r.setRight(r.right() + m_pDrawPad->pen().width());
54 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
55
56 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
57
58 m_mousePressed = false;
59}
60
61void RectangleDrawMode::mouseMoveEvent(QMouseEvent* e)
62{
63 if (m_mousePressed) {
64 QPainter painter;
65 painter.begin(m_pDrawPadCanvas->currentPage());
66 painter.setRasterOp(Qt::NotROP);
67 m_polyline[0] = e->pos();
68 painter.drawRect(QRect(m_polyline[2], m_polyline[1]));
69 painter.drawRect(QRect(m_polyline[2], m_polyline[0]));
70 painter.end();
71
72 QRect r = m_polyline.boundingRect();
73 r = r.normalize();
74 r.setLeft(r.left() - m_pDrawPad->pen().width());
75 r.setTop(r.top() - m_pDrawPad->pen().width());
76 r.setRight(r.right() + m_pDrawPad->pen().width());
77 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
78
79 bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
80
81 m_polyline[1] = m_polyline[0];
82 }
83} 39}
diff --git a/noncore/graphics/drawpad/rectangledrawmode.h b/noncore/graphics/drawpad/rectangledrawmode.h
index 62b85b1..186533d 100644
--- a/noncore/graphics/drawpad/rectangledrawmode.h
+++ b/noncore/graphics/drawpad/rectangledrawmode.h
@@ -1,36 +1,30 @@
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 RECTANGLEDRAWMODE_H 14#ifndef RECTANGLEDRAWMODE_H
15#define RECTANGLEDRAWMODE_H 15#define RECTANGLEDRAWMODE_H
16 16
17#include "drawmode.h" 17#include "shapedrawmode.h"
18 18
19#include <qpointarray.h> 19class RectangleDrawMode : public ShapeDrawMode
20
21class RectangleDrawMode : public DrawMode
22{ 20{
23public: 21public:
24 RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); 22 RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~RectangleDrawMode(); 23 ~RectangleDrawMode();
26 24
27 void mousePressEvent(QMouseEvent* e); 25protected:
28 void mouseReleaseEvent(QMouseEvent* e); 26 void drawFinalShape(QPainter& p);
29 void mouseMoveEvent(QMouseEvent* e); 27 void drawTemporaryShape(QPainter& p);
30
31private:
32 bool m_mousePressed;
33 QPointArray m_polyline;
34}; 28};
35 29
36#endif // RECTANGLEDRAWMODE_H 30#endif // RECTANGLEDRAWMODE_H
diff --git a/noncore/graphics/drawpad/shapedrawmode.cpp b/noncore/graphics/drawpad/shapedrawmode.cpp
new file mode 100644
index 0000000..8b9877d
--- a/dev/null
+++ b/noncore/graphics/drawpad/shapedrawmode.cpp
@@ -0,0 +1,92 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
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 *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "shapedrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qpainter.h>
20#include <qpixmap.h>
21
22ShapeDrawMode::ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25 m_mousePressed = false;
26 m_polyline.resize(3);
27}
28
29ShapeDrawMode::~ShapeDrawMode()
30{
31}
32
33void ShapeDrawMode::mousePressEvent(QMouseEvent* e)
34{
35 m_mousePressed = true;
36 m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
37}
38
39void ShapeDrawMode::mouseReleaseEvent(QMouseEvent* e)
40{
41 Q_UNUSED(e)
42
43 QPainter painter;
44 painter.begin(m_pDrawPadCanvas->currentPage());
45 drawFinalShape(painter);
46 painter.end();
47
48 QRect r = m_polyline.boundingRect();
49 r = r.normalize();
50 r.setLeft(r.left() - m_pDrawPad->pen().width());
51 r.setTop(r.top() - m_pDrawPad->pen().width());
52 r.setRight(r.right() + m_pDrawPad->pen().width());
53 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
54
55 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
56 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
57
58 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
59 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
60
61 m_pDrawPadCanvas->viewport()->update(viewportRect);
62
63 m_mousePressed = false;
64}
65
66void ShapeDrawMode::mouseMoveEvent(QMouseEvent* e)
67{
68 if (m_mousePressed) {
69 m_polyline[0] = e->pos();
70 QPainter painter;
71 painter.begin(m_pDrawPadCanvas->currentPage());
72 drawTemporaryShape(painter);
73 painter.end();
74
75 QRect r = m_polyline.boundingRect();
76 r = r.normalize();
77 r.setLeft(r.left() - m_pDrawPad->pen().width());
78 r.setTop(r.top() - m_pDrawPad->pen().width());
79 r.setRight(r.right() + m_pDrawPad->pen().width());
80 r.setBottom(r.bottom() + m_pDrawPad->pen().width());
81
82 QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
83 m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
84
85 bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
86 m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height());
87
88 m_pDrawPadCanvas->viewport()->update(viewportRect);
89
90 m_polyline[1] = m_polyline[0];
91 }
92}
diff --git a/noncore/graphics/drawpad/shapedrawmode.h b/noncore/graphics/drawpad/shapedrawmode.h
new file mode 100644
index 0000000..292478f
--- a/dev/null
+++ b/noncore/graphics/drawpad/shapedrawmode.h
@@ -0,0 +1,41 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
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 *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#ifndef SHAPEDRAWMODE_H
15#define SHAPEDRAWMODE_H
16
17#include "drawmode.h"
18
19#include <qpointarray.h>
20
21class ShapeDrawMode : public DrawMode
22{
23public:
24 ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~ShapeDrawMode();
26
27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e);
30
31protected:
32 virtual void drawFinalShape(QPainter& p) = 0;
33 virtual void drawTemporaryShape(QPainter& p) = 0;
34
35 QPointArray m_polyline;
36
37private:
38 bool m_mousePressed;
39};
40
41#endif // SHAPEDRAWMODE_H