summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-10 20:24:06 (UTC)
committer leseb <leseb>2002-06-10 20:24:06 (UTC)
commit743296b2abaa9278ce7b83ebde55fbf2c198e218 (patch) (side-by-side diff)
tree22776ec0e2921fc36a61c9522e8a105e7a3eba13
parent4e125ad47285d36a4be02e8b20b6fa36e387c1bc (diff)
downloadopie-743296b2abaa9278ce7b83ebde55fbf2c198e218.zip
opie-743296b2abaa9278ce7b83ebde55fbf2c198e218.tar.gz
opie-743296b2abaa9278ce7b83ebde55fbf2c198e218.tar.bz2
Thumbnail view ready for page attributes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp150
-rw-r--r--noncore/graphics/drawpad/thumbnailview.h31
2 files changed, 118 insertions, 63 deletions
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 428e008..1eadc13 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -22,5 +22,4 @@
#include <qapplication.h>
-#include <qheader.h>
#include <qimage.h>
#include <qlayout.h>
@@ -28,6 +27,8 @@
#include <qtoolbutton.h>
-PageListViewItem::PageListViewItem(Page* page, QListView* parent)
- : QListViewItem(parent)
+#define THUMBNAIL_SIZE 48
+
+PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent)
+ : QListBoxItem(parent)
{
m_pPage = page;
@@ -35,6 +36,6 @@ PageListViewItem::PageListViewItem(Page* page, QListView* parent)
QImage image = m_pPage->convertToImage();
- int previewWidth = 64;
- int previewHeight = 64;
+ int previewWidth = THUMBNAIL_SIZE;
+ int previewHeight = THUMBNAIL_SIZE;
float widthScale = 1.0;
@@ -50,47 +51,98 @@ PageListViewItem::PageListViewItem(Page* page, QListView* parent)
float scale = (widthScale < heightScale ? widthScale : heightScale);
- QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
+ QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
+
+ m_thumbnail.convertFromImage(thumbnailImage);
- QPixmap previewPixmap;
- previewPixmap.convertFromImage(previewImage);
+ m_titleText = QObject::tr("Title:") + " -";
+ m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->width())
+ + "x" + QString::number(m_pPage->height());
+ m_dateTimeText = QObject::tr("Date:") + " -";
- QPixmap pixmap(64, 64);
+ QColor baseColor = parent->colorGroup().base();
+ int h, s, v;
+ baseColor.hsv(&h, &s, &v);
- pixmap.fill(listView()->colorGroup().mid());
- bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2,
- (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap);
+ 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);
+ }
+}
+
+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)));
- setPixmap(0, pixmap);
+ return QMAX(THUMBNAIL_SIZE + maxtextLength + 8, QApplication::globalStrut().width());
}
-PageListViewItem::~PageListViewItem()
+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_dateTimeText);
+
+ if (!selected() && !(listBox()->hasFocus() && listBox()->item(listBox()->currentItem()) == this)) {
+ painter->drawLine(0, itemRect.height() - 1, itemRect.width() - 1, itemRect.height() - 1);
+ }
}
-Page* PageListViewItem::page() const
+Page* PageListBoxItem::page() const
{
return m_pPage;
}
-PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
- : QListView(parent, name)
+PageListBox::PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
+ : QListBox(parent, name)
{
m_pDrawPadCanvas = drawPadCanvas;
- header()->hide();
setVScrollBarMode(QScrollView::AlwaysOn);
- setAllColumnsShowFocus(true);
-
- addColumn(tr("Thumbnail"));
- addColumn(tr("Information"));
updateView();
}
-PageListView::~PageListView()
+PageListBox::~PageListBox()
{
}
-void PageListView::updateView()
+void PageListBox::updateView()
{
clear();
@@ -101,42 +153,36 @@ void PageListView::updateView()
for (; it.current(); ++it) {
- new PageListViewItem(it.current(), this);
+ new PageListBoxItem(it.current(), this);
}
- setSorting(0, false);
select(m_pDrawPadCanvas->currentPage());
}
}
-void PageListView::resizeEvent(QResizeEvent* e)
+void PageListBox::select(Page* page)
{
- Q_UNUSED(e);
+ uint i = 0;
+ uint itemCount = count();
- setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width());
-}
-
-void PageListView::select(Page* page)
-{
- PageListViewItem* item = (PageListViewItem*)firstChild();
+ while (i < itemCount) {
+ PageListBoxItem* currentItem = (PageListBoxItem*)item(i);
- while (item) {
- if (item->page() == page) {
- setSelected(item, true);
- ensureItemVisible(item);
+ if (currentItem->page() == page) {
+ setCurrentItem(currentItem);
break;
}
- item = (PageListViewItem*)(item->nextSibling());
+ i++;
}
}
-Page* PageListView::selected() const
+Page* PageListBox::selected() const
{
Page* page;
- PageListViewItem* item = (PageListViewItem*)selectedItem();
+ PageListBoxItem* selectedItem = (PageListBoxItem*)item(currentItem());
- if (item) {
- page = item->page();
+ if (selectedItem) {
+ page = selectedItem->page();
} else {
page = NULL;
@@ -181,6 +227,6 @@ ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWi
connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown()));
- m_pPageListView = new PageListView(m_pDrawPadCanvas, this);
- connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage()));
+ m_pPageListBox = new PageListBox(m_pDrawPadCanvas, this);
+ connect(m_pPageListBox, SIGNAL(selectionChanged()), this, SLOT(changePage()));
QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
@@ -195,5 +241,5 @@ ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWi
mainLayout->addLayout(buttonLayout);
- mainLayout->addWidget(m_pPageListView);
+ mainLayout->addWidget(m_pPageListBox);
updateView();
@@ -241,5 +287,5 @@ void ThumbnailView::newPage()
m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(),
newPageDialog.selectedColor());
- m_pPageListView->updateView();
+ m_pPageListBox->updateView();
updateView();
}
@@ -258,5 +304,5 @@ void ThumbnailView::clearPage()
if (messageBox.exec() == QMessageBox::Yes) {
m_pDrawPadCanvas->clearPage();
- m_pPageListView->updateView();
+ m_pPageListBox->updateView();
}
}
@@ -274,5 +320,5 @@ void ThumbnailView::deletePage()
if (messageBox.exec() == QMessageBox::Yes) {
m_pDrawPadCanvas->deletePage();
- m_pPageListView->updateView();
+ m_pPageListBox->updateView();
updateView();
}
@@ -282,5 +328,5 @@ void ThumbnailView::movePageUp()
{
m_pDrawPadCanvas->movePageUp();
- m_pPageListView->updateView();
+ m_pPageListBox->updateView();
updateView();
}
@@ -289,5 +335,5 @@ void ThumbnailView::movePageDown()
{
m_pDrawPadCanvas->movePageDown();
- m_pPageListView->updateView();
+ m_pPageListBox->updateView();
updateView();
}
@@ -295,5 +341,5 @@ void ThumbnailView::movePageDown()
void ThumbnailView::changePage()
{
- m_pDrawPadCanvas->selectPage(m_pPageListView->selected());
+ m_pDrawPadCanvas->selectPage(m_pPageListBox->selected());
updateView();
}
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h
index eb748fa..88c3b27 100644
--- a/noncore/graphics/drawpad/thumbnailview.h
+++ b/noncore/graphics/drawpad/thumbnailview.h
@@ -15,6 +15,6 @@
#define THUMBNAILVIEW_H
+#include <qlistbox.h>
#include <qwidget.h>
-#include <qlistview.h>
class DrawPad;
@@ -24,9 +24,13 @@ class Page;
class QToolButton;
-class PageListViewItem : public QListViewItem
+class PageListBoxItem : public QListBoxItem
{
public:
- PageListViewItem(Page* page, QListView* parent);
- ~PageListViewItem();
+ 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;
@@ -34,11 +38,19 @@ public:
private:
Page* m_pPage;
+
+ QPixmap m_thumbnail;
+
+ QString m_titleText;
+ QString m_dimensionText;
+ QString m_dateTimeText;
+
+ QColor m_alternateColor;
};
-class PageListView : public QListView
+class PageListBox : public QListBox
{
public:
- PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
- ~PageListView();
+ PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0);
+ ~PageListBox();
void updateView();
@@ -47,7 +59,4 @@ public:
Page* selected() const;
-protected:
- void resizeEvent(QResizeEvent* e);
-
private:
DrawPadCanvas* m_pDrawPadCanvas;
@@ -84,5 +93,5 @@ private:
QToolButton* m_pMovePageDownButton;
- PageListView* m_pPageListView;
+ PageListBox* m_pPageListBox;
};