# HG changeset patch # User Andre Heinecke # Date 1430928574 -7200 # Node ID 26e1521b9afd672f0f5ae57f657296f6d788e9a7 # Parent 0c05958d254c95be152e0d4f42c07a1328f4cef3 Add the possibility to detach the picture label on doubleclick diff -r 0c05958d254c -r 26e1521b9afd src/imagelabel.cpp --- 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(); +} diff -r 0c05958d254c -r 26e1521b9afd src/imagelabel.h --- 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 #include +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(); diff -r 0c05958d254c -r 26e1521b9afd src/mainwindow.cpp --- 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); } diff -r 0c05958d254c -r 26e1521b9afd src/pngplayer.cpp --- 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(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(layout()); + if (!baseLayout) { + qWarning() << "Wrong layout!"; + return; + } + if (baseLayout->indexOf(mPNGLabel) == -1) { + delete mPNGLabel; + } +} diff -r 0c05958d254c -r 26e1521b9afd src/pngplayer.h --- 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);