summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp17
-rw-r--r--noncore/graphics/drawpad/drawpad.h1
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp33
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h2
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp38
-rw-r--r--noncore/graphics/drawpad/thumbnailview.h7
6 files changed, 75 insertions, 23 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index 58c0d09..ef55268 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -1,48 +1,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 "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)
@@ -72,49 +73,49 @@ DrawPad::DrawPad(QWidget* parent, const char* name)
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()));
+ connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
newPageAction->addTo(pageToolBar);
QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this);
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()), 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);
@@ -247,48 +248,60 @@ 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::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());
+ }
+}
+
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"));
@@ -554,29 +567,29 @@ void DrawPad::importPage()
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, this);
+ ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this);
thumbnailView.showMaximized();
thumbnailView.exec();
}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index 01061b4..9a821f6 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -18,48 +18,49 @@
#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 newPage();
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();
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 0a1e9a5..c23ee34 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -1,41 +1,40 @@
/***************************************************************************
* *
* 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 <qpainter.h>
#include <qtextcodec.h>
#include <qtextstream.h>
#include <qxml.h>
#include <zlib.h>
class DrawPadCanvasXmlHandler: public QXmlDefaultHandler
{
public:
DrawPadCanvasXmlHandler();
~DrawPadCanvasXmlHandler();
QList<Page> pages();
@@ -352,76 +351,74 @@ void DrawPadCanvas::backupPage()
}
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.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()
+void DrawPadCanvas::newPage(uint width, uint height, const QColor& color)
{
- QRect rect = contentsRect();
+ m_pages.insert(m_pages.at() + 1, new Page(width, height));
+ m_pages.current()->fill(color);
- 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())));
+ 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::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.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();
}
bool DrawPadCanvas::undoEnabled()
{
return (m_pageBackups.current() != m_pageBackups.getFirst());
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index cf2d904..d74d425 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();
+ void newPage(uint width, uint height, const QColor& color);
void clearPage();
void deletePage();
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:
DrawPad* m_pDrawPad;
QList<Page> m_pages;
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 476b7b9..08e106d 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -1,40 +1,42 @@
/***************************************************************************
* *
* 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 "drawpad.h"
#include "drawpadcanvas.h"
+#include "newpagedialog.h"
#include "page.h"
#include <qpe/resource.h>
#include <qapplication.h>
#include <qheader.h>
#include <qimage.h>
#include <qlayout.h>
#include <qmessagebox.h>
#include <qtoolbutton.h>
PageListViewItem::PageListViewItem(Page* page, QListView* parent)
: QListViewItem(parent)
{
m_pPage = page;
QImage image = m_pPage->convertToImage();
int previewWidth = 64;
int previewHeight = 64;
float widthScale = 1.0;
float heightScale = 1.0;
@@ -122,63 +124,67 @@ void PageListView::select(Page* page)
setSelected(item, true);
ensureItemVisible(item);
break;
}
item = (PageListViewItem*)(item->nextSibling());
}
}
Page* PageListView::selected() const
{
Page* page;
PageListViewItem* item = (PageListViewItem*)selectedItem();
if (item) {
page = item->page();
} else {
page = NULL;
}
return page;
}
-ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
+ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
: QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel)
{
inLoop = false;
+
+ m_pDrawPad = drawPad;
m_pDrawPadCanvas = drawPadCanvas;
setCaption(tr("Thumbnail"));
QToolButton* newPageButton = new QToolButton(this);
newPageButton->setIconSet(Resource::loadIconSet("new"));
newPageButton->setAutoRaise(true);
+ connect(newPageButton, SIGNAL(clicked()), this, SLOT(newPage()));
QToolButton* clearPageButton = new QToolButton(this);
clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear"));
clearPageButton->setAutoRaise(true);
+ connect(clearPageButton, SIGNAL(clicked()), this, SLOT(clearPage()));
QToolButton* deletePageButton = new QToolButton(this);
deletePageButton->setIconSet(Resource::loadIconSet("trash"));
deletePageButton->setAutoRaise(true);
connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage()));
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);
connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage()));
QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
QHBoxLayout* buttonLayout = new QHBoxLayout(0);
buttonLayout->addWidget(newPageButton);
buttonLayout->addWidget(clearPageButton);
buttonLayout->addWidget(deletePageButton);
buttonLayout->addStretch();
@@ -193,44 +199,74 @@ ThumbnailView::~ThumbnailView()
{
hide();
}
void ThumbnailView::hide()
{
QWidget::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_pPageListView->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_pPageListView->updateView();
+ }
+}
+
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();
m_pPageListView->updateView();
}
}
void ThumbnailView::changePage()
{
m_pDrawPadCanvas->selectPage(m_pPageListView->selected());
}
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h
index 9417655..1fdb168 100644
--- a/noncore/graphics/drawpad/thumbnailview.h
+++ b/noncore/graphics/drawpad/thumbnailview.h
@@ -1,75 +1,80 @@
/***************************************************************************
* *
* 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 <qwidget.h>
#include <qlistview.h>
+class DrawPad;
class DrawPadCanvas;
class Page;
class PageListViewItem : public QListViewItem
{
public:
PageListViewItem(Page* page, QListView* parent);
~PageListViewItem();
Page* page() const;
private:
Page* m_pPage;
};
class PageListView : public QListView
{
public:
PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
~PageListView();
void updateView();
void select(Page* page);
Page* selected() const;
protected:
void resizeEvent(QResizeEvent* e);
private:
DrawPadCanvas* m_pDrawPadCanvas;
};
class ThumbnailView : public QWidget
{
Q_OBJECT
public:
- ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
+ ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
~ThumbnailView();
void hide();
void exec();
public slots:
+ void newPage();
+ void clearPage();
void deletePage();
void changePage();
private:
bool inLoop;
+
+ DrawPad* m_pDrawPad;
DrawPadCanvas* m_pDrawPadCanvas;
PageListView* m_pPageListView;
};
#endif // THUMBNAILVIEW_H