Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

drawpad.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   DrawPad - a drawing program for Opie Environment                      *
00004  *                                                                         *
00005  *   (C) 2002 by S. Prud'homme <prudhomme@laposte.net>                     *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "drawpad.h"
00015 
00016 #include "drawpadcanvas.h"
00017 #include "ellipsetool.h"
00018 #include "erasetool.h"
00019 #include "exportdialog.h"
00020 #include "filledellipsetool.h"
00021 #include "filledrectangletool.h"
00022 #include "filltool.h"
00023 #include "importdialog.h"
00024 #include "linetool.h"
00025 #include "newpagedialog.h"
00026 #include "page.h"
00027 #include "pageinformationdialog.h"
00028 #include "pointtool.h"
00029 #include "rectangletool.h"
00030 #include "texttool.h"
00031 #include "thumbnailview.h"
00032 
00033 #include <opie2/qcolordialog.h>
00034 #include <opie2/ocolorpopupmenu.h>
00035 #include <opie2/oresource.h>
00036 
00037 #include <qpe/applnk.h>
00038 #include <qpe/config.h>
00039 #include <qtoolbar.h>
00040 #include <qpe/qpeapplication.h>
00041 
00042 #include <qmenubar.h>
00043 #include <qaction.h>
00044 #include <qfile.h>
00045 #include <qmessagebox.h>
00046 #include <qspinbox.h>
00047 #include <qtoolbutton.h>
00048 #include <qtooltip.h>
00049 #include <qwhatsthis.h>
00050 
00051 using namespace Opie::Ui;
00052 DrawPad::DrawPad(QWidget* parent, const char* name,  WFlags /*fl*/ )
00053     : QMainWindow(parent, name, WStyle_ContextHelp)
00054 {
00055     // init members
00056     connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
00057              this, SLOT(slotAppMessage(const QCString&, const QByteArray&)) );
00058 
00059     m_pDrawPadCanvas = new DrawPadCanvas(this, this);
00060 
00061     connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView()));
00062 
00063     setCentralWidget(m_pDrawPadCanvas);
00064 
00065     // init menu
00066 
00067     setToolBarsMovable(false);
00068 
00069     QToolBar* menuToolBar = new QToolBar(this);
00070     QMenuBar* menuBar = new QMenuBar(menuToolBar);
00071 
00072     QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar);
00073 
00074     QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this);
00075     connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll()));
00076     deleteAllAction->addTo(toolsPopupMenu);
00077 
00078     toolsPopupMenu->insertSeparator();
00079 
00080     QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this);
00081     connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage()));
00082     importPageAction->addTo(toolsPopupMenu);
00083 
00084     QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this);
00085     connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage()));
00086     exportPageAction->addTo(toolsPopupMenu);
00087 
00088     toolsPopupMenu->insertSeparator();
00089 
00090     QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this);
00091     connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView()));
00092     thumbnailViewAction->addTo(toolsPopupMenu);
00093 
00094     QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this);
00095     connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation()));
00096     pageInformationAction->addTo(toolsPopupMenu);
00097 
00098     toolsPopupMenu->insertSeparator();
00099 
00100     m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this);
00101     m_pAntiAliasingAction->setToggleAction(true);
00102     m_pAntiAliasingAction->addTo(toolsPopupMenu);
00103 
00104     menuBar->insertItem(tr("Tools"), toolsPopupMenu);
00105 
00106     // init page toolbar
00107 
00108     QToolBar* pageToolBar = new QToolBar(this);
00109 
00110     QAction* newPageAction = new QAction(tr("New Page"), Opie::Core::OResource::loadPixmap("new", Opie::Core::OResource::SmallIcon),
00111                                          QString::null, 0, this);
00112     connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
00113     newPageAction->addTo(pageToolBar);
00114     newPageAction->setWhatsThis( tr( "Click here to add a new sheet." ) );
00115 
00116     QAction* clearPageAction = new QAction(tr("Clear Page"),
00117                                            Opie::Core::OResource::loadPixmap("drawpad/clear", Opie::Core::OResource::SmallIcon),
00118                                            QString::null, 0, this);
00119     connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage()));
00120     clearPageAction->addTo(pageToolBar);
00121     clearPageAction->setWhatsThis( tr( "Click here to erase the current sheet." ) );
00122 
00123     QAction* deletePageAction = new QAction(tr("Delete Page"),
00124                                             Opie::Core::OResource::loadPixmap("trash", Opie::Core::OResource::SmallIcon),
00125                                             QString::null, 0, this);
00126     connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
00127     deletePageAction->addTo(pageToolBar);
00128     deletePageAction->setWhatsThis( tr( "Click here to remove the current sheet." ) );
00129 
00130     QToolBar* emptyToolBar = new QToolBar(this);
00131     emptyToolBar->setHorizontalStretchable(true);
00132 
00133     // init navigation toolbar
00134 
00135     QToolBar* navigationToolBar = new QToolBar(this);
00136 
00137     m_pUndoAction = new QAction(tr("Undo"), Opie::Core::OResource::loadPixmap("undo", Opie::Core::OResource::SmallIcon),
00138                                 QString::null, 0, this);
00139     connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
00140     m_pUndoAction->addTo(navigationToolBar);
00141     m_pUndoAction->setWhatsThis( tr( "Click here to undo the last action." ) );
00142 
00143     m_pRedoAction = new QAction(tr("Redo"), Opie::Core::OResource::loadPixmap("redo", Opie::Core::OResource::SmallIcon),
00144                                 QString::null, 0, this);
00145     connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
00146     m_pRedoAction->addTo(navigationToolBar);
00147     m_pRedoAction->setWhatsThis( tr( "Click here to re-perform the last action." ) );
00148 
00149     m_pFirstPageAction = new QAction(tr("First Page"),
00150                                      Opie::Core::OResource::loadPixmap("fastback", Opie::Core::OResource::SmallIcon),
00151                                      QString::null, 0, this);
00152     connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage()));
00153     m_pFirstPageAction->addTo(navigationToolBar);
00154     m_pFirstPageAction->setWhatsThis( tr( "Click here to view the first page." ) );
00155 
00156     m_pPreviousPageAction = new QAction(tr("Previous Page"),
00157                                         Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon),
00158                                         QString::null, 0, this);
00159     connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage()));
00160     m_pPreviousPageAction->addTo(navigationToolBar);
00161     m_pPreviousPageAction->setWhatsThis( tr( "Click here to view the previous page." ) );
00162 
00163     m_pNextPageAction = new QAction(tr("Next Page"),
00164                                     Opie::Core::OResource::loadPixmap("forward", Opie::Core::OResource::SmallIcon),
00165                                     QString::null, 0, this);
00166     connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage()));
00167     m_pNextPageAction->addTo(navigationToolBar);
00168     m_pNextPageAction->setWhatsThis( tr( "Click here to view the next page." ) );
00169 
00170     m_pLastPageAction = new QAction(tr("Last Page"),
00171                                     Opie::Core::OResource::loadPixmap("fastforward", Opie::Core::OResource::SmallIcon),
00172                                     QString::null, 0, this);
00173     connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage()));
00174     m_pLastPageAction->addTo(navigationToolBar);
00175     m_pLastPageAction->setWhatsThis( tr( "Click here to view the last page." ) );
00176 
00177     // init draw mode toolbar
00178 
00179     QToolBar* drawModeToolBar = new QToolBar(this);
00180 
00181     m_pLineToolButton = new QToolButton(drawModeToolBar);
00182     m_pLineToolButton->setToggleButton(true);
00183     QWhatsThis::add( m_pLineToolButton, tr( "Click here to select one of the available tools to draw lines." ) );
00184 
00185 
00186     QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton);
00187 
00188     m_pPointToolAction = new QAction(tr("Draw Point"),
00189                                      Opie::Core::OResource::loadPixmap("drawpad/point", Opie::Core::OResource::SmallIcon),
00190                                      "", 0, this);
00191     connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool()));
00192     m_pPointToolAction->addTo(linePopupMenu);
00193 
00194     m_pLineToolAction = new QAction(tr("Draw Line"),
00195                                     Opie::Core::OResource::loadPixmap("drawpad/line", Opie::Core::OResource::SmallIcon),
00196                                     "", 0, this);
00197     connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool()));
00198     m_pLineToolAction->addTo(linePopupMenu);
00199 
00200     m_pLineToolButton->setPopup(linePopupMenu);
00201     m_pLineToolButton->setPopupDelay(0);
00202 
00203     m_pRectangleToolButton = new QToolButton(drawModeToolBar);
00204     m_pRectangleToolButton->setToggleButton(true);
00205     QWhatsThis::add( m_pRectangleToolButton, tr( "Click here to select one of the available tools to draw rectangles." ) );
00206 
00207     QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton);
00208 
00209     m_pRectangleToolAction = new QAction(tr("Draw Rectangle"),
00210                                          Opie::Core::OResource::loadPixmap("drawpad/rectangle", Opie::Core::OResource::SmallIcon),
00211                                          "", 0, this);
00212     connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool()));
00213     m_pRectangleToolAction->addTo(rectanglePopupMenu);
00214 
00215     m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"),
00216                                                Opie::Core::OResource::loadPixmap("drawpad/filledrectangle",
00217                                                Opie::Core::OResource::SmallIcon), "", 0, this);
00218     connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool()));
00219     m_pFilledRectangleToolAction->addTo(rectanglePopupMenu);
00220 
00221     m_pRectangleToolButton->setPopup(rectanglePopupMenu);
00222     m_pRectangleToolButton->setPopupDelay(0);
00223 
00224     m_pEllipseToolButton = new QToolButton(drawModeToolBar);
00225     m_pEllipseToolButton->setToggleButton(true);
00226     QWhatsThis::add( m_pEllipseToolButton, tr( "Click here to select one of the available tools to draw ellipses." ) );
00227 
00228     QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton);
00229 
00230     m_pEllipseToolAction = new QAction(tr("Draw Ellipse"),
00231                                        Opie::Core::OResource::loadPixmap("drawpad/ellipse", Opie::Core::OResource::SmallIcon),
00232                                        "", 0, this);
00233     connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool()));
00234     m_pEllipseToolAction->addTo(ellipsePopupMenu);
00235 
00236     m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"),
00237                                              Opie::Core::OResource::loadPixmap("drawpad/filledellipse",
00238                                              Opie::Core::OResource::SmallIcon), "", 0, this);
00239     connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool()));
00240     m_pFilledEllipseToolAction->addTo(ellipsePopupMenu);
00241 
00242     m_pEllipseToolButton->setPopup(ellipsePopupMenu);
00243     m_pEllipseToolButton->setPopupDelay(0);
00244 
00245     m_pTextToolAction = new QAction(tr("Insert Text"),
00246                                     Opie::Core::OResource::loadPixmap("drawpad/text", Opie::Core::OResource::SmallIcon),
00247                                     QString::null, 0, this);
00248     m_pTextToolAction->setToggleAction(true);
00249     connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool()));
00250     m_pTextToolAction->addTo(drawModeToolBar);
00251     m_pTextToolAction->setWhatsThis( tr( "Click here to select the text drawing tool." ) );
00252 
00253     m_pFillToolAction = new QAction(tr("Fill Region"),
00254                                     Opie::Core::OResource::loadPixmap("drawpad/fill", Opie::Core::OResource::SmallIcon),
00255                                     QString::null, 0, this);
00256     m_pFillToolAction->setToggleAction(true);
00257     connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool()));
00258     m_pFillToolAction->addTo(drawModeToolBar);
00259     m_pFillToolAction->setWhatsThis( tr( "Click here to select the fill tool." ) );
00260 
00261     m_pEraseToolAction = new QAction(tr("Erase Point"),
00262                                      Opie::Core::OResource::loadPixmap("drawpad/erase", Opie::Core::OResource::SmallIcon),
00263                                      QString::null, 0, this);
00264     m_pEraseToolAction->setToggleAction(true);
00265     connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool()));
00266     m_pEraseToolAction->addTo(drawModeToolBar);
00267     m_pEraseToolAction->setWhatsThis( tr( "Click here to select the eraser tool." ) );
00268 
00269     m_pTool = 0;
00270     setRectangleTool();
00271     setEllipseTool();
00272     setPointTool();
00273 
00274     emptyToolBar = new QToolBar(this);
00275     emptyToolBar->setHorizontalStretchable(true);
00276     emptyToolBar->addSeparator();
00277 
00278     // init draw parameters toolbar
00279 
00280     QToolBar* drawParametersToolBar = new QToolBar(this);
00281 
00282     m_pPenWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar);
00283     connect(m_pPenWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int)));
00284 
00285     QToolTip::add(m_pPenWidthSpinBox, tr("Pen Width"));
00286     m_pPenWidthSpinBox->setValue(1);
00287     m_pPenWidthSpinBox->setFocusPolicy(QWidget::NoFocus);
00288     QWhatsThis::add( m_pPenWidthSpinBox, tr( "Click here to select the width of the drawing pen." ) );
00289 
00290     bool useBigIcon = qApp->desktop()->size().width() > 330;
00291 
00292     m_pPenColorToolButton = new QToolButton(drawParametersToolBar);
00293     m_pPenColorToolButton->setUsesBigPixmap( useBigIcon );
00294     m_pPenColorToolButton->setPixmap(Opie::Core::OResource::loadPixmap("drawpad/pencolor", Opie::Core::OResource::SmallIcon));
00295     QWhatsThis::add( m_pPenColorToolButton, tr( "Click here to select the color used when drawing." ) );
00296 
00297     Opie::OColorPopupMenu* penColorPopupMenu = new Opie::OColorPopupMenu(Qt::black, m_pPenColorToolButton);
00298     connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&)));
00299 
00300     QToolTip::add(m_pPenColorToolButton, tr("Pen Color"));
00301     m_pPenColorToolButton->setPopup(penColorPopupMenu);
00302     m_pPenColorToolButton->setPopupDelay(0);
00303 
00304     changePenColor(Qt::black);
00305 
00306     m_pBrushColorToolButton = new QToolButton(drawParametersToolBar);
00307     m_pBrushColorToolButton->setUsesBigPixmap( useBigIcon );
00308     m_pBrushColorToolButton->setPixmap(Opie::Core::OResource::loadPixmap("drawpad/brushcolor", Opie::Core::OResource::SmallIcon));
00309     QWhatsThis::add( m_pBrushColorToolButton, tr( "Click here to select the color used when filling in areas." ) );
00310 
00311     Opie::OColorPopupMenu* brushColorPopupMenu = new Opie::OColorPopupMenu(Qt::white, m_pBrushColorToolButton);
00312     connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&)));
00313 
00314     QToolTip::add(m_pBrushColorToolButton, tr("Fill Color"));
00315     m_pBrushColorToolButton->setPopup(brushColorPopupMenu);
00316     m_pBrushColorToolButton->setPopupDelay(0);
00317 
00318     changeBrushColor(Qt::white);
00319 
00320     // delay the rest of the initialization and do it from within the mainloop
00321     // if we don't do this, the widget layout may not be constructed upon
00322     // and we will end up with a wrong QScrollview page size (Mickeyl)
00323     QTimer::singleShot( 100, this, SLOT( finishStartup() ) );
00324 }
00325 
00326 
00327 void DrawPad::finishStartup()
00328 {
00329     // init pages
00330 
00331     QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
00332 
00333     if (file.open(IO_ReadOnly)) {
00334         m_pDrawPadCanvas->load(&file);
00335         file.close();
00336     } else {
00337         m_pDrawPadCanvas->initialPage();
00338     }
00339 
00340     loadConfig();
00341 
00342 }
00343 
00344 DrawPad::~DrawPad()
00345 {
00346     saveConfig();
00347 
00348     QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
00349 
00350     if (file.open(IO_WriteOnly)) {
00351         m_pDrawPadCanvas->save(&file);
00352         file.close();
00353     }
00354 }
00355 
00356 bool DrawPad::antiAliasing()
00357 {
00358     return (m_pAntiAliasingAction->isOn());
00359 }
00360 
00361 void DrawPad::newPage()
00362 {
00363     QRect rect = m_pDrawPadCanvas->contentsRect();
00364 
00365     NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this);
00366 
00367     if (newPageDialog.exec() == QDialog::Accepted) {
00368         m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(),
00369                                   newPageDialog.selectedHeight(), newPageDialog.selectedColor());
00370     }
00371 }
00372 
00373 void DrawPad::clearPage()
00374 {
00375     QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"),
00376                            QMessageBox::Information, QMessageBox::Yes,
00377                            QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
00378                            QMessageBox::NoButton, this);
00379 
00380     messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
00381     messageBox.setButtonText(QMessageBox::No, tr("No"));
00382 
00383     if (messageBox.exec() == QMessageBox::Yes) {
00384         m_pDrawPadCanvas->clearPage();
00385     }
00386 }
00387 
00388 void DrawPad::deletePage()
00389 {
00390     QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"),
00391                            QMessageBox::Information, QMessageBox::Yes,
00392                            QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
00393                            QMessageBox::NoButton, this);
00394 
00395     messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
00396     messageBox.setButtonText(QMessageBox::No, tr("No"));
00397 
00398     if (messageBox.exec() == QMessageBox::Yes) {
00399         m_pDrawPadCanvas->deletePage();
00400     }
00401 }
00402 
00403 void DrawPad::setPointTool()
00404 {
00405     if (m_pTool) {
00406         delete m_pTool;
00407     }
00408 
00409     m_pTool = new PointTool(this, m_pDrawPadCanvas);
00410 
00411     m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet());
00412     QToolTip::add(m_pLineToolButton, m_pPointToolAction->text());
00413 
00414     disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0);
00415     connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated()));
00416 
00417     m_pLineToolButton->setOn(true);
00418     m_pRectangleToolButton->setOn(false);
00419     m_pEllipseToolButton->setOn(false);
00420     m_pTextToolAction->setOn(false);
00421     m_pFillToolAction->setOn(false);
00422     m_pEraseToolAction->setOn(false);
00423 }
00424 
00425 void DrawPad::setLineTool()
00426 {
00427     if (m_pTool) {
00428         delete m_pTool;
00429     }
00430 
00431     m_pTool = new LineTool(this, m_pDrawPadCanvas);
00432 
00433     m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet());
00434     QToolTip::add(m_pLineToolButton, m_pLineToolAction->text());
00435 
00436     disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0);
00437     connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated()));
00438 
00439     m_pLineToolButton->setOn(true);
00440     m_pRectangleToolButton->setOn(false);
00441     m_pEllipseToolButton->setOn(false);
00442     m_pTextToolAction->setOn(false);
00443     m_pFillToolAction->setOn(false);
00444     m_pEraseToolAction->setOn(false);
00445 }
00446 
00447 void DrawPad::setRectangleTool()
00448 {
00449     if (m_pTool) {
00450         delete m_pTool;
00451     }
00452 
00453     m_pTool = new RectangleTool(this, m_pDrawPadCanvas);
00454 
00455     m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet());
00456     QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text());
00457 
00458     disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0);
00459     connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated()));
00460 
00461     m_pLineToolButton->setOn(false);
00462     m_pRectangleToolButton->setOn(true);
00463     m_pEllipseToolButton->setOn(false);
00464     m_pTextToolAction->setOn(false);
00465     m_pFillToolAction->setOn(false);
00466     m_pEraseToolAction->setOn(false);
00467 }
00468 
00469 void DrawPad::setFilledRectangleTool()
00470 {
00471     if (m_pTool) {
00472         delete m_pTool;
00473     }
00474 
00475     m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas);
00476 
00477     m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet());
00478     QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text());
00479 
00480     disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0);
00481     connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated()));
00482 
00483     m_pLineToolButton->setOn(false);
00484     m_pRectangleToolButton->setOn(true);
00485     m_pEllipseToolButton->setOn(false);
00486     m_pTextToolAction->setOn(false);
00487     m_pFillToolAction->setOn(false);
00488     m_pEraseToolAction->setOn(false);
00489 }
00490 
00491 void DrawPad::setEllipseTool()
00492 {
00493     if (m_pTool) {
00494         delete m_pTool;
00495     }
00496 
00497     m_pTool = new EllipseTool(this, m_pDrawPadCanvas);
00498 
00499     m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet());
00500     QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text());
00501 
00502     disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0);
00503     connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated()));
00504 
00505     m_pLineToolButton->setOn(false);
00506     m_pRectangleToolButton->setOn(false);
00507     m_pEllipseToolButton->setOn(true);
00508     m_pTextToolAction->setOn(false);
00509     m_pFillToolAction->setOn(false);
00510     m_pEraseToolAction->setOn(false);
00511 }
00512 
00513 void DrawPad::setFilledEllipseTool()
00514 {
00515     if (m_pTool) {
00516         delete m_pTool;
00517     }
00518 
00519     m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas);
00520 
00521     m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet());
00522     QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text());
00523 
00524     disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0);
00525     connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated()));
00526 
00527     m_pLineToolButton->setOn(false);
00528     m_pRectangleToolButton->setOn(false);
00529     m_pEllipseToolButton->setOn(true);
00530     m_pTextToolAction->setOn(false);
00531     m_pFillToolAction->setOn(false);
00532     m_pEraseToolAction->setOn(false);
00533 }
00534 
00535 void DrawPad::setTextTool()
00536 {
00537     if (m_pTool) {
00538         delete m_pTool;
00539     }
00540 
00541     m_pTool = new TextTool(this, m_pDrawPadCanvas);
00542 
00543     m_pLineToolButton->setOn(false);
00544     m_pRectangleToolButton->setOn(false);
00545     m_pEllipseToolButton->setOn(false);
00546     m_pTextToolAction->setOn(true);
00547     m_pFillToolAction->setOn(false);
00548     m_pEraseToolAction->setOn(false);
00549 }
00550 
00551 void DrawPad::setFillTool()
00552 {
00553     if (m_pTool) {
00554         delete m_pTool;
00555     }
00556 
00557     m_pTool = new FillTool(this, m_pDrawPadCanvas);
00558 
00559     m_pLineToolButton->setOn(false);
00560     m_pRectangleToolButton->setOn(false);
00561     m_pEllipseToolButton->setOn(false);
00562     m_pTextToolAction->setOn(false);
00563     m_pFillToolAction->setOn(true);
00564     m_pEraseToolAction->setOn(false);
00565 }
00566 
00567 void DrawPad::setEraseTool()
00568 {
00569     if (m_pTool) {
00570         delete m_pTool;
00571     }
00572 
00573     m_pTool = new EraseTool(this, m_pDrawPadCanvas);
00574 
00575     m_pLineToolButton->setOn(false);
00576     m_pRectangleToolButton->setOn(false);
00577     m_pEllipseToolButton->setOn(false);
00578     m_pTextToolAction->setOn(false);
00579     m_pFillToolAction->setOn(false);
00580     m_pEraseToolAction->setOn(true);
00581 }
00582 
00583 void DrawPad::changePenWidth(int value)
00584 {
00585     m_pen.setWidth(value);
00586 }
00587 
00588 void DrawPad::changePenColor(const QColor& color)
00589 {
00590     m_pen.setColor(color);
00591 
00592     QPainter painter;
00593     painter.begin(m_pPenColorToolButton->pixmap());
00594     int size = AppLnk::smallIconSize();
00595     painter.fillRect(QRect(0, 6*size/7+1, size, size/7), m_pen.color());
00596     painter.end();
00597 
00598     m_pPenColorToolButton->popup()->hide();
00599 }
00600 
00601 void DrawPad::changeBrushColor(const QColor& color)
00602 {
00603     m_brush = QBrush(color);
00604 
00605     QPainter painter;
00606     painter.begin(m_pBrushColorToolButton->pixmap());
00607     int size = AppLnk::smallIconSize();
00608     painter.fillRect(QRect(0, 6*size/7+1, size, size/7), m_brush.color());
00609     painter.end();
00610 
00611     m_pBrushColorToolButton->popup()->hide();
00612 }
00613 
00614 void DrawPad::updateView()
00615 {
00616     uint pagePosition = m_pDrawPadCanvas->pagePosition();
00617     uint pageCount = m_pDrawPadCanvas->pageCount();
00618 
00619     setCaption( tr( "DrawPad - Page %1/%2" ).arg( pagePosition ).arg( pageCount ) );
00620 
00621     m_pUndoAction->setEnabled(m_pDrawPadCanvas->currentPage()->undoEnabled());
00622     m_pRedoAction->setEnabled(m_pDrawPadCanvas->currentPage()->redoEnabled());
00623 
00624     m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
00625     m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
00626     m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
00627     m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
00628 }
00629 
00630 void DrawPad::deleteAll()
00631 {
00632     QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"),
00633                            QMessageBox::Information, QMessageBox::Yes,
00634                            QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
00635                            QMessageBox::NoButton, this);
00636 
00637     messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
00638     messageBox.setButtonText(QMessageBox::No, tr("No"));
00639 
00640     if (messageBox.exec() == QMessageBox::Yes) {
00641         m_pDrawPadCanvas->deleteAll();
00642     }
00643 }
00644 
00645 void DrawPad::importPage()
00646 {
00647     ImportDialog importDialog(this);
00648 
00649     if ( QPEApplication::execDialog( &importDialog ) == QDialog::Accepted ) {
00650         const DocLnk* docLnk = importDialog.selected();
00651 
00652         if (docLnk) {
00653             m_pDrawPadCanvas->importPage(docLnk->file());
00654             delete docLnk;
00655         }
00656     }
00657 }
00658 
00659 void DrawPad::exportPage()
00660 {
00661     ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this);
00662 
00663     if ( QPEApplication::execDialog( &exportDialog ) == QDialog::Accepted ) {
00664         m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(),
00665                                      exportDialog.selectedName(), exportDialog.selectedFormat());
00666     }
00667 }
00668 
00669 void DrawPad::thumbnailView()
00670 {
00671     ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this);
00672 
00673     QPEApplication::showWidget( &thumbnailView );
00674     thumbnailView.exec();
00675 }
00676 
00677 void DrawPad::pageInformation()
00678 {
00679     PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage());
00680 
00681     if (pageInformationDialog.exec() == QDialog::Accepted) {
00682         m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle());
00683     }
00684 }
00685 
00686 void DrawPad::loadConfig()
00687 {
00688     Config config("drawpad");
00689     config.setGroup("General");
00690 
00691     m_pAntiAliasingAction->setOn(config.readBoolEntry("AntiAliasing", false));
00692     m_pPenWidthSpinBox->setValue(config.readNumEntry("PenWidth", 1));
00693     changePenColor(QColor(config.readEntry("PenColor", Qt::black.name())));
00694     changeBrushColor(QColor(config.readEntry("BrushColor", Qt::white.name())));
00695     m_pDrawPadCanvas->selectPage(config.readNumEntry("PagePosition", 1));
00696 }
00697 
00698 void DrawPad::saveConfig()
00699 {
00700     Config config("drawpad");
00701     config.setGroup("General");
00702 
00703     config.writeEntry("PagePosition", (int)m_pDrawPadCanvas->pagePosition());
00704     config.writeEntry("AntiAliasing", antiAliasing());
00705     config.writeEntry("PenWidth", (int)m_pen.width());
00706     config.writeEntry("PenColor", m_pen.color().name());
00707     config.writeEntry("BrushColor", m_brush.color().name());
00708 }
00709 
00710 
00711 /*
00712  * Import a  Thumbnail from SCAP or similiar
00713  */
00714 void DrawPad::slotAppMessage( const QCString& str, const QByteArray& ar ) {
00715     QDataStream stream(ar, IO_ReadOnly );
00716     /*
00717      * import the pixmap
00718      */
00719     if ( str == "importPixmap(QPixmap)" ) {
00720         QPixmap pix;
00721         stream >> pix;;
00722         m_pDrawPadCanvas->importPixmap( pix );
00723         QPEApplication::setKeepRunning();
00724     }
00725 }

Generated on Sat Nov 5 16:17:28 2005 for OPIE by  doxygen 1.4.2