author | leseb <leseb> | 2002-06-07 20:30:30 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-07 20:30:30 (UTC) |
commit | 9dcd598f9b815511cae884d26b18e3c8913b9fcf (patch) (side-by-side diff) | |
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 @@ -12,89 +12,151 @@ ***************************************************************************/ #include "thumbnailview.h" +#include "drawpadcanvas.h" #include "page.h" #include <qpe/resource.h> +#include <qapplication.h> #include <qheader.h> #include <qimage.h> #include <qlayout.h> -#include <qlistview.h> +#include <qmessagebox.h> #include <qtoolbutton.h> -ThumbnailView::ThumbnailView(QList<Page> pages, QWidget* parent, const char* name) - : QDialog(parent, name, true) +PageListViewItem::PageListViewItem(Page* page, QListView* parent) + : QListViewItem(parent) { - setCaption(tr("Thumbnail")); + m_pPage = page; - QToolButton* newPageButton = new QToolButton(this); - newPageButton->setIconSet(Resource::loadIconSet("new")); - newPageButton->setAutoRaise(true); + QImage image = m_pPage->convertToImage(); - QToolButton* clearPageButton = new QToolButton(this); - clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); - clearPageButton->setAutoRaise(true); + int previewWidth = 64; + int previewHeight = 64; - QToolButton* deletePageButton = new QToolButton(this); - deletePageButton->setIconSet(Resource::loadIconSet("trash")); - deletePageButton->setAutoRaise(true); + float widthScale = 1.0; + float heightScale = 1.0; - QToolButton* movePageUpButton = new QToolButton(this); - movePageUpButton->setIconSet(Resource::loadIconSet("up")); - movePageUpButton->setAutoRaise(true); + if (previewWidth < image.width()) { + widthScale = (float)previewWidth / float(image.width()); + } - QToolButton* movePageDownButton = new QToolButton(this); - movePageDownButton->setIconSet(Resource::loadIconSet("down")); - movePageDownButton->setAutoRaise(true); + if (previewHeight < image.height()) { + heightScale = (float)previewHeight / float(image.height()); + } + + float scale = (widthScale < heightScale ? widthScale : heightScale); + QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); + + QPixmap previewPixmap; + previewPixmap.convertFromImage(previewImage); - m_pListView = new QListView(this); + QPixmap pixmap(64, 64); - m_pListView->header()->hide(); - m_pListView->setAllColumnsShowFocus(true); + pixmap.fill(listView()->colorGroup().mid()); + bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, + (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); - m_pListView->addColumn(tr("Thumbnail")); - m_pListView->addColumn(tr("Information")); + setPixmap(0, pixmap); +} - m_pListView->setColumnAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter); - m_pListView->setColumnAlignment(1, Qt::AlignTop); +PageListViewItem::~PageListViewItem() +{ +} + +Page* PageListViewItem::page() const +{ + return m_pPage; +} - QListIterator<Page> iterator(pages); +PageListView::PageListView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) + : QListView(parent, name) +{ + m_pDrawPadCanvas = drawPadCanvas; - for (; iterator.current(); ++iterator) { - QImage image = iterator.current()->convertToImage(); + header()->hide(); + setVScrollBarMode(QScrollView::AlwaysOn); + setAllColumnsShowFocus(true); - int previewWidth = 64; - int previewHeight = 64; + addColumn(tr("Thumbnail")); + addColumn(tr("Information")); - float widthScale = 1.0; - float heightScale = 1.0; + updateView(); +} - if (previewWidth < image.width()) { - widthScale = (float)previewWidth / float(image.width()); - } +PageListView::~PageListView() +{ +} + +void PageListView::updateView() +{ + clear(); - if (previewHeight < image.height()) { - heightScale = (float)previewHeight / float(image.height()); + if (m_pDrawPadCanvas) { + QList<Page> pageList = m_pDrawPadCanvas->pages(); + QListIterator<Page> it(pageList); + + for (; it.current(); ++it) { + new PageListViewItem(it.current(), this); } + } +} - float scale = (widthScale < heightScale ? widthScale : heightScale); - QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); +void PageListView::resizeEvent(QResizeEvent* e) +{ + Q_UNUSED(e); - QPixmap previewPixmap; - previewPixmap.convertFromImage(previewImage); + setColumnWidth(1, contentsRect().width() - columnWidth(0) - verticalScrollBar()->width()); +} - QPixmap pixmap(64, 64); +Page* PageListView::selected() const +{ + Page* page; - pixmap.fill(colorGroup().mid()); - bitBlt(&pixmap, (pixmap.width() - previewPixmap.width()) / 2, - (pixmap.height() - previewPixmap.height()) / 2, &previewPixmap); + PageListViewItem* item = (PageListViewItem*)selectedItem(); - QListViewItem* item = new QListViewItem(m_pListView); - item->setPixmap(0, pixmap); + if (item) { + page = item->page(); + } else { + page = NULL; } + return page; +} + + +ThumbnailView::ThumbnailView(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) + : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) +{ + inLoop = false; + m_pDrawPadCanvas = drawPadCanvas; + + setCaption(tr("Thumbnail")); + + QToolButton* newPageButton = new QToolButton(this); + newPageButton->setIconSet(Resource::loadIconSet("new")); + newPageButton->setAutoRaise(true); + + QToolButton* clearPageButton = new QToolButton(this); + clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); + clearPageButton->setAutoRaise(true); + + QToolButton* deletePageButton = new QToolButton(this); + deletePageButton->setIconSet(Resource::loadIconSet("trash")); + deletePageButton->setAutoRaise(true); + + QToolButton* movePageUpButton = new QToolButton(this); + movePageUpButton->setIconSet(Resource::loadIconSet("up")); + movePageUpButton->setAutoRaise(true); + + QToolButton* movePageDownButton = new QToolButton(this); + movePageDownButton->setIconSet(Resource::loadIconSet("down")); + movePageDownButton->setAutoRaise(true); + + m_pPageListView = new PageListView(m_pDrawPadCanvas, this); + QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); QHBoxLayout* buttonLayout = new QHBoxLayout(0); buttonLayout->addWidget(newPageButton); @@ -104,18 +166,46 @@ ThumbnailView::ThumbnailView(QList<Page> pages, QWidget* parent, const char* nam buttonLayout->addWidget(movePageUpButton); buttonLayout->addWidget(movePageDownButton); mainLayout->addLayout(buttonLayout); - mainLayout->addWidget(m_pListView); + mainLayout->addWidget(m_pPageListView); } ThumbnailView::~ThumbnailView() { + hide(); } -void ThumbnailView::resizeEvent(QResizeEvent* e) +void ThumbnailView::hide() { - QDialog::resizeEvent(e); + QWidget::hide(); + + if (inLoop) { + inLoop = false; + qApp->exit_loop(); + } +} - m_pListView->setColumnWidth(1, m_pListView->contentsRect().width() - m_pListView->columnWidth(0) - - m_pListView->verticalScrollBar()->width()); +void ThumbnailView::exec() +{ + show(); + + if (!inLoop) { + inLoop = true; + qApp->enter_loop(); + } +} + +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(); + } } |