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