Mercurial > retraceit
diff src/pngplayer.cpp @ 3:248d5d1cdb38
Add functionalty to control buttons and make picture resizable
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 23 Mar 2015 19:10:01 +0100 |
parents | 97d2c8869c39 |
children | 107e435cb569 |
line wrap: on
line diff
--- a/src/pngplayer.cpp Mon Mar 23 16:34:42 2015 +0100 +++ b/src/pngplayer.cpp Mon Mar 23 19:10:01 2015 +0100 @@ -5,26 +5,89 @@ * See LICENSE.txt for details. */ #include "pngplayer.h" +#include "constants.h" +#include "imagelabel.h" #include <QVBoxLayout> #include <QPixmap> #include <QLabel> +#include <QPushButton> +#include <QHBoxLayout> +#include <QSlider> + +#include <QDebug> PNGPlayer::PNGPlayer(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { setupGUI(); - return; } void PNGPlayer::setupGUI() { QVBoxLayout *baseLayout = new QVBoxLayout; - mPNGLabel = new QLabel; + mPNGLabel = new ImageLabel; + mPNGLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QHBoxLayout *controlArea = new QHBoxLayout; + QHBoxLayout *controlBtns = new QHBoxLayout; + controlArea->addLayout(controlBtns); + + QPushButton *firstBtn = new QPushButton("First"); + controlBtns->addWidget(firstBtn); + connect(firstBtn, &QPushButton::clicked, this, &PNGPlayer::firstClicked); + + QPushButton *prevBtn = new QPushButton("Prev"); + controlBtns->addWidget(prevBtn); + connect(prevBtn, &QPushButton::clicked, this, &PNGPlayer::back); + + mPlayBtn = new QPushButton("Play"); + mPlayBtn->setCheckable(true); + controlBtns->addWidget(mPlayBtn); + connect(mPlayBtn, &QPushButton::clicked, this, &PNGPlayer::togglePlay); + + QPushButton *nextBtn = new QPushButton("Next"); + connect(nextBtn, &QPushButton::clicked, this, &PNGPlayer::advance); + controlBtns->addWidget(nextBtn); + + QPushButton *lastBtn = new QPushButton("Last"); + controlBtns->addWidget(lastBtn); + connect(lastBtn, &QPushButton::clicked, this, &PNGPlayer::lastClicked); + + mSlider = new QSlider(Qt::Horizontal); + mSlider->setTickPosition(QSlider::TicksBelow); + connect(mSlider, &QSlider::valueChanged, this, &PNGPlayer::sliderChanged); + connect(mSlider, &QSlider::sliderPressed, this, &PNGPlayer::sliderPressed); + connect(mSlider, &QSlider::sliderReleased, this, &PNGPlayer::sliderReleased); + + QVBoxLayout *speedInfoArea = new QVBoxLayout; + QHBoxLayout *speedArea = new QHBoxLayout; + speedInfoArea->addLayout(speedArea); + + QLabel *speedLabel = new QLabel(tr("Speed:")); + speedArea->addWidget(speedLabel); + + mSpeedSlider = new QSlider(Qt::Horizontal); + mSpeedSlider->setMaximum(10000); + mSpeedSlider->setTickInterval(500); + mSpeedSlider->setTickPosition(QSlider::TicksBelow); + speedArea->addWidget(mSpeedSlider); + + mCurSpeedLabel = new QLabel; + speedArea->addWidget(mCurSpeedLabel); + speedArea->addStretch(-1); + + mPositionLabel = new QLabel; + speedInfoArea->addWidget(mPositionLabel); + + controlArea->addLayout(speedInfoArea); + baseLayout->addWidget(mPNGLabel); + baseLayout->addLayout(controlArea); + baseLayout->addWidget(mSlider); + connect(&mAdvanceTimer, SIGNAL(timeout()), this, SIGNAL(advance())); setLayout(baseLayout); - mAdvanceTimer.setInterval(2000); - mAdvanceTimer.start(); } -void PNGPlayer::showPicture(const QString& fileName, const QString& info) { +void PNGPlayer::showPicture(const QString& fileName, int current, int max, + const QDateTime& timestamp) { QPixmap pic(mBaseDir.filePath(fileName)); /* If this is too slow we could use a pixmap cache here and do * some intelligent preloading */ @@ -33,4 +96,69 @@ return; } mPNGLabel->setPixmap(pic); + updatePositions(current, max, timestamp); } + +void PNGPlayer::updatePositions(int current, int max, const QDateTime& timestamp) { + mMax = max; + mSlider->blockSignals(true); /* We only want user generated changes */ + mSlider->setValue(current); + mSlider->blockSignals(false); + mSlider->setMaximum(max); + mPositionLabel->setText("<b>" + tr("Screenshot Nr.:") + " </b>" + + QString("%1 (%2)").arg(current).arg(max) + " / <b>" + + tr("Timestamp:") + " </b>" + timestamp.toString(LONG_DATE_FORMAT)); + + if (mMax == current && mAdvanceTimer.isActive()) { + togglePlay(); + } +} + +void PNGPlayer::setSpeed(int mSecsPerPicture) { + if (mSecsPerPicture == 1000) { + mCurSpeedLabel->setText(tr("%1 second per Picture"). + arg(mSecsPerPicture / 1000)); + } else { + mCurSpeedLabel->setText(tr("%1 seconds per Picture"). + arg(mSecsPerPicture / 1000)); + } + mSpeedSlider->setValue(mSecsPerPicture); + mAdvanceTimer.setInterval(mSecsPerPicture); +} + +void PNGPlayer::togglePlay() { + if (mAdvanceTimer.isActive()) { + mAdvanceTimer.stop(); + mPlayBtn->setText("Play"); + mPlayBtn->setChecked(false); + } else { + mAdvanceTimer.start(); + mPlayBtn->setText("Pause"); + mPlayBtn->setChecked(true); + emit advance(); + } +} + +void PNGPlayer::sliderChanged() { + qDebug() << "Slider moved. "; + emit jumpToFrame(mSlider->value()); +} + +void PNGPlayer::sliderPressed() { + qDebug() << "Slider pressed. Deactivating timer. "; + mAdvanceTimer.stop(); +} + +void PNGPlayer::sliderReleased() { + if (mPlayBtn->isChecked()) { + mAdvanceTimer.start(); + } +} + +void PNGPlayer::firstClicked() { + emit jumpToFrame(0); +} + +void PNGPlayer::lastClicked() { + emit jumpToFrame(mMax); +}