author | leseb <leseb> | 2002-06-13 17:11:03 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-13 17:11:03 (UTC) |
commit | 615176c17202f1a8aa7aa504b8dd747b089385a9 (patch) (side-by-side diff) | |
tree | b5906e134037cd72871e0cecac4a3c9ed4c9a9e2 | |
parent | 54de91b66a2f0f985ff89503e919f85713d1f22c (diff) | |
download | opie-615176c17202f1a8aa7aa504b8dd747b089385a9.zip opie-615176c17202f1a8aa7aa504b8dd747b089385a9.tar.gz opie-615176c17202f1a8aa7aa504b8dd747b089385a9.tar.bz2 |
More progress in page attributes
-rw-r--r-- | noncore/graphics/drawpad/page.cpp | 24 | ||||
-rw-r--r-- | noncore/graphics/drawpad/page.h | 12 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pageinformationdialog.cpp | 49 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pageinformationdialog.h | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 45 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.h | 6 |
6 files changed, 134 insertions, 6 deletions
diff --git a/noncore/graphics/drawpad/page.cpp b/noncore/graphics/drawpad/page.cpp index 35ec0e0..7034a20 100644 --- a/noncore/graphics/drawpad/page.cpp +++ b/noncore/graphics/drawpad/page.cpp @@ -7,27 +7,51 @@ * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "page.h" Page::Page() : QPixmap() { + m_lastModified = QDateTime::currentDateTime(); } Page::Page(int w, int h) : QPixmap(w, h) { + m_lastModified = QDateTime::currentDateTime(); } Page::Page(const QSize& size) : QPixmap(size) { + m_lastModified = QDateTime::currentDateTime(); } Page::~Page() { } + +QString Page::title() const +{ + return m_title; +} + +QDateTime Page::lastModified() const +{ + return m_lastModified; +} + +void Page::setTitle(QString title) +{ + m_title = title; +} + +void Page::setLastModified(QDateTime lastModified) +{ + m_lastModified = lastModified; +} + diff --git a/noncore/graphics/drawpad/page.h b/noncore/graphics/drawpad/page.h index 888f552..020ab1f 100644 --- a/noncore/graphics/drawpad/page.h +++ b/noncore/graphics/drawpad/page.h @@ -7,23 +7,35 @@ * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef PAGE_H #define PAGE_H #include <qpixmap.h> +#include <qdatetime.h> + class Page : public QPixmap { public: Page(); Page(int w, int h); Page(const QSize& size); ~Page(); + + QString title() const; + QDateTime lastModified() const; + + void setTitle(QString title); + void setLastModified(QDateTime lastModified); + +private: + QString m_title; + QDateTime m_lastModified; }; #endif // PAGE_H diff --git a/noncore/graphics/drawpad/pageinformationdialog.cpp b/noncore/graphics/drawpad/pageinformationdialog.cpp index 54cf89d..c0d055e 100644 --- a/noncore/graphics/drawpad/pageinformationdialog.cpp +++ b/noncore/graphics/drawpad/pageinformationdialog.cpp @@ -6,65 +6,112 @@ * * * 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 "pageinformationdialog.h" #include "page.h" +#include <qpe/config.h> +#include <qpe/timestring.h> + #include <qgroupbox.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> PageInformationDialog::PageInformationDialog(Page* page, QWidget* parent, const char* name) : QDialog(parent, name, true) { m_pPage = page; setCaption(tr("Page Information")); QGroupBox* generalGroupBox = new QGroupBox(0, Qt::Vertical, tr("General"), this); QLabel* titleLabel = new QLabel(tr("Title:"), generalGroupBox); + m_pTitleLineEdit = new QLineEdit(generalGroupBox); + m_pTitleLineEdit->setText(page->title()); + + QLabel* dateLabel = new QLabel(tr("Date:"), generalGroupBox); + QLabel* dateValueLabel = new QLabel(dateTimeString(m_pPage->lastModified()), generalGroupBox); QGroupBox* sizeGroupBox = new QGroupBox(0, Qt::Vertical, tr("Size"), this); QLabel* widthLabel = new QLabel(tr("Width:"), sizeGroupBox); QLabel* widthValueLabel = new QLabel(QString::number(m_pPage->width()), sizeGroupBox); QLabel* heightLabel = new QLabel(tr("Height:"), sizeGroupBox); QLabel* heightValueLabel = new QLabel(QString::number(m_pPage->height()), sizeGroupBox); QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); generalGroupBox->layout()->setSpacing(4); sizeGroupBox->layout()->setSpacing(4); - QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 1, 1); + QGridLayout* generalLayout = new QGridLayout(generalGroupBox->layout(), 2, 2); QGridLayout* sizeLayout = new QGridLayout(sizeGroupBox->layout(), 2, 2); generalLayout->addWidget(titleLabel, 0, 0); generalLayout->addWidget(m_pTitleLineEdit, 0, 1); + generalLayout->addWidget(dateLabel, 1, 0); + generalLayout->addWidget(dateValueLabel, 1, 1); + + generalLayout->setColStretch(1, 1); sizeLayout->addWidget(widthLabel, 0, 0); sizeLayout->addWidget(widthValueLabel, 0, 1); sizeLayout->addWidget(heightLabel, 1, 0); sizeLayout->addWidget(heightValueLabel, 1, 1); sizeLayout->setColStretch(1, 1); mainLayout->addWidget(generalGroupBox); mainLayout->addWidget(sizeGroupBox); } PageInformationDialog::~PageInformationDialog() { } QString PageInformationDialog::selectedTitle() { return (m_pTitleLineEdit->text()); } + +QString PageInformationDialog::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; +} diff --git a/noncore/graphics/drawpad/pageinformationdialog.h b/noncore/graphics/drawpad/pageinformationdialog.h index cce74ec..60662a9 100644 --- a/noncore/graphics/drawpad/pageinformationdialog.h +++ b/noncore/graphics/drawpad/pageinformationdialog.h @@ -9,31 +9,35 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef PAGEINFORMATIONDIALOG_H #define PAGEINFORMATIONDIALOG_H #include <qdialog.h> class Page; +#include <qdatetime.h> + class QLineEdit; class PageInformationDialog : public QDialog { Q_OBJECT public: PageInformationDialog(Page* page, QWidget* parent = 0, const char* name = 0); ~PageInformationDialog(); QString selectedTitle(); private: + QString dateTimeString(QDateTime dateTime); + Page* m_pPage; QLineEdit* m_pTitleLineEdit; }; #endif // PAGEINFORMATIONDIALOG_H diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp index 1eadc13..35955e8 100644 --- a/noncore/graphics/drawpad/thumbnailview.cpp +++ b/noncore/graphics/drawpad/thumbnailview.cpp @@ -9,25 +9,27 @@ * 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) { @@ -45,28 +47,28 @@ PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) 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_titleText = QObject::tr("Title:") + " " + m_pPage->title(); m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->width()) + "x" + QString::number(m_pPage->height()); - m_dateTimeText = QObject::tr("Date:") + " -"; + 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); } else if (baseColor != Qt::black) { m_alternateColor = baseColor.light(110); } else { m_alternateColor = QColor(32, 32, 32); } @@ -77,25 +79,25 @@ 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_dateTimeText))); + 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); } @@ -108,36 +110,71 @@ void PageListBoxItem::paint(QPainter *painter) 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_dateTimeText); + 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() { diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h index 88c3b27..2eac667 100644 --- a/noncore/graphics/drawpad/thumbnailview.h +++ b/noncore/graphics/drawpad/thumbnailview.h @@ -12,46 +12,50 @@ ***************************************************************************/ #ifndef THUMBNAILVIEW_H #define THUMBNAILVIEW_H #include <qlistbox.h> #include <qwidget.h> class DrawPad; class DrawPadCanvas; class Page; +#include <qdatetime.h> + class QToolButton; class PageListBoxItem : public QListBoxItem { public: PageListBoxItem(Page* page, QListBox* parent); ~PageListBoxItem(); int height(const QListBox* lb) const; int width(const QListBox* lb) const; void paint(QPainter *painter); Page* page() const; private: + QString dateTimeString(QDateTime dateTime); + Page* m_pPage; QPixmap m_thumbnail; QString m_titleText; QString m_dimensionText; - QString m_dateTimeText; + QString m_dateText; QColor m_alternateColor; }; class PageListBox : public QListBox { public: PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); ~PageListBox(); void updateView(); |