Diffstat (limited to 'noncore/graphics/drawpad/thumbnailview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp new file mode 100644 index 0000000..10ade90 --- a/dev/null +++ b/noncore/graphics/drawpad/thumbnailview.cpp | |||
@@ -0,0 +1,121 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * DrawPad - a drawing program for Opie Environment * | ||
4 | * * | ||
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | ||
6 | * * | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | * * | ||
12 | ***************************************************************************/ | ||
13 | |||
14 | #include "thumbnailview.h" | ||
15 | |||
16 | #include "page.h" | ||
17 | |||
18 | #include <qpe/resource.h> | ||
19 | |||
20 | #include <qheader.h> | ||
21 | #include <qimage.h> | ||
22 | #include <qlayout.h> | ||
23 | #include <qlistview.h> | ||
24 | #include <qtoolbutton.h> | ||
25 | |||
26 | ThumbnailView::ThumbnailView(QList<Page> pages, QWidget* parent, const char* name) | ||
27 | : QDialog(parent, name, true) | ||
28 | { | ||
29 | setCaption(tr("Thumbnail")); | ||
30 | |||
31 | QToolButton* newPageButton = new QToolButton(this); | ||
32 | newPageButton->setIconSet(Resource::loadIconSet("new")); | ||
33 | newPageButton->setAutoRaise(true); | ||
34 | |||
35 | QToolButton* clearPageButton = new QToolButton(this); | ||
36 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | ||
37 | clearPageButton->setAutoRaise(true); | ||
38 | |||
39 | QToolButton* deletePageButton = new QToolButton(this); | ||
40 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | ||
41 | deletePageButton->setAutoRaise(true); | ||
42 | |||
43 | QToolButton* movePageUpButton = new QToolButton(this); | ||
44 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | ||
45 | movePageUpButton->setAutoRaise(true); | ||
46 | |||
47 | QToolButton* movePageDownButton = new QToolButton(this); | ||
48 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | ||
49 | movePageDownButton->setAutoRaise(true); | ||
50 | |||
51 | m_pListView = new QListView(this); | ||
52 | |||
53 | m_pListView->header()->hide(); | ||
54 | m_pListView->setAllColumnsShowFocus(true); | ||
55 | |||
56 | m_pListView->addColumn(tr("Thumbnail")); | ||
57 | m_pListView->addColumn(tr("Information")); | ||
58 | |||
59 | m_pListView->setColumnAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter); | ||
60 | m_pListView->setColumnAlignment(1, Qt::AlignTop); | ||
61 | |||
62 | QListIterator<Page> iterator(pages); | ||
63 | |||
64 | for (; iterator.current(); ++iterator) { | ||
65 | QImage image = iterator.current()->convertToImage(); | ||
66 | |||
67 | int previewWidth = 64; | ||
68 | int previewHeight = 64; | ||
69 | |||
70 | float widthScale = 1.0; | ||
71 | float heightScale = 1.0; | ||
72 | |||
73 | if (previewWidth < image.width()) { | ||
74 | widthScale = (float)previewWidth / float(image.width()); | ||
75 | } | ||
76 | |||
77 | if (previewHeight < image.height()) { | ||
78 | heightScale = (float)previewHeight / float(image.height()); | ||
79 | } | ||
80 | |||
81 | float scale = (widthScale < heightScale ? widthScale : heightScale); | ||
82 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | ||
83 | |||
84 | QPixmap previewPixmap; | ||
85 | previewPixmap.convertFromImage(previewImage); | ||
86 | |||
87 | QPixmap pixmap(64, 64); | ||
88 | |||
89 | pixmap.fill(colorGroup().mid()); | ||
90 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, | ||
91 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); | ||
92 | |||
93 | QListViewItem* item = new QListViewItem(m_pListView); | ||
94 | item->setPixmap(0, pixmap); | ||
95 | } | ||
96 | |||
97 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | ||
98 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); | ||
99 | |||
100 | buttonLayout->addWidget(newPageButton); | ||
101 | buttonLayout->addWidget(clearPageButton); | ||
102 | buttonLayout->addWidget(deletePageButton); | ||
103 | buttonLayout->addStretch(); | ||
104 | buttonLayout->addWidget(movePageUpButton); | ||
105 | buttonLayout->addWidget(movePageDownButton); | ||
106 | |||
107 | mainLayout->addLayout(buttonLayout); | ||
108 | mainLayout->addWidget(m_pListView); | ||
109 | } | ||
110 | |||
111 | ThumbnailView::~ThumbnailView() | ||
112 | { | ||
113 | } | ||
114 | |||
115 | void ThumbnailView::resizeEvent(QResizeEvent* e) | ||
116 | { | ||
117 | QDialog::resizeEvent(e); | ||
118 | |||
119 | m_pListView->setColumnWidth(1, m_pListView->contentsRect().width() - m_pListView->columnWidth(0) | ||
120 | - m_pListView->verticalScrollBar()->width()); | ||
121 | } | ||