summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-12-10 21:45:06 (UTC)
committer harlekin <harlekin>2003-12-10 21:45:06 (UTC)
commit7c21195c1dde6cc91c41e5b15ef5acce568a2f54 (patch) (side-by-side diff)
tree83914e1119fa662dc7a4d37e72624118c62aecaf
parentc80a4d0e0b0ed83757d8494e7f32c8b4b0b6e8d0 (diff)
downloadopie-7c21195c1dde6cc91c41e5b15ef5acce568a2f54.zip
opie-7c21195c1dde6cc91c41e5b15ef5acce568a2f54.tar.gz
opie-7c21195c1dde6cc91c41e5b15ef5acce568a2f54.tar.bz2
reduce includes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp1
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp2
-rw-r--r--noncore/graphics/drawpad/ellipsetool.cpp1
-rw-r--r--noncore/graphics/drawpad/erasetool.cpp1
-rw-r--r--noncore/graphics/drawpad/exportdialog.cpp1
-rw-r--r--noncore/graphics/drawpad/filledellipsetool.cpp1
-rw-r--r--noncore/graphics/drawpad/filltool.cpp1
-rw-r--r--noncore/graphics/drawpad/importdialog.cpp1
-rw-r--r--noncore/graphics/drawpad/linetool.cpp1
-rw-r--r--noncore/graphics/drawpad/main.cpp1
-rw-r--r--noncore/graphics/drawpad/newpagedialog.cpp1
-rw-r--r--noncore/graphics/drawpad/pointtool.cpp1
-rw-r--r--noncore/graphics/drawpad/shapetool.cpp1
-rw-r--r--noncore/graphics/drawpad/texttool.cpp1
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp1
-rw-r--r--noncore/graphics/drawpad/tool.cpp2
16 files changed, 0 insertions, 18 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index 86a10a5..71c9695 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -1,238 +1,237 @@
/***************************************************************************
* *
* 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/config.h>
#include <qpe/global.h>
#include <qmenubar.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>
#include <qwhatsthis.h>
DrawPad::DrawPad(QWidget* parent, const char* name, WFlags fl )
: QMainWindow(parent, name, WStyle_ContextHelp)
{
// init members
m_pDrawPadCanvas = new DrawPadCanvas(this, this);
connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView()));
setCentralWidget(m_pDrawPadCanvas);
// init menu
setToolBarsMovable(false);
QToolBar* menuToolBar = new QToolBar(this);
QMenuBar* menuBar = new QMenuBar(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);
toolsPopupMenu->insertSeparator();
m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this);
m_pAntiAliasingAction->setToggleAction(true);
m_pAntiAliasingAction->addTo(toolsPopupMenu);
menuBar->insertItem(tr("Tools"), toolsPopupMenu);
// init page toolbar
QToolBar* pageToolBar = new QToolBar(this);
QAction* newPageAction = new QAction(tr("New Page"), Resource::loadPixmap("new"), QString::null, 0, this);
connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage()));
newPageAction->addTo(pageToolBar);
newPageAction->setWhatsThis( tr( "Click here to add a new sheet." ) );
QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadPixmap("drawpad/clear"), QString::null, 0, this);
connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage()));
clearPageAction->addTo(pageToolBar);
clearPageAction->setWhatsThis( tr( "Click here to erase the current sheet." ) );
QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadPixmap("trash"), QString::null, 0, this);
connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage()));
deletePageAction->addTo(pageToolBar);
deletePageAction->setWhatsThis( tr( "Click here to remove the current sheet." ) );
QToolBar* emptyToolBar = new QToolBar(this);
emptyToolBar->setHorizontalStretchable(true);
// init navigation toolbar
QToolBar* navigationToolBar = new QToolBar(this);
m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("undo"), QString::null, 0, this);
connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo()));
m_pUndoAction->addTo(navigationToolBar);
m_pUndoAction->setWhatsThis( tr( "Click here to undo the last action." ) );
m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("redo"), QString::null, 0, this);
connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo()));
m_pRedoAction->addTo(navigationToolBar);
m_pRedoAction->setWhatsThis( tr( "Click here to re-perform the last action." ) );
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_pFirstPageAction->setWhatsThis( tr( "Click here to view the first page." ) );
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_pPreviousPageAction->setWhatsThis( tr( "Click here to view the previous page." ) );
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_pNextPageAction->setWhatsThis( tr( "Click here to view the next page." ) );
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);
m_pLastPageAction->setWhatsThis( tr( "Click here to view the last page." ) );
// init draw mode toolbar
QToolBar* drawModeToolBar = new QToolBar(this);
m_pLineToolButton = new QToolButton(drawModeToolBar);
m_pLineToolButton->setToggleButton(true);
QWhatsThis::add( m_pLineToolButton, tr( "Click here to select one of the available tools to draw lines." ) );
QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton);
m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadPixmap("drawpad/point"), "", 0, this);
connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool()));
m_pPointToolAction->addTo(linePopupMenu);
m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadPixmap("drawpad/line"), "", 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);
QWhatsThis::add( m_pRectangleToolButton, tr( "Click here to select one of the available tools to draw rectangles." ) );
QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton);
m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadPixmap("drawpad/rectangle"), "", 0, this);
connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool()));
m_pRectangleToolAction->addTo(rectanglePopupMenu);
m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadPixmap("drawpad/filledrectangle"), "", 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);
QWhatsThis::add( m_pEllipseToolButton, tr( "Click here to select one of the available tools to draw ellipses." ) );
QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton);
m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadPixmap("drawpad/ellipse"), "", 0, this);
connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool()));
m_pEllipseToolAction->addTo(ellipsePopupMenu);
m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadPixmap("drawpad/filledellipse"), "", 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::loadPixmap("drawpad/text"), QString::null, 0, this);
m_pTextToolAction->setToggleAction(true);
connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool()));
m_pTextToolAction->addTo(drawModeToolBar);
m_pTextToolAction->setWhatsThis( tr( "Click here to select the text drawing tool." ) );
m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadPixmap("drawpad/fill"), QString::null, 0, this);
m_pFillToolAction->setToggleAction(true);
connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool()));
m_pFillToolAction->addTo(drawModeToolBar);
m_pFillToolAction->setWhatsThis( tr( "Click here to select the fill tool." ) );
m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadPixmap("drawpad/erase"), QString::null, 0, this);
m_pEraseToolAction->setToggleAction(true);
connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool()));
m_pEraseToolAction->addTo(drawModeToolBar);
m_pEraseToolAction->setWhatsThis( tr( "Click here to select the eraser tool." ) );
m_pTool = 0;
setRectangleTool();
setEllipseTool();
setPointTool();
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index dec498b..446096c 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -1,220 +1,218 @@
/***************************************************************************
* *
* 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>
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 == "image") {
m_title = QString();
m_date = QDateTime::currentDateTime();
} 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");
}
return true;
}
bool DrawPadCanvasXmlHandler::endElement(const QString& namespaceURI, const QString& localName,
const QString& qName)
{
Q_CONST_UNUSED(namespaceURI)
Q_CONST_UNUSED(localName)
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)
{
if (m_state == InTitle) {
m_title = ch;
} else if (m_state == InDate) {
m_date = QDateTime(QDate(1970, 1, 1)).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;
image.loadFromData((const uchar*)byteArray.data(), m_dataLenght, m_dataFormat);
Page* page = new Page(m_title, image.width(), image.height());
page->setLastModified(m_date);
page->pixmap()->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);
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("",
clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0),
clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0)));
m_pages.current()->pixmap()->fill(Qt::white);
}
resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
viewport()->update();
emit pagesChanged();
}
void DrawPadCanvas::initialPage()
{
m_pages.append(new Page("",
clipper()->width()+(verticalScrollBar()->isVisible()?verticalScrollBar()->width():0),
clipper()->height()+(horizontalScrollBar()->isVisible()?horizontalScrollBar()->height():0)));
//236, 232)); no more fixed sizes
m_pages.current()->pixmap()->fill(Qt::white);
resizeContents(m_pages.current()->pixmap()->width(), m_pages.current()->pixmap()->height());
viewport()->update();
emit pagesChanged();
}
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);
diff --git a/noncore/graphics/drawpad/ellipsetool.cpp b/noncore/graphics/drawpad/ellipsetool.cpp
index 0cdb731..2173c97 100644
--- a/noncore/graphics/drawpad/ellipsetool.cpp
+++ b/noncore/graphics/drawpad/ellipsetool.cpp
@@ -1,81 +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. *
* *
***************************************************************************/
#include "ellipsetool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include <qimage.h>
-#include <qpixmap.h>
EllipseTool::EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: ShapeTool(drawPad, drawPadCanvas)
{
}
EllipseTool::~EllipseTool()
{
}
void EllipseTool::drawFinalShape(QPainter& p)
{
p.setRasterOp(Qt::NotROP);
p.drawRect(QRect(m_polyline[2], m_polyline[0]));
p.setRasterOp(Qt::CopyROP);
if (m_pDrawPad->antiAliasing()) {
QRect r = m_polyline.boundingRect();
r = r.normalize();
r.setLeft(r.left() - m_pDrawPad->pen().width());
r.setTop(r.top() - m_pDrawPad->pen().width());
r.setRight(r.right() + m_pDrawPad->pen().width());
r.setBottom(r.bottom() + m_pDrawPad->pen().width());
QPixmap areaPixmap(r.width(), r.height());
bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r);
QImage areaImage = areaPixmap.convertToImage();
QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3);
QPixmap bigAreaPixmap;
bigAreaPixmap.convertFromImage(bigAreaImage);
QPen bigAreaPen = m_pDrawPad->pen();
bigAreaPen.setWidth(bigAreaPen.width() * 3);
QPainter bigAreaPainter;
bigAreaPainter.begin(&bigAreaPixmap);
bigAreaPainter.setPen(bigAreaPen);
bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1,
bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1),
bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1)));
bigAreaPainter.end();
bigAreaImage = bigAreaPixmap.convertToImage();
areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
areaPixmap.convertFromImage(areaImage);
p.drawPixmap(r.x(), r.y(), areaPixmap);
} else {
p.setPen(m_pDrawPad->pen());
p.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
}
}
void EllipseTool::drawTemporaryShape(QPainter& p)
{
p.setRasterOp(Qt::NotROP);
p.drawRect(QRect(m_polyline[2], m_polyline[1]));
p.drawRect(QRect(m_polyline[2], m_polyline[0]));
}
diff --git a/noncore/graphics/drawpad/erasetool.cpp b/noncore/graphics/drawpad/erasetool.cpp
index 2326da5..5d123c4 100644
--- a/noncore/graphics/drawpad/erasetool.cpp
+++ b/noncore/graphics/drawpad/erasetool.cpp
@@ -1,76 +1,75 @@
/***************************************************************************
* *
* 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 "erasetool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include "page.h"
-#include <qpainter.h>
EraseTool::EraseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: Tool(drawPad, drawPadCanvas)
{
m_mousePressed = false;
m_polyline.resize(3);
}
EraseTool::~EraseTool()
{
}
void EraseTool::mousePressEvent(QMouseEvent* e)
{
m_pDrawPadCanvas->backupPage();
m_mousePressed = true;
m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
}
void EraseTool::mouseReleaseEvent(QMouseEvent* e)
{
Q_UNUSED(e)
m_mousePressed = false;
}
void EraseTool::mouseMoveEvent(QMouseEvent* e)
{
if (m_mousePressed) {
QPainter painter;
QPen pen(Qt::white, m_pDrawPad->pen().width());
painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
painter.setPen(pen);
m_polyline[2] = m_polyline[1];
m_polyline[1] = m_polyline[0];
m_polyline[0] = e->pos();
painter.drawPolyline(m_polyline);
painter.end();
QRect r = m_polyline.boundingRect();
r = r.normalize();
r.setLeft(r.left() - m_pDrawPad->pen().width());
r.setTop(r.top() - m_pDrawPad->pen().width());
r.setRight(r.right() + m_pDrawPad->pen().width());
r.setBottom(r.bottom() + m_pDrawPad->pen().width());
QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
m_pDrawPadCanvas->viewport()->update(viewportRect);
}
}
diff --git a/noncore/graphics/drawpad/exportdialog.cpp b/noncore/graphics/drawpad/exportdialog.cpp
index adbd612..d63f428 100644
--- a/noncore/graphics/drawpad/exportdialog.cpp
+++ b/noncore/graphics/drawpad/exportdialog.cpp
@@ -1,176 +1,175 @@
/***************************************************************************
* *
* 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 "exportdialog.h"
#include <opie/ofileselector.h>
#include <qbuttongroup.h>
#include <qcombobox.h>
-#include <qgroupbox.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qradiobutton.h>
#include <qspinbox.h>
#include <stdlib.h>
ExportDialog::ExportDialog(uint pageAt, uint pageCount, QWidget* parent, const char* name)
: QDialog(parent, name, true)
{
setCaption(tr("DrawPad - Export"));
m_pageAt = pageAt;
m_pageCount = pageCount;
QButtonGroup* selectionButtonGroup = new QButtonGroup(0, Qt::Vertical, tr("Page Selection"), this);
connect(selectionButtonGroup, SIGNAL(pressed(int)), this, SLOT(selectionChanged(int)));
QRadioButton* selectAllRadioButton = new QRadioButton(tr("All"), selectionButtonGroup);
QRadioButton* selectCurrentRadioButton = new QRadioButton(tr("Current"), selectionButtonGroup);
QRadioButton* selectRangeRadioButton = new QRadioButton(tr("Range"), selectionButtonGroup);
QLabel* toLabel = new QLabel(tr("To:"), selectionButtonGroup);
m_pFromPageSpinBox = new QSpinBox(1, m_pageCount, 1, selectionButtonGroup);
connect(m_pFromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(fromPageChanged(int)));
m_pToPageSpinBox = new QSpinBox(1, m_pageCount, 1, selectionButtonGroup);
connect(m_pToPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(toPageChanged(int)));
selectionButtonGroup->setButton(1);
selectionChanged(1);
m_pFromPageSpinBox->setValue(pageAt);
m_pToPageSpinBox->setValue(pageAt);
QGroupBox* exportGroupBox = new QGroupBox(0, Qt::Vertical, tr("Export As"), this);
QLabel* nameLabel = new QLabel(tr("Name:"), exportGroupBox);
QLabel* formatLabel = new QLabel(tr("Format:"), exportGroupBox);
m_pNameLineEdit = new QLineEdit(exportGroupBox);
m_pFormatComboBox = new QComboBox(exportGroupBox);
m_pFormatComboBox->insertStrList(QImageIO::outputFormats());
MimeTypes types; types.insert( tr("All Images"), "image/*" );
OFileSelector* fileSelector = new OFileSelector(this, OFileSelector::FileSelector,
OFileSelector::Normal,
QString::null, QString::null,
types );
fileSelector->setNameVisible( false );
QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
selectionButtonGroup->layout()->setSpacing(4);
exportGroupBox->layout()->setSpacing(4);
QGridLayout* selectionLayout = new QGridLayout(selectionButtonGroup->layout(), 2, 2);
QHBoxLayout* rangeLayout = new QHBoxLayout();
QGridLayout* exportLayout = new QGridLayout(exportGroupBox->layout(), 2, 2);
selectionLayout->addWidget(selectAllRadioButton, 0, 0);
selectionLayout->addWidget(selectCurrentRadioButton, 1, 0);
selectionLayout->addWidget(selectRangeRadioButton, 0, 1);
selectionLayout->addLayout(rangeLayout, 1, 1);
rangeLayout->addWidget(m_pFromPageSpinBox);
rangeLayout->addWidget(toLabel);
rangeLayout->addWidget(m_pToPageSpinBox);
exportLayout->addWidget(nameLabel, 0, 0);
exportLayout->addWidget(formatLabel, 1, 0);
exportLayout->addWidget(m_pNameLineEdit, 0, 1);
exportLayout->addWidget(m_pFormatComboBox, 1, 1);
exportLayout->setColStretch(1, 1);
mainLayout->addWidget(selectionButtonGroup);
mainLayout->addWidget(exportGroupBox);
mainLayout->addWidget(fileSelector);
m_pNameLineEdit->setFocus();
}
ExportDialog::~ExportDialog()
{
}
uint ExportDialog::selectedFromPage()
{
return (m_pFromPageSpinBox->value());
}
uint ExportDialog::selectedToPage()
{
return (m_pToPageSpinBox->value());
}
QString ExportDialog::selectedName()
{
return (m_pNameLineEdit->text());
}
QString ExportDialog::selectedFormat()
{
return (m_pFormatComboBox->currentText());
}
void ExportDialog::accept()
{
if (!(m_pNameLineEdit->text().isEmpty())) {
QDialog::accept();
}
}
void ExportDialog::selectionChanged(int id)
{
switch (id) {
case 0:
m_pFromPageSpinBox->setValue(1);
m_pToPageSpinBox->setValue(m_pageCount);
m_pFromPageSpinBox->setEnabled(false);
m_pToPageSpinBox->setEnabled(false);
break;
case 1:
m_pFromPageSpinBox->setValue(m_pageAt);
m_pToPageSpinBox->setValue(m_pageAt);
m_pFromPageSpinBox->setEnabled(false);
m_pToPageSpinBox->setEnabled(false);
break;
case 2:
m_pFromPageSpinBox->setEnabled(true);
m_pToPageSpinBox->setEnabled(true);
break;
default:
break;
}
}
void ExportDialog::fromPageChanged(int value)
{
if (m_pToPageSpinBox->value() < value) {
m_pToPageSpinBox->setValue(value);
}
}
void ExportDialog::toPageChanged(int value)
{
if (m_pFromPageSpinBox->value() > value) {
m_pFromPageSpinBox->setValue(value);
}
}
diff --git a/noncore/graphics/drawpad/filledellipsetool.cpp b/noncore/graphics/drawpad/filledellipsetool.cpp
index 6b5bbc6..41b8571 100644
--- a/noncore/graphics/drawpad/filledellipsetool.cpp
+++ b/noncore/graphics/drawpad/filledellipsetool.cpp
@@ -1,83 +1,82 @@
/***************************************************************************
* *
* 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 "filledellipsetool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include <qimage.h>
-#include <qpixmap.h>
FilledEllipseTool::FilledEllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: ShapeTool(drawPad, drawPadCanvas)
{
}
FilledEllipseTool::~FilledEllipseTool()
{
}
void FilledEllipseTool::drawFinalShape(QPainter& p)
{
p.setRasterOp(Qt::NotROP);
p.drawRect(QRect(m_polyline[2], m_polyline[0]));
p.setRasterOp(Qt::CopyROP);
if (m_pDrawPad->antiAliasing()) {
QRect r = m_polyline.boundingRect();
r = r.normalize();
r.setLeft(r.left() - m_pDrawPad->pen().width());
r.setTop(r.top() - m_pDrawPad->pen().width());
r.setRight(r.right() + m_pDrawPad->pen().width());
r.setBottom(r.bottom() + m_pDrawPad->pen().width());
QPixmap areaPixmap(r.width(), r.height());
bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r);
QImage areaImage = areaPixmap.convertToImage();
QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3);
QPixmap bigAreaPixmap;
bigAreaPixmap.convertFromImage(bigAreaImage);
QPen bigAreaPen = m_pDrawPad->pen();
bigAreaPen.setWidth(bigAreaPen.width() * 3);
QPainter bigAreaPainter;
bigAreaPainter.begin(&bigAreaPixmap);
bigAreaPainter.setPen(bigAreaPen);
bigAreaPainter.setBrush(m_pDrawPad->brush());
bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1,
bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1),
bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1)));
bigAreaPainter.end();
bigAreaImage = bigAreaPixmap.convertToImage();
areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
areaPixmap.convertFromImage(areaImage);
p.drawPixmap(r.x(), r.y(), areaPixmap);
} else {
p.setPen(m_pDrawPad->pen());
p.setBrush(m_pDrawPad->brush());
p.drawEllipse(QRect(m_polyline[2], m_polyline[0]));
}
}
void FilledEllipseTool::drawTemporaryShape(QPainter& p)
{
p.setRasterOp(Qt::NotROP);
p.drawRect(QRect(m_polyline[2], m_polyline[1]));
p.drawRect(QRect(m_polyline[2], m_polyline[0]));
}
diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp
index b47aa60..fedf3a5 100644
--- a/noncore/graphics/drawpad/filltool.cpp
+++ b/noncore/graphics/drawpad/filltool.cpp
@@ -1,165 +1,164 @@
/***************************************************************************
* *
* 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 "filltool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include "page.h"
-#include <qimage.h>
const int FILL_THRESHOLD = 65536;
FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: Tool(drawPad, drawPadCanvas)
{
}
FillTool::~FillTool()
{
}
void FillTool::mousePressEvent(QMouseEvent* e)
{
int x = e->x();
int y = e->y();
m_image = m_pDrawPadCanvas->currentPage()->pixmap()->convertToImage();
if (m_image.depth() <= 8) {
m_image = m_image.convertDepth(32);
}
m_fillRgb = m_pDrawPad->brush().color().rgb();
m_oldRgb = m_image.pixel(x, y);
if (m_oldRgb != m_fillRgb) {
m_pDrawPadCanvas->backupPage();
if (m_pDrawPad->antiAliasing()) {
m_mask.create(m_image.width(), m_image.height(), 8, 2);
m_mask.fill(0);
fillMaskLine(x, y);
for (int i = 0; i < m_image.width(); i++) {
for (int j = 0; j < m_image.height(); j++) {
if (m_mask.pixelIndex(i, j) == 1) {
setInterpolatedPixel(i, j);
}
}
}
} else {
fillLine(x, y);
}
m_pDrawPadCanvas->currentPage()->pixmap()->convertFromImage(m_image);
m_pDrawPadCanvas->viewport()->update();
}
}
void FillTool::mouseReleaseEvent(QMouseEvent* e)
{
Q_UNUSED(e)
}
void FillTool::mouseMoveEvent(QMouseEvent* e)
{
Q_UNUSED(e)
}
void FillTool::fillLine(int x, int y)
{
if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) {
if (m_image.pixel(x, y) == m_oldRgb) {
int x1, x2;
x1 = x - 1;
x2 = x + 1;
while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) {
x1--;
}
while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) {
x2++;
}
for (int i = x1 + 1; i < x2; i++) {
m_image.setPixel(i, y, m_fillRgb);
}
for (int i = x1 + 1; i < x2; i++) {
fillLine(i, y - 1);
}
for (int i = x1 + 1; i < x2; i++) {
fillLine(i, y + 1);
}
}
}
}
void FillTool::fillMaskLine(int x, int y)
{
if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) {
if (m_mask.pixelIndex(x, y) == 0) {
if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) {
int x1, x2;
x1 = x - 1;
x2 = x + 1;
while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) {
x1--;
}
while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) {
x2++;
}
for (int i = x1 + 1; i < x2; i++) {
m_mask.setPixel(i, y, 1);
}
for (int i = x1 + 1; i < x2; i++) {
fillMaskLine(i, y - 1);
}
for (int i = x1 + 1; i < x2; i++) {
fillMaskLine(i, y + 1);
}
}
}
}
}
void FillTool::setInterpolatedPixel(int x, int y)
{
int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255);
int fillGreen = QMIN(QMAX(qGreen(m_fillRgb) + qGreen(m_image.pixel(x, y)) - qGreen(m_oldRgb), 0), 255);
int fillBlue = QMIN(QMAX(qBlue(m_fillRgb) + qBlue(m_image.pixel(x, y)) - qBlue(m_oldRgb), 0), 255);
m_image.setPixel(x, y, qRgb(fillRed, fillGreen, fillBlue));
}
int FillTool::rgbDistance(QRgb rgb1, QRgb rgb2)
{
int redDistance = qRed(rgb2) - qRed(rgb1);
int greenDistance = qGreen(rgb2) - qGreen(rgb1);
int blueDistance = qBlue(rgb2) - qBlue(rgb1);
return (redDistance * redDistance + greenDistance * greenDistance + blueDistance * blueDistance);
}
diff --git a/noncore/graphics/drawpad/importdialog.cpp b/noncore/graphics/drawpad/importdialog.cpp
index 9a59a20..ce2e7ee 100644
--- a/noncore/graphics/drawpad/importdialog.cpp
+++ b/noncore/graphics/drawpad/importdialog.cpp
@@ -1,117 +1,116 @@
/***************************************************************************
* *
* 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 "importdialog.h"
-#include <qpe/applnk.h>
#include <opie/ofileselector.h>
#include <qcheckbox.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpushbutton.h>
ImportDialog::ImportDialog(QWidget* parent, const char* name)
: QDialog(parent, name, true)
{
setCaption(tr("DrawPad - Import"));
MimeTypes types; types.insert( tr("All images"),"image/*" );
m_pFileSelector = new OFileSelector(this,
OFileSelector::FileSelector,
OFileSelector::Normal,
QString::null,
QString::null, types );
m_pFileSelector->setNameVisible( false );
connect(m_pFileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(fileChanged()));
m_pPreviewLabel = new QLabel(this);
m_pPreviewLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
m_pPreviewLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_pPreviewLabel->setFixedSize(114, 114);
m_pPreviewLabel->setBackgroundMode(QWidget::PaletteMid);
m_pAutomaticPreviewCheckBox = new QCheckBox(tr("Automatic preview"), this);
m_pAutomaticPreviewCheckBox->setChecked(true);
QPushButton* previewPushButton = new QPushButton(tr("Preview"), this);
connect(previewPushButton, SIGNAL(clicked()), this, SLOT(preview()));
QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
QHBoxLayout* previewLayout = new QHBoxLayout(4);
QVBoxLayout* previewSecondLayout = new QVBoxLayout(4);
previewSecondLayout->addWidget(m_pAutomaticPreviewCheckBox);
previewSecondLayout->addWidget(previewPushButton);
previewSecondLayout->addStretch();
previewLayout->addWidget(m_pPreviewLabel);
previewLayout->addLayout(previewSecondLayout);
mainLayout->addWidget(m_pFileSelector);
mainLayout->addLayout(previewLayout);
preview();
}
ImportDialog::~ImportDialog()
{
}
const DocLnk* ImportDialog::selected()
{
// FIXME change from pointer to reference -zecke
DocLnk *lnk = new DocLnk( m_pFileSelector->selectedDocument() );
return lnk;
}
void ImportDialog::fileChanged()
{
if (m_pAutomaticPreviewCheckBox->isChecked()) {
preview();
}
}
void ImportDialog::preview()
{
const DocLnk* docLnk = selected();
if (docLnk) {
QImage image(docLnk->file());
int previewWidth = m_pPreviewLabel->contentsRect().width();
int previewHeight = m_pPreviewLabel->contentsRect().height();
float widthScale = 1.0;
float heightScale = 1.0;
if (previewWidth < image.width()) {
widthScale = (float)previewWidth / float(image.width());
}
if (previewHeight < image.height()) {
heightScale = (float)previewHeight / float(image.height());
}
float scale = (widthScale < heightScale ? widthScale : heightScale);
QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
QPixmap previewPixmap;
previewPixmap.convertFromImage(previewImage);
m_pPreviewLabel->setPixmap(previewPixmap);
delete docLnk;
}
}
diff --git a/noncore/graphics/drawpad/linetool.cpp b/noncore/graphics/drawpad/linetool.cpp
index b6baa2a..5ea068c 100644
--- a/noncore/graphics/drawpad/linetool.cpp
+++ b/noncore/graphics/drawpad/linetool.cpp
@@ -1,82 +1,81 @@
/***************************************************************************
* *
* 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 "linetool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include <qimage.h>
-#include <qpixmap.h>
LineTool::LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: ShapeTool(drawPad, drawPadCanvas)
{
}
LineTool::~LineTool()
{
}
void LineTool::drawFinalShape(QPainter& p)
{
p.setRasterOp(Qt::NotROP);
p.drawLine(m_polyline[2], m_polyline[0]);
p.setRasterOp(Qt::CopyROP);
if (m_pDrawPad->antiAliasing()) {
QRect r = m_polyline.boundingRect();
r = r.normalize();
r.setLeft(r.left() - m_pDrawPad->pen().width());
r.setTop(r.top() - m_pDrawPad->pen().width());
r.setRight(r.right() + m_pDrawPad->pen().width());
r.setBottom(r.bottom() + m_pDrawPad->pen().width());
QPixmap areaPixmap(r.width(), r.height());
bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r);
QImage areaImage = areaPixmap.convertToImage();
QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3);
QPixmap bigAreaPixmap;
bigAreaPixmap.convertFromImage(bigAreaImage);
QPen bigAreaPen = m_pDrawPad->pen();
bigAreaPen.setWidth(bigAreaPen.width() * 3);
QPainter bigAreaPainter;
bigAreaPainter.begin(&bigAreaPixmap);
bigAreaPainter.setPen(bigAreaPen);
bigAreaPainter.drawLine((m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1,
(m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1);
bigAreaPainter.end();
bigAreaImage = bigAreaPixmap.convertToImage();
areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
areaPixmap.convertFromImage(areaImage);
p.drawPixmap(r.x(), r.y(), areaPixmap);
} else {
p.setPen(m_pDrawPad->pen());
p.drawLine(m_polyline[2], m_polyline[0]);
}
}
void LineTool::drawTemporaryShape(QPainter& p)
{
p.setRasterOp(Qt::NotROP);
p.drawLine(m_polyline[2], m_polyline[1]);
p.drawLine(m_polyline[2], m_polyline[0]);
}
diff --git a/noncore/graphics/drawpad/main.cpp b/noncore/graphics/drawpad/main.cpp
index 87bc621..c87cc0f 100644
--- a/noncore/graphics/drawpad/main.cpp
+++ b/noncore/graphics/drawpad/main.cpp
@@ -1,19 +1,18 @@
/***************************************************************************
* *
* 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 <qpe/qpeapplication.h>
#include <opie/oapplicationfactory.h>
OPIE_EXPORT_APP( OApplicationFactory<DrawPad> )
diff --git a/noncore/graphics/drawpad/newpagedialog.cpp b/noncore/graphics/drawpad/newpagedialog.cpp
index e6e7fcb..dc8999a 100644
--- a/noncore/graphics/drawpad/newpagedialog.cpp
+++ b/noncore/graphics/drawpad/newpagedialog.cpp
@@ -1,119 +1,118 @@
/***************************************************************************
* *
* 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/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp
index b9b52bc..4fb7ad1 100644
--- a/noncore/graphics/drawpad/pointtool.cpp
+++ b/noncore/graphics/drawpad/pointtool.cpp
@@ -1,111 +1,110 @@
/***************************************************************************
* *
* 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 "pointtool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include "page.h"
#include <qimage.h>
-#include <qpainter.h>
PointTool::PointTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: Tool(drawPad, drawPadCanvas)
{
m_mousePressed = false;
m_polyline.resize(3);
}
PointTool::~PointTool()
{
}
void PointTool::mousePressEvent(QMouseEvent* e)
{
m_pDrawPadCanvas->backupPage();
m_mousePressed = true;
m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
}
void PointTool::mouseReleaseEvent(QMouseEvent* e)
{
Q_UNUSED(e)
m_mousePressed = false;
}
void PointTool::mouseMoveEvent(QMouseEvent* e)
{
if (m_mousePressed) {
m_polyline[2] = m_polyline[1];
m_polyline[1] = m_polyline[0];
m_polyline[0] = e->pos();
QRect r = m_polyline.boundingRect();
r = r.normalize();
r.setLeft(r.left() - m_pDrawPad->pen().width());
r.setTop(r.top() - m_pDrawPad->pen().width());
r.setRight(r.right() + m_pDrawPad->pen().width());
r.setBottom(r.bottom() + m_pDrawPad->pen().width());
QPainter painter;
painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
if (m_pDrawPad->antiAliasing()) {
QPixmap areaPixmap(r.width(), r.height());
bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r);
QImage areaImage = areaPixmap.convertToImage();
QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3);
QPixmap bigAreaPixmap;
bigAreaPixmap.convertFromImage(bigAreaImage);
QPen bigAreaPen = m_pDrawPad->pen();
bigAreaPen.setWidth(bigAreaPen.width() * 3);
QPainter bigAreaPainter;
bigAreaPainter.begin(&bigAreaPixmap);
bigAreaPainter.setPen(bigAreaPen);
QPointArray bigAreaPolyline(3);
bigAreaPolyline.setPoint(0, (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1);
bigAreaPolyline.setPoint(1, (m_polyline[1].x() - r.x()) * 3 + 1, (m_polyline[1].y() - r.y()) * 3 + 1);
bigAreaPolyline.setPoint(2, (m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1);
bigAreaPainter.drawPolyline(bigAreaPolyline);
bigAreaPainter.end();
bigAreaImage = bigAreaPixmap.convertToImage();
areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3);
areaPixmap.convertFromImage(areaImage);
painter.drawPixmap(r.x(), r.y(), areaPixmap);
} else {
painter.setPen(m_pDrawPad->pen());
painter.drawPolyline(m_polyline);
}
painter.end();
QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
m_pDrawPadCanvas->viewport()->update(viewportRect);
}
}
diff --git a/noncore/graphics/drawpad/shapetool.cpp b/noncore/graphics/drawpad/shapetool.cpp
index 22e3dd6..6e4276d 100644
--- a/noncore/graphics/drawpad/shapetool.cpp
+++ b/noncore/graphics/drawpad/shapetool.cpp
@@ -1,94 +1,93 @@
/***************************************************************************
* *
* 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 "shapetool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include "page.h"
-#include <qpainter.h>
ShapeTool::ShapeTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: Tool(drawPad, drawPadCanvas)
{
m_mousePressed = false;
m_polyline.resize(3);
}
ShapeTool::~ShapeTool()
{
}
void ShapeTool::mousePressEvent(QMouseEvent* e)
{
m_pDrawPadCanvas->backupPage();
m_mousePressed = true;
m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos();
}
void ShapeTool::mouseReleaseEvent(QMouseEvent* e)
{
Q_UNUSED(e)
QPainter painter;
painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
drawFinalShape(painter);
painter.end();
QRect r = m_polyline.boundingRect();
r = r.normalize();
r.setLeft(r.left() - m_pDrawPad->pen().width());
r.setTop(r.top() - m_pDrawPad->pen().width());
r.setRight(r.right() + m_pDrawPad->pen().width());
r.setBottom(r.bottom() + m_pDrawPad->pen().width());
QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
m_pDrawPadCanvas->viewport()->update(viewportRect);
m_mousePressed = false;
}
void ShapeTool::mouseMoveEvent(QMouseEvent* e)
{
if (m_mousePressed) {
m_polyline[0] = e->pos();
QPainter painter;
painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
drawTemporaryShape(painter);
painter.end();
QRect r = m_polyline.boundingRect();
r = r.normalize();
r.setLeft(r.left() - m_pDrawPad->pen().width());
r.setTop(r.top() - m_pDrawPad->pen().width());
r.setRight(r.right() + m_pDrawPad->pen().width());
r.setBottom(r.bottom() + m_pDrawPad->pen().width());
QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));
bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());
m_pDrawPadCanvas->viewport()->update(viewportRect);
m_polyline[1] = m_polyline[0];
}
}
diff --git a/noncore/graphics/drawpad/texttool.cpp b/noncore/graphics/drawpad/texttool.cpp
index 9037abd..3a89e80 100644
--- a/noncore/graphics/drawpad/texttool.cpp
+++ b/noncore/graphics/drawpad/texttool.cpp
@@ -1,79 +1,78 @@
/***************************************************************************
* *
* 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 "texttool.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include "page.h"
#include <qlayout.h>
#include <qlineedit.h>
-#include <qpainter.h>
TextToolDialog::TextToolDialog(QWidget* parent, const char* name)
: QDialog(parent, name, true)
{
setCaption(tr("Insert Text"));
m_pLineEdit = new QLineEdit(this);
QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
mainLayout->addWidget(m_pLineEdit);
}
TextToolDialog::~TextToolDialog()
{
}
QString TextToolDialog::text()
{
return m_pLineEdit->text();
}
TextTool::TextTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: Tool(drawPad, drawPadCanvas)
{
}
TextTool::~TextTool()
{
}
void TextTool::mousePressEvent(QMouseEvent* e)
{
TextToolDialog textToolDialog(m_pDrawPad);
if (textToolDialog.exec() == QDialog::Accepted && !textToolDialog.text().isEmpty()) {
m_pDrawPadCanvas->backupPage();
QPainter painter;
painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
painter.setPen(m_pDrawPad->pen());
painter.drawText(e->x(), e->y(), textToolDialog.text());
painter.end();
m_pDrawPadCanvas->viewport()->update();
}
}
void TextTool::mouseReleaseEvent(QMouseEvent* e)
{
Q_UNUSED(e)
}
void TextTool::mouseMoveEvent(QMouseEvent* e)
{
Q_UNUSED(e)
}
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 90ba39c..1ccf484 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -1,218 +1,217 @@
/***************************************************************************
* *
* 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/config.h>
#include <qpe/resource.h>
#include <qpe/timestring.h>
#include <qapplication.h>
-#include <qimage.h>
#include <qlayout.h>
#include <qmessagebox.h>
#include <qtoolbutton.h>
#include <qwhatsthis.h>
#define THUMBNAIL_SIZE 48
PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent)
: QListBoxItem(parent)
{
m_pPage = page;
QImage image = m_pPage->pixmap()->convertToImage();
int previewWidth = THUMBNAIL_SIZE;
int previewHeight = THUMBNAIL_SIZE;
float widthScale = 1.0;
float heightScale = 1.0;
if (previewWidth < image.width()) {
widthScale = (float)previewWidth / float(image.width());
}
if (previewHeight < image.height()) {
heightScale = (float)previewHeight / float(image.height());
}
float scale = (widthScale < heightScale ? widthScale : heightScale);
QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
m_thumbnail.convertFromImage(thumbnailImage);
m_titleText = QObject::tr( "Title: %1" ).arg( m_pPage->title() );
m_dimensionText = QObject::tr( "Dimension: %1x%2" ).
arg( m_pPage->pixmap()->width() ).
arg( m_pPage->pixmap()->height() );
m_dateText = QObject::tr( "Date: %1" ).arg( dateTimeString(m_pPage->lastModified()) );
QColor baseColor = parent->colorGroup().base();
int h, s, v;
baseColor.hsv(&h, &s, &v);
if (v > 128) {
m_alternateColor = baseColor.dark(115);
} else if (baseColor != Qt::black) {
m_alternateColor = baseColor.light(115);
} else {
m_alternateColor = QColor(32, 32, 32);
}
}
PageListBoxItem::~PageListBoxItem()
{
}
int PageListBoxItem::height(const QListBox*) const
{
return QMAX(THUMBNAIL_SIZE + 4, QApplication::globalStrut().height());
}
int PageListBoxItem::width(const QListBox* lb) const
{
QFontMetrics fontMetrics = lb->fontMetrics();
int maxtextLength = QMAX(fontMetrics.width(m_titleText),
QMAX(fontMetrics.width(m_dimensionText),
fontMetrics.width(m_dateText)));
return QMAX(THUMBNAIL_SIZE + maxtextLength + 8, QApplication::globalStrut().width());
}
void PageListBoxItem::paint(QPainter *painter)
{
QRect itemRect = listBox()->itemRect(this);
if (!selected() && (listBox()->index(this) % 2)) {
painter->fillRect(0, 0, itemRect.width(), itemRect.height(), m_alternateColor);
}
painter->drawPixmap(2 + (THUMBNAIL_SIZE - m_thumbnail.width()) / 2,
2 + (THUMBNAIL_SIZE - m_thumbnail.height()) / 2,
m_thumbnail);
QFont standardFont = painter->font();
QFont boldFont = painter->font();
boldFont.setBold(TRUE);
QFontMetrics fontMetrics = painter->fontMetrics();
QRect textRect(THUMBNAIL_SIZE + 6, 2,
itemRect.width() - THUMBNAIL_SIZE - 8,
itemRect.height() - 4);
painter->setFont(boldFont);
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, m_titleText);
painter->setFont(standardFont);
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, m_dimensionText);
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, m_dateText);
if (!selected() && !(listBox()->hasFocus() && listBox()->item(listBox()->currentItem()) == this)) {
painter->drawLine(0, itemRect.height() - 1, itemRect.width() - 1, itemRect.height() - 1);
}
}
Page* PageListBoxItem::page() const
{
return m_pPage;
}
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.append( QString().sprintf("%02d", dateTime.date().day()) );
break;
case 0x0002:
result.append( QString().sprintf("%02d", dateTime.date().month()) );
break;
case 0x0004:
result.append( QString().sprintf("%04d", dateTime.date().year()) );
break;
default:
break;
}
if (i < 2) {
result.append( separator );
}
}
result.append( 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
diff --git a/noncore/graphics/drawpad/tool.cpp b/noncore/graphics/drawpad/tool.cpp
index 0d36912..656078e 100644
--- a/noncore/graphics/drawpad/tool.cpp
+++ b/noncore/graphics/drawpad/tool.cpp
@@ -1,28 +1,26 @@
/***************************************************************************
* *
* 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 "tool.h"
-#include "drawpad.h"
-#include "drawpadcanvas.h"
Tool::Tool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: QObject()
{
m_pDrawPad = drawPad;
m_pDrawPadCanvas = drawPadCanvas;
}
Tool::~Tool()
{
}