QML Inspector: combined pause & play actions into one button

Easier to use now by just clicking on one button, and takes less space.
This commit is contained in:
Lasse Holmstedt
2010-08-23 15:57:45 +02:00
parent b557c58eac
commit 63da8d4cd7
4 changed files with 62 additions and 54 deletions

View File

@@ -61,7 +61,6 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
m_designmodeAction(0), m_designmodeAction(0),
m_reloadAction(0), m_reloadAction(0),
m_playAction(0), m_playAction(0),
m_pauseAction(0),
m_selectAction(0), m_selectAction(0),
m_selectMarqueeAction(0), m_selectMarqueeAction(0),
m_zoomAction(0), m_zoomAction(0),
@@ -74,6 +73,8 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
m_eighthAnimSpeedAction(0), m_eighthAnimSpeedAction(0),
m_tenthAnimSpeedAction(0), m_tenthAnimSpeedAction(0),
m_menuPauseAction(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_colorBox(0),
m_emitSignals(true), m_emitSignals(true),
m_isRunning(false), m_isRunning(false),
@@ -93,7 +94,6 @@ void QmlInspectorToolbar::setEnabled(bool value)
m_reloadAction->setEnabled(value); m_reloadAction->setEnabled(value);
m_playAction->setEnabled(value); m_playAction->setEnabled(value);
m_pauseAction->setEnabled(value);
m_selectAction->setEnabled(value); m_selectAction->setEnabled(value);
m_selectMarqueeAction->setEnabled(value); m_selectMarqueeAction->setEnabled(value);
m_zoomAction->setEnabled(value); m_zoomAction->setEnabled(value);
@@ -108,14 +108,14 @@ void QmlInspectorToolbar::enable()
setEnabled(true); setEnabled(true);
m_emitSignals = false; m_emitSignals = false;
m_designmodeAction->setChecked(false); m_designmodeAction->setChecked(false);
changeAnimationSpeed(1.0f); setAnimationSpeed(1.0f);
activateDesignModeOnClick(); activateDesignModeOnClick();
m_emitSignals = true; m_emitSignals = true;
} }
void QmlInspectorToolbar::disable() void QmlInspectorToolbar::disable()
{ {
changeAnimationSpeed(1.0f); setAnimationSpeed(1.0f);
activateSelectTool(); activateSelectTool();
setEnabled(false); setEnabled(false);
} }
@@ -148,12 +148,10 @@ void QmlInspectorToolbar::activateZoomTool()
m_emitSignals = true; m_emitSignals = true;
} }
void QmlInspectorToolbar::changeAnimationSpeed(qreal slowdownFactor) void QmlInspectorToolbar::setAnimationSpeed(qreal slowdownFactor)
{ {
m_emitSignals = false; m_emitSignals = false;
if (slowdownFactor == 0) { if (slowdownFactor != 0) {
activatePauseOnClick();
} else {
m_animationSpeed = slowdownFactor; m_animationSpeed = slowdownFactor;
if (slowdownFactor == 1.0f) { if (slowdownFactor == 1.0f) {
@@ -167,9 +165,11 @@ void QmlInspectorToolbar::changeAnimationSpeed(qreal slowdownFactor)
} else if (slowdownFactor == 10.0f) { } else if (slowdownFactor == 10.0f) {
m_tenthAnimSpeedAction->setChecked(true); m_tenthAnimSpeedAction->setChecked(true);
} }
updatePlayAction();
activatePlayOnClick(); } else {
updatePauseAction();
} }
m_emitSignals = true; 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_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_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_playAction = new QAction(m_playIcon, tr("Play animations"), this);
m_pauseAction = new QAction(QIcon(QLatin1String(":/qml/images/pause-small.png")), tr("Pause animations"), this);
m_selectAction = new QAction(QIcon(QLatin1String(":/qml/images/select-small.png")), tr("Select"), 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_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); 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->setCheckable(true);
m_designmodeAction->setChecked(false); m_designmodeAction->setChecked(false);
m_playAction->setCheckable(true);
m_playAction->setChecked(true);
m_pauseAction->setCheckable(true);
m_selectAction->setCheckable(true); m_selectAction->setCheckable(true);
m_selectMarqueeAction->setCheckable(true); m_selectMarqueeAction->setCheckable(true);
m_zoomAction->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_designmodeAction, QmlJSInspector::Constants::DESIGNMODE_ACTION, context);
am->registerAction(m_reloadAction, QmlJSInspector::Constants::RELOAD_ACTION, context); am->registerAction(m_reloadAction, QmlJSInspector::Constants::RELOAD_ACTION, context);
am->registerAction(m_playAction, QmlJSInspector::Constants::PLAY_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_selectAction, QmlJSInspector::Constants::SELECT_ACTION, context);
am->registerAction(m_selectMarqueeAction, QmlJSInspector::Constants::SELECT_MARQUEE_ACTION, context); am->registerAction(m_selectMarqueeAction, QmlJSInspector::Constants::SELECT_MARQUEE_ACTION, context);
am->registerAction(m_zoomAction, QmlJSInspector::Constants::ZOOM_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); m_tenthAnimSpeedAction->setCheckable(true);
playSpeedMenuActions->addAction(m_tenthAnimSpeedAction); 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->setCheckable(true);
m_menuPauseAction->setIcon(m_pauseIcon);
playSpeedMenuActions->addAction(m_menuPauseAction); playSpeedMenuActions->addAction(m_menuPauseAction);
// configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::DEBUG)->action())); // 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::DESIGNMODE_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::RELOAD_ACTION)->action())); configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::RELOAD_ACTION)->action()));
QToolButton *playButton = createToolButton(am->command(QmlJSInspector::Constants::PLAY_ACTION)->action()); m_playButton = createToolButton(am->command(QmlJSInspector::Constants::PLAY_ACTION)->action());
playButton->setMenu(playSpeedMenu); m_playButton->setMenu(playSpeedMenu);
configBarLayout->addWidget(playButton); configBarLayout->addWidget(m_playButton);
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::PAUSE_ACTION)->action())); //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_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::SELECT_MARQUEE_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(m_colorBox);
//configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::TO_QML_ACTION)->action())); //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->addStretch();
configBarLayout->addWidget(m_filterLineEdit); //configBarLayout->addWidget(m_filterLineEdit);
setEnabled(false); setEnabled(false);
@@ -298,7 +294,6 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick())); connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick())); connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick()));
connect(m_pauseAction, SIGNAL(triggered()), SLOT(activatePauseOnClick()));
connect(m_zoomAction, SIGNAL(triggered()), SLOT(activateZoomOnClick())); connect(m_zoomAction, SIGNAL(triggered()), SLOT(activateZoomOnClick()));
connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick())); connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
@@ -317,31 +312,31 @@ QWidget *QmlInspectorToolbar::widget() const
void QmlInspectorToolbar::changeToDefaultAnimSpeed() void QmlInspectorToolbar::changeToDefaultAnimSpeed()
{ {
m_animationSpeed = 1.0f; m_animationSpeed = 1.0f;
activatePlayOnClick(); updatePlayAction();
} }
void QmlInspectorToolbar::changeToHalfAnimSpeed() void QmlInspectorToolbar::changeToHalfAnimSpeed()
{ {
m_animationSpeed = 2.0f; m_animationSpeed = 2.0f;
activatePlayOnClick(); updatePlayAction();
} }
void QmlInspectorToolbar::changeToFourthAnimSpeed() void QmlInspectorToolbar::changeToFourthAnimSpeed()
{ {
m_animationSpeed = 4.0f; m_animationSpeed = 4.0f;
activatePlayOnClick(); updatePlayAction();
} }
void QmlInspectorToolbar::changeToEighthAnimSpeed() void QmlInspectorToolbar::changeToEighthAnimSpeed()
{ {
m_animationSpeed = 8.0f; m_animationSpeed = 8.0f;
activatePlayOnClick(); updatePlayAction();
} }
void QmlInspectorToolbar::changeToTenthAnimSpeed() void QmlInspectorToolbar::changeToTenthAnimSpeed()
{ {
m_animationSpeed = 10.0f; m_animationSpeed = 10.0f;
activatePlayOnClick(); updatePlayAction();
} }
void QmlInspectorToolbar::activateDesignModeOnClick() void QmlInspectorToolbar::activateDesignModeOnClick()
@@ -350,7 +345,6 @@ void QmlInspectorToolbar::activateDesignModeOnClick()
m_reloadAction->setEnabled(true); m_reloadAction->setEnabled(true);
m_playAction->setEnabled(checked); m_playAction->setEnabled(checked);
m_pauseAction->setEnabled(checked);
m_selectAction->setEnabled(checked); m_selectAction->setEnabled(checked);
m_selectMarqueeAction->setEnabled(checked); m_selectMarqueeAction->setEnabled(checked);
m_zoomAction->setEnabled(checked); m_zoomAction->setEnabled(checked);
@@ -362,25 +356,34 @@ void QmlInspectorToolbar::activateDesignModeOnClick()
void QmlInspectorToolbar::activatePlayOnClick() void QmlInspectorToolbar::activatePlayOnClick()
{ {
m_pauseAction->setChecked(false); if (m_isRunning) {
if (!m_isRunning || m_animationSpeed != m_previousAnimationSpeed) { updatePauseAction();
m_playAction->setChecked(true); } else {
m_isRunning = true; updatePlayAction();
m_previousAnimationSpeed = m_animationSpeed;
if (m_emitSignals)
emit animationSpeedChanged(m_animationSpeed);
} }
} }
void QmlInspectorToolbar::activatePauseOnClick() void QmlInspectorToolbar::updatePlayAction()
{ {
m_playAction->setChecked(false); m_isRunning = true;
if (m_isRunning) { m_playAction->setIcon(m_playIcon);
m_isRunning = false; if (m_animationSpeed != m_previousAnimationSpeed)
m_pauseAction->setChecked(true); m_previousAnimationSpeed = m_animationSpeed;
if (m_emitSignals)
emit animationSpeedChanged(0.0f); 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() void QmlInspectorToolbar::activateColorPickerOnClick()

View File

@@ -31,10 +31,11 @@
#define QMLINSPECTORTOOLBAR_H #define QMLINSPECTORTOOLBAR_H
#include <QObject> #include <QObject>
#include <QIcon>
QT_FORWARD_DECLARE_CLASS(QAction); QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QColor); QT_FORWARD_DECLARE_CLASS(QColor)
QT_FORWARD_DECLARE_CLASS(QToolButton)
namespace Core { namespace Core {
class Context; class Context;
} }
@@ -77,7 +78,7 @@ public slots:
void activateSelectTool(); void activateSelectTool();
void activateMarqueeSelectTool(); void activateMarqueeSelectTool();
void activateZoomTool(); void activateZoomTool();
void changeAnimationSpeed(qreal slowdownFactor); void setAnimationSpeed(qreal slowdownFactor);
void setDesignModeBehavior(bool inDesignMode); void setDesignModeBehavior(bool inDesignMode);
void setSelectedColor(const QColor &color); void setSelectedColor(const QColor &color);
@@ -99,7 +100,6 @@ signals:
private slots: private slots:
void activateDesignModeOnClick(); void activateDesignModeOnClick();
void activatePlayOnClick(); void activatePlayOnClick();
void activatePauseOnClick();
void activateColorPickerOnClick(); void activateColorPickerOnClick();
void activateSelectToolOnClick(); void activateSelectToolOnClick();
void activateMarqueeSelectToolOnClick(); void activateMarqueeSelectToolOnClick();
@@ -114,11 +114,13 @@ private slots:
void activateFromQml(); void activateFromQml();
void activateToQml(); void activateToQml();
void updatePlayAction();
void updatePauseAction();
private: private:
QAction *m_designmodeAction; QAction *m_designmodeAction;
QAction *m_reloadAction; QAction *m_reloadAction;
QAction *m_playAction; QAction *m_playAction;
QAction *m_pauseAction;
QAction *m_selectAction; QAction *m_selectAction;
QAction *m_selectMarqueeAction; QAction *m_selectMarqueeAction;
QAction *m_zoomAction; QAction *m_zoomAction;
@@ -133,6 +135,10 @@ private:
QAction *m_tenthAnimSpeedAction; QAction *m_tenthAnimSpeedAction;
QAction *m_menuPauseAction; QAction *m_menuPauseAction;
QToolButton *m_playButton;
QIcon m_playIcon;
QIcon m_pauseIcon;
ToolBarColorBox *m_colorBox; ToolBarColorBox *m_colorBox;
bool m_emitSignals; bool m_emitSignals;

View File

@@ -600,7 +600,7 @@ void InspectorUi::setupToolbar(bool doConnect)
connect(m_clientProxy, SIGNAL(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool))); 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(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(); m_toolbar->enable();
} else { } else {
disconnect(m_clientProxy, SIGNAL(connected()), m_toolbar, SLOT(enable())); 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(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool)));
disconnect(m_clientProxy, SIGNAL(selectedColorChanged(QColor)), m_toolbar, SLOT(setSelectedColor(QColor))); 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(); m_toolbar->disable();
} }
} }

View File

@@ -46,7 +46,6 @@ const char * const INFO_OUT_OF_SYNC = "QmlInspector.OutOfSyncWarning";
const char * const DESIGNMODE_ACTION = "QmlInspector.DesignMode"; const char * const DESIGNMODE_ACTION = "QmlInspector.DesignMode";
const char * const RELOAD_ACTION = "QmlInspector.Reload"; const char * const RELOAD_ACTION = "QmlInspector.Reload";
const char * const PLAY_ACTION = "QmlInspector.Play"; 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_ACTION = "QmlInspector.Select";
const char * const SELECT_MARQUEE_ACTION = "QmlInspector.SelectMarquee"; const char * const SELECT_MARQUEE_ACTION = "QmlInspector.SelectMarquee";
const char * const ZOOM_ACTION = "QmlInspector.Zoom"; const char * const ZOOM_ACTION = "QmlInspector.Zoom";