diff options
author | Kai Koehne <[email protected]> | 2010-09-01 17:37:28 +0200 |
---|---|---|
committer | Kai Koehne <[email protected]> | 2010-09-03 12:29:41 +0200 |
commit | 5f1d93c3039215c4db53b2745f0c3466f3e77921 (patch) | |
tree | af0d2e91b484874e6be00509251a89855b4fcee2 /src/tools/qml | |
parent | b7788bd80853eccd216b87c7751fde2e67a777df (diff) |
QmlObserver: Allow changing the animation speed / pausing it via menu
Diffstat (limited to 'src/tools/qml')
-rw-r--r-- | src/tools/qml/qmlobserver/qmlruntime.cpp | 71 | ||||
-rw-r--r-- | src/tools/qml/qmlobserver/qmlruntime.h | 9 |
2 files changed, 70 insertions, 10 deletions
diff --git a/src/tools/qml/qmlobserver/qmlruntime.cpp b/src/tools/qml/qmlobserver/qmlruntime.cpp index 8720a8503b5..4a7e9b880dc 100644 --- a/src/tools/qml/qmlobserver/qmlruntime.cpp +++ b/src/tools/qml/qmlobserver/qmlruntime.cpp @@ -590,6 +590,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) addToolBar(Qt::TopToolBarArea, canvas->toolbar()); canvas->toolbar()->setFloatable(false); canvas->toolbar()->setMovable(false); + m_crumblePathWidget = new Utils::CrumblePath(this); #ifndef Q_WS_MAC QFile file(":/toolbarstyle.css"); @@ -715,10 +716,43 @@ void QDeclarativeViewer::createMenu() QAction *recordOptions = new QAction(tr("Video &Options..."), this); connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions())); - QAction *slowAction = new QAction(tr("&Slow Down Animations"), this); - slowAction->setShortcut(QKeySequence("Ctrl+.")); - slowAction->setCheckable(true); - connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); + QMenu *playSpeedMenu = new QMenu(tr("Animation Speed"), this); + QActionGroup *playSpeedMenuActions = new QActionGroup(this); + playSpeedMenuActions->setExclusive(true); + + QAction *speedAction = playSpeedMenu->addAction(tr("1x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setChecked(true); + animationSpeed = 1.0f; + speedAction->setData(1.0f); + playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.5x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(2.0f); + playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.25x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(4.0f); + playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.125x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(8.0f); + playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.1x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(10.0f); + playSpeedMenuActions->addAction(speedAction); + + pauseAnimationsAction = playSpeedMenu->addAction(tr("Pause"), this, SLOT(pauseAnimations(bool))); + pauseAnimationsAction->setCheckable(true); + pauseAnimationsAction->setShortcut(QKeySequence("Ctrl+.")); + + QAction *playSpeedAction = new QAction(tr("Animations"), this); + playSpeedAction->setMenu(playSpeedMenu); showWarningsWindow = new QAction(tr("Show Warnings"), this); showWarningsWindow->setCheckable((true)); @@ -777,7 +811,7 @@ void QDeclarativeViewer::createMenu() menu->addAction(recordOptions); menu->addAction(proxyAction); - menu->addAction(slowAction); + menu->addAction(playSpeedMenu); menu->addAction(showWarningsWindow); orientation->addAction(landscapeAction); @@ -799,7 +833,7 @@ void QDeclarativeViewer::createMenu() recordMenu->addAction(recordAction); QMenu *debugMenu = menu->addMenu(tr("&Debugging")); - debugMenu->addAction(slowAction); + debugMenu->addAction(playSpeedAction); debugMenu->addAction(showWarningsWindow); debugMenu->addAction(designModeBehaviorAction); #endif // ! Q_OS_SYMBIAN @@ -943,9 +977,24 @@ void QDeclarativeViewer::toggleRecording() setRecording(recording); } -void QDeclarativeViewer::setSlowMode(bool enable) +void QDeclarativeViewer::pauseAnimations(bool enable) { - QUnifiedTimer::instance()->setSlowModeEnabled(enable); + if (enable) { + setAnimationSpeed(0.0); + } else { + setAnimationSpeed(animationSpeed); + } +} + +void QDeclarativeViewer::changeAnimationSpeed() +{ + QAction *action = qobject_cast<QAction*>(sender()); + if (action) { + float f = action->data().toFloat(); + animationSpeed = f; + if (!pauseAnimationsAction->isChecked()) + setAnimationSpeed(animationSpeed); + } } void QDeclarativeViewer::addLibraryPath(const QString& lib) @@ -1424,6 +1473,12 @@ void QDeclarativeViewer::setSizeToView(bool sizeToView) } } +void QDeclarativeViewer::setAnimationSpeed(float f) +{ + QUnifiedTimer::instance()->setSlowdownFactor(f); + QUnifiedTimer::instance()->setSlowModeEnabled(f != 1.0); +} + void QDeclarativeViewer::updateSizeHints(bool initial) { static bool isRecursive = false; diff --git a/src/tools/qml/qmlobserver/qmlruntime.h b/src/tools/qml/qmlobserver/qmlruntime.h index 47491e67125..c4653201c79 100644 --- a/src/tools/qml/qmlobserver/qmlruntime.h +++ b/src/tools/qml/qmlobserver/qmlruntime.h @@ -131,7 +131,8 @@ public slots: void proxySettingsChanged (); void rotateOrientation(); void statusChanged(); - void setSlowMode(bool); + void pauseAnimations(bool); + void changeAnimationSpeed(); void launch(const QString &); protected: @@ -155,13 +156,14 @@ private slots: void warningsWidgetOpened(); void warningsWidgetClosed(); - private: + void setAnimationSpeed(float f); void updateSizeHints(bool initial = false); QString getVideoFileName(); LoggerWidget *loggerWindow; + QmlViewer::QDeclarativeDesignView *canvas; QSize initialSize; QString currentFileOrUrl; @@ -190,6 +192,9 @@ private: bool ffmpegAvailable; bool convertAvailable; + float animationSpeed; + QAction *pauseAnimationsAction; + QActionGroup *orientation; QAction *showWarningsWindow; QAction *designModeBehaviorAction; |