Commit 2f8dc283 authored by Lasse Holmstedt's avatar Lasse Holmstedt Committed by Olivier Goffart
Browse files

added mode buttons to custom qml viewer and qmljsinspector toolbar

parent c53a0337
......@@ -24,6 +24,7 @@ static QToolButton *createToolButton(QAction *action)
QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
QObject(parent),
m_designmodeAction(0),
m_reloadAction(0),
m_playAction(0),
m_pauseAction(0),
......@@ -42,6 +43,7 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
void QmlInspectorToolbar::setEnabled(bool value)
{
m_designmodeAction->setEnabled(value);
m_reloadAction->setEnabled(value);
m_playAction->setEnabled(value);
m_pauseAction->setEnabled(value);
......@@ -56,6 +58,9 @@ void QmlInspectorToolbar::setEnabled(bool value)
void QmlInspectorToolbar::enable()
{
setEnabled(true);
m_emitSignals = false;
activateDesignModeOnClick();
m_emitSignals = true;
}
void QmlInspectorToolbar::disable()
......@@ -104,6 +109,14 @@ void QmlInspectorToolbar::changeAnimationSpeed(qreal slowdownFactor)
m_emitSignals = true;
}
void QmlInspectorToolbar::setDesignModeBehavior(bool inDesignMode)
{
m_emitSignals = false;
m_designmodeAction->setChecked(inDesignMode);
activateDesignModeOnClick();
m_emitSignals = true;
}
void QmlInspectorToolbar::createActions(const Core::Context &context)
{
Core::ICore *core = Core::ICore::instance();
......@@ -111,9 +124,8 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
Debugger::DebuggerUISwitcher *uiSwitcher = pluginManager->getObject<Debugger::DebuggerUISwitcher>();
m_designmodeAction = new QAction(QIcon(":/qml/images/designmode.png"), "Design Mode", this);
m_reloadAction = new QAction(QIcon(":/qml/images/reload.png"), "Reload", this);
m_reloadAction->setDisabled(true);
m_playAction = new QAction(QIcon(":/qml/images/play-small.png"), tr("Play animations"), this);
m_pauseAction = new QAction(QIcon(":/qml/images/pause-small.png"), tr("Pause animations"), this);
m_selectAction = new QAction(QIcon(":/qml/images/select-small.png"), tr("Select"), this);
......@@ -122,6 +134,8 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
m_colorPickerAction = new QAction(QIcon(":/qml/images/color-picker-small.png"), tr("Color Picker"), this);
m_toQmlAction = new QAction(QIcon(":/qml/images/to-qml-small.png"), tr("Apply Changes to QML Viewer"), this);
m_fromQmlAction = new QAction(QIcon(":/qml/images/from-qml-small.png"), tr("Apply Changes to Document"), this);
m_designmodeAction->setCheckable(true);
m_designmodeAction->setChecked(false);
m_playAction->setCheckable(true);
m_playAction->setChecked(true);
m_pauseAction->setCheckable(true);
......@@ -130,6 +144,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
m_zoomAction->setCheckable(true);
m_colorPickerAction->setCheckable(true);
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);
......@@ -149,6 +164,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::DEBUG)->action()));
configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::STOP)->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::PLAY_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::PAUSE_ACTION)->action()));
......@@ -167,6 +183,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
uiSwitcher->setToolbar(QmlJSInspector::Constants::LANG_QML, configBar);
setEnabled(false);
connect(m_designmodeAction, SIGNAL(triggered()), SLOT(activateDesignModeOnClick()));
connect(m_reloadAction, SIGNAL(triggered()), SIGNAL(reloadSelected()));
connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
......@@ -183,6 +200,24 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml()));
}
void QmlInspectorToolbar::activateDesignModeOnClick()
{
bool checked = m_designmodeAction->isChecked();
m_reloadAction->setEnabled(checked);
m_playAction->setEnabled(checked);
m_pauseAction->setEnabled(checked);
m_selectAction->setEnabled(checked);
m_selectMarqueeAction->setEnabled(checked);
m_zoomAction->setEnabled(checked);
m_colorPickerAction->setEnabled(checked);
m_toQmlAction->setEnabled(checked);
m_fromQmlAction->setEnabled(checked);
if (m_emitSignals)
emit designModeSelected(checked);
}
void QmlInspectorToolbar::activatePlayOnClick()
{
m_pauseAction->setChecked(false);
......
......@@ -39,10 +39,12 @@ public slots:
void activateMarqueeSelectTool();
void activateZoomTool();
void changeAnimationSpeed(qreal slowdownFactor);
void setDesignModeBehavior(bool inDesignMode);
signals:
void animationSpeedChanged(qreal slowdownFactor = 1.0f);
void designModeSelected(bool checked);
void reloadSelected();
void colorPickerSelected();
void selectToolSelected();
......@@ -53,6 +55,7 @@ signals:
void applyChangesFromQmlFileSelected();
private slots:
void activateDesignModeOnClick();
void activatePlayOnClick();
void activatePauseOnClick();
void activateColorPickerOnClick();
......@@ -64,6 +67,7 @@ private slots:
void activateToQml();
private:
QAction *m_designmodeAction;
QAction *m_reloadAction;
QAction *m_playAction;
QAction *m_pauseAction;
......
......@@ -77,8 +77,9 @@ bool ClientProxy::connectToViewer(const QString &host, quint16 port)
disconnect(m_designClient,
SIGNAL(selectMarqueeToolActivated()), this, SIGNAL(selectMarqueeToolActivated()));
disconnect(m_designClient,
SIGNAL(animationSpeedChanged(qreal)), this, SIGNAL(animationSpeedChanged(qreal)));
disconnect(m_designClient,
SIGNAL(designModeBehaviorChanged(bool)), this, SIGNAL(designModeBehaviorChanged(bool)));
emit aboutToDisconnect();
......@@ -173,7 +174,8 @@ void ClientProxy::connectionStateChanged()
SIGNAL(selectMarqueeToolActivated()), SIGNAL(selectMarqueeToolActivated()));
connect(m_designClient,
SIGNAL(animationSpeedChanged(qreal)), SIGNAL(animationSpeedChanged(qreal)));
connect(m_designClient,
SIGNAL(designModeBehaviorChanged(bool)), SIGNAL(designModeBehaviorChanged(bool)));
}
(void) new DebuggerClient(m_conn);
......@@ -333,6 +335,12 @@ void ClientProxy::reloadQmlViewer()
m_designClient->reloadViewer();
}
void ClientProxy::setDesignModeBehavior(bool inDesignMode)
{
if (m_designClient && m_conn->isConnected())
m_designClient->setDesignModeBehavior(inDesignMode);
}
void ClientProxy::setAnimationSpeed(qreal slowdownFactor)
{
if (m_designClient && m_conn->isConnected())
......
......@@ -94,11 +94,13 @@ signals:
void selectMarqueeToolActivated();
void zoomToolActivated();
void animationSpeedChanged(qreal slowdownFactor);
void designModeBehaviorChanged(bool inDesignMode);
public slots:
void queryEngineContext(int id);
void reloadQmlViewer();
void setDesignModeBehavior(bool inDesignMode);
void setAnimationSpeed(qreal slowdownFactor = 1.0f);
void changeToColorPickerTool();
void changeToZoomTool();
......
......@@ -93,6 +93,10 @@ void QmlJSDesignDebugClient::messageReceived(const QByteArray &message)
qreal slowdownFactor;
ds >> slowdownFactor;
emit animationSpeedChanged(slowdownFactor);
} else if (type == "SET_DESIGN_MODE") {
bool inDesignMode;
ds >> inDesignMode;
emit designModeBehaviorChanged(inDesignMode);
}
}
......@@ -126,6 +130,20 @@ void QmlJSDesignDebugClient::reloadViewer()
sendMessage(message);
}
void QmlJSDesignDebugClient::setDesignModeBehavior(bool inDesignMode)
{
if (!m_connection || !m_connection->isConnected())
return;
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_DESIGN_MODE")
<< inDesignMode;
sendMessage(message);
}
void QmlJSDesignDebugClient::setAnimationSpeed(qreal slowdownFactor)
{
if (!m_connection || !m_connection->isConnected())
......
......@@ -57,6 +57,7 @@ public:
void setSelectedItemsByObjectId(const QList<QDeclarativeDebugObjectReference> &objects);
void reloadViewer();
void setDesignModeBehavior(bool inDesignMode);
void setAnimationSpeed(qreal slowdownFactor);
void changeToColorPickerTool();
void changeToSelectTool();
......@@ -73,6 +74,7 @@ signals:
void selectMarqueeToolActivated();
void zoomToolActivated();
void animationSpeedChanged(qreal slowdownFactor);
void designModeBehaviorChanged(bool inDesignMode);
protected:
virtual void messageReceived(const QByteArray &);
......
......@@ -17,5 +17,6 @@
<file>images/from-qml-small.png</file>
<file>images/zoom-small.png</file>
<file>images/select-marquee-small.png</file>
<file>images/designmode.png</file>
</qresource>
</RCC>
......@@ -42,6 +42,7 @@ const char * const M_DEBUG_SIMULTANEOUSLY = "QmlInspector.Menu.SimultaneousDebug
const char * const LANG_QML = "QML";
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";
......
......@@ -158,6 +158,7 @@ void InspectorPlugin::extensionsInitialized()
connect(_clientProxy, SIGNAL(connected(QDeclarativeEngineDebug*)), m_toolbar, SLOT(enable()));
connect(_clientProxy, SIGNAL(disconnected()), m_toolbar, SLOT(disable()));
connect(m_toolbar, SIGNAL(designModeSelected(bool)), _clientProxy, SLOT(setDesignModeBehavior(bool)));
connect(m_toolbar, SIGNAL(reloadSelected()), _clientProxy, SLOT(reloadQmlViewer()));
connect(m_toolbar, SIGNAL(animationSpeedChanged(qreal)), _clientProxy, SLOT(setAnimationSpeed(qreal)));
connect(m_toolbar, SIGNAL(colorPickerSelected()), _clientProxy, SLOT(changeToColorPickerTool()));
......@@ -169,6 +170,7 @@ void InspectorPlugin::extensionsInitialized()
connect(_clientProxy, SIGNAL(selectToolActivated()), m_toolbar, SLOT(activateSelectTool()));
connect(_clientProxy, SIGNAL(selectMarqueeToolActivated()), m_toolbar, SLOT(activateMarqueeSelectTool()));
connect(_clientProxy, SIGNAL(zoomToolActivated()), m_toolbar, SLOT(activateZoomTool()));
connect(_clientProxy, SIGNAL(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool)));
connect(_clientProxy, SIGNAL(animationSpeedChanged(qreal)), m_toolbar, SLOT(changeAnimationSpeed(qreal)));
}
......
......@@ -81,12 +81,6 @@ QmlRunControl::~QmlRunControl()
void QmlRunControl::start()
{
if (runMode() == ProjectExplorer::Constants::DEBUGMODE) {
if (!m_commandLineArguments.contains(QmlJSInspector::Constants::ARG_DESIGNMODE)) {
m_commandLineArguments.append(QmlJSInspector::Constants::ARG_DESIGNMODE);
}
}
m_applicationLauncher.start(ProjectExplorer::ApplicationLauncher::Gui, m_executable,
m_commandLineArguments);
......
......@@ -9,5 +9,6 @@
<file>images/from-qml.png</file>
<file>images/zoom.png</file>
<file>images/to-qml.png</file>
<file>images/designmode.png</file>
</qresource>
</RCC>
......@@ -14,6 +14,7 @@ QmlToolbar::QmlToolbar(QWidget *parent) :
m_emitSignals(true),
ui(new Ui)
{
ui->designmode = new QAction(QIcon(":/qml/images/designmode.png"), tr("Design Mode"), this);
ui->play = new QAction(QIcon(":/qml/images/play.png"), tr("Play"), this);
ui->pause = new QAction(QIcon(":/qml/images/pause.png"), tr("Pause"), this);
ui->select = new QAction(QIcon(":/qml/images/select.png"), tr("Select"), this);
......@@ -22,6 +23,9 @@ QmlToolbar::QmlToolbar(QWidget *parent) :
ui->colorPicker = new QAction(QIcon(":/qml/images/color-picker.png"), tr("Color Picker"), this);
ui->toQml = new QAction(QIcon(":/qml/images/to-qml.png"), tr("Apply Changes to QML Viewer"), this);
ui->fromQml = new QAction(QIcon(":/qml/images/from-qml.png"), tr("Apply Changes to Document"), this);
ui->designmode->setCheckable(true);
ui->designmode->setChecked(false);
ui->play->setCheckable(true);
ui->play->setChecked(true);
ui->pause->setCheckable(true);
......@@ -32,6 +36,7 @@ QmlToolbar::QmlToolbar(QWidget *parent) :
setWindowTitle(tr("Tools"));
addAction(ui->designmode);
addAction(ui->play);
addAction(ui->pause);
addSeparator();
......@@ -51,6 +56,8 @@ QmlToolbar::QmlToolbar(QWidget *parent) :
setWindowFlags(Qt::Tool);
connect(ui->designmode, SIGNAL(toggled(bool)), SLOT(setDesignModeBehaviorOnClick(bool)));
connect(ui->colorPicker, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
connect(ui->play, SIGNAL(triggered()), SLOT(activatePlayOnClick()));
......@@ -112,6 +119,29 @@ void QmlToolbar::activateZoom()
m_emitSignals = true;
}
void QmlToolbar::setDesignModeBehavior(bool inDesignMode)
{
m_emitSignals = false;
ui->designmode->setChecked(inDesignMode);
setDesignModeBehaviorOnClick(inDesignMode);
m_emitSignals = true;
}
void QmlToolbar::setDesignModeBehaviorOnClick(bool checked)
{
ui->play->setEnabled(checked);
ui->pause->setEnabled(checked);
ui->select->setEnabled(checked);
ui->selectMarquee->setEnabled(checked);
ui->zoom->setEnabled(checked);
ui->colorPicker->setEnabled(checked);
ui->toQml->setEnabled(checked);
ui->fromQml->setEnabled(checked);
if (m_emitSignals)
emit designModeBehaviorChanged(checked);
}
void QmlToolbar::setColorBoxColor(const QColor &color)
{
ui->colorBox->setColor(color);
......@@ -120,8 +150,8 @@ void QmlToolbar::setColorBoxColor(const QColor &color)
void QmlToolbar::activatePlayOnClick()
{
ui->pause->setChecked(false);
ui->play->setChecked(true);
if (!m_isRunning) {
ui->play->setChecked(true);
m_isRunning = true;
if (m_emitSignals)
emit executionStarted();
......@@ -131,9 +161,9 @@ void QmlToolbar::activatePlayOnClick()
void QmlToolbar::activatePauseOnClick()
{
ui->play->setChecked(false);
ui->pause->setChecked(true);
if (m_isRunning) {
m_isRunning = false;
ui->pause->setChecked(true);
if (m_emitSignals)
emit executionPaused();
}
......
......@@ -17,6 +17,7 @@ public:
~QmlToolbar();
public slots:
void setDesignModeBehavior(bool inDesignMode);
void setColorBoxColor(const QColor &color);
void startExecution();
void pauseExecution();
......@@ -29,6 +30,7 @@ signals:
void executionStarted();
void executionPaused();
void designModeBehaviorChanged(bool inDesignMode);
void colorPickerSelected();
void selectToolSelected();
void marqueeSelectToolSelected();
......@@ -38,6 +40,7 @@ signals:
void applyChangesFromQmlFileSelected();
private slots:
void setDesignModeBehaviorOnClick(bool inDesignMode);
void activatePlayOnClick();
void activatePauseOnClick();
void activateColorPickerOnClick();
......@@ -51,6 +54,7 @@ private slots:
private:
class Ui {
public:
QAction *designmode;
QAction *play;
QAction *pause;
QAction *select;
......
......@@ -40,17 +40,31 @@ void QDeclarativeDesignDebugServer::messageReceived(const QByteArray &message)
QByteArray toolName;
ds >> toolName;
if (toolName == "COLOR_PICKER") {
colorPickerToolRequested();
emit colorPickerToolRequested();
} else if (toolName == "SELECT") {
selectToolRequested();
emit selectToolRequested();
} else if (toolName == "SELECT_MARQUEE") {
selectMarqueeToolRequested();
emit selectMarqueeToolRequested();
} else if (toolName == "ZOOM") {
zoomToolRequested();
emit zoomToolRequested();
}
} else if (type == "SET_DESIGN_MODE") {
bool inDesignMode;
ds >> inDesignMode;
emit designModeBehaviorChanged(inDesignMode);
}
}
void QDeclarativeDesignDebugServer::setDesignModeBehavior(bool inDesignMode)
{
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_DESIGN_MODE")
<< inDesignMode;
sendMessage(message);
}
void QDeclarativeDesignDebugServer::setCurrentObjects(QList<QObject*> objects)
{
......
......@@ -58,12 +58,14 @@ class QDeclarativeDesignDebugServer : public QDeclarativeDebugService
public:
QDeclarativeDesignDebugServer(QObject *parent = 0);
void setDesignModeBehavior(bool inDesignMode);
void setCurrentObjects(QList<QObject*> items);
void setAnimationSpeed(qreal slowdownFactor);
void setCurrentTool(QmlViewer::Constants::DesignTool toolId);
Q_SIGNALS:
void currentObjectsChanged(const QList<QObject*> &objects);
void designModeBehaviorChanged(bool inDesignMode);
void reloadRequested();
void selectToolRequested();
void selectMarqueeToolRequested();
......
......@@ -38,6 +38,7 @@ QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) :
setMouseTracking(true);
connect(qmlDesignDebugServer(), SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool)));
connect(qmlDesignDebugServer(), SIGNAL(reloadRequested()), SLOT(reloadView()));
connect(qmlDesignDebugServer(),
SIGNAL(currentObjectsChanged(QList<QObject*>)),
......@@ -48,7 +49,6 @@ QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) :
connect(qmlDesignDebugServer(), SIGNAL(selectToolRequested()), SLOT(changeToSingleSelectTool()));
connect(qmlDesignDebugServer(), SIGNAL(zoomToolRequested()), SLOT(changeToZoomTool()));
connect(this, SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool)));
connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(onStatusChanged(QDeclarativeView::Status)));
connect(m_colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor)));
......@@ -219,6 +219,10 @@ void QDeclarativeDesignView::wheelEvent(QWheelEvent *event)
void QDeclarativeDesignView::setDesignModeBehavior(bool value)
{
emit designModeBehaviorChanged(value);
m_toolbar->setDesignModeBehavior(value);
m_designModeBehavior = value;
if (m_subcomponentEditorTool) {
m_subcomponentEditorTool->clear();
......@@ -488,6 +492,9 @@ void QDeclarativeDesignView::createToolbar()
m_toolbar = new QmlToolbar(this);
connect(this, SIGNAL(selectedColorChanged(QColor)), m_toolbar, SLOT(setColorBoxColor(QColor)));
connect(this, SIGNAL(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool)));
connect(m_toolbar, SIGNAL(designModeBehaviorChanged(bool)), this, SLOT(setDesignModeBehavior(bool)));
connect(m_toolbar, SIGNAL(executionStarted()), this, SLOT(continueExecution()));
connect(m_toolbar, SIGNAL(executionPaused()), this, SLOT(pauseExecution()));
connect(m_toolbar, SIGNAL(colorPickerSelected()), this, SLOT(changeToColorPickerTool()));
......
......@@ -633,7 +633,6 @@ void QDeclarativeViewer::setDesignModeBehavior(bool value)
{
designModeBehaviorAction->setChecked(value);
canvas->setDesignModeBehavior(value);
canvas->toolbar()->setEnabled(value);
}
void QDeclarativeViewer::setDebugMode(bool on)
......@@ -701,6 +700,7 @@ void QDeclarativeViewer::createMenu()
designModeBehaviorAction->setCheckable(true);
designModeBehaviorAction->setChecked(canvas->designModeBehavior());
connect(designModeBehaviorAction, SIGNAL(triggered(bool)), this, SLOT(setDesignModeBehavior(bool)));
connect(canvas, SIGNAL(designModeBehaviorChanged(bool)), designModeBehaviorAction, SLOT(setChecked(bool)));
QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this);
connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings()));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment