summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-26 14:17:12 (UTC)
committer leseb <leseb>2002-06-26 14:17:12 (UTC)
commit531bb3c03f5576523a3c7ccecc714362507f69e1 (patch) (side-by-side diff)
tree8bdda021e3ddd110ca75df06a1f6a5fbf0429a6c
parent527c3a7240bee3fe1d7c000aecc8ff0a01219fdd (diff)
downloadopie-531bb3c03f5576523a3c7ccecc714362507f69e1.zip
opie-531bb3c03f5576523a3c7ccecc714362507f69e1.tar.gz
opie-531bb3c03f5576523a3c7ccecc714362507f69e1.tar.bz2
Add application config
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.cpp39
-rw-r--r--noncore/graphics/drawpad/drawpad.h6
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp13
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.h1
4 files changed, 54 insertions, 5 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp
index b29f5ba..4eb47a5 100644
--- a/noncore/graphics/drawpad/drawpad.cpp
+++ b/noncore/graphics/drawpad/drawpad.cpp
@@ -13,48 +13,49 @@
#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 <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()));
@@ -207,93 +208,97 @@ DrawPad::DrawPad(QWidget* parent, const char* name)
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)));
+ m_pPenWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar);
+ connect(m_pPenWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int)));
- QToolTip::add(penWidthSpinBox, tr("Pen Width"));
- penWidthSpinBox->setValue(1);
- penWidthSpinBox->setFocusPolicy(QWidget::NoFocus);
+ QToolTip::add(m_pPenWidthSpinBox, tr("Pen Width"));
+ m_pPenWidthSpinBox->setValue(1);
+ m_pPenWidthSpinBox->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();
}
+
+ loadConfig();
}
DrawPad::~DrawPad()
{
+ saveConfig();
+
QFile file(Global::applicationFileName("drawpad", "drawpad.xml"));
if (file.open(IO_WriteOnly)) {
m_pDrawPadCanvas->save(&file);
file.close();
}
}
bool DrawPad::antiAliasing()
{
return (m_pAntiAliasingAction->isOn());
}
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.selectedTitle(), newPageDialog.selectedWidth(),
newPageDialog.selectedHeight(), newPageDialog.selectedColor());
}
}
@@ -598,24 +603,48 @@ void DrawPad::exportPage()
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());
}
}
+
+void DrawPad::loadConfig()
+{
+ Config config("drawpad");
+ config.setGroup("General");
+
+ m_pAntiAliasingAction->setOn(config.readBoolEntry("AntiAliasing", false));
+ m_pPenWidthSpinBox->setValue(config.readNumEntry("PenWidth", 1));
+ changePenColor(QColor(config.readEntry("PenColor", Qt::black.name())));
+ changeBrushColor(QColor(config.readEntry("BrushColor", Qt::white.name())));
+ m_pDrawPadCanvas->selectPage(config.readNumEntry("PagePosition", 1));
+}
+
+void DrawPad::saveConfig()
+{
+ Config config("drawpad");
+ config.setGroup("General");
+
+ config.writeEntry("PagePosition", (int)m_pDrawPadCanvas->pagePosition());
+ config.writeEntry("AntiAliasing", antiAliasing());
+ config.writeEntry("PenWidth", (int)m_pen.width());
+ config.writeEntry("PenColor", m_pen.color().name());
+ config.writeEntry("BrushColor", m_brush.color().name());
+}
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index 8e29c61..c57606c 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -2,105 +2,111 @@
* *
* 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 DRAWPAD_H
#define DRAWPAD_H
#include <qmainwindow.h>
#include <qpen.h>
class DrawPadCanvas;
class Tool;
class QAction;
class QColor;
+class QSpinBox;
class QToolButton;
class QWidgetStack;
class DrawPad : public QMainWindow
{
Q_OBJECT
public:
DrawPad(QWidget* parent = 0, const char* name = 0);
~DrawPad();
Tool* tool() { return m_pTool; }
QPen pen() { return m_pen; }
QBrush brush() { return m_brush; }
bool antiAliasing();
private slots:
void newPage();
void clearPage();
void deletePage();
void setPointTool();
void setLineTool();
void setRectangleTool();
void setFilledRectangleTool();
void setEllipseTool();
void setFilledEllipseTool();
void setTextTool();
void setFillTool();
void setEraseTool();
void changePenWidth(int value);
void changePenColor(const QColor& color);
void changeBrushColor(const QColor& color);
void updateUndoRedoToolButtons();
void updateNavigationToolButtons();
void updateCaption();
void deleteAll();
void importPage();
void exportPage();
void thumbnailView();
void pageInformation();
private:
+ void loadConfig();
+ void saveConfig();
+
DrawPadCanvas* m_pDrawPadCanvas;
Tool* m_pTool;
QPen m_pen;
QBrush m_brush;
QAction* m_pAntiAliasingAction;
QAction* m_pUndoAction;
QAction* m_pRedoAction;
QAction* m_pFirstPageAction;
QAction* m_pPreviousPageAction;
QAction* m_pNextPageAction;
QAction* m_pLastPageAction;
QAction* m_pPointToolAction;
QAction* m_pLineToolAction;
QAction* m_pRectangleToolAction;
QAction* m_pFilledRectangleToolAction;
QAction* m_pEllipseToolAction;
QAction* m_pFilledEllipseToolAction;
QAction* m_pTextToolAction;
QAction* m_pFillToolAction;
QAction* m_pEraseToolAction;
QToolButton* m_pLineToolButton;
QToolButton* m_pRectangleToolButton;
QToolButton* m_pEllipseToolButton;
QToolButton* m_pPenColorToolButton;
QToolButton* m_pBrushColorToolButton;
+
+ QSpinBox* m_pPenWidthSpinBox;
};
#endif // DRAWPAD_H
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index 5437068..05dd408 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -325,48 +325,61 @@ QList<Page> DrawPadCanvas::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::selectPage(uint pagePosition)
+{
+ m_pages.at(pagePosition - 1);
+ 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()
{
m_pages.current()->setLastModified(QDateTime::currentDateTime());
Page* currentBackup = m_pageBackups.current();
while (m_pageBackups.last() != currentBackup) {
m_pageBackups.removeLast();
}
while (m_pageBackups.count() >= (PAGE_BACKUPS + 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.current()->fill(Qt::white);
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h
index dcaff5c..2283e5e 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.h
+++ b/noncore/graphics/drawpad/drawpadcanvas.h
@@ -27,48 +27,49 @@ 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 selectPage(uint pagePosition);
void backupPage();
public slots:
void deleteAll();
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);