Commit d2ed221b authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlObserver: Add 'show app on top' switch to creator + qmlobserver

This is convenient especially in the observer mode.

Reviewed-by: Christiaan Janssen
parent e0811bee
......@@ -68,6 +68,8 @@ public:
void setAnimationSpeed(qreal slowdownFactor);
void setCurrentTool(QmlJSDebugger::Constants::DesignTool toolId);
void reloaded();
void setShowAppOnTop(bool showAppOnTop);
QString idStringForObject(QObject *obj) const;
void sendMessage(const QByteArray &message);
......@@ -81,6 +83,7 @@ Q_SIGNALS:
void currentObjectsChanged(const QList<QObject*> &objects);
void designModeBehaviorChanged(bool inDesignMode);
void showAppOnTopChanged(bool showAppOnTop);
void reloadRequested();
void selectToolRequested();
void selectMarqueeToolRequested();
......
......@@ -61,10 +61,14 @@ public:
static QString idStringForObject(QObject *obj);
QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace);
bool showAppOnTop() const;
public Q_SLOTS:
void setDesignModeBehavior(bool value);
bool designModeBehavior();
void setShowAppOnTop(bool appOnTop);
void changeAnimationSpeed(qreal slowdownFactor);
void continueExecution(qreal slowdownFactor = 1.0f);
void pauseExecution();
......@@ -73,6 +77,7 @@ public Q_SLOTS:
Q_SIGNALS:
void designModeBehaviorChanged(bool inDesignMode);
void showAppOnTopChanged(bool showAppOnTop);
void reloadRequested();
void marqueeSelectToolActivated();
void selectToolActivated();
......
......@@ -110,6 +110,10 @@ void QDeclarativeObserverService::messageReceived(const QByteArray &message)
bool inDesignMode;
ds >> inDesignMode;
emit designModeBehaviorChanged(inDesignMode);
} else if (type == "SHOW_APP_ON_TOP") {
bool showOnTop;
ds >> showOnTop;
emit showAppOnTopChanged(showOnTop);
} else if (type == "CREATE_OBJECT") {
QString qml;
int parentId;
......@@ -207,6 +211,16 @@ void QDeclarativeObserverService::reloaded()
sendMessage(message);
}
void QDeclarativeObserverService::setShowAppOnTop(bool showAppOnTop)
{
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SHOW_APP_ON_TOP") << showAppOnTop;
sendMessage(message);
}
void QDeclarativeObserverService::selectedColorChanged(const QColor &color)
{
QByteArray message;
......
......@@ -57,6 +57,7 @@ const int SceneChangeUpdateInterval = 5000;
QDeclarativeViewObserverPrivate::QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *q) :
q(q),
designModeBehavior(false),
showAppOnTop(false),
executionPaused(false),
slowdownFactor(1.0f),
toolbar(0)
......@@ -87,6 +88,8 @@ QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, QObje
data->debugService = QDeclarativeObserverService::instance();
connect(data->debugService, SIGNAL(designModeBehaviorChanged(bool)),
SLOT(setDesignModeBehavior(bool)));
connect(data->debugService, SIGNAL(showAppOnTopChanged(bool)),
SLOT(setShowAppOnTop(bool)));
connect(data->debugService, SIGNAL(reloadRequested()), SLOT(_q_reloadView()));
connect(data->debugService, SIGNAL(currentObjectsChanged(QList<QObject*>)),
SLOT(_q_onCurrentObjectsChanged(QList<QObject*>)));
......@@ -475,6 +478,33 @@ bool QDeclarativeViewObserver::designModeBehavior()
return data->designModeBehavior;
}
bool QDeclarativeViewObserver::showAppOnTop() const
{
return data->showAppOnTop;
}
void QDeclarativeViewObserver::setShowAppOnTop(bool appOnTop)
{
if (data->view) {
QWidget *rootWidget = data->view;
while (rootWidget->parentWidget())
rootWidget = rootWidget->parentWidget();
Qt::WindowFlags flags = rootWidget->windowFlags();
if (appOnTop) {
flags |= Qt::WindowStaysOnTopHint;
} else {
flags &= ~Qt::WindowStaysOnTopHint;
}
rootWidget->setWindowFlags(flags);
rootWidget->show();
}
data->showAppOnTop = appOnTop;
data->debugService->setShowAppOnTop(appOnTop);
emit showAppOnTopChanged(appOnTop);
}
void QDeclarativeViewObserverPrivate::changeTool(Constants::DesignTool tool,
Constants::ToolFlags /*flags*/)
{
......
......@@ -83,6 +83,7 @@ public:
BoundingRectHighlighter *boundingRectHighlighter;
bool designModeBehavior;
bool showAppOnTop;
bool executionPaused;
qreal slowdownFactor;
......
......@@ -422,6 +422,7 @@ int main(int argc, char ** argv)
viewer->enableExperimentalGestures();
viewer->setDesignModeBehavior(designModeBehavior);
viewer->setStayOnTop(stayOnTop);
foreach (QString lib, imports)
viewer->addLibraryPath(lib);
......
......@@ -755,6 +755,13 @@ void QDeclarativeViewer::createMenu()
connect(observer, SIGNAL(designModeBehaviorChanged(bool)), designModeBehaviorAction, SLOT(setChecked(bool)));
connect(QmlJSDebugger::QDeclarativeObserverService::instance(), SIGNAL(debuggingClientChanged(bool)), designModeBehaviorAction, SLOT(setEnabled(bool)));
appOnTopAction = new QAction(tr("Keep Window on Top"), this);
appOnTopAction->setCheckable(true);
appOnTopAction->setChecked(observer->showAppOnTop());
connect(appOnTopAction, SIGNAL(triggered(bool)), observer, SLOT(setShowAppOnTop(bool)));
connect(observer, SIGNAL(showAppOnTopChanged(bool)), appOnTopAction, SLOT(setChecked(bool)));
QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this);
connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings()));
......@@ -825,6 +832,7 @@ void QDeclarativeViewer::createMenu()
debugMenu->addAction(playSpeedAction);
debugMenu->addAction(showWarningsWindow);
debugMenu->addAction(designModeBehaviorAction);
debugMenu->addAction(appOnTopAction);
#endif // ! Q_OS_SYMBIAN
QMenu *settingsMenu = menu->addMenu(tr("S&ettings"));
......@@ -1487,6 +1495,11 @@ void QDeclarativeViewer::setSizeToView(bool sizeToView)
}
}
void QDeclarativeViewer::setStayOnTop(bool stayOnTop)
{
appOnTopAction->setChecked(stayOnTop);
}
void QDeclarativeViewer::setAnimationSpeed(float f)
{
QDeclarativeDebugHelper::setAnimationSlowDownFactor(f);
......
......@@ -107,6 +107,7 @@ public:
void setUseGL(bool use);
void setUseNativeFileBrowser(bool);
void setSizeToView(bool sizeToView);
void setStayOnTop(bool stayOnTop);
QDeclarativeView *view() const;
LoggerWidget *warningsWidget() const;
......@@ -201,6 +202,7 @@ private:
QActionGroup *orientation;
QAction *showWarningsWindow;
QAction *designModeBehaviorAction;
QAction *appOnTopAction;
QString m_script;
ScriptOptions m_scriptOptions;
......
......@@ -65,6 +65,7 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
m_selectAction(0),
m_zoomAction(0),
m_colorPickerAction(0),
m_showAppOnTopAction(0),
m_defaultAnimSpeedAction(0),
m_halfAnimSpeedAction(0),
m_fourthAnimSpeedAction(0),
......@@ -86,6 +87,7 @@ QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
void QmlInspectorToolbar::setEnabled(bool value)
{
m_fromQmlAction->setEnabled(value);
m_showAppOnTopAction->setEnabled(value);
m_observerModeAction->setEnabled(value);
m_playAction->setEnabled(value);
m_selectAction->setEnabled(value);
......@@ -166,6 +168,13 @@ void QmlInspectorToolbar::setDesignModeBehavior(bool inDesignMode)
m_emitSignals = true;
}
void QmlInspectorToolbar::setShowAppOnTop(bool showAppOnTop)
{
m_emitSignals = false;
m_showAppOnTopAction->setChecked(showAppOnTop);
m_emitSignals = true;
}
void QmlInspectorToolbar::createActions(const Core::Context &context)
{
Core::ICore *core = Core::ICore::instance();
......@@ -174,6 +183,9 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
m_fromQmlAction =
new QAction(QIcon(QLatin1String(":/qml/images/from-qml-small.png")),
tr("Apply Changes on Save"), this);
m_showAppOnTopAction =
new QAction(QIcon(QLatin1String(":/qml/images/app-on-top.png")),
tr("Show application on top"), this);
m_observerModeAction =
new QAction(QIcon(QLatin1String(":/qml/images/observermode.png")),
tr("Observer Mode"), this);
......@@ -191,6 +203,8 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
m_fromQmlAction->setCheckable(true);
m_fromQmlAction->setChecked(true);
m_showAppOnTopAction->setCheckable(true);
m_showAppOnTopAction->setChecked(false);
m_observerModeAction->setCheckable(true);
m_observerModeAction->setChecked(false);
m_selectAction->setCheckable(true);
......@@ -203,6 +217,8 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
am->registerAction(m_zoomAction, QmlJSInspector::Constants::ZOOM_ACTION, context);
am->registerAction(m_colorPickerAction, QmlJSInspector::Constants::COLOR_PICKER_ACTION, context);
am->registerAction(m_fromQmlAction, QmlJSInspector::Constants::FROM_QML_ACTION, context);
am->registerAction(m_showAppOnTopAction,
QmlJSInspector::Constants::SHOW_APP_ON_TOP_ACTION, context);
m_barWidget = new Utils::StyledBar;
m_barWidget->setSingleRow(true);
......@@ -250,6 +266,9 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
configBarLayout->addWidget(
createToolButton(am->command(QmlJSInspector::Constants::FROM_QML_ACTION)->action()));
configBarLayout->addWidget(
createToolButton(
am->command(QmlJSInspector::Constants::SHOW_APP_ON_TOP_ACTION)->action()));
configBarLayout->addSpacing(10);
configBarLayout->addWidget(
......@@ -277,6 +296,7 @@ void QmlInspectorToolbar::createActions(const Core::Context &context)
setEnabled(false);
connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml()));
connect(m_showAppOnTopAction, SIGNAL(triggered()), SLOT(showAppOnTopClick()));
connect(m_observerModeAction, SIGNAL(triggered()), SLOT(activateDesignModeOnClick()));
connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick()));
connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
......@@ -404,6 +424,12 @@ void QmlInspectorToolbar::activateZoomOnClick()
}
}
void QmlInspectorToolbar::showAppOnTopClick()
{
if (m_emitSignals)
emit showAppOnTopSelected(m_showAppOnTopAction->isChecked());
}
void QmlInspectorToolbar::setSelectedColor(const QColor &color)
{
m_colorBox->setColor(color);
......
......@@ -80,6 +80,7 @@ public slots:
void activateZoomTool();
void setAnimationSpeed(qreal slowdownFactor);
void setDesignModeBehavior(bool inDesignMode);
void setShowAppOnTop(bool showAppOnTop);
void setSelectedColor(const QColor &color);
signals:
......@@ -91,6 +92,7 @@ signals:
void selectToolSelected();
void zoomToolSelected();
void showAppOnTopSelected(bool isChecked);
void animationSpeedChanged(qreal slowdownFactor = 1.0f);
private slots:
......@@ -100,6 +102,8 @@ private slots:
void activateSelectToolOnClick();
void activateZoomOnClick();
void showAppOnTopClick();
void changeToDefaultAnimSpeed();
void changeToHalfAnimSpeed();
void changeToFourthAnimSpeed();
......@@ -119,6 +123,8 @@ private:
QAction *m_zoomAction;
QAction *m_colorPickerAction;
QAction *m_showAppOnTopAction;
QAction *m_defaultAnimSpeedAction;
QAction *m_halfAnimSpeedAction;
QAction *m_fourthAnimSpeedAction;
......
......@@ -89,6 +89,8 @@ void ClientProxy::connectToServer()
SIGNAL(animationSpeedChanged(qreal)));
connect(m_observerClient, SIGNAL(designModeBehaviorChanged(bool)),
SIGNAL(designModeBehaviorChanged(bool)));
connect(m_observerClient, SIGNAL(showAppOnTopChanged(bool)),
SIGNAL(showAppOnTopChanged(bool)));
connect(m_observerClient, SIGNAL(reloaded()), this,
SIGNAL(serverReloaded()));
connect(m_observerClient, SIGNAL(selectedColorChanged(QColor)),
......@@ -484,6 +486,12 @@ void ClientProxy::changeToSelectMarqueeTool()
m_observerClient->changeToSelectMarqueeTool();
}
void ClientProxy::showAppOnTop(bool showOnTop)
{
if (isConnected())
m_observerClient->showAppOnTop(showOnTop);
}
void ClientProxy::createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename)
{
......
......@@ -100,6 +100,7 @@ signals:
void zoomToolActivated();
void animationSpeedChanged(qreal slowdownFactor);
void designModeBehaviorChanged(bool inDesignMode);
void showAppOnTopChanged(bool showAppOnTop);
void serverReloaded();
void selectedColorChanged(const QColor &color);
void contextPathUpdated(const QStringList &contextPath);
......@@ -115,6 +116,7 @@ public slots:
void changeToZoomTool();
void changeToSelectTool();
void changeToSelectMarqueeTool();
void showAppOnTop(bool showOnTop);
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename = QString());
void destroyQmlObject(int debugId);
......
......@@ -768,9 +768,9 @@ void InspectorUi::setupToolbar(bool doConnect)
m_clientProxy, SLOT(changeToSelectTool()));
connect(m_toolbar, SIGNAL(applyChangesFromQmlFileTriggered(bool)),
this, SLOT(setApplyChangesToQmlObserver(bool)));
connect(m_toolbar, SIGNAL(showAppOnTopSelected(bool)),
m_clientProxy, SLOT(showAppOnTop(bool)));
connect(this, SIGNAL(livePreviewActivated(bool)),
m_toolbar, SLOT(setLivePreviewChecked(bool)));
connect(m_clientProxy, SIGNAL(colorPickerActivated()),
m_toolbar, SLOT(activateColorPicker()));
connect(m_clientProxy, SIGNAL(selectToolActivated()),
......@@ -779,6 +779,8 @@ void InspectorUi::setupToolbar(bool doConnect)
m_toolbar, SLOT(activateZoomTool()));
connect(m_clientProxy, SIGNAL(designModeBehaviorChanged(bool)),
m_toolbar, SLOT(setDesignModeBehavior(bool)));
connect(m_clientProxy, SIGNAL(showAppOnTopChanged(bool)),
m_toolbar, SLOT(setShowAppOnTop(bool)));
connect(m_clientProxy, SIGNAL(selectedColorChanged(QColor)),
m_toolbar, SLOT(setSelectedColor(QColor)));
......@@ -804,9 +806,9 @@ void InspectorUi::setupToolbar(bool doConnect)
m_clientProxy, SLOT(changeToSelectTool()));
disconnect(m_toolbar, SIGNAL(applyChangesFromQmlFileTriggered(bool)),
this, SLOT(setApplyChangesToQmlObserver(bool)));
disconnect(m_toolbar, SIGNAL(showAppOnTopSelected(bool)),
m_clientProxy, SLOT(showAppOnTop(bool)));
disconnect(this, SIGNAL(livePreviewActivated(bool)),
m_toolbar, SLOT(setLivePreviewChecked(bool)));
disconnect(m_clientProxy, SIGNAL(colorPickerActivated()),
m_toolbar, SLOT(activateColorPicker()));
disconnect(m_clientProxy, SIGNAL(selectToolActivated()),
......@@ -815,6 +817,8 @@ void InspectorUi::setupToolbar(bool doConnect)
m_toolbar, SLOT(activateZoomTool()));
disconnect(m_clientProxy, SIGNAL(designModeBehaviorChanged(bool)),
m_toolbar, SLOT(setDesignModeBehavior(bool)));
disconnect(m_clientProxy, SIGNAL(showAppOnTopChanged(bool)),
m_toolbar, SLOT(setShowAppOnTop(bool)));
disconnect(m_clientProxy, SIGNAL(selectedColorChanged(QColor)),
m_toolbar, SLOT(setSelectedColor(QColor)));
......
......@@ -19,5 +19,6 @@
<file>images/select-marquee-small.png</file>
<file>images/color-picker-small-hicontrast.png</file>
<file>images/observermode.png</file>
<file>images/app-on-top.png</file>
</qresource>
</RCC>
......@@ -50,6 +50,7 @@ const char * const ZOOM_ACTION = "QmlInspector.Zoom";
const char * const COLOR_PICKER_ACTION = "QmlInspector.ColorPicker";
const char * const TO_QML_ACTION = "QmlInspector.ToQml";
const char * const FROM_QML_ACTION = "QmlInspector.FromQml";
const char * const SHOW_APP_ON_TOP_ACTION = "QmlInspector.ShowAppOnTop";
// settings
const char * const S_QML_INSPECTOR = "QML.Inspector";
......
......@@ -107,6 +107,10 @@ void QmlJSObserverClient::messageReceived(const QByteArray &message)
bool inDesignMode;
ds >> inDesignMode;
emit designModeBehaviorChanged(inDesignMode);
} else if (type == "SHOW_APP_ON_TOP") {
bool showAppOnTop;
ds >> showAppOnTop;
emit showAppOnTopChanged(showAppOnTop);
} else if (type == "RELOADED") {
emit reloaded();
} else if (type == "COLOR_CHANGED") {
......@@ -337,6 +341,23 @@ void QmlJSObserverClient::changeToZoomTool()
sendMessage(message);
}
void QmlJSObserverClient::showAppOnTop(bool showOnTop)
{
if (!m_connection || !m_connection->isConnected())
return;
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SHOW_APP_ON_TOP")
<< showOnTop;
if (debug)
qDebug() << "QmlJSObserverClient: Sending" <<"SHOWONTOP" << showOnTop;
sendMessage(message);
}
void QmlJSObserverClient::createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename)
{
......
......@@ -62,6 +62,7 @@ public:
void changeToSelectTool();
void changeToSelectMarqueeTool();
void changeToZoomTool();
void showAppOnTop(bool showOnTop);
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename);
......@@ -90,6 +91,7 @@ signals:
void zoomToolActivated();
void animationSpeedChanged(qreal slowdownFactor);
void designModeBehaviorChanged(bool inDesignMode);
void showAppOnTopChanged(bool showAppOnTop);
void reloaded(); // the server has reloaded the document
void contextPathUpdated(const QStringList &path);
......
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