summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-14 15:13:02 (UTC)
committer leseb <leseb>2002-06-14 15:13:02 (UTC)
commit4898376fe38510a7cd54d24485860a3fa7187ad3 (patch) (side-by-side diff)
treee8d0fe758cc3ce655074713103ea00cf96bac43b
parentf1d0fd5330f4e6a8313cd8e5dcdb5e843805ae3f (diff)
downloadopie-4898376fe38510a7cd54d24485860a3fa7187ad3.zip
opie-4898376fe38510a7cd54d24485860a3fa7187ad3.tar.gz
opie-4898376fe38510a7cd54d24485860a3fa7187ad3.tar.bz2
Page attributes works!!!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp6
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp50
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h2
-rw-r--r--noncore/graphics/drawpad/newpagedialog.cpp5
-rw-r--r--noncore/graphics/drawpad/newpagedialog.h1
-rw-r--r--noncore/graphics/drawpad/page.cpp6
-rw-r--r--noncore/graphics/drawpad/page.h4
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp4
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
@@ -1,608 +1,610 @@
/***************************************************************************
* *
* 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)
: 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()), 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);
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()), 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);
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);
m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this);
connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage()));
m_pNextPageAction->addTo(navigationToolBar);
m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this);
connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage()));
m_pLastPageAction->addTo(navigationToolBar);
// init draw mode toolbar
QPEToolBar* drawModeToolBar = new QPEToolBar(this);
m_pLineToolButton = new QToolButton(drawModeToolBar);
m_pLineToolButton->setToggleButton(true);
QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton);
m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadIconSet("drawpad/point.png"), "", 0, this);
connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool()));
m_pPointToolAction->addTo(linePopupMenu);
m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadIconSet("drawpad/line.png"), "", 0, this);
connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool()));
m_pLineToolAction->addTo(linePopupMenu);
m_pLineToolButton->setPopup(linePopupMenu);
m_pLineToolButton->setPopupDelay(0);
m_pRectangleToolButton = new QToolButton(drawModeToolBar);
m_pRectangleToolButton->setToggleButton(true);
QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton);
m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadIconSet("drawpad/rectangle.png"), "", 0, this);
connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool()));
m_pRectangleToolAction->addTo(rectanglePopupMenu);
m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadIconSet("drawpad/filledrectangle.png"), "", 0, this);
connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool()));
m_pFilledRectangleToolAction->addTo(rectanglePopupMenu);
m_pRectangleToolButton->setPopup(rectanglePopupMenu);
m_pRectangleToolButton->setPopupDelay(0);
m_pEllipseToolButton = new QToolButton(drawModeToolBar);
m_pEllipseToolButton->setToggleButton(true);
QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton);
m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadIconSet("drawpad/ellipse.png"), "", 0, this);
connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool()));
m_pEllipseToolAction->addTo(ellipsePopupMenu);
m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadIconSet("drawpad/filledellipse.png"), "", 0, this);
connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool()));
m_pFilledEllipseToolAction->addTo(ellipsePopupMenu);
m_pEllipseToolButton->setPopup(ellipsePopupMenu);
m_pEllipseToolButton->setPopupDelay(0);
m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadIconSet("drawpad/text.png"), QString::null, 0, this);
m_pTextToolAction->setToggleAction(true);
connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool()));
m_pTextToolAction->addTo(drawModeToolBar);
m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadIconSet("drawpad/fill.png"), QString::null, 0, this);
m_pFillToolAction->setToggleAction(true);
connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool()));
m_pFillToolAction->addTo(drawModeToolBar);
m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadIconSet("drawpad/erase.png"), QString::null, 0, this);
m_pEraseToolAction->setToggleAction(true);
connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool()));
m_pEraseToolAction->addTo(drawModeToolBar);
m_pTool = 0;
setRectangleTool();
setEllipseTool();
setPointTool();
emptyToolBar = new QPEToolBar(this);
emptyToolBar->setHorizontalStretchable(true);
emptyToolBar->addSeparator();
// init draw parameters toolbar
QPEToolBar* drawParametersToolBar = new QPEToolBar(this);
QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar);
connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int)));
QToolTip::add(penWidthSpinBox, tr("Pen Width"));
penWidthSpinBox->setValue(1);
penWidthSpinBox->setFocusPolicy(QWidget::NoFocus);
m_pPenColorToolButton = new QToolButton(drawParametersToolBar);
m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png"));
ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, m_pPenColorToolButton);
connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&)));
QToolTip::add(m_pPenColorToolButton, tr("Pen Color"));
m_pPenColorToolButton->setPopup(penColorPopupMenu);
m_pPenColorToolButton->setPopupDelay(0);
changePenColor(Qt::black);
m_pBrushColorToolButton = new QToolButton(drawParametersToolBar);
m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png"));
ColorPopupMenu* brushColorPopupMenu = new ColorPopupMenu(Qt::white, m_pBrushColorToolButton);
connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&)));
QToolTip::add(m_pBrushColorToolButton, tr("Fill Color"));
m_pBrushColorToolButton->setPopup(brushColorPopupMenu);
m_pBrushColorToolButton->setPopupDelay(0);
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());
+ 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);
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()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new LineTool(this, m_pDrawPadCanvas);
m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet());
QToolTip::add(m_pLineToolButton, m_pLineToolAction->text());
disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0);
connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, 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::setRectangleTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new RectangleTool(this, m_pDrawPadCanvas);
m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet());
QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text());
disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0);
connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated()));
m_pLineToolButton->setOn(false);
m_pRectangleToolButton->setOn(true);
m_pEllipseToolButton->setOn(false);
m_pTextToolAction->setOn(false);
m_pFillToolAction->setOn(false);
m_pEraseToolAction->setOn(false);
}
void DrawPad::setFilledRectangleTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas);
m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet());
QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text());
disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0);
connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated()));
m_pLineToolButton->setOn(false);
m_pRectangleToolButton->setOn(true);
m_pEllipseToolButton->setOn(false);
m_pTextToolAction->setOn(false);
m_pFillToolAction->setOn(false);
m_pEraseToolAction->setOn(false);
}
void DrawPad::setEllipseTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new EllipseTool(this, m_pDrawPadCanvas);
m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet());
QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text());
disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0);
connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated()));
m_pLineToolButton->setOn(false);
m_pRectangleToolButton->setOn(false);
m_pEllipseToolButton->setOn(true);
m_pTextToolAction->setOn(false);
m_pFillToolAction->setOn(false);
m_pEraseToolAction->setOn(false);
}
void DrawPad::setFilledEllipseTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas);
m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet());
QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text());
disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0);
connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated()));
m_pLineToolButton->setOn(false);
m_pRectangleToolButton->setOn(false);
m_pEllipseToolButton->setOn(true);
m_pTextToolAction->setOn(false);
m_pFillToolAction->setOn(false);
m_pEraseToolAction->setOn(false);
}
void DrawPad::setTextTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new TextTool(this, m_pDrawPadCanvas);
m_pLineToolButton->setOn(false);
m_pRectangleToolButton->setOn(false);
m_pEllipseToolButton->setOn(false);
m_pTextToolAction->setOn(true);
m_pFillToolAction->setOn(false);
m_pEraseToolAction->setOn(false);
}
void DrawPad::setFillTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new FillTool(this, m_pDrawPadCanvas);
m_pLineToolButton->setOn(false);
m_pRectangleToolButton->setOn(false);
m_pEllipseToolButton->setOn(false);
m_pTextToolAction->setOn(false);
m_pFillToolAction->setOn(true);
m_pEraseToolAction->setOn(false);
}
void DrawPad::setEraseTool()
{
if (m_pTool) {
delete m_pTool;
}
m_pTool = new EraseTool(this, m_pDrawPadCanvas);
m_pLineToolButton->setOn(false);
m_pRectangleToolButton->setOn(false);
m_pEllipseToolButton->setOn(false);
m_pTextToolAction->setOn(false);
m_pFillToolAction->setOn(false);
m_pEraseToolAction->setOn(true);
}
void DrawPad::changePenWidth(int value)
{
m_pen.setWidth(value);
}
void DrawPad::changePenColor(const QColor& color)
{
m_pen.setColor(color);
QPainter painter;
painter.begin(m_pPenColorToolButton->pixmap());
painter.fillRect(QRect(0, 12, 14, 2), m_pen.color());
painter.end();
m_pPenColorToolButton->popup()->hide();
}
void DrawPad::changeBrushColor(const QColor& color)
{
m_brush = QBrush(color);
QPainter painter;
painter.begin(m_pBrushColorToolButton->pixmap());
painter.fillRect(QRect(0, 12, 14, 2), m_brush.color());
painter.end();
m_pBrushColorToolButton->popup()->hide();
}
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(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
@@ -1,560 +1,586 @@
/***************************************************************************
* *
* 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 "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();
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;
}
textStream << " </images>" << endl;
textStream << "</drawpad>";
}
void DrawPadCanvas::importPage(const QString& fileName)
{
Page* importedPage = new Page();
importedPage->load(fileName);
m_pages.insert(m_pages.at() + 1, importedPage);
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::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()->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)->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);
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()
{
int index = m_pages.at();
Page* page = m_pages.take();
m_pages.insert(index + 1, page);
emit pagesChanged();
}
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()
{
*(m_pages.current()) = *(m_pageBackups.prev());
viewport()->update();
emit pageBackupsChanged();
}
void DrawPadCanvas::redo()
{
*(m_pages.current()) = *(m_pageBackups.next());
viewport()->update();
emit pageBackupsChanged();
}
void DrawPadCanvas::goFirstPage()
{
m_pages.first();
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::goPreviousPage()
{
m_pages.prev();
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::goNextPage()
{
m_pages.next();
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::goLastPage()
{
m_pages.last();
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::contentsMousePressEvent(QMouseEvent* e)
{
m_pDrawPad->tool()->mousePressEvent(e);
}
void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e)
{
m_pDrawPad->tool()->mouseReleaseEvent(e);
}
void DrawPadCanvas::contentsMouseMoveEvent(QMouseEvent* e)
{
m_pDrawPad->tool()->mouseMoveEvent(e);
}
void DrawPadCanvas::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
{
QRect clipRect(cx, cy, cw, ch);
QRect pixmapRect(0, 0, m_pages.current()->width(), m_pages.current()->height());
QRect drawRect = pixmapRect.intersect(clipRect);
p->drawPixmap(drawRect.topLeft(), *(m_pages.current()), drawRect);
if (drawRect.right() < clipRect.right()) {
p->fillRect(drawRect.right() + 1, cy, cw - drawRect.width(), ch, colorGroup().dark());
}
if (drawRect.bottom() < clipRect.bottom()) {
p->fillRect(cx, drawRect.bottom() + 1, cw, ch - drawRect.height(), colorGroup().dark());
}
}
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
@@ -1,85 +1,85 @@
/***************************************************************************
* *
* 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);
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:
DrawPad* m_pDrawPad;
QList<Page> m_pages;
QList<Page> m_pageBackups;
};
#endif // DRAWPADCANVAS_H
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
@@ -1,114 +1,119 @@
/***************************************************************************
* *
* 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 "newpagedialog.h"
#include <qbuttongroup.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qradiobutton.h>
#include <qspinbox.h>
NewPageDialog::NewPageDialog(uint width, uint height, const QColor& penColor,
const QColor& brushColor, QWidget* parent, const char* name)
: QDialog(parent, name, true)
{
setCaption(tr("New Page"));
m_penColor = penColor;
m_brushColor = brushColor;
QGroupBox* generalGroupBox = new QGroupBox(0, Qt::Vertical, tr("General"), this);
QLabel* titleLabel = new QLabel(tr("Title:"), generalGroupBox);
m_pTitleLineEdit = new QLineEdit(generalGroupBox);
QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this);
QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox);
QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox);
m_pWidthSpinBox = new QSpinBox(1, 1024, 1, sizeGroupBox);
m_pHeightSpinBox = new QSpinBox(1, 1024, 1, sizeGroupBox);
m_pWidthSpinBox->setValue(width);
m_pHeightSpinBox->setValue(height);
m_pContentButtonGroup = new QButtonGroup(0, Qt::Vertical, tr("Background"), this);
QRadioButton* whiteColorRadioButton = new QRadioButton(tr("White"), m_pContentButtonGroup);
QRadioButton* penColorRadioButton = new QRadioButton(tr("Pen Color"), m_pContentButtonGroup);
QRadioButton* brushColorRadioButton = new QRadioButton(tr("Fill Color"), m_pContentButtonGroup);
m_pContentButtonGroup->setButton(0);
QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
generalGroupBox->layout()->setSpacing(4);
sizeGroupBox->layout()->setSpacing(4);
m_pContentButtonGroup->layout()->setSpacing(4);
QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 1, 1);
QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2);
QVBoxLayout* contentLayout = new QVBoxLayout(m_pContentButtonGroup->layout());
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);
break;
}
}
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
@@ -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. *
* *
***************************************************************************/
#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,57 +1,59 @@
/***************************************************************************
* *
* 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)
{
m_lastModified = 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
@@ -132,251 +132,251 @@ Page* PageListBoxItem::page() const
}
QString PageListBoxItem::dateTimeString(QDateTime dateTime)
{
QString result;
Config config("qpe");
config.setGroup("Date");
QChar separator = config.readEntry("Separator", "/")[0];
DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear);
for (int i = 0; i < 3; i++) {
switch((shortOrder >> (i * 3)) & 0x0007) {
case 0x0001:
result += QString().sprintf("%02d", dateTime.date().day());
break;
case 0x0002:
result += QString().sprintf("%02d", dateTime.date().month());
break;
case 0x0004:
result += QString().sprintf("%04d", dateTime.date().year());
break;
default:
break;
}
if (i < 2) {
result += separator;
}
}
result += QString().sprintf(" %02d:%02d", dateTime.time().hour(), dateTime.time().minute());
return result;
}
PageListBox::PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
: QListBox(parent, name)
{
m_pDrawPadCanvas = drawPadCanvas;
setVScrollBarMode(QScrollView::AlwaysOn);
updateView();
}
PageListBox::~PageListBox()
{
}
void PageListBox::updateView()
{
clear();
if (m_pDrawPadCanvas) {
QList<Page> pageList = m_pDrawPadCanvas->pages();
QListIterator<Page> it(pageList);
for (; it.current(); ++it) {
new PageListBoxItem(it.current(), this);
}
select(m_pDrawPadCanvas->currentPage());
}
}
void PageListBox::select(Page* page)
{
uint i = 0;
uint itemCount = count();
while (i < itemCount) {
PageListBoxItem* currentItem = (PageListBoxItem*)item(i);
if (currentItem->page() == page) {
setCurrentItem(currentItem);
break;
}
i++;
}
}
Page* PageListBox::selected() const
{
Page* page;
PageListBoxItem* selectedItem = (PageListBoxItem*)item(currentItem());
if (selectedItem) {
page = selectedItem->page();
} else {
page = NULL;
}
return page;
}
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("DrawPad - Thumbnail View"));
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()));
m_pMovePageUpButton = new QToolButton(this);
m_pMovePageUpButton->setIconSet(Resource::loadIconSet("up"));
m_pMovePageUpButton->setAutoRaise(true);
connect(m_pMovePageUpButton, SIGNAL(clicked()), this, SLOT(movePageUp()));
m_pMovePageDownButton = new QToolButton(this);
m_pMovePageDownButton->setIconSet(Resource::loadIconSet("down"));
m_pMovePageDownButton->setAutoRaise(true);
connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown()));
m_pPageListBox = new PageListBox(m_pDrawPadCanvas, this);
connect(m_pPageListBox, 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();
buttonLayout->addWidget(m_pMovePageUpButton);
buttonLayout->addWidget(m_pMovePageDownButton);
mainLayout->addLayout(buttonLayout);
mainLayout->addWidget(m_pPageListBox);
updateView();
}
ThumbnailView::~ThumbnailView()
{
hide();
}
void ThumbnailView::updateView()
{
m_pMovePageUpButton->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled());
m_pMovePageDownButton->setEnabled(m_pDrawPadCanvas->goNextPageEnabled());
}
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_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?"),
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_pPageListBox->updateView();
updateView();
}
}
void ThumbnailView::movePageUp()
{
m_pDrawPadCanvas->movePageUp();
m_pPageListBox->updateView();
updateView();
}
void ThumbnailView::movePageDown()
{
m_pDrawPadCanvas->movePageDown();
m_pPageListBox->updateView();
updateView();
}
void ThumbnailView::changePage()
{
m_pDrawPadCanvas->selectPage(m_pPageListBox->selected());
updateView();
}