changeset 38:26e1521b9afd

Add the possibility to detach the picture label on doubleclick
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 06 May 2015 18:09:34 +0200
parents 0c05958d254c
children 5d05b812807b
files src/imagelabel.cpp src/imagelabel.h src/mainwindow.cpp src/pngplayer.cpp src/pngplayer.h
diffstat 5 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/imagelabel.cpp	Wed May 06 17:17:13 2015 +0200
+++ b/src/imagelabel.cpp	Wed May 06 18:09:34 2015 +0200
@@ -34,3 +34,13 @@
     pixSize.scale(size(), Qt::KeepAspectRatio);
     label->setFixedSize(pixSize);
 }
+
+void ImageLabel::mouseDoubleClickEvent(QMouseEvent * e) {
+    QWidget::mouseDoubleClickEvent(e);
+    emit doubleClicked();
+}
+
+void ImageLabel::closeEvent(QCloseEvent *e) {
+    Q_UNUSED(e);
+    emit closeRequested();
+}
--- a/src/imagelabel.h	Wed May 06 17:17:13 2015 +0200
+++ b/src/imagelabel.h	Wed May 06 18:09:34 2015 +0200
@@ -12,6 +12,8 @@
 #include <QPixmap>
 #include <QLabel>
 
+class QMouseEvent;
+
 class ImageLabel : public QWidget
 {
     Q_OBJECT
@@ -23,8 +25,14 @@
 public slots:
     void setPixmap(const QPixmap&);
 
+Q_SIGNALS:
+    void doubleClicked();
+    void closeRequested();
+
 protected:
     void resizeEvent(QResizeEvent *);
+    void mouseDoubleClickEvent(QMouseEvent * event);
+    void closeEvent(QCloseEvent *);
 
 private slots:
     void resizeImage();
--- a/src/mainwindow.cpp	Wed May 06 17:17:13 2015 +0200
+++ b/src/mainwindow.cpp	Wed May 06 18:09:34 2015 +0200
@@ -79,6 +79,7 @@
 void MainWindow::closeEvent(QCloseEvent *event) {
     mSettings.setValue("geometry", saveGeometry());
     mSettings.setValue("windowState", saveState());
+    mPlayer->close();
     QMainWindow::closeEvent(event);
 }
 
--- a/src/pngplayer.cpp	Wed May 06 17:17:13 2015 +0200
+++ b/src/pngplayer.cpp	Wed May 06 18:09:34 2015 +0200
@@ -34,6 +34,8 @@
     QVBoxLayout *baseLayout = new QVBoxLayout;
     mPNGLabel = new ImageLabel;
     mPNGLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    connect(mPNGLabel, &ImageLabel::doubleClicked, this, &PNGPlayer::togglePicFullscreen);
+    connect(mPNGLabel, &ImageLabel::closeRequested, this, &PNGPlayer::togglePicFullscreen);
 
     QHBoxLayout *controlArea = new QHBoxLayout;
     QHBoxLayout *controlBtns = new QHBoxLayout;
@@ -197,3 +199,30 @@
     QSettings settings;
     settings.setValue(REPLAY_SPEED_KEY, (mSpeedSlider->value() * REPLAY_SPEED_STEP_MS) / 1000.0);
 }
+
+void PNGPlayer::togglePicFullscreen() {
+    qDebug() << "togglePicFullscreen";
+    QVBoxLayout *baseLayout = qobject_cast<QVBoxLayout*>(layout());
+    if (!baseLayout) {
+        qWarning() << "Wrong layout!";
+        return;
+    }
+    if (baseLayout->indexOf(mPNGLabel) == -1) {
+        baseLayout->insertWidget(0, mPNGLabel);
+    } else {
+        baseLayout->removeWidget(mPNGLabel);
+        mPNGLabel->setParent(NULL, Qt::Tool);
+        mPNGLabel->showMaximized();
+    }
+}
+
+void PNGPlayer::close() {
+    QVBoxLayout *baseLayout = qobject_cast<QVBoxLayout*>(layout());
+    if (!baseLayout) {
+        qWarning() << "Wrong layout!";
+        return;
+    }
+    if (baseLayout->indexOf(mPNGLabel) == -1) {
+        delete mPNGLabel;
+    }
+}
--- a/src/pngplayer.h	Wed May 06 17:17:13 2015 +0200
+++ b/src/pngplayer.h	Wed May 06 18:09:34 2015 +0200
@@ -24,6 +24,12 @@
 public:
     PNGPlayer (QWidget * parent = 0, Qt::WindowFlags f = 0);
 
+    /**@brief close the player 
+     *
+     * This function makes sure that the png label is also
+     * closed when detached.
+     **/
+    void close();
 protected:
     void setupGUI();
 
@@ -68,6 +74,9 @@
     /**@brief the speed bar was changed */
     void speedChanged();
 
+    /**@brief detach the actual picture as fullscreen */
+    void togglePicFullscreen();
+
 Q_SIGNALS:
     /** @brief Emited if something went wrong. e.g. file not readable */
     void error(const QString& msg);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)