-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 150 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.h | 31 |
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 | |||
@@ -21,21 +21,22 @@ | |||
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | 22 | ||
23 | #include <qapplication.h> | 23 | #include <qapplication.h> |
24 | #include <qheader.h> | ||
25 | #include <qimage.h> | 24 | #include <qimage.h> |
26 | #include <qlayout.h> | 25 | #include <qlayout.h> |
27 | #include <qmessagebox.h> | 26 | #include <qmessagebox.h> |
28 | #include <qtoolbutton.h> | 27 | #include <qtoolbutton.h> |
29 | 28 | ||
30 | PageListViewItem::PageListViewItem(Page* page, QListView* parent) | 29 | #define THUMBNAIL_SIZE 48 |
31 | : QListViewItem(parent) | 30 | |
31 | PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) | ||
32 | : QListBoxItem(parent) | ||
32 | { | 33 | { |
33 | m_pPage = page; | 34 | m_pPage = page; |
34 | 35 | ||
35 | QImage image = m_pPage->convertToImage(); | 36 | QImage image = m_pPage->convertToImage(); |
36 | 37 | ||
37 | int previewWidth = 64; | 38 | int previewWidth = THUMBNAIL_SIZE; |
38 | int previewHeight = 64; | 39 | int previewHeight = THUMBNAIL_SIZE; |
39 | 40 | ||
40 | float widthScale = 1.0; | 41 | float widthScale = 1.0; |
41 | float heightScale = 1.0; | 42 | float heightScale = 1.0; |
@@ -49,49 +50,100 @@ PageListViewItem::PageListViewItem(Page* page, QListView* parent) | |||
49 | } | 50 | } |
50 | 51 | ||
51 | float scale = (widthScale < heightScale ? widthScale : heightScale); | 52 | float scale = (widthScale < heightScale ? widthScale : heightScale); |
52 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | 53 | QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); |
54 | |||
55 | m_thumbnail.convertFromImage(thumbnailImage); | ||
53 | 56 | ||
54 | QPixmap previewPixmap; | 57 | m_titleText = QObject::tr("Title:") + " -"; |
55 | previewPixmap.convertFromImage(previewImage); | 58 | m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->width()) |
59 | + "x" + QString::number(m_pPage->height()); | ||
60 | m_dateTimeText = QObject::tr("Date:") + " -"; | ||
56 | 61 | ||
57 | QPixmap pixmap(64, 64); | 62 | QColor baseColor = parent->colorGroup().base(); |
63 | int h, s, v; | ||
64 | baseColor.hsv(&h, &s, &v); | ||
58 | 65 | ||
59 | pixmap.fill(listView()->colorGroup().mid()); | 66 | if (v > 128) { |
60 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, | 67 | m_alternateColor = baseColor.dark(106); |
61 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); | 68 | } else if (baseColor != Qt::black) { |
69 | m_alternateColor = baseColor.light(110); | ||
70 | } else { | ||
71 | m_alternateColor = QColor(32, 32, 32); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | PageListBoxItem::~PageListBoxItem() | ||
76 | { | ||
77 | } | ||
78 | |||
79 | int PageListBoxItem::height(const QListBox*) const | ||
80 | { | ||
81 | return QMAX(THUMBNAIL_SIZE + 4, QApplication::globalStrut().height()); | ||
82 | } | ||
83 | |||
84 | int PageListBoxItem::width(const QListBox* lb) const | ||
85 | { | ||
86 | QFontMetrics fontMetrics = lb->fontMetrics(); | ||
87 | int maxtextLength = QMAX(fontMetrics.width(m_titleText), | ||
88 | QMAX(fontMetrics.width(m_dimensionText), | ||
89 | fontMetrics.width(m_dateTimeText))); | ||
62 | 90 | ||
63 | setPixmap(0, pixmap); | 91 | return QMAX(THUMBNAIL_SIZE + maxtextLength + 8, QApplication::globalStrut().width()); |
64 | } | 92 | } |
65 | 93 | ||
66 | PageListViewItem::~PageListViewItem() | 94 | void PageListBoxItem::paint(QPainter *painter) |
67 | { | 95 | { |
96 | QRect itemRect = listBox()->itemRect(this); | ||
97 | |||
98 | if (!selected() && (listBox()->index(this) % 2)) { | ||
99 | painter->fillRect(0, 0, itemRect.width(), itemRect.height(), m_alternateColor); | ||
68 | } | 100 | } |
69 | 101 | ||
70 | Page* PageListViewItem::page() const | 102 | painter->drawPixmap(2 + (THUMBNAIL_SIZE - m_thumbnail.width()) / 2, |
103 | 2 + (THUMBNAIL_SIZE - m_thumbnail.height()) / 2, | ||
104 | m_thumbnail); | ||
105 | |||
106 | QFont standardFont = painter->font(); | ||
107 | QFont boldFont = painter->font(); | ||
108 | boldFont.setBold(TRUE); | ||
109 | |||
110 | QFontMetrics fontMetrics = painter->fontMetrics(); | ||
111 | QRect textRect(THUMBNAIL_SIZE + 6, 2, | ||
112 | itemRect.width() - THUMBNAIL_SIZE - 8, | ||
113 | itemRect.height() - 4); | ||
114 | |||
115 | painter->setFont(boldFont); | ||
116 | painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, m_titleText); | ||
117 | |||
118 | painter->setFont(standardFont); | ||
119 | painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, m_dimensionText); | ||
120 | painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, m_dateTimeText); | ||
121 | |||
122 | if (!selected() && !(listBox()->hasFocus() && listBox()->item(listBox()->currentItem()) == this)) { | ||
123 | painter->drawLine(0, itemRect.height() - 1, itemRect.width() - 1, itemRect.height() - 1); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | Page* PageListBoxItem::page() const | ||
71 | { | 128 | { |
72 | return m_pPage; | 129 | return m_pPage; |
73 | } | 130 | } |
74 | 131 | ||
75 | PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) | 132 | PageListBox::PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) |
76 | : QListView(parent, name) | 133 | : QListBox(parent, name) |
77 | { | 134 | { |
78 | m_pDrawPadCanvas = drawPadCanvas; | 135 | m_pDrawPadCanvas = drawPadCanvas; |
79 | 136 | ||
80 | header()->hide(); | ||
81 | setVScrollBarMode(QScrollView::AlwaysOn); | 137 | setVScrollBarMode(QScrollView::AlwaysOn); |
82 | setAllColumnsShowFocus(true); | ||
83 | |||
84 | addColumn(tr("Thumbnail")); | ||
85 | addColumn(tr("Information")); | ||
86 | 138 | ||
87 | updateView(); | 139 | updateView(); |
88 | } | 140 | } |
89 | 141 | ||
90 | PageListView::~PageListView() | 142 | PageListBox::~PageListBox() |
91 | { | 143 | { |
92 | } | 144 | } |
93 | 145 | ||
94 | void PageListView::updateView() | 146 | void PageListBox::updateView() |
95 | { | 147 | { |
96 | clear(); | 148 | clear(); |
97 | 149 | ||
@@ -100,44 +152,38 @@ void PageListView::updateView() | |||
100 | QListIterator<Page> it(pageList); | 152 | QListIterator<Page> it(pageList); |
101 | 153 | ||
102 | for (; it.current(); ++it) { | 154 | for (; it.current(); ++it) { |
103 | new PageListViewItem(it.current(), this); | 155 | new PageListBoxItem(it.current(), this); |
104 | } | 156 | } |
105 | 157 | ||
106 | setSorting(0, false); | ||
107 | select(m_pDrawPadCanvas->currentPage()); | 158 | select(m_pDrawPadCanvas->currentPage()); |
108 | } | 159 | } |
109 | } | 160 | } |
110 | 161 | ||
111 | void PageListView::resizeEvent(QResizeEvent* e) | 162 | void PageListBox::select(Page* page) |
112 | { | 163 | { |
113 | Q_UNUSED(e); | 164 | uint i = 0; |
165 | uint itemCount = count(); | ||
114 | 166 | ||
115 | setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); | 167 | while (i < itemCount) { |
116 | } | 168 | PageListBoxItem* currentItem = (PageListBoxItem*)item(i); |
117 | |||
118 | void PageListView::select(Page* page) | ||
119 | { | ||
120 | PageListViewItem* item = (PageListViewItem*)firstChild(); | ||
121 | 169 | ||
122 | while (item) { | 170 | if (currentItem->page() == page) { |
123 | if (item->page() == page) { | 171 | setCurrentItem(currentItem); |
124 | setSelected(item, true); | ||
125 | ensureItemVisible(item); | ||
126 | break; | 172 | break; |
127 | } | 173 | } |
128 | 174 | ||
129 | item = (PageListViewItem*)(item->nextSibling()); | 175 | i++; |
130 | } | 176 | } |
131 | } | 177 | } |
132 | 178 | ||
133 | Page* PageListView::selected() const | 179 | Page* PageListBox::selected() const |
134 | { | 180 | { |
135 | Page* page; | 181 | Page* page; |
136 | 182 | ||
137 | PageListViewItem* item = (PageListViewItem*)selectedItem(); | 183 | PageListBoxItem* selectedItem = (PageListBoxItem*)item(currentItem()); |
138 | 184 | ||
139 | if (item) { | 185 | if (selectedItem) { |
140 | page = item->page(); | 186 | page = selectedItem->page(); |
141 | } else { | 187 | } else { |
142 | page = NULL; | 188 | page = NULL; |
143 | } | 189 | } |
@@ -180,8 +226,8 @@ ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWi | |||
180 | m_pMovePageDownButton->setAutoRaise(true); | 226 | m_pMovePageDownButton->setAutoRaise(true); |
181 | connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown())); | 227 | connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown())); |
182 | 228 | ||
183 | m_pPageListView = new PageListView(m_pDrawPadCanvas, this); | 229 | m_pPageListBox = new PageListBox(m_pDrawPadCanvas, this); |
184 | connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage())); | 230 | connect(m_pPageListBox, SIGNAL(selectionChanged()), this, SLOT(changePage())); |
185 | 231 | ||
186 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 232 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
187 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); | 233 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); |
@@ -194,7 +240,7 @@ ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWi | |||
194 | buttonLayout->addWidget(m_pMovePageDownButton); | 240 | buttonLayout->addWidget(m_pMovePageDownButton); |
195 | 241 | ||
196 | mainLayout->addLayout(buttonLayout); | 242 | mainLayout->addLayout(buttonLayout); |
197 | mainLayout->addWidget(m_pPageListView); | 243 | mainLayout->addWidget(m_pPageListBox); |
198 | 244 | ||
199 | updateView(); | 245 | updateView(); |
200 | } | 246 | } |
@@ -240,7 +286,7 @@ void ThumbnailView::newPage() | |||
240 | if (newPageDialog.exec() == QDialog::Accepted) { | 286 | if (newPageDialog.exec() == QDialog::Accepted) { |
241 | m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(), | 287 | m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(), |
242 | newPageDialog.selectedColor()); | 288 | newPageDialog.selectedColor()); |
243 | m_pPageListView->updateView(); | 289 | m_pPageListBox->updateView(); |
244 | updateView(); | 290 | updateView(); |
245 | } | 291 | } |
246 | } | 292 | } |
@@ -257,7 +303,7 @@ void ThumbnailView::clearPage() | |||
257 | 303 | ||
258 | if (messageBox.exec() == QMessageBox::Yes) { | 304 | if (messageBox.exec() == QMessageBox::Yes) { |
259 | m_pDrawPadCanvas->clearPage(); | 305 | m_pDrawPadCanvas->clearPage(); |
260 | m_pPageListView->updateView(); | 306 | m_pPageListBox->updateView(); |
261 | } | 307 | } |
262 | } | 308 | } |
263 | 309 | ||
@@ -273,7 +319,7 @@ void ThumbnailView::deletePage() | |||
273 | 319 | ||
274 | if (messageBox.exec() == QMessageBox::Yes) { | 320 | if (messageBox.exec() == QMessageBox::Yes) { |
275 | m_pDrawPadCanvas->deletePage(); | 321 | m_pDrawPadCanvas->deletePage(); |
276 | m_pPageListView->updateView(); | 322 | m_pPageListBox->updateView(); |
277 | updateView(); | 323 | updateView(); |
278 | } | 324 | } |
279 | } | 325 | } |
@@ -281,19 +327,19 @@ void ThumbnailView::deletePage() | |||
281 | void ThumbnailView::movePageUp() | 327 | void ThumbnailView::movePageUp() |
282 | { | 328 | { |
283 | m_pDrawPadCanvas->movePageUp(); | 329 | m_pDrawPadCanvas->movePageUp(); |
284 | m_pPageListView->updateView(); | 330 | m_pPageListBox->updateView(); |
285 | updateView(); | 331 | updateView(); |
286 | } | 332 | } |
287 | 333 | ||
288 | void ThumbnailView::movePageDown() | 334 | void ThumbnailView::movePageDown() |
289 | { | 335 | { |
290 | m_pDrawPadCanvas->movePageDown(); | 336 | m_pDrawPadCanvas->movePageDown(); |
291 | m_pPageListView->updateView(); | 337 | m_pPageListBox->updateView(); |
292 | updateView(); | 338 | updateView(); |
293 | } | 339 | } |
294 | 340 | ||
295 | void ThumbnailView::changePage() | 341 | void ThumbnailView::changePage() |
296 | { | 342 | { |
297 | m_pDrawPadCanvas->selectPage(m_pPageListView->selected()); | 343 | m_pDrawPadCanvas->selectPage(m_pPageListBox->selected()); |
298 | updateView(); | 344 | updateView(); |
299 | } | 345 | } |
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 | |||
@@ -14,8 +14,8 @@ | |||
14 | #ifndef THUMBNAILVIEW_H | 14 | #ifndef THUMBNAILVIEW_H |
15 | #define THUMBNAILVIEW_H | 15 | #define THUMBNAILVIEW_H |
16 | 16 | ||
17 | #include <qlistbox.h> | ||
17 | #include <qwidget.h> | 18 | #include <qwidget.h> |
18 | #include <qlistview.h> | ||
19 | 19 | ||
20 | class DrawPad; | 20 | class DrawPad; |
21 | class DrawPadCanvas; | 21 | class DrawPadCanvas; |
@@ -23,32 +23,41 @@ class Page; | |||
23 | 23 | ||
24 | class QToolButton; | 24 | class QToolButton; |
25 | 25 | ||
26 | class PageListViewItem : public QListViewItem | 26 | class PageListBoxItem : public QListBoxItem |
27 | { | 27 | { |
28 | public: | 28 | public: |
29 | PageListViewItem(Page* page, QListView* parent); | 29 | PageListBoxItem(Page* page, QListBox* parent); |
30 | ~PageListViewItem(); | 30 | ~PageListBoxItem(); |
31 | |||
32 | int height(const QListBox* lb) const; | ||
33 | int width(const QListBox* lb) const; | ||
34 | void paint(QPainter *painter); | ||
31 | 35 | ||
32 | Page* page() const; | 36 | Page* page() const; |
33 | 37 | ||
34 | private: | 38 | private: |
35 | Page* m_pPage; | 39 | Page* m_pPage; |
40 | |||
41 | QPixmap m_thumbnail; | ||
42 | |||
43 | QString m_titleText; | ||
44 | QString m_dimensionText; | ||
45 | QString m_dateTimeText; | ||
46 | |||
47 | QColor m_alternateColor; | ||
36 | }; | 48 | }; |
37 | 49 | ||
38 | class PageListView : public QListView | 50 | class PageListBox : public QListBox |
39 | { | 51 | { |
40 | public: | 52 | public: |
41 | PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); | 53 | PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); |
42 | ~PageListView(); | 54 | ~PageListBox(); |
43 | 55 | ||
44 | void updateView(); | 56 | void updateView(); |
45 | 57 | ||
46 | void select(Page* page); | 58 | void select(Page* page); |
47 | Page* selected() const; | 59 | Page* selected() const; |
48 | 60 | ||
49 | protected: | ||
50 | void resizeEvent(QResizeEvent* e); | ||
51 | |||
52 | private: | 61 | private: |
53 | DrawPadCanvas* m_pDrawPadCanvas; | 62 | DrawPadCanvas* m_pDrawPadCanvas; |
54 | }; | 63 | }; |
@@ -83,7 +92,7 @@ private: | |||
83 | QToolButton* m_pMovePageUpButton; | 92 | QToolButton* m_pMovePageUpButton; |
84 | QToolButton* m_pMovePageDownButton; | 93 | QToolButton* m_pMovePageDownButton; |
85 | 94 | ||
86 | PageListView* m_pPageListView; | 95 | PageListBox* m_pPageListBox; |
87 | }; | 96 | }; |
88 | 97 | ||
89 | #endif // THUMBNAILVIEW_H | 98 | #endif // THUMBNAILVIEW_H |