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