summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-07 20:30:30 (UTC)
committer leseb <leseb>2002-06-07 20:30:30 (UTC)
commit9dcd598f9b815511cae884d26b18e3c8913b9fcf (patch) (side-by-side diff)
tree4b18e7fa7c864b2dca4da76bc89c2a975e80a73c
parent640d964cfdc7467f6cacb513087cd3acda2c04f0 (diff)
downloadopie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.zip
opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.tar.gz
opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.tar.bz2
Make progress in thumbnail view
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp54
-rw-r--r--noncore/graphics/drawpad/drawpad.h4
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp75
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp196
-rw-r--r--noncore/graphics/drawpad/thumbnailview.h53
5 files changed, 262 insertions, 120 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
@@ -17,111 +17,112 @@
#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 "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)
: QMainWindow(parent, name)
{
// init members
m_pDrawPadCanvas = new DrawPadCanvas(this, this);
connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons()));
connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption()));
connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons()));
setCentralWidget(m_pDrawPadCanvas);
// init menu
setToolBarsMovable(false);
QPEToolBar* menuToolBar = new QPEToolBar(this);
QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar);
QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar);
QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this);
- connect(deleteAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deleteAll()));
+ 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);
menuBar->insertItem(tr("Tools"), toolsPopupMenu);
// init page toolbar
QPEToolBar* pageToolBar = new QPEToolBar(this);
QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this);
connect(newPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(newPage()));
newPageAction->addTo(pageToolBar);
QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
- connect(clearPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearPage()));
+ connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage()));
clearPageAction->addTo(pageToolBar);
QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this);
- connect(deletePageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(deletePage()));
+ connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
deletePageAction->addTo(pageToolBar);
QPEToolBar* emptyToolBar = new QPEToolBar(this);
emptyToolBar->setHorizontalStretchable(true);
// init navigation toolbar
QPEToolBar* navigationToolBar = new QPEToolBar(this);
m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("drawpad/undo"), QString::null, 0, this);
connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
m_pUndoAction->addTo(navigationToolBar);
m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("drawpad/redo"), QString::null, 0, this);
connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
m_pRedoAction->addTo(navigationToolBar);
m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this);
connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage()));
m_pFirstPageAction->addTo(navigationToolBar);
m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this);
connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage()));
m_pPreviousPageAction->addTo(navigationToolBar);
@@ -246,48 +247,78 @@ DrawPad::DrawPad(QWidget* parent, const char* name)
changeBrushColor(Qt::white);
// init pages
QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
if (file.open(IO_ReadOnly)) {
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::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);
+
+ messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
+ messageBox.setButtonText(QMessageBox::No, tr("No"));
+
+ if (messageBox.exec() == QMessageBox::Yes) {
+ m_pDrawPadCanvas->deletePage();
+ }
+}
+
void DrawPad::setPointTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new PointTool(this, m_pDrawPadCanvas);
m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet());
QToolTip::add(m_pLineToolButton, m_pPointToolAction->text());
disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0);
connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated()));
m_pLineToolButton->setOn(true);
m_pRectangleToolButton->setOn(false);
m_pEllipseToolButton->setOn(false);
m_pTextToolAction->setOn(false);
m_pFillToolAction->setOn(false);
m_pEraseToolAction->setOn(false);
}
void DrawPad::setLineTool()
{
@@ -478,59 +509,74 @@ void DrawPad::changeBrushColor(const QColor& color)
void DrawPad::updateUndoRedoToolButtons()
{
m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled());
m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled());
}
void DrawPad::updateNavigationToolButtons()
{
m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
}
void DrawPad::updateCaption()
{
uint pagePosition = m_pDrawPadCanvas->pagePosition();
uint pageCount = m_pDrawPadCanvas->pageCount();
setCaption(tr("DrawPad") + " - " + tr("Page") + " "
+ QString::number(pagePosition) + "/" + QString::number(pageCount));
}
+void DrawPad::deleteAll()
+{
+ QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"),
+ 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->deleteAll();
+ }
+}
+
void DrawPad::importPage()
{
ImportDialog importDialog(this);
importDialog.showMaximized();
if (importDialog.exec() == QDialog::Accepted) {
const DocLnk* docLnk = importDialog.selected();
if (docLnk) {
m_pDrawPadCanvas->importPage(docLnk->file());
delete docLnk;
}
}
}
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(m_pDrawPadCanvas->pages(), this);
+ ThumbnailView thumbnailView(m_pDrawPadCanvas, this);
thumbnailView.showMaximized();
thumbnailView.exec();
}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index b0b3666..01061b4 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -18,66 +18,70 @@
#include <qpen.h>
class DrawPadCanvas;
class Tool;
class QAction;
class QColor;
class QToolButton;
class QWidgetStack;
class DrawPad : public QMainWindow
{
Q_OBJECT
public:
DrawPad(QWidget* parent = 0, const char* name = 0);
~DrawPad();
Tool* tool() { return m_pTool; }
QPen pen() { return m_pen; }
QBrush brush() { return m_brush; }
private slots:
+ void clearPage();
+ void deletePage();
+
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 updateUndoRedoToolButtons();
void updateNavigationToolButtons();
void updateCaption();
+ void deleteAll();
void importPage();
void exportPage();
void thumbnailView();
private:
DrawPadCanvas* m_pDrawPadCanvas;
Tool* m_pTool;
QPen m_pen;
QBrush m_brush;
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;
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 79bef35..252f4d5 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -3,49 +3,48 @@
* 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 "drawpadcanvas.h"
#include "drawpad.h"
#include "newpagedialog.h"
#include "page.h"
#include "tool.h"
#include <qpe/applnk.h>
#include <qpe/filemanager.h>
#include <qpe/mimetype.h>
#include <qbuffer.h>
#include <qimage.h>
-#include <qmessagebox.h>
#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,
@@ -325,140 +324,110 @@ uint DrawPadCanvas::pagePosition()
uint DrawPadCanvas::pageCount()
{
return m_pages.count();
}
void DrawPadCanvas::backupPage()
{
QPixmap* 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()
{
- QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"),
- QMessageBox::Information, QMessageBox::Yes,
- QMessageBox::No | QMessageBox::Escape | QMessageBox::Default,
- QMessageBox::NoButton, this);
+ m_pages.clear();
- messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
- messageBox.setButtonText(QMessageBox::No, tr("No"));
-
- if (messageBox.exec() == QMessageBox::Yes) {
- m_pages.clear();
-
- m_pages.append(new Page(contentsRect().size()));
- m_pages.current()->fill(Qt::white);
+ m_pages.append(new Page(contentsRect().size()));
+ m_pages.current()->fill(Qt::white);
- m_pageBackups.clear();
- m_pageBackups.append(new Page(*(m_pages.current())));
+ m_pageBackups.clear();
+ m_pageBackups.append(new Page(*(m_pages.current())));
- resizeContents(m_pages.current()->width(), m_pages.current()->height());
- viewport()->update();
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
- emit pagesChanged();
- emit pageBackupsChanged();
- }
+ emit pagesChanged();
+ emit pageBackupsChanged();
}
void DrawPadCanvas::newPage()
{
QRect rect = contentsRect();
NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(),
m_pDrawPad->brush().color(), this);
if (newPageDialog.exec() == QDialog::Accepted) {
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 Page(*(m_pages.current())));
resizeContents(m_pages.current()->width(), m_pages.current()->height());
viewport()->update();
emit pagesChanged();
emit pageBackupsChanged();
}
}
void DrawPadCanvas::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_pages.current()->fill(Qt::white);
+ m_pages.current()->fill(Qt::white);
- viewport()->update();
- }
+ viewport()->update();
}
void DrawPadCanvas::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);
-
- messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
- messageBox.setButtonText(QMessageBox::No, tr("No"));
+ m_pages.remove(m_pages.current());
- if (messageBox.exec() == QMessageBox::Yes) {
- m_pages.remove(m_pages.current());
-
- if (m_pages.isEmpty()) {
- m_pages.append(new Page(contentsRect().size()));
- m_pages.current()->fill(Qt::white);
- }
+ if (m_pages.isEmpty()) {
+ m_pages.append(new Page(contentsRect().size()));
+ m_pages.current()->fill(Qt::white);
+ }
- m_pageBackups.clear();
- m_pageBackups.append(new Page(*(m_pages.current())));
+ m_pageBackups.clear();
+ m_pageBackups.append(new Page(*(m_pages.current())));
- resizeContents(m_pages.current()->width(), m_pages.current()->height());
- viewport()->update();
+ resizeContents(m_pages.current()->width(), m_pages.current()->height());
+ viewport()->update();
- emit pagesChanged();
- emit pageBackupsChanged();
- }
+ emit pagesChanged();
+ emit pageBackupsChanged();
}
bool DrawPadCanvas::undoEnabled()
{
return (m_pageBackups.current() != m_pageBackups.getFirst());
}
bool DrawPadCanvas::redoEnabled()
{
return (m_pageBackups.current() != m_pageBackups.getLast());
}
bool DrawPadCanvas::goPreviousPageEnabled()
{
return (m_pages.current() != m_pages.getFirst());
}
bool DrawPadCanvas::goNextPageEnabled()
{
return (m_pages.current() != m_pages.getLast());
}
void DrawPadCanvas::undo()
{
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 10ade90..1754ce9 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -1,121 +1,211 @@
/***************************************************************************
* *
* 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 "thumbnailview.h"
+#include "drawpadcanvas.h"
#include "page.h"
#include <qpe/resource.h>
+#include <qapplication.h>
#include <qheader.h>
#include <qimage.h>
#include <qlayout.h>
-#include <qlistview.h>
+#include <qmessagebox.h>
#include <qtoolbutton.h>
-ThumbnailView::ThumbnailView(QList<Page> pages, QWidget* parent, const char* name)
- : QDialog(parent, name, true)
+PageListViewItem::PageListViewItem(Page* page, QListView* parent)
+ : QListViewItem(parent)
{
- setCaption(tr("Thumbnail"));
+ m_pPage = page;
- QToolButton* newPageButton = new QToolButton(this);
- newPageButton->setIconSet(Resource::loadIconSet("new"));
- newPageButton->setAutoRaise(true);
+ QImage image = m_pPage->convertToImage();
- QToolButton* clearPageButton = new QToolButton(this);
- clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear"));
- clearPageButton->setAutoRaise(true);
+ int previewWidth = 64;
+ int previewHeight = 64;
- QToolButton* deletePageButton = new QToolButton(this);
- deletePageButton->setIconSet(Resource::loadIconSet("trash"));
- deletePageButton->setAutoRaise(true);
+ float widthScale = 1.0;
+ float heightScale = 1.0;
- QToolButton* movePageUpButton = new QToolButton(this);
- movePageUpButton->setIconSet(Resource::loadIconSet("up"));
- movePageUpButton->setAutoRaise(true);
+ if (previewWidth < image.width()) {
+ widthScale = (float)previewWidth / float(image.width());
+ }
- QToolButton* movePageDownButton = new QToolButton(this);
- movePageDownButton->setIconSet(Resource::loadIconSet("down"));
- movePageDownButton->setAutoRaise(true);
+ 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);
- m_pListView = new QListView(this);
+ QPixmap pixmap(64, 64);
- m_pListView->header()->hide();
- m_pListView->setAllColumnsShowFocus(true);
+ pixmap.fill(listView()->colorGroup().mid());
+ bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2,
+ (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap);
- m_pListView->addColumn(tr("Thumbnail"));
- m_pListView->addColumn(tr("Information"));
+ setPixmap(0, pixmap);
+}
- m_pListView->setColumnAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter);
- m_pListView->setColumnAlignment(1, Qt::AlignTop);
+PageListViewItem::~PageListViewItem()
+{
+}
+
+Page* PageListViewItem::page() const
+{
+ return m_pPage;
+}
- QListIterator<Page> iterator(pages);
+PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
+ : QListView(parent, name)
+{
+ m_pDrawPadCanvas = drawPadCanvas;
- for (; iterator.current(); ++iterator) {
- QImage image = iterator.current()->convertToImage();
+ header()->hide();
+ setVScrollBarMode(QScrollView::AlwaysOn);
+ setAllColumnsShowFocus(true);
- int previewWidth = 64;
- int previewHeight = 64;
+ addColumn(tr("Thumbnail"));
+ addColumn(tr("Information"));
- float widthScale = 1.0;
- float heightScale = 1.0;
+ updateView();
+}
- if (previewWidth < image.width()) {
- widthScale = (float)previewWidth / float(image.width());
- }
+PageListView::~PageListView()
+{
+}
+
+void PageListView::updateView()
+{
+ clear();
- if (previewHeight < image.height()) {
- heightScale = (float)previewHeight / float(image.height());
+ if (m_pDrawPadCanvas) {
+ QList<Page> pageList = m_pDrawPadCanvas->pages();
+ QListIterator<Page> it(pageList);
+
+ for (; it.current(); ++it) {
+ new PageListViewItem(it.current(), this);
}
+ }
+}
- float scale = (widthScale < heightScale ? widthScale : heightScale);
- QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
+void PageListView::resizeEvent(QResizeEvent* e)
+{
+ Q_UNUSED(e);
- QPixmap previewPixmap;
- previewPixmap.convertFromImage(previewImage);
+ setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width());
+}
- QPixmap pixmap(64, 64);
+Page* PageListView::selected() const
+{
+ Page* page;
- pixmap.fill(colorGroup().mid());
- bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2,
- (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap);
+ PageListViewItem* item = (PageListViewItem*)selectedItem();
- QListViewItem* item = new QListViewItem(m_pListView);
- item->setPixmap(0, pixmap);
+ if (item) {
+ page = item->page();
+ } else {
+ page = NULL;
}
+ return page;
+}
+
+
+ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
+ : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel)
+{
+ inLoop = false;
+ m_pDrawPadCanvas = drawPadCanvas;
+
+ 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_pPageListView = new PageListView(m_pDrawPadCanvas, this);
+
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);
+ mainLayout->addWidget(m_pPageListView);
}
ThumbnailView::~ThumbnailView()
{
+ hide();
}
-void ThumbnailView::resizeEvent(QResizeEvent* e)
+void ThumbnailView::hide()
{
- QDialog::resizeEvent(e);
+ QWidget::hide();
+
+ if (inLoop) {
+ inLoop = false;
+ qApp->exit_loop();
+ }
+}
- m_pListView->setColumnWidth(1, m_pListView->contentsRect().width() - m_pListView->columnWidth(0)
- - m_pListView->verticalScrollBar()->width());
+void ThumbnailView::exec()
+{
+ show();
+
+ if (!inLoop) {
+ inLoop = true;
+ qApp->enter_loop();
+ }
+}
+
+void ThumbnailView::deletePage()
+{
+ QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\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->deletePage();
+ }
}
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h
index c74730d..ae97ff1 100644
--- a/noncore/graphics/drawpad/thumbnailview.h
+++ b/noncore/graphics/drawpad/thumbnailview.h
@@ -1,40 +1,73 @@
/***************************************************************************
* *
* 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 THUMBNAILVIEW_H
#define THUMBNAILVIEW_H
-#include <qdialog.h>
+#include <qwidget.h>
+#include <qlistview.h>
-#include <qlist.h>
+class DrawPadCanvas;
+class Page;
-class QListView;
+class PageListViewItem : public QListViewItem
+{
+public:
+ PageListViewItem(Page* page, QListView* parent);
+ ~PageListViewItem();
-class Page;
+ Page* page() const;
-class ThumbnailView : public QDialog
-{
- Q_OBJECT
+private:
+ Page* m_pPage;
+};
+class PageListView : public QListView
+{
public:
- ThumbnailView(QList<Page> pages, QWidget* parent = 0, const char* name = 0);
- ~ThumbnailView();
+ PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
+ ~PageListView();
+
+ void updateView();
+
+ Page* selected() const;
protected:
void resizeEvent(QResizeEvent* e);
private:
- QListView* m_pListView;
+ DrawPadCanvas* m_pDrawPadCanvas;
+};
+
+class ThumbnailView : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
+ ~ThumbnailView();
+
+ void hide();
+ void exec();
+
+public slots:
+ void deletePage();
+
+private:
+ bool inLoop;
+ DrawPadCanvas* m_pDrawPadCanvas;
+
+ PageListView* m_pPageListView;
};
#endif // THUMBNAILVIEW_H