changeset 5:107e435cb569

Enable speed slider in pngplayer
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 25 Mar 2015 14:24:38 +0100
parents e4748da7140b
children 031ce03cfdf2
files src/constants.h src/mainwindow.cpp src/mainwindow.h src/pngplayer.cpp src/pngplayer.h
diffstat 5 files changed, 49 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/constants.h	Wed Mar 25 14:23:46 2015 +0100
+++ b/src/constants.h	Wed Mar 25 14:24:38 2015 +0100
@@ -57,9 +57,12 @@
 #define LONG_DATE_FORMAT "dd.MM.yyyy, hh:mm:ss.zzz"
 
 /**@def the config key for the replay speed */
-#define REPLAY_SPEED_KEY "MSecsPerPicture"
+#define REPLAY_SPEED_KEY "Speed"
 
-/**@def the default value for the replay speed in ms*/
-#define REPLAY_SPEED_DEFAULT 1000
+/**@def the default value for the replay speed in REPLAY_SPEED_STEP_MS steps */
+#define REPLAY_SPEED_DEFAULT 5
+
+/**@def the value for a step in the speed slider */
+#define REPLAY_SPEED_STEP_MS 500
 
 #endif // CONSTANTS_H
--- a/src/mainwindow.cpp	Wed Mar 25 14:23:46 2015 +0100
+++ b/src/mainwindow.cpp	Wed Mar 25 14:24:38 2015 +0100
@@ -63,7 +63,8 @@
     connect (mPlayer, &PNGPlayer::jumpToFrame, mDataView, &MetaDataView::selectRow);
     connect (mDataView, &MetaDataView::selectionChanged, mPlayer,
              &PNGPlayer::showPicture);
-    mPlayer->setSpeed(mSettings.value(REPLAY_SPEED_KEY, REPLAY_SPEED_DEFAULT).toInt());
+    connect (mDataView, &MetaDataView::selectionChanged, this,
+             &MainWindow::showPictureNameStatus);
 }
 
 void MainWindow::showErrorMessage(const QString& errMsg) {
@@ -149,3 +150,10 @@
     mPlayer->setBaseDir(folder);
     mDataView->selectNextRow();
 }
+
+void MainWindow::showPictureNameStatus(const QString& fileName, int current,
+            int max, const QDateTime& timestamp) {
+    if (current != 0 && max != 0) {
+        statusBar()->showMessage(tr("Showing: '%1'").arg(fileName));
+    }
+}
--- a/src/mainwindow.h	Wed Mar 25 14:23:46 2015 +0100
+++ b/src/mainwindow.h	Wed Mar 25 14:24:38 2015 +0100
@@ -12,6 +12,7 @@
  */
 #include <QMainWindow>
 #include <QSettings>
+#include <QDateTime>
 
 class QPushButton;
 class QDropEvent;
@@ -52,6 +53,13 @@
     /** @brief Show an error dialog to the user. */
     void showErrorMessage(const QString& errMsg);
 
+    /** @brief update the status bar for the image.
+     *
+     * Function signature is similar to showPicture in pngviewer
+     */
+    void showPictureNameStatus(const QString& fileName, int current,
+            int max, const QDateTime& timestamp );
+
 private:
     QSettings mSettings;
 
--- a/src/pngplayer.cpp	Wed Mar 25 14:23:46 2015 +0100
+++ b/src/pngplayer.cpp	Wed Mar 25 14:24:38 2015 +0100
@@ -13,11 +13,15 @@
 #include <QPushButton>
 #include <QHBoxLayout>
 #include <QSlider>
+#include <QSettings>
 
 #include <QDebug>
 
 PNGPlayer::PNGPlayer(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) {
     setupGUI();
+    QSettings settings;
+    mSpeedSlider->setValue(settings.value(REPLAY_SPEED_KEY, REPLAY_SPEED_DEFAULT).toInt());
+    speedChanged();
 }
 
 void PNGPlayer::setupGUI() {
@@ -64,10 +68,14 @@
     speedArea->addWidget(speedLabel);
 
     mSpeedSlider = new QSlider(Qt::Horizontal);
-    mSpeedSlider->setMaximum(10000);
-    mSpeedSlider->setTickInterval(500);
+    mSpeedSlider->setMaximum(10);
+    mSpeedSlider->setTickInterval(1);
     mSpeedSlider->setTickPosition(QSlider::TicksBelow);
+    mSpeedSlider->setTracking(false);
+    mSpeedSlider->setInvertedAppearance(true);
+
     speedArea->addWidget(mSpeedSlider);
+    connect(mSpeedSlider, &QSlider::valueChanged, this, &PNGPlayer::speedChanged);
 
     mCurSpeedLabel = new QLabel;
     speedArea->addWidget(mCurSpeedLabel);
@@ -117,12 +125,11 @@
 void PNGPlayer::setSpeed(int mSecsPerPicture) {
     if (mSecsPerPicture == 1000) {
         mCurSpeedLabel->setText(tr("%1 second per Picture").
-                                arg(mSecsPerPicture / 1000));
+                                arg(mSecsPerPicture / 1000.));
     } else {
         mCurSpeedLabel->setText(tr("%1 seconds per Picture").
-                                arg(mSecsPerPicture / 1000));
+                                arg(mSecsPerPicture / 1000.));
     }
-    mSpeedSlider->setValue(mSecsPerPicture);
     mAdvanceTimer.setInterval(mSecsPerPicture);
 }
 
@@ -162,3 +169,13 @@
 void PNGPlayer::lastClicked() {
     emit jumpToFrame(mMax);
 }
+
+void PNGPlayer::speedChanged() {
+    if (mSpeedSlider->value()) {
+        setSpeed(mSpeedSlider->value() * REPLAY_SPEED_STEP_MS);
+    } else {
+        setSpeed(REPLAY_SPEED_STEP_MS / 2);
+    }
+    QSettings settings;
+    settings.setValue(REPLAY_SPEED_KEY, mSpeedSlider->value());
+}
--- a/src/pngplayer.h	Wed Mar 25 14:23:46 2015 +0100
+++ b/src/pngplayer.h	Wed Mar 25 14:24:38 2015 +0100
@@ -62,6 +62,10 @@
 
     /**@brief start or pause the replay */
     void togglePlay();
+
+    /**@brief the speed bar was changed */
+    void speedChanged();
+
 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)