author | leseb <leseb> | 2002-06-09 16:06:21 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-09 16:06:21 (UTC) |
commit | b59a64c90deba66180e3a778d411296e984f64ea (patch) (side-by-side diff) | |
tree | 88ef0767602dd174f5911719ffb346a4fcf7420f | |
parent | 29c0d188836a59bff1fbcd1d338fcd3334c0f1f5 (diff) | |
download | opie-b59a64c90deba66180e3a778d411296e984f64ea.zip opie-b59a64c90deba66180e3a778d411296e984f64ea.tar.gz opie-b59a64c90deba66180e3a778d411296e984f64ea.tar.bz2 |
Changing page order now works in thumbnail view
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.cpp | 18 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpadcanvas.h | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.cpp | 43 | ||||
-rw-r--r-- | noncore/graphics/drawpad/thumbnailview.h | 11 |
4 files changed, 65 insertions, 9 deletions
diff --git a/noncore/graphics/drawpad/drawpadcanvas.cpp b/noncore/graphics/drawpad/drawpadcanvas.cpp index c23ee34..bcb6877 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.cpp +++ b/noncore/graphics/drawpad/drawpadcanvas.cpp @@ -326,192 +326,210 @@ uint DrawPadCanvas::pageCount() return m_pages.count(); } void DrawPadCanvas::selectPage(Page* page) { m_pages.findRef(page); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::backupPage() { QPixmap* currentBackup = m_pageBackups.current(); while (m_pageBackups.last() != currentBackup) { m_pageBackups.removeLast(); } while (m_pageBackups.count() >= (5 + 1)) { m_pageBackups.removeFirst(); } m_pageBackups.append(new Page(*(m_pages.current()))); emit pageBackupsChanged(); } void DrawPadCanvas::deleteAll() { m_pages.clear(); m_pages.append(new Page(contentsRect().size())); m_pages.current()->fill(Qt::white); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::newPage(uint width, uint height, const QColor& color) { m_pages.insert(m_pages.at() + 1, new Page(width, height)); m_pages.current()->fill(color); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::clearPage() { m_pages.current()->fill(Qt::white); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pageBackupsChanged(); } void DrawPadCanvas::deletePage() { m_pages.remove(m_pages.current()); if (m_pages.isEmpty()) { m_pages.append(new Page(contentsRect().size())); m_pages.current()->fill(Qt::white); } m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } +void DrawPadCanvas::movePageUp() +{ + int index = m_pages.at(); + Page* page = m_pages.take(); + m_pages.insert(index - 1, page); + + emit pagesChanged(); +} + +void DrawPadCanvas::movePageDown() +{ + int index = m_pages.at(); + Page* page = m_pages.take(); + m_pages.insert(index + 1, page); + + emit pagesChanged(); +} + bool DrawPadCanvas::undoEnabled() { return (m_pageBackups.current() != m_pageBackups.getFirst()); } bool DrawPadCanvas::redoEnabled() { return (m_pageBackups.current() != m_pageBackups.getLast()); } bool DrawPadCanvas::goPreviousPageEnabled() { return (m_pages.current() != m_pages.getFirst()); } bool DrawPadCanvas::goNextPageEnabled() { return (m_pages.current() != m_pages.getLast()); } void DrawPadCanvas::undo() { *(m_pages.current()) = *(m_pageBackups.prev()); viewport()->update(); emit pageBackupsChanged(); } void DrawPadCanvas::redo() { *(m_pages.current()) = *(m_pageBackups.next()); viewport()->update(); emit pageBackupsChanged(); } void DrawPadCanvas::goFirstPage() { m_pages.first(); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::goPreviousPage() { m_pages.prev(); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::goNextPage() { m_pages.next(); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::goLastPage() { m_pages.last(); m_pageBackups.clear(); m_pageBackups.append(new Page(*(m_pages.current()))); resizeContents(m_pages.current()->width(), m_pages.current()->height()); viewport()->update(); emit pagesChanged(); emit pageBackupsChanged(); } void DrawPadCanvas::contentsMousePressEvent(QMouseEvent* e) { m_pDrawPad->tool()->mousePressEvent(e); } void DrawPadCanvas::contentsMouseReleaseEvent(QMouseEvent* e) diff --git a/noncore/graphics/drawpad/drawpadcanvas.h b/noncore/graphics/drawpad/drawpadcanvas.h index d74d425..39cf752 100644 --- a/noncore/graphics/drawpad/drawpadcanvas.h +++ b/noncore/graphics/drawpad/drawpadcanvas.h @@ -1,83 +1,85 @@ /*************************************************************************** * * * DrawPad - a drawing program for Opie Environment * * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef DRAWPADCANVAS_H #define DRAWPADCANVAS_H #include <qscrollview.h> #include <qlist.h> #include <qpointarray.h> class DrawPad; class Page; class DrawPadCanvas : public QScrollView { Q_OBJECT public: DrawPadCanvas(DrawPad* drawPad, QWidget* parent = 0, const char* name = 0); ~DrawPadCanvas(); void load(QIODevice* ioDevice); void initialPage(); void save(QIODevice* ioDevice); void importPage(const QString& fileName); void exportPage(uint fromPage, uint toPage, const QString& name, const QString& format); bool undoEnabled(); bool redoEnabled(); bool goPreviousPageEnabled(); bool goNextPageEnabled(); Page* currentPage(); QList<Page> pages(); uint pagePosition(); uint pageCount(); void selectPage(Page* page); void backupPage(); public slots: void deleteAll(); void newPage(uint width, uint height, const QColor& color); void clearPage(); void deletePage(); + void movePageUp(); + void movePageDown(); void undo(); void redo(); void goFirstPage(); void goPreviousPage(); void goNextPage(); void goLastPage(); signals: void pagesChanged(); void pageBackupsChanged(); protected: void contentsMousePressEvent(QMouseEvent* e); void contentsMouseReleaseEvent(QMouseEvent* e); void contentsMouseMoveEvent(QMouseEvent* e); void drawContents(QPainter* p, int cx, int cy, int cw, int ch); private: DrawPad* m_pDrawPad; QList<Page> m_pages; QList<Page> m_pageBackups; }; #endif // DRAWPADCANVAS_H diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp index 0c7934e..428e008 100644 --- a/noncore/graphics/drawpad/thumbnailview.cpp +++ b/noncore/graphics/drawpad/thumbnailview.cpp @@ -77,196 +77,223 @@ PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const { m_pDrawPadCanvas = drawPadCanvas; header()->hide(); setVScrollBarMode(QScrollView::AlwaysOn); setAllColumnsShowFocus(true); addColumn(tr("Thumbnail")); addColumn(tr("Information")); updateView(); } PageListView::~PageListView() { } void PageListView::updateView() { clear(); if (m_pDrawPadCanvas) { QList<Page> pageList = m_pDrawPadCanvas->pages(); QListIterator<Page> it(pageList); for (; it.current(); ++it) { new PageListViewItem(it.current(), this); } setSorting(0, false); select(m_pDrawPadCanvas->currentPage()); } } void PageListView::resizeEvent(QResizeEvent* e) { Q_UNUSED(e); setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); } void PageListView::select(Page* page) { PageListViewItem* item = (PageListViewItem*)firstChild(); while (item) { if (item->page() == page) { setSelected(item, true); ensureItemVisible(item); break; } item = (PageListViewItem*)(item->nextSibling()); } } Page* PageListView::selected() const { Page* page; PageListViewItem* item = (PageListViewItem*)selectedItem(); if (item) { page = item->page(); } else { page = NULL; } return page; } ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) { inLoop = false; m_pDrawPad = drawPad; m_pDrawPadCanvas = drawPadCanvas; setCaption(tr("DrawPad - Thumbnail View")); QToolButton* newPageButton = new QToolButton(this); newPageButton->setIconSet(Resource::loadIconSet("new")); newPageButton->setAutoRaise(true); connect(newPageButton, SIGNAL(clicked()), this, SLOT(newPage())); QToolButton* clearPageButton = new QToolButton(this); clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); clearPageButton->setAutoRaise(true); connect(clearPageButton, SIGNAL(clicked()), this, SLOT(clearPage())); QToolButton* deletePageButton = new QToolButton(this); deletePageButton->setIconSet(Resource::loadIconSet("trash")); deletePageButton->setAutoRaise(true); connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage())); - QToolButton* movePageUpButton = new QToolButton(this); - movePageUpButton->setIconSet(Resource::loadIconSet("up")); - movePageUpButton->setAutoRaise(true); + m_pMovePageUpButton = new QToolButton(this); + m_pMovePageUpButton->setIconSet(Resource::loadIconSet("up")); + m_pMovePageUpButton->setAutoRaise(true); + connect(m_pMovePageUpButton, SIGNAL(clicked()), this, SLOT(movePageUp())); - QToolButton* movePageDownButton = new QToolButton(this); - movePageDownButton->setIconSet(Resource::loadIconSet("down")); - movePageDownButton->setAutoRaise(true); + m_pMovePageDownButton = new QToolButton(this); + m_pMovePageDownButton->setIconSet(Resource::loadIconSet("down")); + m_pMovePageDownButton->setAutoRaise(true); + connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown())); m_pPageListView = new PageListView(m_pDrawPadCanvas, this); connect(m_pPageListView, SIGNAL(selectionChanged()), this, SLOT(changePage())); QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); QHBoxLayout* buttonLayout = new QHBoxLayout(0); buttonLayout->addWidget(newPageButton); buttonLayout->addWidget(clearPageButton); buttonLayout->addWidget(deletePageButton); buttonLayout->addStretch(); - buttonLayout->addWidget(movePageUpButton); - buttonLayout->addWidget(movePageDownButton); + buttonLayout->addWidget(m_pMovePageUpButton); + buttonLayout->addWidget(m_pMovePageDownButton); mainLayout->addLayout(buttonLayout); mainLayout->addWidget(m_pPageListView); + + updateView(); } ThumbnailView::~ThumbnailView() { hide(); } +void ThumbnailView::updateView() +{ + m_pMovePageUpButton->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); + m_pMovePageDownButton->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); +} + void ThumbnailView::hide() { QWidget::hide(); if (inLoop) { inLoop = false; qApp->exit_loop(); } } void ThumbnailView::exec() { show(); if (!inLoop) { inLoop = true; qApp->enter_loop(); } } void ThumbnailView::newPage() { QRect rect = m_pDrawPadCanvas->contentsRect(); NewPageDialog newPageDialog(rect.width(), rect.height(), m_pDrawPad->pen().color(), m_pDrawPad->brush().color(), this); if (newPageDialog.exec() == QDialog::Accepted) { m_pDrawPadCanvas->newPage(newPageDialog.selectedWidth(), newPageDialog.selectedHeight(), newPageDialog.selectedColor()); m_pPageListView->updateView(); + updateView(); } } void ThumbnailView::clearPage() { QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe selected page?"), QMessageBox::Information, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, QMessageBox::NoButton, this); messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); messageBox.setButtonText(QMessageBox::No, tr("No")); if (messageBox.exec() == QMessageBox::Yes) { m_pDrawPadCanvas->clearPage(); m_pPageListView->updateView(); } } void ThumbnailView::deletePage() { QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe selected page?"), QMessageBox::Information, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, QMessageBox::NoButton, this); messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); messageBox.setButtonText(QMessageBox::No, tr("No")); if (messageBox.exec() == QMessageBox::Yes) { m_pDrawPadCanvas->deletePage(); m_pPageListView->updateView(); + updateView(); } } +void ThumbnailView::movePageUp() +{ + m_pDrawPadCanvas->movePageUp(); + m_pPageListView->updateView(); + updateView(); +} + +void ThumbnailView::movePageDown() +{ + m_pDrawPadCanvas->movePageDown(); + m_pPageListView->updateView(); + updateView(); +} + void ThumbnailView::changePage() { m_pDrawPadCanvas->selectPage(m_pPageListView->selected()); + updateView(); } diff --git a/noncore/graphics/drawpad/thumbnailview.h b/noncore/graphics/drawpad/thumbnailview.h index 1fdb168..eb748fa 100644 --- a/noncore/graphics/drawpad/thumbnailview.h +++ b/noncore/graphics/drawpad/thumbnailview.h @@ -1,80 +1,89 @@ /*************************************************************************** * * * DrawPad - a drawing program for Opie Environment * * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef THUMBNAILVIEW_H #define THUMBNAILVIEW_H #include <qwidget.h> #include <qlistview.h> class DrawPad; class DrawPadCanvas; class Page; +class QToolButton; + class PageListViewItem : public QListViewItem { public: PageListViewItem(Page* page, QListView* parent); ~PageListViewItem(); Page* page() const; private: Page* m_pPage; }; class PageListView : public QListView { public: PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); ~PageListView(); void updateView(); void select(Page* page); Page* selected() const; protected: void resizeEvent(QResizeEvent* e); private: DrawPadCanvas* m_pDrawPadCanvas; }; class ThumbnailView : public QWidget { Q_OBJECT public: ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent = 0, const char* name = 0); ~ThumbnailView(); - + + void updateView(); + void hide(); void exec(); public slots: void newPage(); void clearPage(); void deletePage(); + void movePageUp(); + void movePageDown(); void changePage(); private: bool inLoop; DrawPad* m_pDrawPad; DrawPadCanvas* m_pDrawPadCanvas; + QToolButton* m_pMovePageUpButton; + QToolButton* m_pMovePageDownButton; + PageListView* m_pPageListView; }; #endif // THUMBNAILVIEW_H |