-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 19 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 20 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 5 |
4 files changed, 40 insertions, 6 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 3331193..d9d0ce0 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp @@ -9,96 +9,98 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "drawpad.h" #include "drawpadcanvas.h" #include "ellipsetool.h" #include "erasetool.h" #include "exportdialog.h" #include "filledellipsetool.h" #include "filledrectangletool.h" #include "filltool.h" #include "importdialog.h" #include "linetool.h" #include "newpagedialog.h" #include "page.h" #include "pageinformationdialog.h" #include "pointtool.h" #include "rectangletool.h" #include "texttool.h" #include "thumbnailview.h" #include <opie2/qcolordialog.h> #include <opie2/ocolorpopupmenu.h> #include <qpe/applnk.h> #include <qpe/config.h> #include <qtoolbar.h> #include <qpe/resource.h> #include <qpe/qpeapplication.h> #include <qmenubar.h> #include <qaction.h> #include <qfile.h> #include <qmessagebox.h> #include <qspinbox.h> #include <qtoolbutton.h> #include <qtooltip.h> #include <qwhatsthis.h> using namespace Opie::Ui; using namespace Opie::Ui; DrawPad::DrawPad(QWidget* parent, const char* name, WFlags /*fl*/ ) : QMainWindow(parent, name, WStyle_ContextHelp) { // init members + connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), + this, SLOT(slotAppMessage(const QCString&, const QByteArray&)) ); m_pDrawPadCanvas = new DrawPadCanvas(this, this); connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView())); setCentralWidget(m_pDrawPadCanvas); // init menu setToolBarsMovable(false); QToolBar* menuToolBar = new QToolBar(this); QMenuBar* menuBar = new QMenuBar(menuToolBar); QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar); QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); deleteAllAction->addTo(toolsPopupMenu); toolsPopupMenu->insertSeparator(); QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); importPageAction->addTo(toolsPopupMenu); QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); exportPageAction->addTo(toolsPopupMenu); toolsPopupMenu->insertSeparator(); QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); thumbnailViewAction->addTo(toolsPopupMenu); QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this); connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation())); pageInformationAction->addTo(toolsPopupMenu); toolsPopupMenu->insertSeparator(); m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this); m_pAntiAliasingAction->setToggleAction(true); m_pAntiAliasingAction->addTo(toolsPopupMenu); menuBar->insertItem(tr("Tools"), toolsPopupMenu); @@ -618,48 +620,65 @@ void DrawPad::exportPage() ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); if ( QPEApplication::execDialog( &exportDialog ) == QDialog::Accepted ) { m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), exportDialog.selectedName(), exportDialog.selectedFormat()); } } void DrawPad::thumbnailView() { ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); QPEApplication::showWidget( &thumbnailView ); thumbnailView.exec(); } void DrawPad::pageInformation() { PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage()); if (pageInformationDialog.exec() == QDialog::Accepted) { m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle()); } } void DrawPad::loadConfig() { Config config("drawpad"); config.setGroup("General"); m_pAntiAliasingAction->setOn(config.readBoolEntry("AntiAliasing", false)); m_pPenWidthSpinBox->setValue(config.readNumEntry("PenWidth", 1)); changePenColor(QColor(config.readEntry("PenColor", Qt::black.name()))); changeBrushColor(QColor(config.readEntry("BrushColor", Qt::white.name()))); m_pDrawPadCanvas->selectPage(config.readNumEntry("PagePosition", 1)); } void DrawPad::saveConfig() { Config config("drawpad"); config.setGroup("General"); config.writeEntry("PagePosition", (int)m_pDrawPadCanvas->pagePosition()); config.writeEntry("AntiAliasing", antiAliasing()); config.writeEntry("PenWidth", (int)m_pen.width()); config.writeEntry("PenColor", m_pen.color().name()); config.writeEntry("BrushColor", m_brush.color().name()); } + + +/* + * Import a Thumbnail from SCAP or similiar + */ +void DrawPad::slotAppMessage( const QCString& str, const QByteArray& ar ) { + QDataStream stream(ar, IO_ReadOnly ); + /* + * import the pixmap + */ + if ( str == "importPixmap(QPixmap)" ) { + QPixmap pix; + stream >> pix;; + m_pDrawPadCanvas->importPixmap( pix ); + QPEApplication::setKeepRunning(); + } +} diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index 8ba6e58..ba9e47d 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h @@ -3,96 +3,98 @@ * DrawPad - a drawing program for Opie Environment * * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef DRAWPAD_H #define DRAWPAD_H #include <qmainwindow.h> #include <qpen.h> class DrawPadCanvas; class Tool; class QAction; class QColor; class QSpinBox; class QToolButton; class QWidgetStack; class DrawPad : public QMainWindow { Q_OBJECT public: DrawPad(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); ~DrawPad(); static QString appName() { return QString::fromLatin1("drawpad"); } Tool* tool() { return m_pTool; } QPen pen() { return m_pen; } QBrush brush() { return m_brush; } bool antiAliasing(); void finishStartup(); private slots: void newPage(); void clearPage(); void deletePage(); + void slotAppMessage( const QCString&, const QByteArray& ); + void setPointTool(); void setLineTool(); void setRectangleTool(); void setFilledRectangleTool(); void setEllipseTool(); void setFilledEllipseTool(); void setTextTool(); void setFillTool(); void setEraseTool(); void changePenWidth(int value); void changePenColor(const QColor& color); void changeBrushColor(const QColor& color); void updateView(); void deleteAll(); void importPage(); void exportPage(); void thumbnailView(); void pageInformation(); private: void loadConfig(); void saveConfig(); DrawPadCanvas* m_pDrawPadCanvas; Tool* m_pTool; QPen m_pen; QBrush m_brush; QAction* m_pAntiAliasingAction; QAction* m_pUndoAction; QAction* m_pRedoAction; QAction* m_pFirstPageAction; QAction* m_pPreviousPageAction; QAction* m_pNextPageAction; QAction* m_pLastPageAction; QAction* m_pPointToolAction; QAction* m_pLineToolAction; QAction* m_pRectangleToolAction; QAction* m_pFilledRectangleToolAction; QAction* m_pEllipseToolAction; QAction* m_pFilledEllipseToolAction; diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 446096c..423ef26 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp @@ -135,306 +135,318 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) r += l - '0'; } else { r += l - 'a' + 10; } byteArray[i] = r; } QImage image; image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); Page* page = new Page(m_title, image.width(), image.height()); page->setLastModified(m_date); page->pixmap()->convertFromImage(image); m_pages.append(page); } return true; } DrawPadCanvas::DrawPadCanvas(DrawPad* drawPad, QWidget* parent, const char* name) : QScrollView(parent, name) { m_pDrawPad = drawPad; m_pages.setAutoDelete(true); viewport()->setBackgroundMode(QWidget::NoBackground); } DrawPadCanvas::~DrawPadCanvas() { } void DrawPadCanvas::load(QIODevice* ioDevice) { QTextStream textStream(ioDevice); textStream.setCodec(QTextCodec::codecForName("UTF-8")); QXmlInputSource xmlInputSource(textStream); QXmlSimpleReader xmlSimpleReader; DrawPadCanvasXmlHandler drawPadCanvasXmlHandler; xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); xmlSimpleReader.parse(xmlInputSource); m_pages = drawPadCanvasXmlHandler.pages(); if (m_pages.isEmpty()) { - m_pages.append(new Page("", + m_pages.append(new Page("", clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0), clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0))); m_pages.current()->pixmap()->fill(Qt::white); } resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } void DrawPadCanvas::initialPage() { - m_pages.append(new Page("", + m_pages.append(new Page("", clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0), clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0))); //236, 232)); no more fixed sizes m_pages.current()->pixmap()->fill(Qt::white); resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } void DrawPadCanvas::save(QIODevice* ioDevice) { QTextStream textStream(ioDevice); textStream.setCodec(QTextCodec::codecForName("UTF-8")); textStream << "<drawpad>" << endl; textStream << " <images>" << endl; QListIterator<Page> bufferIterator(m_pages); for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { textStream << " <image>" << endl; textStream << " <title>" << bufferIterator.current()->title() << "</title>" << endl; int intDate = QDateTime(QDate(1970, 1, 1)).secsTo(bufferIterator.current()->lastModified()); textStream << " <date>" << intDate << "</date>" << endl; QImage image = bufferIterator.current()->pixmap()->convertToImage(); QByteArray byteArray; QBuffer buffer(byteArray); QImageIO imageIO(&buffer, "PNG"); buffer.open(IO_WriteOnly); imageIO.setImage(image); imageIO.write(); buffer.close(); textStream << " <data length=\"" << byteArray.size() << "\" format=\"PNG\">"; static const char hexchars[] = "0123456789abcdef"; for (int i = 0; i < (int)byteArray.size(); i++ ) { uchar s = (uchar)byteArray[i]; textStream << hexchars[s >> 4]; textStream << hexchars[s & 0x0f]; } textStream << "</data>" << endl; textStream << " </image>" << endl; } textStream << " </images>" << endl; textStream << "</drawpad>"; } void DrawPadCanvas::importPage(const QString& fileName) { Page* importedPage = new Page(); importedPage->pixmap()->load(fileName); m_pages.insert(m_pages.at() + 1, importedPage); resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } +void DrawPadCanvas::importPixmap( const QPixmap& pix ) { + Page* importedPage = new Page(); + + (*importedPage->pixmap()) = pix; + m_pages.insert(m_pages.at()+1, importedPage ); + resizeContents(m_pages.current()->pixmap()->width(), + m_pages.current()->pixmap()->height() ); + viewport()->update(); + + emit pagesChanged(); +} + void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,const QString& format) { if (fromPage == toPage) { DocLnk docLnk; MimeType mimeType(format); docLnk.setName(name); docLnk.setType(mimeType.id()); FileManager fileManager; QIODevice* ioDevice = fileManager.saveFile(docLnk); QImageIO imageIO(ioDevice, format); QImage image = m_pages.current()->pixmap()->convertToImage(); imageIO.setImage(image); imageIO.write(); delete ioDevice; } else { for (uint i = fromPage; i <= toPage; i++) { DocLnk docLnk; MimeType mimeType(format); docLnk.setName(name + QString::number(i)); docLnk.setType(mimeType.id()); FileManager fileManager; QIODevice* ioDevice = fileManager.saveFile(docLnk); QImageIO imageIO(ioDevice, format); QImage image = m_pages.at(i - 1)->pixmap()->convertToImage(); imageIO.setImage(image); imageIO.write(); delete ioDevice; } } } Page* DrawPadCanvas::currentPage() { return m_pages.current(); } QList<Page> DrawPadCanvas::pages() { return m_pages; } uint DrawPadCanvas::pagePosition() { return (m_pages.at() + 1); } uint DrawPadCanvas::pageCount() { return m_pages.count(); } void DrawPadCanvas::selectPage(Page* page) { m_pages.findRef(page); resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } void DrawPadCanvas::backupPage() { m_pages.current()->backup(); emit pagesChanged(); } void DrawPadCanvas::selectPage(uint pagePosition) { m_pages.at(pagePosition - 1); resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } void DrawPadCanvas::deleteAll() { m_pages.clear(); - m_pages.append(new Page("", + m_pages.append(new Page("", clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0), clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0))); m_pages.current()->pixmap()->fill(Qt::white); resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) { m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); m_pages.current()->pixmap()->fill(color); resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } void DrawPadCanvas::clearPage() { m_pages.current()->pixmap()->fill(Qt::white); resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); } void DrawPadCanvas::deletePage() { m_pages.remove(m_pages.current()); if (m_pages.isEmpty()) { - m_pages.append(new Page("", + m_pages.append(new Page("", clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0), clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0))); m_pages.current()->pixmap()->fill(Qt::white); } resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height()); viewport()->update(); emit pagesChanged(); } void DrawPadCanvas::movePageUp() { int index = m_pages.at(); Page* page = m_pages.take(); m_pages.insert(index - 1, page); emit pagesChanged(); } void DrawPadCanvas::movePageDown() { int index = m_pages.at(); Page* page = m_pages.take(); m_pages.insert(index + 1, page); emit pagesChanged(); } bool DrawPadCanvas::goPreviousPageEnabled() { return (m_pages.current() != m_pages.getFirst()); } bool DrawPadCanvas::goNextPageEnabled() { return (m_pages.current() != m_pages.getLast()); } void DrawPadCanvas::undo() { m_pages.current()->undo(); viewport()->update(); emit pagesChanged(); } diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index 80a2a7e..2b3d4a5 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h @@ -1,82 +1,83 @@ /*************************************************************************** * * * DrawPad - a drawing program for Opie Environment * * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef DRAWPADCANVAS_H #define DRAWPADCANVAS_H #include <qscrollview.h> #include <qlist.h> #include <qpointarray.h> class DrawPad; class Page; class DrawPadCanvas : public QScrollView -{ +{ Q_OBJECT public: DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); ~DrawPadCanvas(); void load(QIODevice* ioDevice); void initialPage(); void save(QIODevice* ioDevice); void importPage(const QString& fileName); void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); + void importPixmap( const QPixmap& ); bool goPreviousPageEnabled(); bool goNextPageEnabled(); Page* currentPage(); QList<Page> pages(); uint pagePosition(); uint pageCount(); void selectPage(Page* page); void selectPage(uint pagePosition); void backupPage(); public slots: void deleteAll(); void newPage(QString title, uint width, uint height, const QColor& color); void clearPage(); void deletePage(); void movePageUp(); void movePageDown(); - + void undo(); void redo(); void goFirstPage(); void goPreviousPage(); void goNextPage(); void goLastPage(); signals: void pagesChanged(); protected: void contentsMousePressEvent(QMouseEvent* e); void contentsMouseReleaseEvent(QMouseEvent* e); void contentsMouseMoveEvent(QMouseEvent* e); void drawContents(QPainter* p, int cx, int cy, int cw, int ch); private: DrawPad* m_pDrawPad; QList<Page> m_pages; }; #endif // DRAWPADCANVAS_H |