author | leseb <leseb> | 2002-06-07 20:30:30 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-07 20:30:30 (UTC) |
commit | 9dcd598f9b815511cae884d26b18e3c8913b9fcf (patch) (unidiff) | |
tree | 4b18e7fa7c864b2dca4da76bc89c2a975e80a73c /noncore/graphics/drawpad/thumbnailview.cpp | |
parent | 640d964cfdc7467f6cacb513087cd3acda2c04f0 (diff) | |
download | opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.zip opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.tar.gz opie-9dcd598f9b815511cae884d26b18e3c8913b9fcf.tar.bz2 |
Make progress in thumbnail view
Diffstat (limited to 'noncore/graphics/drawpad/thumbnailview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 196 |
1 files changed, 143 insertions, 53 deletions
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp index 10ade90..1754ce9 100644 --- a/noncore/graphics/drawpad/thumbnailview.cpp +++ b/noncore/graphics/drawpad/thumbnailview.cpp | |||
@@ -10,112 +10,202 @@ | |||
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "thumbnailview.h" | 14 | #include "thumbnailview.h" |
15 | 15 | ||
16 | #include "drawpadcanvas.h" | ||
16 | #include "page.h" | 17 | #include "page.h" |
17 | 18 | ||
18 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
19 | 20 | ||
21 | #include <qapplication.h> | ||
20 | #include <qheader.h> | 22 | #include <qheader.h> |
21 | #include <qimage.h> | 23 | #include <qimage.h> |
22 | #include <qlayout.h> | 24 | #include <qlayout.h> |
23 | #include <qlistview.h> | 25 | #include <qmessagebox.h> |
24 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
25 | 27 | ||
26 | ThumbnailView::ThumbnailView(QList<Page> pages, QWidget* parent, const char* name) | 28 | PageListViewItem::PageListViewItem(Page* page, QListView* parent) |
27 | : QDialog(parent, name, true) | 29 | : QListViewItem(parent) |
28 | { | 30 | { |
29 | setCaption(tr("Thumbnail")); | 31 | m_pPage = page; |
30 | 32 | ||
31 | QToolButton* newPageButton = new QToolButton(this); | 33 | QImage image = m_pPage->convertToImage(); |
32 | newPageButton->setIconSet(Resource::loadIconSet("new")); | ||
33 | newPageButton->setAutoRaise(true); | ||
34 | 34 | ||
35 | QToolButton* clearPageButton = new QToolButton(this); | 35 | int previewWidth = 64; |
36 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | 36 | int previewHeight = 64; |
37 | clearPageButton->setAutoRaise(true); | ||
38 | 37 | ||
39 | QToolButton* deletePageButton = new QToolButton(this); | 38 | float widthScale = 1.0; |
40 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | 39 | float heightScale = 1.0; |
41 | deletePageButton->setAutoRaise(true); | ||
42 | 40 | ||
43 | QToolButton* movePageUpButton = new QToolButton(this); | 41 | if (previewWidth < image.width()) { |
44 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | 42 | widthScale = (float)previewWidth / float(image.width()); |
45 | movePageUpButton->setAutoRaise(true); | 43 | } |
46 | 44 | ||
47 | QToolButton* movePageDownButton = new QToolButton(this); | 45 | if (previewHeight < image.height()) { |
48 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | 46 | heightScale = (float)previewHeight / float(image.height()); |
49 | movePageDownButton->setAutoRaise(true); | 47 | } |
48 | |||
49 | float scale = (widthScale < heightScale ? widthScale : heightScale); | ||
50 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | ||
51 | |||
52 | QPixmap previewPixmap; | ||
53 | previewPixmap.convertFromImage(previewImage); | ||
50 | 54 | ||
51 | m_pListView = new QListView(this); | 55 | QPixmap pixmap(64, 64); |
52 | 56 | ||
53 | m_pListView->header()->hide(); | 57 | pixmap.fill(listView()->colorGroup().mid()); |
54 | m_pListView->setAllColumnsShowFocus(true); | 58 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, |
59 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); | ||
55 | 60 | ||
56 | m_pListView->addColumn(tr("Thumbnail")); | 61 | setPixmap(0, pixmap); |
57 | m_pListView->addColumn(tr("Information")); | 62 | } |
58 | 63 | ||
59 | m_pListView->setColumnAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter); | 64 | PageListViewItem::~PageListViewItem() |
60 | m_pListView->setColumnAlignment(1, Qt::AlignTop); | 65 | { |
66 | } | ||
67 | |||
68 | Page* PageListViewItem::page() const | ||
69 | { | ||
70 | return m_pPage; | ||
71 | } | ||
61 | 72 | ||
62 | QListIterator<Page> iterator(pages); | 73 | PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) |
74 | : QListView(parent, name) | ||
75 | { | ||
76 | m_pDrawPadCanvas = drawPadCanvas; | ||
63 | 77 | ||
64 | for (; iterator.current(); ++iterator) { | 78 | header()->hide(); |
65 | QImage image = iterator.current()->convertToImage(); | 79 | setVScrollBarMode(QScrollView::AlwaysOn); |
80 | setAllColumnsShowFocus(true); | ||
66 | 81 | ||
67 | int previewWidth = 64; | 82 | addColumn(tr("Thumbnail")); |
68 | int previewHeight = 64; | 83 | addColumn(tr("Information")); |
69 | 84 | ||
70 | float widthScale = 1.0; | 85 | updateView(); |
71 | float heightScale = 1.0; | 86 | } |
72 | 87 | ||
73 | if (previewWidth < image.width()) { | 88 | PageListView::~PageListView() |
74 | widthScale = (float)previewWidth / float(image.width()); | 89 | { |
75 | } | 90 | } |
91 | |||
92 | void PageListView::updateView() | ||
93 | { | ||
94 | clear(); | ||
76 | 95 | ||
77 | if (previewHeight < image.height()) { | 96 | if (m_pDrawPadCanvas) { |
78 | heightScale = (float)previewHeight / float(image.height()); | 97 | QList<Page> pageList = m_pDrawPadCanvas->pages(); |
98 | QListIterator<Page> it(pageList); | ||
99 | |||
100 | for (; it.current(); ++it) { | ||
101 | new PageListViewItem(it.current(), this); | ||
79 | } | 102 | } |
103 | } | ||
104 | } | ||
80 | 105 | ||
81 | float scale = (widthScale < heightScale ? widthScale : heightScale); | 106 | void PageListView::resizeEvent(QResizeEvent* e) |
82 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | 107 | { |
108 | Q_UNUSED(e); | ||
83 | 109 | ||
84 | QPixmap previewPixmap; | 110 | setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); |
85 | previewPixmap.convertFromImage(previewImage); | 111 | } |
86 | 112 | ||
87 | QPixmap pixmap(64, 64); | 113 | Page* PageListView::selected() const |
114 | { | ||
115 | Page* page; | ||
88 | 116 | ||
89 | pixmap.fill(colorGroup().mid()); | 117 | PageListViewItem* item = (PageListViewItem*)selectedItem(); |
90 | bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, | ||
91 | (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); | ||
92 | 118 | ||
93 | QListViewItem* item = new QListViewItem(m_pListView); | 119 | if (item) { |
94 | item->setPixmap(0, pixmap); | 120 | page = item->page(); |
121 | } else { | ||
122 | page = NULL; | ||
95 | } | 123 | } |
96 | 124 | ||
125 | return page; | ||
126 | } | ||
127 | |||
128 | |||
129 | ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) | ||
130 | : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) | ||
131 | { | ||
132 | inLoop = false; | ||
133 | m_pDrawPadCanvas = drawPadCanvas; | ||
134 | |||
135 | setCaption(tr("Thumbnail")); | ||
136 | |||
137 | QToolButton* newPageButton = new QToolButton(this); | ||
138 | newPageButton->setIconSet(Resource::loadIconSet("new")); | ||
139 | newPageButton->setAutoRaise(true); | ||
140 | |||
141 | QToolButton* clearPageButton = new QToolButton(this); | ||
142 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | ||
143 | clearPageButton->setAutoRaise(true); | ||
144 | |||
145 | QToolButton* deletePageButton = new QToolButton(this); | ||
146 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | ||
147 | deletePageButton->setAutoRaise(true); | ||
148 | |||
149 | QToolButton* movePageUpButton = new QToolButton(this); | ||
150 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | ||
151 | movePageUpButton->setAutoRaise(true); | ||
152 | |||
153 | QToolButton* movePageDownButton = new QToolButton(this); | ||
154 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | ||
155 | movePageDownButton->setAutoRaise(true); | ||
156 | |||
157 | m_pPageListView = new PageListView(m_pDrawPadCanvas, this); | ||
158 | |||
97 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 159 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
98 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); | 160 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); |
99 | 161 | ||
100 | buttonLayout->addWidget(newPageButton); | 162 | buttonLayout->addWidget(newPageButton); |
101 | buttonLayout->addWidget(clearPageButton); | 163 | buttonLayout->addWidget(clearPageButton); |
102 | buttonLayout->addWidget(deletePageButton); | 164 | buttonLayout->addWidget(deletePageButton); |
103 | buttonLayout->addStretch(); | 165 | buttonLayout->addStretch(); |
104 | buttonLayout->addWidget(movePageUpButton); | 166 | buttonLayout->addWidget(movePageUpButton); |
105 | buttonLayout->addWidget(movePageDownButton); | 167 | buttonLayout->addWidget(movePageDownButton); |
106 | 168 | ||
107 | mainLayout->addLayout(buttonLayout); | 169 | mainLayout->addLayout(buttonLayout); |
108 | mainLayout->addWidget(m_pListView); | 170 | mainLayout->addWidget(m_pPageListView); |
109 | } | 171 | } |
110 | 172 | ||
111 | ThumbnailView::~ThumbnailView() | 173 | ThumbnailView::~ThumbnailView() |
112 | { | 174 | { |
175 | hide(); | ||
113 | } | 176 | } |
114 | 177 | ||
115 | void ThumbnailView::resizeEvent(QResizeEvent* e) | 178 | void ThumbnailView::hide() |
116 | { | 179 | { |
117 | QDialog::resizeEvent(e); | 180 | QWidget::hide(); |
181 | |||
182 | if (inLoop) { | ||
183 | inLoop = false; | ||
184 | qApp->exit_loop(); | ||
185 | } | ||
186 | } | ||
118 | 187 | ||
119 | m_pListView->setColumnWidth(1, m_pListView->contentsRect().width() - m_pListView->columnWidth(0) | 188 | void ThumbnailView::exec() |
120 | - m_pListView->verticalScrollBar()->width()); | 189 | { |
190 | show(); | ||
191 | |||
192 | if (!inLoop) { | ||
193 | inLoop = true; | ||
194 | qApp->enter_loop(); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | void ThumbnailView::deletePage() | ||
199 | { | ||
200 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), | ||
201 | QMessageBox::Information, QMessageBox::Yes, | ||
202 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | ||
203 | QMessageBox::NoButton, this); | ||
204 | |||
205 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | ||
206 | messageBox.setButtonText(QMessageBox::No, tr("No")); | ||
207 | |||
208 | if (messageBox.exec() == QMessageBox::Yes) { | ||
209 | m_pDrawPadCanvas->deletePage(); | ||
210 | } | ||
121 | } | 211 | } |