-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 13 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 1 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 27 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.h | 2 |
4 files changed, 42 insertions, 1 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index 252f4d5..0a1e9a5 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp | |||
@@ -322,16 +322,29 @@ uint DrawPadCanvas::pagePosition() | |||
322 | return (m_pages.at() + 1); | 322 | return (m_pages.at() + 1); |
323 | } | 323 | } |
324 | 324 | ||
325 | uint DrawPadCanvas::pageCount() | 325 | uint DrawPadCanvas::pageCount() |
326 | { | 326 | { |
327 | return m_pages.count(); | 327 | return m_pages.count(); |
328 | } | 328 | } |
329 | 329 | ||
330 | void DrawPadCanvas::selectPage(Page* page) | ||
331 | { | ||
332 | m_pages.findRef(page); | ||
333 | m_pageBackups.clear(); | ||
334 | m_pageBackups.append(new Page(*(m_pages.current()))); | ||
335 | |||
336 | resizeContents(m_pages.current()->width(), m_pages.current()->height()); | ||
337 | viewport()->update(); | ||
338 | |||
339 | emit pagesChanged(); | ||
340 | emit pageBackupsChanged(); | ||
341 | } | ||
342 | |||
330 | void DrawPadCanvas::backupPage() | 343 | void DrawPadCanvas::backupPage() |
331 | { | 344 | { |
332 | QPixmap* currentBackup = m_pageBackups.current(); | 345 | QPixmap* currentBackup = m_pageBackups.current(); |
333 | while (m_pageBackups.last() != currentBackup) { | 346 | while (m_pageBackups.last() != currentBackup) { |
334 | m_pageBackups.removeLast(); | 347 | m_pageBackups.removeLast(); |
335 | } | 348 | } |
336 | 349 | ||
337 | while (m_pageBackups.count() >= (5 + 1)) { | 350 | while (m_pageBackups.count() >= (5 + 1)) { |
diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index 47763f9..cf2d904 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h | |||
@@ -42,16 +42,17 @@ public: | |||
42 | bool goPreviousPageEnabled(); | 42 | bool goPreviousPageEnabled(); |
43 | bool goNextPageEnabled(); | 43 | bool goNextPageEnabled(); |
44 | 44 | ||
45 | Page* currentPage(); | 45 | Page* currentPage(); |
46 | QList<Page> pages(); | 46 | QList<Page> pages(); |
47 | uint pagePosition(); | 47 | uint pagePosition(); |
48 | uint pageCount(); | 48 | uint pageCount(); |
49 | 49 | ||
50 | void selectPage(Page* page); | ||
50 | void backupPage(); | 51 | void backupPage(); |
51 | 52 | ||
52 | public slots: | 53 | public slots: |
53 | void deleteAll(); | 54 | void deleteAll(); |
54 | void newPage(); | 55 | void newPage(); |
55 | void clearPage(); | 56 | void clearPage(); |
56 | void deletePage(); | 57 | void deletePage(); |
57 | 58 | ||
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp index 1754ce9..476b7b9 100644 --- a/noncore/graphics/drawpad/thumbnailview.cpp +++ b/noncore/graphics/drawpad/thumbnailview.cpp | |||
@@ -95,42 +95,59 @@ void PageListView::updateView() | |||
95 | 95 | ||
96 | if (m_pDrawPadCanvas) { | 96 | if (m_pDrawPadCanvas) { |
97 | QList<Page> pageList = m_pDrawPadCanvas->pages(); | 97 | QList<Page> pageList = m_pDrawPadCanvas->pages(); |
98 | QListIterator<Page> it(pageList); | 98 | QListIterator<Page> it(pageList); |
99 | 99 | ||
100 | for (; it.current(); ++it) { | 100 | for (; it.current(); ++it) { |
101 | new PageListViewItem(it.current(), this); | 101 | new PageListViewItem(it.current(), this); |
102 | } | 102 | } |
103 | |||
104 | setSorting(0, false); | ||
105 | select(m_pDrawPadCanvas->currentPage()); | ||
103 | } | 106 | } |
104 | } | 107 | } |
105 | 108 | ||
106 | void PageListView::resizeEvent(QResizeEvent* e) | 109 | void PageListView::resizeEvent(QResizeEvent* e) |
107 | { | 110 | { |
108 | Q_UNUSED(e); | 111 | Q_UNUSED(e); |
109 | 112 | ||
110 | setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); | 113 | setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); |
111 | } | 114 | } |
112 | 115 | ||
116 | void PageListView::select(Page* page) | ||
117 | { | ||
118 | PageListViewItem* item = (PageListViewItem*)firstChild(); | ||
119 | |||
120 | while (item) { | ||
121 | if (item->page() == page) { | ||
122 | setSelected(item, true); | ||
123 | ensureItemVisible(item); | ||
124 | break; | ||
125 | } | ||
126 | |||
127 | item = (PageListViewItem*)(item->nextSibling()); | ||
128 | } | ||
129 | } | ||
130 | |||
113 | Page* PageListView::selected() const | 131 | Page* PageListView::selected() const |
114 | { | 132 | { |
115 | Page* page; | 133 | Page* page; |
116 | 134 | ||
117 | PageListViewItem* item = (PageListViewItem*)selectedItem(); | 135 | PageListViewItem* item = (PageListViewItem*)selectedItem(); |
118 | 136 | ||
119 | if (item) { | 137 | if (item) { |
120 | page = item->page(); | 138 | page = item->page(); |
121 | } else { | 139 | } else { |
122 | page = NULL; | 140 | page = NULL; |
123 | } | 141 | } |
124 | 142 | ||
125 | return page; | 143 | return page; |
126 | } | 144 | } |
127 | 145 | ||
128 | |||
129 | ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) | 146 | ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) |
130 | : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) | 147 | : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) |
131 | { | 148 | { |
132 | inLoop = false; | 149 | inLoop = false; |
133 | m_pDrawPadCanvas = drawPadCanvas; | 150 | m_pDrawPadCanvas = drawPadCanvas; |
134 | 151 | ||
135 | setCaption(tr("Thumbnail")); | 152 | setCaption(tr("Thumbnail")); |
136 | 153 | ||
@@ -140,26 +157,28 @@ ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, cons | |||
140 | 157 | ||
141 | QToolButton* clearPageButton = new QToolButton(this); | 158 | QToolButton* clearPageButton = new QToolButton(this); |
142 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); | 159 | clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); |
143 | clearPageButton->setAutoRaise(true); | 160 | clearPageButton->setAutoRaise(true); |
144 | 161 | ||
145 | QToolButton* deletePageButton = new QToolButton(this); | 162 | QToolButton* deletePageButton = new QToolButton(this); |
146 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); | 163 | deletePageButton->setIconSet(Resource::loadIconSet("trash")); |
147 | deletePageButton->setAutoRaise(true); | 164 | deletePageButton->setAutoRaise(true); |
165 | connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage())); | ||
148 | 166 | ||
149 | QToolButton* movePageUpButton = new QToolButton(this); | 167 | QToolButton* movePageUpButton = new QToolButton(this); |
150 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); | 168 | movePageUpButton->setIconSet(Resource::loadIconSet("up")); |
151 | movePageUpButton->setAutoRaise(true); | 169 | movePageUpButton->setAutoRaise(true); |
152 | 170 | ||
153 | QToolButton* movePageDownButton = new QToolButton(this); | 171 | QToolButton* movePageDownButton = new QToolButton(this); |
154 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); | 172 | movePageDownButton->setIconSet(Resource::loadIconSet("down")); |
155 | movePageDownButton->setAutoRaise(true); | 173 | movePageDownButton->setAutoRaise(true); |
156 | 174 | ||
157 | m_pPageListView = new PageListView(m_pDrawPadCanvas, this); | 175 | m_pPageListView = new PageListView(m_pDrawPadCanvas, this); |
176 | connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage())); | ||
158 | 177 | ||
159 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 178 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
160 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); | 179 | QHBoxLayout* buttonLayout = new QHBoxLayout(0); |
161 | 180 | ||
162 | buttonLayout->addWidget(newPageButton); | 181 | buttonLayout->addWidget(newPageButton); |
163 | buttonLayout->addWidget(clearPageButton); | 182 | buttonLayout->addWidget(clearPageButton); |
164 | buttonLayout->addWidget(deletePageButton); | 183 | buttonLayout->addWidget(deletePageButton); |
165 | buttonLayout->addStretch(); | 184 | buttonLayout->addStretch(); |
@@ -202,10 +221,16 @@ void ThumbnailView::deletePage() | |||
202 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 221 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
203 | QMessageBox::NoButton, this); | 222 | QMessageBox::NoButton, this); |
204 | 223 | ||
205 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 224 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
206 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 225 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
207 | 226 | ||
208 | if (messageBox.exec() == QMessageBox::Yes) { | 227 | if (messageBox.exec() == QMessageBox::Yes) { |
209 | m_pDrawPadCanvas->deletePage(); | 228 | m_pDrawPadCanvas->deletePage(); |
229 | m_pPageListView->updateView(); | ||
210 | } | 230 | } |
211 | } | 231 | } |
232 | |||
233 | void ThumbnailView::changePage() | ||
234 | { | ||
235 | m_pDrawPadCanvas->selectPage(m_pPageListView->selected()); | ||
236 | } | ||
diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h index ae97ff1..9417655 100644 --- a/noncore/graphics/drawpad/thumbnailview.h +++ b/noncore/graphics/drawpad/thumbnailview.h | |||
@@ -35,16 +35,17 @@ private: | |||
35 | class PageListView : public QListView | 35 | class PageListView : public QListView |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); | 38 | PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); |
39 | ~PageListView(); | 39 | ~PageListView(); |
40 | 40 | ||
41 | void updateView(); | 41 | void updateView(); |
42 | 42 | ||
43 | void select(Page* page); | ||
43 | Page* selected() const; | 44 | Page* selected() const; |
44 | 45 | ||
45 | protected: | 46 | protected: |
46 | void resizeEvent(QResizeEvent* e); | 47 | void resizeEvent(QResizeEvent* e); |
47 | 48 | ||
48 | private: | 49 | private: |
49 | DrawPadCanvas* m_pDrawPadCanvas; | 50 | DrawPadCanvas* m_pDrawPadCanvas; |
50 | }; | 51 | }; |
@@ -57,16 +58,17 @@ public: | |||
57 | ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); | 58 | ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); |
58 | ~ThumbnailView(); | 59 | ~ThumbnailView(); |
59 | 60 | ||
60 | void hide(); | 61 | void hide(); |
61 | void exec(); | 62 | void exec(); |
62 | 63 | ||
63 | public slots: | 64 | public slots: |
64 | void deletePage(); | 65 | void deletePage(); |
66 | void changePage(); | ||
65 | 67 | ||
66 | private: | 68 | private: |
67 | bool inLoop; | 69 | bool inLoop; |
68 | DrawPadCanvas* m_pDrawPadCanvas; | 70 | DrawPadCanvas* m_pDrawPadCanvas; |
69 | 71 | ||
70 | PageListView* m_pPageListView; | 72 | PageListView* m_pPageListView; |
71 | }; | 73 | }; |
72 | 74 | ||