From a6438101199b86fcd544040a8292909840b90fb7 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Wed, 3 Apr 2019 16:11:22 +0200 Subject: [PATCH] image viewer --- cimageviewer.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ cimageviewer.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++ clabel.cpp | 25 +++++++++++++++++++++ clabel.h | 29 ++++++++++++++++++++++++ cmainwindow.cpp | 30 +++++++++++++++++++++++++ cmainwindow.h | 25 +++++++++++++++++++++ common.cpp | 4 ++-- 7 files changed, 223 insertions(+), 2 deletions(-) diff --git a/cimageviewer.cpp b/cimageviewer.cpp index 6d25f47..db0a5dd 100644 --- a/cimageviewer.cpp +++ b/cimageviewer.cpp @@ -1,6 +1,10 @@ #include "cimageviewer.h" #include "ui_cimageviewer.h" +#include + +#include + cImageViewer::cImageViewer(QWidget *parent) : QDialog(parent), @@ -8,6 +12,11 @@ cImageViewer::cImageViewer(QWidget *parent) : { ui->setupUi(this); ui->m_lpImage->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + +// connect(ui->m_lpImage, &cLabel::imageNext, this, &cImageViewer::onImageNext); +// connect(ui->m_lpImage, &cLabel::imagePrev, this, &cImageViewer::onImagePrev); +// connect(ui->m_lpImage, &cLabel::imageFirst, this, &cImageViewer::onImageFirst); +// connect(ui->m_lpImage, &cLabel::imageLast, this, &cImageViewer::onImageLast); } cImageViewer::~cImageViewer() @@ -18,4 +27,52 @@ cImageViewer::~cImageViewer() void cImageViewer::setImage(cImage* lpImage) { ui->m_lpImage->setImage(lpImage); + + setWindowFlag(Qt::Window); + showFullScreen(); + + ui->m_lpImage->setFocus(); +} + +void cImageViewer::keyPressEvent(QKeyEvent* e) +{ + switch(e->key()) + { + case Qt::Key_Left: + emit imagePrev(); + break; + case Qt::Key_Right: + emit imageNext(); + break; + case Qt::Key_Home: + emit imageFirst(); + break; + case Qt::Key_End: + emit imageLast(); + break; + default: + break; + } + + QDialog::keyPressEvent(e); +} + +void cImageViewer::onImageNext() +{ + emit imageNext(); +} + +void cImageViewer::onImagePrev() +{ + emit imagePrev(); +} + +void cImageViewer::onImageLast() +{ + emit imageLast(); +} + +void cImageViewer::onImageFirst() +{ + emit imageFirst(); } diff --git a/cimageviewer.h b/cimageviewer.h index f92061a..1a98532 100644 --- a/cimageviewer.h +++ b/cimageviewer.h @@ -22,6 +22,61 @@ public: void setImage(cImage* lpImage); private: Ui::cImageViewer* ui; + +protected: + void keyPressEvent(QKeyEvent* e); + +private slots: + /*! + \brief + + \fn onImageNext + */ + void onImageNext(); + /*! + \brief + + \fn onImagePrev + */ + void onImagePrev(); + /*! + \brief + + \fn onImageLast + */ + void onImageLast(); + /*! + \brief + + \fn onImageFirst + */ + void onImageFirst(); + +signals: + /*! + \brief + + \fn imageNext + */ + void imageNext(); + /*! + \brief + + \fn imagePrev + */ + void imagePrev(); + /*! + \brief + + \fn imageLast + */ + void imageLast(); + /*! + \brief + + \fn imageFirst + */ + void imageFirst(); }; #endif // CIMAGEVIEWER_H diff --git a/clabel.cpp b/clabel.cpp index 3959e19..e32079b 100644 --- a/clabel.cpp +++ b/clabel.cpp @@ -1,11 +1,13 @@ #include "clabel.h" #include +#include cLabel::cLabel(QWidget *parent, Qt::WindowFlags f) : QLabel(parent, f) { + installEventFilter(this); } cLabel::cLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) : @@ -23,3 +25,26 @@ void cLabel::resizeEvent(QResizeEvent* e) QLabel::resizeEvent(e); setPixmap(QPixmap::fromImage(m_lpImage->scaled(width(), height(), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation))); } + +void cLabel::keyPressEvent(QKeyEvent* e) +{ + switch(e->key()) + { + case Qt::Key_Left: + emit imagePrev(); + break; + case Qt::Key_Right: + emit imageNext(); + break; + case Qt::Key_Home: + emit imageFirst(); + break; + case Qt::Key_End: + emit imageLast(); + break; + default: + break; + } + + QLabel::keyPressEvent(e); +} diff --git a/clabel.h b/clabel.h index b608b86..06e4547 100644 --- a/clabel.h +++ b/clabel.h @@ -9,6 +9,8 @@ class cLabel : public QLabel { + Q_OBJECT + public: cLabel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); cLabel(const QString &text, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); @@ -19,6 +21,33 @@ private: protected: void resizeEvent(QResizeEvent* e); + void keyPressEvent(QKeyEvent* e); + +signals: + /*! + \brief + + \fn imageNext + */ + void imageNext(); + /*! + \brief + + \fn imagePrev + */ + void imagePrev(); + /*! + \brief + + \fn imageLast + */ + void imageLast(); + /*! + \brief + + \fn imageFirst + */ + void imageFirst(); }; #endif // CLABEL_H diff --git a/cmainwindow.cpp b/cmainwindow.cpp index e783555..4cceada 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -476,8 +476,18 @@ void cMainWindow::onThumbnailDoubleClicked(const QModelIndex& index) if(image.isNull()) return; + connect(&imageViewer, &cImageViewer::imageNext, this, &cMainWindow::onImageNext); + connect(&imageViewer, &cImageViewer::imagePrev, this, &cMainWindow::onImagePrev); + connect(&imageViewer, &cImageViewer::imageFirst, this, &cMainWindow::onImageFirst); + connect(&imageViewer, &cImageViewer::imageLast, this, &cMainWindow::onImageLast); + imageViewer.setImage(&image); imageViewer.exec(); + + disconnect(&imageViewer, &cImageViewer::imageNext, this, &cMainWindow::onImageNext); + disconnect(&imageViewer, &cImageViewer::imagePrev, this, &cMainWindow::onImagePrev); + disconnect(&imageViewer, &cImageViewer::imageFirst, this, &cMainWindow::onImageFirst); + disconnect(&imageViewer, &cImageViewer::imageLast, this, &cMainWindow::onImageLast); } void cMainWindow::onFolderSelected(const QItemSelection& /*selection*/, const QItemSelection& /*previous*/) @@ -982,3 +992,23 @@ void cMainWindow::onFilterTagChanged(QList idList, bool bAnd) m_lpThumbnailSortFilterProxyModel->setTagList(idList, bAnd); showCount(); } + +void cMainWindow::onImageNext() +{ + qDebug() << "next image"; +} + +void cMainWindow::onImagePrev() +{ + qDebug() << "prev image"; +} + +void cMainWindow::onImageLast() +{ + qDebug() << "last image"; +} + +void cMainWindow::onImageFirst() +{ + qDebug() << "first image"; +} diff --git a/cmainwindow.h b/cmainwindow.h index 6818963..f403338 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -393,6 +393,31 @@ private slots: \param idList */ void onFilterTagChanged(QList idList, bool bAnd); + + /*! + \brief + + \fn onImageNext + */ + void onImageNext(); + /*! + \brief + + \fn onImagePrev + */ + void onImagePrev(); + /*! + \brief + + \fn onImageLast + */ + void onImageLast(); + /*! + \brief + + \fn onImageFirst + */ + void onImageFirst(); }; #endif // CMAINWINDOW_H diff --git a/common.cpp b/common.cpp index 165c709..561c670 100644 --- a/common.cpp +++ b/common.cpp @@ -127,11 +127,11 @@ QStandardItem* insertPath(QString szPath, QStandardItem* lpRootItem) switch(path) { case 0: - lpNewItem->setData(QVariant::fromValue(true), STYLEDDELEGATE_BOLD); + lpNewItem->setData(QVariant::fromValue(false), STYLEDDELEGATE_BOLD); lpNewItem->setData(QVariant::fromValue(false), STYLEDDELEGATE_ITALIC); break; case 1: - lpNewItem->setData(QVariant::fromValue(false), STYLEDDELEGATE_BOLD); + lpNewItem->setData(QVariant::fromValue(true), STYLEDDELEGATE_BOLD); lpNewItem->setData(QVariant::fromValue(false), STYLEDDELEGATE_ITALIC); break; case 2: