Diffstat (limited to 'noncore/graphics/drawpad/drawpad.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index b325323..58c0d09 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -29,24 +29,25 @@ | |||
29 | 29 | ||
30 | #include <opie/colordialog.h> | 30 | #include <opie/colordialog.h> |
31 | #include <opie/colorpopupmenu.h> | 31 | #include <opie/colorpopupmenu.h> |
32 | 32 | ||
33 | #include <qpe/applnk.h> | 33 | #include <qpe/applnk.h> |
34 | #include <qpe/global.h> | 34 | #include <qpe/global.h> |
35 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
36 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | 38 | ||
39 | #include <qaction.h> | 39 | #include <qaction.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qmessagebox.h> | ||
41 | #include <qpainter.h> | 42 | #include <qpainter.h> |
42 | #include <qspinbox.h> | 43 | #include <qspinbox.h> |
43 | #include <qtoolbutton.h> | 44 | #include <qtoolbutton.h> |
44 | #include <qtooltip.h> | 45 | #include <qtooltip.h> |
45 | 46 | ||
46 | DrawPad::DrawPad(QWidget* parent, const char* name) | 47 | DrawPad::DrawPad(QWidget* parent, const char* name) |
47 | : QMainWindow(parent, name) | 48 | : QMainWindow(parent, name) |
48 | { | 49 | { |
49 | // init members | 50 | // init members |
50 | 51 | ||
51 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 52 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
52 | 53 | ||
@@ -57,25 +58,25 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
57 | setCentralWidget(m_pDrawPadCanvas); | 58 | setCentralWidget(m_pDrawPadCanvas); |
58 | 59 | ||
59 | // init menu | 60 | // init menu |
60 | 61 | ||
61 | setToolBarsMovable(false); | 62 | setToolBarsMovable(false); |
62 | 63 | ||
63 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 64 | QPEToolBar* menuToolBar = new QPEToolBar(this); |
64 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); | 65 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); |
65 | 66 | ||
66 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); | 67 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); |
67 | 68 | ||
68 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); | 69 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); |
69 | connect(deleteAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deleteAll())); | 70 | connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); |
70 | deleteAllAction->addTo(toolsPopupMenu); | 71 | deleteAllAction->addTo(toolsPopupMenu); |
71 | 72 | ||
72 | toolsPopupMenu->insertSeparator(); | 73 | toolsPopupMenu->insertSeparator(); |
73 | 74 | ||
74 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); | 75 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); |
75 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); | 76 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); |
76 | importPageAction->addTo(toolsPopupMenu); | 77 | importPageAction->addTo(toolsPopupMenu); |
77 | 78 | ||
78 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); | 79 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); |
79 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); | 80 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); |
80 | exportPageAction->addTo(toolsPopupMenu); | 81 | exportPageAction->addTo(toolsPopupMenu); |
81 | 82 | ||
@@ -87,29 +88,29 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
87 | 88 | ||
88 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); | 89 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); |
89 | 90 | ||
90 | // init page toolbar | 91 | // init page toolbar |
91 | 92 | ||
92 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 93 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
93 | 94 | ||
94 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); | 95 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); |
95 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); | 96 | connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage())); |
96 | newPageAction->addTo(pageToolBar); | 97 | newPageAction->addTo(pageToolBar); |
97 | 98 | ||
98 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); | 99 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); |
99 | connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage())); | 100 | connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); |
100 | clearPageAction->addTo(pageToolBar); | 101 | clearPageAction->addTo(pageToolBar); |
101 | 102 | ||
102 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); | 103 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); |
103 | connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage())); | 104 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); |
104 | deletePageAction->addTo(pageToolBar); | 105 | deletePageAction->addTo(pageToolBar); |
105 | 106 | ||
106 | QPEToolBar* emptyToolBar = new QPEToolBar(this); | 107 | QPEToolBar* emptyToolBar = new QPEToolBar(this); |
107 | emptyToolBar->setHorizontalStretchable(true); | 108 | emptyToolBar->setHorizontalStretchable(true); |
108 | 109 | ||
109 | // init navigation toolbar | 110 | // init navigation toolbar |
110 | 111 | ||
111 | QPEToolBar* navigationToolBar = new QPEToolBar(this); | 112 | QPEToolBar* navigationToolBar = new QPEToolBar(this); |
112 | 113 | ||
113 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); | 114 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this); |
114 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); | 115 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); |
115 | m_pUndoAction->addTo(navigationToolBar); | 116 | m_pUndoAction->addTo(navigationToolBar); |
@@ -258,24 +259,54 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
258 | } | 259 | } |
259 | 260 | ||
260 | DrawPad::~DrawPad() | 261 | DrawPad::~DrawPad() |
261 | { | 262 | { |
262 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 263 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
263 | 264 | ||
264 | if (file.open(IO_WriteOnly)) { | 265 | if (file.open(IO_WriteOnly)) { |
265 | m_pDrawPadCanvas->save(&file); | 266 | m_pDrawPadCanvas->save(&file); |
266 | file.close(); | 267 | file.close(); |
267 | } | 268 | } |
268 | } | 269 | } |
269 | 270 | ||
271 | void DrawPad::clearPage() | ||
272 | { | ||
273 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | ||
274 | QMessageBox::Information, QMessageBox::Yes, | ||
275 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
276 | QMessageBox::NoButton, this); | ||
277 | |||
278 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
279 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
280 | |||
281 | if (messageBox.exec() == QMessageBox::Yes) { | ||
282 | m_pDrawPadCanvas->clearPage(); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | void DrawPad::deletePage() | ||
287 | { | ||
288 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), | ||
289 | QMessageBox::Information, QMessageBox::Yes, | ||
290 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
291 | QMessageBox::NoButton, this); | ||
292 | |||
293 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
294 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
295 | |||
296 | if (messageBox.exec() == QMessageBox::Yes) { | ||
297 | m_pDrawPadCanvas->deletePage(); | ||
298 | } | ||
299 | } | ||
300 | |||
270 | void DrawPad::setPointTool() | 301 | void DrawPad::setPointTool() |
271 | { | 302 | { |
272 | if (m_pTool) { | 303 | if (m_pTool) { |
273 | delete m_pTool; | 304 | delete m_pTool; |
274 | } | 305 | } |
275 | 306 | ||
276 | m_pTool = new PointTool(this, m_pDrawPadCanvas); | 307 | m_pTool = new PointTool(this, m_pDrawPadCanvas); |
277 | 308 | ||
278 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); | 309 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); |
279 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); | 310 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); |
280 | 311 | ||
281 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); | 312 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); |
@@ -490,24 +521,39 @@ void DrawPad::updateNavigationToolButtons() | |||
490 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 521 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
491 | } | 522 | } |
492 | 523 | ||
493 | void DrawPad::updateCaption() | 524 | void DrawPad::updateCaption() |
494 | { | 525 | { |
495 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); | 526 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); |
496 | uint pageCount = m_pDrawPadCanvas->pageCount(); | 527 | uint pageCount = m_pDrawPadCanvas->pageCount(); |
497 | 528 | ||
498 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " | 529 | setCaption(tr("DrawPad") + " - " + tr("Page") + " " |
499 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); | 530 | + QString::number(pagePosition) + "/" + QString::number(pageCount)); |
500 | } | 531 | } |
501 | 532 | ||
533 | void DrawPad::deleteAll() | ||
534 | { | ||
535 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | ||
536 | QMessageBox::Information, QMessageBox::Yes, | ||
537 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
538 | QMessageBox::NoButton, this); | ||
539 | |||
540 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
541 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
542 | |||
543 | if (messageBox.exec() == QMessageBox::Yes) { | ||
544 | m_pDrawPadCanvas->deleteAll(); | ||
545 | } | ||
546 | } | ||
547 | |||
502 | void DrawPad::importPage() | 548 | void DrawPad::importPage() |
503 | { | 549 | { |
504 | ImportDialog importDialog(this); | 550 | ImportDialog importDialog(this); |
505 | 551 | ||
506 | importDialog.showMaximized(); | 552 | importDialog.showMaximized(); |
507 | 553 | ||
508 | if (importDialog.exec() == QDialog::Accepted) { | 554 | if (importDialog.exec() == QDialog::Accepted) { |
509 | const DocLnk* docLnk = importDialog.selected(); | 555 | const DocLnk* docLnk = importDialog.selected(); |
510 | 556 | ||
511 | if (docLnk) { | 557 | if (docLnk) { |
512 | m_pDrawPadCanvas->importPage(docLnk->file()); | 558 | m_pDrawPadCanvas->importPage(docLnk->file()); |
513 | delete docLnk; | 559 | delete docLnk; |
@@ -520,17 +566,17 @@ void DrawPad::exportPage() | |||
520 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); | 566 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); |
521 | 567 | ||
522 | exportDialog.showMaximized(); | 568 | exportDialog.showMaximized(); |
523 | 569 | ||
524 | if (exportDialog.exec() == QDialog::Accepted) { | 570 | if (exportDialog.exec() == QDialog::Accepted) { |
525 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), | 571 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), |
526 | exportDialog.selectedName(), exportDialog.selectedFormat()); | 572 | exportDialog.selectedName(), exportDialog.selectedFormat()); |
527 | } | 573 | } |
528 | } | 574 | } |
529 | 575 | ||
530 | void DrawPad::thumbnailView() | 576 | void DrawPad::thumbnailView() |
531 | { | 577 | { |
532 | ThumbnailView thumbnailView(m_pDrawPadCanvas->pages(), this); | 578 | ThumbnailView thumbnailView(m_pDrawPadCanvas, this); |
533 | 579 | ||
534 | thumbnailView.showMaximized(); | 580 | thumbnailView.showMaximized(); |
535 | thumbnailView.exec(); | 581 | thumbnailView.exec(); |
536 | } | 582 | } |