author | leseb <leseb> | 2002-06-06 20:51:27 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-06 20:51:27 (UTC) |
commit | 43bde653ce03f4c5202860f4e23c7612144a38f0 (patch) (unidiff) | |
tree | aa89f01ade2667699e2d9ba69daabb9810e48c35 | |
parent | 38946b6ef966a154d979d7dd254cf463f6dadbe5 (diff) | |
download | opie-43bde653ce03f4c5202860f4e23c7612144a38f0.zip opie-43bde653ce03f4c5202860f4e23c7612144a38f0.tar.gz opie-43bde653ce03f4c5202860f4e23c7612144a38f0.tar.bz2 |
New page class, thumbnail view draft
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 15 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 1 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.pro | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 64 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 11 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasetool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filltool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.cpp | 33 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.h | 29 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pointtool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/shapetool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/texttool.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 121 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.h | 40 |
14 files changed, 285 insertions, 43 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 74787e5..b325323 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -1,521 +1,536 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "drawpad.h" | 14 | #include "drawpad.h" |
15 | 15 | ||
16 | #include "drawpadcanvas.h" | 16 | #include "drawpadcanvas.h" |
17 | #include "ellipsetool.h" | 17 | #include "ellipsetool.h" |
18 | #include "erasetool.h" | 18 | #include "erasetool.h" |
19 | #include "exportdialog.h" | 19 | #include "exportdialog.h" |
20 | #include "filledellipsetool.h" | 20 | #include "filledellipsetool.h" |
21 | #include "filledrectangletool.h" | 21 | #include "filledrectangletool.h" |
22 | #include "filltool.h" | 22 | #include "filltool.h" |
23 | #include "importdialog.h" | 23 | #include "importdialog.h" |
24 | #include "linetool.h" | 24 | #include "linetool.h" |
25 | #include "pointtool.h" | 25 | #include "pointtool.h" |
26 | #include "rectangletool.h" | 26 | #include "rectangletool.h" |
27 | #include "texttool.h" | 27 | #include "texttool.h" |
28 | #include "thumbnailview.h" | ||
28 | 29 | ||
29 | #include <opie/colordialog.h> | 30 | #include <opie/colordialog.h> |
30 | #include <opie/colorpopupmenu.h> | 31 | #include <opie/colorpopupmenu.h> |
31 | 32 | ||
32 | #include <qpe/applnk.h> | 33 | #include <qpe/applnk.h> |
33 | #include <qpe/global.h> | 34 | #include <qpe/global.h> |
34 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
35 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
36 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
37 | 38 | ||
38 | #include <qaction.h> | 39 | #include <qaction.h> |
39 | #include <qfile.h> | 40 | #include <qfile.h> |
40 | #include <qpainter.h> | 41 | #include <qpainter.h> |
41 | #include <qspinbox.h> | 42 | #include <qspinbox.h> |
42 | #include <qtoolbutton.h> | 43 | #include <qtoolbutton.h> |
43 | #include <qtooltip.h> | 44 | #include <qtooltip.h> |
44 | 45 | ||
45 | DrawPad::DrawPad(QWidget* parent, const char* name) | 46 | DrawPad::DrawPad(QWidget* parent, const char* name) |
46 | : QMainWindow(parent, name) | 47 | : QMainWindow(parent, name) |
47 | { | 48 | { |
48 | // init members | 49 | // init members |
49 | 50 | ||
50 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 51 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
51 | 52 | ||
52 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); | 53 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); |
53 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); | 54 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); |
54 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); | 55 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); |
55 | 56 | ||
56 | setCentralWidget(m_pDrawPadCanvas); | 57 | setCentralWidget(m_pDrawPadCanvas); |
57 | 58 | ||
58 | // init menu | 59 | // init menu |
59 | 60 | ||
60 | setToolBarsMovable(false); | 61 | setToolBarsMovable(false); |
61 | 62 | ||
62 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 63 | QPEToolBar* menuToolBar = new QPEToolBar(this); |
63 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); | 64 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); |
64 | 65 | ||
65 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); | 66 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); |
66 | 67 | ||
67 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); | 68 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); |
68 | connect(deleteAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deleteAll())); | 69 | connect(deleteAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deleteAll())); |
69 | deleteAllAction->addTo(toolsPopupMenu); | 70 | deleteAllAction->addTo(toolsPopupMenu); |
70 | 71 | ||
71 | toolsPopupMenu->insertSeparator(); | 72 | toolsPopupMenu->insertSeparator(); |
72 | 73 | ||
73 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); | 74 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); |
74 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); | 75 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); |
75 | importPageAction->addTo(toolsPopupMenu); | 76 | importPageAction->addTo(toolsPopupMenu); |
76 | 77 | ||
77 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); | 78 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); |
78 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); | 79 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); |
79 | exportPageAction->addTo(toolsPopupMenu); | 80 | exportPageAction->addTo(toolsPopupMenu); |
80 | 81 | ||
82 | toolsPopupMenu->insertSeparator(); | ||
83 | |||
84 | QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); | ||
85 | connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); | ||
86 | thumbnailViewAction->addTo(toolsPopupMenu); | ||
87 | |||
81 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); | 88 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); |
82 | 89 | ||
83 | // init page toolbar | 90 | // init page toolbar |
84 | 91 | ||
85 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 92 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
86 | 93 | ||
87 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); | 94 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); |
88 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); | 95 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); |
89 | newPageAction->addTo(pageToolBar); | 96 | newPageAction->addTo(pageToolBar); |
90 | 97 | ||
91 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); | 98 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); |
92 | connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); | 99 | connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); |
93 | clearPageAction->addTo(pageToolBar); | 100 | clearPageAction->addTo(pageToolBar); |
94 | 101 | ||
95 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); | 102 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); |
96 | connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); | 103 | connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); |
97 | deletePageAction->addTo(pageToolBar); | 104 | deletePageAction->addTo(pageToolBar); |
98 | 105 | ||
99 | QPEToolBar* emptyToolBar = new QPEToolBar(this); | 106 | QPEToolBar* emptyToolBar = new QPEToolBar(this); |
100 | emptyToolBar->setHorizontalStretchable(true); | 107 | emptyToolBar->setHorizontalStretchable(true); |
101 | 108 | ||
102 | // init navigation toolbar | 109 | // init navigation toolbar |
103 | 110 | ||
104 | QPEToolBar* navigationToolBar = new QPEToolBar(this); | 111 | QPEToolBar* navigationToolBar = new QPEToolBar(this); |
105 | 112 | ||
106 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); | 113 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); |
107 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); | 114 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); |
108 | m_pUndoAction->addTo(navigationToolBar); | 115 | m_pUndoAction->addTo(navigationToolBar); |
109 | 116 | ||
110 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); | 117 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this); |
111 | connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); | 118 | connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); |
112 | m_pRedoAction->addTo(navigationToolBar); | 119 | m_pRedoAction->addTo(navigationToolBar); |
113 | 120 | ||
114 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); | 121 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); |
115 | connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); | 122 | connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); |
116 | m_pFirstPageAction->addTo(navigationToolBar); | 123 | m_pFirstPageAction->addTo(navigationToolBar); |
117 | 124 | ||
118 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); | 125 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); |
119 | connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); | 126 | connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); |
120 | m_pPreviousPageAction->addTo(navigationToolBar); | 127 | m_pPreviousPageAction->addTo(navigationToolBar); |
121 | 128 | ||
122 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); | 129 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); |
123 | connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); | 130 | connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); |
124 | m_pNextPageAction->addTo(navigationToolBar); | 131 | m_pNextPageAction->addTo(navigationToolBar); |
125 | 132 | ||
126 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); | 133 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); |
127 | connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); | 134 | connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); |
128 | m_pLastPageAction->addTo(navigationToolBar); | 135 | m_pLastPageAction->addTo(navigationToolBar); |
129 | 136 | ||
130 | // init draw mode toolbar | 137 | // init draw mode toolbar |
131 | 138 | ||
132 | QPEToolBar* drawModeToolBar = new QPEToolBar(this); | 139 | QPEToolBar* drawModeToolBar = new QPEToolBar(this); |
133 | 140 | ||
134 | m_pLineToolButton = new QToolButton(drawModeToolBar); | 141 | m_pLineToolButton = new QToolButton(drawModeToolBar); |
135 | m_pLineToolButton->setToggleButton(true); | 142 | m_pLineToolButton->setToggleButton(true); |
136 | 143 | ||
137 | QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton); | 144 | QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton); |
138 | 145 | ||
139 | m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), "", 0, this); | 146 | m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), "", 0, this); |
140 | connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool())); | 147 | connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool())); |
141 | m_pPointToolAction->addTo(linePopupMenu); | 148 | m_pPointToolAction->addTo(linePopupMenu); |
142 | 149 | ||
143 | m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), "", 0, this); | 150 | m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), "", 0, this); |
144 | connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool())); | 151 | connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool())); |
145 | m_pLineToolAction->addTo(linePopupMenu); | 152 | m_pLineToolAction->addTo(linePopupMenu); |
146 | 153 | ||
147 | m_pLineToolButton->setPopup(linePopupMenu); | 154 | m_pLineToolButton->setPopup(linePopupMenu); |
148 | m_pLineToolButton->setPopupDelay(0); | 155 | m_pLineToolButton->setPopupDelay(0); |
149 | 156 | ||
150 | m_pRectangleToolButton = new QToolButton(drawModeToolBar); | 157 | m_pRectangleToolButton = new QToolButton(drawModeToolBar); |
151 | m_pRectangleToolButton->setToggleButton(true); | 158 | m_pRectangleToolButton->setToggleButton(true); |
152 | 159 | ||
153 | QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton); | 160 | QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton); |
154 | 161 | ||
155 | m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), "", 0, this); | 162 | m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), "", 0, this); |
156 | connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool())); | 163 | connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool())); |
157 | m_pRectangleToolAction->addTo(rectanglePopupMenu); | 164 | m_pRectangleToolAction->addTo(rectanglePopupMenu); |
158 | 165 | ||
159 | m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadIconSet("drawpad/filledrectangle.png"), "", 0, this); | 166 | m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadIconSet("drawpad/filledrectangle.png"), "", 0, this); |
160 | connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool())); | 167 | connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool())); |
161 | m_pFilledRectangleToolAction->addTo(rectanglePopupMenu); | 168 | m_pFilledRectangleToolAction->addTo(rectanglePopupMenu); |
162 | 169 | ||
163 | m_pRectangleToolButton->setPopup(rectanglePopupMenu); | 170 | m_pRectangleToolButton->setPopup(rectanglePopupMenu); |
164 | m_pRectangleToolButton->setPopupDelay(0); | 171 | m_pRectangleToolButton->setPopupDelay(0); |
165 | 172 | ||
166 | m_pEllipseToolButton = new QToolButton(drawModeToolBar); | 173 | m_pEllipseToolButton = new QToolButton(drawModeToolBar); |
167 | m_pEllipseToolButton->setToggleButton(true); | 174 | m_pEllipseToolButton->setToggleButton(true); |
168 | 175 | ||
169 | QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton); | 176 | QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton); |
170 | 177 | ||
171 | m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), "", 0, this); | 178 | m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), "", 0, this); |
172 | connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool())); | 179 | connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool())); |
173 | m_pEllipseToolAction->addTo(ellipsePopupMenu); | 180 | m_pEllipseToolAction->addTo(ellipsePopupMenu); |
174 | 181 | ||
175 | m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadIconSet("drawpad/filledellipse.png"), "", 0, this); | 182 | m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadIconSet("drawpad/filledellipse.png"), "", 0, this); |
176 | connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool())); | 183 | connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool())); |
177 | m_pFilledEllipseToolAction->addTo(ellipsePopupMenu); | 184 | m_pFilledEllipseToolAction->addTo(ellipsePopupMenu); |
178 | 185 | ||
179 | m_pEllipseToolButton->setPopup(ellipsePopupMenu); | 186 | m_pEllipseToolButton->setPopup(ellipsePopupMenu); |
180 | m_pEllipseToolButton->setPopupDelay(0); | 187 | m_pEllipseToolButton->setPopupDelay(0); |
181 | 188 | ||
182 | m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadIconSet("drawpad/text.png"), QString::null, 0, this); | 189 | m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadIconSet("drawpad/text.png"), QString::null, 0, this); |
183 | m_pTextToolAction->setToggleAction(true); | 190 | m_pTextToolAction->setToggleAction(true); |
184 | connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool())); | 191 | connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool())); |
185 | m_pTextToolAction->addTo(drawModeToolBar); | 192 | m_pTextToolAction->addTo(drawModeToolBar); |
186 | 193 | ||
187 | m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); | 194 | m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); |
188 | m_pFillToolAction->setToggleAction(true); | 195 | m_pFillToolAction->setToggleAction(true); |
189 | connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); | 196 | connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); |
190 | m_pFillToolAction->addTo(drawModeToolBar); | 197 | m_pFillToolAction->addTo(drawModeToolBar); |
191 | 198 | ||
192 | m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); | 199 | m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); |
193 | m_pEraseToolAction->setToggleAction(true); | 200 | m_pEraseToolAction->setToggleAction(true); |
194 | connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); | 201 | connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); |
195 | m_pEraseToolAction->addTo(drawModeToolBar); | 202 | m_pEraseToolAction->addTo(drawModeToolBar); |
196 | 203 | ||
197 | m_pTool = 0; | 204 | m_pTool = 0; |
198 | setRectangleTool(); | 205 | setRectangleTool(); |
199 | setEllipseTool(); | 206 | setEllipseTool(); |
200 | setPointTool(); | 207 | setPointTool(); |
201 | 208 | ||
202 | emptyToolBar = new QPEToolBar(this); | 209 | emptyToolBar = new QPEToolBar(this); |
203 | emptyToolBar->setHorizontalStretchable(true); | 210 | emptyToolBar->setHorizontalStretchable(true); |
204 | emptyToolBar->addSeparator(); | 211 | emptyToolBar->addSeparator(); |
205 | 212 | ||
206 | // init draw parameters toolbar | 213 | // init draw parameters toolbar |
207 | 214 | ||
208 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); | 215 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); |
209 | 216 | ||
210 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); | 217 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); |
211 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); | 218 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); |
212 | 219 | ||
213 | QToolTip::add(penWidthSpinBox, tr("Pen Width")); | 220 | QToolTip::add(penWidthSpinBox, tr("Pen Width")); |
214 | penWidthSpinBox->setValue(1); | 221 | penWidthSpinBox->setValue(1); |
215 | penWidthSpinBox->setFocusPolicy(QWidget::NoFocus); | 222 | penWidthSpinBox->setFocusPolicy(QWidget::NoFocus); |
216 | 223 | ||
217 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); | 224 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); |
218 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); | 225 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); |
219 | 226 | ||
220 | ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, m_pPenColorToolButton); | 227 | ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, m_pPenColorToolButton); |
221 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); | 228 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); |
222 | 229 | ||
223 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); | 230 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); |
224 | m_pPenColorToolButton->setPopup(penColorPopupMenu); | 231 | m_pPenColorToolButton->setPopup(penColorPopupMenu); |
225 | m_pPenColorToolButton->setPopupDelay(0); | 232 | m_pPenColorToolButton->setPopupDelay(0); |
226 | 233 | ||
227 | changePenColor(Qt::black); | 234 | changePenColor(Qt::black); |
228 | 235 | ||
229 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); | 236 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); |
230 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); | 237 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); |
231 | 238 | ||
232 | ColorPopupMenu* brushColorPopupMenu = new ColorPopupMenu(Qt::white, m_pBrushColorToolButton); | 239 | ColorPopupMenu* brushColorPopupMenu = new ColorPopupMenu(Qt::white, m_pBrushColorToolButton); |
233 | connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); | 240 | connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); |
234 | 241 | ||
235 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); | 242 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); |
236 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); | 243 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); |
237 | m_pBrushColorToolButton->setPopupDelay(0); | 244 | m_pBrushColorToolButton->setPopupDelay(0); |
238 | 245 | ||
239 | changeBrushColor(Qt::white); | 246 | changeBrushColor(Qt::white); |
240 | 247 | ||
241 | // init pages | 248 | // init pages |
242 | 249 | ||
243 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 250 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
244 | 251 | ||
245 | if (file.open(IO_ReadOnly)) { | 252 | if (file.open(IO_ReadOnly)) { |
246 | m_pDrawPadCanvas->load(&file); | 253 | m_pDrawPadCanvas->load(&file); |
247 | file.close(); | 254 | file.close(); |
248 | } else { | 255 | } else { |
249 | m_pDrawPadCanvas->initialPage(); | 256 | m_pDrawPadCanvas->initialPage(); |
250 | } | 257 | } |
251 | } | 258 | } |
252 | 259 | ||
253 | DrawPad::~DrawPad() | 260 | DrawPad::~DrawPad() |
254 | { | 261 | { |
255 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 262 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
256 | 263 | ||
257 | if (file.open(IO_WriteOnly)) { | 264 | if (file.open(IO_WriteOnly)) { |
258 | m_pDrawPadCanvas->save(&file); | 265 | m_pDrawPadCanvas->save(&file); |
259 | file.close(); | 266 | file.close(); |
260 | } | 267 | } |
261 | } | 268 | } |
262 | 269 | ||
263 | void DrawPad::setPointTool() | 270 | void DrawPad::setPointTool() |
264 | { | 271 | { |
265 | if (m_pTool) { | 272 | if (m_pTool) { |
266 | delete m_pTool; | 273 | delete m_pTool; |
267 | } | 274 | } |
268 | 275 | ||
269 | m_pTool = new PointTool(this, m_pDrawPadCanvas); | 276 | m_pTool = new PointTool(this, m_pDrawPadCanvas); |
270 | 277 | ||
271 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); | 278 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); |
272 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); | 279 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); |
273 | 280 | ||
274 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); | 281 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); |
275 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated())); | 282 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated())); |
276 | 283 | ||
277 | m_pLineToolButton->setOn(true); | 284 | m_pLineToolButton->setOn(true); |
278 | m_pRectangleToolButton->setOn(false); | 285 | m_pRectangleToolButton->setOn(false); |
279 | m_pEllipseToolButton->setOn(false); | 286 | m_pEllipseToolButton->setOn(false); |
280 | m_pTextToolAction->setOn(false); | 287 | m_pTextToolAction->setOn(false); |
281 | m_pFillToolAction->setOn(false); | 288 | m_pFillToolAction->setOn(false); |
282 | m_pEraseToolAction->setOn(false); | 289 | m_pEraseToolAction->setOn(false); |
283 | } | 290 | } |
284 | 291 | ||
285 | void DrawPad::setLineTool() | 292 | void DrawPad::setLineTool() |
286 | { | 293 | { |
287 | if (m_pTool) { | 294 | if (m_pTool) { |
288 | delete m_pTool; | 295 | delete m_pTool; |
289 | } | 296 | } |
290 | 297 | ||
291 | m_pTool = new LineTool(this, m_pDrawPadCanvas); | 298 | m_pTool = new LineTool(this, m_pDrawPadCanvas); |
292 | 299 | ||
293 | m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet()); | 300 | m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet()); |
294 | QToolTip::add(m_pLineToolButton, m_pLineToolAction->text()); | 301 | QToolTip::add(m_pLineToolButton, m_pLineToolAction->text()); |
295 | 302 | ||
296 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); | 303 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); |
297 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated())); | 304 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated())); |
298 | 305 | ||
299 | m_pLineToolButton->setOn(true); | 306 | m_pLineToolButton->setOn(true); |
300 | m_pRectangleToolButton->setOn(false); | 307 | m_pRectangleToolButton->setOn(false); |
301 | m_pEllipseToolButton->setOn(false); | 308 | m_pEllipseToolButton->setOn(false); |
302 | m_pTextToolAction->setOn(false); | 309 | m_pTextToolAction->setOn(false); |
303 | m_pFillToolAction->setOn(false); | 310 | m_pFillToolAction->setOn(false); |
304 | m_pEraseToolAction->setOn(false); | 311 | m_pEraseToolAction->setOn(false); |
305 | } | 312 | } |
306 | 313 | ||
307 | void DrawPad::setRectangleTool() | 314 | void DrawPad::setRectangleTool() |
308 | { | 315 | { |
309 | if (m_pTool) { | 316 | if (m_pTool) { |
310 | delete m_pTool; | 317 | delete m_pTool; |
311 | } | 318 | } |
312 | 319 | ||
313 | m_pTool = new RectangleTool(this, m_pDrawPadCanvas); | 320 | m_pTool = new RectangleTool(this, m_pDrawPadCanvas); |
314 | 321 | ||
315 | m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet()); | 322 | m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet()); |
316 | QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text()); | 323 | QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text()); |
317 | 324 | ||
318 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); | 325 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); |
319 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated())); | 326 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated())); |
320 | 327 | ||
321 | m_pLineToolButton->setOn(false); | 328 | m_pLineToolButton->setOn(false); |
322 | m_pRectangleToolButton->setOn(true); | 329 | m_pRectangleToolButton->setOn(true); |
323 | m_pEllipseToolButton->setOn(false); | 330 | m_pEllipseToolButton->setOn(false); |
324 | m_pTextToolAction->setOn(false); | 331 | m_pTextToolAction->setOn(false); |
325 | m_pFillToolAction->setOn(false); | 332 | m_pFillToolAction->setOn(false); |
326 | m_pEraseToolAction->setOn(false); | 333 | m_pEraseToolAction->setOn(false); |
327 | } | 334 | } |
328 | 335 | ||
329 | void DrawPad::setFilledRectangleTool() | 336 | void DrawPad::setFilledRectangleTool() |
330 | { | 337 | { |
331 | if (m_pTool) { | 338 | if (m_pTool) { |
332 | delete m_pTool; | 339 | delete m_pTool; |
333 | } | 340 | } |
334 | 341 | ||
335 | m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas); | 342 | m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas); |
336 | 343 | ||
337 | m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet()); | 344 | m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet()); |
338 | QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text()); | 345 | QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text()); |
339 | 346 | ||
340 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); | 347 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); |
341 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated())); | 348 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated())); |
342 | 349 | ||
343 | m_pLineToolButton->setOn(false); | 350 | m_pLineToolButton->setOn(false); |
344 | m_pRectangleToolButton->setOn(true); | 351 | m_pRectangleToolButton->setOn(true); |
345 | m_pEllipseToolButton->setOn(false); | 352 | m_pEllipseToolButton->setOn(false); |
346 | m_pTextToolAction->setOn(false); | 353 | m_pTextToolAction->setOn(false); |
347 | m_pFillToolAction->setOn(false); | 354 | m_pFillToolAction->setOn(false); |
348 | m_pEraseToolAction->setOn(false); | 355 | m_pEraseToolAction->setOn(false); |
349 | } | 356 | } |
350 | 357 | ||
351 | void DrawPad::setEllipseTool() | 358 | void DrawPad::setEllipseTool() |
352 | { | 359 | { |
353 | if (m_pTool) { | 360 | if (m_pTool) { |
354 | delete m_pTool; | 361 | delete m_pTool; |
355 | } | 362 | } |
356 | 363 | ||
357 | m_pTool = new EllipseTool(this, m_pDrawPadCanvas); | 364 | m_pTool = new EllipseTool(this, m_pDrawPadCanvas); |
358 | 365 | ||
359 | m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet()); | 366 | m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet()); |
360 | QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text()); | 367 | QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text()); |
361 | 368 | ||
362 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); | 369 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); |
363 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated())); | 370 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated())); |
364 | 371 | ||
365 | m_pLineToolButton->setOn(false); | 372 | m_pLineToolButton->setOn(false); |
366 | m_pRectangleToolButton->setOn(false); | 373 | m_pRectangleToolButton->setOn(false); |
367 | m_pEllipseToolButton->setOn(true); | 374 | m_pEllipseToolButton->setOn(true); |
368 | m_pTextToolAction->setOn(false); | 375 | m_pTextToolAction->setOn(false); |
369 | m_pFillToolAction->setOn(false); | 376 | m_pFillToolAction->setOn(false); |
370 | m_pEraseToolAction->setOn(false); | 377 | m_pEraseToolAction->setOn(false); |
371 | } | 378 | } |
372 | 379 | ||
373 | void DrawPad::setFilledEllipseTool() | 380 | void DrawPad::setFilledEllipseTool() |
374 | { | 381 | { |
375 | if (m_pTool) { | 382 | if (m_pTool) { |
376 | delete m_pTool; | 383 | delete m_pTool; |
377 | } | 384 | } |
378 | 385 | ||
379 | m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas); | 386 | m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas); |
380 | 387 | ||
381 | m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet()); | 388 | m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet()); |
382 | QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text()); | 389 | QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text()); |
383 | 390 | ||
384 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); | 391 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); |
385 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated())); | 392 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated())); |
386 | 393 | ||
387 | m_pLineToolButton->setOn(false); | 394 | m_pLineToolButton->setOn(false); |
388 | m_pRectangleToolButton->setOn(false); | 395 | m_pRectangleToolButton->setOn(false); |
389 | m_pEllipseToolButton->setOn(true); | 396 | m_pEllipseToolButton->setOn(true); |
390 | m_pTextToolAction->setOn(false); | 397 | m_pTextToolAction->setOn(false); |
391 | m_pFillToolAction->setOn(false); | 398 | m_pFillToolAction->setOn(false); |
392 | m_pEraseToolAction->setOn(false); | 399 | m_pEraseToolAction->setOn(false); |
393 | } | 400 | } |
394 | 401 | ||
395 | void DrawPad::setTextTool() | 402 | void DrawPad::setTextTool() |
396 | { | 403 | { |
397 | if (m_pTool) { | 404 | if (m_pTool) { |
398 | delete m_pTool; | 405 | delete m_pTool; |
399 | } | 406 | } |
400 | 407 | ||
401 | m_pTool = new TextTool(this, m_pDrawPadCanvas); | 408 | m_pTool = new TextTool(this, m_pDrawPadCanvas); |
402 | 409 | ||
403 | m_pLineToolButton->setOn(false); | 410 | m_pLineToolButton->setOn(false); |
404 | m_pRectangleToolButton->setOn(false); | 411 | m_pRectangleToolButton->setOn(false); |
405 | m_pEllipseToolButton->setOn(false); | 412 | m_pEllipseToolButton->setOn(false); |
406 | m_pTextToolAction->setOn(true); | 413 | m_pTextToolAction->setOn(true); |
407 | m_pFillToolAction->setOn(false); | 414 | m_pFillToolAction->setOn(false); |
408 | m_pEraseToolAction->setOn(false); | 415 | m_pEraseToolAction->setOn(false); |
409 | } | 416 | } |
410 | 417 | ||
411 | void DrawPad::setFillTool() | 418 | void DrawPad::setFillTool() |
412 | { | 419 | { |
413 | if (m_pTool) { | 420 | if (m_pTool) { |
414 | delete m_pTool; | 421 | delete m_pTool; |
415 | } | 422 | } |
416 | 423 | ||
417 | m_pTool = new FillTool(this, m_pDrawPadCanvas); | 424 | m_pTool = new FillTool(this, m_pDrawPadCanvas); |
418 | 425 | ||
419 | m_pLineToolButton->setOn(false); | 426 | m_pLineToolButton->setOn(false); |
420 | m_pRectangleToolButton->setOn(false); | 427 | m_pRectangleToolButton->setOn(false); |
421 | m_pEllipseToolButton->setOn(false); | 428 | m_pEllipseToolButton->setOn(false); |
422 | m_pTextToolAction->setOn(false); | 429 | m_pTextToolAction->setOn(false); |
423 | m_pFillToolAction->setOn(true); | 430 | m_pFillToolAction->setOn(true); |
424 | m_pEraseToolAction->setOn(false); | 431 | m_pEraseToolAction->setOn(false); |
425 | } | 432 | } |
426 | 433 | ||
427 | void DrawPad::setEraseTool() | 434 | void DrawPad::setEraseTool() |
428 | { | 435 | { |
429 | if (m_pTool) { | 436 | if (m_pTool) { |
430 | delete m_pTool; | 437 | delete m_pTool; |
431 | } | 438 | } |
432 | 439 | ||
433 | m_pTool = new EraseTool(this, m_pDrawPadCanvas); | 440 | m_pTool = new EraseTool(this, m_pDrawPadCanvas); |
434 | 441 | ||
435 | m_pLineToolButton->setOn(false); | 442 | m_pLineToolButton->setOn(false); |
436 | m_pRectangleToolButton->setOn(false); | 443 | m_pRectangleToolButton->setOn(false); |
437 | m_pEllipseToolButton->setOn(false); | 444 | m_pEllipseToolButton->setOn(false); |
438 | m_pTextToolAction->setOn(false); | 445 | m_pTextToolAction->setOn(false); |
439 | m_pFillToolAction->setOn(false); | 446 | m_pFillToolAction->setOn(false); |
440 | m_pEraseToolAction->setOn(true); | 447 | m_pEraseToolAction->setOn(true); |
441 | } | 448 | } |
442 | 449 | ||
443 | void DrawPad::changePenWidth(int value) | 450 | void DrawPad::changePenWidth(int value) |
444 | { | 451 | { |
445 | m_pen.setWidth(value); | 452 | m_pen.setWidth(value); |
446 | } | 453 | } |
447 | 454 | ||
448 | void DrawPad::changePenColor(const QColor& color) | 455 | void DrawPad::changePenColor(const QColor& color) |
449 | { | 456 | { |
450 | m_pen.setColor(color); | 457 | m_pen.setColor(color); |
451 | 458 | ||
452 | QPainter painter; | 459 | QPainter painter; |
453 | painter.begin(m_pPenColorToolButton->pixmap()); | 460 | painter.begin(m_pPenColorToolButton->pixmap()); |
454 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); | 461 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); |
455 | painter.end(); | 462 | painter.end(); |
456 | 463 | ||
457 | m_pPenColorToolButton->popup()->hide(); | 464 | m_pPenColorToolButton->popup()->hide(); |
458 | } | 465 | } |
459 | 466 | ||
460 | void DrawPad::changeBrushColor(const QColor& color) | 467 | void DrawPad::changeBrushColor(const QColor& color) |
461 | { | 468 | { |
462 | m_brush = QBrush(color); | 469 | m_brush = QBrush(color); |
463 | 470 | ||
464 | QPainter painter; | 471 | QPainter painter; |
465 | painter.begin(m_pBrushColorToolButton->pixmap()); | 472 | painter.begin(m_pBrushColorToolButton->pixmap()); |
466 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); | 473 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); |
467 | painter.end(); | 474 | painter.end(); |
468 | 475 | ||
469 | m_pBrushColorToolButton->popup()->hide(); | 476 | m_pBrushColorToolButton->popup()->hide(); |
470 | } | 477 | } |
471 | 478 | ||
472 | void DrawPad::updateUndoRedoToolButtons() | 479 | void DrawPad::updateUndoRedoToolButtons() |
473 | { | 480 | { |
474 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); | 481 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); |
475 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); | 482 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); |
476 | } | 483 | } |
477 | 484 | ||
478 | void DrawPad::updateNavigationToolButtons() | 485 | void DrawPad::updateNavigationToolButtons() |
479 | { | 486 | { |
480 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 487 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
481 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 488 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
482 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 489 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
483 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 490 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
484 | } | 491 | } |
485 | 492 | ||
486 | void DrawPad::updateCaption() | 493 | void DrawPad::updateCaption() |
487 | { | 494 | { |
488 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); | 495 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); |
489 | uint pageCount = m_pDrawPadCanvas->pageCount(); | 496 | uint pageCount = m_pDrawPadCanvas->pageCount(); |
490 | 497 | ||
491 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " | 498 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " |
492 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); | 499 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); |
493 | } | 500 | } |
494 | 501 | ||
495 | void DrawPad::importPage() | 502 | void DrawPad::importPage() |
496 | { | 503 | { |
497 | ImportDialog importDialog(this); | 504 | ImportDialog importDialog(this); |
498 | 505 | ||
499 | importDialog.showMaximized(); | 506 | importDialog.showMaximized(); |
500 | 507 | ||
501 | if (importDialog.exec() == QDialog::Accepted) { | 508 | if (importDialog.exec() == QDialog::Accepted) { |
502 | const DocLnk* docLnk = importDialog.selected(); | 509 | const DocLnk* docLnk = importDialog.selected(); |
503 | 510 | ||
504 | if (docLnk) { | 511 | if (docLnk) { |
505 | m_pDrawPadCanvas->importPage(docLnk->file()); | 512 | m_pDrawPadCanvas->importPage(docLnk->file()); |
506 | delete docLnk; | 513 | delete docLnk; |
507 | } | 514 | } |
508 | } | 515 | } |
509 | } | 516 | } |
510 | 517 | ||
511 | void DrawPad::exportPage() | 518 | void DrawPad::exportPage() |
512 | { | 519 | { |
513 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); | 520 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); |
514 | 521 | ||
515 | exportDialog.showMaximized(); | 522 | exportDialog.showMaximized(); |
516 | 523 | ||
517 | if (exportDialog.exec() == QDialog::Accepted) { | 524 | if (exportDialog.exec() == QDialog::Accepted) { |
518 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), | 525 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), |
519 | exportDialog.selectedName(), exportDialog.selectedFormat()); | 526 | exportDialog.selectedName(), exportDialog.selectedFormat()); |
520 | } | 527 | } |
521 | } | 528 | } |
529 | |||
530 | void DrawPad::thumbnailView() | ||
531 | { | ||
532 | ThumbnailView thumbnailView(m_pDrawPadCanvas->pages(), this); | ||
533 | |||
534 | thumbnailView.showMaximized(); | ||
535 | thumbnailView.exec(); | ||
536 | } | ||
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index 0dcd5c9..b0b3666 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h | |||
@@ -1,95 +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 | #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 DrawPadCanvas; | 21 | class DrawPadCanvas; |
22 | class Tool; | 22 | class Tool; |
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); | 34 | DrawPad(QWidget* parent = 0, const char* name = 0); |
35 | ~DrawPad(); | 35 | ~DrawPad(); |
36 | 36 | ||
37 | Tool* tool() { return m_pTool; } | 37 | Tool* tool() { return m_pTool; } |
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 setPointTool(); | 42 | void setPointTool(); |
43 | void setLineTool(); | 43 | void setLineTool(); |
44 | void setRectangleTool(); | 44 | void setRectangleTool(); |
45 | void setFilledRectangleTool(); | 45 | void setFilledRectangleTool(); |
46 | void setEllipseTool(); | 46 | void setEllipseTool(); |
47 | void setFilledEllipseTool(); | 47 | void setFilledEllipseTool(); |
48 | void setTextTool(); | 48 | void setTextTool(); |
49 | void setFillTool(); | 49 | void setFillTool(); |
50 | void setEraseTool(); | 50 | void setEraseTool(); |
51 | 51 | ||
52 | void changePenWidth(int value); | 52 | void changePenWidth(int value); |
53 | void changePenColor(const QColor& color); | 53 | void changePenColor(const QColor& color); |
54 | void changeBrushColor(const QColor& color); | 54 | void changeBrushColor(const QColor& color); |
55 | 55 | ||
56 | void updateUndoRedoToolButtons(); | 56 | void updateUndoRedoToolButtons(); |
57 | void updateNavigationToolButtons(); | 57 | void updateNavigationToolButtons(); |
58 | void updateCaption(); | 58 | void updateCaption(); |
59 | 59 | ||
60 | void importPage(); | 60 | void importPage(); |
61 | void exportPage(); | 61 | void exportPage(); |
62 | void thumbnailView(); | ||
62 | 63 | ||
63 | private: | 64 | private: |
64 | DrawPadCanvas* m_pDrawPadCanvas; | 65 | DrawPadCanvas* m_pDrawPadCanvas; |
65 | 66 | ||
66 | Tool* m_pTool; | 67 | Tool* m_pTool; |
67 | QPen m_pen; | 68 | QPen m_pen; |
68 | QBrush m_brush; | 69 | QBrush m_brush; |
69 | 70 | ||
70 | QAction* m_pUndoAction; | 71 | QAction* m_pUndoAction; |
71 | QAction* m_pRedoAction; | 72 | QAction* m_pRedoAction; |
72 | 73 | ||
73 | QAction* m_pFirstPageAction; | 74 | QAction* m_pFirstPageAction; |
74 | QAction* m_pPreviousPageAction; | 75 | QAction* m_pPreviousPageAction; |
75 | QAction* m_pNextPageAction; | 76 | QAction* m_pNextPageAction; |
76 | QAction* m_pLastPageAction; | 77 | QAction* m_pLastPageAction; |
77 | 78 | ||
78 | QAction* m_pPointToolAction; | 79 | QAction* m_pPointToolAction; |
79 | QAction* m_pLineToolAction; | 80 | QAction* m_pLineToolAction; |
80 | QAction* m_pRectangleToolAction; | 81 | QAction* m_pRectangleToolAction; |
81 | QAction* m_pFilledRectangleToolAction; | 82 | QAction* m_pFilledRectangleToolAction; |
82 | QAction* m_pEllipseToolAction; | 83 | QAction* m_pEllipseToolAction; |
83 | QAction* m_pFilledEllipseToolAction; | 84 | QAction* m_pFilledEllipseToolAction; |
84 | QAction* m_pTextToolAction; | 85 | QAction* m_pTextToolAction; |
85 | QAction* m_pFillToolAction; | 86 | QAction* m_pFillToolAction; |
86 | QAction* m_pEraseToolAction; | 87 | QAction* m_pEraseToolAction; |
87 | 88 | ||
88 | QToolButton* m_pLineToolButton; | 89 | QToolButton* m_pLineToolButton; |
89 | QToolButton* m_pRectangleToolButton; | 90 | QToolButton* m_pRectangleToolButton; |
90 | QToolButton* m_pEllipseToolButton; | 91 | QToolButton* m_pEllipseToolButton; |
91 | QToolButton* m_pPenColorToolButton; | 92 | QToolButton* m_pPenColorToolButton; |
92 | QToolButton* m_pBrushColorToolButton; | 93 | QToolButton* m_pBrushColorToolButton; |
93 | }; | 94 | }; |
94 | 95 | ||
95 | #endif // DRAWPAD_H | 96 | #endif // DRAWPAD_H |
diff --git a/noncore/graphics/drawpad/drawpad.pro b/noncore/graphics/drawpad/drawpad.pro index 9360256..9a640d2 100644 --- a/noncore/graphics/drawpad/drawpad.pro +++ b/noncore/graphics/drawpad/drawpad.pro | |||
@@ -1,54 +1,58 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | HEADERS = drawpad.h \ | 3 | HEADERS = drawpad.h \ |
4 | drawpadcanvas.h \ | 4 | drawpadcanvas.h \ |
5 | ellipsetool.h \ | 5 | ellipsetool.h \ |
6 | erasetool.h \ | 6 | erasetool.h \ |
7 | exportdialog.h \ | 7 | exportdialog.h \ |
8 | filltool.h \ | 8 | filltool.h \ |
9 | filledellipsetool.h \ | 9 | filledellipsetool.h \ |
10 | filledrectangletool.h \ | 10 | filledrectangletool.h \ |
11 | importdialog.h \ | 11 | importdialog.h \ |
12 | linetool.h \ | 12 | linetool.h \ |
13 | newpagedialog.h \ | 13 | newpagedialog.h \ |
14 | page.h \ | ||
14 | pointtool.h \ | 15 | pointtool.h \ |
15 | rectangletool.h \ | 16 | rectangletool.h \ |
16 | shapetool.h \ | 17 | shapetool.h \ |
17 | texttool.h \ | 18 | texttool.h \ |
19 | thumbnailview.h \ | ||
18 | tool.h | 20 | tool.h |
19 | SOURCES = drawpad.cpp \ | 21 | SOURCES = drawpad.cpp \ |
20 | drawpadcanvas.cpp \ | 22 | drawpadcanvas.cpp \ |
21 | ellipsetool.cpp \ | 23 | ellipsetool.cpp \ |
22 | erasetool.cpp \ | 24 | erasetool.cpp \ |
23 | exportdialog.cpp \ | 25 | exportdialog.cpp \ |
24 | filltool.cpp \ | 26 | filltool.cpp \ |
25 | filledellipsetool.cpp \ | 27 | filledellipsetool.cpp \ |
26 | filledrectangletool.cpp \ | 28 | filledrectangletool.cpp \ |
27 | importdialog.cpp \ | 29 | importdialog.cpp \ |
28 | linetool.cpp \ | 30 | linetool.cpp \ |
29 | main.cpp \ | 31 | main.cpp \ |
30 | newpagedialog.cpp \ | 32 | newpagedialog.cpp \ |
33 | page.cpp \ | ||
31 | pointtool.cpp \ | 34 | pointtool.cpp \ |
32 | rectangletool.cpp \ | 35 | rectangletool.cpp \ |
33 | shapetool.cpp \ | 36 | shapetool.cpp \ |
34 | texttool.cpp \ | 37 | texttool.cpp \ |
38 | thumbnailview.cpp \ | ||
35 | tool.cpp | 39 | tool.cpp |
36 | INCLUDEPATH+= $(OPIEDIR)/include \ | 40 | INCLUDEPATH+= $(OPIEDIR)/include \ |
37 | $(QTDIR)/src/3rdparty/zlib | 41 | $(QTDIR)/src/3rdparty/zlib |
38 | DEPENDPATH+= $(OPIEDIR)/include | 42 | DEPENDPATH+= $(OPIEDIR)/include |
39 | LIBS += -lqpe -lopie | 43 | LIBS += -lqpe -lopie |
40 | DESTDIR = $(OPIEDIR)/bin | 44 | DESTDIR = $(OPIEDIR)/bin |
41 | TARGET = drawpad | 45 | TARGET = drawpad |
42 | 46 | ||
43 | TRANSLATIONS= ../../i18n/de/drawpad.ts | 47 | TRANSLATIONS= ../../i18n/de/drawpad.ts |
44 | TRANSLATIONS+= ../../i18n/en/drawpad.ts | 48 | TRANSLATIONS+= ../../i18n/en/drawpad.ts |
45 | TRANSLATIONS+= ../../i18n/fr/drawpad.ts | 49 | TRANSLATIONS+= ../../i18n/fr/drawpad.ts |
46 | TRANSLATIONS+= ../../i18n/hu/drawpad.ts | 50 | TRANSLATIONS+= ../../i18n/hu/drawpad.ts |
47 | TRANSLATIONS+= ../../i18n/ja/drawpad.ts | 51 | TRANSLATIONS+= ../../i18n/ja/drawpad.ts |
48 | TRANSLATIONS+= ../../i18n/ko/drawpad.ts | 52 | TRANSLATIONS+= ../../i18n/ko/drawpad.ts |
49 | TRANSLATIONS+= ../../i18n/no/drawpad.ts | 53 | TRANSLATIONS+= ../../i18n/no/drawpad.ts |
50 | TRANSLATIONS+= ../../i18n/pl/drawpad.ts | 54 | TRANSLATIONS+= ../../i18n/pl/drawpad.ts |
51 | TRANSLATIONS+= ../../i18n/pt_BR/drawpad.ts | 55 | TRANSLATIONS+= ../../i18n/pt_BR/drawpad.ts |
52 | TRANSLATIONS+= ../../i18n/sl/drawpad.ts | 56 | TRANSLATIONS+= ../../i18n/sl/drawpad.ts |
53 | TRANSLATIONS+= ../../i18n/zh_CN/drawpad.ts | 57 | TRANSLATIONS+= ../../i18n/zh_CN/drawpad.ts |
54 | TRANSLATIONS+= ../../i18n/zh_TW/drawpad.ts | 58 | TRANSLATIONS+= ../../i18n/zh_TW/drawpad.ts |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 9f1e50b..79bef35 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -1,563 +1,563 @@ | |||
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 "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "newpagedialog.h" | 17 | #include "newpagedialog.h" |
18 | #include "page.h" | ||
18 | #include "tool.h" | 19 | #include "tool.h" |
19 | 20 | ||
20 | #include <qpe/applnk.h> | 21 | #include <qpe/applnk.h> |
21 | #include <qpe/filemanager.h> | 22 | #include <qpe/filemanager.h> |
22 | #include <qpe/mimetype.h> | 23 | #include <qpe/mimetype.h> |
23 | 24 | ||
24 | #include <qbuffer.h> | 25 | #include <qbuffer.h> |
25 | #include <qimage.h> | 26 | #include <qimage.h> |
26 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
27 | #include <qpainter.h> | 28 | #include <qpainter.h> |
28 | #include <qpixmap.h> | ||
29 | #include <qtextcodec.h> | 29 | #include <qtextcodec.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qxml.h> | 31 | #include <qxml.h> |
32 | 32 | ||
33 | #include <zlib.h> | 33 | #include <zlib.h> |
34 | 34 | ||
35 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler | 35 | class DrawPadCanvasXmlHandler: public QXmlDefaultHandler |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | DrawPadCanvasXmlHandler(); | 38 | DrawPadCanvasXmlHandler(); |
39 | ~DrawPadCanvasXmlHandler(); | 39 | ~DrawPadCanvasXmlHandler(); |
40 | 40 | ||
41 | QList<QPixmap> pixmaps(); | 41 | QList<Page> pages(); |
42 | 42 | ||
43 | bool startElement(const QString& namespaceURI, const QString& localName, | 43 | bool startElement(const QString& namespaceURI, const QString& localName, |
44 | const QString& qName, const QXmlAttributes& atts); | 44 | const QString& qName, const QXmlAttributes& atts); |
45 | bool endElement(const QString& namespaceURI, const QString& localName, | 45 | bool endElement(const QString& namespaceURI, const QString& localName, |
46 | const QString& qName); | 46 | const QString& qName); |
47 | bool characters(const QString& ch); | 47 | bool characters(const QString& ch); |
48 | 48 | ||
49 | private: | 49 | private: |
50 | enum State { | 50 | enum State { |
51 | Unknown, | 51 | Unknown, |
52 | InData | 52 | InData |
53 | }; | 53 | }; |
54 | 54 | ||
55 | State m_state; | 55 | State m_state; |
56 | ulong m_dataLenght; | 56 | ulong m_dataLenght; |
57 | QString m_dataFormat; | 57 | QString m_dataFormat; |
58 | QList<QPixmap> m_pixmaps; | 58 | QList<Page> m_pages; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() | 61 | DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() |
62 | { | 62 | { |
63 | m_state = Unknown; | 63 | m_state = Unknown; |
64 | } | 64 | } |
65 | 65 | ||
66 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() | 66 | DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() |
67 | { | 67 | { |
68 | } | 68 | } |
69 | 69 | ||
70 | QList<QPixmap> DrawPadCanvasXmlHandler::pixmaps() | 70 | QList<Page> DrawPadCanvasXmlHandler::pages() |
71 | { | 71 | { |
72 | return m_pixmaps; | 72 | return m_pages; |
73 | } | 73 | } |
74 | 74 | ||
75 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, | 75 | bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, |
76 | const QString& qName, const QXmlAttributes& atts) | 76 | const QString& qName, const QXmlAttributes& atts) |
77 | { | 77 | { |
78 | Q_CONST_UNUSED(namespaceURI) | 78 | Q_CONST_UNUSED(namespaceURI) |
79 | Q_CONST_UNUSED(localName) | 79 | Q_CONST_UNUSED(localName) |
80 | 80 | ||
81 | if (qName.compare("data") == 0) { | 81 | if (qName.compare("data") == 0) { |
82 | m_state = InData; | 82 | m_state = InData; |
83 | m_dataLenght = atts.value("length").toULong(); | 83 | m_dataLenght = atts.value("length").toULong(); |
84 | m_dataFormat = atts.value("format"); | 84 | m_dataFormat = atts.value("format"); |
85 | 85 | ||
86 | if (m_dataFormat.isEmpty()) { | 86 | if (m_dataFormat.isEmpty()) { |
87 | m_dataFormat = "XPM"; | 87 | m_dataFormat = "XPM"; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | return true; | 91 | return true; |
92 | } | 92 | } |
93 | 93 | ||
94 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, | 94 | bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, |
95 | const QString& qName) | 95 | const QString& qName) |
96 | { | 96 | { |
97 | Q_CONST_UNUSED(namespaceURI) | 97 | Q_CONST_UNUSED(namespaceURI) |
98 | Q_CONST_UNUSED(localName) | 98 | Q_CONST_UNUSED(localName) |
99 | 99 | ||
100 | if (qName.compare("data") == 0) { | 100 | if (qName.compare("data") == 0) { |
101 | m_state = Unknown; | 101 | m_state = Unknown; |
102 | } | 102 | } |
103 | 103 | ||
104 | return true; | 104 | return true; |
105 | } | 105 | } |
106 | 106 | ||
107 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) | 107 | bool DrawPadCanvasXmlHandler::characters(const QString& ch) |
108 | { | 108 | { |
109 | if (m_state == InData) { | 109 | if (m_state == InData) { |
110 | QByteArray byteArray(ch.length() / 2); | 110 | QByteArray byteArray(ch.length() / 2); |
111 | 111 | ||
112 | for (int i = 0; i < (int)ch.length() / 2; i++) { | 112 | for (int i = 0; i < (int)ch.length() / 2; i++) { |
113 | char h = ch[2 * i].latin1(); | 113 | char h = ch[2 * i].latin1(); |
114 | char l = ch[2 * i + 1].latin1(); | 114 | char l = ch[2 * i + 1].latin1(); |
115 | uchar r = 0; | 115 | uchar r = 0; |
116 | 116 | ||
117 | if (h <= '9') { | 117 | if (h <= '9') { |
118 | r += h - '0'; | 118 | r += h - '0'; |
119 | } else { | 119 | } else { |
120 | r += h - 'a' + 10; | 120 | r += h - 'a' + 10; |
121 | } | 121 | } |
122 | 122 | ||
123 | r = r << 4; | 123 | r = r << 4; |
124 | 124 | ||
125 | if (l <= '9') { | 125 | if (l <= '9') { |
126 | r += l - '0'; | 126 | r += l - '0'; |
127 | } else { | 127 | } else { |
128 | r += l - 'a' + 10; | 128 | r += l - 'a' + 10; |
129 | } | 129 | } |
130 | 130 | ||
131 | byteArray[i] = r; | 131 | byteArray[i] = r; |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | QImage image; | 135 | QImage image; |
136 | 136 | ||
137 | if (m_dataFormat == "XPM") { | 137 | if (m_dataFormat == "XPM") { |
138 | if (m_dataLenght < ch.length() * 5) { | 138 | if (m_dataLenght < ch.length() * 5) { |
139 | m_dataLenght = ch.length() * 5; | 139 | m_dataLenght = ch.length() * 5; |
140 | } | 140 | } |
141 | 141 | ||
142 | QByteArray byteArrayUnzipped(m_dataLenght); | 142 | QByteArray byteArrayUnzipped(m_dataLenght); |
143 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); | 143 | ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); |
144 | 144 | ||
145 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); | 145 | image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); |
146 | } else { | 146 | } else { |
147 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); | 147 | image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); |
148 | } | 148 | } |
149 | 149 | ||
150 | QPixmap* pixmap = new QPixmap(image.width(), image.height()); | 150 | Page* page = new Page(image.width(), image.height()); |
151 | pixmap->convertFromImage(image); | 151 | page->convertFromImage(image); |
152 | m_pixmaps.append(pixmap); | 152 | m_pages.append(page); |
153 | } | 153 | } |
154 | 154 | ||
155 | return true; | 155 | return true; |
156 | } | 156 | } |
157 | 157 | ||
158 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) | 158 | DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) |
159 | : QScrollView(parent, name) | 159 | : QScrollView(parent, name) |
160 | { | 160 | { |
161 | m_pDrawPad = drawPad; | 161 | m_pDrawPad = drawPad; |
162 | m_pages.setAutoDelete(true); | 162 | m_pages.setAutoDelete(true); |
163 | m_pageBackups.setAutoDelete(true); | 163 | m_pageBackups.setAutoDelete(true); |
164 | 164 | ||
165 | viewport()->setBackgroundMode(QWidget::NoBackground); | 165 | viewport()->setBackgroundMode(QWidget::NoBackground); |
166 | } | 166 | } |
167 | 167 | ||
168 | DrawPadCanvas::~DrawPadCanvas() | 168 | DrawPadCanvas::~DrawPadCanvas() |
169 | { | 169 | { |
170 | } | 170 | } |
171 | 171 | ||
172 | void DrawPadCanvas::load(QIODevice* ioDevice) | 172 | void DrawPadCanvas::load(QIODevice* ioDevice) |
173 | { | 173 | { |
174 | QTextStream textStream(ioDevice); | 174 | QTextStream textStream(ioDevice); |
175 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 175 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
176 | 176 | ||
177 | QXmlInputSource xmlInputSource(textStream); | 177 | QXmlInputSource xmlInputSource(textStream); |
178 | QXmlSimpleReader xmlSimpleReader; | 178 | QXmlSimpleReader xmlSimpleReader; |
179 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; | 179 | DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; |
180 | 180 | ||
181 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); | 181 | xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); |
182 | xmlSimpleReader.parse(xmlInputSource); | 182 | xmlSimpleReader.parse(xmlInputSource); |
183 | 183 | ||
184 | m_pages = drawPadCanvasXmlHandler.pixmaps(); | 184 | m_pages = drawPadCanvasXmlHandler.pages(); |
185 | 185 | ||
186 | if (m_pages.isEmpty()) { | 186 | if (m_pages.isEmpty()) { |
187 | m_pages.append(new QPixmap(contentsRect().size())); | 187 | m_pages.append(new Page(contentsRect().size())); |
188 | m_pages.current()->fill(Qt::white); | 188 | m_pages.current()->fill(Qt::white); |
189 | } | 189 | } |
190 | 190 | ||
191 | m_pageBackups.clear(); | 191 | m_pageBackups.clear(); |
192 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 192 | m_pageBackups.append(new Page(*(m_pages.current()))); |
193 | 193 | ||
194 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 194 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
195 | viewport()->update(); | 195 | viewport()->update(); |
196 | 196 | ||
197 | emit pagesChanged(); | 197 | emit pagesChanged(); |
198 | emit pageBackupsChanged(); | 198 | emit pageBackupsChanged(); |
199 | } | 199 | } |
200 | 200 | ||
201 | void DrawPadCanvas::initialPage() | 201 | void DrawPadCanvas::initialPage() |
202 | { | 202 | { |
203 | m_pages.append(new QPixmap(236, 232)); | 203 | m_pages.append(new Page(236, 232)); |
204 | m_pages.current()->fill(Qt::white); | 204 | m_pages.current()->fill(Qt::white); |
205 | 205 | ||
206 | m_pageBackups.clear(); | 206 | m_pageBackups.clear(); |
207 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 207 | m_pageBackups.append(new Page(*(m_pages.current()))); |
208 | 208 | ||
209 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 209 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
210 | viewport()->update(); | 210 | viewport()->update(); |
211 | 211 | ||
212 | emit pagesChanged(); | 212 | emit pagesChanged(); |
213 | emit pageBackupsChanged(); | 213 | emit pageBackupsChanged(); |
214 | } | 214 | } |
215 | 215 | ||
216 | void DrawPadCanvas::save(QIODevice* ioDevice) | 216 | void DrawPadCanvas::save(QIODevice* ioDevice) |
217 | { | 217 | { |
218 | QTextStream textStream(ioDevice); | 218 | QTextStream textStream(ioDevice); |
219 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); | 219 | textStream.setCodec(QTextCodec::codecForName("UTF-8")); |
220 | 220 | ||
221 | textStream << "<drawpad>" << endl; | 221 | textStream << "<drawpad>" << endl; |
222 | textStream << " <images>" << endl; | 222 | textStream << " <images>" << endl; |
223 | 223 | ||
224 | QListIterator<QPixmap> bufferIterator(m_pages); | 224 | QListIterator<Page> bufferIterator(m_pages); |
225 | 225 | ||
226 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { | 226 | for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { |
227 | textStream << " <image>" << endl; | 227 | textStream << " <image>" << endl; |
228 | 228 | ||
229 | QImage image = bufferIterator.current()->convertToImage(); | 229 | QImage image = bufferIterator.current()->convertToImage(); |
230 | QByteArray byteArray; | 230 | QByteArray byteArray; |
231 | QBuffer buffer(byteArray); | 231 | QBuffer buffer(byteArray); |
232 | QImageIO imageIO(&buffer, "PNG"); | 232 | QImageIO imageIO(&buffer, "PNG"); |
233 | 233 | ||
234 | buffer.open(IO_WriteOnly); | 234 | buffer.open(IO_WriteOnly); |
235 | imageIO.setImage(image); | 235 | imageIO.setImage(image); |
236 | imageIO.write(); | 236 | imageIO.write(); |
237 | buffer.close(); | 237 | buffer.close(); |
238 | 238 | ||
239 | textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; | 239 | textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; |
240 | 240 | ||
241 | static const char hexchars[] = "0123456789abcdef"; | 241 | static const char hexchars[] = "0123456789abcdef"; |
242 | 242 | ||
243 | for (int i = 0; i < (int)byteArray.size(); i++ ) { | 243 | for (int i = 0; i < (int)byteArray.size(); i++ ) { |
244 | uchar s = (uchar)byteArray[i]; | 244 | uchar s = (uchar)byteArray[i]; |
245 | textStream << hexchars[s >> 4]; | 245 | textStream << hexchars[s >> 4]; |
246 | textStream << hexchars[s & 0x0f]; | 246 | textStream << hexchars[s & 0x0f]; |
247 | } | 247 | } |
248 | 248 | ||
249 | textStream << "</data>" << endl; | 249 | textStream << "</data>" << endl; |
250 | textStream << " </image>" << endl; | 250 | textStream << " </image>" << endl; |
251 | } | 251 | } |
252 | 252 | ||
253 | textStream << " </images>" << endl; | 253 | textStream << " </images>" << endl; |
254 | textStream << "</drawpad>"; | 254 | textStream << "</drawpad>"; |
255 | } | 255 | } |
256 | 256 | ||
257 | void DrawPadCanvas::importPage(const QString& fileName) | 257 | void DrawPadCanvas::importPage(const QString& fileName) |
258 | { | 258 | { |
259 | QPixmap* importedPixmap = new QPixmap(); | 259 | Page* importedPage = new Page(); |
260 | 260 | ||
261 | importedPixmap->load(fileName); | 261 | importedPage->load(fileName); |
262 | m_pages.insert(m_pages.at() + 1, importedPixmap); | 262 | m_pages.insert(m_pages.at() + 1, importedPage); |
263 | 263 | ||
264 | m_pageBackups.clear(); | 264 | m_pageBackups.clear(); |
265 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 265 | m_pageBackups.append(new Page(*(m_pages.current()))); |
266 | 266 | ||
267 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 267 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
268 | viewport()->update(); | 268 | viewport()->update(); |
269 | 269 | ||
270 | emit pagesChanged(); | 270 | emit pagesChanged(); |
271 | emit pageBackupsChanged(); | 271 | emit pageBackupsChanged(); |
272 | } | 272 | } |
273 | 273 | ||
274 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) | 274 | void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) |
275 | { | 275 | { |
276 | if (fromPage == toPage) { | 276 | if (fromPage == toPage) { |
277 | DocLnk docLnk; | 277 | DocLnk docLnk; |
278 | MimeType mimeType(format); | 278 | MimeType mimeType(format); |
279 | 279 | ||
280 | docLnk.setName(name); | 280 | docLnk.setName(name); |
281 | docLnk.setType(mimeType.id()); | 281 | docLnk.setType(mimeType.id()); |
282 | 282 | ||
283 | FileManager fileManager; | 283 | FileManager fileManager; |
284 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 284 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
285 | QImageIO imageIO(ioDevice, format); | 285 | QImageIO imageIO(ioDevice, format); |
286 | 286 | ||
287 | QImage image = m_pages.current()->convertToImage(); | 287 | QImage image = m_pages.current()->convertToImage(); |
288 | imageIO.setImage(image); | 288 | imageIO.setImage(image); |
289 | imageIO.write(); | 289 | imageIO.write(); |
290 | delete ioDevice; | 290 | delete ioDevice; |
291 | } else { | 291 | } else { |
292 | for (uint i = fromPage; i <= toPage; i++) { | 292 | for (uint i = fromPage; i <= toPage; i++) { |
293 | DocLnk docLnk; | 293 | DocLnk docLnk; |
294 | MimeType mimeType(format); | 294 | MimeType mimeType(format); |
295 | 295 | ||
296 | docLnk.setName(name + QString::number(i)); | 296 | docLnk.setName(name + QString::number(i)); |
297 | docLnk.setType(mimeType.id()); | 297 | docLnk.setType(mimeType.id()); |
298 | 298 | ||
299 | FileManager fileManager; | 299 | FileManager fileManager; |
300 | QIODevice* ioDevice = fileManager.saveFile(docLnk); | 300 | QIODevice* ioDevice = fileManager.saveFile(docLnk); |
301 | QImageIO imageIO(ioDevice, format); | 301 | QImageIO imageIO(ioDevice, format); |
302 | 302 | ||
303 | QImage image = m_pages.at(i - 1)->convertToImage(); | 303 | QImage image = m_pages.at(i - 1)->convertToImage(); |
304 | imageIO.setImage(image); | 304 | imageIO.setImage(image); |
305 | imageIO.write(); | 305 | imageIO.write(); |
306 | delete ioDevice; | 306 | delete ioDevice; |
307 | } | 307 | } |
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | QPixmap* DrawPadCanvas::currentPage() | 311 | Page* DrawPadCanvas::currentPage() |
312 | { | 312 | { |
313 | return m_pages.current(); | 313 | return m_pages.current(); |
314 | } | 314 | } |
315 | 315 | ||
316 | QList<QPixmap> DrawPadCanvas::pages() | 316 | QList<Page> DrawPadCanvas::pages() |
317 | { | 317 | { |
318 | return m_pages; | 318 | return m_pages; |
319 | } | 319 | } |
320 | 320 | ||
321 | uint DrawPadCanvas::pagePosition() | 321 | uint DrawPadCanvas::pagePosition() |
322 | { | 322 | { |
323 | return (m_pages.at() + 1); | 323 | return (m_pages.at() + 1); |
324 | } | 324 | } |
325 | 325 | ||
326 | uint DrawPadCanvas::pageCount() | 326 | uint DrawPadCanvas::pageCount() |
327 | { | 327 | { |
328 | return m_pages.count(); | 328 | return m_pages.count(); |
329 | } | 329 | } |
330 | 330 | ||
331 | void DrawPadCanvas::backupPage() | 331 | void DrawPadCanvas::backupPage() |
332 | { | 332 | { |
333 | QPixmap* currentBackup = m_pageBackups.current(); | 333 | QPixmap* currentBackup = m_pageBackups.current(); |
334 | while (m_pageBackups.last() != currentBackup) { | 334 | while (m_pageBackups.last() != currentBackup) { |
335 | m_pageBackups.removeLast(); | 335 | m_pageBackups.removeLast(); |
336 | } | 336 | } |
337 | 337 | ||
338 | while (m_pageBackups.count() >= (5 + 1)) { | 338 | while (m_pageBackups.count() >= (5 + 1)) { |
339 | m_pageBackups.removeFirst(); | 339 | m_pageBackups.removeFirst(); |
340 | } | 340 | } |
341 | 341 | ||
342 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 342 | m_pageBackups.append(new Page(*(m_pages.current()))); |
343 | 343 | ||
344 | emit pageBackupsChanged(); | 344 | emit pageBackupsChanged(); |
345 | } | 345 | } |
346 | 346 | ||
347 | void DrawPadCanvas::deleteAll() | 347 | void DrawPadCanvas::deleteAll() |
348 | { | 348 | { |
349 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | 349 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), |
350 | QMessageBox::Information, QMessageBox::Yes, | 350 | QMessageBox::Information, QMessageBox::Yes, |
351 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 351 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
352 | QMessageBox::NoButton, this); | 352 | QMessageBox::NoButton, this); |
353 | 353 | ||
354 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 354 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
355 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 355 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
356 | 356 | ||
357 | if (messageBox.exec() == QMessageBox::Yes) { | 357 | if (messageBox.exec() == QMessageBox::Yes) { |
358 | m_pages.clear(); | 358 | m_pages.clear(); |
359 | 359 | ||
360 | m_pages.append(new QPixmap(contentsRect().size())); | 360 | m_pages.append(new Page(contentsRect().size())); |
361 | m_pages.current()->fill(Qt::white); | 361 | m_pages.current()->fill(Qt::white); |
362 | 362 | ||
363 | m_pageBackups.clear(); | 363 | m_pageBackups.clear(); |
364 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 364 | m_pageBackups.append(new Page(*(m_pages.current()))); |
365 | 365 | ||
366 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 366 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
367 | viewport()->update(); | 367 | viewport()->update(); |
368 | 368 | ||
369 | emit pagesChanged(); | 369 | emit pagesChanged(); |
370 | emit pageBackupsChanged(); | 370 | emit pageBackupsChanged(); |
371 | } | 371 | } |
372 | } | 372 | } |
373 | 373 | ||
374 | void DrawPadCanvas::newPage() | 374 | void DrawPadCanvas::newPage() |
375 | { | 375 | { |
376 | QRect rect = contentsRect(); | 376 | QRect rect = contentsRect(); |
377 | 377 | ||
378 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), | 378 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), |
379 | m_pDrawPad->brush().color(), this); | 379 | m_pDrawPad->brush().color(), this); |
380 | 380 | ||
381 | if (newPageDialog.exec() == QDialog::Accepted) { | 381 | if (newPageDialog.exec() == QDialog::Accepted) { |
382 | m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.selectedWidth(), | 382 | m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(), |
383 | newPageDialog.selectedHeight())); | 383 | newPageDialog.selectedHeight())); |
384 | m_pages.current()->fill(newPageDialog.selectedColor()); | 384 | m_pages.current()->fill(newPageDialog.selectedColor()); |
385 | 385 | ||
386 | m_pageBackups.clear(); | 386 | m_pageBackups.clear(); |
387 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 387 | m_pageBackups.append(new Page(*(m_pages.current()))); |
388 | 388 | ||
389 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 389 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
390 | viewport()->update(); | 390 | viewport()->update(); |
391 | 391 | ||
392 | emit pagesChanged(); | 392 | emit pagesChanged(); |
393 | emit pageBackupsChanged(); | 393 | emit pageBackupsChanged(); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
397 | void DrawPadCanvas::clearPage() | 397 | void DrawPadCanvas::clearPage() |
398 | { | 398 | { |
399 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | 399 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), |
400 | QMessageBox::Information, QMessageBox::Yes, | 400 | QMessageBox::Information, QMessageBox::Yes, |
401 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 401 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
402 | QMessageBox::NoButton, this); | 402 | QMessageBox::NoButton, this); |
403 | 403 | ||
404 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 404 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
405 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 405 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
406 | 406 | ||
407 | if (messageBox.exec() == QMessageBox::Yes) { | 407 | if (messageBox.exec() == QMessageBox::Yes) { |
408 | m_pages.current()->fill(Qt::white); | 408 | m_pages.current()->fill(Qt::white); |
409 | 409 | ||
410 | viewport()->update(); | 410 | viewport()->update(); |
411 | } | 411 | } |
412 | } | 412 | } |
413 | 413 | ||
414 | void DrawPadCanvas::deletePage() | 414 | void DrawPadCanvas::deletePage() |
415 | { | 415 | { |
416 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), | 416 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), |
417 | QMessageBox::Information, QMessageBox::Yes, | 417 | QMessageBox::Information, QMessageBox::Yes, |
418 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 418 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
419 | QMessageBox::NoButton, this); | 419 | QMessageBox::NoButton, this); |
420 | 420 | ||
421 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 421 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
422 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 422 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
423 | 423 | ||
424 | if (messageBox.exec() == QMessageBox::Yes) { | 424 | if (messageBox.exec() == QMessageBox::Yes) { |
425 | m_pages.remove(m_pages.current()); | 425 | m_pages.remove(m_pages.current()); |
426 | 426 | ||
427 | if (m_pages.isEmpty()) { | 427 | if (m_pages.isEmpty()) { |
428 | m_pages.append(new QPixmap(contentsRect().size())); | 428 | m_pages.append(new Page(contentsRect().size())); |
429 | m_pages.current()->fill(Qt::white); | 429 | m_pages.current()->fill(Qt::white); |
430 | } | 430 | } |
431 | 431 | ||
432 | m_pageBackups.clear(); | 432 | m_pageBackups.clear(); |
433 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 433 | m_pageBackups.append(new Page(*(m_pages.current()))); |
434 | 434 | ||
435 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 435 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
436 | viewport()->update(); | 436 | viewport()->update(); |
437 | 437 | ||
438 | emit pagesChanged(); | 438 | emit pagesChanged(); |
439 | emit pageBackupsChanged(); | 439 | emit pageBackupsChanged(); |
440 | } | 440 | } |
441 | } | 441 | } |
442 | 442 | ||
443 | bool DrawPadCanvas::undoEnabled() | 443 | bool DrawPadCanvas::undoEnabled() |
444 | { | 444 | { |
445 | return (m_pageBackups.current() != m_pageBackups.getFirst()); | 445 | return (m_pageBackups.current() != m_pageBackups.getFirst()); |
446 | } | 446 | } |
447 | 447 | ||
448 | bool DrawPadCanvas::redoEnabled() | 448 | bool DrawPadCanvas::redoEnabled() |
449 | { | 449 | { |
450 | return (m_pageBackups.current() != m_pageBackups.getLast()); | 450 | return (m_pageBackups.current() != m_pageBackups.getLast()); |
451 | } | 451 | } |
452 | 452 | ||
453 | bool DrawPadCanvas::goPreviousPageEnabled() | 453 | bool DrawPadCanvas::goPreviousPageEnabled() |
454 | { | 454 | { |
455 | return (m_pages.current() != m_pages.getFirst()); | 455 | return (m_pages.current() != m_pages.getFirst()); |
456 | } | 456 | } |
457 | 457 | ||
458 | bool DrawPadCanvas::goNextPageEnabled() | 458 | bool DrawPadCanvas::goNextPageEnabled() |
459 | { | 459 | { |
460 | return (m_pages.current() != m_pages.getLast()); | 460 | return (m_pages.current() != m_pages.getLast()); |
461 | } | 461 | } |
462 | 462 | ||
463 | void DrawPadCanvas::undo() | 463 | void DrawPadCanvas::undo() |
464 | { | 464 | { |
465 | *(m_pages.current()) = *(m_pageBackups.prev()); | 465 | *(m_pages.current()) = *(m_pageBackups.prev()); |
466 | 466 | ||
467 | viewport()->update(); | 467 | viewport()->update(); |
468 | 468 | ||
469 | emit pageBackupsChanged(); | 469 | emit pageBackupsChanged(); |
470 | } | 470 | } |
471 | 471 | ||
472 | void DrawPadCanvas::redo() | 472 | void DrawPadCanvas::redo() |
473 | { | 473 | { |
474 | *(m_pages.current()) = *(m_pageBackups.next()); | 474 | *(m_pages.current()) = *(m_pageBackups.next()); |
475 | 475 | ||
476 | viewport()->update(); | 476 | viewport()->update(); |
477 | 477 | ||
478 | emit pageBackupsChanged(); | 478 | emit pageBackupsChanged(); |
479 | } | 479 | } |
480 | 480 | ||
481 | void DrawPadCanvas::goFirstPage() | 481 | void DrawPadCanvas::goFirstPage() |
482 | { | 482 | { |
483 | m_pages.first(); | 483 | m_pages.first(); |
484 | m_pageBackups.clear(); | 484 | m_pageBackups.clear(); |
485 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 485 | m_pageBackups.append(new Page(*(m_pages.current()))); |
486 | 486 | ||
487 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 487 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
488 | viewport()->update(); | 488 | viewport()->update(); |
489 | 489 | ||
490 | emit pagesChanged(); | 490 | emit pagesChanged(); |
491 | emit pageBackupsChanged(); | 491 | emit pageBackupsChanged(); |
492 | } | 492 | } |
493 | 493 | ||
494 | void DrawPadCanvas::goPreviousPage() | 494 | void DrawPadCanvas::goPreviousPage() |
495 | { | 495 | { |
496 | m_pages.prev(); | 496 | m_pages.prev(); |
497 | m_pageBackups.clear(); | 497 | m_pageBackups.clear(); |
498 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 498 | m_pageBackups.append(new Page(*(m_pages.current()))); |
499 | 499 | ||
500 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 500 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
501 | viewport()->update(); | 501 | viewport()->update(); |
502 | 502 | ||
503 | emit pagesChanged(); | 503 | emit pagesChanged(); |
504 | emit pageBackupsChanged(); | 504 | emit pageBackupsChanged(); |
505 | } | 505 | } |
506 | 506 | ||
507 | void DrawPadCanvas::goNextPage() | 507 | void DrawPadCanvas::goNextPage() |
508 | { | 508 | { |
509 | m_pages.next(); | 509 | m_pages.next(); |
510 | m_pageBackups.clear(); | 510 | m_pageBackups.clear(); |
511 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 511 | m_pageBackups.append(new Page(*(m_pages.current()))); |
512 | 512 | ||
513 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 513 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
514 | viewport()->update(); | 514 | viewport()->update(); |
515 | 515 | ||
516 | emit pagesChanged(); | 516 | emit pagesChanged(); |
517 | emit pageBackupsChanged(); | 517 | emit pageBackupsChanged(); |
518 | } | 518 | } |
519 | 519 | ||
520 | void DrawPadCanvas::goLastPage() | 520 | void DrawPadCanvas::goLastPage() |
521 | { | 521 | { |
522 | m_pages.last(); | 522 | m_pages.last(); |
523 | m_pageBackups.clear(); | 523 | m_pageBackups.clear(); |
524 | m_pageBackups.append(new QPixmap(*(m_pages.current()))); | 524 | m_pageBackups.append(new Page(*(m_pages.current()))); |
525 | 525 | ||
526 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | 526 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); |
527 | viewport()->update(); | 527 | viewport()->update(); |
528 | 528 | ||
529 | emit pagesChanged(); | 529 | emit pagesChanged(); |
530 | emit pageBackupsChanged(); | 530 | emit pageBackupsChanged(); |
531 | } | 531 | } |
532 | 532 | ||
533 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) | 533 | void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) |
534 | { | 534 | { |
535 | m_pDrawPad->tool()->mousePressEvent(e); | 535 | m_pDrawPad->tool()->mousePressEvent(e); |
536 | } | 536 | } |
537 | 537 | ||
538 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) | 538 | void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) |
539 | { | 539 | { |
540 | m_pDrawPad->tool()->mouseReleaseEvent(e); | 540 | m_pDrawPad->tool()->mouseReleaseEvent(e); |
541 | } | 541 | } |
542 | 542 | ||
543 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) | 543 | void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e) |
544 | { | 544 | { |
545 | m_pDrawPad->tool()->mouseMoveEvent(e); | 545 | m_pDrawPad->tool()->mouseMoveEvent(e); |
546 | } | 546 | } |
547 | 547 | ||
548 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 548 | void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |
549 | { | 549 | { |
550 | QRect clipRect(cx, cy, cw, ch); | 550 | QRect clipRect(cx, cy, cw, ch); |
551 | QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height()); | 551 | QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height()); |
552 | QRect drawRect = pixmapRect.intersect(clipRect); | 552 | QRect drawRect = pixmapRect.intersect(clipRect); |
553 | 553 | ||
554 | p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect); | 554 | p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect); |
555 | 555 | ||
556 | if (drawRect.right() < clipRect.right()) { | 556 | if (drawRect.right() < clipRect.right()) { |
557 | p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); | 557 | p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark()); |
558 | } | 558 | } |
559 | 559 | ||
560 | if (drawRect.bottom() < clipRect.bottom()) { | 560 | if (drawRect.bottom() < clipRect.bottom()) { |
561 | p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark()); | 561 | p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark()); |
562 | } | 562 | } |
563 | } | 563 | } |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index e05ce8a..47763f9 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h | |||
@@ -1,83 +1,82 @@ | |||
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 <qscrollview.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 | class Page; | |
24 | class QPixmap; | ||
25 | 24 | ||
26 | class DrawPadCanvas : public QScrollView | 25 | class DrawPadCanvas : public QScrollView |
27 | { | 26 | { |
28 | Q_OBJECT | 27 | Q_OBJECT |
29 | 28 | ||
30 | public: | 29 | public: |
31 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); | 30 | DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); |
32 | ~DrawPadCanvas(); | 31 | ~DrawPadCanvas(); |
33 | 32 | ||
34 | void load(QIODevice* ioDevice); | 33 | void load(QIODevice* ioDevice); |
35 | void initialPage(); | 34 | void initialPage(); |
36 | void save(QIODevice* ioDevice); | 35 | void save(QIODevice* ioDevice); |
37 | 36 | ||
38 | void importPage(const QString& fileName); | 37 | void importPage(const QString& fileName); |
39 | void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); | 38 | void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); |
40 | 39 | ||
41 | bool undoEnabled(); | 40 | bool undoEnabled(); |
42 | bool redoEnabled(); | 41 | bool redoEnabled(); |
43 | bool goPreviousPageEnabled(); | 42 | bool goPreviousPageEnabled(); |
44 | bool goNextPageEnabled(); | 43 | bool goNextPageEnabled(); |
45 | 44 | ||
46 | QPixmap* currentPage(); | 45 | Page* currentPage(); |
47 | QList<QPixmap> pages(); | 46 | QList<Page> pages(); |
48 | uint pagePosition(); | 47 | uint pagePosition(); |
49 | uint pageCount(); | 48 | uint pageCount(); |
50 | 49 | ||
51 | void backupPage(); | 50 | void backupPage(); |
52 | 51 | ||
53 | public slots: | 52 | public slots: |
54 | void deleteAll(); | 53 | void deleteAll(); |
55 | void newPage(); | 54 | void newPage(); |
56 | void clearPage(); | 55 | void clearPage(); |
57 | void deletePage(); | 56 | void deletePage(); |
58 | 57 | ||
59 | void undo(); | 58 | void undo(); |
60 | void redo(); | 59 | void redo(); |
61 | 60 | ||
62 | void goFirstPage(); | 61 | void goFirstPage(); |
63 | void goPreviousPage(); | 62 | void goPreviousPage(); |
64 | void goNextPage(); | 63 | void goNextPage(); |
65 | void goLastPage(); | 64 | void goLastPage(); |
66 | 65 | ||
67 | signals: | 66 | signals: |
68 | void pagesChanged(); | 67 | void pagesChanged(); |
69 | void pageBackupsChanged(); | 68 | void pageBackupsChanged(); |
70 | 69 | ||
71 | protected: | 70 | protected: |
72 | void contentsMousePressEvent(QMouseEvent* e); | 71 | void contentsMousePressEvent(QMouseEvent* e); |
73 | void contentsMouseReleaseEvent(QMouseEvent* e); | 72 | void contentsMouseReleaseEvent(QMouseEvent* e); |
74 | void contentsMouseMoveEvent(QMouseEvent* e); | 73 | void contentsMouseMoveEvent(QMouseEvent* e); |
75 | void drawContents(QPainter* p, int cx, int cy, int cw, int ch); | 74 | void drawContents(QPainter* p, int cx, int cy, int cw, int ch); |
76 | 75 | ||
77 | private: | 76 | private: |
78 | DrawPad* m_pDrawPad; | 77 | DrawPad* m_pDrawPad; |
79 | QList<QPixmap> m_pages; | 78 | QList<Page> m_pages; |
80 | QList<QPixmap> m_pageBackups; | 79 | QList<Page> m_pageBackups; |
81 | }; | 80 | }; |
82 | 81 | ||
83 | #endif // DRAWPADCANVAS_H | 82 | #endif // DRAWPADCANVAS_H |
diff --git a/noncore/graphics/drawpad/erasetool.cpp b/noncore/graphics/drawpad/erasetool.cpp index 828994b..f77e038 100644 --- a/noncore/graphics/drawpad/erasetool.cpp +++ b/noncore/graphics/drawpad/erasetool.cpp | |||
@@ -1,76 +1,76 @@ | |||
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 "erasetool.h" | 14 | #include "erasetool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | #include "page.h" | ||
18 | 19 | ||
19 | #include <qpainter.h> | 20 | #include <qpainter.h> |
20 | #include <qpixmap.h> | ||
21 | 21 | ||
22 | EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : Tool(drawPad, drawPadCanvas) | 23 | : Tool(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 | EraseTool::~EraseTool() | 29 | EraseTool::~EraseTool() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void EraseTool::mousePressEvent(QMouseEvent* e) | 33 | void EraseTool::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 EraseTool::mouseReleaseEvent(QMouseEvent* e) | 39 | void EraseTool::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 | m_pDrawPadCanvas->backupPage(); | 45 | m_pDrawPadCanvas->backupPage(); |
46 | } | 46 | } |
47 | 47 | ||
48 | void EraseTool::mouseMoveEvent(QMouseEvent* e) | 48 | void EraseTool::mouseMoveEvent(QMouseEvent* e) |
49 | { | 49 | { |
50 | if (m_mousePressed) { | 50 | if (m_mousePressed) { |
51 | QPainter painter; | 51 | QPainter painter; |
52 | QPen pen(Qt::white, m_pDrawPad->pen().width()); | 52 | QPen pen(Qt::white, m_pDrawPad->pen().width()); |
53 | painter.begin(m_pDrawPadCanvas->currentPage()); | 53 | painter.begin(m_pDrawPadCanvas->currentPage()); |
54 | painter.setPen(pen); | 54 | painter.setPen(pen); |
55 | m_polyline[2] = m_polyline[1]; | 55 | m_polyline[2] = m_polyline[1]; |
56 | m_polyline[1] = m_polyline[0]; | 56 | m_polyline[1] = m_polyline[0]; |
57 | m_polyline[0] = e->pos(); | 57 | m_polyline[0] = e->pos(); |
58 | painter.drawPolyline(m_polyline); | 58 | painter.drawPolyline(m_polyline); |
59 | painter.end(); | 59 | painter.end(); |
60 | 60 | ||
61 | QRect r = m_polyline.boundingRect(); | 61 | QRect r = m_polyline.boundingRect(); |
62 | r = r.normalize(); | 62 | r = r.normalize(); |
63 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 63 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
64 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 64 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
65 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 65 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
66 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 66 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
67 | 67 | ||
68 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 68 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
69 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 69 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
70 | 70 | ||
71 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 71 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
72 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 72 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
73 | 73 | ||
74 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 74 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
75 | } | 75 | } |
76 | } | 76 | } |
diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp index 004da02..d323cc2 100644 --- a/noncore/graphics/drawpad/filltool.cpp +++ b/noncore/graphics/drawpad/filltool.cpp | |||
@@ -1,90 +1,90 @@ | |||
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 "filltool.h" | 14 | #include "filltool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | #include "page.h" | ||
18 | 19 | ||
19 | #include <qimage.h> | 20 | #include <qimage.h> |
20 | #include <qpixmap.h> | ||
21 | 21 | ||
22 | FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : Tool(drawPad, drawPadCanvas) | 23 | : Tool(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | FillTool::~FillTool() | 27 | FillTool::~FillTool() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void FillTool::mousePressEvent(QMouseEvent* e) | 31 | void FillTool::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 | fillLine(x, y); | 41 | fillLine(x, y); |
42 | 42 | ||
43 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); | 43 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); |
44 | m_pDrawPadCanvas->viewport()->update(); | 44 | m_pDrawPadCanvas->viewport()->update(); |
45 | 45 | ||
46 | m_pDrawPadCanvas->backupPage(); | 46 | m_pDrawPadCanvas->backupPage(); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | void FillTool::mouseReleaseEvent(QMouseEvent* e) | 50 | void FillTool::mouseReleaseEvent(QMouseEvent* e) |
51 | { | 51 | { |
52 | Q_UNUSED(e) | 52 | Q_UNUSED(e) |
53 | } | 53 | } |
54 | 54 | ||
55 | void FillTool::mouseMoveEvent(QMouseEvent* e) | 55 | void FillTool::mouseMoveEvent(QMouseEvent* e) |
56 | { | 56 | { |
57 | Q_UNUSED(e) | 57 | Q_UNUSED(e) |
58 | } | 58 | } |
59 | 59 | ||
60 | void FillTool::fillLine(int x, int y) | 60 | void FillTool::fillLine(int x, int y) |
61 | { | 61 | { |
62 | if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { | 62 | if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { |
63 | if (m_image.pixel(x, y) == m_oldRgb) { | 63 | if (m_image.pixel(x, y) == m_oldRgb) { |
64 | int x1, x2; | 64 | int x1, x2; |
65 | 65 | ||
66 | x1 = x - 1; | 66 | x1 = x - 1; |
67 | x2 = x + 1; | 67 | x2 = x + 1; |
68 | 68 | ||
69 | while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) { | 69 | while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) { |
70 | x1--; | 70 | x1--; |
71 | } | 71 | } |
72 | 72 | ||
73 | while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) { | 73 | while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) { |
74 | x2++; | 74 | x2++; |
75 | } | 75 | } |
76 | 76 | ||
77 | for (int i = x1 + 1; i < x2; i++) { | 77 | for (int i = x1 + 1; i < x2; i++) { |
78 | m_image.setPixel(i, y, m_fillRgb); | 78 | m_image.setPixel(i, y, m_fillRgb); |
79 | } | 79 | } |
80 | 80 | ||
81 | for (int i = x1 + 1; i < x2; i++) { | 81 | for (int i = x1 + 1; i < x2; i++) { |
82 | fillLine(i, y - 1); | 82 | fillLine(i, y - 1); |
83 | } | 83 | } |
84 | 84 | ||
85 | for (int i = x1 + 1; i < x2; i++) { | 85 | for (int i = x1 + 1; i < x2; i++) { |
86 | fillLine(i, y + 1); | 86 | fillLine(i, y + 1); |
87 | } | 87 | } |
88 | } | 88 | } |
89 | } | 89 | } |
90 | } | 90 | } |
diff --git a/noncore/graphics/drawpad/page.cpp b/noncore/graphics/drawpad/page.cpp new file mode 100644 index 0000000..35ec0e0 --- a/dev/null +++ b/noncore/graphics/drawpad/page.cpp | |||
@@ -0,0 +1,33 @@ | |||
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 "page.h" | ||
15 | |||
16 | Page::Page() | ||
17 | : QPixmap() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | Page::Page(int w, int h) | ||
22 | : QPixmap(w, h) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | Page::Page(const QSize& size) | ||
27 | : QPixmap(size) | ||
28 | { | ||
29 | } | ||
30 | |||
31 | Page::~Page() | ||
32 | { | ||
33 | } | ||
diff --git a/noncore/graphics/drawpad/page.h b/noncore/graphics/drawpad/page.h new file mode 100644 index 0000000..888f552 --- a/dev/null +++ b/noncore/graphics/drawpad/page.h | |||
@@ -0,0 +1,29 @@ | |||
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 PAGE_H | ||
15 | #define PAGE_H | ||
16 | |||
17 | #include <qpixmap.h> | ||
18 | |||
19 | class Page : public QPixmap | ||
20 | { | ||
21 | public: | ||
22 | Page(); | ||
23 | Page(int w, int h); | ||
24 | Page(const QSize& size); | ||
25 | |||
26 | ~Page(); | ||
27 | }; | ||
28 | |||
29 | #endif // PAGE_H | ||
diff --git a/noncore/graphics/drawpad/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp index e281284..656044b 100644 --- a/noncore/graphics/drawpad/pointtool.cpp +++ b/noncore/graphics/drawpad/pointtool.cpp | |||
@@ -1,75 +1,75 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "pointtool.h" | 14 | #include "pointtool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | #include "page.h" | ||
18 | 19 | ||
19 | #include <qpainter.h> | 20 | #include <qpainter.h> |
20 | #include <qpixmap.h> | ||
21 | 21 | ||
22 | PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : Tool(drawPad, drawPadCanvas) | 23 | : Tool(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 | PointTool::~PointTool() | 29 | PointTool::~PointTool() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void PointTool::mousePressEvent(QMouseEvent* e) | 33 | void PointTool::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 PointTool::mouseReleaseEvent(QMouseEvent* e) | 39 | void PointTool::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 | m_pDrawPadCanvas->backupPage(); | 45 | m_pDrawPadCanvas->backupPage(); |
46 | } | 46 | } |
47 | 47 | ||
48 | void PointTool::mouseMoveEvent(QMouseEvent* e) | 48 | void PointTool::mouseMoveEvent(QMouseEvent* e) |
49 | { | 49 | { |
50 | if (m_mousePressed) { | 50 | if (m_mousePressed) { |
51 | QPainter painter; | 51 | QPainter painter; |
52 | painter.begin(m_pDrawPadCanvas->currentPage()); | 52 | painter.begin(m_pDrawPadCanvas->currentPage()); |
53 | painter.setPen(m_pDrawPad->pen()); | 53 | painter.setPen(m_pDrawPad->pen()); |
54 | m_polyline[2] = m_polyline[1]; | 54 | m_polyline[2] = m_polyline[1]; |
55 | m_polyline[1] = m_polyline[0]; | 55 | m_polyline[1] = m_polyline[0]; |
56 | m_polyline[0] = e->pos(); | 56 | m_polyline[0] = e->pos(); |
57 | painter.drawPolyline(m_polyline); | 57 | painter.drawPolyline(m_polyline); |
58 | painter.end(); | 58 | painter.end(); |
59 | 59 | ||
60 | QRect r = m_polyline.boundingRect(); | 60 | QRect r = m_polyline.boundingRect(); |
61 | r = r.normalize(); | 61 | r = r.normalize(); |
62 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 62 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
63 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 63 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
64 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 64 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
65 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 65 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
66 | 66 | ||
67 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 67 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
68 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 68 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
69 | 69 | ||
70 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 70 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
71 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 71 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
72 | 72 | ||
73 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 73 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
74 | } | 74 | } |
75 | } | 75 | } |
diff --git a/noncore/graphics/drawpad/shapetool.cpp b/noncore/graphics/drawpad/shapetool.cpp index bc5d9c0..8870a78 100644 --- a/noncore/graphics/drawpad/shapetool.cpp +++ b/noncore/graphics/drawpad/shapetool.cpp | |||
@@ -1,94 +1,94 @@ | |||
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 "shapetool.h" | 14 | #include "shapetool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | #include "page.h" | ||
18 | 19 | ||
19 | #include <qpainter.h> | 20 | #include <qpainter.h> |
20 | #include <qpixmap.h> | ||
21 | 21 | ||
22 | ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : Tool(drawPad, drawPadCanvas) | 23 | : Tool(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 | ShapeTool::~ShapeTool() | 29 | ShapeTool::~ShapeTool() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void ShapeTool::mousePressEvent(QMouseEvent* e) | 33 | void ShapeTool::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 ShapeTool::mouseReleaseEvent(QMouseEvent* e) | 39 | void ShapeTool::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e) | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | QPainter painter; | 43 | QPainter painter; |
44 | painter.begin(m_pDrawPadCanvas->currentPage()); | 44 | painter.begin(m_pDrawPadCanvas->currentPage()); |
45 | drawFinalShape(painter); | 45 | drawFinalShape(painter); |
46 | painter.end(); | 46 | painter.end(); |
47 | 47 | ||
48 | QRect r = m_polyline.boundingRect(); | 48 | QRect r = m_polyline.boundingRect(); |
49 | r = r.normalize(); | 49 | r = r.normalize(); |
50 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 50 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
51 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 51 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
52 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 52 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
53 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 53 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
54 | 54 | ||
55 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 55 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
56 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 56 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
57 | 57 | ||
58 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 58 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
59 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 59 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
60 | 60 | ||
61 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 61 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
62 | 62 | ||
63 | m_mousePressed = false; | 63 | m_mousePressed = false; |
64 | 64 | ||
65 | m_pDrawPadCanvas->backupPage(); | 65 | m_pDrawPadCanvas->backupPage(); |
66 | } | 66 | } |
67 | 67 | ||
68 | void ShapeTool::mouseMoveEvent(QMouseEvent* e) | 68 | void ShapeTool::mouseMoveEvent(QMouseEvent* e) |
69 | { | 69 | { |
70 | if (m_mousePressed) { | 70 | if (m_mousePressed) { |
71 | m_polyline[0] = e->pos(); | 71 | m_polyline[0] = e->pos(); |
72 | QPainter painter; | 72 | QPainter painter; |
73 | painter.begin(m_pDrawPadCanvas->currentPage()); | 73 | painter.begin(m_pDrawPadCanvas->currentPage()); |
74 | drawTemporaryShape(painter); | 74 | drawTemporaryShape(painter); |
75 | painter.end(); | 75 | painter.end(); |
76 | 76 | ||
77 | QRect r = m_polyline.boundingRect(); | 77 | QRect r = m_polyline.boundingRect(); |
78 | r = r.normalize(); | 78 | r = r.normalize(); |
79 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 79 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
80 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 80 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
81 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 81 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
82 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 82 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
83 | 83 | ||
84 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 84 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
85 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 85 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
86 | 86 | ||
87 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 87 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
88 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 88 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
89 | 89 | ||
90 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 90 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
91 | 91 | ||
92 | m_polyline[1] = m_polyline[0]; | 92 | m_polyline[1] = m_polyline[0]; |
93 | } | 93 | } |
94 | } | 94 | } |
diff --git a/noncore/graphics/drawpad/texttool.cpp b/noncore/graphics/drawpad/texttool.cpp index 37b4801..34c8a76 100644 --- a/noncore/graphics/drawpad/texttool.cpp +++ b/noncore/graphics/drawpad/texttool.cpp | |||
@@ -1,79 +1,79 @@ | |||
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 "texttool.h" | 14 | #include "texttool.h" |
15 | 15 | ||
16 | #include "drawpad.h" | 16 | #include "drawpad.h" |
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | #include "page.h" | ||
18 | 19 | ||
19 | #include <qlayout.h> | 20 | #include <qlayout.h> |
20 | #include <qlineedit.h> | 21 | #include <qlineedit.h> |
21 | #include <qpainter.h> | 22 | #include <qpainter.h> |
22 | #include <qpixmap.h> | ||
23 | 23 | ||
24 | TextToolDialog::TextToolDialog(QWidget* parent, const char* name) | 24 | TextToolDialog::TextToolDialog(QWidget* parent, const char* name) |
25 | : QDialog(parent, name, true) | 25 | : QDialog(parent, name, true) |
26 | { | 26 | { |
27 | setCaption(tr("Insert Text")); | 27 | setCaption(tr("Insert Text")); |
28 | 28 | ||
29 | m_pLineEdit = new QLineEdit(this); | 29 | m_pLineEdit = new QLineEdit(this); |
30 | 30 | ||
31 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 31 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
32 | 32 | ||
33 | mainLayout->addWidget(m_pLineEdit); | 33 | mainLayout->addWidget(m_pLineEdit); |
34 | } | 34 | } |
35 | 35 | ||
36 | TextToolDialog::~TextToolDialog() | 36 | TextToolDialog::~TextToolDialog() |
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | QString TextToolDialog::text() | 40 | QString TextToolDialog::text() |
41 | { | 41 | { |
42 | return m_pLineEdit->text(); | 42 | return m_pLineEdit->text(); |
43 | } | 43 | } |
44 | 44 | ||
45 | TextTool::TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 45 | TextTool::TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
46 | : Tool(drawPad, drawPadCanvas) | 46 | : Tool(drawPad, drawPadCanvas) |
47 | { | 47 | { |
48 | } | 48 | } |
49 | 49 | ||
50 | TextTool::~TextTool() | 50 | TextTool::~TextTool() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | void TextTool::mousePressEvent(QMouseEvent* e) | 54 | void TextTool::mousePressEvent(QMouseEvent* e) |
55 | { | 55 | { |
56 | TextToolDialog textToolDialog(m_pDrawPad); | 56 | TextToolDialog textToolDialog(m_pDrawPad); |
57 | 57 | ||
58 | if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) { | 58 | if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) { |
59 | QPainter painter; | 59 | QPainter painter; |
60 | painter.begin(m_pDrawPadCanvas->currentPage()); | 60 | painter.begin(m_pDrawPadCanvas->currentPage()); |
61 | painter.setPen(m_pDrawPad->pen()); | 61 | painter.setPen(m_pDrawPad->pen()); |
62 | painter.drawText(e->x(), e->y(), textToolDialog.text()); | 62 | painter.drawText(e->x(), e->y(), textToolDialog.text()); |
63 | painter.end(); | 63 | painter.end(); |
64 | 64 | ||
65 | m_pDrawPadCanvas->viewport()->update(); | 65 | m_pDrawPadCanvas->viewport()->update(); |
66 | 66 | ||
67 | m_pDrawPadCanvas->backupPage(); | 67 | m_pDrawPadCanvas->backupPage(); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | void TextTool::mouseReleaseEvent(QMouseEvent* e) | 71 | void TextTool::mouseReleaseEvent(QMouseEvent* e) |
72 | { | 72 | { |
73 | Q_UNUSED(e) | 73 | Q_UNUSED(e) |
74 | } | 74 | } |
75 | 75 | ||
76 | void TextTool::mouseMoveEvent(QMouseEvent* e) | 76 | void TextTool::mouseMoveEvent(QMouseEvent* e) |
77 | { | 77 | { |
78 | Q_UNUSED(e) | 78 | Q_UNUSED(e) |
79 | } | 79 | } |
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp new file mode 100644 index 0000000..10ade90 --- a/dev/null +++ b/noncore/graphics/drawpad/thumbnailview.cpp | |||
@@ -0,0 +1,121 @@ | |||
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 "thumbnailview.h" | ||
15 | |||
16 | #include "page.h" | ||
17 | |||
18 | #include <qpe/resource.h> | ||
19 | |||
20 | #include <qheader.h> | ||
21 | #include <qimage.h> | ||
22 | #include <qlayout.h> | ||
23 | #include <qlistview.h> | ||
24 | #include <qtoolbutton.h> | ||
25 | |||
26 | ThumbnailView::ThumbnailView(QList<Page> pages, QWidget* parent, const char* name) | ||
27 | : QDialog(parent, name, true) | ||
28 | { | ||
29 | setCaption(tr("Thumbnail")); | ||
30 | |||
31 | QToolButton* newPageButton = new QToolButton(this); | ||
32 | newPageButton->setIconSet(Resource::loadIconSet("new")); | ||
33 | newPageButton->setAutoRaise(true); | ||
34 | |||
35 | QToolButton* clearPageButton = new QToolButton(this); | ||
36 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | ||
37 | clearPageButton->setAutoRaise(true); | ||
38 | |||
39 | QToolButton* deletePageButton = new QToolButton(this); | ||
40 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | ||
41 | deletePageButton->setAutoRaise(true); | ||
42 | |||
43 | QToolButton* movePageUpButton = new QToolButton(this); | ||
44 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | ||
45 | movePageUpButton->setAutoRaise(true); | ||
46 | |||
47 | QToolButton* movePageDownButton = new QToolButton(this); | ||
48 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | ||
49 | movePageDownButton->setAutoRaise(true); | ||
50 | |||
51 | m_pListView = new QListView(this); | ||
52 | |||
53 | m_pListView->header()->hide(); | ||
54 | m_pListView->setAllColumnsShowFocus(true); | ||
55 | |||
56 | m_pListView->addColumn(tr("Thumbnail")); | ||
57 | m_pListView->addColumn(tr("Information")); | ||
58 | |||
59 | m_pListView->setColumnAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter); | ||
60 | m_pListView->setColumnAlignment(1, Qt::AlignTop); | ||
61 | |||
62 | QListIterator<Page> iterator(pages); | ||
63 | |||
64 | for (; iterator.current(); ++iterator) { | ||
65 | QImage image = iterator.current()->convertToImage(); | ||
66 | |||
67 | int previewWidth = 64; | ||
68 | int previewHeight = 64; | ||
69 | |||
70 | float widthScale = 1.0; | ||
71 | float heightScale = 1.0; | ||
72 | |||
73 | if (previewWidth < image.width()) { | ||
74 | widthScale = (float)previewWidth / float(image.width()); | ||
75 | } | ||
76 | |||
77 | if (previewHeight < image.height()) { | ||
78 | heightScale = (float)previewHeight / float(image.height()); | ||
79 | } | ||
80 | |||
81 | float scale = (widthScale < heightScale ? widthScale : heightScale); | ||
82 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | ||
83 | |||
84 | QPixmap previewPixmap; | ||
85 | previewPixmap.convertFromImage(previewImage); | ||
86 | |||
87 | QPixmap pixmap(64, 64); | ||
88 | |||
89 | pixmap.fill(colorGroup().mid()); | ||
90 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, | ||
91 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); | ||
92 | |||
93 | QListViewItem* item = new QListViewItem(m_pListView); | ||
94 | item->setPixmap(0, pixmap); | ||
95 | } | ||
96 | |||
97 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | ||
98 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); | ||
99 | |||
100 | buttonLayout->addWidget(newPageButton); | ||
101 | buttonLayout->addWidget(clearPageButton); | ||
102 | buttonLayout->addWidget(deletePageButton); | ||
103 | buttonLayout->addStretch(); | ||
104 | buttonLayout->addWidget(movePageUpButton); | ||
105 | buttonLayout->addWidget(movePageDownButton); | ||
106 | |||
107 | mainLayout->addLayout(buttonLayout); | ||
108 | mainLayout->addWidget(m_pListView); | ||
109 | } | ||
110 | |||
111 | ThumbnailView::~ThumbnailView() | ||
112 | { | ||
113 | } | ||
114 | |||
115 | void ThumbnailView::resizeEvent(QResizeEvent* e) | ||
116 | { | ||
117 | QDialog::resizeEvent(e); | ||
118 | |||
119 | m_pListView->setColumnWidth(1, m_pListView->contentsRect().width() - m_pListView->columnWidth(0) | ||
120 | - m_pListView->verticalScrollBar()->width()); | ||
121 | } | ||
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h new file mode 100644 index 0000000..c74730d --- a/dev/null +++ b/noncore/graphics/drawpad/thumbnailview.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 THUMBNAILVIEW_H | ||
15 | #define THUMBNAILVIEW_H | ||
16 | |||
17 | #include <qdialog.h> | ||
18 | |||
19 | #include <qlist.h> | ||
20 | |||
21 | class QListView; | ||
22 | |||
23 | class Page; | ||
24 | |||
25 | class ThumbnailView : public QDialog | ||
26 | { | ||
27 | Q_OBJECT | ||
28 | |||
29 | public: | ||
30 | ThumbnailView(QList<Page> pages, QWidget* parent = 0, const char* name = 0); | ||
31 | ~ThumbnailView(); | ||
32 | |||
33 | protected: | ||
34 | void resizeEvent(QResizeEvent* e); | ||
35 | |||
36 | private: | ||
37 | QListView* m_pListView; | ||
38 | }; | ||
39 | |||
40 | #endif // THUMBNAILVIEW_H | ||