Diffstat (limited to 'noncore/graphics/drawpad/drawpad.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index b29f5ba..4eb47a5 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -13,48 +13,49 @@ | |||
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 "page.h" |
27 | #include "pageinformationdialog.h" | 27 | #include "pageinformationdialog.h" |
28 | #include "pointtool.h" | 28 | #include "pointtool.h" |
29 | #include "rectangletool.h" | 29 | #include "rectangletool.h" |
30 | #include "texttool.h" | 30 | #include "texttool.h" |
31 | #include "thumbnailview.h" | 31 | #include "thumbnailview.h" |
32 | 32 | ||
33 | #include <opie/colordialog.h> | 33 | #include <opie/colordialog.h> |
34 | #include <opie/colorpopupmenu.h> | 34 | #include <opie/colorpopupmenu.h> |
35 | 35 | ||
36 | #include <qpe/applnk.h> | 36 | #include <qpe/applnk.h> |
37 | #include <qpe/config.h> | ||
37 | #include <qpe/global.h> | 38 | #include <qpe/global.h> |
38 | #include <qpe/qpemenubar.h> | 39 | #include <qpe/qpemenubar.h> |
39 | #include <qpe/qpetoolbar.h> | 40 | #include <qpe/qpetoolbar.h> |
40 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
41 | 42 | ||
42 | #include <qaction.h> | 43 | #include <qaction.h> |
43 | #include <qfile.h> | 44 | #include <qfile.h> |
44 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
45 | #include <qpainter.h> | 46 | #include <qpainter.h> |
46 | #include <qspinbox.h> | 47 | #include <qspinbox.h> |
47 | #include <qtoolbutton.h> | 48 | #include <qtoolbutton.h> |
48 | #include <qtooltip.h> | 49 | #include <qtooltip.h> |
49 | 50 | ||
50 | DrawPad::DrawPad(QWidget* parent, const char* name) | 51 | DrawPad::DrawPad(QWidget* parent, const char* name) |
51 | : QMainWindow(parent, name) | 52 | : QMainWindow(parent, name) |
52 | { | 53 | { |
53 | // init members | 54 | // init members |
54 | 55 | ||
55 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 56 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
56 | 57 | ||
57 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); | 58 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); |
58 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); | 59 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); |
59 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); | 60 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); |
60 | 61 | ||
@@ -207,93 +208,97 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
207 | 208 | ||
208 | m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); | 209 | m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this); |
209 | m_pFillToolAction->setToggleAction(true); | 210 | m_pFillToolAction->setToggleAction(true); |
210 | connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); | 211 | connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); |
211 | m_pFillToolAction->addTo(drawModeToolBar); | 212 | m_pFillToolAction->addTo(drawModeToolBar); |
212 | 213 | ||
213 | m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); | 214 | m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this); |
214 | m_pEraseToolAction->setToggleAction(true); | 215 | m_pEraseToolAction->setToggleAction(true); |
215 | connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); | 216 | connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); |
216 | m_pEraseToolAction->addTo(drawModeToolBar); | 217 | m_pEraseToolAction->addTo(drawModeToolBar); |
217 | 218 | ||
218 | m_pTool = 0; | 219 | m_pTool = 0; |
219 | setRectangleTool(); | 220 | setRectangleTool(); |
220 | setEllipseTool(); | 221 | setEllipseTool(); |
221 | setPointTool(); | 222 | setPointTool(); |
222 | 223 | ||
223 | emptyToolBar = new QPEToolBar(this); | 224 | emptyToolBar = new QPEToolBar(this); |
224 | emptyToolBar->setHorizontalStretchable(true); | 225 | emptyToolBar->setHorizontalStretchable(true); |
225 | emptyToolBar->addSeparator(); | 226 | emptyToolBar->addSeparator(); |
226 | 227 | ||
227 | // init draw parameters toolbar | 228 | // init draw parameters toolbar |
228 | 229 | ||
229 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); | 230 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); |
230 | 231 | ||
231 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); | 232 | m_pPenWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); |
232 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); | 233 | connect(m_pPenWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); |
233 | 234 | ||
234 | QToolTip::add(penWidthSpinBox, tr("Pen Width")); | 235 | QToolTip::add(m_pPenWidthSpinBox, tr("Pen Width")); |
235 | penWidthSpinBox->setValue(1); | 236 | m_pPenWidthSpinBox->setValue(1); |
236 | penWidthSpinBox->setFocusPolicy(QWidget::NoFocus); | 237 | m_pPenWidthSpinBox->setFocusPolicy(QWidget::NoFocus); |
237 | 238 | ||
238 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); | 239 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); |
239 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); | 240 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); |
240 | 241 | ||
241 | ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, m_pPenColorToolButton); | 242 | ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, m_pPenColorToolButton); |
242 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); | 243 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); |
243 | 244 | ||
244 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); | 245 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); |
245 | m_pPenColorToolButton->setPopup(penColorPopupMenu); | 246 | m_pPenColorToolButton->setPopup(penColorPopupMenu); |
246 | m_pPenColorToolButton->setPopupDelay(0); | 247 | m_pPenColorToolButton->setPopupDelay(0); |
247 | 248 | ||
248 | changePenColor(Qt::black); | 249 | changePenColor(Qt::black); |
249 | 250 | ||
250 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); | 251 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); |
251 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); | 252 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); |
252 | 253 | ||
253 | ColorPopupMenu* brushColorPopupMenu = new ColorPopupMenu(Qt::white, m_pBrushColorToolButton); | 254 | ColorPopupMenu* brushColorPopupMenu = new ColorPopupMenu(Qt::white, m_pBrushColorToolButton); |
254 | connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); | 255 | connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); |
255 | 256 | ||
256 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); | 257 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); |
257 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); | 258 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); |
258 | m_pBrushColorToolButton->setPopupDelay(0); | 259 | m_pBrushColorToolButton->setPopupDelay(0); |
259 | 260 | ||
260 | changeBrushColor(Qt::white); | 261 | changeBrushColor(Qt::white); |
261 | 262 | ||
262 | // init pages | 263 | // init pages |
263 | 264 | ||
264 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 265 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
265 | 266 | ||
266 | if (file.open(IO_ReadOnly)) { | 267 | if (file.open(IO_ReadOnly)) { |
267 | m_pDrawPadCanvas->load(&file); | 268 | m_pDrawPadCanvas->load(&file); |
268 | file.close(); | 269 | file.close(); |
269 | } else { | 270 | } else { |
270 | m_pDrawPadCanvas->initialPage(); | 271 | m_pDrawPadCanvas->initialPage(); |
271 | } | 272 | } |
273 | |||
274 | loadConfig(); | ||
272 | } | 275 | } |
273 | 276 | ||
274 | DrawPad::~DrawPad() | 277 | DrawPad::~DrawPad() |
275 | { | 278 | { |
279 | saveConfig(); | ||
280 | |||
276 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 281 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
277 | 282 | ||
278 | if (file.open(IO_WriteOnly)) { | 283 | if (file.open(IO_WriteOnly)) { |
279 | m_pDrawPadCanvas->save(&file); | 284 | m_pDrawPadCanvas->save(&file); |
280 | file.close(); | 285 | file.close(); |
281 | } | 286 | } |
282 | } | 287 | } |
283 | 288 | ||
284 | bool DrawPad::antiAliasing() | 289 | bool DrawPad::antiAliasing() |
285 | { | 290 | { |
286 | return (m_pAntiAliasingAction->isOn()); | 291 | return (m_pAntiAliasingAction->isOn()); |
287 | } | 292 | } |
288 | 293 | ||
289 | void DrawPad::newPage() | 294 | void DrawPad::newPage() |
290 | { | 295 | { |
291 | QRect rect = m_pDrawPadCanvas->contentsRect(); | 296 | QRect rect = m_pDrawPadCanvas->contentsRect(); |
292 | 297 | ||
293 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); | 298 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); |
294 | 299 | ||
295 | if (newPageDialog.exec() == QDialog::Accepted) { | 300 | if (newPageDialog.exec() == QDialog::Accepted) { |
296 | m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), | 301 | m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), |
297 | newPageDialog.selectedHeight(), newPageDialog.selectedColor()); | 302 | newPageDialog.selectedHeight(), newPageDialog.selectedColor()); |
298 | } | 303 | } |
299 | } | 304 | } |
@@ -598,24 +603,48 @@ void DrawPad::exportPage() | |||
598 | exportDialog.showMaximized(); | 603 | exportDialog.showMaximized(); |
599 | 604 | ||
600 | if (exportDialog.exec() == QDialog::Accepted) { | 605 | if (exportDialog.exec() == QDialog::Accepted) { |
601 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), | 606 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), |
602 | exportDialog.selectedName(), exportDialog.selectedFormat()); | 607 | exportDialog.selectedName(), exportDialog.selectedFormat()); |
603 | } | 608 | } |
604 | } | 609 | } |
605 | 610 | ||
606 | void DrawPad::thumbnailView() | 611 | void DrawPad::thumbnailView() |
607 | { | 612 | { |
608 | ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); | 613 | ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); |
609 | 614 | ||
610 | thumbnailView.showMaximized(); | 615 | thumbnailView.showMaximized(); |
611 | thumbnailView.exec(); | 616 | thumbnailView.exec(); |
612 | } | 617 | } |
613 | 618 | ||
614 | void DrawPad::pageInformation() | 619 | void DrawPad::pageInformation() |
615 | { | 620 | { |
616 | PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage()); | 621 | PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage()); |
617 | 622 | ||
618 | if (pageInformationDialog.exec() == QDialog::Accepted) { | 623 | if (pageInformationDialog.exec() == QDialog::Accepted) { |
619 | m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle()); | 624 | m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle()); |
620 | } | 625 | } |
621 | } | 626 | } |
627 | |||
628 | void DrawPad::loadConfig() | ||
629 | { | ||
630 | Config config("drawpad"); | ||
631 | config.setGroup("General"); | ||
632 | |||
633 | m_pAntiAliasingAction->setOn(config.readBoolEntry("AntiAliasing", false)); | ||
634 | m_pPenWidthSpinBox->setValue(config.readNumEntry("PenWidth", 1)); | ||
635 | changePenColor(QColor(config.readEntry("PenColor", Qt::black.name()))); | ||
636 | changeBrushColor(QColor(config.readEntry("BrushColor", Qt::white.name()))); | ||
637 | m_pDrawPadCanvas->selectPage(config.readNumEntry("PagePosition", 1)); | ||
638 | } | ||
639 | |||
640 | void DrawPad::saveConfig() | ||
641 | { | ||
642 | Config config("drawpad"); | ||
643 | config.setGroup("General"); | ||
644 | |||
645 | config.writeEntry("PagePosition", (int)m_pDrawPadCanvas->pagePosition()); | ||
646 | config.writeEntry("AntiAliasing", antiAliasing()); | ||
647 | config.writeEntry("PenWidth", (int)m_pen.width()); | ||
648 | config.writeEntry("PenColor", m_pen.color().name()); | ||
649 | config.writeEntry("BrushColor", m_brush.color().name()); | ||
650 | } | ||