Mercurial > retraceit
comparison src/pngplayer.cpp @ 5:107e435cb569
Enable speed slider in pngplayer
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 25 Mar 2015 14:24:38 +0100 |
parents | 248d5d1cdb38 |
children | c11fe56aa4a2 |
comparison
equal
deleted
inserted
replaced
4:e4748da7140b | 5:107e435cb569 |
---|---|
11 #include <QPixmap> | 11 #include <QPixmap> |
12 #include <QLabel> | 12 #include <QLabel> |
13 #include <QPushButton> | 13 #include <QPushButton> |
14 #include <QHBoxLayout> | 14 #include <QHBoxLayout> |
15 #include <QSlider> | 15 #include <QSlider> |
16 #include <QSettings> | |
16 | 17 |
17 #include <QDebug> | 18 #include <QDebug> |
18 | 19 |
19 PNGPlayer::PNGPlayer(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { | 20 PNGPlayer::PNGPlayer(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { |
20 setupGUI(); | 21 setupGUI(); |
22 QSettings settings; | |
23 mSpeedSlider->setValue(settings.value(REPLAY_SPEED_KEY, REPLAY_SPEED_DEFAULT).toInt()); | |
24 speedChanged(); | |
21 } | 25 } |
22 | 26 |
23 void PNGPlayer::setupGUI() { | 27 void PNGPlayer::setupGUI() { |
24 QVBoxLayout *baseLayout = new QVBoxLayout; | 28 QVBoxLayout *baseLayout = new QVBoxLayout; |
25 mPNGLabel = new ImageLabel; | 29 mPNGLabel = new ImageLabel; |
62 | 66 |
63 QLabel *speedLabel = new QLabel(tr("Speed:")); | 67 QLabel *speedLabel = new QLabel(tr("Speed:")); |
64 speedArea->addWidget(speedLabel); | 68 speedArea->addWidget(speedLabel); |
65 | 69 |
66 mSpeedSlider = new QSlider(Qt::Horizontal); | 70 mSpeedSlider = new QSlider(Qt::Horizontal); |
67 mSpeedSlider->setMaximum(10000); | 71 mSpeedSlider->setMaximum(10); |
68 mSpeedSlider->setTickInterval(500); | 72 mSpeedSlider->setTickInterval(1); |
69 mSpeedSlider->setTickPosition(QSlider::TicksBelow); | 73 mSpeedSlider->setTickPosition(QSlider::TicksBelow); |
74 mSpeedSlider->setTracking(false); | |
75 mSpeedSlider->setInvertedAppearance(true); | |
76 | |
70 speedArea->addWidget(mSpeedSlider); | 77 speedArea->addWidget(mSpeedSlider); |
78 connect(mSpeedSlider, &QSlider::valueChanged, this, &PNGPlayer::speedChanged); | |
71 | 79 |
72 mCurSpeedLabel = new QLabel; | 80 mCurSpeedLabel = new QLabel; |
73 speedArea->addWidget(mCurSpeedLabel); | 81 speedArea->addWidget(mCurSpeedLabel); |
74 speedArea->addStretch(-1); | 82 speedArea->addStretch(-1); |
75 | 83 |
115 } | 123 } |
116 | 124 |
117 void PNGPlayer::setSpeed(int mSecsPerPicture) { | 125 void PNGPlayer::setSpeed(int mSecsPerPicture) { |
118 if (mSecsPerPicture == 1000) { | 126 if (mSecsPerPicture == 1000) { |
119 mCurSpeedLabel->setText(tr("%1 second per Picture"). | 127 mCurSpeedLabel->setText(tr("%1 second per Picture"). |
120 arg(mSecsPerPicture / 1000)); | 128 arg(mSecsPerPicture / 1000.)); |
121 } else { | 129 } else { |
122 mCurSpeedLabel->setText(tr("%1 seconds per Picture"). | 130 mCurSpeedLabel->setText(tr("%1 seconds per Picture"). |
123 arg(mSecsPerPicture / 1000)); | 131 arg(mSecsPerPicture / 1000.)); |
124 } | 132 } |
125 mSpeedSlider->setValue(mSecsPerPicture); | |
126 mAdvanceTimer.setInterval(mSecsPerPicture); | 133 mAdvanceTimer.setInterval(mSecsPerPicture); |
127 } | 134 } |
128 | 135 |
129 void PNGPlayer::togglePlay() { | 136 void PNGPlayer::togglePlay() { |
130 if (mAdvanceTimer.isActive()) { | 137 if (mAdvanceTimer.isActive()) { |
160 } | 167 } |
161 | 168 |
162 void PNGPlayer::lastClicked() { | 169 void PNGPlayer::lastClicked() { |
163 emit jumpToFrame(mMax); | 170 emit jumpToFrame(mMax); |
164 } | 171 } |
172 | |
173 void PNGPlayer::speedChanged() { | |
174 if (mSpeedSlider->value()) { | |
175 setSpeed(mSpeedSlider->value() * REPLAY_SPEED_STEP_MS); | |
176 } else { | |
177 setSpeed(REPLAY_SPEED_STEP_MS / 2); | |
178 } | |
179 QSettings settings; | |
180 settings.setValue(REPLAY_SPEED_KEY, mSpeedSlider->value()); | |
181 } |