From 43bde653ce03f4c5202860f4e23c7612144a38f0 Mon Sep 17 00:00:00 2001 From: leseb Date: Thu, 06 Jun 2002 20:51:27 +0000 Subject: New page class, thumbnail view draft --- (limited to 'noncore') diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 74787e5..b325323 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp @@ -25,6 +25,7 @@ #include "pointtool.h" #include "rectangletool.h" #include "texttool.h" +#include "thumbnailview.h" #include #include @@ -78,6 +79,12 @@ DrawPad::DrawPad(QWidget* parent, const char* name) 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); + menuBar->insertItem(tr("Tools"), toolsPopupMenu); // init page toolbar @@ -519,3 +526,11 @@ void DrawPad::exportPage() exportDialog.selectedName(), exportDialog.selectedFormat()); } } + +void DrawPad::thumbnailView() +{ + ThumbnailView thumbnailView(m_pDrawPadCanvas->pages(), this); + + thumbnailView.showMaximized(); + thumbnailView.exec(); +} diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index 0dcd5c9..b0b3666 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h @@ -59,6 +59,7 @@ private slots: void importPage(); void exportPage(); + void thumbnailView(); private: DrawPadCanvas* m_pDrawPadCanvas; diff --git a/noncore/graphics/drawpad/drawpad.pro b/noncore/graphics/drawpad/drawpad.pro index 9360256..9a640d2 100644 --- a/noncore/graphics/drawpad/drawpad.pro +++ b/noncore/graphics/drawpad/drawpad.pro @@ -11,10 +11,12 @@ HEADERS = drawpad.h \ importdialog.h \ linetool.h \ newpagedialog.h \ + page.h \ pointtool.h \ rectangletool.h \ shapetool.h \ texttool.h \ + thumbnailview.h \ tool.h SOURCES = drawpad.cpp \ drawpadcanvas.cpp \ @@ -28,10 +30,12 @@ SOURCES = drawpad.cpp \ linetool.cpp \ main.cpp \ newpagedialog.cpp \ + page.cpp \ pointtool.cpp \ rectangletool.cpp \ shapetool.cpp \ texttool.cpp \ + thumbnailview.cpp \ tool.cpp INCLUDEPATH += $(OPIEDIR)/include \ $(QTDIR)/src/3rdparty/zlib diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 9f1e50b..79bef35 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp @@ -15,6 +15,7 @@ #include "drawpad.h" #include "newpagedialog.h" +#include "page.h" #include "tool.h" #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -38,7 +38,7 @@ public: DrawPadCanvasXmlHandler(); ~DrawPadCanvasXmlHandler(); - QList pixmaps(); + QList pages(); bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts); @@ -55,7 +55,7 @@ private: State m_state; ulong m_dataLenght; QString m_dataFormat; - QList m_pixmaps; + QList m_pages; }; DrawPadCanvasXmlHandler::DrawPadCanvasXmlHandler() @@ -67,9 +67,9 @@ DrawPadCanvasXmlHandler::~DrawPadCanvasXmlHandler() { } -QList DrawPadCanvasXmlHandler::pixmaps() +QList DrawPadCanvasXmlHandler::pages() { - return m_pixmaps; + return m_pages; } bool DrawPadCanvasXmlHandler::startElement(const QString& namespaceURI, const QString& localName, @@ -147,9 +147,9 @@ bool DrawPadCanvasXmlHandler::characters(const QString& ch) image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat); } - QPixmap* pixmap = new QPixmap(image.width(), image.height()); - pixmap->convertFromImage(image); - m_pixmaps.append(pixmap); + Page* page = new Page(image.width(), image.height()); + page->convertFromImage(image); + m_pages.append(page); } return true; @@ -181,15 +181,15 @@ void DrawPadCanvas::load(QIODevice* ioDevice) xmlSimpleReader.setContentHandler(&drawPadCanvasXmlHandler); xmlSimpleReader.parse(xmlInputSource); - m_pages = drawPadCanvasXmlHandler.pixmaps(); + m_pages = drawPadCanvasXmlHandler.pages(); if (m_pages.isEmpty()) { - m_pages.append(new QPixmap(contentsRect().size())); + m_pages.append(new Page(contentsRect().size())); m_pages.current()->fill(Qt::white); } m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -200,11 +200,11 @@ void DrawPadCanvas::load(QIODevice* ioDevice) void DrawPadCanvas::initialPage() { - m_pages.append(new QPixmap(236, 232)); + m_pages.append(new Page(236, 232)); m_pages.current()->fill(Qt::white); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -221,7 +221,7 @@ void DrawPadCanvas::save(QIODevice* ioDevice) textStream << "" << endl; textStream << " " << endl; - QListIterator bufferIterator(m_pages); + QListIterator bufferIterator(m_pages); for (bufferIterator.toFirst(); bufferIterator.current() != 0; ++bufferIterator) { textStream << " " << endl; @@ -256,13 +256,13 @@ void DrawPadCanvas::save(QIODevice* ioDevice) void DrawPadCanvas::importPage(const QString& fileName) { - QPixmap* importedPixmap = new QPixmap(); + Page* importedPage = new Page(); - importedPixmap->load(fileName); - m_pages.insert(m_pages.at() + 1, importedPixmap); + importedPage->load(fileName); + m_pages.insert(m_pages.at() + 1, importedPage); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -308,12 +308,12 @@ void DrawPadCanvas::exportPage(uint fromPage, uint toPage, const QString& name,c } } -QPixmap* DrawPadCanvas::currentPage() +Page* DrawPadCanvas::currentPage() { return m_pages.current(); } -QList DrawPadCanvas::pages() +QList DrawPadCanvas::pages() { return m_pages; } @@ -339,7 +339,7 @@ void DrawPadCanvas::backupPage() m_pageBackups.removeFirst(); } - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); emit pageBackupsChanged(); } @@ -357,11 +357,11 @@ void DrawPadCanvas::deleteAll() if (messageBox.exec() == QMessageBox::Yes) { m_pages.clear(); - m_pages.append(new QPixmap(contentsRect().size())); + m_pages.append(new Page(contentsRect().size())); m_pages.current()->fill(Qt::white); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -379,12 +379,12 @@ void DrawPadCanvas::newPage() m_pDrawPad->brush().color(), this); if (newPageDialog.exec() == QDialog::Accepted) { - m_pages.insert(m_pages.at() + 1, new QPixmap(newPageDialog.selectedWidth(), - newPageDialog.selectedHeight())); + m_pages.insert(m_pages.at() + 1, new Page(newPageDialog.selectedWidth(), + newPageDialog.selectedHeight())); m_pages.current()->fill(newPageDialog.selectedColor()); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -425,12 +425,12 @@ void DrawPadCanvas::deletePage() m_pages.remove(m_pages.current()); if (m_pages.isEmpty()) { - m_pages.append(new QPixmap(contentsRect().size())); + m_pages.append(new Page(contentsRect().size())); m_pages.current()->fill(Qt::white); } m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -482,7 +482,7 @@ void DrawPadCanvas::goFirstPage() { m_pages.first(); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -495,7 +495,7 @@ void DrawPadCanvas::goPreviousPage() { m_pages.prev(); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -508,7 +508,7 @@ void DrawPadCanvas::goNextPage() { m_pages.next(); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); @@ -521,7 +521,7 @@ void DrawPadCanvas::goLastPage() { m_pages.last(); m_pageBackups.clear(); - m_pageBackups.append(new QPixmap(*(m_pages.current()))); + m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index e05ce8a..47763f9 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h @@ -20,8 +20,7 @@ #include class DrawPad; - -class QPixmap; +class Page; class DrawPadCanvas : public QScrollView { @@ -43,8 +42,8 @@ public: bool goPreviousPageEnabled(); bool goNextPageEnabled(); - QPixmap* currentPage(); - QList pages(); + Page* currentPage(); + QList pages(); uint pagePosition(); uint pageCount(); @@ -76,8 +75,8 @@ protected: private: DrawPad* m_pDrawPad; - QList m_pages; - QList m_pageBackups; + QList m_pages; + QList m_pageBackups; }; #endif // DRAWPADCANVAS_H diff --git a/noncore/graphics/drawpad/erasetool.cpp b/noncore/graphics/drawpad/erasetool.cpp index 828994b..f77e038 100644 --- a/noncore/graphics/drawpad/erasetool.cpp +++ b/noncore/graphics/drawpad/erasetool.cpp @@ -15,9 +15,9 @@ #include "drawpad.h" #include "drawpadcanvas.h" +#include "page.h" #include -#include EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : Tool(drawPad, drawPadCanvas) diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp index 004da02..d323cc2 100644 --- a/noncore/graphics/drawpad/filltool.cpp +++ b/noncore/graphics/drawpad/filltool.cpp @@ -15,9 +15,9 @@ #include "drawpad.h" #include "drawpadcanvas.h" +#include "page.h" #include -#include FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : Tool(drawPad, drawPadCanvas) diff --git a/noncore/graphics/drawpad/page.cpp b/noncore/graphics/drawpad/page.cpp new file mode 100644 index 0000000..35ec0e0 --- a/dev/null +++ b/noncore/graphics/drawpad/page.cpp @@ -0,0 +1,33 @@ +/*************************************************************************** + * * + * DrawPad - a drawing program for Opie Environment * + * * + * (C) 2002 by S. Prud'homme * + * * + * 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() +{ +} + +Page::Page(int w, int h) + : QPixmap(w, h) +{ +} + +Page::Page(const QSize& size) + : QPixmap(size) +{ +} + +Page::~Page() +{ +} diff --git a/noncore/graphics/drawpad/page.h b/noncore/graphics/drawpad/page.h new file mode 100644 index 0000000..888f552 --- a/dev/null +++ b/noncore/graphics/drawpad/page.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * * + * DrawPad - a drawing program for Opie Environment * + * * + * (C) 2002 by S. Prud'homme * + * * + * 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 + +class Page : public QPixmap +{ +public: + Page(); + Page(int w, int h); + Page(const QSize& size); + + ~Page(); +}; + +#endif // PAGE_H diff --git a/noncore/graphics/drawpad/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp index e281284..656044b 100644 --- a/noncore/graphics/drawpad/pointtool.cpp +++ b/noncore/graphics/drawpad/pointtool.cpp @@ -15,9 +15,9 @@ #include "drawpad.h" #include "drawpadcanvas.h" +#include "page.h" #include -#include PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : Tool(drawPad, drawPadCanvas) diff --git a/noncore/graphics/drawpad/shapetool.cpp b/noncore/graphics/drawpad/shapetool.cpp index bc5d9c0..8870a78 100644 --- a/noncore/graphics/drawpad/shapetool.cpp +++ b/noncore/graphics/drawpad/shapetool.cpp @@ -15,9 +15,9 @@ #include "drawpad.h" #include "drawpadcanvas.h" +#include "page.h" #include -#include ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : Tool(drawPad, drawPadCanvas) diff --git a/noncore/graphics/drawpad/texttool.cpp b/noncore/graphics/drawpad/texttool.cpp index 37b4801..34c8a76 100644 --- a/noncore/graphics/drawpad/texttool.cpp +++ b/noncore/graphics/drawpad/texttool.cpp @@ -15,11 +15,11 @@ #include "drawpad.h" #include "drawpadcanvas.h" +#include "page.h" #include #include #include -#include TextToolDialog::TextToolDialog(QWidget* parent, const char* name) : QDialog(parent, name, true) diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp new file mode 100644 index 0000000..10ade90 --- a/dev/null +++ b/noncore/graphics/drawpad/thumbnailview.cpp @@ -0,0 +1,121 @@ +/*************************************************************************** + * * + * DrawPad - a drawing program for Opie Environment * + * * + * (C) 2002 by S. Prud'homme * + * * + * 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 "thumbnailview.h" + +#include "page.h" + +#include + +#include +#include +#include +#include +#include + +ThumbnailView::ThumbnailView(QList pages, QWidget* parent, const char* name) + : QDialog(parent, name, true) +{ + setCaption(tr("Thumbnail")); + + QToolButton* newPageButton = new QToolButton(this); + newPageButton->setIconSet(Resource::loadIconSet("new")); + newPageButton->setAutoRaise(true); + + QToolButton* clearPageButton = new QToolButton(this); + clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); + clearPageButton->setAutoRaise(true); + + QToolButton* deletePageButton = new QToolButton(this); + deletePageButton->setIconSet(Resource::loadIconSet("trash")); + deletePageButton->setAutoRaise(true); + + QToolButton* movePageUpButton = new QToolButton(this); + movePageUpButton->setIconSet(Resource::loadIconSet("up")); + movePageUpButton->setAutoRaise(true); + + QToolButton* movePageDownButton = new QToolButton(this); + movePageDownButton->setIconSet(Resource::loadIconSet("down")); + movePageDownButton->setAutoRaise(true); + + m_pListView = new QListView(this); + + m_pListView->header()->hide(); + m_pListView->setAllColumnsShowFocus(true); + + m_pListView->addColumn(tr("Thumbnail")); + m_pListView->addColumn(tr("Information")); + + m_pListView->setColumnAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter); + m_pListView->setColumnAlignment(1, Qt::AlignTop); + + QListIterator iterator(pages); + + for (; iterator.current(); ++iterator) { + QImage image = iterator.current()->convertToImage(); + + int previewWidth = 64; + int previewHeight = 64; + + float widthScale = 1.0; + float heightScale = 1.0; + + if (previewWidth < image.width()) { + widthScale = (float)previewWidth / float(image.width()); + } + + if (previewHeight < image.height()) { + heightScale = (float)previewHeight / float(image.height()); + } + + float scale = (widthScale < heightScale ? widthScale : heightScale); + QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); + + QPixmap previewPixmap; + previewPixmap.convertFromImage(previewImage); + + QPixmap pixmap(64, 64); + + pixmap.fill(colorGroup().mid()); + bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, + (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); + + QListViewItem* item = new QListViewItem(m_pListView); + item->setPixmap(0, pixmap); + } + + QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); + QHBoxLayout* buttonLayout = new QHBoxLayout(0); + + buttonLayout->addWidget(newPageButton); + buttonLayout->addWidget(clearPageButton); + buttonLayout->addWidget(deletePageButton); + buttonLayout->addStretch(); + buttonLayout->addWidget(movePageUpButton); + buttonLayout->addWidget(movePageDownButton); + + mainLayout->addLayout(buttonLayout); + mainLayout->addWidget(m_pListView); +} + +ThumbnailView::~ThumbnailView() +{ +} + +void ThumbnailView::resizeEvent(QResizeEvent* e) +{ + QDialog::resizeEvent(e); + + m_pListView->setColumnWidth(1, m_pListView->contentsRect().width() - m_pListView->columnWidth(0) + - m_pListView->verticalScrollBar()->width()); +} diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h new file mode 100644 index 0000000..c74730d --- a/dev/null +++ b/noncore/graphics/drawpad/thumbnailview.h @@ -0,0 +1,40 @@ +/*************************************************************************** + * * + * DrawPad - a drawing program for Opie Environment * + * * + * (C) 2002 by S. Prud'homme * + * * + * 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 THUMBNAILVIEW_H +#define THUMBNAILVIEW_H + +#include + +#include + +class QListView; + +class Page; + +class ThumbnailView : public QDialog +{ + Q_OBJECT + +public: + ThumbnailView(QList pages, QWidget* parent = 0, const char* name = 0); + ~ThumbnailView(); + +protected: + void resizeEvent(QResizeEvent* e); + +private: + QListView* m_pListView; +}; + +#endif // THUMBNAILVIEW_H -- cgit v0.9.0.2