summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-14 19:15:16 (UTC)
committer leseb <leseb>2002-06-14 19:15:16 (UTC)
commit251404b1ad7c5712270233821699ab8492fe76ac (patch) (side-by-side diff)
treeb78e72bd4d420e95951eca8b5f5015cf405f2f9c
parent0aa515c2f050a85dbaf7b20b7a3c3fc12a213ed1 (diff)
downloadopie-251404b1ad7c5712270233821699ab8492fe76ac.zip
opie-251404b1ad7c5712270233821699ab8492fe76ac.tar.gz
opie-251404b1ad7c5712270233821699ab8492fe76ac.tar.bz2
Minor fixes
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpadcanvas.cpp4
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp4
2 files changed, 4 insertions, 4 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp
index dcf0871..4547b41 100644
--- a/noncore/graphics/drawpad/drawpadcanvas.cpp
+++ b/noncore/graphics/drawpad/drawpadcanvas.cpp
@@ -1,586 +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 == "image") {
m_title = QString();
- m_date = QDateTime(QDate(1970, 1, 1));
+ 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");
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 == "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 = m_date.addSecs(ch.toInt());
+ 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;
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(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.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.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()
{
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.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(QString title, uint width, uint height, const QColor& color)
{
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.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/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 81ec79f..14092bf 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -1,382 +1,382 @@
/***************************************************************************
* *
* 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>
#define THUMBNAIL_SIZE 48
PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent)
: QListBoxItem(parent)
{
m_pPage = page;
QImage image = m_pPage->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:") + " " + m_pPage->title();
m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->width())
+ "x" + QString::number(m_pPage->height());
m_dateText = QObject::tr("Date:") + " " + 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(106);
+ m_alternateColor = baseColor.dark(115);
} else if (baseColor != Qt::black) {
- m_alternateColor = baseColor.light(110);
+ 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 += 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.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();
}