author | leseb <leseb> | 2002-03-21 17:33:38 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-21 17:33:38 (UTC) |
commit | 29baf8dcda3d05d91d340b739de0fdd9e37f5749 (patch) (unidiff) | |
tree | 5f2958a16cc1f065cdef3e31c2c9500f8aac2e7b | |
parent | 60c9126183ea72c08ad5cb77b8939812627aae17 (diff) | |
download | opie-29baf8dcda3d05d91d340b739de0fdd9e37f5749.zip opie-29baf8dcda3d05d91d340b739de0fdd9e37f5749.tar.gz opie-29baf8dcda3d05d91d340b739de0fdd9e37f5749.tar.bz2 |
Enable any size pages
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 39 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 3 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.pro | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 138 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 18 | ||||
-rw-r--r-- | noncore/graphics/drawpad/ellipsedrawmode.cpp | 63 | ||||
-rw-r--r-- | noncore/graphics/drawpad/ellipsedrawmode.h | 16 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasedrawmode.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filldrawmode.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/linedrawmode.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/linedrawmode.h | 16 | ||||
-rw-r--r-- | noncore/graphics/drawpad/newpagedialog.cpp | 61 | ||||
-rw-r--r-- | noncore/graphics/drawpad/newpagedialog.h | 40 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pointdrawmode.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/drawpad/rectangledrawmode.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/rectangledrawmode.h | 16 | ||||
-rw-r--r-- | noncore/graphics/drawpad/shapedrawmode.cpp | 92 | ||||
-rw-r--r-- | noncore/graphics/drawpad/shapedrawmode.h | 41 |
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 | |||
@@ -1,267 +1,267 @@ | |||
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 "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 | ||
38 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | 38 | DrawPad::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 | ||
80 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 73 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
81 | 74 | ||
82 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); | 75 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); |
83 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); | 76 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); |
84 | newPageAction->addTo(pageToolBar); | 77 | newPageAction->addTo(pageToolBar); |
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 | ||
153 | m_pFillDrawModeAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); | 142 | m_pFillDrawModeAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); |
154 | m_pFillDrawModeAction->setToggleAction(true); | 143 | m_pFillDrawModeAction->setToggleAction(true); |
155 | connect(m_pFillDrawModeAction, SIGNAL(activated()), this, SLOT(setFillDrawMode())); | 144 | connect(m_pFillDrawModeAction, SIGNAL(activated()), this, SLOT(setFillDrawMode())); |
156 | m_pFillDrawModeAction->addTo(drawModeToolBar); | 145 | m_pFillDrawModeAction->addTo(drawModeToolBar); |
157 | 146 | ||
158 | m_pEraseDrawModeAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); | 147 | m_pEraseDrawModeAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); |
159 | m_pEraseDrawModeAction->setToggleAction(true); | 148 | m_pEraseDrawModeAction->setToggleAction(true); |
160 | connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode())); | 149 | connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode())); |
161 | m_pEraseDrawModeAction->addTo(drawModeToolBar); | 150 | m_pEraseDrawModeAction->addTo(drawModeToolBar); |
162 | 151 | ||
163 | m_pDrawMode = 0; | 152 | m_pDrawMode = 0; |
164 | setPointDrawMode(); | 153 | setPointDrawMode(); |
165 | 154 | ||
166 | emptyToolBar = new QPEToolBar(this); | 155 | emptyToolBar = new QPEToolBar(this); |
167 | emptyToolBar->setHorizontalStretchable(true); | 156 | emptyToolBar->setHorizontalStretchable(true); |
168 | emptyToolBar->addSeparator(); | 157 | emptyToolBar->addSeparator(); |
169 | 158 | ||
170 | // init draw parameters toolbar | 159 | // init draw parameters toolbar |
171 | 160 | ||
172 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); | 161 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); |
173 | 162 | ||
174 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); | 163 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); |
175 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); | 164 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); |
176 | 165 | ||
177 | penWidthSpinBox->setValue(1); | 166 | penWidthSpinBox->setValue(1); |
178 | 167 | ||
179 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); | 168 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); |
180 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); | 169 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); |
181 | 170 | ||
182 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); | 171 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); |
183 | 172 | ||
184 | ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); | 173 | ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); |
185 | connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); | 174 | connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); |
186 | penColorPopupMenu->insertItem(penColorPanel); | 175 | penColorPopupMenu->insertItem(penColorPanel); |
187 | 176 | ||
188 | penColorPopupMenu->insertSeparator(); | 177 | penColorPopupMenu->insertSeparator(); |
189 | 178 | ||
190 | QAction* choosePenColorAction = new QAction(tr("More"), tr("More..."), 0, this); | 179 | QAction* choosePenColorAction = new QAction(tr("More"), tr("More..."), 0, this); |
191 | connect(choosePenColorAction, SIGNAL(activated()), this, SLOT(choosePenColor())); | 180 | connect(choosePenColorAction, SIGNAL(activated()), this, SLOT(choosePenColor())); |
192 | choosePenColorAction->addTo(penColorPopupMenu); | 181 | choosePenColorAction->addTo(penColorPopupMenu); |
193 | 182 | ||
194 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); | 183 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); |
195 | m_pPenColorToolButton->setPopup(penColorPopupMenu); | 184 | m_pPenColorToolButton->setPopup(penColorPopupMenu); |
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 | ||
222 | DrawPad::~DrawPad() | 222 | DrawPad::~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 | ||
232 | void DrawPad::setPointDrawMode() | 232 | void 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); |
244 | m_pFillDrawModeAction->setOn(false); | 244 | m_pFillDrawModeAction->setOn(false); |
245 | m_pEraseDrawModeAction->setOn(false); | 245 | m_pEraseDrawModeAction->setOn(false); |
246 | } | 246 | } |
247 | 247 | ||
248 | void DrawPad::setLineDrawMode() | 248 | void DrawPad::setLineDrawMode() |
249 | { | 249 | { |
250 | if (m_pDrawMode) { | 250 | if (m_pDrawMode) { |
251 | delete m_pDrawMode; | 251 | delete m_pDrawMode; |
252 | } | 252 | } |
253 | 253 | ||
254 | m_pDrawMode = new LineDrawMode(this, m_pDrawPadCanvas); | 254 | m_pDrawMode = new LineDrawMode(this, m_pDrawPadCanvas); |
255 | 255 | ||
256 | m_pPointDrawModeAction->setOn(false); | 256 | m_pPointDrawModeAction->setOn(false); |
257 | m_pLineDrawModeAction->setOn(true); | 257 | m_pLineDrawModeAction->setOn(true); |
258 | m_pRectangleDrawModeAction->setOn(false); | 258 | m_pRectangleDrawModeAction->setOn(false); |
259 | m_pEllipseDrawModeAction->setOn(false); | 259 | m_pEllipseDrawModeAction->setOn(false); |
260 | m_pFillDrawModeAction->setOn(false); | 260 | m_pFillDrawModeAction->setOn(false); |
261 | m_pEraseDrawModeAction->setOn(false); | 261 | m_pEraseDrawModeAction->setOn(false); |
262 | } | 262 | } |
263 | 263 | ||
264 | void DrawPad::setRectangleDrawMode() | 264 | void DrawPad::setRectangleDrawMode() |
265 | { | 265 | { |
266 | if (m_pDrawMode) { | 266 | if (m_pDrawMode) { |
267 | delete m_pDrawMode; | 267 | delete m_pDrawMode; |
@@ -334,48 +334,57 @@ void DrawPad::changePenColor(const QColor& color) | |||
334 | { | 334 | { |
335 | m_pen.setColor(color); | 335 | m_pen.setColor(color); |
336 | 336 | ||
337 | QPainter painter; | 337 | QPainter painter; |
338 | painter.begin(m_pPenColorToolButton->pixmap()); | 338 | painter.begin(m_pPenColorToolButton->pixmap()); |
339 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); | 339 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); |
340 | painter.end(); | 340 | painter.end(); |
341 | 341 | ||
342 | m_pPenColorToolButton->popup()->hide(); | 342 | m_pPenColorToolButton->popup()->hide(); |
343 | } | 343 | } |
344 | 344 | ||
345 | void DrawPad::changeBrushColor(const QColor& color) | 345 | void DrawPad::changeBrushColor(const QColor& color) |
346 | { | 346 | { |
347 | m_brush = QBrush(color); | 347 | m_brush = QBrush(color); |
348 | 348 | ||
349 | QPainter painter; | 349 | QPainter painter; |
350 | painter.begin(m_pBrushColorToolButton->pixmap()); | 350 | painter.begin(m_pBrushColorToolButton->pixmap()); |
351 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); | 351 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); |
352 | painter.end(); | 352 | painter.end(); |
353 | 353 | ||
354 | m_pBrushColorToolButton->popup()->hide(); | 354 | m_pBrushColorToolButton->popup()->hide(); |
355 | } | 355 | } |
356 | 356 | ||
357 | void DrawPad::choosePenColor() | 357 | 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 | ||
363 | void DrawPad::chooseBrushColor() | 363 | void 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 | ||
369 | void DrawPad::updateUndoRedoToolButtons() | 369 | void 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 | ||
375 | void DrawPad::updateNavigationToolButtons() | 375 | void 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 | |||
383 | void 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 | |||
@@ -1,84 +1,85 @@ | |||
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); |
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 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 | ||
58 | private: | 59 | private: |
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; |
81 | QToolButton* m_pBrushColorToolButton; | 82 | QToolButton* m_pBrushColorToolButton; |
82 | }; | 83 | }; |
83 | 84 | ||
84 | #endif // DRAWPAD_H | 85 | #endif // DRAWPAD_H |
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,65 +1,66 @@ | |||
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 | ||
29 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 30 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
30 | { | 31 | { |
31 | public: | 32 | public: |
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); |
42 | 43 | ||
43 | private: | 44 | private: |
44 | enum State { | 45 | enum State { |
45 | Unknown, | 46 | Unknown, |
46 | InData | 47 | InData |
47 | }; | 48 | }; |
48 | 49 | ||
49 | State m_state; | 50 | State m_state; |
50 | ulong m_dataLenght; | 51 | ulong m_dataLenght; |
51 | QList<QPixmap> m_pixmaps; | 52 | QList<QPixmap> m_pixmaps; |
52 | }; | 53 | }; |
53 | 54 | ||
54 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() | 55 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() |
55 | { | 56 | { |
56 | m_state = Unknown; | 57 | m_state = Unknown; |
57 | } | 58 | } |
58 | 59 | ||
59 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() | 60 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() |
60 | { | 61 | { |
61 | } | 62 | } |
62 | 63 | ||
63 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() | 64 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() |
64 | { | 65 | { |
65 | return m_pixmaps; | 66 | return m_pixmaps; |
@@ -92,329 +93,354 @@ bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QStr | |||
92 | return true; | 93 | return true; |
93 | } | 94 | } |
94 | 95 | ||
95 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) | 96 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) |
96 | { | 97 | { |
97 | if (m_state == InData) { | 98 | if (m_state == InData) { |
98 | QByteArray byteArray(ch.length() / 2); | 99 | QByteArray byteArray(ch.length() / 2); |
99 | 100 | ||
100 | for (int i = 0; i < (int)ch.length() / 2; i++) { | 101 | for (int i = 0; i < (int)ch.length() / 2; i++) { |
101 | char h = ch[2 * i].latin1(); | 102 | char h = ch[2 * i].latin1(); |
102 | char l = ch[2 * i + 1].latin1(); | 103 | char l = ch[2 * i + 1].latin1(); |
103 | uchar r = 0; | 104 | uchar r = 0; |
104 | 105 | ||
105 | if (h <= '9') { | 106 | if (h <= '9') { |
106 | r += h - '0'; | 107 | r += h - '0'; |
107 | } else { | 108 | } else { |
108 | r += h - 'a' + 10; | 109 | r += h - 'a' + 10; |
109 | } | 110 | } |
110 | 111 | ||
111 | r = r << 4; | 112 | r = r << 4; |
112 | 113 | ||
113 | if (l <= '9') { | 114 | if (l <= '9') { |
114 | r += l - '0'; | 115 | r += l - '0'; |
115 | } else { | 116 | } else { |
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 | ||
140 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name, WFlags f) | 141 | DrawPadCanvas::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 | ||
153 | DrawPadCanvas::~DrawPadCanvas() | 149 | DrawPadCanvas::~DrawPadCanvas() |
154 | { | 150 | { |
155 | } | 151 | } |
156 | 152 | ||
157 | void DrawPadCanvas::load(QIODevice* ioDevice) | 153 | void 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 | |||
182 | void 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 | ||
182 | void DrawPadCanvas::save(QIODevice* ioDevice) | 197 | void 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(); |
204 | 219 | ||
205 | ulong size = byteArray.size() * 2; | 220 | ulong size = byteArray.size() * 2; |
206 | QByteArray byteArrayZipped(size); | 221 | QByteArray byteArrayZipped(size); |
207 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); | 222 | ::compress((uchar*)byteArrayZipped.data(), &size, (uchar*)byteArray.data(), byteArray.size()); |
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 | ||
227 | QPixmap* DrawPadCanvas::currentPage() | 242 | QPixmap* DrawPadCanvas::currentPage() |
228 | { | 243 | { |
229 | return m_pages.current(); | 244 | return m_pages.current(); |
230 | } | 245 | } |
231 | 246 | ||
247 | uint DrawPadCanvas::pagePosition() | ||
248 | { | ||
249 | return (m_pages.at() + 1); | ||
250 | } | ||
251 | |||
252 | uint DrawPadCanvas::pageCount() | ||
253 | { | ||
254 | return m_pages.count(); | ||
255 | } | ||
256 | |||
232 | void DrawPadCanvas::clearAll() | 257 | void 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 | ||
248 | void DrawPadCanvas::newPage() | 274 | void 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 | ||
260 | void DrawPadCanvas::clearPage() | 297 | void 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 | ||
266 | void DrawPadCanvas::deletePage() | 304 | void 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 | ||
284 | bool DrawPadCanvas::undoEnabled() | 323 | bool DrawPadCanvas::undoEnabled() |
285 | { | 324 | { |
286 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | 325 | return (m_pageBackups.current() != m_pageBackups.getFirst()); |
287 | } | 326 | } |
288 | 327 | ||
289 | bool DrawPadCanvas::redoEnabled() | 328 | bool DrawPadCanvas::redoEnabled() |
290 | { | 329 | { |
291 | return (m_pageBackups.current() != m_pageBackups.getLast()); | 330 | return (m_pageBackups.current() != m_pageBackups.getLast()); |
292 | } | 331 | } |
293 | 332 | ||
294 | bool DrawPadCanvas::goPreviousPageEnabled() | 333 | bool DrawPadCanvas::goPreviousPageEnabled() |
295 | { | 334 | { |
296 | return (m_pages.current() != m_pages.getFirst()); | 335 | return (m_pages.current() != m_pages.getFirst()); |
297 | } | 336 | } |
298 | 337 | ||
299 | bool DrawPadCanvas::goNextPageEnabled() | 338 | bool DrawPadCanvas::goNextPageEnabled() |
300 | { | 339 | { |
301 | return (m_pages.current() != m_pages.getLast()); | 340 | return (m_pages.current() != m_pages.getLast()); |
302 | } | 341 | } |
303 | 342 | ||
304 | void DrawPadCanvas::undo() | 343 | void 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 | ||
312 | void DrawPadCanvas::redo() | 352 | void 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 | ||
320 | void DrawPadCanvas::goFirstPage() | 361 | void 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 | ||
331 | void DrawPadCanvas::goPreviousPage() | 374 | void 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 | ||
342 | void DrawPadCanvas::goNextPage() | 387 | void 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 | ||
353 | void DrawPadCanvas::goLastPage() | 400 | void 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 | ||
364 | void DrawPadCanvas::mousePressEvent(QMouseEvent* e) | 413 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
365 | { | 414 | { |
366 | m_pDrawPad->drawMode()->mousePressEvent(e); | 415 | m_pDrawPad->drawMode()->mousePressEvent(e); |
367 | } | 416 | } |
368 | 417 | ||
369 | void DrawPadCanvas::mouseReleaseEvent(QMouseEvent* e) | 418 | void 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 | ||
387 | void DrawPadCanvas::mouseMoveEvent(QMouseEvent* e) | 436 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) |
388 | { | 437 | { |
389 | m_pDrawPad->drawMode()->mouseMoveEvent(e); | 438 | m_pDrawPad->drawMode()->mouseMoveEvent(e); |
390 | } | 439 | } |
391 | 440 | ||
392 | void DrawPadCanvas::resizeEvent(QResizeEvent* e) | 441 | void 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 | |||
410 | void 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 | ||
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 QScrollView |
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); |
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 | ||
44 | public slots: | 47 | public 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 | ||
58 | signals: | 61 | signals: |
59 | void pagesChanged(); | 62 | void pagesChanged(); |
60 | void pageBackupsChanged(); | 63 | void pageBackupsChanged(); |
61 | 64 | ||
62 | protected: | 65 | protected: |
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 | ||
69 | private: | 71 | private: |
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 | ||
22 | EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EllipseDrawMode::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 | ||
29 | EllipseDrawMode::~EllipseDrawMode() | 27 | EllipseDrawMode::~EllipseDrawMode() |
30 | { | 28 | { |
31 | } | 29 | } |
32 | 30 | ||
33 | void EllipseDrawMode::mousePressEvent(QMouseEvent* e) | 31 | void 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 | ||
39 | void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e) | 40 | void 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 | |||
64 | void 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> | 19 | class EllipseDrawMode : public ShapeDrawMode |
20 | |||
21 | class EllipseDrawMode : public DrawMode | ||
22 | { | 20 | { |
23 | public: | 21 | public: |
24 | EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 22 | EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
25 | ~EllipseDrawMode(); | 23 | ~EllipseDrawMode(); |
26 | 24 | ||
27 | void mousePressEvent(QMouseEvent* e); | 25 | protected: |
28 | void mouseReleaseEvent(QMouseEvent* e); | 26 | void drawFinalShape(QPainter& p); |
29 | void mouseMoveEvent(QMouseEvent* e); | 27 | void drawTemporaryShape(QPainter& p); |
30 | |||
31 | private: | ||
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 | |||
@@ -18,51 +18,57 @@ | |||
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | EraseDrawMode::EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EraseDrawMode::EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | m_mousePressed = false; | 25 | m_mousePressed = false; |
26 | m_polyline.resize(3); | 26 | m_polyline.resize(3); |
27 | } | 27 | } |
28 | 28 | ||
29 | EraseDrawMode::~EraseDrawMode() | 29 | EraseDrawMode::~EraseDrawMode() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void EraseDrawMode::mousePressEvent(QMouseEvent* e) | 33 | void EraseDrawMode::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_mousePressed = true; | 35 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void EraseDrawMode::mouseReleaseEvent(QMouseEvent* e) | 39 | void EraseDrawMode::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e) | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | m_mousePressed = false; | 43 | m_mousePressed = false; |
44 | } | 44 | } |
45 | 45 | ||
46 | void EraseDrawMode::mouseMoveEvent(QMouseEvent* e) | 46 | void 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 | |||
@@ -1,96 +1,96 @@ | |||
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 "filldrawmode.h" | 14 | #include "filldrawmode.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qimage.h> | 19 | #include <qimage.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | FillDrawMode::~FillDrawMode() | 27 | FillDrawMode::~FillDrawMode() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void FillDrawMode::mousePressEvent(QMouseEvent* e) | 31 | void 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 | ||
52 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) | 52 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) |
53 | { | 53 | { |
54 | Q_UNUSED(e) | 54 | Q_UNUSED(e) |
55 | } | 55 | } |
56 | 56 | ||
57 | void FillDrawMode::mouseMoveEvent(QMouseEvent* e) | 57 | void FillDrawMode::mouseMoveEvent(QMouseEvent* e) |
58 | { | 58 | { |
59 | Q_UNUSED(e) | 59 | Q_UNUSED(e) |
60 | } | 60 | } |
61 | 61 | ||
62 | void FillDrawMode::fillEast(int x, int y) | 62 | void 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 | } |
73 | 73 | ||
74 | void FillDrawMode::fillSouth(int x, int y) | 74 | void FillDrawMode::fillSouth(int x, int y) |
75 | { | 75 | { |
76 | if (y < m_image.height()) { | 76 | if (y < m_image.height()) { |
77 | if (m_image.pixel(x, y) == m_oldRgb) { | 77 | if (m_image.pixel(x, y) == m_oldRgb) { |
78 | m_image.setPixel(x, y, m_fillRgb); | 78 | m_image.setPixel(x, y, m_fillRgb); |
79 | fillEast(x + 1, y); | 79 | fillEast(x + 1, y); |
80 | fillSouth(x, y + 1); | 80 | fillSouth(x, y + 1); |
81 | fillWest(x - 1, y); | 81 | fillWest(x - 1, y); |
82 | } | 82 | } |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | void FillDrawMode::fillWest(int x, int y) | 86 | void FillDrawMode::fillWest(int x, int y) |
87 | { | 87 | { |
88 | if (x >= 0) { | 88 | if (x >= 0) { |
89 | if (m_image.pixel(x, y) == m_oldRgb) { | 89 | if (m_image.pixel(x, y) == m_oldRgb) { |
90 | m_image.setPixel(x, y, m_fillRgb); | 90 | m_image.setPixel(x, y, m_fillRgb); |
91 | fillSouth(x, y + 1); | 91 | fillSouth(x, y + 1); |
92 | fillWest(x - 1, y); | 92 | fillWest(x - 1, y); |
93 | fillNorth(x, y - 1); | 93 | fillNorth(x, y - 1); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
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 | |||
22 | LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 19 | LineDrawMode::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 | ||
29 | LineDrawMode::~LineDrawMode() | 24 | LineDrawMode::~LineDrawMode() |
30 | { | 25 | { |
31 | } | 26 | } |
32 | 27 | ||
33 | void LineDrawMode::mousePressEvent(QMouseEvent* e) | 28 | void 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 | ||
39 | void LineDrawMode::mouseReleaseEvent(QMouseEvent* e) | 34 | void 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 | |||
61 | void 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> | 19 | class LineDrawMode : public ShapeDrawMode |
20 | |||
21 | class LineDrawMode : public DrawMode | ||
22 | { | 20 | { |
23 | public: | 21 | public: |
24 | LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 22 | LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
25 | ~LineDrawMode(); | 23 | ~LineDrawMode(); |
26 | 24 | ||
27 | void mousePressEvent(QMouseEvent* e); | 25 | protected: |
28 | void mouseReleaseEvent(QMouseEvent* e); | 26 | void drawFinalShape(QPainter& p); |
29 | void mouseMoveEvent(QMouseEvent* e); | 27 | void drawTemporaryShape(QPainter& p); |
30 | |||
31 | private: | ||
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 | |||
20 | NewPageDialog::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 | |||
39 | NewPageDialog::~NewPageDialog() | ||
40 | { | ||
41 | } | ||
42 | |||
43 | void NewPageDialog::setWidth(int width) | ||
44 | { | ||
45 | m_pWidthSpinBox->setValue(width); | ||
46 | } | ||
47 | |||
48 | void NewPageDialog::setHeight(int height) | ||
49 | { | ||
50 | m_pHeightSpinBox->setValue(height); | ||
51 | } | ||
52 | |||
53 | int NewPageDialog::width() | ||
54 | { | ||
55 | return m_pWidthSpinBox->value(); | ||
56 | } | ||
57 | |||
58 | int 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 | |||
19 | class QSpinBox; | ||
20 | |||
21 | class NewPageDialog : public QDialog | ||
22 | { | ||
23 | Q_OBJECT | ||
24 | |||
25 | public: | ||
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 | |||
35 | private: | ||
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 | |||
@@ -17,51 +17,57 @@ | |||
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 | ||
22 | PointDrawMode::PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | PointDrawMode::PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | m_mousePressed = false; | 25 | m_mousePressed = false; |
26 | m_polyline.resize(3); | 26 | m_polyline.resize(3); |
27 | } | 27 | } |
28 | 28 | ||
29 | PointDrawMode::~PointDrawMode() | 29 | PointDrawMode::~PointDrawMode() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void PointDrawMode::mousePressEvent(QMouseEvent* e) | 33 | void PointDrawMode::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_mousePressed = true; | 35 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void PointDrawMode::mouseReleaseEvent(QMouseEvent* e) | 39 | void PointDrawMode::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e) | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | m_mousePressed = false; | 43 | m_mousePressed = false; |
44 | } | 44 | } |
45 | 45 | ||
46 | void PointDrawMode::mouseMoveEvent(QMouseEvent* e) | 46 | void 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 | |||
22 | RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 19 | RectangleDrawMode::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 | ||
29 | RectangleDrawMode::~RectangleDrawMode() | 24 | RectangleDrawMode::~RectangleDrawMode() |
30 | { | 25 | { |
31 | } | 26 | } |
32 | 27 | ||
33 | void RectangleDrawMode::mousePressEvent(QMouseEvent* e) | 28 | void 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 | ||
39 | void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e) | 34 | void 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 | |||
61 | void 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> | 19 | class RectangleDrawMode : public ShapeDrawMode |
20 | |||
21 | class RectangleDrawMode : public DrawMode | ||
22 | { | 20 | { |
23 | public: | 21 | public: |
24 | RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 22 | RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
25 | ~RectangleDrawMode(); | 23 | ~RectangleDrawMode(); |
26 | 24 | ||
27 | void mousePressEvent(QMouseEvent* e); | 25 | protected: |
28 | void mouseReleaseEvent(QMouseEvent* e); | 26 | void drawFinalShape(QPainter& p); |
29 | void mouseMoveEvent(QMouseEvent* e); | 27 | void drawTemporaryShape(QPainter& p); |
30 | |||
31 | private: | ||
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 | |||
22 | ShapeDrawMode::ShapeDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | ||
23 | : DrawMode(drawPad, drawPadCanvas) | ||
24 | { | ||
25 | m_mousePressed = false; | ||
26 | m_polyline.resize(3); | ||
27 | } | ||
28 | |||
29 | ShapeDrawMode::~ShapeDrawMode() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | void ShapeDrawMode::mousePressEvent(QMouseEvent* e) | ||
34 | { | ||
35 | m_mousePressed = true; | ||
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | ||
37 | } | ||
38 | |||
39 | void 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 | |||
66 | void 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 | |||
21 | class ShapeDrawMode : public DrawMode | ||
22 | { | ||
23 | public: | ||
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 | |||
31 | protected: | ||
32 | virtual void drawFinalShape(QPainter& p) = 0; | ||
33 | virtual void drawTemporaryShape(QPainter& p) = 0; | ||
34 | |||
35 | QPointArray m_polyline; | ||
36 | |||
37 | private: | ||
38 | bool m_mousePressed; | ||
39 | }; | ||
40 | |||
41 | #endif // SHAPEDRAWMODE_H | ||