-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 @@ -2,48 +2,49 @@ * * * 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. * * * ***************************************************************************/ #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 <opie/colordialog.h> #include <opie/colorpopupmenu.h> #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/resource.h> #include <qaction.h> #include <qfile.h> #include <qmessagebox.h> #include <qpainter.h> #include <qspinbox.h> #include <qtoolbutton.h> #include <qtooltip.h> DrawPad::DrawPad(QWidget* parent, const char* name) @@ -260,50 +261,50 @@ DrawPad::DrawPad(QWidget* parent, const char* name) m_pDrawPadCanvas->load(&file); file.close(); } else { m_pDrawPadCanvas->initialPage(); } } DrawPad::~DrawPad() { QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); if (file.open(IO_WriteOnly)) { m_pDrawPadCanvas->save(&file); file.close(); } } void DrawPad::newPage() { QRect rect = m_pDrawPadCanvas->contentsRect(); NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); if (newPageDialog.exec() == QDialog::Accepted) { - m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(), - newPageDialog.selectedColor()); + m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), + newPageDialog.selectedHeight(), newPageDialog.selectedColor()); } } void DrawPad::clearPage() { QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), QMessageBox::Information, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, QMessageBox::NoButton, this); messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); messageBox.setButtonText(QMessageBox::No, tr("No")); if (messageBox.exec() == QMessageBox::Yes) { m_pDrawPadCanvas->clearPage(); } } void DrawPad::deletePage() { QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), QMessageBox::Information, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, QMessageBox::NoButton, this); @@ -583,26 +584,27 @@ void DrawPad::exportPage() { ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); exportDialog.showMaximized(); if (exportDialog.exec() == QDialog::Accepted) { m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), exportDialog.selectedName(), exportDialog.selectedFormat()); } } void DrawPad::thumbnailView() { ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); thumbnailView.showMaximized(); thumbnailView.exec(); } void DrawPad::pageInformation() { PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage()); if (pageInformationDialog.exec() == QDialog::Accepted) { + m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle()); } } 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 @@ -26,224 +26,248 @@ #include <qpainter.h> #include <qtextcodec.h> #include <qtextstream.h> #include <qxml.h> #include <zlib.h> class DrawPadCanvasXmlHandler: public QXmlDefaultHandler { public: DrawPadCanvasXmlHandler(); ~DrawPadCanvasXmlHandler(); QList<Page> pages(); bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts); bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName); bool characters(const QString& ch); private: enum State { Unknown, + InTitle, + InDate, InData }; State m_state; + QString m_title; + QDateTime m_date; ulong m_dataLenght; QString m_dataFormat; QList<Page> m_pages; }; DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() { m_state = Unknown; } DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() { } QList<Page> DrawPadCanvasXmlHandler::pages() { return m_pages; } bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) { Q_CONST_UNUSED(namespaceURI) Q_CONST_UNUSED(localName) - if (qName.compare("data") == 0) { + if (qName == "image") { + m_title = QString(); + m_date = QDateTime(QDate(1970, 1, 1)); + } else if (qName == "title") { + m_state = InTitle; + } else if (qName == "date") { + m_state = InDate; + } else if (qName == "data") { m_state = InData; m_dataLenght = atts.value("length").toULong(); m_dataFormat = atts.value("format"); if (m_dataFormat.isEmpty()) { m_dataFormat = "XPM"; } } return true; } bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName, const QString& qName) { Q_CONST_UNUSED(namespaceURI) Q_CONST_UNUSED(localName) - if (qName.compare("data") == 0) { + if (qName == "title") { + m_state = Unknown; + } else if (qName == "date") { + m_state = Unknown; + } else if (qName == "data") { m_state = Unknown; } return true; } -bool DrawPadCanvasXmlHandler::characters(const QString& ch) +bool DrawPadCanvasXmlHandler::characters(const QString& ch) { - if (m_state == InData) { + if (m_state == InTitle) { + m_title = ch; + } else if (m_state == InDate) { + m_date = m_date.addSecs(ch.toInt()); + } else if (m_state == InData) { QByteArray byteArray(ch.length() / 2); for (int i = 0; i < (int)ch.length() / 2; i++) { char h = ch[2 * i].latin1(); char l = ch[2 * i + 1].latin1(); uchar r = 0; if (h <= '9') { r += h - '0'; } else { r += h - 'a' + 10; } r = r << 4; if (l <= '9') { r += l - '0'; } else { r += l - 'a' + 10; } byteArray[i] = r; } QImage image; if (m_dataFormat == "XPM") { if (m_dataLenght < ch.length() * 5) { m_dataLenght = ch.length() * 5; } QByteArray byteArrayUnzipped(m_dataLenght); ::uncompress((uchar*)byteArrayUnzipped.data(), &m_dataLenght, (uchar*)byteArray.data(), byteArray.size()); image.loadFromData((const uchar*)byteArrayUnzipped.data(), m_dataLenght, m_dataFormat); } else { image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); } - Page* page = new Page(image.width(), image.height()); + Page* page = new Page(m_title, image.width(), image.height()); + page->setLastModified(m_date); page->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); m_pageBackups.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(contentsRect().size())); + m_pages.append(new Page("", contentsRect().size())); m_pages.current()->fill(Qt::white); } m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::initialPage() { - m_pages.append(new Page(236, 232)); + m_pages.append(new Page("", 236, 232)); m_pages.current()->fill(Qt::white); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } 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()->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; } @@ -320,113 +344,115 @@ uint DrawPadCanvas::pagePosition() { return (m_pages.at() + 1); } uint DrawPadCanvas::pageCount() { return m_pages.count(); } void DrawPadCanvas::selectPage(Page* page) { m_pages.findRef(page); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::backupPage() { - QPixmap* currentBackup = m_pageBackups.current(); + m_pages.current()->setLastModified(QDateTime::currentDateTime()); + + Page* currentBackup = m_pageBackups.current(); while (m_pageBackups.last() != currentBackup) { m_pageBackups.removeLast(); } while (m_pageBackups.count() >= (5 + 1)) { m_pageBackups.removeFirst(); } m_pageBackups.append(new Page(*(m_pages.current()))); emit pageBackupsChanged(); } void DrawPadCanvas::deleteAll() { m_pages.clear(); - m_pages.append(new Page(contentsRect().size())); + m_pages.append(new Page("", contentsRect().size())); m_pages.current()->fill(Qt::white); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } -void DrawPadCanvas::newPage(uint width, uint height, const QColor& color) +void DrawPadCanvas::newPage(QString title, uint width, uint height, const QColor& color) { - m_pages.insert(m_pages.at() + 1, new Page(width, height)); + m_pages.insert(m_pages.at() + 1, new Page(title, width, height)); m_pages.current()->fill(color); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::clearPage() { m_pages.current()->fill(Qt::white); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pageBackupsChanged(); } void DrawPadCanvas::deletePage() { m_pages.remove(m_pages.current()); if (m_pages.isEmpty()) { - m_pages.append(new Page(contentsRect().size())); + m_pages.append(new Page("", contentsRect().size())); m_pages.current()->fill(Qt::white); } m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::movePageUp() { int index = m_pages.at(); Page* page = m_pages.take(); m_pages.insert(index - 1, page); emit pagesChanged(); } void DrawPadCanvas::movePageDown() { 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 @@ -31,49 +31,49 @@ public: ~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); bool undoEnabled(); bool redoEnabled(); bool goPreviousPageEnabled(); bool goNextPageEnabled(); Page* currentPage(); QList<Page> pages(); uint pagePosition(); uint pageCount(); void selectPage(Page* page); void backupPage(); public slots: void deleteAll(); - void newPage(uint width, uint height, const QColor& color); + 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(); void pageBackupsChanged(); 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: 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 @@ -64,48 +64,53 @@ NewPageDialog::NewPageDialog(uint width, uint height, const QColor& penColor, generalLayout->addWidget(titleLabel, 0, 0); generalLayout->addWidget(m_pTitleLineEdit, 0, 1); sizeLayout->addWidget(widthLabel, 0, 0); sizeLayout->addWidget(heightLabel, 1, 0); sizeLayout->addWidget(m_pWidthSpinBox, 0, 1); sizeLayout->addWidget(m_pHeightSpinBox, 1, 1); sizeLayout->setColStretch(1, 1); contentLayout->addWidget(whiteColorRadioButton); contentLayout->addWidget(penColorRadioButton); contentLayout->addWidget(brushColorRadioButton); mainLayout->addWidget(generalGroupBox); mainLayout->addWidget(sizeGroupBox); mainLayout->addWidget(m_pContentButtonGroup); } NewPageDialog::~NewPageDialog() { } +QString NewPageDialog::selectedTitle() +{ + return (m_pTitleLineEdit->text()); +} + uint NewPageDialog::selectedWidth() { return (m_pWidthSpinBox->value()); } uint NewPageDialog::selectedHeight() { return (m_pHeightSpinBox->value()); } const QColor& NewPageDialog::selectedColor() { switch (m_pContentButtonGroup->id(m_pContentButtonGroup->selected())) { case 0: return (Qt::white); break; case 1: return (m_penColor); break; case 2: return (m_brushColor); break; default: return (Qt::white); 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 @@ -8,41 +8,42 @@ * 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 NEWPAGEDIALOG_H #define NEWPAGEDIALOG_H #include <qdialog.h> class QButtonGroup; class QLineEdit; class QSpinBox; class NewPageDialog : public QDialog { Q_OBJECT public: NewPageDialog(uint width, uint height, const QColor& foregroundColor, const QColor& backgroundColor, QWidget* parent = 0, const char* name = 0); ~NewPageDialog(); + QString selectedTitle(); uint selectedWidth(); uint selectedHeight(); const QColor& selectedColor(); private: QLineEdit* m_pTitleLineEdit; QSpinBox* m_pWidthSpinBox; QSpinBox* m_pHeightSpinBox; QColor m_penColor; QColor m_brushColor; QButtonGroup* m_pContentButtonGroup; }; #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,54 +1,56 @@ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include "page.h" Page::Page() : QPixmap() { m_lastModified = QDateTime::currentDateTime(); } -Page::Page(int w, int h) +Page::Page(QString title, int w, int h) : QPixmap(w, h) { + m_title = title; m_lastModified = QDateTime::currentDateTime(); } -Page::Page(const QSize& size) +Page::Page(QString title, const QSize& size) : QPixmap(size) { + m_title = title; m_lastModified = QDateTime::currentDateTime(); } Page::~Page() { } QString Page::title() const { return m_title; } QDateTime Page::lastModified() const { return m_lastModified; } void Page::setTitle(QString title) { m_title = title; } void Page::setLastModified(QDateTime lastModified) { 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 @@ /*************************************************************************** * * * 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 PAGE_H #define PAGE_H #include <qpixmap.h> #include <qdatetime.h> class Page : public QPixmap { public: Page(); - Page(int w, int h); - Page(const QSize& size); + Page(QString title, int w, int h); + Page(QString title, const QSize& size); ~Page(); QString title() const; QDateTime lastModified() const; void setTitle(QString title); void setLastModified(QDateTime lastModified); private: QString m_title; QDateTime m_lastModified; }; #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 @@ -300,50 +300,50 @@ void ThumbnailView::hide() if (inLoop) { inLoop = false; qApp->exit_loop(); } } void ThumbnailView::exec() { show(); if (!inLoop) { inLoop = true; qApp->enter_loop(); } } void ThumbnailView::newPage() { QRect rect = m_pDrawPadCanvas->contentsRect(); NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), m_pDrawPad->brush().color(), this); if (newPageDialog.exec() == QDialog::Accepted) { - m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(), - newPageDialog.selectedColor()); + m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), + newPageDialog.selectedHeight(), newPageDialog.selectedColor()); m_pPageListBox->updateView(); updateView(); } } void ThumbnailView::clearPage() { QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe selected page?"), QMessageBox::Information, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, QMessageBox::NoButton, this); messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); messageBox.setButtonText(QMessageBox::No, tr("No")); if (messageBox.exec() == QMessageBox::Yes) { m_pDrawPadCanvas->clearPage(); m_pPageListBox->updateView(); } } void ThumbnailView::deletePage() { QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), |