forked from qt-creator/qt-creator
QmlJSDebugger: Separated animation speed and paused state
This separates animation speed and paused state in the communication protocol between the Qt Creator QmlJSInspector plugin and the QmlJSDebugger server. Point is to allow changing the speed of the animation before resuming execution. These two things were already separated in the QML Observer, but not in Qt Creator. Reviewed-by: Kai Koehne
This commit is contained in:
@@ -73,19 +73,13 @@ QmlInspectorToolBar::QmlInspectorToolBar(QObject *parent) :
|
||||
m_zoomAction(0),
|
||||
m_colorPickerAction(0),
|
||||
m_showAppOnTopAction(0),
|
||||
m_defaultAnimSpeedAction(0),
|
||||
m_halfAnimSpeedAction(0),
|
||||
m_fourthAnimSpeedAction(0),
|
||||
m_eighthAnimSpeedAction(0),
|
||||
m_tenthAnimSpeedAction(0),
|
||||
m_menuPauseAction(0),
|
||||
m_playSpeedMenuActions(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),
|
||||
m_paused(false),
|
||||
m_animationSpeed(1.0f),
|
||||
m_previousAnimationSpeed(0.0f),
|
||||
m_activeTool(NoTool),
|
||||
m_barWidget(0)
|
||||
{
|
||||
@@ -142,32 +136,33 @@ void QmlInspectorToolBar::activateZoomTool()
|
||||
m_emitSignals = true;
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::setAnimationSpeed(qreal slowdownFactor)
|
||||
void QmlInspectorToolBar::setAnimationSpeed(qreal slowDownFactor)
|
||||
{
|
||||
m_emitSignals = false;
|
||||
if (slowdownFactor != 0) {
|
||||
m_animationSpeed = slowdownFactor;
|
||||
if (m_animationSpeed == slowDownFactor)
|
||||
return;
|
||||
|
||||
if (slowdownFactor == 1.0f) {
|
||||
m_defaultAnimSpeedAction->setChecked(true);
|
||||
} else if (slowdownFactor == 2.0f) {
|
||||
m_halfAnimSpeedAction->setChecked(true);
|
||||
} else if (slowdownFactor == 4.0f) {
|
||||
m_fourthAnimSpeedAction->setChecked(true);
|
||||
} else if (slowdownFactor == 8.0f) {
|
||||
m_eighthAnimSpeedAction->setChecked(true);
|
||||
} else if (slowdownFactor == 10.0f) {
|
||||
m_tenthAnimSpeedAction->setChecked(true);
|
||||
m_emitSignals = false;
|
||||
m_animationSpeed = slowDownFactor;
|
||||
|
||||
foreach (QAction *action, m_playSpeedMenuActions->actions()) {
|
||||
if (action->data().toReal() == slowDownFactor) {
|
||||
action->setChecked(true);
|
||||
break;
|
||||
}
|
||||
updatePlayAction();
|
||||
} else {
|
||||
m_menuPauseAction->setChecked(true);
|
||||
updatePauseAction();
|
||||
}
|
||||
|
||||
m_emitSignals = true;
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::setExecutionPaused(bool paused)
|
||||
{
|
||||
if (m_paused == paused)
|
||||
return;
|
||||
|
||||
m_paused = paused;
|
||||
updatePlayAction();
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::setDesignModeBehavior(bool inDesignMode)
|
||||
{
|
||||
m_emitSignals = false;
|
||||
@@ -220,7 +215,8 @@ void QmlInspectorToolBar::createActions(const Core::Context &context)
|
||||
m_colorPickerAction->setCheckable(true);
|
||||
|
||||
am->registerAction(m_observerModeAction, Constants::DESIGNMODE_ACTION, context);
|
||||
am->registerAction(m_playAction, Constants::PLAY_ACTION, context);
|
||||
Core::Command *command = am->registerAction(m_playAction, Constants::PLAY_ACTION, context);
|
||||
command->setAttribute(Core::Command::CA_UpdateIcon);
|
||||
am->registerAction(m_selectAction, Constants::SELECT_ACTION, context);
|
||||
am->registerAction(m_zoomAction, Constants::ZOOM_ACTION, context);
|
||||
am->registerAction(m_colorPickerAction, Constants::COLOR_PICKER_ACTION, context);
|
||||
@@ -232,40 +228,33 @@ void QmlInspectorToolBar::createActions(const Core::Context &context)
|
||||
m_barWidget->setProperty("topBorder", true);
|
||||
|
||||
QMenu *playSpeedMenu = new QMenu(m_barWidget);
|
||||
QActionGroup *playSpeedMenuActions = new QActionGroup(this);
|
||||
playSpeedMenuActions->setExclusive(true);
|
||||
playSpeedMenu->addAction(tr("Animation Speed"));
|
||||
playSpeedMenu->addSeparator();
|
||||
m_defaultAnimSpeedAction =
|
||||
playSpeedMenu->addAction(tr("1x"), this, SLOT(changeToDefaultAnimSpeed()));
|
||||
m_defaultAnimSpeedAction->setCheckable(true);
|
||||
m_defaultAnimSpeedAction->setChecked(true);
|
||||
playSpeedMenuActions->addAction(m_defaultAnimSpeedAction);
|
||||
m_playSpeedMenuActions = new QActionGroup(this);
|
||||
m_playSpeedMenuActions->setExclusive(true);
|
||||
QAction *speedAction = playSpeedMenu->addAction(tr("1x"), this, SLOT(changeAnimationSpeed()));
|
||||
speedAction->setCheckable(true);
|
||||
speedAction->setChecked(true);
|
||||
speedAction->setData(1.0f);
|
||||
m_playSpeedMenuActions->addAction(speedAction);
|
||||
|
||||
m_halfAnimSpeedAction =
|
||||
playSpeedMenu->addAction(tr("0.5x"), this, SLOT(changeToHalfAnimSpeed()));
|
||||
m_halfAnimSpeedAction->setCheckable(true);
|
||||
playSpeedMenuActions->addAction(m_halfAnimSpeedAction);
|
||||
speedAction = playSpeedMenu->addAction(tr("0.5x"), this, SLOT(changeAnimationSpeed()));
|
||||
speedAction->setCheckable(true);
|
||||
speedAction->setData(2.0f);
|
||||
m_playSpeedMenuActions->addAction(speedAction);
|
||||
|
||||
m_fourthAnimSpeedAction =
|
||||
playSpeedMenu->addAction(tr("0.25x"), this, SLOT(changeToFourthAnimSpeed()));
|
||||
m_fourthAnimSpeedAction->setCheckable(true);
|
||||
playSpeedMenuActions->addAction(m_fourthAnimSpeedAction);
|
||||
speedAction = playSpeedMenu->addAction(tr("0.25x"), this, SLOT(changeAnimationSpeed()));
|
||||
speedAction->setCheckable(true);
|
||||
speedAction->setData(4.0f);
|
||||
m_playSpeedMenuActions->addAction(speedAction);
|
||||
|
||||
m_eighthAnimSpeedAction =
|
||||
playSpeedMenu->addAction(tr("0.125x"), this, SLOT(changeToEighthAnimSpeed()));
|
||||
m_eighthAnimSpeedAction->setCheckable(true);
|
||||
playSpeedMenuActions->addAction(m_eighthAnimSpeedAction);
|
||||
speedAction = playSpeedMenu->addAction(tr("0.125x"), this, SLOT(changeAnimationSpeed()));
|
||||
speedAction->setCheckable(true);
|
||||
speedAction->setData(8.0f);
|
||||
m_playSpeedMenuActions->addAction(speedAction);
|
||||
|
||||
m_tenthAnimSpeedAction =
|
||||
playSpeedMenu->addAction(tr("0.1x"), this, SLOT(changeToTenthAnimSpeed()));
|
||||
m_tenthAnimSpeedAction->setCheckable(true);
|
||||
playSpeedMenuActions->addAction(m_tenthAnimSpeedAction);
|
||||
|
||||
m_menuPauseAction = playSpeedMenu->addAction(tr("Pause"), this, SLOT(updatePauseAction()));
|
||||
m_menuPauseAction->setCheckable(true);
|
||||
m_menuPauseAction->setIcon(m_pauseIcon);
|
||||
playSpeedMenuActions->addAction(m_menuPauseAction);
|
||||
speedAction = playSpeedMenu->addAction(tr("0.1x"), this, SLOT(changeAnimationSpeed()));
|
||||
speedAction->setCheckable(true);
|
||||
speedAction->setData(10.0f);
|
||||
m_playSpeedMenuActions->addAction(speedAction);
|
||||
|
||||
QHBoxLayout *toolBarLayout = new QHBoxLayout(m_barWidget);
|
||||
toolBarLayout->setMargin(0);
|
||||
@@ -324,33 +313,13 @@ QWidget *QmlInspectorToolBar::widget() const
|
||||
return m_barWidget;
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::changeToDefaultAnimSpeed()
|
||||
void QmlInspectorToolBar::changeAnimationSpeed()
|
||||
{
|
||||
m_animationSpeed = 1.0f;
|
||||
updatePlayAction();
|
||||
}
|
||||
QAction *action = static_cast<QAction*>(sender());
|
||||
|
||||
void QmlInspectorToolBar::changeToHalfAnimSpeed()
|
||||
{
|
||||
m_animationSpeed = 2.0f;
|
||||
updatePlayAction();
|
||||
}
|
||||
m_animationSpeed = action->data().toReal();
|
||||
emit animationSpeedChanged(m_animationSpeed);
|
||||
|
||||
void QmlInspectorToolBar::changeToFourthAnimSpeed()
|
||||
{
|
||||
m_animationSpeed = 4.0f;
|
||||
updatePlayAction();
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::changeToEighthAnimSpeed()
|
||||
{
|
||||
m_animationSpeed = 8.0f;
|
||||
updatePlayAction();
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::changeToTenthAnimSpeed()
|
||||
{
|
||||
m_animationSpeed = 10.0f;
|
||||
updatePlayAction();
|
||||
}
|
||||
|
||||
@@ -368,34 +337,14 @@ void QmlInspectorToolBar::activateDesignModeOnClick()
|
||||
|
||||
void QmlInspectorToolBar::activatePlayOnClick()
|
||||
{
|
||||
if (m_isRunning) {
|
||||
updatePauseAction();
|
||||
} else {
|
||||
updatePlayAction();
|
||||
}
|
||||
m_paused = !m_paused;
|
||||
emit executionPausedChanged(m_paused);
|
||||
updatePlayAction();
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::updatePlayAction()
|
||||
{
|
||||
m_isRunning = true;
|
||||
m_playAction->setIcon(m_pauseIcon);
|
||||
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_playIcon);
|
||||
if (m_emitSignals)
|
||||
emit animationSpeedChanged(0.0f);
|
||||
|
||||
m_playButton->setDefaultAction(m_playAction);
|
||||
m_playAction->setIcon(m_paused ? m_playIcon : m_pauseIcon);
|
||||
}
|
||||
|
||||
void QmlInspectorToolBar::activateColorPickerOnClick()
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||
QT_FORWARD_DECLARE_CLASS(QActionGroup)
|
||||
QT_FORWARD_DECLARE_CLASS(QColor)
|
||||
QT_FORWARD_DECLARE_CLASS(QToolButton)
|
||||
|
||||
@@ -84,7 +85,10 @@ public slots:
|
||||
void activateColorPicker();
|
||||
void activateSelectTool();
|
||||
void activateZoomTool();
|
||||
void setAnimationSpeed(qreal slowdownFactor);
|
||||
|
||||
void setAnimationSpeed(qreal slowDownFactor);
|
||||
void setExecutionPaused(bool paused);
|
||||
|
||||
void setDesignModeBehavior(bool inDesignMode);
|
||||
void setShowAppOnTop(bool showAppOnTop);
|
||||
void setSelectedColor(const QColor &color);
|
||||
@@ -99,7 +103,9 @@ signals:
|
||||
void zoomToolSelected();
|
||||
|
||||
void showAppOnTopSelected(bool isChecked);
|
||||
void animationSpeedChanged(qreal slowdownFactor = 1.0f);
|
||||
|
||||
void animationSpeedChanged(qreal slowdownFactor);
|
||||
void executionPausedChanged(bool paused);
|
||||
|
||||
private slots:
|
||||
void activateDesignModeOnClick();
|
||||
@@ -110,16 +116,11 @@ private slots:
|
||||
|
||||
void showAppOnTopClick();
|
||||
|
||||
void changeToDefaultAnimSpeed();
|
||||
void changeToHalfAnimSpeed();
|
||||
void changeToFourthAnimSpeed();
|
||||
void changeToEighthAnimSpeed();
|
||||
void changeToTenthAnimSpeed();
|
||||
void changeAnimationSpeed();
|
||||
|
||||
void activateFromQml();
|
||||
|
||||
void updatePlayAction();
|
||||
void updatePauseAction();
|
||||
|
||||
void activeDebugLanguagesChanged(Debugger::DebuggerLanguages languages);
|
||||
|
||||
@@ -135,12 +136,7 @@ private:
|
||||
|
||||
QAction *m_showAppOnTopAction;
|
||||
|
||||
QAction *m_defaultAnimSpeedAction;
|
||||
QAction *m_halfAnimSpeedAction;
|
||||
QAction *m_fourthAnimSpeedAction;
|
||||
QAction *m_eighthAnimSpeedAction;
|
||||
QAction *m_tenthAnimSpeedAction;
|
||||
QAction *m_menuPauseAction;
|
||||
QActionGroup *m_playSpeedMenuActions;
|
||||
|
||||
QToolButton *m_playButton;
|
||||
QIcon m_playIcon;
|
||||
@@ -149,9 +145,8 @@ private:
|
||||
ToolBarColorBox *m_colorBox;
|
||||
|
||||
bool m_emitSignals;
|
||||
bool m_isRunning;
|
||||
bool m_paused;
|
||||
qreal m_animationSpeed;
|
||||
qreal m_previousAnimationSpeed;
|
||||
|
||||
DesignTool m_activeTool;
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ void ClientProxy::connectToServer()
|
||||
SIGNAL(selectMarqueeToolActivated()));
|
||||
connect(m_observerClient, SIGNAL(animationSpeedChanged(qreal)),
|
||||
SIGNAL(animationSpeedChanged(qreal)));
|
||||
connect(m_observerClient, SIGNAL(executionPausedChanged(bool)),
|
||||
SIGNAL(executionPausedChanged(bool)));
|
||||
connect(m_observerClient, SIGNAL(designModeBehaviorChanged(bool)),
|
||||
SIGNAL(designModeBehaviorChanged(bool)));
|
||||
connect(m_observerClient, SIGNAL(showAppOnTopChanged(bool)),
|
||||
@@ -545,10 +547,16 @@ void ClientProxy::setDesignModeBehavior(bool inDesignMode)
|
||||
m_observerClient->setDesignModeBehavior(inDesignMode);
|
||||
}
|
||||
|
||||
void ClientProxy::setAnimationSpeed(qreal slowdownFactor)
|
||||
void ClientProxy::setAnimationSpeed(qreal slowDownFactor)
|
||||
{
|
||||
if (isConnected())
|
||||
m_observerClient->setAnimationSpeed(slowdownFactor);
|
||||
m_observerClient->setAnimationSpeed(slowDownFactor);
|
||||
}
|
||||
|
||||
void ClientProxy::setExecutionPaused(bool paused)
|
||||
{
|
||||
if (isConnected())
|
||||
m_observerClient->setExecutionPaused(paused);
|
||||
}
|
||||
|
||||
void ClientProxy::changeToColorPickerTool()
|
||||
|
||||
@@ -106,7 +106,8 @@ signals:
|
||||
void selectToolActivated();
|
||||
void selectMarqueeToolActivated();
|
||||
void zoomToolActivated();
|
||||
void animationSpeedChanged(qreal slowdownFactor);
|
||||
void animationSpeedChanged(qreal slowDownFactor);
|
||||
void executionPausedChanged(bool paused);
|
||||
void designModeBehaviorChanged(bool inDesignMode);
|
||||
void showAppOnTopChanged(bool showAppOnTop);
|
||||
void serverReloaded();
|
||||
@@ -120,7 +121,8 @@ public slots:
|
||||
void reloadQmlViewer();
|
||||
|
||||
void setDesignModeBehavior(bool inDesignMode);
|
||||
void setAnimationSpeed(qreal slowdownFactor = 1.0f);
|
||||
void setAnimationSpeed(qreal slowDownFactor);
|
||||
void setExecutionPaused(bool paused);
|
||||
void changeToColorPickerTool();
|
||||
void changeToZoomTool();
|
||||
void changeToSelectTool();
|
||||
|
||||
@@ -884,6 +884,8 @@ void InspectorUi::connectSignals()
|
||||
m_toolBar, SLOT(setSelectedColor(QColor)));
|
||||
connect(m_clientProxy, SIGNAL(animationSpeedChanged(qreal)),
|
||||
m_toolBar, SLOT(setAnimationSpeed(qreal)));
|
||||
connect(m_clientProxy, SIGNAL(executionPausedChanged(bool)),
|
||||
m_toolBar, SLOT(setExecutionPaused(bool)));
|
||||
|
||||
connect(m_toolBar, SIGNAL(applyChangesFromQmlFileTriggered(bool)),
|
||||
this, SLOT(setApplyChangesToQmlObserver(bool)));
|
||||
@@ -894,6 +896,8 @@ void InspectorUi::connectSignals()
|
||||
m_clientProxy, SLOT(reloadQmlViewer()));
|
||||
connect(m_toolBar, SIGNAL(animationSpeedChanged(qreal)),
|
||||
m_clientProxy, SLOT(setAnimationSpeed(qreal)));
|
||||
connect(m_toolBar, SIGNAL(executionPausedChanged(bool)),
|
||||
m_clientProxy, SLOT(setExecutionPaused(bool)));
|
||||
connect(m_toolBar, SIGNAL(colorPickerSelected()),
|
||||
m_clientProxy, SLOT(changeToColorPickerTool()));
|
||||
connect(m_toolBar, SIGNAL(zoomToolSelected()),
|
||||
|
||||
@@ -106,12 +106,21 @@ void QmlJSObserverClient::messageReceived(const QByteArray &message)
|
||||
break;
|
||||
}
|
||||
case ObserverProtocol::AnimationSpeedChanged: {
|
||||
qreal slowdownFactor;
|
||||
ds >> slowdownFactor;
|
||||
qreal slowDownFactor;
|
||||
ds >> slowDownFactor;
|
||||
|
||||
log(LogReceive, type, QString::number(slowdownFactor));
|
||||
log(LogReceive, type, QString::number(slowDownFactor));
|
||||
|
||||
emit animationSpeedChanged(slowdownFactor);
|
||||
emit animationSpeedChanged(slowDownFactor);
|
||||
break;
|
||||
}
|
||||
case ObserverProtocol::ExecutionPausedChanged: {
|
||||
bool paused;
|
||||
ds >> paused;
|
||||
|
||||
log(LogReceive, type, paused ? QLatin1String("true") : QLatin1String("false"));
|
||||
|
||||
emit executionPausedChanged(paused);
|
||||
break;
|
||||
}
|
||||
case ObserverProtocol::SetDesignMode: {
|
||||
@@ -291,7 +300,7 @@ void QmlJSObserverClient::setDesignModeBehavior(bool inDesignMode)
|
||||
sendMessage(message);
|
||||
}
|
||||
|
||||
void QmlJSObserverClient::setAnimationSpeed(qreal slowdownFactor)
|
||||
void QmlJSObserverClient::setAnimationSpeed(qreal slowDownFactor)
|
||||
{
|
||||
if (!m_connection || !m_connection->isConnected())
|
||||
return;
|
||||
@@ -301,10 +310,27 @@ void QmlJSObserverClient::setAnimationSpeed(qreal slowdownFactor)
|
||||
|
||||
ObserverProtocol::Message cmd = ObserverProtocol::SetAnimationSpeed;
|
||||
ds << cmd
|
||||
<< slowdownFactor;
|
||||
<< slowDownFactor;
|
||||
|
||||
|
||||
log(LogSend, cmd, QString::number(slowdownFactor));
|
||||
log(LogSend, cmd, QString::number(slowDownFactor));
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
|
||||
void QmlJSObserverClient::setExecutionPaused(bool paused)
|
||||
{
|
||||
if (!m_connection || !m_connection->isConnected())
|
||||
return;
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
|
||||
ObserverProtocol::Message cmd = ObserverProtocol::SetExecutionPaused;
|
||||
ds << cmd
|
||||
<< paused;
|
||||
|
||||
log(LogSend, cmd, paused ? QLatin1String("true") : QLatin1String("false"));
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ public:
|
||||
void setCurrentObjects(const QList<int> &debugIds);
|
||||
void reloadViewer();
|
||||
void setDesignModeBehavior(bool inDesignMode);
|
||||
void setAnimationSpeed(qreal slowdownFactor);
|
||||
void setAnimationSpeed(qreal slowDownFactor);
|
||||
void setExecutionPaused(bool paused);
|
||||
void changeToColorPickerTool();
|
||||
void changeToSelectTool();
|
||||
void changeToSelectMarqueeTool();
|
||||
@@ -92,6 +93,7 @@ signals:
|
||||
void selectMarqueeToolActivated();
|
||||
void zoomToolActivated();
|
||||
void animationSpeedChanged(qreal slowdownFactor);
|
||||
void executionPausedChanged(bool paused);
|
||||
void designModeBehaviorChanged(bool inDesignMode);
|
||||
void showAppOnTopChanged(bool showAppOnTop);
|
||||
void reloaded(); // the server has reloadetd he document
|
||||
|
||||
Reference in New Issue
Block a user