From 63da8d4cd790c3cd01876b6fe267be536e648c3d Mon Sep 17 00:00:00 2001
From: Lasse Holmstedt <lasse.holmstedt@nokia.com>
Date: Mon, 23 Aug 2010 15:57:45 +0200
Subject: [PATCH] QML Inspector: combined pause & play actions into one button

Easier to use now by just clicking on one button, and takes less space.
---
 .../qmljsinspector/qmlinspectortoolbar.cpp    | 93 ++++++++++---------
 .../qmljsinspector/qmlinspectortoolbar.h      | 18 ++--
 src/plugins/qmljsinspector/qmljsinspector.cpp |  4 +-
 .../qmljsinspector/qmljsinspectorconstants.h  |  1 -
 4 files changed, 62 insertions(+), 54 deletions(-)

diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp b/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp
index 55a0908b663..a63fa116da5 100644
--- a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp
+++ b/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp
@@ -61,7 +61,6 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
     m_designmodeAction(0),
     m_reloadAction(0),
     m_playAction(0),
-    m_pauseAction(0),
     m_selectAction(0),
     m_selectMarqueeAction(0),
     m_zoomAction(0),
@@ -74,6 +73,8 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
     m_eighthAnimSpeedAction(0),
     m_tenthAnimSpeedAction(0),
     m_menuPauseAction(0),
+    m_playIcon(QIcon(QLatin1String(":/qml/images/play-small.png"))),
+    m_pauseIcon(QIcon(QLatin1String(":/qml/images/pause-small.png"))),
     m_colorBox(0),
     m_emitSignals(true),
     m_isRunning(false),
@@ -93,7 +94,6 @@ void QmlInspectorToolbar::setEnabled(bool value)
 
     m_reloadAction->setEnabled(value);
     m_playAction->setEnabled(value);
-    m_pauseAction->setEnabled(value);
     m_selectAction->setEnabled(value);
     m_selectMarqueeAction->setEnabled(value);
     m_zoomAction->setEnabled(value);
@@ -108,14 +108,14 @@ void QmlInspectorToolbar::enable()
     setEnabled(true);
     m_emitSignals = false;
     m_designmodeAction->setChecked(false);
-    changeAnimationSpeed(1.0f);
+    setAnimationSpeed(1.0f);
     activateDesignModeOnClick();
     m_emitSignals = true;
 }
 
 void QmlInspectorToolbar::disable()
 {
-    changeAnimationSpeed(1.0f);
+    setAnimationSpeed(1.0f);
     activateSelectTool();
     setEnabled(false);
 }
@@ -148,12 +148,10 @@ void QmlInspectorToolbar::activateZoomTool()
     m_emitSignals = true;
 }
 
-void QmlInspectorToolbar::changeAnimationSpeed(qreal slowdownFactor)
+void QmlInspectorToolbar::setAnimationSpeed(qreal slowdownFactor)
 {
     m_emitSignals = false;
-    if (slowdownFactor == 0) {
-        activatePauseOnClick();
-    } else {
+    if (slowdownFactor != 0) {
         m_animationSpeed = slowdownFactor;
 
         if (slowdownFactor == 1.0f) {
@@ -167,9 +165,11 @@ void QmlInspectorToolbar::changeAnimationSpeed(qreal slowdownFactor)
         } else if (slowdownFactor == 10.0f) {
             m_tenthAnimSpeedAction->setChecked(true);
         }
-
-        activatePlayOnClick();
+        updatePlayAction();
+    } else {
+        updatePauseAction();
     }
+
     m_emitSignals = true;
 }
 
@@ -190,8 +190,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
     m_designmodeAction = new QAction(QIcon(QLatin1String(":/qml/images/designmode.png")), tr("Design Mode"), this);
 
     m_reloadAction = new QAction(QIcon(QLatin1String(":/qml/images/reload.png")), tr("Reload"), this);
-    m_playAction = new QAction(QIcon(QLatin1String(":/qml/images/play-small.png")), tr("Play animations"), this);
-    m_pauseAction = new QAction(QIcon(QLatin1String(":/qml/images/pause-small.png")), tr("Pause animations"), this);
+    m_playAction = new QAction(m_playIcon, tr("Play animations"), this);
     m_selectAction = new QAction(QIcon(QLatin1String(":/qml/images/select-small.png")), tr("Select"), this);
     m_selectMarqueeAction = new QAction(QIcon(QLatin1String(":/qml/images/select-marquee-small.png")), tr("Select (Marquee)"), this);
     m_zoomAction = new QAction(QIcon(QLatin1String(":/qml/images/zoom-small.png")), tr("Zoom"), this);
@@ -200,9 +199,6 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
 
     m_designmodeAction->setCheckable(true);
     m_designmodeAction->setChecked(false);
-    m_playAction->setCheckable(true);
-    m_playAction->setChecked(true);
-    m_pauseAction->setCheckable(true);
     m_selectAction->setCheckable(true);
     m_selectMarqueeAction->setCheckable(true);
     m_zoomAction->setCheckable(true);
@@ -214,7 +210,6 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
     am->registerAction(m_designmodeAction, QmlJSInspector::Constants::DESIGNMODE_ACTION, context);
     am->registerAction(m_reloadAction, QmlJSInspector::Constants::RELOAD_ACTION, context);
     am->registerAction(m_playAction, QmlJSInspector::Constants::PLAY_ACTION, context);
-    am->registerAction(m_pauseAction, QmlJSInspector::Constants::PAUSE_ACTION, context);
     am->registerAction(m_selectAction, QmlJSInspector::Constants::SELECT_ACTION, context);
     am->registerAction(m_selectMarqueeAction, QmlJSInspector::Constants::SELECT_MARQUEE_ACTION, context);
     am->registerAction(m_zoomAction, QmlJSInspector::Constants::ZOOM_ACTION, context);
@@ -256,8 +251,9 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
     m_tenthAnimSpeedAction->setCheckable(true);
     playSpeedMenuActions->addAction(m_tenthAnimSpeedAction);
 
-    m_menuPauseAction = playSpeedMenu->addAction(tr("Pause"), this, SLOT(activatePauseOnClick()));
+    m_menuPauseAction = playSpeedMenu->addAction(tr("Pause"), this, SLOT(updatePauseAction()));
     m_menuPauseAction->setCheckable(true);
+    m_menuPauseAction->setIcon(m_pauseIcon);
     playSpeedMenuActions->addAction(m_menuPauseAction);
 
 //    configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::DEBUG)->action()));
@@ -266,10 +262,10 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
     configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::DESIGNMODE_ACTION)->action()));
     configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::RELOAD_ACTION)->action()));
 
-    QToolButton *playButton = createToolButton(am->command(QmlJSInspector::Constants::PLAY_ACTION)->action());
-    playButton->setMenu(playSpeedMenu);
-    configBarLayout->addWidget(playButton);
-    configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::PAUSE_ACTION)->action()));
+    m_playButton = createToolButton(am->command(QmlJSInspector::Constants::PLAY_ACTION)->action());
+    m_playButton->setMenu(playSpeedMenu);
+    configBarLayout->addWidget(m_playButton);
+    //configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::PAUSE_ACTION)->action()));
 
     configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::SELECT_ACTION)->action()));
     configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::SELECT_MARQUEE_ACTION)->action()));
@@ -285,10 +281,10 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
     configBarLayout->addWidget(m_colorBox);
     //configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::TO_QML_ACTION)->action()));
 
-    m_filterLineEdit = new Utils::FilterLineEdit(m_barWidget);
+    //m_filterLineEdit = new Utils::FilterLineEdit(m_barWidget);
 
     configBarLayout->addStretch();
-    configBarLayout->addWidget(m_filterLineEdit);
+    //configBarLayout->addWidget(m_filterLineEdit);
 
     setEnabled(false);
 
@@ -298,7 +294,6 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
     connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
 
     connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick()));
-    connect(m_pauseAction, SIGNAL(triggered()), SLOT(activatePauseOnClick()));
 
     connect(m_zoomAction, SIGNAL(triggered()), SLOT(activateZoomOnClick()));
     connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
@@ -317,31 +312,31 @@ QWidget *QmlInspectorToolbar::widget() const
 void QmlInspectorToolbar::changeToDefaultAnimSpeed()
 {
     m_animationSpeed = 1.0f;
-    activatePlayOnClick();
+    updatePlayAction();
 }
 
 void QmlInspectorToolbar::changeToHalfAnimSpeed()
 {
     m_animationSpeed = 2.0f;
-    activatePlayOnClick();
+    updatePlayAction();
 }
 
 void QmlInspectorToolbar::changeToFourthAnimSpeed()
 {
     m_animationSpeed = 4.0f;
-    activatePlayOnClick();
+    updatePlayAction();
 }
 
 void QmlInspectorToolbar::changeToEighthAnimSpeed()
 {
     m_animationSpeed = 8.0f;
-    activatePlayOnClick();
+    updatePlayAction();
 }
 
 void QmlInspectorToolbar::changeToTenthAnimSpeed()
 {
     m_animationSpeed = 10.0f;
-    activatePlayOnClick();
+    updatePlayAction();
 }
 
 void QmlInspectorToolbar::activateDesignModeOnClick()
@@ -350,7 +345,6 @@ void QmlInspectorToolbar::activateDesignModeOnClick()
 
     m_reloadAction->setEnabled(true);
     m_playAction->setEnabled(checked);
-    m_pauseAction->setEnabled(checked);
     m_selectAction->setEnabled(checked);
     m_selectMarqueeAction->setEnabled(checked);
     m_zoomAction->setEnabled(checked);
@@ -362,25 +356,34 @@ void QmlInspectorToolbar::activateDesignModeOnClick()
 
 void QmlInspectorToolbar::activatePlayOnClick()
 {
-    m_pauseAction->setChecked(false);
-    if (!m_isRunning || m_animationSpeed != m_previousAnimationSpeed) {
-        m_playAction->setChecked(true);
-        m_isRunning = true;
-        m_previousAnimationSpeed = m_animationSpeed;
-        if (m_emitSignals)
-            emit animationSpeedChanged(m_animationSpeed);
+    if (m_isRunning) {
+        updatePauseAction();
+    } else {
+        updatePlayAction();
     }
 }
 
-void QmlInspectorToolbar::activatePauseOnClick()
+void QmlInspectorToolbar::updatePlayAction()
 {
-    m_playAction->setChecked(false);
-    if (m_isRunning) {
-        m_isRunning = false;
-        m_pauseAction->setChecked(true);
-        if (m_emitSignals)
-            emit animationSpeedChanged(0.0f);
-    }
+    m_isRunning = true;
+    m_playAction->setIcon(m_playIcon);
+    if (m_animationSpeed != m_previousAnimationSpeed)
+        m_previousAnimationSpeed = m_animationSpeed;
+
+    if (m_emitSignals)
+        emit animationSpeedChanged(m_animationSpeed);
+
+    m_playButton->setDefaultAction(m_playAction);
+}
+
+void QmlInspectorToolbar::updatePauseAction()
+{
+    m_isRunning = false;
+    m_playAction->setIcon(m_pauseIcon);
+    if (m_emitSignals)
+        emit animationSpeedChanged(0.0f);
+
+    m_playButton->setDefaultAction(m_playAction);
 }
 
 void QmlInspectorToolbar::activateColorPickerOnClick()
diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.h b/src/plugins/qmljsinspector/qmlinspectortoolbar.h
index 8b9309a0512..9d2d4165fc9 100644
--- a/src/plugins/qmljsinspector/qmlinspectortoolbar.h
+++ b/src/plugins/qmljsinspector/qmlinspectortoolbar.h
@@ -31,10 +31,11 @@
 #define QMLINSPECTORTOOLBAR_H
 
 #include <QObject>
+#include <QIcon>
 
-QT_FORWARD_DECLARE_CLASS(QAction);
-QT_FORWARD_DECLARE_CLASS(QColor);
-
+QT_FORWARD_DECLARE_CLASS(QAction)
+QT_FORWARD_DECLARE_CLASS(QColor)
+QT_FORWARD_DECLARE_CLASS(QToolButton)
 namespace Core {
     class Context;
 }
@@ -77,7 +78,7 @@ public slots:
     void activateSelectTool();
     void activateMarqueeSelectTool();
     void activateZoomTool();
-    void changeAnimationSpeed(qreal slowdownFactor);
+    void setAnimationSpeed(qreal slowdownFactor);
     void setDesignModeBehavior(bool inDesignMode);
     void setSelectedColor(const QColor &color);
 
@@ -99,7 +100,6 @@ signals:
 private slots:
     void activateDesignModeOnClick();
     void activatePlayOnClick();
-    void activatePauseOnClick();
     void activateColorPickerOnClick();
     void activateSelectToolOnClick();
     void activateMarqueeSelectToolOnClick();
@@ -114,11 +114,13 @@ private slots:
     void activateFromQml();
     void activateToQml();
 
+    void updatePlayAction();
+    void updatePauseAction();
+
 private:
     QAction *m_designmodeAction;
     QAction *m_reloadAction;
     QAction *m_playAction;
-    QAction *m_pauseAction;
     QAction *m_selectAction;
     QAction *m_selectMarqueeAction;
     QAction *m_zoomAction;
@@ -133,6 +135,10 @@ private:
     QAction *m_tenthAnimSpeedAction;
     QAction *m_menuPauseAction;
 
+    QToolButton *m_playButton;
+    QIcon m_playIcon;
+    QIcon m_pauseIcon;
+
     ToolBarColorBox *m_colorBox;
 
     bool m_emitSignals;
diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp
index 315126abeab..55f43a9d719 100644
--- a/src/plugins/qmljsinspector/qmljsinspector.cpp
+++ b/src/plugins/qmljsinspector/qmljsinspector.cpp
@@ -600,7 +600,7 @@ void InspectorUi::setupToolbar(bool doConnect)
         connect(m_clientProxy, SIGNAL(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool)));
         connect(m_clientProxy, SIGNAL(selectedColorChanged(QColor)), m_toolbar, SLOT(setSelectedColor(QColor)));
 
-        connect(m_clientProxy, SIGNAL(animationSpeedChanged(qreal)), m_toolbar, SLOT(changeAnimationSpeed(qreal)));
+        connect(m_clientProxy, SIGNAL(animationSpeedChanged(qreal)), m_toolbar, SLOT(setAnimationSpeed(qreal)));
         m_toolbar->enable();
     } else {
         disconnect(m_clientProxy, SIGNAL(connected()), m_toolbar, SLOT(enable()));
@@ -623,7 +623,7 @@ void InspectorUi::setupToolbar(bool doConnect)
         disconnect(m_clientProxy, SIGNAL(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool)));
         disconnect(m_clientProxy, SIGNAL(selectedColorChanged(QColor)), m_toolbar, SLOT(setSelectedColor(QColor)));
 
-        disconnect(m_clientProxy, SIGNAL(animationSpeedChanged(qreal)), m_toolbar, SLOT(changeAnimationSpeed(qreal)));
+        disconnect(m_clientProxy, SIGNAL(animationSpeedChanged(qreal)), m_toolbar, SLOT(setAnimationSpeed(qreal)));
         m_toolbar->disable();
     }
 }
diff --git a/src/plugins/qmljsinspector/qmljsinspectorconstants.h b/src/plugins/qmljsinspector/qmljsinspectorconstants.h
index d9f08fbd7c2..c7db285f40a 100644
--- a/src/plugins/qmljsinspector/qmljsinspectorconstants.h
+++ b/src/plugins/qmljsinspector/qmljsinspectorconstants.h
@@ -46,7 +46,6 @@ const char * const INFO_OUT_OF_SYNC = "QmlInspector.OutOfSyncWarning";
 const char * const DESIGNMODE_ACTION = "QmlInspector.DesignMode";
 const char * const RELOAD_ACTION = "QmlInspector.Reload";
 const char * const PLAY_ACTION = "QmlInspector.Play";
-const char * const PAUSE_ACTION = "QmlInspector.Pause";
 const char * const SELECT_ACTION = "QmlInspector.Select";
 const char * const SELECT_MARQUEE_ACTION = "QmlInspector.SelectMarquee";
 const char * const ZOOM_ACTION = "QmlInspector.Zoom";
-- 
GitLab