From 0b877b48dc990ca6bb806be668d60f6ced470de2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 6 Apr 2011 14:45:11 +0200 Subject: Removed some superfluous semicolons Reviewed-by: Kai Koehne --- src/script/api/qscriptengineagent_p.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/script/api/qscriptengineagent_p.h b/src/script/api/qscriptengineagent_p.h index abe4e9e..b96d19d 100644 --- a/src/script/api/qscriptengineagent_p.h +++ b/src/script/api/qscriptengineagent_p.h @@ -57,22 +57,22 @@ public: static QScriptEngineAgentPrivate* get(QScriptEngineAgent* p) {return p->d_func();} QScriptEngineAgentPrivate(){} - virtual ~QScriptEngineAgentPrivate(){}; + virtual ~QScriptEngineAgentPrivate(){} void attach(); void detach(); //scripts - virtual void sourceParsed(JSC::ExecState*, const JSC::SourceCode&, int /*errorLine*/, const JSC::UString& /*errorMsg*/) {}; + virtual void sourceParsed(JSC::ExecState*, const JSC::SourceCode&, int /*errorLine*/, const JSC::UString& /*errorMsg*/) {} virtual void scriptUnload(qint64 id) { q_ptr->scriptUnload(id); - }; + } virtual void scriptLoad(qint64 id, const JSC::UString &program, const JSC::UString &fileName, int baseLineNumber) { q_ptr->scriptLoad(id,program, fileName, baseLineNumber); - }; + } //exceptions virtual void exception(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, int lineno, bool hasHandler) @@ -81,7 +81,7 @@ public: Q_UNUSED(sourceID); Q_UNUSED(lineno); Q_UNUSED(hasHandler); - }; + } virtual void exceptionThrow(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, bool hasHandler); virtual void exceptionCatch(const JSC::DebuggerCallFrame& frame, intptr_t sourceID); @@ -92,20 +92,20 @@ public: Q_UNUSED(lineno); q_ptr->contextPush(); q_ptr->functionEntry(sourceID); - }; + } virtual void returnEvent(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, int lineno); virtual void willExecuteProgram(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, int lineno) { Q_UNUSED(frame); Q_UNUSED(sourceID); Q_UNUSED(lineno); - }; + } virtual void didExecuteProgram(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, int lineno) { Q_UNUSED(frame); - Q_UNUSED(sourceID); + Q_UNUSED(sourceID); Q_UNUSED(lineno); - }; + } virtual void functionExit(const JSC::JSValue& returnValue, intptr_t sourceID); //others virtual void didReachBreakpoint(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, int lineno/*, int column*/); -- cgit v0.12 From 9fa0a9319ee0f178d03f9bdc4afbabb8563b4c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 6 Apr 2011 16:31:09 +0200 Subject: QDeclarativeDebugServer: Send hello answer before any service messages This is necessary since some services may like to send a message back immediately when its state changes to enabled. Reviewed-by: Kai Koehne --- src/declarative/debugger/qdeclarativedebugserver.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/declarative/debugger/qdeclarativedebugserver.cpp b/src/declarative/debugger/qdeclarativedebugserver.cpp index e43b90d..f76c747 100644 --- a/src/declarative/debugger/qdeclarativedebugserver.cpp +++ b/src/declarative/debugger/qdeclarativedebugserver.cpp @@ -242,6 +242,17 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) int version; in >> version >> d->clientPlugins; + // Send the hello answer immediately, since it needs to arrive before + // the plugins below start sending messages. + QByteArray helloAnswer; + { + QDataStream out(&helloAnswer, QIODevice::WriteOnly); + out << QString(QLatin1String("QDeclarativeDebugClient")) << 0 << protocolVersion << d->plugins.keys(); + } + d->connection->send(helloAnswer); + + d->gotHello = true; + QHash::Iterator iter = d->plugins.begin(); for (; iter != d->plugins.end(); ++iter) { QDeclarativeDebugService::Status newStatus = QDeclarativeDebugService::Unavailable; @@ -251,14 +262,6 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) iter.value()->statusChanged(newStatus); } - QByteArray helloAnswer; - { - QDataStream out(&helloAnswer, QIODevice::WriteOnly); - out << QString(QLatin1String("QDeclarativeDebugClient")) << 0 << protocolVersion << d->plugins.keys(); - } - d->connection->send(helloAnswer); - - d->gotHello = true; qWarning("QDeclarativeDebugServer: Connection established"); } else { -- cgit v0.12 From 97e423b50d316c3a9e2083c3a9d80bf16554faa9 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 3 May 2011 16:50:46 +0300 Subject: Do not allow fullscreen/maximized windows to expand beyond client rect Automatic layouting of widgets still managed to layout maximized and fullscreen windows larger than client rect in Symbian in some cases. Fixed by limiting window dimensions to client area boundaries in setGeometry_sys if the window is maximized or fullscreen. Task-number: QTBUG-5697 Reviewed-by: Sami Merila --- src/gui/kernel/qwidget_s60.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 12bcc4b..5e9584b 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -235,19 +235,21 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) QSize oldSize(q->size()); QRect oldGeom(data.crect); - // Lose maximized status if deliberate resize - if (w != oldSize.width() || h != oldSize.height()) - data.window_state &= ~Qt::WindowMaximized; - bool checkExtra = true; - if (q->isWindow() && (data.window_state & Qt::WindowFullScreen)) { - // Do not modity window size for fullscreen windows, if requested - // size is already equal to clientRect. + if (q->isWindow() && (data.window_state & (Qt::WindowFullScreen | Qt::WindowMaximized))) { + // Do not allow fullscreen/maximized windows to expand beyond client rect TRect r = static_cast(S60->appUi())->ClientRect(); + w = qMin(w, r.Width()); + h = qMin(h, r.Height()); + if (w == r.Width() && h == r.Height()) checkExtra = false; } + // Lose maximized status if deliberate resize + if (w != oldSize.width() || h != oldSize.height()) + data.window_state &= ~Qt::WindowMaximized; + if (checkExtra && extra) { // any size restrictions? w = qMin(w,extra->maxw); h = qMin(h,extra->maxh); -- cgit v0.12 From 35faeb205843c4f0b921d2b878d2d24962c64664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Fri, 25 Mar 2011 13:36:16 +0100 Subject: Moved the QML Observer Service and related functionality into Qt This code was previously developed as part of Qt Creator in share/qtcreator/qml/qmljsdebugger/ Moving it into Qt will allow us to simplify the setup required before you can debug QML applications. To avoid adding too much weight to the QtDeclarative module, a declarativeobserver plugin was introduced that contains the QDeclarativeViewObserver and related classes. The QDeclarativeObserverService is just a stub service that loads this plugin once a QML debugging client connects. The plugin implements the QDeclarativeObserverInterface A QJSDebugService was separated out of QJSDebuggerAgent, so that the service can be active while the agent is instantiated lazily. Each QDeclarativeEngine adds itself to the QJSDebugService. Currently only the first one is used when instantiating the agent. QDeclarativeObserverService is hooked into QDeclarativeView, with the view registering itself to the service, allowing the QDeclarativeViewObserver to be created for the view once somebody connects to the service. Again, only the first view is used at the moment. Change-Id: Ib50579c6d24361c2b39528e5556410d3446c2e90 Reviewed-by: Martin Jones Reviewed-by: Michael Brasser --- src/declarative/debugger/debugger.pri | 11 +- .../debugger/qdeclarativeobserverservice.cpp | 137 +++ .../debugger/qdeclarativeobserverservice_p.h | 91 ++ src/declarative/debugger/qjsdebuggeragent.cpp | 576 ++++++++++ src/declarative/debugger/qjsdebuggeragent_p.h | 204 ++++ src/declarative/debugger/qjsdebugservice.cpp | 198 ++++ src/declarative/debugger/qjsdebugservice_p.h | 99 ++ src/declarative/qml/qdeclarativeengine.cpp | 6 +- src/declarative/qml/qdeclarativeengine_p.h | 1 - src/declarative/util/qdeclarativeview.cpp | 5 +- .../declarativeobserver/declarativeobserver.pro | 53 + .../editor/abstractliveedittool.cpp | 200 ++++ .../editor/abstractliveedittool_p.h | 121 ++ .../editor/boundingrecthighlighter.cpp | 284 +++++ .../editor/boundingrecthighlighter_p.h | 126 +++ .../declarativeobserver/editor/colorpickertool.cpp | 131 +++ .../declarativeobserver/editor/colorpickertool_p.h | 99 ++ .../declarativeobserver/editor/editor.qrc | 24 + .../editor/images/color-picker-24.png | Bin 0 -> 3440 bytes .../editor/images/color-picker-hicontrast.png | Bin 0 -> 3192 bytes .../editor/images/color-picker.png | Bin 0 -> 3173 bytes .../editor/images/from-qml-24.png | Bin 0 -> 3395 bytes .../declarativeobserver/editor/images/from-qml.png | Bin 0 -> 3205 bytes .../editor/images/observermode-24.png | Bin 0 -> 1283 bytes .../editor/images/observermode.png | Bin 0 -> 3539 bytes .../declarativeobserver/editor/images/pause-24.png | Bin 0 -> 3307 bytes .../declarativeobserver/editor/images/pause.png | Bin 0 -> 3097 bytes .../declarativeobserver/editor/images/play-24.png | Bin 0 -> 3655 bytes .../declarativeobserver/editor/images/play.png | Bin 0 -> 3363 bytes .../declarativeobserver/editor/images/reload.png | Bin 0 -> 3418 bytes .../editor/images/resize_handle.png | Bin 0 -> 160 bytes .../editor/images/select-24.png | Bin 0 -> 3510 bytes .../editor/images/select-marquee-24.png | Bin 0 -> 2891 bytes .../editor/images/select-marquee.png | Bin 0 -> 2871 bytes .../declarativeobserver/editor/images/select.png | Bin 0 -> 3308 bytes .../editor/images/to-qml-24.png | Bin 0 -> 3407 bytes .../declarativeobserver/editor/images/to-qml.png | Bin 0 -> 3227 bytes .../declarativeobserver/editor/images/zoom-24.png | Bin 0 -> 3566 bytes .../declarativeobserver/editor/images/zoom.png | Bin 0 -> 3347 bytes .../declarativeobserver/editor/livelayeritem.cpp | 92 ++ .../declarativeobserver/editor/livelayeritem_p.h | 73 ++ .../editor/liverubberbandselectionmanipulator.cpp | 165 +++ .../editor/liverubberbandselectionmanipulator_p.h | 102 ++ .../editor/liveselectionindicator.cpp | 148 +++ .../editor/liveselectionindicator_p.h | 90 ++ .../editor/liveselectionrectangle.cpp | 113 ++ .../editor/liveselectionrectangle_p.h | 83 ++ .../editor/liveselectiontool.cpp | 442 ++++++++ .../editor/liveselectiontool_p.h | 126 +++ .../editor/livesingleselectionmanipulator.cpp | 151 +++ .../editor/livesingleselectionmanipulator_p.h | 95 ++ .../declarativeobserver/editor/qmltoolbar.cpp | 328 ++++++ .../declarativeobserver/editor/qmltoolbar_p.h | 138 +++ .../editor/subcomponenteditortool.cpp | 364 ++++++ .../editor/subcomponenteditortool_p.h | 131 +++ .../editor/subcomponentmasklayeritem.cpp | 124 +++ .../editor/subcomponentmasklayeritem_p.h | 77 ++ .../declarativeobserver/editor/toolbarcolorbox.cpp | 134 +++ .../declarativeobserver/editor/toolbarcolorbox_p.h | 87 ++ .../declarativeobserver/editor/zoomtool.cpp | 336 ++++++ .../declarativeobserver/editor/zoomtool_p.h | 113 ++ .../qdeclarativeobserverplugin.cpp | 81 ++ .../qdeclarativeobserverplugin.h | 71 ++ .../qdeclarativeobserverprotocol.h | 145 +++ .../qdeclarativeviewobserver.cpp | 1159 ++++++++++++++++++++ .../qdeclarativeviewobserver_p.h | 154 +++ .../qdeclarativeviewobserver_p_p.h | 165 +++ .../declarativeobserver/qmlobserverconstants_p.h | 90 ++ src/plugins/qmltooling/qmltooling.pro | 2 +- .../qmltooling/tcpserver/qtcpserverconnection.cpp | 1 + .../qmltooling/tcpserver/qtcpserverconnection.h | 1 - 71 files changed, 7740 insertions(+), 7 deletions(-) create mode 100644 src/declarative/debugger/qdeclarativeobserverservice.cpp create mode 100644 src/declarative/debugger/qdeclarativeobserverservice_p.h create mode 100644 src/declarative/debugger/qjsdebuggeragent.cpp create mode 100644 src/declarative/debugger/qjsdebuggeragent_p.h create mode 100644 src/declarative/debugger/qjsdebugservice.cpp create mode 100644 src/declarative/debugger/qjsdebugservice_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/colorpickertool.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/colorpickertool_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/editor.qrc create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-hicontrast.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/color-picker.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/from-qml-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/from-qml.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/observermode-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/observermode.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/pause-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/pause.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/play-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/play.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/reload.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/resize_handle.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/select-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/select.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/to-qml-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/to-qml.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/zoom-24.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/images/zoom.png create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/livelayeritem.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/livelayeritem_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/zoomtool.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/editor/zoomtool_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.h create mode 100644 src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h create mode 100644 src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp create mode 100644 src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h create mode 100644 src/plugins/qmltooling/declarativeobserver/qmlobserverconstants_p.h diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 75287b4..044db3c 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -8,7 +8,10 @@ SOURCES += \ $$PWD/qdeclarativedebug.cpp \ $$PWD/qdeclarativedebugtrace.cpp \ $$PWD/qdeclarativedebughelper.cpp \ - $$PWD/qdeclarativedebugserver.cpp + $$PWD/qdeclarativedebugserver.cpp \ + $$PWD/qdeclarativeobserverservice.cpp \ + $$PWD/qjsdebuggeragent.cpp \ + $$PWD/qjsdebugservice.cpp HEADERS += \ $$PWD/qdeclarativedebuggerstatus_p.h \ @@ -20,4 +23,8 @@ HEADERS += \ $$PWD/qdeclarativedebugtrace_p.h \ $$PWD/qdeclarativedebughelper_p.h \ $$PWD/qdeclarativedebugserver_p.h \ - debugger/qdeclarativedebugserverconnection_p.h + $$PWD/qdeclarativedebugserverconnection_p.h \ + $$PWD/qdeclarativeobserverservice_p.h \ + $$PWD/qdeclarativeobserverinterface_p.h \ + $$PWD/qjsdebuggeragent_p.h \ + $$PWD/qjsdebugservice_p.h diff --git a/src/declarative/debugger/qdeclarativeobserverservice.cpp b/src/declarative/debugger/qdeclarativeobserverservice.cpp new file mode 100644 index 0000000..a623c55 --- /dev/null +++ b/src/declarative/debugger/qdeclarativeobserverservice.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qdeclarativeobserverservice_p.h" +#include "private/qdeclarativeobserverinterface_p.h" + +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QDeclarativeObserverService, serviceInstance) + +QDeclarativeObserverService::QDeclarativeObserverService() + : QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode")) + , m_observer(0) +{ +} + +QDeclarativeObserverService *QDeclarativeObserverService::instance() +{ + return serviceInstance(); +} + +void QDeclarativeObserverService::addView(QDeclarativeView *view) +{ + m_views.append(view); +} + +void QDeclarativeObserverService::removeView(QDeclarativeView *view) +{ + m_views.removeAll(view); +} + +void QDeclarativeObserverService::sendMessage(const QByteArray &message) +{ + if (status() != Enabled) + return; + + QDeclarativeDebugService::sendMessage(message); +} + +void QDeclarativeObserverService::statusChanged(Status status) +{ + if (m_views.isEmpty()) + return; + + if (status == Enabled) { + if (!m_observer) + m_observer = loadObserverPlugin(); + + if (!m_observer) { + qWarning() << "Error while loading observer plugin"; + return; + } + + m_observer->activate(); + } else { + if (m_observer) + m_observer->deactivate(); + } +} + +void QDeclarativeObserverService::messageReceived(const QByteArray &message) +{ + emit gotMessage(message); +} + +QDeclarativeObserverInterface *QDeclarativeObserverService::loadObserverPlugin() +{ + QStringList pluginCandidates; + const QStringList paths = QCoreApplication::libraryPaths(); + foreach (const QString &libPath, paths) { + const QDir dir(libPath + QLatin1String("/qmltooling")); + if (dir.exists()) + foreach (const QString &pluginPath, dir.entryList(QDir::Files)) + pluginCandidates << dir.absoluteFilePath(pluginPath); + } + + foreach (const QString &pluginPath, pluginCandidates) { + QPluginLoader loader(pluginPath); + if (!loader.load()) + continue; + + QDeclarativeObserverInterface *observer = + qobject_cast(loader.instance()); + + if (observer) + return observer; + loader.unload(); + } + return 0; +} + +QT_END_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativeobserverservice_p.h b/src/declarative/debugger/qdeclarativeobserverservice_p.h new file mode 100644 index 0000000..36f31dc --- /dev/null +++ b/src/declarative/debugger/qdeclarativeobserverservice_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEOBSERVERSERVICE_H +#define QDECLARATIVEOBSERVERSERVICE_H + +#include "private/qdeclarativedebugservice_p.h" +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeView; +class QDeclarativeObserverInterface; + +class Q_DECLARATIVE_EXPORT QDeclarativeObserverService : public QDeclarativeDebugService +{ + Q_OBJECT + +public: + QDeclarativeObserverService(); + static QDeclarativeObserverService *instance(); + + void addView(QDeclarativeView *); + void removeView(QDeclarativeView *); + QList views() const { return m_views; } + + void sendMessage(const QByteArray &message); + +Q_SIGNALS: + void gotMessage(const QByteArray &message); + +protected: + virtual void statusChanged(Status status); + virtual void messageReceived(const QByteArray &); + +private: + static QDeclarativeObserverInterface *loadObserverPlugin(); + + QList m_views; + QDeclarativeObserverInterface *m_observer; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEOBSERVERSERVICE_H diff --git a/src/declarative/debugger/qjsdebuggeragent.cpp b/src/declarative/debugger/qjsdebuggeragent.cpp new file mode 100644 index 0000000..601c8c8 --- /dev/null +++ b/src/declarative/debugger/qjsdebuggeragent.cpp @@ -0,0 +1,576 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qjsdebuggeragent_p.h" +#include "private/qdeclarativedebughelper_p.h" + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QJSDebuggerAgentPrivate +{ +public: + QJSDebuggerAgentPrivate(QJSDebuggerAgent *q) + : q(q), state(NoState) + {} + + void continueExec(); + void recordKnownObjects(const QList &); + QList getLocals(QScriptContext *); + void positionChange(qint64 scriptId, int lineNumber, int columnNumber); + QScriptEngine *engine() { return q->engine(); } + void stopped(); + +public: + QJSDebuggerAgent *q; + JSDebuggerState state; + int stepDepth; + int stepCount; + + QEventLoop loop; + QHash filenames; + JSAgentBreakpoints breakpoints; + // breakpoints by filename (without path) + QHash fileNameToBreakpoints; + QStringList watchExpressions; + QSet knownObjectIds; +}; + +namespace { + +class SetupExecEnv +{ +public: + SetupExecEnv(QJSDebuggerAgentPrivate *a) + : agent(a), + previousState(a->state), + hadException(a->engine()->hasUncaughtException()) + { + agent->state = StoppedState; + } + + ~SetupExecEnv() + { + if (!hadException && agent->engine()->hasUncaughtException()) + agent->engine()->clearExceptions(); + agent->state = previousState; + } + +private: + QJSDebuggerAgentPrivate *agent; + JSDebuggerState previousState; + bool hadException; +}; + +} // anonymous namespace + +static JSAgentWatchData fromScriptValue(const QString &expression, + const QScriptValue &value) +{ + static const QString arrayStr = QCoreApplication::translate + ("Debugger::JSAgentWatchData", "[Array of length %1]"); + static const QString undefinedStr = QCoreApplication::translate + ("Debugger::JSAgentWatchData", ""); + + JSAgentWatchData data; + data.exp = expression.toUtf8(); + data.name = data.exp; + data.hasChildren = false; + data.value = value.toString().toUtf8(); + data.objectId = value.objectId(); + if (value.isArray()) { + data.type = "Array"; + data.value = arrayStr.arg(value.property(QLatin1String("length")).toString()).toUtf8(); + data.hasChildren = true; + } else if (value.isBool()) { + data.type = "Bool"; + // data.value = value.toBool() ? "true" : "false"; + } else if (value.isDate()) { + data.type = "Date"; + data.value = value.toDateTime().toString().toUtf8(); + } else if (value.isError()) { + data.type = "Error"; + } else if (value.isFunction()) { + data.type = "Function"; + } else if (value.isUndefined()) { + data.type = undefinedStr.toUtf8(); + } else if (value.isNumber()) { + data.type = "Number"; + } else if (value.isRegExp()) { + data.type = "RegExp"; + } else if (value.isString()) { + data.type = "String"; + } else if (value.isVariant()) { + data.type = "Variant"; + } else if (value.isQObject()) { + const QObject *obj = value.toQObject(); + data.type = "Object"; + data.value += '['; + data.value += obj->metaObject()->className(); + data.value += ']'; + data.hasChildren = true; + } else if (value.isObject()) { + data.type = "Object"; + data.hasChildren = true; + data.value = "[Object]"; + } else if (value.isNull()) { + data.type = ""; + } else { + data.type = ""; + } + return data; +} + +static QList expandObject(const QScriptValue &object) +{ + QList result; + QScriptValueIterator it(object); + while (it.hasNext()) { + it.next(); + if (it.flags() & QScriptValue::SkipInEnumeration) + continue; + if (/*object.isQObject() &&*/ it.value().isFunction()) { + // Cosmetics: skip all functions and slot, there are too many of them, + // and it is not useful information in the debugger. + continue; + } + JSAgentWatchData data = fromScriptValue(it.name(), it.value()); + result.append(data); + } + if (result.isEmpty()) { + JSAgentWatchData data; + data.name = ""; + data.hasChildren = false; + data.value = " "; + data.objectId = 0; + result.append(data); + } + return result; +} + +static QString fileName(const QString &fileUrl) +{ + int lastDelimiterPos = fileUrl.lastIndexOf(QLatin1Char('/')); + return fileUrl.mid(lastDelimiterPos, fileUrl.size() - lastDelimiterPos); +} + +void QJSDebuggerAgentPrivate::recordKnownObjects(const QList& list) +{ + foreach (const JSAgentWatchData &data, list) + knownObjectIds << data.objectId; +} + +QList QJSDebuggerAgentPrivate::getLocals(QScriptContext *ctx) +{ + QList locals; + if (ctx) { + QScriptValue activationObject = ctx->activationObject(); + QScriptValue thisObject = ctx->thisObject(); + locals = expandObject(activationObject); + if (thisObject.isObject() + && thisObject.objectId() != engine()->globalObject().objectId() + && QScriptValueIterator(thisObject).hasNext()) + locals.prepend(fromScriptValue(QLatin1String("this"), thisObject)); + recordKnownObjects(locals); + knownObjectIds << activationObject.objectId(); + } + return locals; +} + +/*! + Constructs a new agent for the given \a engine. The agent will + report debugging-related events (e.g. step completion) to the given + \a backend. +*/ +QJSDebuggerAgent::QJSDebuggerAgent(QScriptEngine *engine, QObject *parent) + : QObject(parent) + , QScriptEngineAgent(engine) + , d(new QJSDebuggerAgentPrivate(this)) +{ + QJSDebuggerAgent::engine()->setAgent(this); +} + +QJSDebuggerAgent::QJSDebuggerAgent(QDeclarativeEngine *engine, QObject *parent) + : QObject(parent) + , QScriptEngineAgent(QDeclarativeDebugHelper::getScriptEngine(engine)) + , d(new QJSDebuggerAgentPrivate(this)) +{ + QJSDebuggerAgent::engine()->setAgent(this); +} + +/*! + Destroys this QJSDebuggerAgent. +*/ +QJSDebuggerAgent::~QJSDebuggerAgent() +{ + engine()->setAgent(0); + delete d; +} + +void QJSDebuggerAgent::setBreakpoints(const JSAgentBreakpoints &breakpoints) +{ + d->breakpoints = breakpoints; + + d->fileNameToBreakpoints.clear(); + foreach (const JSAgentBreakpointData &bp, breakpoints) + d->fileNameToBreakpoints.insertMulti(fileName(QString::fromUtf8(bp.fileUrl)), bp); +} + +void QJSDebuggerAgent::setWatchExpressions(const QStringList &watchExpressions) +{ + d->watchExpressions = watchExpressions; +} + +void QJSDebuggerAgent::stepOver() +{ + d->stepDepth = 0; + d->state = SteppingOverState; + d->continueExec(); +} + +void QJSDebuggerAgent::stepInto() +{ + d->stepDepth = 0; + d->state = SteppingIntoState; + d->continueExec(); +} + +void QJSDebuggerAgent::stepOut() +{ + d->stepDepth = 0; + d->state = SteppingOutState; + d->continueExec(); +} + +void QJSDebuggerAgent::continueExecution() +{ + d->state = NoState; + d->continueExec(); +} + +JSAgentWatchData QJSDebuggerAgent::executeExpression(const QString &expr) +{ + SetupExecEnv execEnv(d); + + JSAgentWatchData data = fromScriptValue(expr, engine()->evaluate(expr)); + d->knownObjectIds << data.objectId; + return data; +} + +QList QJSDebuggerAgent::expandObjectById(quint64 objectId) +{ + SetupExecEnv execEnv(d); + + QScriptValue v; + if (d->knownObjectIds.contains(objectId)) + v = engine()->objectById(objectId); + + QList result = expandObject(v); + d->recordKnownObjects(result); + return result; +} + +QList QJSDebuggerAgent::locals() +{ + SetupExecEnv execEnv(d); + return d->getLocals(engine()->currentContext()); +} + +QList QJSDebuggerAgent::localsAtFrame(int frameId) +{ + SetupExecEnv execEnv(d); + + int deep = 0; + QScriptContext *ctx = engine()->currentContext(); + while (ctx && deep < frameId) { + ctx = ctx->parentContext(); + deep++; + } + + return d->getLocals(ctx); +} + +QList QJSDebuggerAgent::backtrace() +{ + SetupExecEnv execEnv(d); + + QList backtrace; + + for (QScriptContext *ctx = engine()->currentContext(); ctx; ctx = ctx->parentContext()) { + QScriptContextInfo info(ctx); + + JSAgentStackData frame; + frame.functionName = info.functionName().toUtf8(); + if (frame.functionName.isEmpty()) { + if (ctx->parentContext()) { + switch (info.functionType()) { + case QScriptContextInfo::ScriptFunction: + frame.functionName = ""; + break; + case QScriptContextInfo::NativeFunction: + frame.functionName = ""; + break; + case QScriptContextInfo::QtFunction: + case QScriptContextInfo::QtPropertyFunction: + frame.functionName = ""; + break; + } + } else { + frame.functionName = ""; + } + } + frame.lineNumber = info.lineNumber(); + // if the line number is unknown, fallback to the function line number + if (frame.lineNumber == -1) + frame.lineNumber = info.functionStartLineNumber(); + + frame.fileUrl = info.fileName().toUtf8(); + backtrace.append(frame); + } + + return backtrace; +} + +QList QJSDebuggerAgent::watches() +{ + SetupExecEnv execEnv(d); + + QList watches; + foreach (const QString &expr, d->watchExpressions) + watches << fromScriptValue(expr, engine()->evaluate(expr)); + d->recordKnownObjects(watches); + return watches; +} + +void QJSDebuggerAgent::setProperty(qint64 objectId, + const QString &property, + const QString &value) +{ + SetupExecEnv execEnv(d); + + if (d->knownObjectIds.contains(objectId)) { + QScriptValue object = engine()->objectById(objectId); + if (object.isObject()) { + QScriptValue result = engine()->evaluate(value); + object.setProperty(property, result); + } + } +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::scriptLoad(qint64 id, const QString &program, + const QString &fileName, int) +{ + Q_UNUSED(program); + d->filenames.insert(id, fileName); +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::scriptUnload(qint64 id) +{ + d->filenames.remove(id); +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::contextPush() +{ +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::contextPop() +{ +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::functionEntry(qint64 scriptId) +{ + Q_UNUSED(scriptId); + d->stepDepth++; +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue) +{ + Q_UNUSED(scriptId); + Q_UNUSED(returnValue); + d->stepDepth--; +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::positionChange(qint64 scriptId, int lineNumber, int columnNumber) +{ + d->positionChange(scriptId, lineNumber, columnNumber); +} + +void QJSDebuggerAgentPrivate::positionChange(qint64 scriptId, int lineNumber, int columnNumber) +{ + Q_UNUSED(columnNumber); + + if (state == StoppedState) + return; //no re-entrency + + // check breakpoints + if (!breakpoints.isEmpty()) { + QHash::const_iterator it = filenames.constFind(scriptId); + QScriptContext *ctx = engine()->currentContext(); + QScriptContextInfo info(ctx); + if (it == filenames.constEnd()) { + // It is possible that the scripts are loaded before the agent is attached + QString filename = info.fileName(); + + JSAgentStackData frame; + frame.functionName = info.functionName().toUtf8(); + + QPair key = qMakePair(filename, lineNumber); + it = filenames.insert(scriptId, filename); + } + + const QString filePath = it.value(); + JSAgentBreakpoints bps = fileNameToBreakpoints.values(fileName(filePath)).toSet(); + + foreach (const JSAgentBreakpointData &bp, bps) { + if (bp.lineNumber == lineNumber) { + stopped(); + return; + } + } + } + + switch (state) { + case NoState: + case StoppedState: + // Do nothing + break; + case SteppingOutState: + if (stepDepth >= 0) + break; + //fallthough + case SteppingOverState: + if (stepDepth > 0) + break; + //fallthough + case SteppingIntoState: + stopped(); + break; + } + +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::exceptionThrow(qint64 scriptId, + const QScriptValue &exception, + bool hasHandler) +{ + Q_UNUSED(scriptId); + Q_UNUSED(exception); + Q_UNUSED(hasHandler); +// qDebug() << Q_FUNC_INFO << exception.toString() << hasHandler; +#if 0 //sometimes, we get exceptions that we should just ignore. + if (!hasHandler && state != StoppedState) + stopped(true, exception); +#endif +} + +/*! + \reimp +*/ +void QJSDebuggerAgent::exceptionCatch(qint64 scriptId, const QScriptValue &exception) +{ + Q_UNUSED(scriptId); + Q_UNUSED(exception); +} + +bool QJSDebuggerAgent::supportsExtension(Extension extension) const +{ + return extension == QScriptEngineAgent::DebuggerInvocationRequest; +} + +QVariant QJSDebuggerAgent::extension(Extension extension, const QVariant &argument) +{ + if (extension == QScriptEngineAgent::DebuggerInvocationRequest) { + d->stopped(); + return QVariant(); + } + return QScriptEngineAgent::extension(extension, argument); +} + +void QJSDebuggerAgentPrivate::stopped() +{ + bool becauseOfException = false; + const QScriptValue &exception = QScriptValue(); + + knownObjectIds.clear(); + state = StoppedState; + + emit q->stopped(becauseOfException, exception.toString()); + + loop.exec(QEventLoop::ExcludeUserInputEvents); +} + +void QJSDebuggerAgentPrivate::continueExec() +{ + loop.quit(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/debugger/qjsdebuggeragent_p.h b/src/declarative/debugger/qjsdebuggeragent_p.h new file mode 100644 index 0000000..ce5a044 --- /dev/null +++ b/src/declarative/debugger/qjsdebuggeragent_p.h @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QJSDEBUGGERAGENT_P_H +#define QJSDEBUGGERAGENT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE +class QScriptValue; +class QDeclarativeEngine; +QT_END_NAMESPACE + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QJSDebuggerAgentPrivate; + +enum JSDebuggerState +{ + NoState, + SteppingIntoState, + SteppingOverState, + SteppingOutState, + StoppedState +}; + +struct JSAgentWatchData +{ + QByteArray exp; + QByteArray name; + QByteArray value; + QByteArray type; + bool hasChildren; + quint64 objectId; +}; + +inline QDataStream &operator<<(QDataStream &s, const JSAgentWatchData &data) +{ + return s << data.exp << data.name << data.value + << data.type << data.hasChildren << data.objectId; +} + +struct JSAgentStackData +{ + QByteArray functionName; + QByteArray fileUrl; + qint32 lineNumber; +}; + +inline QDataStream &operator<<(QDataStream &s, const JSAgentStackData &data) +{ + return s << data.functionName << data.fileUrl << data.lineNumber; +} + +struct JSAgentBreakpointData +{ + QByteArray functionName; + QByteArray fileUrl; + qint32 lineNumber; +}; + +typedef QSet JSAgentBreakpoints; + +inline QDataStream &operator<<(QDataStream &s, const JSAgentBreakpointData &data) +{ + return s << data.functionName << data.fileUrl << data.lineNumber; +} + +inline QDataStream &operator>>(QDataStream &s, JSAgentBreakpointData &data) +{ + return s >> data.functionName >> data.fileUrl >> data.lineNumber; +} + +inline bool operator==(const JSAgentBreakpointData &b1, const JSAgentBreakpointData &b2) +{ + return b1.lineNumber == b2.lineNumber && b1.fileUrl == b2.fileUrl; +} + +inline uint qHash(const JSAgentBreakpointData &b) +{ + return b.lineNumber ^ qHash(b.fileUrl); +} + + +class QJSDebuggerAgent : public QObject, public QScriptEngineAgent +{ + Q_OBJECT + +public: + QJSDebuggerAgent(QScriptEngine *engine, QObject *parent = 0); + QJSDebuggerAgent(QDeclarativeEngine *engine, QObject *parent = 0); + ~QJSDebuggerAgent(); + + void setBreakpoints(const JSAgentBreakpoints &); + void setWatchExpressions(const QStringList &); + + void stepOver(); + void stepInto(); + void stepOut(); + void continueExecution(); + + JSAgentWatchData executeExpression(const QString &expr); + QList expandObjectById(quint64 objectId); + QList locals(); + QList localsAtFrame(int frameId); + QList backtrace(); + QList watches(); + void setProperty(qint64 objectId, + const QString &property, + const QString &value); + + // reimplemented + void scriptLoad(qint64 id, const QString &program, + const QString &fileName, int baseLineNumber); + void scriptUnload(qint64 id); + + void contextPush(); + void contextPop(); + + void functionEntry(qint64 scriptId); + void functionExit(qint64 scriptId, + const QScriptValue &returnValue); + + void positionChange(qint64 scriptId, + int lineNumber, int columnNumber); + + void exceptionThrow(qint64 scriptId, + const QScriptValue &exception, + bool hasHandler); + void exceptionCatch(qint64 scriptId, + const QScriptValue &exception); + + bool supportsExtension(Extension extension) const; + QVariant extension(Extension extension, + const QVariant &argument = QVariant()); + +Q_SIGNALS: + void stopped(bool becauseOfException, + const QString &exception); + +private: + friend class QJSDebuggerAgentPrivate; + QJSDebuggerAgentPrivate *d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QJSDEBUGGERAGENT_P_H diff --git a/src/declarative/debugger/qjsdebugservice.cpp b/src/declarative/debugger/qjsdebugservice.cpp new file mode 100644 index 0000000..f8cd095 --- /dev/null +++ b/src/declarative/debugger/qjsdebugservice.cpp @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qjsdebugservice_p.h" +#include "private/qjsdebuggeragent_p.h" + +#include +#include +#include +#include + +Q_GLOBAL_STATIC(QJSDebugService, serviceInstance) + +QJSDebugService::QJSDebugService(QObject *parent) + : QDeclarativeDebugService(QLatin1String("JSDebugger"), parent) + , m_agent(0) +{ +} + +QJSDebugService::~QJSDebugService() +{ + delete m_agent; +} + +QJSDebugService *QJSDebugService::instance() +{ + return serviceInstance(); +} + +void QJSDebugService::addEngine(QDeclarativeEngine *engine) +{ + Q_ASSERT(engine); + Q_ASSERT(!m_engines.contains(engine)); + + m_engines.append(engine); +} + +void QJSDebugService::removeEngine(QDeclarativeEngine *engine) +{ + Q_ASSERT(engine); + Q_ASSERT(m_engines.contains(engine)); + + m_engines.removeAll(engine); +} + +void QJSDebugService::statusChanged(Status status) +{ + if (status == Enabled && !m_engines.isEmpty() && !m_agent) { + // Multiple engines are currently unsupported + QDeclarativeEngine *engine = m_engines.first(); + m_agent = new QJSDebuggerAgent(engine, engine); + + connect(m_agent, SIGNAL(stopped(bool,QString)), + this, SLOT(executionStopped(bool,QString))); + + } else if (status != Enabled && m_agent) { + delete m_agent; + m_agent = 0; + } +} + +void QJSDebugService::messageReceived(const QByteArray &message) +{ + if (!m_agent) { + qWarning() << "QJSDebugService::messageReceived: No QJSDebuggerAgent available"; + return; + } + + QDataStream ds(message); + QByteArray command; + ds >> command; + if (command == "BREAKPOINTS") { + JSAgentBreakpoints breakpoints; + ds >> breakpoints; + m_agent->setBreakpoints(breakpoints); + + //qDebug() << "BREAKPOINTS"; + //foreach (const JSAgentBreakpointData &bp, breakpoints) + // qDebug() << "BREAKPOINT: " << bp.fileUrl << bp.lineNumber; + } else if (command == "WATCH_EXPRESSIONS") { + QStringList watchExpressions; + ds >> watchExpressions; + m_agent->setWatchExpressions(watchExpressions); + } else if (command == "STEPOVER") { + m_agent->stepOver(); + } else if (command == "STEPINTO" || command == "INTERRUPT") { + m_agent->stepInto(); + } else if (command == "STEPOUT") { + m_agent->stepOut(); + } else if (command == "CONTINUE") { + m_agent->continueExecution(); + } else if (command == "EXEC") { + QByteArray id; + QString expr; + ds >> id >> expr; + + JSAgentWatchData data = m_agent->executeExpression(expr); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("RESULT") << id << data; + sendMessage(reply); + } else if (command == "EXPAND") { + QByteArray requestId; + quint64 objectId; + ds >> requestId >> objectId; + + QList result = m_agent->expandObjectById(objectId); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("EXPANDED") << requestId << result; + sendMessage(reply); + } else if (command == "ACTIVATE_FRAME") { + int frameId; + ds >> frameId; + + QList locals = m_agent->localsAtFrame(frameId); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("LOCALS") << frameId << locals; + sendMessage(reply); + } else if (command == "SET_PROPERTY") { + QByteArray id; + qint64 objectId; + QString property; + QString value; + ds >> id >> objectId >> property >> value; + + m_agent->setProperty(objectId, property, value); + + //TODO: feedback + } else if (command == "PING") { + int ping; + ds >> ping; + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("PONG") << ping; + sendMessage(reply); + } else { + qDebug() << Q_FUNC_INFO << "Unknown command" << command; + } + + QDeclarativeDebugService::messageReceived(message); +} + +void QJSDebugService::executionStopped(bool becauseOfException, + const QString &exception) +{ + const QList backtrace = m_agent->backtrace(); + const QList watches = m_agent->watches(); + const QList locals = m_agent->locals(); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << QByteArray("STOPPED") << backtrace << watches << locals + << becauseOfException << exception; + sendMessage(reply); +} diff --git a/src/declarative/debugger/qjsdebugservice_p.h b/src/declarative/debugger/qjsdebugservice_p.h new file mode 100644 index 0000000..6839ca8 --- /dev/null +++ b/src/declarative/debugger/qjsdebugservice_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QJSDEBUGSERVICE_P_H +#define QJSDEBUGSERVICE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include "private/qdeclarativedebugservice_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeEngine; +class QJSDebuggerAgent; + +class QJSDebugService : public QDeclarativeDebugService +{ + Q_OBJECT + +public: + QJSDebugService(QObject *parent = 0); + ~QJSDebugService(); + + static QJSDebugService *instance(); + + void addEngine(QDeclarativeEngine *); + void removeEngine(QDeclarativeEngine *); + +protected: + void statusChanged(Status status); + void messageReceived(const QByteArray &); + +private Q_SLOTS: + void executionStopped(bool becauseOfException, + const QString &exception); + +private: + QList m_engines; + QPointer m_agent; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QJSDEBUGSERVICE_P_H diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 9fde18c..fb3e136 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -71,6 +71,7 @@ #include "private/qdeclarativenotifier_p.h" #include "private/qdeclarativedebugtrace_p.h" #include "private/qdeclarativeapplication_p.h" +#include "private/qjsdebugservice_p.h" #include #include @@ -583,6 +584,7 @@ void QDeclarativeEnginePrivate::init() QDeclarativeEngineDebugServer::isDebuggingEnabled()) { isDebugging = true; QDeclarativeEngineDebugServer::instance()->addEngine(q); + QJSDebugService::instance()->addEngine(q); } } @@ -645,8 +647,10 @@ QDeclarativeEngine::QDeclarativeEngine(QObject *parent) QDeclarativeEngine::~QDeclarativeEngine() { Q_D(QDeclarativeEngine); - if (d->isDebugging) + if (d->isDebugging) { QDeclarativeEngineDebugServer::instance()->remEngine(this); + QJSDebugService::instance()->removeEngine(this); + } } /*! \fn void QDeclarativeEngine::quit() diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 88b4e80..1777c88 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -95,7 +95,6 @@ class QDeclarativeImportDatabase; class QDeclarativeObjectScriptClass; class QDeclarativeTypeNameScriptClass; class QDeclarativeValueTypeScriptClass; -class QScriptEngineDebugger; class QNetworkReply; class QNetworkAccessManager; class QDeclarativeNetworkAccessManagerFactory; diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index e24f80f..628c82c 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -299,6 +300,8 @@ void QDeclarativeViewPrivate::init() q->viewport()->setAttribute(Qt::WA_OpaquePaintEvent); q->viewport()->setAttribute(Qt::WA_NoSystemBackground); #endif + + QDeclarativeObserverService::instance()->addView(q); } /*! @@ -306,6 +309,7 @@ void QDeclarativeViewPrivate::init() */ QDeclarativeView::~QDeclarativeView() { + QDeclarativeObserverService::instance()->removeView(this); } /*! \property QDeclarativeView::source @@ -558,7 +562,6 @@ void QDeclarativeView::continueExecute() emit statusChanged(status()); } - /*! \internal */ diff --git a/src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro b/src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro new file mode 100644 index 0000000..bccabcb --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/declarativeobserver.pro @@ -0,0 +1,53 @@ +TARGET = declarativeobserver +QT += declarative + +include(../../qpluginbase.pri) + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/qmltooling +QTDIR_build:REQUIRES += "contains(QT_CONFIG, declarative)" + +SOURCES += \ + qdeclarativeobserverplugin.cpp \ + qdeclarativeviewobserver.cpp \ + editor/abstractliveedittool.cpp \ + editor/liveselectiontool.cpp \ + editor/livelayeritem.cpp \ + editor/livesingleselectionmanipulator.cpp \ + editor/liverubberbandselectionmanipulator.cpp \ + editor/liveselectionrectangle.cpp \ + editor/liveselectionindicator.cpp \ + editor/boundingrecthighlighter.cpp \ + editor/subcomponenteditortool.cpp \ + editor/subcomponentmasklayeritem.cpp \ + editor/zoomtool.cpp \ + editor/colorpickertool.cpp \ + editor/qmltoolbar.cpp \ + editor/toolbarcolorbox.cpp + +HEADERS += \ + qdeclarativeobserverplugin.h \ + qdeclarativeobserverprotocol.h \ + qdeclarativeviewobserver_p.h \ + qdeclarativeviewobserver_p_p.h \ + qmlobserverconstants_p.h \ + editor/abstractliveedittool_p.h \ + editor/liveselectiontool_p.h \ + editor/livelayeritem_p.h \ + editor/livesingleselectionmanipulator_p.h \ + editor/liverubberbandselectionmanipulator_p.h \ + editor/liveselectionrectangle_p.h \ + editor/liveselectionindicator_p.h \ + editor/boundingrecthighlighter_p.h \ + editor/subcomponenteditortool_p.h \ + editor/subcomponentmasklayeritem_p.h \ + editor/zoomtool_p.h \ + editor/colorpickertool_p.h \ + editor/qmltoolbar_p.h \ + editor/toolbarcolorbox_p.h + +RESOURCES += editor/editor.qrc + +target.path += $$[QT_INSTALL_PLUGINS]/qmltooling +INSTALLS += target + +symbian:TARGET.UID3=0x20031E90 diff --git a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp new file mode 100644 index 0000000..9588311 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "abstractliveedittool_p.h" +#include "qdeclarativeviewobserver_p_p.h" + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewObserver *editorView) + : QObject(editorView), m_observer(editorView) +{ +} + + +AbstractLiveEditTool::~AbstractLiveEditTool() +{ +} + +QDeclarativeViewObserver *AbstractLiveEditTool::observer() const +{ + return m_observer; +} + +QDeclarativeView *AbstractLiveEditTool::view() const +{ + return m_observer->declarativeView(); +} + +QGraphicsScene* AbstractLiveEditTool::scene() const +{ + return view()->scene(); +} + +void AbstractLiveEditTool::updateSelectedItems() +{ + selectedItemsChanged(items()); +} + +QList AbstractLiveEditTool::items() const +{ + return observer()->selectedItems(); +} + +void AbstractLiveEditTool::enterContext(QGraphicsItem *itemToEnter) +{ + observer()->data->enterContext(itemToEnter); +} + +bool AbstractLiveEditTool::topItemIsMovable(const QList & itemList) +{ + QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList); + if (firstSelectableItem == 0) + return false; + if (toQDeclarativeItem(firstSelectableItem) != 0) + return true; + + return false; + +} + +bool AbstractLiveEditTool::topSelectedItemIsMovable(const QList &itemList) +{ + QList selectedItems = observer()->selectedItems(); + + foreach (QGraphicsItem *item, itemList) { + QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); + if (declarativeItem + && selectedItems.contains(declarativeItem) + /*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/) + return true; + } + + return false; + +} + +bool AbstractLiveEditTool::topItemIsResizeHandle(const QList &/*itemList*/) +{ + return false; +} + +QDeclarativeItem *AbstractLiveEditTool::toQDeclarativeItem(QGraphicsItem *item) +{ + return qobject_cast(item->toGraphicsObject()); +} + +QGraphicsItem *AbstractLiveEditTool::topMovableGraphicsItem(const QList &itemList) +{ + foreach (QGraphicsItem *item, itemList) { + if (item->flags().testFlag(QGraphicsItem::ItemIsMovable)) + return item; + } + return 0; +} + +QDeclarativeItem *AbstractLiveEditTool::topMovableDeclarativeItem(const QList + &itemList) +{ + foreach (QGraphicsItem *item, itemList) { + QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); + if (declarativeItem /*&& (declarativeItem->qmlItemNode().hasShowContent())*/) + return declarativeItem; + } + + return 0; +} + +QList AbstractLiveEditTool::toGraphicsObjectList(const QList + &itemList) +{ + QList gfxObjects; + foreach (QGraphicsItem *item, itemList) { + QGraphicsObject *obj = item->toGraphicsObject(); + if (obj) + gfxObjects << obj; + } + + return gfxObjects; +} + +QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item) +{ + QString className(QLatin1String("QGraphicsItem")); + QString objectStringId; + + QString constructedName; + + QGraphicsObject *gfxObject = item->toGraphicsObject(); + if (gfxObject) { + className = QLatin1String(gfxObject->metaObject()->className()); + + className.remove(QRegExp(QLatin1String("_QMLTYPE_\\d+"))); + className.remove(QRegExp(QLatin1String("_QML_\\d+"))); + if (className.startsWith(QLatin1String("QDeclarative"))) + className = className.remove(QLatin1String("QDeclarative")); + + QDeclarativeItem *declarativeItem = qobject_cast(gfxObject); + if (declarativeItem) { + objectStringId = m_observer->idStringForObject(declarativeItem); + } + + if (!objectStringId.isEmpty()) { + constructedName = objectStringId + QLatin1String(" (") + className + QLatin1Char(')'); + } else { + if (!gfxObject->objectName().isEmpty()) { + constructedName = gfxObject->objectName() + QLatin1String(" (") + className + QLatin1Char(')'); + } else { + constructedName = className; + } + } + } + + return constructedName; +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h new file mode 100644 index 0000000..1dbc323 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ABSTRACTLIVEEDITTOOL_H +#define ABSTRACTLIVEEDITTOOL_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QMouseEvent; +class QGraphicsItem; +class QDeclarativeItem; +class QKeyEvent; +class QGraphicsScene; +class QGraphicsObject; +class QWheelEvent; +class QDeclarativeView; +QT_END_NAMESPACE + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserver; + +class AbstractLiveEditTool : public QObject +{ + Q_OBJECT +public: + AbstractLiveEditTool(QDeclarativeViewObserver *observer); + + virtual ~AbstractLiveEditTool(); + + virtual void mousePressEvent(QMouseEvent *event) = 0; + virtual void mouseMoveEvent(QMouseEvent *event) = 0; + virtual void mouseReleaseEvent(QMouseEvent *event) = 0; + virtual void mouseDoubleClickEvent(QMouseEvent *event) = 0; + + virtual void hoverMoveEvent(QMouseEvent *event) = 0; + virtual void wheelEvent(QWheelEvent *event) = 0; + + virtual void keyPressEvent(QKeyEvent *event) = 0; + virtual void keyReleaseEvent(QKeyEvent *keyEvent) = 0; + virtual void itemsAboutToRemoved(const QList &itemList) = 0; + + virtual void clear() = 0; + + void updateSelectedItems(); + QList items() const; + + void enterContext(QGraphicsItem *itemToEnter); + + bool topItemIsMovable(const QList &itemList); + bool topItemIsResizeHandle(const QList &itemList); + bool topSelectedItemIsMovable(const QList &itemList); + + QString titleForItem(QGraphicsItem *item); + + static QList toGraphicsObjectList(const QList &itemList); + static QGraphicsItem* topMovableGraphicsItem(const QList &itemList); + static QDeclarativeItem* topMovableDeclarativeItem(const QList &itemList); + static QDeclarativeItem *toQDeclarativeItem(QGraphicsItem *item); + +protected: + virtual void selectedItemsChanged(const QList &objectList) = 0; + + QDeclarativeViewObserver *observer() const; + QDeclarativeView *view() const; + QGraphicsScene *scene() const; + +private: + QDeclarativeViewObserver *m_observer; + QList m_itemList; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // ABSTRACTLIVEEDITTOOL_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp b/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp new file mode 100644 index 0000000..98dbc4f --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter.cpp @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "boundingrecthighlighter_p.h" + +#include "../qdeclarativeviewobserver_p.h" +#include "../qmlobserverconstants_p.h" + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +const qreal AnimDelta = 0.025f; +const int AnimInterval = 30; +const int AnimFrames = 10; + +BoundingBox::BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem, + QObject *parent) + : QObject(parent), + highlightedObject(itemToHighlight), + highlightPolygon(0), + highlightPolygonEdge(0) +{ + highlightPolygon = new BoundingBoxPolygonItem(parentItem); + highlightPolygonEdge = new BoundingBoxPolygonItem(parentItem); + + highlightPolygon->setPen(QPen(QColor(0, 22, 159))); + highlightPolygonEdge->setPen(QPen(QColor(158, 199, 255))); + + highlightPolygon->setFlag(QGraphicsItem::ItemIsSelectable, false); + highlightPolygonEdge->setFlag(QGraphicsItem::ItemIsSelectable, false); +} + +BoundingBox::~BoundingBox() +{ + highlightedObject.clear(); +} + +BoundingBoxPolygonItem::BoundingBoxPolygonItem(QGraphicsItem *item) : QGraphicsPolygonItem(item) +{ + QPen pen; + pen.setColor(QColor(108, 141, 221)); + pen.setWidth(1); + setPen(pen); +} + +int BoundingBoxPolygonItem::type() const +{ + return Constants::EditorItemType; +} + +BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewObserver *view) : + LiveLayerItem(view->declarativeView()->scene()), + m_view(view), + m_animFrame(0) +{ + m_animTimer = new QTimer(this); + m_animTimer->setInterval(AnimInterval); + connect(m_animTimer, SIGNAL(timeout()), SLOT(animTimeout())); +} + +BoundingRectHighlighter::~BoundingRectHighlighter() +{ + +} + +void BoundingRectHighlighter::animTimeout() +{ + ++m_animFrame; + if (m_animFrame == AnimFrames) { + m_animTimer->stop(); + } + + qreal alpha = m_animFrame / float(AnimFrames); + + foreach (BoundingBox *box, m_boxes) { + box->highlightPolygonEdge->setOpacity(alpha); + } +} + +void BoundingRectHighlighter::clear() +{ + if (m_boxes.length()) { + m_animTimer->stop(); + + foreach (BoundingBox *box, m_boxes) { + freeBoundingBox(box); + } + } +} + +BoundingBox *BoundingRectHighlighter::boxFor(QGraphicsObject *item) const +{ + foreach (BoundingBox *box, m_boxes) { + if (box->highlightedObject.data() == item) { + return box; + } + } + return 0; +} + +void BoundingRectHighlighter::highlight(QList items) +{ + if (items.isEmpty()) + return; + + bool animate = false; + + QList newBoxes; + foreach (QGraphicsObject *itemToHighlight, items) { + BoundingBox *box = boxFor(itemToHighlight); + if (!box) { + box = createBoundingBox(itemToHighlight); + animate = true; + } + + newBoxes << box; + } + qSort(newBoxes); + + if (newBoxes != m_boxes) { + clear(); + m_boxes << newBoxes; + } + + highlightAll(animate); +} + +void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight) +{ + if (!itemToHighlight) + return; + + bool animate = false; + + BoundingBox *box = boxFor(itemToHighlight); + if (!box) { + box = createBoundingBox(itemToHighlight); + m_boxes << box; + animate = true; + qSort(m_boxes); + } + + highlightAll(animate); +} + +BoundingBox *BoundingRectHighlighter::createBoundingBox(QGraphicsObject *itemToHighlight) +{ + if (!m_freeBoxes.isEmpty()) { + BoundingBox *box = m_freeBoxes.last(); + if (box->highlightedObject.isNull()) { + box->highlightedObject = itemToHighlight; + box->highlightPolygon->show(); + box->highlightPolygonEdge->show(); + m_freeBoxes.removeLast(); + return box; + } + } + + BoundingBox *box = new BoundingBox(itemToHighlight, this, this); + + connect(itemToHighlight, SIGNAL(xChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(yChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(widthChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(heightChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(rotationChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(destroyed(QObject*)), this, SLOT(itemDestroyed(QObject*))); + + return box; +} + +void BoundingRectHighlighter::removeBoundingBox(BoundingBox *box) +{ + delete box; + box = 0; +} + +void BoundingRectHighlighter::freeBoundingBox(BoundingBox *box) +{ + if (!box->highlightedObject.isNull()) { + disconnect(box->highlightedObject.data(), SIGNAL(xChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(yChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(widthChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(heightChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(rotationChanged()), this, SLOT(refresh())); + } + + box->highlightedObject.clear(); + box->highlightPolygon->hide(); + box->highlightPolygonEdge->hide(); + m_boxes.removeOne(box); + m_freeBoxes << box; +} + +void BoundingRectHighlighter::itemDestroyed(QObject *obj) +{ + foreach (BoundingBox *box, m_boxes) { + if (box->highlightedObject.data() == obj) { + freeBoundingBox(box); + break; + } + } +} + +void BoundingRectHighlighter::highlightAll(bool animate) +{ + foreach (BoundingBox *box, m_boxes) { + if (box && box->highlightedObject.isNull()) { + // clear all highlights + clear(); + return; + } + QGraphicsObject *item = box->highlightedObject.data(); + QRectF itemAndChildRect = item->boundingRect() | item->childrenBoundingRect(); + + QPolygonF boundingRectInSceneSpace(item->mapToScene(itemAndChildRect)); + QPolygonF boundingRectInLayerItemSpace = mapFromScene(boundingRectInSceneSpace); + QRectF bboxRect + = m_view->adjustToScreenBoundaries(boundingRectInLayerItemSpace.boundingRect()); + QRectF edgeRect = bboxRect; + edgeRect.adjust(-1, -1, 1, 1); + + box->highlightPolygon->setPolygon(QPolygonF(bboxRect)); + box->highlightPolygonEdge->setPolygon(QPolygonF(edgeRect)); + + if (animate) + box->highlightPolygonEdge->setOpacity(0); + } + + if (animate) { + m_animFrame = 0; + m_animTimer->start(); + } +} + +void BoundingRectHighlighter::refresh() +{ + if (!m_boxes.isEmpty()) + highlightAll(true); +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter_p.h b/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter_p.h new file mode 100644 index 0000000..c1beed8 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/boundingrecthighlighter_p.h @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BOUNDINGRECTHIGHLIGHTER_H +#define BOUNDINGRECTHIGHLIGHTER_H + +#include "livelayeritem_p.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) +QT_FORWARD_DECLARE_CLASS(QPainter) +QT_FORWARD_DECLARE_CLASS(QWidget) +QT_FORWARD_DECLARE_CLASS(QStyleOptionGraphicsItem) +QT_FORWARD_DECLARE_CLASS(QTimer) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserver; +class BoundingBox; + +class BoundingRectHighlighter : public LiveLayerItem +{ + Q_OBJECT +public: + explicit BoundingRectHighlighter(QDeclarativeViewObserver *view); + ~BoundingRectHighlighter(); + void clear(); + void highlight(QList items); + void highlight(QGraphicsObject* item); + +private slots: + void refresh(); + void animTimeout(); + void itemDestroyed(QObject *); + +private: + BoundingBox *boxFor(QGraphicsObject *item) const; + void highlightAll(bool animate); + BoundingBox *createBoundingBox(QGraphicsObject *itemToHighlight); + void removeBoundingBox(BoundingBox *box); + void freeBoundingBox(BoundingBox *box); + +private: + Q_DISABLE_COPY(BoundingRectHighlighter) + + QDeclarativeViewObserver *m_view; + QList m_boxes; + QList m_freeBoxes; + QTimer *m_animTimer; + qreal m_animScale; + int m_animFrame; + +}; + +class BoundingBox : public QObject +{ + Q_OBJECT +public: + explicit BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem, + QObject *parent = 0); + ~BoundingBox(); + QWeakPointer highlightedObject; + QGraphicsPolygonItem *highlightPolygon; + QGraphicsPolygonItem *highlightPolygonEdge; + +private: + Q_DISABLE_COPY(BoundingBox) + +}; + +class BoundingBoxPolygonItem : public QGraphicsPolygonItem +{ +public: + explicit BoundingBoxPolygonItem(QGraphicsItem *item); + int type() const; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // BOUNDINGRECTHIGHLIGHTER_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/colorpickertool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/colorpickertool.cpp new file mode 100644 index 0000000..a71e408 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/colorpickertool.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "colorpickertool_p.h" + +#include "../qdeclarativeviewobserver_p.h" + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +ColorPickerTool::ColorPickerTool(QDeclarativeViewObserver *view) : + AbstractLiveEditTool(view) +{ + m_selectedColor.setRgb(0,0,0); +} + +ColorPickerTool::~ColorPickerTool() +{ + +} + +void ColorPickerTool::mousePressEvent(QMouseEvent * /*event*/) +{ +} + +void ColorPickerTool::mouseMoveEvent(QMouseEvent *event) +{ + pickColor(event->pos()); +} + +void ColorPickerTool::mouseReleaseEvent(QMouseEvent *event) +{ + pickColor(event->pos()); +} + +void ColorPickerTool::mouseDoubleClickEvent(QMouseEvent * /*event*/) +{ +} + + +void ColorPickerTool::hoverMoveEvent(QMouseEvent * /*event*/) +{ +} + +void ColorPickerTool::keyPressEvent(QKeyEvent * /*event*/) +{ +} + +void ColorPickerTool::keyReleaseEvent(QKeyEvent * /*keyEvent*/) +{ +} +void ColorPickerTool::wheelEvent(QWheelEvent * /*event*/) +{ +} + +void ColorPickerTool::itemsAboutToRemoved(const QList &/*itemList*/) +{ +} + +void ColorPickerTool::clear() +{ + view()->setCursor(Qt::CrossCursor); +} + +void ColorPickerTool::selectedItemsChanged(const QList &/*itemList*/) +{ +} + +void ColorPickerTool::pickColor(const QPoint &pos) +{ + QRgb fillColor = view()->backgroundBrush().color().rgb(); + if (view()->backgroundBrush().style() == Qt::NoBrush) + fillColor = view()->palette().color(QPalette::Base).rgb(); + + QRectF target(0,0, 1, 1); + QRect source(pos.x(), pos.y(), 1, 1); + QImage img(1, 1, QImage::Format_ARGB32); + img.fill(fillColor); + QPainter painter(&img); + view()->render(&painter, target, source); + m_selectedColor = QColor::fromRgb(img.pixel(0, 0)); + + emit selectedColorChanged(m_selectedColor); +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/colorpickertool_p.h b/src/plugins/qmltooling/declarativeobserver/editor/colorpickertool_p.h new file mode 100644 index 0000000..86a8893 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/colorpickertool_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLORPICKERTOOL_H +#define COLORPICKERTOOL_H + +#include "abstractliveedittool_p.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QPoint) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class ColorPickerTool : public AbstractLiveEditTool +{ + Q_OBJECT +public: + explicit ColorPickerTool(QDeclarativeViewObserver *view); + + virtual ~ColorPickerTool(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + + void hoverMoveEvent(QMouseEvent *event); + + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *keyEvent); + + void wheelEvent(QWheelEvent *event); + + void itemsAboutToRemoved(const QList &itemList); + + void clear(); + +signals: + void selectedColorChanged(const QColor &color); + +protected: + + void selectedItemsChanged(const QList &itemList); + +private: + void pickColor(const QPoint &pos); + +private: + QColor m_selectedColor; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // COLORPICKERTOOL_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/editor.qrc b/src/plugins/qmltooling/declarativeobserver/editor/editor.qrc new file mode 100644 index 0000000..77744d5 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/editor.qrc @@ -0,0 +1,24 @@ + + + images/resize_handle.png + images/select.png + images/select-marquee.png + images/color-picker.png + images/play.png + images/pause.png + images/from-qml.png + images/to-qml.png + images/color-picker-hicontrast.png + images/zoom.png + images/color-picker-24.png + images/from-qml-24.png + images/pause-24.png + images/play-24.png + images/to-qml-24.png + images/zoom-24.png + images/select-24.png + images/select-marquee-24.png + images/observermode.png + images/observermode-24.png + + diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-24.png new file mode 100644 index 0000000..cff4721 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-hicontrast.png b/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-hicontrast.png new file mode 100644 index 0000000..b953d08 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker-hicontrast.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker.png b/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker.png new file mode 100644 index 0000000..026c31b Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/color-picker.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/from-qml-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/from-qml-24.png new file mode 100644 index 0000000..0ad21f3 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/from-qml-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/from-qml.png b/src/plugins/qmltooling/declarativeobserver/editor/images/from-qml.png new file mode 100644 index 0000000..666382c Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/from-qml.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/observermode-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/observermode-24.png new file mode 100644 index 0000000..5e74d86 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/observermode-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/observermode.png b/src/plugins/qmltooling/declarativeobserver/editor/images/observermode.png new file mode 100644 index 0000000..daed21c Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/observermode.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/pause-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/pause-24.png new file mode 100644 index 0000000..d9a2f6f Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/pause-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/pause.png b/src/plugins/qmltooling/declarativeobserver/editor/images/pause.png new file mode 100644 index 0000000..114d89b Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/pause.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/play-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/play-24.png new file mode 100644 index 0000000..e2b9fbc Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/play-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/play.png b/src/plugins/qmltooling/declarativeobserver/editor/images/play.png new file mode 100644 index 0000000..011598a Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/play.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/reload.png b/src/plugins/qmltooling/declarativeobserver/editor/images/reload.png new file mode 100644 index 0000000..7042bec Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/reload.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/resize_handle.png b/src/plugins/qmltooling/declarativeobserver/editor/images/resize_handle.png new file mode 100644 index 0000000..2934f25 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/resize_handle.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/select-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/select-24.png new file mode 100644 index 0000000..5388a9d Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/select-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee-24.png new file mode 100644 index 0000000..0111dda Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee.png b/src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee.png new file mode 100644 index 0000000..92fe40d Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/select-marquee.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/select.png b/src/plugins/qmltooling/declarativeobserver/editor/images/select.png new file mode 100644 index 0000000..6722855 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/select.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/to-qml-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/to-qml-24.png new file mode 100644 index 0000000..b72450d Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/to-qml-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/to-qml.png b/src/plugins/qmltooling/declarativeobserver/editor/images/to-qml.png new file mode 100644 index 0000000..2ab951f Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/to-qml.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/zoom-24.png b/src/plugins/qmltooling/declarativeobserver/editor/images/zoom-24.png new file mode 100644 index 0000000..0346200 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/zoom-24.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/images/zoom.png b/src/plugins/qmltooling/declarativeobserver/editor/images/zoom.png new file mode 100644 index 0000000..17f0da6 Binary files /dev/null and b/src/plugins/qmltooling/declarativeobserver/editor/images/zoom.png differ diff --git a/src/plugins/qmltooling/declarativeobserver/editor/livelayeritem.cpp b/src/plugins/qmltooling/declarativeobserver/editor/livelayeritem.cpp new file mode 100644 index 0000000..7b508a4 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/livelayeritem.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "livelayeritem_p.h" + +#include "../qmlobserverconstants_p.h" + +#include + +QT_BEGIN_NAMESPACE + +LiveLayerItem::LiveLayerItem(QGraphicsScene* scene) + : QGraphicsObject() +{ + scene->addItem(this); + setZValue(1); + setFlag(QGraphicsItem::ItemIsMovable, false); +} + +LiveLayerItem::~LiveLayerItem() +{ +} + +void LiveLayerItem::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem * /*option*/, + QWidget * /*widget*/) +{ +} + +int LiveLayerItem::type() const +{ + return Constants::EditorItemType; +} + +QRectF LiveLayerItem::boundingRect() const +{ + return childrenBoundingRect(); +} + +QList LiveLayerItem::findAllChildItems() const +{ + return findAllChildItems(this); +} + +QList LiveLayerItem::findAllChildItems(const QGraphicsItem *item) const +{ + QList itemList(item->childItems()); + + foreach (QGraphicsItem *childItem, item->childItems()) + itemList += findAllChildItems(childItem); + + return itemList; +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/livelayeritem_p.h b/src/plugins/qmltooling/declarativeobserver/editor/livelayeritem_p.h new file mode 100644 index 0000000..242e365 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/livelayeritem_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LIVELAYERITEM_H +#define LIVELAYERITEM_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class LiveLayerItem : public QGraphicsObject +{ +public: + LiveLayerItem(QGraphicsScene *scene); + ~LiveLayerItem(); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = 0); + QRectF boundingRect() const; + int type() const; + + QList findAllChildItems() const; + +protected: + QList findAllChildItems(const QGraphicsItem *item) const; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // LIVELAYERITEM_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator.cpp b/src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator.cpp new file mode 100644 index 0000000..6c37ba5 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "liverubberbandselectionmanipulator_p.h" + +#include "../qdeclarativeviewobserver_p_p.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +LiveRubberBandSelectionManipulator::LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, + QDeclarativeViewObserver *editorView) + : m_selectionRectangleElement(layerItem), + m_editorView(editorView), + m_beginFormEditorItem(0), + m_isActive(false) +{ + m_selectionRectangleElement.hide(); +} + +void LiveRubberBandSelectionManipulator::clear() +{ + m_selectionRectangleElement.clear(); + m_isActive = false; + m_beginPoint = QPointF(); + m_itemList.clear(); + m_oldSelectionList.clear(); +} + +QGraphicsItem *LiveRubberBandSelectionManipulator::topFormEditorItem(const QList + &itemList) +{ + if (itemList.isEmpty()) + return 0; + + return itemList.first(); +} + +void LiveRubberBandSelectionManipulator::begin(const QPointF &beginPoint) +{ + m_beginPoint = beginPoint; + m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint); + m_selectionRectangleElement.show(); + m_isActive = true; + QDeclarativeViewObserverPrivate *observerPrivate + = QDeclarativeViewObserverPrivate::get(m_editorView); + m_beginFormEditorItem = topFormEditorItem(observerPrivate->selectableItems(beginPoint)); + m_oldSelectionList = m_editorView->selectedItems(); +} + +void LiveRubberBandSelectionManipulator::update(const QPointF &updatePoint) +{ + m_selectionRectangleElement.setRect(m_beginPoint, updatePoint); +} + +void LiveRubberBandSelectionManipulator::end() +{ + m_oldSelectionList.clear(); + m_selectionRectangleElement.hide(); + m_isActive = false; +} + +void LiveRubberBandSelectionManipulator::select(SelectionType selectionType) +{ + QDeclarativeViewObserverPrivate *observerPrivate + = QDeclarativeViewObserverPrivate::get(m_editorView); + QList itemList + = observerPrivate->selectableItems(m_selectionRectangleElement.rect(), + Qt::IntersectsItemShape); + QList newSelectionList; + + foreach (QGraphicsItem* item, itemList) { + if (item + && item->parentItem() + && !newSelectionList.contains(item) + //&& m_beginFormEditorItem->childItems().contains(item) // TODO activate this test + ) + { + newSelectionList.append(item); + } + } + + if (newSelectionList.isEmpty() && m_beginFormEditorItem) + newSelectionList.append(m_beginFormEditorItem); + + QList resultList; + + switch (selectionType) { + case AddToSelection: { + resultList.append(m_oldSelectionList); + resultList.append(newSelectionList); + } + break; + case ReplaceSelection: { + resultList.append(newSelectionList); + } + break; + case RemoveFromSelection: { + QSet oldSelectionSet(m_oldSelectionList.toSet()); + QSet newSelectionSet(newSelectionList.toSet()); + resultList.append(oldSelectionSet.subtract(newSelectionSet).toList()); + } + } + + m_editorView->setSelectedItems(resultList); +} + + +void LiveRubberBandSelectionManipulator::setItems(const QList &itemList) +{ + m_itemList = itemList; +} + +QPointF LiveRubberBandSelectionManipulator::beginPoint() const +{ + return m_beginPoint; +} + +bool LiveRubberBandSelectionManipulator::isActive() const +{ + return m_isActive; +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator_p.h b/src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator_p.h new file mode 100644 index 0000000..8d15288 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liverubberbandselectionmanipulator_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RUBBERBANDSELECTIONMANIPULATOR_H +#define RUBBERBANDSELECTIONMANIPULATOR_H + +#include "liveselectionrectangle_p.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserver; + +class LiveRubberBandSelectionManipulator +{ +public: + enum SelectionType { + ReplaceSelection, + AddToSelection, + RemoveFromSelection + }; + + LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, + QDeclarativeViewObserver *editorView); + + void setItems(const QList &itemList); + + void begin(const QPointF& beginPoint); + void update(const QPointF& updatePoint); + void end(); + + void clear(); + + void select(SelectionType selectionType); + + QPointF beginPoint() const; + + bool isActive() const; + +protected: + QGraphicsItem *topFormEditorItem(const QList &itemList); + +private: + QList m_itemList; + QList m_oldSelectionList; + LiveSelectionRectangle m_selectionRectangleElement; + QPointF m_beginPoint; + QDeclarativeViewObserver *m_editorView; + QGraphicsItem *m_beginFormEditorItem; + bool m_isActive; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // RUBBERBANDSELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp new file mode 100644 index 0000000..96e9dbf --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "liveselectionindicator_p.h" + +#include "../qdeclarativeviewobserver_p_p.h" +#include "../qmlobserverconstants_p.h" + +#include + +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewObserver *editorView, + QGraphicsObject *layerItem) + : m_layerItem(layerItem), m_view(editorView) +{ +} + +LiveSelectionIndicator::~LiveSelectionIndicator() +{ + clear(); +} + +void LiveSelectionIndicator::show() +{ + foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash.values()) + item->show(); +} + +void LiveSelectionIndicator::hide() +{ + foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash.values()) + item->hide(); +} + +void LiveSelectionIndicator::clear() +{ + if (!m_layerItem.isNull()) { + QHashIterator iter(m_indicatorShapeHash); + while (iter.hasNext()) { + iter.next(); + m_layerItem.data()->scene()->removeItem(iter.value()); + delete iter.value(); + } + } + + m_indicatorShapeHash.clear(); + +} + +QPolygonF LiveSelectionIndicator::addBoundingRectToPolygon(QGraphicsItem *item, QPolygonF &polygon) +{ + // ### remove this if statement when QTBUG-12172 gets fixed + if (item->boundingRect() != QRectF(0,0,0,0)) { + QPolygonF bounding = item->mapToScene(item->boundingRect()); + if (bounding.isClosed()) //avoid crashes if there is an infinite scale. + polygon = polygon.united(bounding); + } + + foreach (QGraphicsItem *child, item->childItems()) { + if (!QDeclarativeViewObserverPrivate::get(m_view)->isEditorItem(child)) + addBoundingRectToPolygon(child, polygon); + } + return polygon; +} + +void LiveSelectionIndicator::setItems(const QList > &itemList) +{ + clear(); + + // set selections to also all children if they are not editor items + + foreach (const QWeakPointer &object, itemList) { + if (object.isNull()) + continue; + + QGraphicsItem *item = object.data(); + + QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem + = new QGraphicsPolygonItem(m_layerItem.data()); + if (!m_indicatorShapeHash.contains(item)) { + m_indicatorShapeHash.insert(item, newSelectionIndicatorGraphicsItem); + + QPolygonF boundingShapeInSceneSpace; + addBoundingRectToPolygon(item, boundingShapeInSceneSpace); + + QRectF boundingRect + = m_view->adjustToScreenBoundaries(boundingShapeInSceneSpace.boundingRect()); + QPolygonF boundingRectInLayerItemSpace = m_layerItem.data()->mapFromScene(boundingRect); + + QPen pen; + pen.setColor(QColor(108, 141, 221)); + newSelectionIndicatorGraphicsItem->setData(Constants::EditorItemDataKey, + QVariant(true)); + newSelectionIndicatorGraphicsItem->setFlag(QGraphicsItem::ItemIsSelectable, false); + newSelectionIndicatorGraphicsItem->setPolygon(boundingRectInLayerItemSpace); + newSelectionIndicatorGraphicsItem->setPen(pen); + } + } +} + +QT_END_NAMESPACE + diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h new file mode 100644 index 0000000..da95955 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionindicator_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LIVESELECTIONINDICATOR_H +#define LIVESELECTIONINDICATOR_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QGraphicsObject; +class QGraphicsPolygonItem; +class QGraphicsItem; +class QPolygonF; +QT_END_NAMESPACE + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserver; + +class LiveSelectionIndicator +{ +public: + LiveSelectionIndicator(QDeclarativeViewObserver* editorView, QGraphicsObject *layerItem); + ~LiveSelectionIndicator(); + + void show(); + void hide(); + + void clear(); + + void setItems(const QList > &itemList); + +private: + QPolygonF addBoundingRectToPolygon(QGraphicsItem *item, QPolygonF &polygon); + +private: + QHash m_indicatorShapeHash; + QWeakPointer m_layerItem; + QDeclarativeViewObserver *m_view; + +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // LIVESELECTIONINDICATOR_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle.cpp b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle.cpp new file mode 100644 index 0000000..2a1d393 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "liveselectionrectangle_p.h" + +#include "../qmlobserverconstants_p.h" + +#include +#include +#include +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +class SelectionRectShape : public QGraphicsRectItem +{ +public: + SelectionRectShape(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} + int type() const { return Constants::EditorItemType; } +}; + +LiveSelectionRectangle::LiveSelectionRectangle(QGraphicsObject *layerItem) + : m_controlShape(new SelectionRectShape(layerItem)), + m_layerItem(layerItem) +{ + m_controlShape->setPen(QPen(Qt::black)); + m_controlShape->setBrush(QColor(128, 128, 128, 50)); +} + +LiveSelectionRectangle::~LiveSelectionRectangle() +{ + if (m_layerItem) + m_layerItem.data()->scene()->removeItem(m_controlShape); +} + +void LiveSelectionRectangle::clear() +{ + hide(); +} +void LiveSelectionRectangle::show() +{ + m_controlShape->show(); +} + +void LiveSelectionRectangle::hide() +{ + m_controlShape->hide(); +} + +QRectF LiveSelectionRectangle::rect() const +{ + return m_controlShape->mapFromScene(m_controlShape->rect()).boundingRect(); +} + +void LiveSelectionRectangle::setRect(const QPointF &firstPoint, + const QPointF &secondPoint) +{ + double firstX = std::floor(firstPoint.x()) + 0.5; + double firstY = std::floor(firstPoint.y()) + 0.5; + double secondX = std::floor(secondPoint.x()) + 0.5; + double secondY = std::floor(secondPoint.y()) + 0.5; + QPointF topLeftPoint(firstX < secondX ? firstX : secondX, + firstY < secondY ? firstY : secondY); + QPointF bottomRightPoint(firstX > secondX ? firstX : secondX, + firstY > secondY ? firstY : secondY); + + QRectF rect(topLeftPoint, bottomRightPoint); + m_controlShape->setRect(rect); +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle_p.h b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle_p.h new file mode 100644 index 0000000..d1bed72 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectionrectangle_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LIVESELECTIONRECTANGLE_H +#define LIVESELECTIONRECTANGLE_H + +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsObject) +QT_FORWARD_DECLARE_CLASS(QGraphicsRectItem) +QT_FORWARD_DECLARE_CLASS(QPointF) +QT_FORWARD_DECLARE_CLASS(QRectF) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class LiveSelectionRectangle +{ +public: + LiveSelectionRectangle(QGraphicsObject *layerItem); + ~LiveSelectionRectangle(); + + void show(); + void hide(); + + void clear(); + + void setRect(const QPointF &firstPoint, + const QPointF &secondPoint); + + QRectF rect() const; + +private: + QGraphicsRectItem *m_controlShape; + QWeakPointer m_layerItem; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // LIVESELECTIONRECTANGLE_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp new file mode 100644 index 0000000..d85926e --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool.cpp @@ -0,0 +1,442 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "liveselectiontool_p.h" +#include "livelayeritem_p.h" + +#include "../qdeclarativeviewobserver_p_p.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +LiveSelectionTool::LiveSelectionTool(QDeclarativeViewObserver *editorView) : + AbstractLiveEditTool(editorView), + m_rubberbandSelectionMode(false), + m_rubberbandSelectionManipulator( + QDeclarativeViewObserverPrivate::get(editorView)->manipulatorLayer, editorView), + m_singleSelectionManipulator(editorView), + m_selectionIndicator(editorView, + QDeclarativeViewObserverPrivate::get(editorView)->manipulatorLayer), + //m_resizeIndicator(editorView->manipulatorLayer()), + m_selectOnlyContentItems(true) +{ + +} + +LiveSelectionTool::~LiveSelectionTool() +{ +} + +void LiveSelectionTool::setRubberbandSelectionMode(bool value) +{ + m_rubberbandSelectionMode = value; +} + +LiveSingleSelectionManipulator::SelectionType LiveSelectionTool::getSelectionType(Qt::KeyboardModifiers + modifiers) +{ + LiveSingleSelectionManipulator::SelectionType selectionType + = LiveSingleSelectionManipulator::ReplaceSelection; + if (modifiers.testFlag(Qt::ControlModifier)) { + selectionType = LiveSingleSelectionManipulator::RemoveFromSelection; + } else if (modifiers.testFlag(Qt::ShiftModifier)) { + selectionType = LiveSingleSelectionManipulator::AddToSelection; + } + return selectionType; +} + +bool LiveSelectionTool::alreadySelected(const QList &itemList) const +{ + QDeclarativeViewObserverPrivate *observerPrivate + = QDeclarativeViewObserverPrivate::get(observer()); + const QList selectedItems = observerPrivate->selectedItems(); + + if (selectedItems.isEmpty()) + return false; + + foreach (QGraphicsItem *item, itemList) + if (selectedItems.contains(item)) + return true; + + return false; +} + +void LiveSelectionTool::mousePressEvent(QMouseEvent *event) +{ + QDeclarativeViewObserverPrivate *observerPrivate + = QDeclarativeViewObserverPrivate::get(observer()); + QList itemList = observerPrivate->selectableItems(event->pos()); + LiveSingleSelectionManipulator::SelectionType selectionType = getSelectionType(event->modifiers()); + + if (event->buttons() & Qt::LeftButton) { + m_mousePressTimer.start(); + + if (m_rubberbandSelectionMode) { + m_rubberbandSelectionManipulator.begin(event->pos()); + } else { + m_singleSelectionManipulator.begin(event->pos()); + m_singleSelectionManipulator.select(selectionType, m_selectOnlyContentItems); + } + } else if (event->buttons() & Qt::RightButton) { + createContextMenu(itemList, event->globalPos()); + } +} + +void LiveSelectionTool::createContextMenu(QList itemList, QPoint globalPos) +{ + if (!QDeclarativeViewObserverPrivate::get(observer())->mouseInsideContextItem()) + return; + + QMenu contextMenu; + connect(&contextMenu, SIGNAL(hovered(QAction*)), + this, SLOT(contextMenuElementHovered(QAction*))); + + m_contextMenuItemList = itemList; + + contextMenu.addAction(tr("Items")); + contextMenu.addSeparator(); + int shortcutKey = Qt::Key_1; + bool addKeySequence = true; + int i = 0; + + foreach (QGraphicsItem * const item, itemList) { + QString itemTitle = titleForItem(item); + QAction *elementAction = contextMenu.addAction(itemTitle, this, + SLOT(contextMenuElementSelected())); + + if (observer()->selectedItems().contains(item)) { + QFont boldFont = elementAction->font(); + boldFont.setBold(true); + elementAction->setFont(boldFont); + } + + elementAction->setData(i); + if (addKeySequence) + elementAction->setShortcut(QKeySequence(shortcutKey)); + + shortcutKey++; + if (shortcutKey > Qt::Key_9) + addKeySequence = false; + + ++i; + } + // add root item separately + // QString itemTitle = QString(tr("%1")).arg(titleForItem(view()->currentRootItem())); + // contextMenu.addAction(itemTitle, this, SLOT(contextMenuElementSelected())); + // m_contextMenuItemList.append(view()->currentRootItem()); + + contextMenu.exec(globalPos); + m_contextMenuItemList.clear(); +} + +void LiveSelectionTool::contextMenuElementSelected() +{ + QAction *senderAction = static_cast(sender()); + int itemListIndex = senderAction->data().toInt(); + if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { + + QPointF updatePt(0, 0); + QGraphicsItem *item = m_contextMenuItemList.at(itemListIndex); + m_singleSelectionManipulator.begin(updatePt); + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, + QList() << item, + false); + m_singleSelectionManipulator.end(updatePt); + enterContext(item); + } +} + +void LiveSelectionTool::contextMenuElementHovered(QAction *action) +{ + int itemListIndex = action->data().toInt(); + if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { + QGraphicsObject *item = m_contextMenuItemList.at(itemListIndex)->toGraphicsObject(); + QDeclarativeViewObserverPrivate::get(observer())->highlight(item); + } +} + +void LiveSelectionTool::mouseMoveEvent(QMouseEvent *event) +{ + if (m_singleSelectionManipulator.isActive()) { + QPointF mouseMovementVector = m_singleSelectionManipulator.beginPoint() - event->pos(); + + if ((mouseMovementVector.toPoint().manhattanLength() > Constants::DragStartDistance) + && (m_mousePressTimer.elapsed() > Constants::DragStartTime)) + { + m_singleSelectionManipulator.end(event->pos()); + //view()->changeToMoveTool(m_singleSelectionManipulator.beginPoint()); + return; + } + } else if (m_rubberbandSelectionManipulator.isActive()) { + QPointF mouseMovementVector = m_rubberbandSelectionManipulator.beginPoint() - event->pos(); + + if ((mouseMovementVector.toPoint().manhattanLength() > Constants::DragStartDistance) + && (m_mousePressTimer.elapsed() > Constants::DragStartTime)) { + m_rubberbandSelectionManipulator.update(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::RemoveFromSelection); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::AddToSelection); + else + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::ReplaceSelection); + } + } +} + +void LiveSelectionTool::hoverMoveEvent(QMouseEvent * event) +{ +// ### commented out until move tool is re-enabled +// QList itemList = view()->items(event->pos()); +// if (!itemList.isEmpty() && !m_rubberbandSelectionMode) { +// +// foreach (QGraphicsItem *item, itemList) { +// if (item->type() == Constants::ResizeHandleItemType) { +// ResizeHandleItem* resizeHandle = ResizeHandleItem::fromGraphicsItem(item); +// if (resizeHandle) +// view()->changeTool(Constants::ResizeToolMode); +// return; +// } +// } +// if (topSelectedItemIsMovable(itemList)) +// view()->changeTool(Constants::MoveToolMode); +// } + QDeclarativeViewObserverPrivate *observerPrivate + = QDeclarativeViewObserverPrivate::get(observer()); + + QList selectableItemList = observerPrivate->selectableItems(event->pos()); + if (!selectableItemList.isEmpty()) { + QGraphicsObject *item = selectableItemList.first()->toGraphicsObject(); + if (item) + QDeclarativeViewObserverPrivate::get(observer())->highlight(item); + + return; + } + + QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); +} + +void LiveSelectionTool::mouseReleaseEvent(QMouseEvent *event) +{ + if (m_singleSelectionManipulator.isActive()) { + m_singleSelectionManipulator.end(event->pos()); + } + else if (m_rubberbandSelectionManipulator.isActive()) { + + QPointF mouseMovementVector = m_rubberbandSelectionManipulator.beginPoint() - event->pos(); + if (mouseMovementVector.toPoint().manhattanLength() < Constants::DragStartDistance) { + m_singleSelectionManipulator.begin(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::RemoveFromSelection, + m_selectOnlyContentItems); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::AddToSelection, + m_selectOnlyContentItems); + else + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, + m_selectOnlyContentItems); + + m_singleSelectionManipulator.end(event->pos()); + } else { + m_rubberbandSelectionManipulator.update(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::RemoveFromSelection); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::AddToSelection); + else + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::ReplaceSelection); + + m_rubberbandSelectionManipulator.end(); + } + } +} + +void LiveSelectionTool::mouseDoubleClickEvent(QMouseEvent * /*event*/) +{ +} + +void LiveSelectionTool::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Left: + case Qt::Key_Right: + case Qt::Key_Up: + case Qt::Key_Down: + // disabled for now, cannot move stuff yet. + //view()->changeTool(Constants::MoveToolMode); + //view()->currentTool()->keyPressEvent(event); + break; + } +} + +void LiveSelectionTool::keyReleaseEvent(QKeyEvent * /*keyEvent*/) +{ + +} + +void LiveSelectionTool::wheelEvent(QWheelEvent *event) +{ + if (event->orientation() == Qt::Horizontal || m_rubberbandSelectionMode) + return; + + QDeclarativeViewObserverPrivate *observerPrivate + = QDeclarativeViewObserverPrivate::get(observer()); + QList itemList = observerPrivate->selectableItems(event->pos()); + + if (itemList.isEmpty()) + return; + + int selectedIdx = 0; + if (!observer()->selectedItems().isEmpty()) { + selectedIdx = itemList.indexOf(observer()->selectedItems().first()); + if (selectedIdx >= 0) { + if (event->delta() > 0) { + selectedIdx++; + if (selectedIdx == itemList.length()) + selectedIdx = 0; + } else if (event->delta() < 0) { + selectedIdx--; + if (selectedIdx == -1) + selectedIdx = itemList.length() - 1; + } + } else { + selectedIdx = 0; + } + } + + QPointF updatePt(0, 0); + m_singleSelectionManipulator.begin(updatePt); + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::ReplaceSelection, + QList() << itemList.at(selectedIdx), + false); + m_singleSelectionManipulator.end(updatePt); + +} + +void LiveSelectionTool::setSelectOnlyContentItems(bool selectOnlyContentItems) +{ + m_selectOnlyContentItems = selectOnlyContentItems; +} + +void LiveSelectionTool::itemsAboutToRemoved(const QList &/*itemList*/) +{ +} + +void LiveSelectionTool::clear() +{ + view()->setCursor(Qt::ArrowCursor); + m_rubberbandSelectionManipulator.clear(), + m_singleSelectionManipulator.clear(); + m_selectionIndicator.clear(); + //m_resizeIndicator.clear(); +} + +void LiveSelectionTool::selectedItemsChanged(const QList &itemList) +{ + foreach (const QWeakPointer &obj, m_selectedItemList) { + if (!obj.isNull()) { + disconnect(obj.data(), SIGNAL(xChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(yChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects())); + } + } + + QList objects = toGraphicsObjectList(itemList); + m_selectedItemList.clear(); + + foreach (QGraphicsObject *obj, objects) { + m_selectedItemList.append(obj); + connect(obj, SIGNAL(xChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(yChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects())); + } + + m_selectionIndicator.setItems(m_selectedItemList); + //m_resizeIndicator.setItems(toGraphicsObjectList(itemList)); +} + +void LiveSelectionTool::repaintBoundingRects() +{ + m_selectionIndicator.setItems(m_selectedItemList); +} + +void LiveSelectionTool::selectUnderPoint(QMouseEvent *event) +{ + m_singleSelectionManipulator.begin(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::RemoveFromSelection, + m_selectOnlyContentItems); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::AddToSelection, + m_selectOnlyContentItems); + else + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, + m_selectOnlyContentItems); + + m_singleSelectionManipulator.end(event->pos()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool_p.h b/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool_p.h new file mode 100644 index 0000000..3daac3d --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/liveselectiontool_p.h @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LIVESELECTIONTOOL_H +#define LIVESELECTIONTOOL_H + +#include "abstractliveedittool_p.h" +#include "liverubberbandselectionmanipulator_p.h" +#include "livesingleselectionmanipulator_p.h" +#include "liveselectionindicator_p.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) +QT_FORWARD_DECLARE_CLASS(QMouseEvent) +QT_FORWARD_DECLARE_CLASS(QKeyEvent) +QT_FORWARD_DECLARE_CLASS(QAction) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class LiveSelectionTool : public AbstractLiveEditTool +{ + Q_OBJECT + +public: + LiveSelectionTool(QDeclarativeViewObserver* editorView); + ~LiveSelectionTool(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void hoverMoveEvent(QMouseEvent *event); + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *keyEvent); + void wheelEvent(QWheelEvent *event); + + void itemsAboutToRemoved(const QList &itemList); +// QVariant itemChange(const QList &itemList, +// QGraphicsItem::GraphicsItemChange change, +// const QVariant &value ); + +// void update(); + + void clear(); + + void selectedItemsChanged(const QList &itemList); + + void selectUnderPoint(QMouseEvent *event); + + void setSelectOnlyContentItems(bool selectOnlyContentItems); + + void setRubberbandSelectionMode(bool value); + +private slots: + void contextMenuElementSelected(); + void contextMenuElementHovered(QAction *action); + void repaintBoundingRects(); + +private: + void createContextMenu(QList itemList, QPoint globalPos); + LiveSingleSelectionManipulator::SelectionType getSelectionType(Qt::KeyboardModifiers modifiers); + bool alreadySelected(const QList &itemList) const; + +private: + bool m_rubberbandSelectionMode; + LiveRubberBandSelectionManipulator m_rubberbandSelectionManipulator; + LiveSingleSelectionManipulator m_singleSelectionManipulator; + LiveSelectionIndicator m_selectionIndicator; + //ResizeIndicator m_resizeIndicator; + QTime m_mousePressTimer; + bool m_selectOnlyContentItems; + + QList > m_selectedItemList; + + QList m_contextMenuItemList; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // LIVESELECTIONTOOL_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator.cpp b/src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator.cpp new file mode 100644 index 0000000..e753b64 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "livesingleselectionmanipulator_p.h" + +#include "../qdeclarativeviewobserver_p_p.h" + +#include + +QT_BEGIN_NAMESPACE + +LiveSingleSelectionManipulator::LiveSingleSelectionManipulator(QDeclarativeViewObserver *editorView) + : m_editorView(editorView), + m_isActive(false) +{ +} + + +void LiveSingleSelectionManipulator::begin(const QPointF &beginPoint) +{ + m_beginPoint = beginPoint; + m_isActive = true; + m_oldSelectionList = QDeclarativeViewObserverPrivate::get(m_editorView)->selectedItems(); +} + +void LiveSingleSelectionManipulator::update(const QPointF &/*updatePoint*/) +{ + m_oldSelectionList.clear(); +} + +void LiveSingleSelectionManipulator::clear() +{ + m_beginPoint = QPointF(); + m_oldSelectionList.clear(); +} + + +void LiveSingleSelectionManipulator::end(const QPointF &/*updatePoint*/) +{ + m_oldSelectionList.clear(); + m_isActive = false; +} + +void LiveSingleSelectionManipulator::select(SelectionType selectionType, + const QList &items, + bool /*selectOnlyContentItems*/) +{ + QGraphicsItem *selectedItem = 0; + + foreach (QGraphicsItem* item, items) + { + //FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); + if (item + /*&& !formEditorItem->qmlItemNode().isRootNode() + && (formEditorItem->qmlItemNode().hasShowContent() || !selectOnlyContentItems)*/) + { + selectedItem = item; + break; + } + } + + QList resultList; + + switch (selectionType) { + case AddToSelection: { + resultList.append(m_oldSelectionList); + if (selectedItem && !m_oldSelectionList.contains(selectedItem)) + resultList.append(selectedItem); + } + break; + case ReplaceSelection: { + if (selectedItem) + resultList.append(selectedItem); + } + break; + case RemoveFromSelection: { + resultList.append(m_oldSelectionList); + if (selectedItem) + resultList.removeAll(selectedItem); + } + break; + case InvertSelection: { + if (selectedItem + && !m_oldSelectionList.contains(selectedItem)) + { + resultList.append(selectedItem); + } + } + } + + m_editorView->setSelectedItems(resultList); +} + +void LiveSingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems) +{ + QDeclarativeViewObserverPrivate *observerPrivate = + QDeclarativeViewObserverPrivate::get(m_editorView); + QList itemList = observerPrivate->selectableItems(m_beginPoint); + select(selectionType, itemList, selectOnlyContentItems); +} + + +bool LiveSingleSelectionManipulator::isActive() const +{ + return m_isActive; +} + +QPointF LiveSingleSelectionManipulator::beginPoint() const +{ + return m_beginPoint; +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator_p.h b/src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator_p.h new file mode 100644 index 0000000..68329e5 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/livesingleselectionmanipulator_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LIVESINGLESELECTIONMANIPULATOR_H +#define LIVESINGLESELECTIONMANIPULATOR_H + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserver; + +class LiveSingleSelectionManipulator +{ +public: + LiveSingleSelectionManipulator(QDeclarativeViewObserver *editorView); + + enum SelectionType { + ReplaceSelection, + AddToSelection, + RemoveFromSelection, + InvertSelection + }; + + void begin(const QPointF& beginPoint); + void update(const QPointF& updatePoint); + void end(const QPointF& updatePoint); + + void select(SelectionType selectionType, const QList &items, + bool selectOnlyContentItems); + void select(SelectionType selectionType, bool selectOnlyContentItems); + + void clear(); + + QPointF beginPoint() const; + + bool isActive() const; + +private: + QList m_oldSelectionList; + QPointF m_beginPoint; + QDeclarativeViewObserver *m_editorView; + bool m_isActive; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // LIVESINGLESELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar.cpp b/src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar.cpp new file mode 100644 index 0000000..359e9ef --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar.cpp @@ -0,0 +1,328 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmltoolbar_p.h" +#include "toolbarcolorbox_p.h" + +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +QmlToolBar::QmlToolBar(QWidget *parent) + : QToolBar(parent) + , m_emitSignals(true) + , m_paused(false) + , m_animationSpeed(1.0f) + , ui(new Ui) +{ + ui->playIcon = QIcon(QLatin1String(":/qml/images/play-24.png")); + ui->pauseIcon = QIcon(QLatin1String(":/qml/images/pause-24.png")); + + ui->designmode = new QAction(QIcon(QLatin1String(":/qml/images/observermode-24.png")), + tr("Observer Mode"), this); + ui->play = new QAction(ui->pauseIcon, tr("Play/Pause Animations"), this); + ui->select = new QAction(QIcon(QLatin1String(":/qml/images/select-24.png")), tr("Select"), this); + ui->selectMarquee = new QAction(QIcon(QLatin1String(":/qml/images/select-marquee-24.png")), + tr("Select (Marquee)"), this); + ui->zoom = new QAction(QIcon(QLatin1String(":/qml/images/zoom-24.png")), tr("Zoom"), this); + ui->colorPicker = new QAction(QIcon(QLatin1String(":/qml/images/color-picker-24.png")), + tr("Color Picker"), this); + ui->toQml = new QAction(QIcon(QLatin1String(":/qml/images/to-qml-24.png")), + tr("Apply Changes to QML Viewer"), this); + ui->fromQml = new QAction(QIcon(QLatin1String(":/qml/images/from-qml-24.png")), + tr("Apply Changes to Document"), this); + ui->designmode->setCheckable(true); + ui->designmode->setChecked(false); + + ui->play->setCheckable(false); + ui->select->setCheckable(true); + ui->selectMarquee->setCheckable(true); + ui->zoom->setCheckable(true); + ui->colorPicker->setCheckable(true); + + setWindowTitle(tr("Tools")); + + addAction(ui->designmode); + addAction(ui->play); + addSeparator(); + + addAction(ui->select); + // disabled because multi selection does not do anything useful without design mode + //addAction(ui->selectMarquee); + addSeparator(); + addAction(ui->zoom); + addAction(ui->colorPicker); + //addAction(ui->fromQml); + + ui->colorBox = new ToolBarColorBox(this); + ui->colorBox->setMinimumSize(24, 24); + ui->colorBox->setMaximumSize(28, 28); + ui->colorBox->setColor(Qt::black); + addWidget(ui->colorBox); + + setWindowFlags(Qt::Tool); + + QMenu *playSpeedMenu = new QMenu(this); + ui->playSpeedMenuActions = new QActionGroup(this); + ui->playSpeedMenuActions->setExclusive(true); + + QAction *speedAction = playSpeedMenu->addAction(tr("1x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setChecked(true); + speedAction->setData(1.0f); + ui->playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.5x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(2.0f); + ui->playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.25x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(4.0f); + ui->playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.125x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(8.0f); + ui->playSpeedMenuActions->addAction(speedAction); + + speedAction = playSpeedMenu->addAction(tr("0.1x"), this, SLOT(changeAnimationSpeed())); + speedAction->setCheckable(true); + speedAction->setData(10.0f); + ui->playSpeedMenuActions->addAction(speedAction); + + ui->play->setMenu(playSpeedMenu); + + connect(ui->designmode, SIGNAL(toggled(bool)), SLOT(setDesignModeBehaviorOnClick(bool))); + + connect(ui->colorPicker, SIGNAL(triggered()), SLOT(activateColorPickerOnClick())); + + connect(ui->play, SIGNAL(triggered()), SLOT(activatePlayOnClick())); + + connect(ui->zoom, SIGNAL(triggered()), SLOT(activateZoomOnClick())); + connect(ui->colorPicker, SIGNAL(triggered()), SLOT(activateColorPickerOnClick())); + connect(ui->select, SIGNAL(triggered()), SLOT(activateSelectToolOnClick())); + connect(ui->selectMarquee, SIGNAL(triggered()), SLOT(activateMarqueeSelectToolOnClick())); + + connect(ui->toQml, SIGNAL(triggered()), SLOT(activateToQml())); + connect(ui->fromQml, SIGNAL(triggered()), SLOT(activateFromQml())); +} + +QmlToolBar::~QmlToolBar() +{ + delete ui; +} + +void QmlToolBar::activateColorPicker() +{ + m_emitSignals = false; + activateColorPickerOnClick(); + m_emitSignals = true; +} + +void QmlToolBar::activateSelectTool() +{ + m_emitSignals = false; + activateSelectToolOnClick(); + m_emitSignals = true; +} + +void QmlToolBar::activateMarqueeSelectTool() +{ + m_emitSignals = false; + activateMarqueeSelectToolOnClick(); + m_emitSignals = true; +} + +void QmlToolBar::activateZoom() +{ + m_emitSignals = false; + activateZoomOnClick(); + m_emitSignals = true; +} + +void QmlToolBar::setAnimationSpeed(qreal slowDownFactor) +{ + if (m_animationSpeed == slowDownFactor) + return; + + m_emitSignals = false; + m_animationSpeed = slowDownFactor; + + foreach (QAction *action, ui->playSpeedMenuActions->actions()) { + if (action->data().toReal() == slowDownFactor) { + action->setChecked(true); + break; + } + } + + m_emitSignals = true; +} + +void QmlToolBar::setAnimationPaused(bool paused) +{ + if (m_paused == paused) + return; + + m_paused = paused; + updatePlayAction(); +} + +void QmlToolBar::changeAnimationSpeed() +{ + QAction *action = qobject_cast(sender()); + m_animationSpeed = action->data().toReal(); + emit animationSpeedChanged(m_animationSpeed); +} + +void QmlToolBar::setDesignModeBehavior(bool inDesignMode) +{ + m_emitSignals = false; + ui->designmode->setChecked(inDesignMode); + setDesignModeBehaviorOnClick(inDesignMode); + m_emitSignals = true; +} + +void QmlToolBar::setDesignModeBehaviorOnClick(bool 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); +} + +void QmlToolBar::activatePlayOnClick() +{ + m_paused = !m_paused; + emit animationPausedChanged(m_paused); + updatePlayAction(); +} + +void QmlToolBar::updatePlayAction() +{ + ui->play->setIcon(m_paused ? ui->playIcon : ui->pauseIcon); +} + +void QmlToolBar::activateColorPickerOnClick() +{ + ui->zoom->setChecked(false); + ui->select->setChecked(false); + ui->selectMarquee->setChecked(false); + + ui->colorPicker->setChecked(true); + if (m_activeTool != Constants::ColorPickerMode) { + m_activeTool = Constants::ColorPickerMode; + if (m_emitSignals) + emit colorPickerSelected(); + } +} + +void QmlToolBar::activateSelectToolOnClick() +{ + ui->zoom->setChecked(false); + ui->selectMarquee->setChecked(false); + ui->colorPicker->setChecked(false); + + ui->select->setChecked(true); + if (m_activeTool != Constants::SelectionToolMode) { + m_activeTool = Constants::SelectionToolMode; + if (m_emitSignals) + emit selectToolSelected(); + } +} + +void QmlToolBar::activateMarqueeSelectToolOnClick() +{ + ui->zoom->setChecked(false); + ui->select->setChecked(false); + ui->colorPicker->setChecked(false); + + ui->selectMarquee->setChecked(true); + if (m_activeTool != Constants::MarqueeSelectionToolMode) { + m_activeTool = Constants::MarqueeSelectionToolMode; + if (m_emitSignals) + emit marqueeSelectToolSelected(); + } +} + +void QmlToolBar::activateZoomOnClick() +{ + ui->select->setChecked(false); + ui->selectMarquee->setChecked(false); + ui->colorPicker->setChecked(false); + + ui->zoom->setChecked(true); + if (m_activeTool != Constants::ZoomMode) { + m_activeTool = Constants::ZoomMode; + if (m_emitSignals) + emit zoomToolSelected(); + } +} + +void QmlToolBar::activateFromQml() +{ + if (m_emitSignals) + emit applyChangesFromQmlFileSelected(); +} + +void QmlToolBar::activateToQml() +{ + if (m_emitSignals) + emit applyChangesToQmlFileSelected(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar_p.h b/src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar_p.h new file mode 100644 index 0000000..459eafd --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/qmltoolbar_p.h @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLTOOLBAR_H +#define QMLTOOLBAR_H + +#include +#include + +#include "../qmlobserverconstants_p.h" + +QT_FORWARD_DECLARE_CLASS(QActionGroup) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class ToolBarColorBox; + +class QmlToolBar : public QToolBar +{ + Q_OBJECT + +public: + explicit QmlToolBar(QWidget *parent = 0); + ~QmlToolBar(); + +public slots: + void setDesignModeBehavior(bool inDesignMode); + void setColorBoxColor(const QColor &color); + void activateColorPicker(); + void activateSelectTool(); + void activateMarqueeSelectTool(); + void activateZoom(); + + void setAnimationSpeed(qreal slowDownFactor); + void setAnimationPaused(bool paused); + +signals: + void animationSpeedChanged(qreal factor); + void animationPausedChanged(bool paused); + + void designModeBehaviorChanged(bool inDesignMode); + void colorPickerSelected(); + void selectToolSelected(); + void marqueeSelectToolSelected(); + void zoomToolSelected(); + + void applyChangesToQmlFileSelected(); + void applyChangesFromQmlFileSelected(); + +private slots: + void setDesignModeBehaviorOnClick(bool inDesignMode); + void activatePlayOnClick(); + void activateColorPickerOnClick(); + void activateSelectToolOnClick(); + void activateMarqueeSelectToolOnClick(); + void activateZoomOnClick(); + + void activateFromQml(); + void activateToQml(); + + void changeAnimationSpeed(); + + void updatePlayAction(); + +private: + class Ui { + public: + QAction *designmode; + QAction *play; + QAction *select; + QAction *selectMarquee; + QAction *zoom; + QAction *colorPicker; + QAction *toQml; + QAction *fromQml; + QIcon playIcon; + QIcon pauseIcon; + ToolBarColorBox *colorBox; + + QActionGroup *playSpeedMenuActions; + }; + + bool m_emitSignals; + bool m_paused; + qreal m_animationSpeed; + + Constants::DesignTool m_activeTool; + + Ui *ui; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLTOOLBAR_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp new file mode 100644 index 0000000..ab77296 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool.cpp @@ -0,0 +1,364 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "subcomponenteditortool_p.h" +#include "subcomponentmasklayeritem_p.h" +#include "livelayeritem_p.h" + +#include "../qdeclarativeviewobserver_p_p.h" + +#include +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +const qreal MaxOpacity = 0.5f; + +SubcomponentEditorTool::SubcomponentEditorTool(QDeclarativeViewObserver *view) + : AbstractLiveEditTool(view), + m_animIncrement(0.05f), + m_animTimer(new QTimer(this)) +{ + QDeclarativeViewObserverPrivate *observerPrivate = + QDeclarativeViewObserverPrivate::get(view); + m_mask = new SubcomponentMaskLayerItem(view, observerPrivate->manipulatorLayer); + connect(m_animTimer, SIGNAL(timeout()), SLOT(animate())); + m_animTimer->setInterval(20); +} + +SubcomponentEditorTool::~SubcomponentEditorTool() +{ + +} + +void SubcomponentEditorTool::mousePressEvent(QMouseEvent * /*event*/) +{ + +} + +void SubcomponentEditorTool::mouseMoveEvent(QMouseEvent * /*event*/) +{ + +} + +bool SubcomponentEditorTool::containsCursor(const QPoint &mousePos) const +{ + if (!m_currentContext.size()) + return false; + + QPointF scenePos = view()->mapToScene(mousePos); + QRectF itemRect = m_currentContext.top()->boundingRect() + | m_currentContext.top()->childrenBoundingRect(); + QRectF polyRect = m_currentContext.top()->mapToScene(itemRect).boundingRect(); + + return polyRect.contains(scenePos); +} + +void SubcomponentEditorTool::mouseReleaseEvent(QMouseEvent * /*event*/) +{ + +} + +void SubcomponentEditorTool::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton + && !containsCursor(event->pos()) + && m_currentContext.size() > 1) + { + aboutToPopContext(); + } +} + +void SubcomponentEditorTool::hoverMoveEvent(QMouseEvent *event) +{ + if (!containsCursor(event->pos()) && m_currentContext.size() > 1) { + QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); + } +} + +void SubcomponentEditorTool::wheelEvent(QWheelEvent * /*event*/) +{ + +} + +void SubcomponentEditorTool::keyPressEvent(QKeyEvent * /*event*/) +{ + +} + +void SubcomponentEditorTool::keyReleaseEvent(QKeyEvent * /*keyEvent*/) +{ + +} + +void SubcomponentEditorTool::itemsAboutToRemoved(const QList &/*itemList*/) +{ + +} + +void SubcomponentEditorTool::animate() +{ + if (m_animIncrement > 0) { + if (m_mask->opacity() + m_animIncrement < MaxOpacity) { + m_mask->setOpacity(m_mask->opacity() + m_animIncrement); + } else { + m_animTimer->stop(); + m_mask->setOpacity(MaxOpacity); + } + } else { + if (m_mask->opacity() + m_animIncrement > 0) { + m_mask->setOpacity(m_mask->opacity() + m_animIncrement); + } else { + m_animTimer->stop(); + m_mask->setOpacity(0); + popContext(); + emit contextPathChanged(m_path); + } + } + +} + +void SubcomponentEditorTool::clear() +{ + m_currentContext.clear(); + m_mask->setCurrentItem(0); + m_animTimer->stop(); + m_mask->hide(); + m_path.clear(); + + emit contextPathChanged(m_path); + emit cleared(); +} + +void SubcomponentEditorTool::selectedItemsChanged(const QList &/*itemList*/) +{ + +} + +void SubcomponentEditorTool::setCurrentItem(QGraphicsItem* contextItem) +{ + if (!contextItem) + return; + + QGraphicsObject *gfxObject = contextItem->toGraphicsObject(); + if (!gfxObject) + return; + + //QString parentClassName = gfxObject->metaObject()->className(); + //if (parentClassName.contains(QRegExp("_QMLTYPE_\\d+"))) + + bool containsSelectableItems = false; + foreach (QGraphicsItem *item, gfxObject->childItems()) { + if (item->type() == Constants::EditorItemType + || item->type() == Constants::ResizeHandleItemType) + { + continue; + } + containsSelectableItems = true; + break; + } + + if (containsSelectableItems) { + m_mask->setCurrentItem(gfxObject); + m_mask->setOpacity(0); + m_mask->show(); + m_animIncrement = 0.05f; + m_animTimer->start(); + + QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); + observer()->setSelectedItems(QList()); + + pushContext(gfxObject); + } +} + +QGraphicsItem *SubcomponentEditorTool::firstChildOfContext(QGraphicsItem *item) const +{ + if (!item) + return 0; + + if (isDirectChildOfContext(item)) + return item; + + QGraphicsItem *parent = item->parentItem(); + while (parent) { + if (isDirectChildOfContext(parent)) + return parent; + parent = parent->parentItem(); + } + + return 0; +} + +bool SubcomponentEditorTool::isChildOfContext(QGraphicsItem *item) const +{ + return (firstChildOfContext(item) != 0); +} + +bool SubcomponentEditorTool::isDirectChildOfContext(QGraphicsItem *item) const +{ + return (item->parentItem() == m_currentContext.top()); +} + +bool SubcomponentEditorTool::itemIsChildOfQmlSubComponent(QGraphicsItem *item) const +{ + if (item->parentItem() && item->parentItem() != m_currentContext.top()) { + QGraphicsObject *parent = item->parentItem()->toGraphicsObject(); + QString parentClassName = QLatin1String(parent->metaObject()->className()); + + if (parentClassName.contains(QRegExp(QLatin1String("_QMLTYPE_\\d+")))) { + return true; + } else { + return itemIsChildOfQmlSubComponent(parent); + } + } + + return false; +} + +void SubcomponentEditorTool::pushContext(QGraphicsObject *contextItem) +{ + connect(contextItem, SIGNAL(destroyed(QObject*)), this, SLOT(contextDestroyed(QObject*))); + connect(contextItem, SIGNAL(xChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(yChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(widthChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(heightChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(rotationChanged()), this, SLOT(resizeMask())); + + m_currentContext.push(contextItem); + QString title = titleForItem(contextItem); + emit contextPushed(title); + + m_path << title; + emit contextPathChanged(m_path); +} + +void SubcomponentEditorTool::aboutToPopContext() +{ + if (m_currentContext.size() > 2) { + popContext(); + emit contextPathChanged(m_path); + } else { + m_animIncrement = -0.05f; + m_animTimer->start(); + } +} + +QGraphicsObject *SubcomponentEditorTool::popContext() +{ + QGraphicsObject *popped = m_currentContext.pop(); + m_path.removeLast(); + + emit contextPopped(); + + disconnect(popped, SIGNAL(xChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(yChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(scaleChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(widthChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(heightChanged()), this, SLOT(resizeMask())); + + if (m_currentContext.size() > 1) { + QGraphicsObject *item = m_currentContext.top(); + m_mask->setCurrentItem(item); + m_mask->setOpacity(MaxOpacity); + m_mask->setVisible(true); + } else { + m_mask->setVisible(false); + } + + return popped; +} + +void SubcomponentEditorTool::resizeMask() +{ + QGraphicsObject *item = m_currentContext.top(); + m_mask->setCurrentItem(item); +} + +QGraphicsObject *SubcomponentEditorTool::currentRootItem() const +{ + return m_currentContext.top(); +} + +void SubcomponentEditorTool::contextDestroyed(QObject *contextToDestroy) +{ + disconnect(contextToDestroy, SIGNAL(destroyed(QObject*)), + this, SLOT(contextDestroyed(QObject*))); + + // pop out the whole context - it might not be safe anymore. + while (m_currentContext.size() > 1) { + m_currentContext.pop(); + m_path.removeLast(); + emit contextPopped(); + } + m_mask->setVisible(false); + + emit contextPathChanged(m_path); +} + +QGraphicsObject *SubcomponentEditorTool::setContext(int contextIndex) +{ + Q_ASSERT(contextIndex >= 0); + + // sometimes we have to delete the context while user was still clicking around, + // so just bail out. + if (contextIndex >= m_currentContext.size() -1) + return 0; + + while (m_currentContext.size() - 1 > contextIndex) { + popContext(); + } + emit contextPathChanged(m_path); + + return m_currentContext.top(); +} + +int SubcomponentEditorTool::contextIndex() const +{ + return m_currentContext.size() - 1; +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h b/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h new file mode 100644 index 0000000..15217eb --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/subcomponenteditortool_p.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SUBCOMPONENTEDITORTOOL_H +#define SUBCOMPONENTEDITORTOOL_H + +#include "abstractliveedittool_p.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsObject) +QT_FORWARD_DECLARE_CLASS(QPoint) +QT_FORWARD_DECLARE_CLASS(QTimer) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class SubcomponentMaskLayerItem; + +class SubcomponentEditorTool : public AbstractLiveEditTool +{ + Q_OBJECT + +public: + SubcomponentEditorTool(QDeclarativeViewObserver *view); + ~SubcomponentEditorTool(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + + void hoverMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *keyEvent); + void itemsAboutToRemoved(const QList &itemList); + + void clear(); + + bool containsCursor(const QPoint &mousePos) const; + bool itemIsChildOfQmlSubComponent(QGraphicsItem *item) const; + + bool isChildOfContext(QGraphicsItem *item) const; + bool isDirectChildOfContext(QGraphicsItem *item) const; + QGraphicsItem *firstChildOfContext(QGraphicsItem *item) const; + + void setCurrentItem(QGraphicsItem *contextObject); + + void pushContext(QGraphicsObject *contextItem); + + QGraphicsObject *currentRootItem() const; + QGraphicsObject *setContext(int contextIndex); + int contextIndex() const; + +signals: + void exitContextRequested(); + void cleared(); + void contextPushed(const QString &contextTitle); + void contextPopped(); + void contextPathChanged(const QStringList &path); + +protected: + void selectedItemsChanged(const QList &itemList); + +private slots: + void animate(); + void contextDestroyed(QObject *context); + void resizeMask(); + +private: + QGraphicsObject *popContext(); + void aboutToPopContext(); + +private: + QStack m_currentContext; + QStringList m_path; + + qreal m_animIncrement; + SubcomponentMaskLayerItem *m_mask; + QTimer *m_animTimer; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // SUBCOMPONENTEDITORTOOL_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp b/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp new file mode 100644 index 0000000..15d2a2c --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "subcomponentmasklayeritem_p.h" + +#include "../qmlobserverconstants_p.h" +#include "../qdeclarativeviewobserver_p.h" + +#include + +QT_BEGIN_NAMESPACE + +SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewObserver *observer, + QGraphicsItem *parentItem) : + QGraphicsPolygonItem(parentItem), + m_observer(observer), + m_currentItem(0), + m_borderRect(new QGraphicsRectItem(this)) +{ + m_borderRect->setRect(0,0,0,0); + m_borderRect->setPen(QPen(QColor(60, 60, 60), 1)); + m_borderRect->setData(Constants::EditorItemDataKey, QVariant(true)); + + setBrush(QBrush(QColor(160,160,160))); + setPen(Qt::NoPen); +} + +int SubcomponentMaskLayerItem::type() const +{ + return Constants::EditorItemType; +} + +static QRectF resizeRect(const QRectF &newRect, const QRectF &oldRect) +{ + QRectF result = newRect; + if (oldRect.left() < newRect.left()) + result.setLeft(oldRect.left()); + + if (oldRect.top() < newRect.top()) + result.setTop(oldRect.top()); + + if (oldRect.right() > newRect.right()) + result.setRight(oldRect.right()); + + if (oldRect.bottom() > newRect.bottom()) + result.setBottom(oldRect.bottom()); + + return result; +} + + +void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) +{ + QGraphicsItem *prevItem = m_currentItem; + m_currentItem = item; + + if (!m_currentItem) + return; + + QPolygonF viewPoly(QRectF(m_observer->declarativeView()->rect())); + viewPoly = m_observer->declarativeView()->mapToScene(viewPoly.toPolygon()); + + QRectF itemRect = item->boundingRect() | item->childrenBoundingRect(); + QPolygonF itemPoly(itemRect); + itemPoly = item->mapToScene(itemPoly); + + // if updating the same item as before, resize the rectangle only bigger, not smaller. + if (prevItem == item && prevItem != 0) { + m_itemPolyRect = resizeRect(itemPoly.boundingRect(), m_itemPolyRect); + } else { + m_itemPolyRect = itemPoly.boundingRect(); + } + QRectF borderRect = m_itemPolyRect; + borderRect.adjust(-1, -1, 1, 1); + m_borderRect->setRect(borderRect); + + itemPoly = viewPoly.subtracted(QPolygonF(m_itemPolyRect)); + setPolygon(itemPoly); +} + +QGraphicsItem *SubcomponentMaskLayerItem::currentItem() const +{ + return m_currentItem; +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem_p.h b/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem_p.h new file mode 100644 index 0000000..e0b892d --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/subcomponentmasklayeritem_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SUBCOMPONENTMASKLAYERITEM_H +#define SUBCOMPONENTMASKLAYERITEM_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserver; + +class SubcomponentMaskLayerItem : public QGraphicsPolygonItem +{ +public: + explicit SubcomponentMaskLayerItem(QDeclarativeViewObserver *observer, + QGraphicsItem *parentItem = 0); + int type() const; + void setCurrentItem(QGraphicsItem *item); + void setBoundingBox(const QRectF &boundingBox); + QGraphicsItem *currentItem() const; + QRectF itemRect() const; + +private: + QDeclarativeViewObserver *m_observer; + QGraphicsItem *m_currentItem; + QGraphicsRectItem *m_borderRect; + QRectF m_itemPolyRect; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // SUBCOMPONENTMASKLAYERITEM_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox.cpp b/src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox.cpp new file mode 100644 index 0000000..35582fb --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "toolbarcolorbox_p.h" + +#include "../qmlobserverconstants_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +ToolBarColorBox::ToolBarColorBox(QWidget *parent) : + QLabel(parent) +{ + m_copyHexColor = new QAction(QIcon(QLatin1String(":/qml/images/color-picker-hicontrast.png")), + tr("Copy Color"), this); + connect(m_copyHexColor, SIGNAL(triggered()), SLOT(copyColorToClipboard())); + setScaledContents(false); +} + +void ToolBarColorBox::setColor(const QColor &color) +{ + m_color = color; + + QPixmap pix = createDragPixmap(width()); + setPixmap(pix); + update(); +} + +void ToolBarColorBox::mousePressEvent(QMouseEvent *event) +{ + m_dragBeginPoint = event->pos(); + m_dragStarted = false; +} + +void ToolBarColorBox::mouseMoveEvent(QMouseEvent *event) +{ + + if (event->buttons() & Qt::LeftButton + && (QPoint(event->pos() - m_dragBeginPoint).manhattanLength() + > Constants::DragStartDistance) + && !m_dragStarted) + { + m_dragStarted = true; + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setText(m_color.name()); + drag->setMimeData(mimeData); + drag->setPixmap(createDragPixmap()); + + drag->exec(); + } +} + +QPixmap ToolBarColorBox::createDragPixmap(int size) const +{ + QPixmap pix(size, size); + QPainter p(&pix); + + QColor borderColor1 = QColor(143, 143 ,143); + QColor borderColor2 = QColor(43, 43, 43); + + p.setBrush(QBrush(m_color)); + p.setPen(QPen(QBrush(borderColor2),1)); + + p.fillRect(0, 0, size, size, borderColor1); + p.drawRect(1,1, size - 3, size - 3); + return pix; +} + +void ToolBarColorBox::contextMenuEvent(QContextMenuEvent *ev) +{ + QMenu contextMenu; + contextMenu.addAction(m_copyHexColor); + contextMenu.exec(ev->globalPos()); +} + +void ToolBarColorBox::copyColorToClipboard() +{ + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(m_color.name()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox_p.h b/src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox_p.h new file mode 100644 index 0000000..d4914fa --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/toolbarcolorbox_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TOOLBARCOLORBOX_H +#define TOOLBARCOLORBOX_H + +#include +#include +#include + +QT_FORWARD_DECLARE_CLASS(QContextMenuEvent) +QT_FORWARD_DECLARE_CLASS(QAction) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class ToolBarColorBox : public QLabel +{ + Q_OBJECT + +public: + explicit ToolBarColorBox(QWidget *parent = 0); + void setColor(const QColor &color); + +protected: + void contextMenuEvent(QContextMenuEvent *ev); + void mousePressEvent(QMouseEvent *ev); + void mouseMoveEvent(QMouseEvent *ev); +private slots: + void copyColorToClipboard(); + +private: + QPixmap createDragPixmap(int size = 24) const; + +private: + bool m_dragStarted; + QPoint m_dragBeginPoint; + QAction *m_copyHexColor; + QColor m_color; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // TOOLBARCOLORBOX_H diff --git a/src/plugins/qmltooling/declarativeobserver/editor/zoomtool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/zoomtool.cpp new file mode 100644 index 0000000..b70cda5 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/zoomtool.cpp @@ -0,0 +1,336 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "zoomtool_p.h" + +#include "../qdeclarativeviewobserver_p_p.h" + +#include +#include +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +ZoomTool::ZoomTool(QDeclarativeViewObserver *view) : + AbstractLiveEditTool(view), + m_rubberbandManipulator(), + m_smoothZoomMultiplier(0.05f), + m_currentScale(1.0f) +{ + m_zoomTo100Action = new QAction(tr("Zoom to &100%"), this); + m_zoomInAction = new QAction(tr("Zoom In"), this); + m_zoomOutAction = new QAction(tr("Zoom Out"), this); + m_zoomInAction->setShortcut(QKeySequence(Qt::Key_Plus)); + m_zoomOutAction->setShortcut(QKeySequence(Qt::Key_Minus)); + + + LiveLayerItem *layerItem = QDeclarativeViewObserverPrivate::get(view)->manipulatorLayer; + QGraphicsObject *layerObject = reinterpret_cast(layerItem); + m_rubberbandManipulator = new LiveRubberBandSelectionManipulator(layerObject, view); + + + connect(m_zoomTo100Action, SIGNAL(triggered()), SLOT(zoomTo100())); + connect(m_zoomInAction, SIGNAL(triggered()), SLOT(zoomIn())); + connect(m_zoomOutAction, SIGNAL(triggered()), SLOT(zoomOut())); +} + +ZoomTool::~ZoomTool() +{ + delete m_rubberbandManipulator; +} + +void ZoomTool::mousePressEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); + + QPointF scenePos = view()->mapToScene(event->pos()); + + if (event->buttons() & Qt::RightButton) { + QMenu contextMenu; + contextMenu.addAction(m_zoomTo100Action); + contextMenu.addSeparator(); + contextMenu.addAction(m_zoomInAction); + contextMenu.addAction(m_zoomOutAction); + contextMenu.exec(event->globalPos()); + } else if (event->buttons() & Qt::LeftButton) { + m_dragBeginPos = scenePos; + m_dragStarted = false; + } +} + +void ZoomTool::mouseMoveEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); + + QPointF scenePos = view()->mapToScene(event->pos()); + + if (event->buttons() & Qt::LeftButton + && (QPointF(scenePos - m_dragBeginPos).manhattanLength() + > Constants::DragStartDistance / 3) + && !m_dragStarted) + { + m_dragStarted = true; + m_rubberbandManipulator->begin(m_dragBeginPos); + return; + } + + if (m_dragStarted) + m_rubberbandManipulator->update(scenePos); + +} + +void ZoomTool::mouseReleaseEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); + QPointF scenePos = view()->mapToScene(event->pos()); + + if (m_dragStarted) { + m_rubberbandManipulator->end(); + + int x1 = qMin(scenePos.x(), m_rubberbandManipulator->beginPoint().x()); + int x2 = qMax(scenePos.x(), m_rubberbandManipulator->beginPoint().x()); + int y1 = qMin(scenePos.y(), m_rubberbandManipulator->beginPoint().y()); + int y2 = qMax(scenePos.y(), m_rubberbandManipulator->beginPoint().y()); + + QPointF scenePosTopLeft = QPoint(x1, y1); + QPointF scenePosBottomRight = QPoint(x2, y2); + + QRectF sceneArea(scenePosTopLeft, scenePosBottomRight); + + m_currentScale = qMin(view()->rect().width() / sceneArea.width(), + view()->rect().height() / sceneArea.height()); + + + QTransform transform; + transform.scale(m_currentScale, m_currentScale); + + view()->setTransform(transform); + view()->setSceneRect(sceneArea); + } else { + Qt::KeyboardModifier modifierKey = Qt::ControlModifier; +#ifdef Q_WS_MAC + modifierKey = Qt::AltModifier; +#endif + if (event->modifiers() & modifierKey) { + zoomOut(); + } else { + zoomIn(); + } + } +} + +void ZoomTool::zoomIn() +{ + m_currentScale = nextZoomScale(ZoomIn); + scaleView(view()->mapToScene(m_mousePos)); +} + +void ZoomTool::zoomOut() +{ + m_currentScale = nextZoomScale(ZoomOut); + scaleView(view()->mapToScene(m_mousePos)); +} + +void ZoomTool::mouseDoubleClickEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); +} + + +void ZoomTool::hoverMoveEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); +} + + +void ZoomTool::keyPressEvent(QKeyEvent * /*event*/) +{ +} + +void ZoomTool::wheelEvent(QWheelEvent *event) +{ + if (event->orientation() != Qt::Vertical) + return; + + Qt::KeyboardModifier smoothZoomModifier = Qt::ControlModifier; + if (event->modifiers() & smoothZoomModifier) { + int numDegrees = event->delta() / 8; + m_currentScale += m_smoothZoomMultiplier * (numDegrees / 15.0f); + + scaleView(view()->mapToScene(m_mousePos)); + + } else if (!event->modifiers()) { + if (event->delta() > 0) { + m_currentScale = nextZoomScale(ZoomIn); + } else if (event->delta() < 0) { + m_currentScale = nextZoomScale(ZoomOut); + } + scaleView(view()->mapToScene(m_mousePos)); + } +} + +void ZoomTool::keyReleaseEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Plus: + zoomIn(); + break; + case Qt::Key_Minus: + zoomOut(); + break; + case Qt::Key_1: + case Qt::Key_2: + case Qt::Key_3: + case Qt::Key_4: + case Qt::Key_5: + case Qt::Key_6: + case Qt::Key_7: + case Qt::Key_8: + case Qt::Key_9: + { + m_currentScale = ((event->key() - Qt::Key_0) * 1.0f); + scaleView(view()->mapToScene(m_mousePos)); // view()->mapToScene(view()->rect().center()) + break; + } + + default: + break; + } + +} + +void ZoomTool::itemsAboutToRemoved(const QList &/*itemList*/) +{ +} + +void ZoomTool::clear() +{ + view()->setCursor(Qt::ArrowCursor); +} + +void ZoomTool::selectedItemsChanged(const QList &/*itemList*/) +{ +} + +void ZoomTool::scaleView(const QPointF ¢erPos) +{ + + QTransform transform; + transform.scale(m_currentScale, m_currentScale); + view()->setTransform(transform); + + QPointF adjustedCenterPos = centerPos; + QSize rectSize(view()->rect().width() / m_currentScale, + view()->rect().height() / m_currentScale); + + QRectF sceneRect; + if (qAbs(m_currentScale - 1.0f) < Constants::ZoomSnapDelta) { + adjustedCenterPos.rx() = rectSize.width() / 2; + adjustedCenterPos.ry() = rectSize.height() / 2; + } + + if (m_currentScale < 1.0f) { + adjustedCenterPos.rx() = rectSize.width() / 2; + adjustedCenterPos.ry() = rectSize.height() / 2; + sceneRect.setRect(view()->rect().width() / 2 -rectSize.width() / 2, + view()->rect().height() / 2 -rectSize.height() / 2, + rectSize.width(), + rectSize.height()); + } else { + sceneRect.setRect(adjustedCenterPos.x() - rectSize.width() / 2, + adjustedCenterPos.y() - rectSize.height() / 2, + rectSize.width(), + rectSize.height()); + } + + view()->setSceneRect(sceneRect); +} + +void ZoomTool::zoomTo100() +{ + m_currentScale = 1.0f; + scaleView(view()->mapToScene(view()->rect().center())); +} + +qreal ZoomTool::nextZoomScale(ZoomDirection direction) const +{ + static QList zoomScales = + QList() + << 0.125f + << 1.0f / 6.0f + << 0.25f + << 1.0f / 3.0f + << 0.5f + << 2.0f / 3.0f + << 1.0f + << 2.0f + << 3.0f + << 4.0f + << 5.0f + << 6.0f + << 7.0f + << 8.0f + << 12.0f + << 16.0f + << 32.0f + << 48.0f; + + if (direction == ZoomIn) { + for (int i = 0; i < zoomScales.length(); ++i) { + if (zoomScales[i] > m_currentScale || i == zoomScales.length() - 1) + return zoomScales[i]; + } + } else { + for (int i = zoomScales.length() - 1; i >= 0; --i) { + if (zoomScales[i] < m_currentScale || i == 0) + return zoomScales[i]; + } + } + + return 1.0f; +} + +QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/declarativeobserver/editor/zoomtool_p.h b/src/plugins/qmltooling/declarativeobserver/editor/zoomtool_p.h new file mode 100644 index 0000000..6734cf9 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/editor/zoomtool_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ZOOMTOOL_H +#define ZOOMTOOL_H + +#include "abstractliveedittool_p.h" +#include "liverubberbandselectionmanipulator_p.h" + +QT_FORWARD_DECLARE_CLASS(QAction) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class ZoomTool : public AbstractLiveEditTool +{ + Q_OBJECT + +public: + enum ZoomDirection { + ZoomIn, + ZoomOut + }; + + explicit ZoomTool(QDeclarativeViewObserver *view); + + virtual ~ZoomTool(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + + void hoverMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *keyEvent); + void itemsAboutToRemoved(const QList &itemList); + + void clear(); + +protected: + void selectedItemsChanged(const QList &itemList); + +private slots: + void zoomTo100(); + void zoomIn(); + void zoomOut(); + +private: + qreal nextZoomScale(ZoomDirection direction) const; + void scaleView(const QPointF ¢erPos); + +private: + bool m_dragStarted; + QPoint m_mousePos; // in view coords + QPointF m_dragBeginPos; + QAction *m_zoomTo100Action; + QAction *m_zoomInAction; + QAction *m_zoomOutAction; + LiveRubberBandSelectionManipulator *m_rubberbandManipulator; + + qreal m_smoothZoomMultiplier; + qreal m_currentScale; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // ZOOMTOOL_H diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.cpp b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.cpp new file mode 100644 index 0000000..458b7ef --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativeobserverplugin.h" + +#include "qdeclarativeviewobserver_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +QDeclarativeObserverPlugin::QDeclarativeObserverPlugin() : + m_observer(0) +{ +} + +QDeclarativeObserverPlugin::~QDeclarativeObserverPlugin() +{ + delete m_observer; +} + +void QDeclarativeObserverPlugin::activate() +{ + QDeclarativeObserverService *service = QDeclarativeObserverService::instance(); + QList views = service->views(); + if (views.isEmpty()) + return; + + // TODO: Support multiple views + QDeclarativeView *view = service->views().at(0); + m_observer = new QDeclarativeViewObserver(view, view); +} + +void QDeclarativeObserverPlugin::deactivate() +{ + delete m_observer; +} + +Q_EXPORT_PLUGIN2(declarativeobserver, QDeclarativeObserverPlugin) + +QT_END_NAMESPACE + diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.h new file mode 100644 index 0000000..82d3dbc --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverplugin.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEOBSERVERPLUGIN_H +#define QDECLARATIVEOBSERVERPLUGIN_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QDeclarativeViewObserver; + +class QDeclarativeObserverPlugin : public QObject, public QDeclarativeObserverInterface +{ + Q_OBJECT + Q_DISABLE_COPY(QDeclarativeObserverPlugin) + Q_INTERFACES(QDeclarativeObserverInterface) + +public: + QDeclarativeObserverPlugin(); + ~QDeclarativeObserverPlugin(); + + void activate(); + void deactivate(); + +private: + QPointer m_observer; +}; + +QT_END_NAMESPACE + +#endif // QDECLARATIVEOBSERVERPLUGIN_H diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h new file mode 100644 index 0000000..eb46693 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeobserverprotocol.h @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEOBSERVERPROTOCOL_H +#define QDECLARATIVEOBSERVERPROTOCOL_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class ObserverProtocol : public QObject +{ + Q_OBJECT + Q_ENUMS(Message Tool) + +public: + enum Message { + AnimationSpeedChanged = 0, + AnimationPausedChanged = 19, // highest value + ChangeTool = 1, + ClearComponentCache = 2, + ColorChanged = 3, + ContextPathUpdated = 4, + CreateObject = 5, + CurrentObjectsChanged = 6, + DestroyObject = 7, + MoveObject = 8, + ObjectIdList = 9, + Reload = 10, + Reloaded = 11, + SetAnimationSpeed = 12, + SetAnimationPaused = 18, + SetContextPathIdx = 13, + SetCurrentObjects = 14, + SetDesignMode = 15, + ShowAppOnTop = 16, + ToolChanged = 17 + }; + + enum Tool { + ColorPickerTool, + SelectMarqueeTool, + SelectTool, + ZoomTool + }; + + static inline QString toString(Message message) + { + return QLatin1String(staticMetaObject.enumerator(0).valueToKey(message)); + } + + static inline QString toString(Tool tool) + { + return QLatin1String(staticMetaObject.enumerator(1).valueToKey(tool)); + } +}; + +inline QDataStream & operator<< (QDataStream &stream, ObserverProtocol::Message message) +{ + return stream << static_cast(message); +} + +inline QDataStream & operator>> (QDataStream &stream, ObserverProtocol::Message &message) +{ + quint32 i; + stream >> i; + message = static_cast(i); + return stream; +} + +inline QDebug operator<< (QDebug dbg, ObserverProtocol::Message message) +{ + dbg << ObserverProtocol::toString(message); + return dbg; +} + +inline QDataStream & operator<< (QDataStream &stream, ObserverProtocol::Tool tool) +{ + return stream << static_cast(tool); +} + +inline QDataStream & operator>> (QDataStream &stream, ObserverProtocol::Tool &tool) +{ + quint32 i; + stream >> i; + tool = static_cast(i); + return stream; +} + +inline QDebug operator<< (QDebug dbg, ObserverProtocol::Tool tool) +{ + dbg << ObserverProtocol::toString(tool); + return dbg; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEOBSERVERPROTOCOL_H diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp new file mode 100644 index 0000000..b0a8162 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp @@ -0,0 +1,1159 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "QtDeclarative/private/qdeclarativeobserverservice_p.h" +#include "QtDeclarative/private/qdeclarativedebughelper_p.h" + +#include "qdeclarativeviewobserver_p.h" +#include "qdeclarativeviewobserver_p_p.h" +#include "qdeclarativeobserverprotocol.h" + +#include "editor/liveselectiontool_p.h" +#include "editor/zoomtool_p.h" +#include "editor/colorpickertool_p.h" +#include "editor/livelayeritem_p.h" +#include "editor/boundingrecthighlighter_p.h" +#include "editor/subcomponenteditortool_p.h" +#include "editor/qmltoolbar_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static inline void initEditorResource() { Q_INIT_RESOURCE(editor); } + +QT_BEGIN_NAMESPACE + +const char * const KEY_TOOLBOX_GEOMETRY = "toolBox/geometry"; + +const int SceneChangeUpdateInterval = 5000; + + +class ToolBox : public QWidget +{ + Q_OBJECT + +public: + ToolBox(QWidget *parent = 0); + ~ToolBox(); + + QmlToolBar *toolBar() const { return m_toolBar; } + +private: + QSettings m_settings; + QmlToolBar *m_toolBar; +}; + +ToolBox::ToolBox(QWidget *parent) + : QWidget(parent, Qt::Tool) + , m_settings(QLatin1String("Nokia"), QLatin1String("QmlObserver"), this) + , m_toolBar(new QmlToolBar) +{ + setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::CustomizeWindowHint); + setWindowTitle(tr("Qt Quick Toolbox")); + + QVBoxLayout *verticalLayout = new QVBoxLayout; + verticalLayout->setMargin(0); + verticalLayout->addWidget(m_toolBar); + setLayout(verticalLayout); + + restoreGeometry(m_settings.value(QLatin1String(KEY_TOOLBOX_GEOMETRY)).toByteArray()); +} + +ToolBox::~ToolBox() +{ + m_settings.setValue(QLatin1String(KEY_TOOLBOX_GEOMETRY), saveGeometry()); +} + + +QDeclarativeViewObserverPrivate::QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *q) : + q(q), + designModeBehavior(false), + showAppOnTop(false), + animationPaused(false), + slowDownFactor(1.0f), + toolBox(0) +{ +} + +QDeclarativeViewObserverPrivate::~QDeclarativeViewObserverPrivate() +{ +} + +QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, + QObject *parent) : + QObject(parent), + data(new QDeclarativeViewObserverPrivate(this)) +{ + initEditorResource(); + + data->view = view; + data->manipulatorLayer = new LiveLayerItem(view->scene()); + data->selectionTool = new LiveSelectionTool(this); + data->zoomTool = new ZoomTool(this); + data->colorPickerTool = new ColorPickerTool(this); + data->boundingRectHighlighter = new BoundingRectHighlighter(this); + data->subcomponentEditorTool = new SubcomponentEditorTool(this); + data->currentTool = data->selectionTool; + + // to capture ChildRemoved event when viewport changes + data->view->installEventFilter(this); + + data->setViewport(data->view->viewport()); + + data->debugService = QDeclarativeObserverService::instance(); + connect(data->debugService, SIGNAL(gotMessage(QByteArray)), + this, SLOT(handleMessage(QByteArray))); + + connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), + data.data(), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); + + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + SIGNAL(selectedColorChanged(QColor))); + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + this, SLOT(sendColorChanged(QColor))); + + connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared())); + connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), + SIGNAL(inspectorContextPushed(QString))); + connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), + SIGNAL(inspectorContextPopped())); + connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), + this, SLOT(sendContextPathUpdated(QStringList))); + + data->_q_changeToSingleSelectTool(); +} + +QDeclarativeViewObserver::~QDeclarativeViewObserver() +{ +} + +void QDeclarativeViewObserver::setObserverContext(int contextIndex) +{ + if (data->subcomponentEditorTool->contextIndex() != contextIndex) { + QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex); + if (object) + setSelectedItems(QList() << object); + } +} + +void QDeclarativeViewObserverPrivate::_q_setToolBoxVisible(bool visible) +{ +#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) + if (!toolBox && visible) + createToolBox(); + if (toolBox) + toolBox->setVisible(visible); +#else + Q_UNUSED(visible) +#endif +} + +void QDeclarativeViewObserverPrivate::_q_reloadView() +{ + subcomponentEditorTool->clear(); + clearHighlight(); + emit q->reloadRequested(); +} + +void QDeclarativeViewObserverPrivate::setViewport(QWidget *widget) +{ + if (viewport.data() == widget) + return; + + if (viewport) + viewport.data()->removeEventFilter(q); + + viewport = widget; + if (viewport) { + // make sure we get mouse move events + viewport.data()->setMouseTracking(true); + viewport.data()->installEventFilter(q); + } +} + +void QDeclarativeViewObserverPrivate::clearEditorItems() +{ + clearHighlight(); + setSelectedItems(QList()); +} + +bool QDeclarativeViewObserver::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == data->view) { + // Event from view + if (event->type() == QEvent::ChildRemoved) { + // Might mean that viewport has changed + if (data->view->viewport() != data->viewport.data()) + data->setViewport(data->view->viewport()); + } + return QObject::eventFilter(obj, event); + } + + // Event from viewport + switch (event->type()) { + case QEvent::Leave: { + if (leaveEvent(event)) + return true; + break; + } + case QEvent::MouseButtonPress: { + if (mousePressEvent(static_cast(event))) + return true; + break; + } + case QEvent::MouseMove: { + if (mouseMoveEvent(static_cast(event))) + return true; + break; + } + case QEvent::MouseButtonRelease: { + if (mouseReleaseEvent(static_cast(event))) + return true; + break; + } + case QEvent::KeyPress: { + if (keyPressEvent(static_cast(event))) + return true; + break; + } + case QEvent::KeyRelease: { + if (keyReleaseEvent(static_cast(event))) + return true; + break; + } + case QEvent::MouseButtonDblClick: { + if (mouseDoubleClickEvent(static_cast(event))) + return true; + break; + } + case QEvent::Wheel: { + if (wheelEvent(static_cast(event))) + return true; + break; + } + default: { + break; + } + } //switch + + // standard event processing + return QObject::eventFilter(obj, event); +} + +bool QDeclarativeViewObserver::leaveEvent(QEvent * /*event*/) +{ + if (!data->designModeBehavior) + return false; + data->clearHighlight(); + return true; +} + +bool QDeclarativeViewObserver::mousePressEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) + return false; + data->cursorPos = event->pos(); + data->currentTool->mousePressEvent(event); + return true; +} + +bool QDeclarativeViewObserver::mouseMoveEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) { + data->clearEditorItems(); + return false; + } + data->cursorPos = event->pos(); + + QList selItems = data->selectableItems(event->pos()); + if (!selItems.isEmpty()) { + declarativeView()->setToolTip(data->currentTool->titleForItem(selItems.first())); + } else { + declarativeView()->setToolTip(QString()); + } + if (event->buttons()) { + data->subcomponentEditorTool->mouseMoveEvent(event); + data->currentTool->mouseMoveEvent(event); + } else { + data->subcomponentEditorTool->hoverMoveEvent(event); + data->currentTool->hoverMoveEvent(event); + } + return true; +} + +bool QDeclarativeViewObserver::mouseReleaseEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) + return false; + data->subcomponentEditorTool->mouseReleaseEvent(event); + + data->cursorPos = event->pos(); + data->currentTool->mouseReleaseEvent(event); + return true; +} + +bool QDeclarativeViewObserver::keyPressEvent(QKeyEvent *event) +{ + if (!data->designModeBehavior) + return false; + + data->currentTool->keyPressEvent(event); + return true; +} + +bool QDeclarativeViewObserver::keyReleaseEvent(QKeyEvent *event) +{ + if (!data->designModeBehavior) + return false; + + switch (event->key()) { + case Qt::Key_V: + data->_q_changeToSingleSelectTool(); + break; +// disabled because multiselection does not do anything useful without design mode +// case Qt::Key_M: +// data->_q_changeToMarqueeSelectTool(); +// break; + case Qt::Key_I: + data->_q_changeToColorPickerTool(); + break; + case Qt::Key_Z: + data->_q_changeToZoomTool(); + break; + case Qt::Key_Enter: + case Qt::Key_Return: + if (!data->selectedItems().isEmpty()) + data->subcomponentEditorTool->setCurrentItem(data->selectedItems().first()); + break; + case Qt::Key_Space: + setAnimationPaused(!data->animationPaused); + break; + default: + break; + } + + data->currentTool->keyReleaseEvent(event); + return true; +} + +void QDeclarativeViewObserverPrivate::_q_createQmlObject(const QString &qml, QObject *parent, + const QStringList &importList, + const QString &filename) +{ + if (!parent) + return; + + QString imports; + foreach (const QString &s, importList) { + imports += s; + imports += QLatin1Char('\n'); + } + + QDeclarativeContext *parentContext = view->engine()->contextForObject(parent); + QDeclarativeComponent component(view->engine(), q); + QByteArray constructedQml = QString(imports + qml).toLatin1(); + + component.setData(constructedQml, QUrl::fromLocalFile(filename)); + QObject *newObject = component.create(parentContext); + if (newObject) { + newObject->setParent(parent); + QDeclarativeItem *parentItem = qobject_cast(parent); + QDeclarativeItem *newItem = qobject_cast(newObject); + if (parentItem && newItem) + newItem->setParentItem(parentItem); + } +} + +void QDeclarativeViewObserverPrivate::_q_reparentQmlObject(QObject *object, QObject *newParent) +{ + if (!newParent) + return; + + object->setParent(newParent); + QDeclarativeItem *newParentItem = qobject_cast(newParent); + QDeclarativeItem *item = qobject_cast(object); + if (newParentItem && item) + item->setParentItem(newParentItem); +} + +void QDeclarativeViewObserverPrivate::_q_clearComponentCache() +{ + view->engine()->clearComponentCache(); +} + +void QDeclarativeViewObserverPrivate::_q_removeFromSelection(QObject *obj) +{ + QList items = selectedItems(); + if (QGraphicsItem *item = qobject_cast(obj)) + items.removeOne(item); + setSelectedItems(items); +} + +QGraphicsItem *QDeclarativeViewObserverPrivate::currentRootItem() const +{ + return subcomponentEditorTool->currentRootItem(); +} + +bool QDeclarativeViewObserver::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) + return false; + + if (data->currentToolMode != Constants::SelectionToolMode + && data->currentToolMode != Constants::MarqueeSelectionToolMode) + return true; + + QGraphicsItem *itemToEnter = 0; + QList itemList = data->view->items(event->pos()); + data->filterForSelection(itemList); + + if (data->selectedItems().isEmpty() && !itemList.isEmpty()) { + itemToEnter = itemList.first(); + } else if (!data->selectedItems().isEmpty() && !itemList.isEmpty()) { + itemToEnter = itemList.first(); + } + + if (itemToEnter) + itemToEnter = data->subcomponentEditorTool->firstChildOfContext(itemToEnter); + + data->subcomponentEditorTool->setCurrentItem(itemToEnter); + data->subcomponentEditorTool->mouseDoubleClickEvent(event); + + if ((event->buttons() & Qt::LeftButton) && itemToEnter) { + if (QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject()) + setSelectedItems(QList() << objectToEnter); + } + + return true; +} + +bool QDeclarativeViewObserver::wheelEvent(QWheelEvent *event) +{ + if (!data->designModeBehavior) + return false; + data->currentTool->wheelEvent(event); + return true; +} + +void QDeclarativeViewObserverPrivate::enterContext(QGraphicsItem *itemToEnter) +{ + QGraphicsItem *itemUnderCurrentContext = itemToEnter; + if (itemUnderCurrentContext) + itemUnderCurrentContext = subcomponentEditorTool->firstChildOfContext(itemToEnter); + + if (itemUnderCurrentContext) + subcomponentEditorTool->setCurrentItem(itemToEnter); +} + +void QDeclarativeViewObserver::setDesignModeBehavior(bool value) +{ + emit designModeBehaviorChanged(value); + + if (data->toolBox) + data->toolBox->toolBar()->setDesignModeBehavior(value); + sendDesignModeBehavior(value); + + data->designModeBehavior = value; + if (data->subcomponentEditorTool) { + data->subcomponentEditorTool->clear(); + data->clearHighlight(); + data->setSelectedItems(QList()); + + if (data->view->rootObject()) + data->subcomponentEditorTool->pushContext(data->view->rootObject()); + } + + if (!data->designModeBehavior) + data->clearEditorItems(); +} + +bool QDeclarativeViewObserver::designModeBehavior() +{ + return data->designModeBehavior; +} + +bool QDeclarativeViewObserver::showAppOnTop() const +{ + return data->showAppOnTop; +} + +void QDeclarativeViewObserver::setShowAppOnTop(bool appOnTop) +{ + if (data->view) { + QWidget *window = data->view->window(); + Qt::WindowFlags flags = window->windowFlags(); + if (appOnTop) + flags |= Qt::WindowStaysOnTopHint; + else + flags &= ~Qt::WindowStaysOnTopHint; + + window->setWindowFlags(flags); + window->show(); + } + + data->showAppOnTop = appOnTop; + sendShowAppOnTop(appOnTop); + + emit showAppOnTopChanged(appOnTop); +} + +void QDeclarativeViewObserverPrivate::changeTool(Constants::DesignTool tool, + Constants::ToolFlags /*flags*/) +{ + switch (tool) { + case Constants::SelectionToolMode: + _q_changeToSingleSelectTool(); + break; + case Constants::NoTool: + default: + currentTool = 0; + break; + } +} + +void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(QList items) +{ + foreach (const QWeakPointer &obj, currentSelection) { + if (QGraphicsItem *item = obj.data()) { + if (!items.contains(item)) { + QObject::disconnect(obj.data(), SIGNAL(destroyed(QObject*)), + this, SLOT(_q_removeFromSelection(QObject*))); + currentSelection.removeOne(obj); + } + } + } + + foreach (QGraphicsItem *item, items) { + if (item) { + if (QGraphicsObject *obj = item->toGraphicsObject()) { + QObject::connect(obj, SIGNAL(destroyed(QObject*)), + this, SLOT(_q_removeFromSelection(QObject*))); + currentSelection.append(obj); + } + } + } + + currentTool->updateSelectedItems(); +} + +void QDeclarativeViewObserverPrivate::setSelectedItems(QList items) +{ + QList > oldList = currentSelection; + setSelectedItemsForTools(items); + if (oldList != currentSelection) { + QList objectList; + foreach (const QWeakPointer &graphicsObject, currentSelection) { + if (graphicsObject) + objectList << graphicsObject.data(); + } + + q->sendCurrentObjects(objectList); + } +} + +QList QDeclarativeViewObserverPrivate::selectedItems() const +{ + QList selection; + foreach (const QWeakPointer &selectedObject, currentSelection) { + if (selectedObject.data()) + selection << selectedObject.data(); + } + + return selection; +} + +void QDeclarativeViewObserver::setSelectedItems(QList items) +{ + data->setSelectedItems(items); +} + +QList QDeclarativeViewObserver::selectedItems() const +{ + return data->selectedItems(); +} + +QDeclarativeView *QDeclarativeViewObserver::declarativeView() +{ + return data->view; +} + +void QDeclarativeViewObserverPrivate::clearHighlight() +{ + boundingRectHighlighter->clear(); +} + +void QDeclarativeViewObserverPrivate::highlight(QGraphicsObject * item, ContextFlags flags) +{ + highlight(QList() << item, flags); +} + +void QDeclarativeViewObserverPrivate::highlight(QList items, ContextFlags flags) +{ + if (items.isEmpty()) + return; + + QList objectList; + foreach (QGraphicsItem *item, items) { + QGraphicsItem *child = item; + if (flags & ContextSensitive) + child = subcomponentEditorTool->firstChildOfContext(item); + + if (child) { + QGraphicsObject *childObject = child->toGraphicsObject(); + if (childObject) + objectList << childObject; + } + } + + boundingRectHighlighter->highlight(objectList); +} + +bool QDeclarativeViewObserverPrivate::mouseInsideContextItem() const +{ + return subcomponentEditorTool->containsCursor(cursorPos.toPoint()); +} + +QList QDeclarativeViewObserverPrivate::selectableItems( + const QPointF &scenePos) const +{ + QList itemlist = view->scene()->items(scenePos); + return filterForCurrentContext(itemlist); +} + +QList QDeclarativeViewObserverPrivate::selectableItems(const QPoint &pos) const +{ + QList itemlist = view->items(pos); + return filterForCurrentContext(itemlist); +} + +QList QDeclarativeViewObserverPrivate::selectableItems( + const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const +{ + QList itemlist = view->scene()->items(sceneRect, selectionMode); + + return filterForCurrentContext(itemlist); +} + +void QDeclarativeViewObserverPrivate::_q_changeToSingleSelectTool() +{ + currentToolMode = Constants::SelectionToolMode; + selectionTool->setRubberbandSelectionMode(false); + + changeToSelectTool(); + + emit q->selectToolActivated(); + q->sendCurrentTool(Constants::SelectionToolMode); +} + +void QDeclarativeViewObserverPrivate::changeToSelectTool() +{ + if (currentTool == selectionTool) + return; + + currentTool->clear(); + currentTool = selectionTool; + currentTool->clear(); + currentTool->updateSelectedItems(); +} + +void QDeclarativeViewObserverPrivate::_q_changeToMarqueeSelectTool() +{ + changeToSelectTool(); + currentToolMode = Constants::MarqueeSelectionToolMode; + selectionTool->setRubberbandSelectionMode(true); + + emit q->marqueeSelectToolActivated(); + q->sendCurrentTool(Constants::MarqueeSelectionToolMode); +} + +void QDeclarativeViewObserverPrivate::_q_changeToZoomTool() +{ + currentToolMode = Constants::ZoomMode; + currentTool->clear(); + currentTool = zoomTool; + currentTool->clear(); + + emit q->zoomToolActivated(); + q->sendCurrentTool(Constants::ZoomMode); +} + +void QDeclarativeViewObserverPrivate::_q_changeToColorPickerTool() +{ + if (currentTool == colorPickerTool) + return; + + currentToolMode = Constants::ColorPickerMode; + currentTool->clear(); + currentTool = colorPickerTool; + currentTool->clear(); + + emit q->colorPickerActivated(); + q->sendCurrentTool(Constants::ColorPickerMode); +} + +void QDeclarativeViewObserverPrivate::_q_changeContextPathIndex(int index) +{ + subcomponentEditorTool->setContext(index); +} + +void QDeclarativeViewObserver::setAnimationSpeed(qreal slowDownFactor) +{ + Q_ASSERT(slowDownFactor > 0); + if (data->slowDownFactor == slowDownFactor) + return; + + animationSpeedChangeRequested(slowDownFactor); + sendAnimationSpeed(slowDownFactor); +} + +void QDeclarativeViewObserver::setAnimationPaused(bool paused) +{ + if (data->animationPaused == paused) + return; + + animationPausedChangeRequested(paused); + sendAnimationPaused(paused); +} + +void QDeclarativeViewObserver::animationSpeedChangeRequested(qreal factor) +{ + if (data->slowDownFactor != factor) { + data->slowDownFactor = factor; + emit animationSpeedChanged(factor); + } + + const float effectiveFactor = data->animationPaused ? 0 : factor; + QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor); +} + +void QDeclarativeViewObserver::animationPausedChangeRequested(bool paused) +{ + if (data->animationPaused != paused) { + data->animationPaused = paused; + emit animationPausedChanged(paused); + } + + const float effectiveFactor = paused ? 0 : data->slowDownFactor; + QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor); +} + + +void QDeclarativeViewObserverPrivate::_q_applyChangesFromClient() +{ +} + + +QList QDeclarativeViewObserverPrivate::filterForSelection( + QList &itemlist) const +{ + foreach (QGraphicsItem *item, itemlist) { + if (isEditorItem(item) || !subcomponentEditorTool->isChildOfContext(item)) + itemlist.removeOne(item); + } + + return itemlist; +} + +QList QDeclarativeViewObserverPrivate::filterForCurrentContext( + QList &itemlist) const +{ + foreach (QGraphicsItem *item, itemlist) { + + if (isEditorItem(item) || !subcomponentEditorTool->isDirectChildOfContext(item)) { + + // if we're a child, but not directly, replace with the parent that is directly in context. + if (QGraphicsItem *contextParent = subcomponentEditorTool->firstChildOfContext(item)) { + if (contextParent != item) { + if (itemlist.contains(contextParent)) { + itemlist.removeOne(item); + } else { + itemlist.replace(itemlist.indexOf(item), contextParent); + } + } + } else { + itemlist.removeOne(item); + } + } + } + + return itemlist; +} + +bool QDeclarativeViewObserverPrivate::isEditorItem(QGraphicsItem *item) const +{ + return (item->type() == Constants::EditorItemType + || item->type() == Constants::ResizeHandleItemType + || item->data(Constants::EditorItemDataKey).toBool()); +} + +void QDeclarativeViewObserverPrivate::_q_onStatusChanged(QDeclarativeView::Status status) +{ + if (status == QDeclarativeView::Ready) { + if (view->rootObject()) { + if (subcomponentEditorTool->contextIndex() != -1) + subcomponentEditorTool->clear(); + subcomponentEditorTool->pushContext(view->rootObject()); + } + q->sendReloaded(); + } +} + +void QDeclarativeViewObserverPrivate::_q_onCurrentObjectsChanged(QList objects) +{ + QList items; + QList gfxObjects; + foreach (QObject *obj, objects) { + QDeclarativeItem* declarativeItem = qobject_cast(obj); + if (declarativeItem) { + items << declarativeItem; + if (QGraphicsObject *gfxObj = declarativeItem->toGraphicsObject()) + gfxObjects << gfxObj; + } + } + if (designModeBehavior) { + setSelectedItemsForTools(items); + clearHighlight(); + highlight(gfxObjects, QDeclarativeViewObserverPrivate::IgnoreContext); + } +} + +// adjusts bounding boxes on edges of screen to be visible +QRectF QDeclarativeViewObserver::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace) +{ + int marginFromEdge = 1; + QRectF boundingRect(boundingRectInSceneSpace); + if (qAbs(boundingRect.left()) - 1 < 2) + boundingRect.setLeft(marginFromEdge); + + QRect rect = data->view->rect(); + + if (boundingRect.right() >= rect.right()) + boundingRect.setRight(rect.right() - marginFromEdge); + + if (qAbs(boundingRect.top()) - 1 < 2) + boundingRect.setTop(marginFromEdge); + + if (boundingRect.bottom() >= rect.bottom()) + boundingRect.setBottom(rect.bottom() - marginFromEdge); + + return boundingRect; +} + +void QDeclarativeViewObserverPrivate::createToolBox() +{ + toolBox = new ToolBox(q->declarativeView()); + + QmlToolBar *toolBar = toolBox->toolBar(); + + QObject::connect(q, SIGNAL(selectedColorChanged(QColor)), + toolBar, SLOT(setColorBoxColor(QColor))); + + QObject::connect(q, SIGNAL(designModeBehaviorChanged(bool)), + toolBar, SLOT(setDesignModeBehavior(bool))); + + QObject::connect(toolBar, SIGNAL(designModeBehaviorChanged(bool)), + q, SLOT(setDesignModeBehavior(bool))); + QObject::connect(toolBar, SIGNAL(animationSpeedChanged(qreal)), q, SLOT(setAnimationSpeed(qreal))); + QObject::connect(toolBar, SIGNAL(animationPausedChanged(bool)), q, SLOT(setAnimationPaused(bool))); + QObject::connect(toolBar, SIGNAL(colorPickerSelected()), this, SLOT(_q_changeToColorPickerTool())); + QObject::connect(toolBar, SIGNAL(zoomToolSelected()), this, SLOT(_q_changeToZoomTool())); + QObject::connect(toolBar, SIGNAL(selectToolSelected()), this, SLOT(_q_changeToSingleSelectTool())); + QObject::connect(toolBar, SIGNAL(marqueeSelectToolSelected()), + this, SLOT(_q_changeToMarqueeSelectTool())); + + QObject::connect(toolBar, SIGNAL(applyChangesFromQmlFileSelected()), + this, SLOT(_q_applyChangesFromClient())); + + QObject::connect(q, SIGNAL(animationSpeedChanged(qreal)), toolBar, SLOT(setAnimationSpeed(qreal))); + QObject::connect(q, SIGNAL(animationPausedChanged(bool)), toolBar, SLOT(setAnimationPaused(bool))); + + QObject::connect(q, SIGNAL(selectToolActivated()), toolBar, SLOT(activateSelectTool())); + + // disabled features + //connect(d->m_toolBar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient())); + //connect(q, SIGNAL(resizeToolActivated()), d->m_toolBar, SLOT(activateSelectTool())); + //connect(q, SIGNAL(moveToolActivated()), d->m_toolBar, SLOT(activateSelectTool())); + + QObject::connect(q, SIGNAL(colorPickerActivated()), toolBar, SLOT(activateColorPicker())); + QObject::connect(q, SIGNAL(zoomToolActivated()), toolBar, SLOT(activateZoom())); + QObject::connect(q, SIGNAL(marqueeSelectToolActivated()), + toolBar, SLOT(activateMarqueeSelectTool())); +} + +void QDeclarativeViewObserver::handleMessage(const QByteArray &message) +{ + QDataStream ds(message); + + ObserverProtocol::Message type; + ds >> type; + + switch (type) { + case ObserverProtocol::SetCurrentObjects: { + int itemCount = 0; + ds >> itemCount; + + QList selectedObjects; + for (int i = 0; i < itemCount; ++i) { + int debugId = -1; + ds >> debugId; + QObject *obj = QDeclarativeDebugService::objectForId(debugId); + + if (obj) + selectedObjects << obj; + } + + data->_q_onCurrentObjectsChanged(selectedObjects); + break; + } + case ObserverProtocol::Reload: { + data->_q_reloadView(); + break; + } + case ObserverProtocol::SetAnimationSpeed: { + qreal speed; + ds >> speed; + animationSpeedChangeRequested(speed); + break; + } + case ObserverProtocol::SetAnimationPaused: { + bool paused; + ds >> paused; + animationPausedChangeRequested(paused); + break; + } + case ObserverProtocol::ChangeTool: { + ObserverProtocol::Tool tool; + ds >> tool; + switch (tool) { + case ObserverProtocol::ColorPickerTool: + data->_q_changeToColorPickerTool(); + break; + case ObserverProtocol::SelectTool: + data->_q_changeToSingleSelectTool(); + break; + case ObserverProtocol::SelectMarqueeTool: + data->_q_changeToMarqueeSelectTool(); + break; + case ObserverProtocol::ZoomTool: + data->_q_changeToZoomTool(); + break; + default: + qWarning() << "Warning: Unhandled tool:" << tool; + } + break; + } + case ObserverProtocol::SetDesignMode: { + bool inDesignMode; + ds >> inDesignMode; + setDesignModeBehavior(inDesignMode); + break; + } + case ObserverProtocol::ShowAppOnTop: { + bool showOnTop; + ds >> showOnTop; + setShowAppOnTop(showOnTop); + break; + } + case ObserverProtocol::CreateObject: { + QString qml; + int parentId; + QString filename; + QStringList imports; + ds >> qml >> parentId >> imports >> filename; + data->_q_createQmlObject(qml, QDeclarativeDebugService::objectForId(parentId), + imports, filename); + break; + } + case ObserverProtocol::DestroyObject: { + int debugId; + ds >> debugId; + if (QObject* obj = QDeclarativeDebugService::objectForId(debugId)) + obj->deleteLater(); + break; + } + case ObserverProtocol::MoveObject: { + int debugId, newParent; + ds >> debugId >> newParent; + data->_q_reparentQmlObject(QDeclarativeDebugService::objectForId(debugId), + QDeclarativeDebugService::objectForId(newParent)); + break; + } + case ObserverProtocol::ObjectIdList: { + int itemCount; + ds >> itemCount; + data->stringIdForObjectId.clear(); + for (int i = 0; i < itemCount; ++i) { + int itemDebugId; + QString itemIdString; + ds >> itemDebugId + >> itemIdString; + + data->stringIdForObjectId.insert(itemDebugId, itemIdString); + } + break; + } + case ObserverProtocol::SetContextPathIdx: { + int contextPathIndex; + ds >> contextPathIndex; + data->_q_changeContextPathIndex(contextPathIndex); + break; + } + case ObserverProtocol::ClearComponentCache: { + data->_q_clearComponentCache(); + break; + } + default: + qWarning() << "Warning: Not handling message:" << type; + } +} + +void QDeclarativeViewObserver::sendDesignModeBehavior(bool inDesignMode) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::SetDesignMode + << inDesignMode; + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendCurrentObjects(QList objects) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::CurrentObjectsChanged + << objects.length(); + + foreach (QObject *object, objects) { + int id = QDeclarativeDebugService::idForObject(object); + ds << id; + } + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendCurrentTool(Constants::DesignTool toolId) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::ToolChanged + << toolId; + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendAnimationSpeed(qreal slowDownFactor) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::AnimationSpeedChanged + << slowDownFactor; + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendAnimationPaused(bool paused) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::AnimationPausedChanged + << paused; + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendReloaded() +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::Reloaded; + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendShowAppOnTop(bool showAppOnTop) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::ShowAppOnTop << showAppOnTop; + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendColorChanged(const QColor &color) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::ColorChanged + << color; + + data->debugService->sendMessage(message); +} + +void QDeclarativeViewObserver::sendContextPathUpdated(const QStringList &contextPath) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << ObserverProtocol::ContextPathUpdated + << contextPath; + + data->debugService->sendMessage(message); +} + +QString QDeclarativeViewObserver::idStringForObject(QObject *obj) const +{ + int id = QDeclarativeDebugService::idForObject(obj); + QString idString = data->stringIdForObjectId.value(id, QString()); + return idString; +} + +QT_END_NAMESPACE + +#include "qdeclarativeviewobserver.moc" diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h new file mode 100644 index 0000000..6e986c2 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p.h @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEVIEWOBSERVER_P_H +#define QDECLARATIVEVIEWOBSERVER_P_H + +#include +#include "qmlobserverconstants_p.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QDeclarativeItem) +QT_FORWARD_DECLARE_CLASS(QMouseEvent) +QT_FORWARD_DECLARE_CLASS(QToolBar) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserverPrivate; + +class QDeclarativeViewObserver : public QObject +{ + Q_OBJECT + +public: + explicit QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent = 0); + ~QDeclarativeViewObserver(); + + void setSelectedItems(QList items); + QList selectedItems() const; + + QDeclarativeView *declarativeView(); + + QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); + + bool showAppOnTop() const; + + void sendDesignModeBehavior(bool inDesignMode); + void sendCurrentObjects(QList items); + void sendAnimationSpeed(qreal slowDownFactor); + void sendAnimationPaused(bool paused); + void sendCurrentTool(Constants::DesignTool toolId); + void sendReloaded(); + void sendShowAppOnTop(bool showAppOnTop); + + QString idStringForObject(QObject *obj) const; + +public Q_SLOTS: + void sendColorChanged(const QColor &color); + void sendContextPathUpdated(const QStringList &contextPath); + + void setDesignModeBehavior(bool value); + bool designModeBehavior(); + + void setShowAppOnTop(bool appOnTop); + + void setAnimationSpeed(qreal factor); + void setAnimationPaused(bool paused); + + void setObserverContext(int contextIndex); + +Q_SIGNALS: + void designModeBehaviorChanged(bool inDesignMode); + void showAppOnTopChanged(bool showAppOnTop); + void reloadRequested(); + void marqueeSelectToolActivated(); + void selectToolActivated(); + void zoomToolActivated(); + void colorPickerActivated(); + void selectedColorChanged(const QColor &color); + + void animationSpeedChanged(qreal factor); + void animationPausedChanged(bool paused); + + void inspectorContextCleared(); + void inspectorContextPushed(const QString &contextTitle); + void inspectorContextPopped(); + +protected: + bool eventFilter(QObject *obj, QEvent *event); + + bool leaveEvent(QEvent *); + bool mousePressEvent(QMouseEvent *event); + bool mouseMoveEvent(QMouseEvent *event); + bool mouseReleaseEvent(QMouseEvent *event); + bool keyPressEvent(QKeyEvent *event); + bool keyReleaseEvent(QKeyEvent *keyEvent); + bool mouseDoubleClickEvent(QMouseEvent *event); + bool wheelEvent(QWheelEvent *event); + + void setSelectedItemsForTools(QList items); + +private slots: + void handleMessage(const QByteArray &message); + + void animationSpeedChangeRequested(qreal factor); + void animationPausedChangeRequested(bool paused); + +private: + Q_DISABLE_COPY(QDeclarativeViewObserver) + + inline QDeclarativeViewObserverPrivate *d_func() { return data.data(); } + QScopedPointer data; + friend class QDeclarativeViewObserverPrivate; + friend class AbstractLiveEditTool; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEVIEWOBSERVER_P_H diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h new file mode 100644 index 0000000..6022555 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver_p_p.h @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEVIEWOBSERVER_P_P_H +#define QDECLARATIVEVIEWOBSERVER_P_P_H + +#include "qdeclarativeviewobserver_p.h" + +#include +#include + +#include "QtDeclarative/private/qdeclarativeobserverservice_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QDeclarativeViewObserver; +class LiveSelectionTool; +class ZoomTool; +class ColorPickerTool; +class LiveLayerItem; +class BoundingRectHighlighter; +class SubcomponentEditorTool; +class ToolBox; +class AbstractLiveEditTool; + +class QDeclarativeViewObserverPrivate : public QObject +{ + Q_OBJECT +public: + enum ContextFlags { + IgnoreContext, + ContextSensitive + }; + + QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *); + ~QDeclarativeViewObserverPrivate(); + + QDeclarativeView *view; + QDeclarativeViewObserver *q; + QDeclarativeObserverService *debugService; + QWeakPointer viewport; + QHash stringIdForObjectId; + + QPointF cursorPos; + QList > currentSelection; + + Constants::DesignTool currentToolMode; + AbstractLiveEditTool *currentTool; + + LiveSelectionTool *selectionTool; + ZoomTool *zoomTool; + ColorPickerTool *colorPickerTool; + SubcomponentEditorTool *subcomponentEditorTool; + LiveLayerItem *manipulatorLayer; + + BoundingRectHighlighter *boundingRectHighlighter; + + bool designModeBehavior; + bool showAppOnTop; + + bool animationPaused; + qreal slowDownFactor; + + ToolBox *toolBox; + + void setViewport(QWidget *widget); + + void clearEditorItems(); + void createToolBox(); + void changeToSelectTool(); + QList filterForCurrentContext(QList &itemlist) const; + QList filterForSelection(QList &itemlist) const; + + QList selectableItems(const QPoint &pos) const; + QList selectableItems(const QPointF &scenePos) const; + QList selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; + + void setSelectedItemsForTools(QList items); + void setSelectedItems(QList items); + QList selectedItems() const; + + void changeTool(Constants::DesignTool tool, + Constants::ToolFlags flags = Constants::NoToolFlags); + + void clearHighlight(); + void highlight(QList item, ContextFlags flags = ContextSensitive); + void highlight(QGraphicsObject *item, ContextFlags flags = ContextSensitive); + + bool mouseInsideContextItem() const; + bool isEditorItem(QGraphicsItem *item) const; + + QGraphicsItem *currentRootItem() const; + + void enterContext(QGraphicsItem *itemToEnter); + +public slots: + void _q_setToolBoxVisible(bool visible); + + void _q_reloadView(); + void _q_onStatusChanged(QDeclarativeView::Status status); + void _q_onCurrentObjectsChanged(QList objects); + void _q_applyChangesFromClient(); + void _q_createQmlObject(const QString &qml, QObject *parent, + const QStringList &imports, const QString &filename = QString()); + void _q_reparentQmlObject(QObject *, QObject *); + + void _q_changeToSingleSelectTool(); + void _q_changeToMarqueeSelectTool(); + void _q_changeToZoomTool(); + void _q_changeToColorPickerTool(); + void _q_changeContextPathIndex(int index); + void _q_clearComponentCache(); + void _q_removeFromSelection(QObject *); + +public: + static QDeclarativeViewObserverPrivate *get(QDeclarativeViewObserver *v) { return v->d_func(); } +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEVIEWOBSERVER_P_P_H diff --git a/src/plugins/qmltooling/declarativeobserver/qmlobserverconstants_p.h b/src/plugins/qmltooling/declarativeobserver/qmlobserverconstants_p.h new file mode 100644 index 0000000..353e235 --- /dev/null +++ b/src/plugins/qmltooling/declarativeobserver/qmlobserverconstants_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLOBSERVERCONSTANTS_H +#define QMLOBSERVERCONSTANTS_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +namespace Constants { + +enum DesignTool { + NoTool = 0, + SelectionToolMode = 1, + MarqueeSelectionToolMode = 2, + MoveToolMode = 3, + ResizeToolMode = 4, + ColorPickerMode = 5, + ZoomMode = 6 +}; + +enum ToolFlags { + NoToolFlags = 0, + UseCursorPos = 1 +}; + +static const int DragStartTime = 50; + +static const int DragStartDistance = 20; + +static const double ZoomSnapDelta = 0.04; + +static const int EditorItemDataKey = 1000; + +enum GraphicsItemTypes { + EditorItemType = 0xEAAA, + ResizeHandleItemType = 0xEAEA +}; + + +} // namespace Constants + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLOBSERVERCONSTANTS_H diff --git a/src/plugins/qmltooling/qmltooling.pro b/src/plugins/qmltooling/qmltooling.pro index 01cf1a9..832d57c 100644 --- a/src/plugins/qmltooling/qmltooling.pro +++ b/src/plugins/qmltooling/qmltooling.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = tcpserver +SUBDIRS = tcpserver declarativeobserver diff --git a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp index e1298e8..44b2886 100644 --- a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp +++ b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp @@ -41,6 +41,7 @@ #include "qtcpserverconnection.h" +#include #include #include diff --git a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h index 66a10e1..62791d3 100644 --- a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h +++ b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h @@ -42,7 +42,6 @@ #ifndef QTCPSERVERCONNECTION_H #define QTCPSERVERCONNECTION_H -#include #include QT_BEGIN_NAMESPACE -- cgit v0.12 From 5517cc588c39814530b8bfd957821f55be42acf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 18 Apr 2011 17:20:49 +0200 Subject: Introduced a CONFIG option that enables declarative debug services This replaces the need for applications to explicitly make a call to enable the debug services, and rather does it in declarative.h when the 'declarative_debug' CONFIG option is used. Done-with: Kai Koehne Change-Id: I817f22a4ec9226a1ee2d080c1f5bb75d8599a06e Reviewed-by: Martin Jones Reviewed-by: Michael Brasser --- mkspecs/features/declarative_debug.prf | 1 + src/declarative/qml/qdeclarative.h | 11 +++++++++++ src/declarative/qml/qdeclarativeengine.cpp | 11 +++++++++++ tools/qml/main.cpp | 3 --- tools/qml/qml.pro | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 mkspecs/features/declarative_debug.prf diff --git a/mkspecs/features/declarative_debug.prf b/mkspecs/features/declarative_debug.prf new file mode 100644 index 0000000..b0248f0 --- /dev/null +++ b/mkspecs/features/declarative_debug.prf @@ -0,0 +1 @@ +contains(QT, declarative):DEFINES += QT_DECLARATIVE_DEBUG diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h index 5da7901..28a6be4 100644 --- a/src/declarative/qml/qdeclarative.h +++ b/src/declarative/qml/qdeclarative.h @@ -405,6 +405,17 @@ QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true) return qmlAttachedPropertiesObject(&idx, obj, &T::staticMetaObject, create); } +// Enable debugging before any QDeclarativeEngine is created +struct Q_DECLARATIVE_EXPORT QDeclarativeDebuggingEnabler +{ + QDeclarativeDebuggingEnabler(); +}; + +// Execute code in constructor before first QDeclarativeEngine is instantiated +#if defined(QT_DECLARATIVE_DEBUG) +static QDeclarativeDebuggingEnabler qmlEnableDebuggingHelper; +#endif + QT_END_NAMESPACE QML_DECLARE_TYPE(QObject) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index fb3e136..2841b15 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1088,6 +1088,17 @@ QObject *qmlAttachedPropertiesObject(int *idCache, const QObject *object, return qmlAttachedPropertiesObjectById(*idCache, object, create); } +QDeclarativeDebuggingEnabler::QDeclarativeDebuggingEnabler() +{ +#ifndef QDECLARATIVE_NO_DEBUG_PROTOCOL + if (!QDeclarativeEnginePrivate::qml_debugging_enabled) { + qWarning("Qml debugging is enabled. Only use this in a safe environment!"); + } + QDeclarativeEnginePrivate::qml_debugging_enabled = true; +#endif +} + + class QDeclarativeDataExtended { public: QDeclarativeDataExtended(); diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 24a4940..3b20996 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -52,7 +52,6 @@ #include #include #include "qdeclarativetester.h" -#include QT_USE_NAMESPACE @@ -539,8 +538,6 @@ int main(int argc, char ** argv) QApplication::setGraphicsSystem(QLatin1String("raster")); #endif - QDeclarativeDebugHelper::enableDebugging(); - Application app(argc, argv); app.setApplicationName(QLatin1String("QtQmlViewer")); app.setOrganizationName(QLatin1String("Nokia")); diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index 9467b70..cf685a8 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -1,5 +1,5 @@ TEMPLATE = app -CONFIG += qt uic +CONFIG += qt uic declarative_debug DESTDIR = ../../bin include(qml.pri) -- cgit v0.12 From 713a4c2fc2a52277a9b820608e3270507850ac47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 3 May 2011 14:46:43 +0200 Subject: Removed some trailing whitespace --- src/declarative/qml/qdeclarativeengine.cpp | 34 +++++++++++++++--------------- src/declarative/qml/qdeclarativeengine_p.h | 10 ++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 2841b15..3cb2112 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -124,7 +124,7 @@ QT_BEGIN_NAMESPACE \brief The QtObject element is the most basic element in QML. The QtObject element is a non-visual element which contains only the - objectName property. + objectName property. It can be useful to create a QtObject if you need an extremely lightweight element to enclose a set of custom properties: @@ -139,7 +139,7 @@ QT_BEGIN_NAMESPACE This property holds the QObject::objectName for this specific object instance. This allows a C++ application to locate an item within a QML component - using the QObject::findChild() method. For example, the following C++ + using the QObject::findChild() method. For example, the following C++ application locates the child \l Rectangle item and dynamically changes its \c color value: @@ -153,7 +153,7 @@ QT_BEGIN_NAMESPACE Rectangle { anchors.fill: parent - color: "red" + color: "red" objectName: "myRect" } } @@ -167,7 +167,7 @@ QT_BEGIN_NAMESPACE view.show(); QDeclarativeItem *item = view.rootObject()->findChild("myRect"); - if (item) + if (item) item->setProperty("color", QColor(Qt::yellow)); \endcode */ @@ -203,7 +203,7 @@ void QDeclarativeEnginePrivate::defineModule() \keyword QmlGlobalQtObject -\brief The \c Qt object provides useful enums and functions from Qt, for use in all QML files. +\brief The \c Qt object provides useful enums and functions from Qt, for use in all QML files. The \c Qt object is a global object with utility functions, properties and enums. @@ -761,7 +761,7 @@ QNetworkAccessManager *QDeclarativeEngine::networkAccessManager() const /*! Sets the \a provider to use for images requested via the \e - image: url scheme, with host \a providerId. The QDeclarativeEngine + image: url scheme, with host \a providerId. The QDeclarativeEngine takes ownership of \a provider. Image providers enable support for pixmap and threaded image @@ -1070,7 +1070,7 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool cre rv = pf(const_cast(object)); - if (rv) + if (rv) data->attachedProperties()->insert(id, rv); return rv; @@ -1273,7 +1273,7 @@ Returns a \l Component object created using the QML file at the specified \a url or \c null if an empty string was given. The returned component's \l Component::status property indicates whether the -component was successfully created. If the status is \c Component.Error, +component was successfully created. If the status is \c Component.Error, see \l Component::errorString() for an error description. Call \l {Component::createObject()}{Component.createObject()} on the returned @@ -1633,7 +1633,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr return engine->newVariant(QVariant::fromValue(date.toString(format))); } else if (formatArg.isNumber()) { enumFormat = Qt::DateFormat(formatArg.toUInt32()); - } else { + } else { return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid datetime format")); } } @@ -1698,7 +1698,7 @@ QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine } /*! -\qmlmethod rect Qt::rect(int x, int y, int width, int height) +\qmlmethod rect Qt::rect(int x, int y, int width, int height) Returns a \c rect with the top-left corner at \c x, \c y and the specified \c width and \c height. @@ -1870,7 +1870,7 @@ Binary to ASCII - this function returns a base64 encoding of \c data. */ QScriptValue QDeclarativeEnginePrivate::btoa(QScriptContext *ctxt, QScriptEngine *) { - if (ctxt->argumentCount() != 1) + if (ctxt->argumentCount() != 1) return ctxt->throwError(QLatin1String("Qt.btoa(): Invalid arguments")); QByteArray data = ctxt->argument(0).toString().toUtf8(); @@ -1885,7 +1885,7 @@ ASCII to binary - this function returns a base64 decoding of \c data. QScriptValue QDeclarativeEnginePrivate::atob(QScriptContext *ctxt, QScriptEngine *) { - if (ctxt->argumentCount() != 1) + if (ctxt->argumentCount() != 1) return ctxt->throwError(QLatin1String("Qt.atob(): Invalid arguments")); QByteArray data = ctxt->argument(0).toString().toUtf8(); @@ -2304,7 +2304,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(const QMetaObj } } -QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeType *type, int minorVersion, +QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeType *type, int minorVersion, QDeclarativeError &error) { QList types; @@ -2313,7 +2313,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy const QMetaObject *metaObject = type->metaObject(); while (metaObject) { - QDeclarativeType *t = QDeclarativeMetaType::qmlType(metaObject, type->module(), + QDeclarativeType *t = QDeclarativeMetaType::qmlType(metaObject, type->module(), type->majorVersion(), minorVersion); if (t) { maxMinorVersion = qMax(maxMinorVersion, t->minorVersion()); @@ -2357,7 +2357,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy // Signals override: // * other signals and methods of the same name. - // * properties named on + // * properties named on // * automatic Changed notify signals // Methods override: @@ -2382,7 +2382,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy QDeclarativePropertyCache::Data *current = d; while (!overloadError && current) { current = d->overrideData(current); - if (current && raw->isAllowedInRevision(current)) + if (current && raw->isAllowedInRevision(current)) overloadError = true; } } @@ -2390,7 +2390,7 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::createCache(QDeclarativeTy if (overloadError) { if (hasCopied) raw->release(); - + error.setDescription(QLatin1String("Type ") + QString::fromUtf8(type->qmlTypeName()) + QLatin1String(" ") + QString::number(type->majorVersion()) + QLatin1String(".") + QString::number(minorVersion) + QLatin1String(" contains an illegal property \"") + overloadName + QLatin1String("\". This is an error in the type's implementation.")); return 0; } diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 1777c88..fd851f7 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -331,14 +331,14 @@ public: /*! Returns a QDeclarativePropertyCache for \a obj if one is available. -If \a obj is null, being deleted or contains a dynamic meta object 0 +If \a obj is null, being deleted or contains a dynamic meta object 0 is returned. The returned cache is not referenced, so if it is to be stored, call addref(). */ -QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj) +QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj) { - if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted) + if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted) return 0; const QMetaObject *mo = obj->metaObject(); @@ -348,10 +348,10 @@ QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj) } /*! -Returns a QDeclarativePropertyCache for \a metaObject. +Returns a QDeclarativePropertyCache for \a metaObject. As the cache is persisted for the life of the engine, \a metaObject must be -a static "compile time" meta-object, or a meta-object that is otherwise known to +a static "compile time" meta-object, or a meta-object that is otherwise known to exist for the lifetime of the QDeclarativeEngine. The returned cache is not referenced, so if it is to be stored, call addref(). -- cgit v0.12 From 0abf1dd99eeb252ae10c9f3cd99b64ee0b4d6e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 4 May 2011 17:29:44 +0200 Subject: Added forgotten file qdeclarativeobserverinterface_p.h This should have been part of 35faeb205843c4f0b921d2b878d2d24962c64664 --- .../debugger/qdeclarativeobserverinterface_p.h | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/declarative/debugger/qdeclarativeobserverinterface_p.h diff --git a/src/declarative/debugger/qdeclarativeobserverinterface_p.h b/src/declarative/debugger/qdeclarativeobserverinterface_p.h new file mode 100644 index 0000000..501c132 --- /dev/null +++ b/src/declarative/debugger/qdeclarativeobserverinterface_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEOBSERVERINTERFACE_H +#define QDECLARATIVEOBSERVERINTERFACE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QDeclarativeObserverInterface +{ +public: + QDeclarativeObserverInterface() {} + virtual ~QDeclarativeObserverInterface() {} + + virtual void activate() = 0; + virtual void deactivate() = 0; +}; + +Q_DECLARE_INTERFACE(QDeclarativeObserverInterface, "com.trolltech.Qt.QDeclarativeObserverInterface/1.0") + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDECLARATIVEOBSERVERINTERFACE_H -- cgit v0.12 From 894515429397be20670806825099b4b9896d50d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 4 May 2011 18:59:49 +0200 Subject: Fixed compile on Windows This compiled fine on Linux, but on Windows the project root is not automatically included in the INCLUDEPATH. Use the correct relative path to make the include work. Problem introduced with 35faeb205843c4f0b921d2b878d2d24962c64664 --- .../qmltooling/declarativeobserver/editor/abstractliveedittool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp index 9588311..b3ed22e 100644 --- a/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp +++ b/src/plugins/qmltooling/declarativeobserver/editor/abstractliveedittool.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "abstractliveedittool_p.h" -#include "qdeclarativeviewobserver_p_p.h" +#include "../qdeclarativeviewobserver_p_p.h" #include -- cgit v0.12 From 23e772584531278e3b2a6c735ff9db88f7ffd76e Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 3 May 2011 09:52:30 +0200 Subject: qmake nmake generator: pass MAKEFLAGS to sub-make calls Unlike other make tools nmake doesn't do this automatically. Reviewed-by: ossi --- qmake/generators/makefile.cpp | 28 ++++++++++++++-------------- qmake/generators/makefile.h | 2 ++ qmake/generators/win32/msvc_nmake.cpp | 9 +++++++++ qmake/generators/win32/msvc_nmake.h | 2 ++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index 595768f..c3d3933 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -2373,6 +2373,14 @@ MakefileGenerator::writeSubDirs(QTextStream &t) qDeleteAll(targets); } +void MakefileGenerator::writeSubMakeCall(QTextStream &t, const QString &callPrefix, + const QString &makeArguments, const QString &callPostfix) +{ + t << callPrefix + << "$(MAKE)" << makeArguments + << callPostfix << endl; +} + void MakefileGenerator::writeSubTargets(QTextStream &t, QList targets, int flags) { @@ -2496,9 +2504,7 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QListdepends); if(project->isEmpty("QMAKE_NOFORCE")) t << " FORCE"; - t << out_directory_cdin - << "$(MAKE)" << makefilein - << out_directory_cdout << endl; + writeSubMakeCall(t, out_directory_cdin, makefilein, out_directory_cdout); } for(int suffix = 0; suffix < targetSuffixes.size(); ++suffix) { @@ -2518,9 +2524,7 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QListtarget << "-" << targetSuffixes.at(suffix) << "-ordered "; if(project->isEmpty("QMAKE_NOFORCE")) t << " FORCE"; - t << out_directory_cdin - << "$(MAKE)" << makefilein << " " << s - << out_directory_cdout << endl; + writeSubMakeCall(t, out_directory_cdin, makefilein, out_directory_cdout); } t << subtarget->target << "-" << targetSuffixes.at(suffix) << ": " << mkfile; if(!subtarget->depends.isEmpty()) @@ -2528,9 +2532,7 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QListisEmpty("QMAKE_NOFORCE")) t << " FORCE"; - t << out_directory_cdin - << "$(MAKE)" << makefilein << " " << s - << out_directory_cdout << endl; + writeSubMakeCall(t, out_directory_cdin, makefilein, out_directory_cdout); } } t << endl; @@ -2664,12 +2666,10 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QList findSubDirsSubTargets() const; + virtual void writeSubMakeCall(QTextStream &t, const QString &outDirectory_cdin, + const QString &makeFileIn, const QString &outDirectory_cdout); void writeSubTargets(QTextStream &t, QList subtargets, int flags); //extra compiler interface diff --git a/qmake/generators/win32/msvc_nmake.cpp b/qmake/generators/win32/msvc_nmake.cpp index c55806d..e0e2fe0 100644 --- a/qmake/generators/win32/msvc_nmake.cpp +++ b/qmake/generators/win32/msvc_nmake.cpp @@ -85,6 +85,15 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t) return false; } +void NmakeMakefileGenerator::writeSubMakeCall(QTextStream &t, const QString &callPrefix, + const QString &makeArguments, const QString &callPostfix) +{ + // Pass MAKEFLAGS as environment variable to sub-make calls. + // Unlike other make tools nmake doesn't do this automatically. + t << "\n\t@set MAKEFLAGS=$(MAKEFLAGS)"; + Win32MakefileGenerator::writeSubMakeCall(t, callPrefix, makeArguments, callPostfix); +} + QString NmakeMakefileGenerator::getPdbTarget() { return QString(project->first("TARGET") + project->first("TARGET_VERSION_EXT") + ".pdb"); diff --git a/qmake/generators/win32/msvc_nmake.h b/qmake/generators/win32/msvc_nmake.h index 8954655..689cc19 100644 --- a/qmake/generators/win32/msvc_nmake.h +++ b/qmake/generators/win32/msvc_nmake.h @@ -57,6 +57,8 @@ class NmakeMakefileGenerator : public Win32MakefileGenerator void init(); protected: + virtual void writeSubMakeCall(QTextStream &t, const QString &callPrefix, + const QString &makeArguments, const QString &callPostfix); virtual QString getPdbTarget(); virtual QString defaultInstall(const QString &t); virtual QStringList &findDependencies(const QString &file); -- cgit v0.12 From 18a05b0d40a8b569e369248c748a9ed65883f522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Thu, 5 May 2011 10:46:30 +0200 Subject: Lighthouse: Fix up Xlib --- src/plugins/platforms/xlib/qglxintegration.cpp | 8 +++----- src/plugins/platforms/xlib/qglxintegration.h | 4 ++-- src/plugins/platforms/xlib/qxlibscreen.cpp | 4 +--- src/plugins/platforms/xlib/qxlibstatic.cpp | 4 ---- src/plugins/platforms/xlib/qxlibstatic.h | 4 ++++ 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/plugins/platforms/xlib/qglxintegration.cpp b/src/plugins/platforms/xlib/qglxintegration.cpp index 7a0f36d..a43851c 100644 --- a/src/plugins/platforms/xlib/qglxintegration.cpp +++ b/src/plugins/platforms/xlib/qglxintegration.cpp @@ -46,15 +46,13 @@ #include "qxlibwindow.h" #include "qxlibscreen.h" #include "qxlibdisplay.h" +#include "qxlibstatic.h" #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2) -#include -#include -#include -#include "qglxconvenience.h" - #include "qglxintegration.h" +#include "qglxconvenience.h" + #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) #include #endif diff --git a/src/plugins/platforms/xlib/qglxintegration.h b/src/plugins/platforms/xlib/qglxintegration.h index 57c716b..d0527c3 100644 --- a/src/plugins/platforms/xlib/qglxintegration.h +++ b/src/plugins/platforms/xlib/qglxintegration.h @@ -47,10 +47,10 @@ #include #include -#include - #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2) +#define Status int #include +#undef Status QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/xlib/qxlibscreen.cpp b/src/plugins/platforms/xlib/qxlibscreen.cpp index 7c8a367..c4c8126 100644 --- a/src/plugins/platforms/xlib/qxlibscreen.cpp +++ b/src/plugins/platforms/xlib/qxlibscreen.cpp @@ -54,8 +54,6 @@ #include -#include - QT_BEGIN_NAMESPACE static int (*original_x_errhandler)(Display *dpy, XErrorEvent *); @@ -201,7 +199,7 @@ QXlibScreen::QXlibScreen() #ifndef DONT_USE_MIT_SHM - Status MIT_SHM_extension_supported = XShmQueryExtension (mDisplay->nativeDisplay()); + int MIT_SHM_extension_supported = XShmQueryExtension (mDisplay->nativeDisplay()); Q_ASSERT(MIT_SHM_extension_supported == True); #endif original_x_errhandler = XSetErrorHandler(qt_x_errhandler); diff --git a/src/plugins/platforms/xlib/qxlibstatic.cpp b/src/plugins/platforms/xlib/qxlibstatic.cpp index 6117781..7b562ea 100644 --- a/src/plugins/platforms/xlib/qxlibstatic.cpp +++ b/src/plugins/platforms/xlib/qxlibstatic.cpp @@ -51,10 +51,6 @@ #include -#ifndef QT_NO_XFIXES -#include -#endif // QT_NO_XFIXES - static const char * x11_atomnames = { // window-manager <-> client protocols "WM_PROTOCOLS\0" diff --git a/src/plugins/platforms/xlib/qxlibstatic.h b/src/plugins/platforms/xlib/qxlibstatic.h index 72cfaec..ebc8085 100644 --- a/src/plugins/platforms/xlib/qxlibstatic.h +++ b/src/plugins/platforms/xlib/qxlibstatic.h @@ -118,6 +118,10 @@ extern "C" { } #endif +#ifndef QT_NO_XFIXES +#include +#endif // QT_NO_XFIXES + // #define QT_NO_XKB #ifndef QT_NO_XKB # include -- cgit v0.12 From 3a93262bcf39de34c3655ca83642c1a5bb3a7d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Thu, 5 May 2011 17:34:07 +0200 Subject: Dont do doneCurrent in swapBuffers --- src/plugins/platforms/xcb/qglxintegration.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/platforms/xcb/qglxintegration.cpp b/src/plugins/platforms/xcb/qglxintegration.cpp index 190221c..1417157 100644 --- a/src/plugins/platforms/xcb/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/qglxintegration.cpp @@ -110,7 +110,6 @@ void QGLXContext::swapBuffers() { Q_XCB_NOOP(m_screen->connection()); glXSwapBuffers(DISPLAY_FROM_XCB(m_screen), m_drawable); - doneCurrent(); Q_XCB_NOOP(m_screen->connection()); } -- cgit v0.12 From 7d9f03c87e0e096934583a36340de5446e1d0520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 5 May 2011 19:43:38 +0200 Subject: Fixed license header File added in 35faeb205843c4f0b921d2b878d2d24962c64664 --- .../qdeclarativeviewobserver.cpp | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp index b0a8162..2286990 100644 --- a/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp +++ b/src/plugins/qmltooling/declarativeobserver/qdeclarativeviewobserver.cpp @@ -1,20 +1,19 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +/**************************************************************************** ** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** No Commercial Usage +** This file is part of the QtDeclarative module of the Qt Toolkit. ** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. ** ** GNU Lesser General Public License Usage -** ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the @@ -29,7 +28,16 @@ ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** -**************************************************************************/ +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #include "QtDeclarative/private/qdeclarativeobserverservice_p.h" #include "QtDeclarative/private/qdeclarativedebughelper_p.h" -- cgit v0.12 From 1f0f8a1b15fa4efa58feb2799614afc8bf0bd6e3 Mon Sep 17 00:00:00 2001 From: Christiaan Janssen Date: Fri, 29 Apr 2011 15:33:11 +0200 Subject: QmlDebugger: adding slots to items in Live Preview Reviewed-by: Kai Koehne --- src/declarative/qml/qdeclarativeenginedebug.cpp | 17 +++++++++++++---- src/declarative/qml/qdeclarativeenginedebug_p.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 31fd516..0ac7680 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -518,8 +518,13 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) QString propertyName; QVariant expr; bool isLiteralValue; + QString filename; + int line; ds >> objectId >> propertyName >> expr >> isLiteralValue; - setBinding(objectId, propertyName, expr, isLiteralValue); + if (!ds.atEnd()) { // backward compatibility from 2.1, 2.2 + ds >> filename >> line; + } + setBinding(objectId, propertyName, expr, isLiteralValue, filename, line); } else if (type == "RESET_BINDING") { int objectId; QString propertyName; @@ -537,7 +542,9 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) void QDeclarativeEngineDebugServer::setBinding(int objectId, const QString &propertyName, const QVariant &expression, - bool isLiteralValue) + bool isLiteralValue, + QString filename, + int line) { QObject *object = objectForId(objectId); QDeclarativeContext *context = qmlContext(object); @@ -559,6 +566,7 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId, newBinding = new QDeclarativeBinding(expression.toString(), object, context); newBinding->setTarget(property); newBinding->setNotifyOnValueChanged(true); + newBinding->setSourceLocation(filename, line); } state->changeBindingInRevertList(object, propertyName, newBinding); @@ -574,11 +582,12 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId, property.write(expression); } else if (hasValidSignal(object, propertyName)) { QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); - QDeclarativeExpression *oldExpression = QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); - declarativeExpression->setSourceLocation(oldExpression->sourceFile(), oldExpression->lineNumber()); + QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); + declarativeExpression->setSourceLocation(filename, line); } else if (property.isProperty()) { QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); binding->setTarget(property); + binding->setSourceLocation(filename, line); binding->setNotifyOnValueChanged(true); QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); if (oldBinding) diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h index e95676c..64b2724 100644 --- a/src/declarative/qml/qdeclarativeenginedebug_p.h +++ b/src/declarative/qml/qdeclarativeenginedebug_p.h @@ -115,7 +115,7 @@ private: QDeclarativeObjectData objectData(QObject *); QDeclarativeObjectProperty propertyData(QObject *, int); QVariant valueContents(const QVariant &defaultValue) const; - void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue); + void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue, QString filename = QString(), int line = -1); void resetBinding(int objectId, const QString &propertyName); void setMethodBody(int objectId, const QString &method, const QString &body); -- cgit v0.12 From 582be247290fd015798b3d84d692c0236dbff4e1 Mon Sep 17 00:00:00 2001 From: Christiaan Janssen Date: Fri, 29 Apr 2011 15:54:59 +0200 Subject: QmlDebugger: removing slots in Live Preview Reviewed-by: Kai Koehne --- src/declarative/qml/qdeclarativeenginedebug.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 0ac7680..bf6658a 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -647,7 +647,10 @@ void QDeclarativeEngineDebugServer::resetBinding(int objectId, const QString &pr } } } - } else { + } else if (hasValidSignal(object, propertyName)) { + QDeclarativeProperty property(object, propertyName, context); + QDeclarativePropertyPrivate::setSignalExpression(property, 0); + } else { if (QDeclarativePropertyChanges *propertyChanges = qobject_cast(object)) { propertyChanges->removeProperty(propertyName); } -- cgit v0.12 From b6c562d0ccf07983fc60d33e33086117744e205a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 5 May 2011 14:04:22 +0200 Subject: qmake: remove dead code from VcxprojGenerator Reviewed-by: ossi --- qmake/generators/win32/msvc_vcxproj.cpp | 18 ------------------ qmake/generators/win32/msvc_vcxproj.h | 10 ---------- 2 files changed, 28 deletions(-) diff --git a/qmake/generators/win32/msvc_vcxproj.cpp b/qmake/generators/win32/msvc_vcxproj.cpp index 1e7c4b7..5b75cfa 100644 --- a/qmake/generators/win32/msvc_vcxproj.cpp +++ b/qmake/generators/win32/msvc_vcxproj.cpp @@ -41,26 +41,9 @@ #include "msvc_vcxproj.h" #include "msbuild_objectmodel.h" -#include -#include -#include - - -QT_BEGIN_NAMESPACE -// Filter GUIDs (Do NOT change these!) ------------------------------ -const char _GUIDSourceFiles[] = "{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"; -const char _GUIDHeaderFiles[] = "{93995380-89BD-4b04-88EB-625FBE52EBFB}"; -const char _GUIDGeneratedFiles[] = "{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}"; -const char _GUIDResourceFiles[] = "{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}"; -const char _GUIDLexYaccFiles[] = "{E12AE0D2-192F-4d59-BD23-7D3FA58D3183}"; -const char _GUIDTranslationFiles[] = "{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}"; -const char _GUIDFormFiles[] = "{99349809-55BA-4b9d-BF79-8FDBB0286EB3}"; -const char _GUIDExtraCompilerFiles[] = "{E0D8C965-CC5F-43d7-AD63-FAEF0BBC0F85}"; -QT_END_NAMESPACE QT_BEGIN_NAMESPACE - VcxprojGenerator::VcxprojGenerator() : VcprojGenerator() { } @@ -71,4 +54,3 @@ VCProjectWriter *VcxprojGenerator::createProjectWriter() } QT_END_NAMESPACE - diff --git a/qmake/generators/win32/msvc_vcxproj.h b/qmake/generators/win32/msvc_vcxproj.h index 3283cc7..90f6652 100644 --- a/qmake/generators/win32/msvc_vcxproj.h +++ b/qmake/generators/win32/msvc_vcxproj.h @@ -42,8 +42,6 @@ #ifndef MSVC_VCXPROJ_H #define MSVC_VCXPROJ_H -#include "winmakefile.h" -#include "msbuild_objectmodel.h" #include "msvc_vcproj.h" QT_BEGIN_NAMESPACE @@ -52,19 +50,11 @@ class VcxprojGenerator : public VcprojGenerator { public: VcxprojGenerator(); - ~VcxprojGenerator(); protected: virtual VCProjectWriter *createProjectWriter(); - -private: - friend class VCFilter; - }; -inline VcxprojGenerator::~VcxprojGenerator() -{ } - QT_END_NAMESPACE #endif // MSVC_VCXPROJ_H -- cgit v0.12 From 3edf2608f572982f5ef7c89d4772d2d28b635c69 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 5 May 2011 10:51:27 +0200 Subject: qmake vc(x)proj generator: support x64 Qt builds Task-number: QTBUG-17911 Reviewed-by: ossi --- qmake/generators/win32/msvc_vcproj.cpp | 22 +++++++++++++--------- qmake/generators/win32/msvc_vcproj.h | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index f243e86..06920e9 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -208,6 +208,7 @@ const char _slnExtSections[] = "\n\tGlobalSection(ExtensibilityGlobals) = pos VcprojGenerator::VcprojGenerator() : Win32MakefileGenerator(), init_flag(false), + is64Bit(false), projectWriter(0) { } @@ -597,14 +598,16 @@ nextfile: } } t << _slnGlobalBeg; + + QString slnConf = _slnSolutionConf; if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH")) { - QString slnConfCE = _slnSolutionConf; - QString platform = QString("|") + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")"; - slnConfCE.replace(QString("|Win32"), platform); - t << slnConfCE; - } else { - t << _slnSolutionConf; + QString slnPlatform = QString("|") + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")"; + slnConf.replace(QString("|Win32"), slnPlatform); + } else if (is64Bit) { + slnConf.replace(QString("|Win32"), "|x64"); } + t << slnConf; + t << _slnProjDepBeg; // Restore previous after_user_var options @@ -621,7 +624,7 @@ nextfile: t << _slnProjDepEnd; t << _slnProjConfBeg; for(QList::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) { - QString platform = "Win32"; + QString platform = is64Bit ? "x64" : "Win32"; if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH")) platform = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")"; t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag1).arg(platform) << platform; @@ -661,6 +664,7 @@ void VcprojGenerator::init() if (init_flag) return; init_flag = true; + is64Bit = (project->first("QMAKE_TARGET.arch") == "x86_64"); projectWriter = createProjectWriter(); if(project->first("TEMPLATE") == "vcsubdirs") //too much work for subdirs @@ -831,7 +835,7 @@ void VcprojGenerator::initProject() vcProject.Keyword = project->first("VCPROJ_KEYWORD"); if (project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) { - vcProject.PlatformName = (vcProject.Configuration.idl.TargetEnvironment == midlTargetWin64 ? "Win64" : "Win32"); + vcProject.PlatformName = (is64Bit ? "x64" : "Win32"); } else { vcProject.PlatformName = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")"; } @@ -895,7 +899,7 @@ void VcprojGenerator::initConfiguration() conf.Name = isDebug ? "Debug" : "Release"; conf.ConfigurationName = conf.Name; if (project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) { - conf.Name += (conf.idl.TargetEnvironment == midlTargetWin64 ? "|Win64" : "|Win32"); + conf.Name += (is64Bit ? "|x64" : "|Win32"); } else { conf.Name += "|" + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")"; } diff --git a/qmake/generators/win32/msvc_vcproj.h b/qmake/generators/win32/msvc_vcproj.h index fdcd73f..497f5a7 100644 --- a/qmake/generators/win32/msvc_vcproj.h +++ b/qmake/generators/win32/msvc_vcproj.h @@ -57,6 +57,7 @@ struct QUuid; class VcprojGenerator : public Win32MakefileGenerator { bool init_flag; + bool is64Bit; bool writeVcprojParts(QTextStream &); bool writeMakefile(QTextStream &); -- cgit v0.12 From a8fdea9460ffd4814240543b0fd340aee593db85 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 9 May 2011 12:42:44 +1000 Subject: Augment documentation Change-Id: I3469c63207d4ca75c5f942dc3fa84c5a71ceb3a2 Task-number: QTBUG-19112 Reviewed-by: Martin Jones --- src/declarative/qml/qdeclarativeengine.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 3cb2112..aa4bcd4 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1326,6 +1326,8 @@ Example (where \c parentItem is the id of an existing QML item): In the case of an error, a QtScript Error object is thrown. This object has an additional property, \c qmlErrors, which is an array of the errors encountered. Each object in this array has the members \c lineNumber, \c columnNumber, \c fileName and \c message. +For example, if the above snippet had misspelled color as 'colro' then the array would contain an object like the following: +{ "lineNumber" : 1, "columnNumber" : 32, "fileName" : "dynamicSnippet1", "message" : "Cannot assign to non-existent property \"colro\""}. Note that this function returns immediately, and therefore may not work if the \a qml string loads new components (that is, external QML files that have not yet been loaded). -- cgit v0.12 From b4068161ecc7789e04054508f969fa924d0cc0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Sun, 8 May 2011 10:53:56 +0200 Subject: Fix the wayland windowsurface so that we have stencil and depth buffer --- .../platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp b/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp index ebe4c7b..7929ccb 100644 --- a/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp +++ b/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp @@ -178,7 +178,7 @@ void QWaylandGLWindowSurface::resize(const QSize &size) QWindowSurface::resize(size); window()->platformWindow()->glContext()->makeCurrent(); delete mPaintDevice; - mPaintDevice = new QGLFramebufferObject(size); + mPaintDevice = new QGLFramebufferObject(size,QGLFramebufferObject::CombinedDepthStencil); } QT_END_NAMESPACE -- cgit v0.12 From a166615d7a0d346e519aa0e53a1e9776e41a4167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Sun, 8 May 2011 17:41:36 +0200 Subject: Add the wayland client libraries to rpath if we use rpath --- src/plugins/platforms/wayland/wayland.pro | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index 8d2d4b5..f739fb1 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -31,6 +31,10 @@ INCLUDEPATH += $$QMAKE_INCDIR_WAYLAND LIBS += $$QMAKE_LIBS_WAYLAND QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_WAYLAND +!isEmpty(QMAKE_LFLAGS_RPATH) { + !isEmpty(QMAKE_LIBDIR_WAYLAND):QMAKE_LFLAGS += $${QMAKE_LFLAGS_RPATH}$${QMAKE_LIBDIR_WAYLAND} +} + INCLUDEPATH += $$PWD include ($$PWD/gl_integration/gl_integration.pri) -- cgit v0.12 From eb0c2e7229bb3559e6f8754122b298479407c153 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 9 May 2011 12:09:33 +0200 Subject: Added Wayland selection support. --- src/gui/kernel/qclipboard.h | 1 + src/gui/kernel/qplatformclipboard_qpa.cpp | 7 +++++++ src/gui/kernel/qplatformclipboard_qpa.h | 1 + src/plugins/platforms/wayland/qwaylanddisplay.cpp | 7 ++++++- src/plugins/platforms/wayland/qwaylanddisplay.h | 1 + src/plugins/platforms/wayland/qwaylandinputdevice.h | 1 + src/plugins/platforms/wayland/qwaylandintegration.cpp | 9 +++++++++ src/plugins/platforms/wayland/qwaylandintegration.h | 3 +++ src/plugins/platforms/wayland/wayland.pro | 6 ++++-- 9 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qclipboard.h b/src/gui/kernel/qclipboard.h index b55bdc6..019917e 100644 --- a/src/gui/kernel/qclipboard.h +++ b/src/gui/kernel/qclipboard.h @@ -112,6 +112,7 @@ protected: friend class QBaseApplication; friend class QDragManager; friend class QMimeSource; + friend class QPlatformClipboard; private: Q_DISABLE_COPY(QClipboard) diff --git a/src/gui/kernel/qplatformclipboard_qpa.cpp b/src/gui/kernel/qplatformclipboard_qpa.cpp index 957a4df..33d2afc 100644 --- a/src/gui/kernel/qplatformclipboard_qpa.cpp +++ b/src/gui/kernel/qplatformclipboard_qpa.cpp @@ -42,6 +42,8 @@ #ifndef QT_NO_CLIPBOARD +#include + QT_BEGIN_NAMESPACE class QClipboardData @@ -100,6 +102,11 @@ bool QPlatformClipboard::supportsMode(QClipboard::Mode mode) const return mode == QClipboard::Clipboard; } +void QPlatformClipboard::emitChanged(QClipboard::Mode mode) +{ + QApplication::clipboard()->emitChanged(mode); +} + QT_END_NAMESPACE #endif //QT_NO_CLIPBOARD diff --git a/src/gui/kernel/qplatformclipboard_qpa.h b/src/gui/kernel/qplatformclipboard_qpa.h index 3381c06..5444a1f 100644 --- a/src/gui/kernel/qplatformclipboard_qpa.h +++ b/src/gui/kernel/qplatformclipboard_qpa.h @@ -62,6 +62,7 @@ public: virtual const QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard ) const; virtual void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard); virtual bool supportsMode(QClipboard::Mode mode) const; + void emitChanged(QClipboard::Mode mode); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 876b46a..974453d 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -45,6 +45,7 @@ #include "qwaylandscreen.h" #include "qwaylandcursor.h" #include "qwaylandinputdevice.h" +#include "qwaylandclipboard.h" #ifdef QT_WAYLAND_GL_SUPPORT #include "gl_integration/qwaylandglintegration.h" @@ -52,6 +53,7 @@ #include #include +#include #include #include @@ -249,7 +251,6 @@ void QWaylandDisplay::displayHandleGlobal(uint32_t id, uint32_t version) { Q_UNUSED(version); - if (interface == "wl_output") { struct wl_output *output = wl_output_create(mDisplay, id, 1); wl_output_add_listener(output, &outputListener, this); @@ -264,5 +265,9 @@ void QWaylandDisplay::displayHandleGlobal(uint32_t id, QWaylandInputDevice *inputDevice = new QWaylandInputDevice(mDisplay, id); mInputDevices.append(inputDevice); + } else if (interface == "wl_selection_offer") { + QPlatformIntegration *plat = QApplicationPrivate::platformIntegration(); + QWaylandClipboard *clipboard = static_cast(plat->clipboard()); + clipboard->createSelectionOffer(id); } } diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.h b/src/plugins/platforms/wayland/qwaylanddisplay.h index a2cb1b2..0658956 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.h +++ b/src/plugins/platforms/wayland/qwaylanddisplay.h @@ -80,6 +80,7 @@ public: void frameCallback(wl_display_frame_func_t func, struct wl_surface *surface, void *data); struct wl_display *wl_display() const { return mDisplay; } + struct wl_shell *wl_shell() const { return mShell; } QList inputDevices() const { return mInputDevices; } diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.h b/src/plugins/platforms/wayland/qwaylandinputdevice.h index 3c83252..251259b 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice.h +++ b/src/plugins/platforms/wayland/qwaylandinputdevice.h @@ -60,6 +60,7 @@ public: QWaylandInputDevice(struct wl_display *display, uint32_t id); void attach(QWaylandBuffer *buffer, int x, int y); void handleWindowDestroyed(QWaylandWindow *window); + struct wl_input_device *wl_input_device() const { return mInputDevice; } private: struct wl_display *mDisplay; diff --git a/src/plugins/platforms/wayland/qwaylandintegration.cpp b/src/plugins/platforms/wayland/qwaylandintegration.cpp index b6401f6..6166c14 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.cpp +++ b/src/plugins/platforms/wayland/qwaylandintegration.cpp @@ -45,6 +45,7 @@ #include "qwaylandshmsurface.h" #include "qwaylandshmwindow.h" #include "qwaylandnativeinterface.h" +#include "qwaylandclipboard.h" #include "qgenericunixfontdatabase.h" @@ -64,6 +65,7 @@ QWaylandIntegration::QWaylandIntegration(bool useOpenGL) , mDisplay(new QWaylandDisplay()) , mUseOpenGL(useOpenGL) , mNativeInterface(new QWaylandNativeInterface) + , mClipboard(0) { } @@ -132,3 +134,10 @@ bool QWaylandIntegration::hasOpenGL() const return false; #endif } + +QPlatformClipboard *QWaylandIntegration::clipboard() const +{ + if (!mClipboard) + mClipboard = new QWaylandClipboard(mDisplay); + return mClipboard; +} diff --git a/src/plugins/platforms/wayland/qwaylandintegration.h b/src/plugins/platforms/wayland/qwaylandintegration.h index 71f6d9c..fc748b0 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.h +++ b/src/plugins/platforms/wayland/qwaylandintegration.h @@ -65,6 +65,8 @@ public: QPlatformNativeInterface *nativeInterface() const; + QPlatformClipboard *clipboard() const; + private: bool hasOpenGL() const; @@ -72,6 +74,7 @@ private: QWaylandDisplay *mDisplay; bool mUseOpenGL; QPlatformNativeInterface *mNativeInterface; + mutable QPlatformClipboard *mClipboard; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index f739fb1..76f8be5 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -15,7 +15,8 @@ SOURCES = main.cpp \ qwaylanddisplay.cpp \ qwaylandwindow.cpp \ qwaylandscreen.cpp \ - qwaylandshmwindow.cpp + qwaylandshmwindow.cpp \ + qwaylandclipboard.cpp HEADERS = qwaylandintegration.h \ qwaylandnativeinterface.h \ @@ -25,7 +26,8 @@ HEADERS = qwaylandintegration.h \ qwaylandscreen.h \ qwaylandshmsurface.h \ qwaylandbuffer.h \ - qwaylandshmwindow.h + qwaylandshmwindow.h \ + qwaylandclipboard.h INCLUDEPATH += $$QMAKE_INCDIR_WAYLAND LIBS += $$QMAKE_LIBS_WAYLAND -- cgit v0.12 From 5e3240f53720921bbcb869cd5a4b35167b087505 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 6 May 2011 18:36:43 +0200 Subject: Added Wayland selection support. Messed up when I cherry-picked eb0c2e7229bb3559e6f8754122b298479407c153 --- .../platforms/wayland/qwaylandclipboard.cpp | 242 +++++++++++++++++++++ src/plugins/platforms/wayland/qwaylandclipboard.h | 86 ++++++++ src/plugins/platforms/wayland/wayland.pro | 2 + src/plugins/platforms/xcb/xcb.pro | 2 + src/plugins/platforms/xlib/xlib.pro | 2 + 5 files changed, 334 insertions(+) create mode 100644 src/plugins/platforms/wayland/qwaylandclipboard.cpp create mode 100644 src/plugins/platforms/wayland/qwaylandclipboard.h diff --git a/src/plugins/platforms/wayland/qwaylandclipboard.cpp b/src/plugins/platforms/wayland/qwaylandclipboard.cpp new file mode 100644 index 0000000..9c533aa --- /dev/null +++ b/src/plugins/platforms/wayland/qwaylandclipboard.cpp @@ -0,0 +1,242 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandclipboard.h" +#include "qwaylanddisplay.h" +#include "qwaylandinputdevice.h" +#include +#include +#include +#include +#include +#include + +static QWaylandClipboard *clipboard; + +class QWaylandSelection +{ +public: + QWaylandSelection(QWaylandDisplay *display, QMimeData *data); + ~QWaylandSelection(); + +private: + static uint32_t getTime(); + static void send(void *data, struct wl_selection *selection, const char *mime_type, int fd); + static void cancelled(void *data, struct wl_selection *selection); + static const struct wl_selection_listener selectionListener; + + QMimeData *mMimeData; + struct wl_selection *mSelection; +}; + +const struct wl_selection_listener QWaylandSelection::selectionListener = { + QWaylandSelection::send, + QWaylandSelection::cancelled +}; + +uint32_t QWaylandSelection::getTime() +{ + struct timeval tv; + gettimeofday(&tv, 0); + return tv.tv_sec * 1000 + tv.tv_usec / 1000; +} + +QWaylandSelection::QWaylandSelection(QWaylandDisplay *display, QMimeData *data) + : mMimeData(data), mSelection(0) +{ + struct wl_shell *shell = display->wl_shell(); + mSelection = wl_shell_create_selection(shell); + wl_selection_add_listener(mSelection, &selectionListener, this); + foreach (const QString &format, data->formats()) + wl_selection_offer(mSelection, format.toLatin1().constData()); + wl_selection_activate(mSelection, + display->inputDevices().at(0)->wl_input_device(), + getTime()); +} + +QWaylandSelection::~QWaylandSelection() +{ + if (mSelection) { + clipboard->unregisterSelection(this); + wl_selection_destroy(mSelection); + } + delete mMimeData; +} + +void QWaylandSelection::send(void *data, + struct wl_selection *selection, + const char *mime_type, + int fd) +{ + Q_UNUSED(selection); + QWaylandSelection *self = static_cast(data); + QString mimeType = QString::fromLatin1(mime_type); + QByteArray content = self->mMimeData->data(mimeType); + if (!content.isEmpty()) { + QFile f; + if (f.open(fd, QIODevice::WriteOnly)) + f.write(content); + } + close(fd); +} + +void QWaylandSelection::cancelled(void *data, struct wl_selection *selection) +{ + Q_UNUSED(selection); + delete static_cast(data); +} + +QWaylandClipboard::QWaylandClipboard(QWaylandDisplay *display) + : mDisplay(display), mSelection(0), mMimeDataIn(0), mOffer(0) +{ + clipboard = this; +} + +QWaylandClipboard::~QWaylandClipboard() +{ + if (mOffer) + wl_selection_offer_destroy(mOffer); + delete mMimeDataIn; + qDeleteAll(mSelections); +} + +void QWaylandClipboard::unregisterSelection(QWaylandSelection *selection) +{ + mSelections.removeOne(selection); +} + +void QWaylandClipboard::syncCallback(void *data) +{ + *static_cast(data) = true; +} + +void QWaylandClipboard::forceRoundtrip(struct wl_display *display) +{ + bool done = false; + wl_display_sync_callback(display, syncCallback, &done); + wl_display_iterate(display, WL_DISPLAY_WRITABLE); + while (!done) + wl_display_iterate(display, WL_DISPLAY_READABLE); +} + +const QMimeData *QWaylandClipboard::mimeData(QClipboard::Mode mode) const +{ + Q_ASSERT(mode == QClipboard::Clipboard); + if (!mMimeDataIn) + mMimeDataIn = new QMimeData; + mMimeDataIn->clear(); + if (!mOfferedMimeTypes.isEmpty() && mOffer) { + foreach (const QString &mimeType, mOfferedMimeTypes) { + int pipefd[2]; + if (pipe(pipefd) == -1) { + qWarning("QWaylandClipboard::mimedata: pipe() failed"); + break; + } + QByteArray mimeTypeBa = mimeType.toLatin1(); + wl_selection_offer_receive(mOffer, mimeTypeBa.constData(), pipefd[1]); + QByteArray content; + forceRoundtrip(mDisplay->wl_display()); + char buf[256]; + int n; + close(pipefd[1]); + while ((n = read(pipefd[0], &buf, sizeof buf)) > 0) + content.append(buf, n); + close(pipefd[0]); + mMimeDataIn->setData(mimeType, content); + } + } + return mMimeDataIn; +} + +void QWaylandClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) +{ + Q_ASSERT(mode == QClipboard::Clipboard); + if (!mDisplay->inputDevices().isEmpty()) { + if (!data) + data = new QMimeData; + mSelection = new QWaylandSelection(mDisplay, data); + } else { + qWarning("QWaylandClipboard::setMimeData: No input devices"); + } +} + +bool QWaylandClipboard::supportsMode(QClipboard::Mode mode) const +{ + return mode == QClipboard::Clipboard; +} + +const struct wl_selection_offer_listener QWaylandClipboard::selectionOfferListener = { + QWaylandClipboard::offer, + QWaylandClipboard::keyboardFocus +}; + +void QWaylandClipboard::createSelectionOffer(uint32_t id) +{ + mOfferedMimeTypes.clear(); + if (mOffer) + wl_selection_offer_destroy(mOffer); + mOffer = 0; + struct wl_selection_offer *offer = wl_selection_offer_create(mDisplay->wl_display(), id, 1); + wl_selection_offer_add_listener(offer, &selectionOfferListener, this); +} + +void QWaylandClipboard::offer(void *data, + struct wl_selection_offer *selection_offer, + const char *type) +{ + Q_UNUSED(selection_offer); + QWaylandClipboard *self = static_cast(data); + self->mOfferedMimeTypes.append(QString::fromLatin1(type)); +} + +void QWaylandClipboard::keyboardFocus(void *data, + struct wl_selection_offer *selection_offer, + wl_input_device *input_device) +{ + QWaylandClipboard *self = static_cast(data); + if (!input_device) { + wl_selection_offer_destroy(selection_offer); + self->mOffer = 0; + return; + } + self->mOffer = selection_offer; + self->emitChanged(QClipboard::Clipboard); +} diff --git a/src/plugins/platforms/wayland/qwaylandclipboard.h b/src/plugins/platforms/wayland/qwaylandclipboard.h new file mode 100644 index 0000000..606a1f6 --- /dev/null +++ b/src/plugins/platforms/wayland/qwaylandclipboard.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDCLIPBOARD_H +#define QWAYLANDCLIPBOARD_H + +#include +#include + +class QWaylandDisplay; +class QWaylandSelection; +struct wl_selection_offer; + +class QWaylandClipboard : public QPlatformClipboard +{ +public: + QWaylandClipboard(QWaylandDisplay *display); + ~QWaylandClipboard(); + + const QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard) const; + void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard); + bool supportsMode(QClipboard::Mode mode) const; + + void unregisterSelection(QWaylandSelection *selection); + + void createSelectionOffer(uint32_t id); + +private: + static void offer(void *data, + struct wl_selection_offer *selection_offer, + const char *type); + static void keyboardFocus(void *data, + struct wl_selection_offer *selection_offer, + struct wl_input_device *input_device); + static const struct wl_selection_offer_listener selectionOfferListener; + + static void syncCallback(void *data); + static void forceRoundtrip(struct wl_display *display); + + QWaylandDisplay *mDisplay; + QWaylandSelection *mSelection; + mutable QMimeData *mMimeDataIn; + QList mSelections; + QStringList mOfferedMimeTypes; + struct wl_selection_offer *mOffer; +}; + +#endif // QWAYLANDCLIPBOARD_H diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index 76f8be5..1303fcd 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -6,6 +6,8 @@ QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms DEFINES += Q_PLATFORM_WAYLAND DEFINES += $$QMAKE_DEFINES_WAYLAND +QT += core-private gui-private opengl-private + SOURCES = main.cpp \ qwaylandintegration.cpp \ qwaylandnativeinterface.cpp \ diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro index 101bdcd..139f5c9 100644 --- a/src/plugins/platforms/xcb/xcb.pro +++ b/src/plugins/platforms/xcb/xcb.pro @@ -3,6 +3,8 @@ TARGET = xcb include(../../qpluginbase.pri) QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms +QT += core-private gui-private + SOURCES = \ qxcbconnection.cpp \ qxcbintegration.cpp \ diff --git a/src/plugins/platforms/xlib/xlib.pro b/src/plugins/platforms/xlib/xlib.pro index ea77a29..ffce14b 100644 --- a/src/plugins/platforms/xlib/xlib.pro +++ b/src/plugins/platforms/xlib/xlib.pro @@ -3,6 +3,8 @@ TARGET = qxlib include(../../qpluginbase.pri) QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms +QT += core-private gui-private opengl-private + SOURCES = \ main.cpp \ qxlibintegration.cpp \ -- cgit v0.12 From 805a963d315e2f4b7dacc3e15a8ecf33179b6161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 9 May 2011 14:07:55 +0200 Subject: Remove not supported qmake api --- src/plugins/platforms/wayland/wayland.pro | 2 -- src/plugins/platforms/xcb/xcb.pro | 2 -- src/plugins/platforms/xlib/xlib.pro | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index 1303fcd..76f8be5 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -6,8 +6,6 @@ QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms DEFINES += Q_PLATFORM_WAYLAND DEFINES += $$QMAKE_DEFINES_WAYLAND -QT += core-private gui-private opengl-private - SOURCES = main.cpp \ qwaylandintegration.cpp \ qwaylandnativeinterface.cpp \ diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro index 139f5c9..101bdcd 100644 --- a/src/plugins/platforms/xcb/xcb.pro +++ b/src/plugins/platforms/xcb/xcb.pro @@ -3,8 +3,6 @@ TARGET = xcb include(../../qpluginbase.pri) QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms -QT += core-private gui-private - SOURCES = \ qxcbconnection.cpp \ qxcbintegration.cpp \ diff --git a/src/plugins/platforms/xlib/xlib.pro b/src/plugins/platforms/xlib/xlib.pro index ffce14b..ea77a29 100644 --- a/src/plugins/platforms/xlib/xlib.pro +++ b/src/plugins/platforms/xlib/xlib.pro @@ -3,8 +3,6 @@ TARGET = qxlib include(../../qpluginbase.pri) QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms -QT += core-private gui-private opengl-private - SOURCES = \ main.cpp \ qxlibintegration.cpp \ -- cgit v0.12 From 0dce79459e4ac5b2ed64c01052206e21764d8933 Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Mon, 9 May 2011 16:21:11 +0300 Subject: Provide internal API to avoid automatic translation of input widget There will be cases when client will want to disable splitview automatic view translation, so that keyboard is just brought on top of the application and no other actions happen. There will be no new public Qt GUI API to cover the cases (the public API will come from QML Components), but the implementation is done with new private API. Task-number: QTBUG-18716 Reviewed-by: Miikka Heikkinen --- src/gui/inputmethod/qcoefepinputcontext_p.h | 1 + src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 10 ++++++++-- src/gui/kernel/qt_s60_p.h | 2 ++ src/s60installs/bwins/QtGuiu.def | 1 + src/s60installs/eabi/QtGuiu.def | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/gui/inputmethod/qcoefepinputcontext_p.h b/src/gui/inputmethod/qcoefepinputcontext_p.h index de3577f..57c1e45 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_p.h +++ b/src/gui/inputmethod/qcoefepinputcontext_p.h @@ -168,6 +168,7 @@ private: }; Q_GUI_EXPORT void qt_s60_setPartialScreenInputMode(bool enable); +Q_GUI_EXPORT void qt_s60_setPartialScreenAutomaticTranslation(bool enable); QT_END_NAMESPACE diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 06dc25c..a4d53c0 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -88,6 +88,11 @@ Q_GUI_EXPORT void qt_s60_setPartialScreenInputMode(bool enable) ic->update(); } +Q_GUI_EXPORT void qt_s60_setPartialScreenAutomaticTranslation(bool enable) +{ + S60->partial_keyboardAutoTranslation = enable; +} + QCoeFepInputContext::QCoeFepInputContext(QObject *parent) : QInputContext(parent), m_fepState(q_check_ptr(new CAknEdwinState)), // CBase derived object needs check on new @@ -559,12 +564,13 @@ void QCoeFepInputContext::ensureFocusWidgetVisible(QWidget *widget) widget->resize(widget->width(), splitViewRect.height() - windowTop); } - if (gv->scene()) { + if (gv->scene() && S60->partial_keyboardAutoTranslation) { const QRectF microFocusRect = gv->scene()->inputMethodQuery(Qt::ImMicroFocus).toRectF(); gv->ensureVisible(microFocusRect); } } else { - translateInputWidget(); + if (S60->partial_keyboardAutoTranslation) + translateInputWidget(); } if (alwaysResize) diff --git a/src/gui/kernel/qt_s60_p.h b/src/gui/kernel/qt_s60_p.h index 02977ce..c5f7751 100644 --- a/src/gui/kernel/qt_s60_p.h +++ b/src/gui/kernel/qt_s60_p.h @@ -159,6 +159,7 @@ public: int menuBeingConstructed : 1; int orientationSet : 1; int partial_keyboard : 1; + int partial_keyboardAutoTranslation : 1; QApplication::QS60MainApplicationFactory s60ApplicationFactory; // typedef'ed pointer type QPointer splitViewLastWidget; @@ -348,6 +349,7 @@ inline QS60Data::QS60Data() menuBeingConstructed(0), orientationSet(0), partial_keyboard(0), + partial_keyboardAutoTranslation(1), s60ApplicationFactory(0) #ifdef Q_OS_SYMBIAN ,s60InstalledTrapHandler(0) diff --git a/src/s60installs/bwins/QtGuiu.def b/src/s60installs/bwins/QtGuiu.def index 813bbf8..495db21 100644 --- a/src/s60installs/bwins/QtGuiu.def +++ b/src/s60installs/bwins/QtGuiu.def @@ -13953,4 +13953,5 @@ EXPORTS ?staticMetaObjectExtraData@QWorkspace@@0UQMetaObjectExtraData@@B @ 13952 NONAME ; struct QMetaObjectExtraData const QWorkspace::staticMetaObjectExtraData ?staticMetaObjectExtraData@QSessionManager@@0UQMetaObjectExtraData@@B @ 13953 NONAME ; struct QMetaObjectExtraData const QSessionManager::staticMetaObjectExtraData ?qt_static_metacall@QGraphicsItemAnimation@@CAXPAVQObject@@W4Call@QMetaObject@@HPAPAX@Z @ 13954 NONAME ; void QGraphicsItemAnimation::qt_static_metacall(class QObject *, enum QMetaObject::Call, int, void * *) + ?qt_s60_setPartialScreenAutomaticTranslation@@YAX_N@Z @ 13955 NONAME ; void qt_s60_setPartialScreenAutomaticTranslation(bool) diff --git a/src/s60installs/eabi/QtGuiu.def b/src/s60installs/eabi/QtGuiu.def index 6646401..133e627 100644 --- a/src/s60installs/eabi/QtGuiu.def +++ b/src/s60installs/eabi/QtGuiu.def @@ -12799,4 +12799,5 @@ EXPORTS _ZNK10QZipWriter6deviceEv @ 12798 NONAME _ZNK10QZipWriter6existsEv @ 12799 NONAME _ZNK10QZipWriter6statusEv @ 12800 NONAME + _Z43qt_s60_setPartialScreenAutomaticTranslationb @ 12801 NONAME -- cgit v0.12 From bde58ad1e7d2b38d2882aaf869e93b0415128836 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 22 Mar 2011 11:13:08 +0100 Subject: Enable performance monitoring at application startup. Reviewed-by: Michael Brasser (cherry picked from commit 8765bdaebf5db409dc2121bce3b9838f3663bd7e) --- .../debugger/qdeclarativedebugserver.cpp | 50 +++++++++++++++++++--- .../debugger/qdeclarativedebugserver_p.h | 3 ++ .../debugger/qdeclarativedebugserverconnection_p.h | 1 + .../debugger/qdeclarativedebugservice.cpp | 10 +++++ .../debugger/qdeclarativedebugservice_p.h | 2 + .../debugger/qdeclarativedebugtrace.cpp | 9 +++- .../debugger/qdeclarativedebugtrace_p.h | 1 + src/declarative/debugger/qpacketprotocol.cpp | 49 ++++++++++++++++++++- src/declarative/debugger/qpacketprotocol_p.h | 2 + .../qmltooling/tcpserver/qtcpserverconnection.cpp | 14 +++++- .../qmltooling/tcpserver/qtcpserverconnection.h | 1 + 11 files changed, 132 insertions(+), 10 deletions(-) diff --git a/src/declarative/debugger/qdeclarativedebugserver.cpp b/src/declarative/debugger/qdeclarativedebugserver.cpp index f76c747..34ba520 100644 --- a/src/declarative/debugger/qdeclarativedebugserver.cpp +++ b/src/declarative/debugger/qdeclarativedebugserver.cpp @@ -90,7 +90,11 @@ public: QHash plugins; QStringList clientPlugins; bool gotHello; + QString waitingForMsgFromService; +private: + // private slot + void _q_deliverMessage(const QString &serviceName, const QByteArray &message); static QDeclarativeDebugServerConnection *loadConnectionPlugin(); }; @@ -227,7 +231,6 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) QDataStream in(message); if (!d->gotHello) { - QString name; int op; in >> name >> op; @@ -299,17 +302,33 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) QByteArray message; in >> message; - QHash::Iterator iter = - d->plugins.find(name); - if (iter == d->plugins.end()) { - qWarning() << "QDeclarativeDebugServer: Message received for missing plugin" << name; + if (d->waitingForMsgFromService == name) { + // deliver directly so that it is delivered before waitForMessage is returning. + d->_q_deliverMessage(name, message); + d->waitingForMsgFromService.clear(); } else { - (*iter)->messageReceived(message); + // deliver message in next event loop run. + // Fixes the case that the service does start it's own event loop ..., + // but the networking code doesn't deliver any new messages because readyRead + // hasn't returned. + QMetaObject::invokeMethod(this, "_q_deliverMessage", Qt::QueuedConnection, + Q_ARG(QString, name), + Q_ARG(QByteArray, message)); } } } } +void QDeclarativeDebugServerPrivate::_q_deliverMessage(const QString &serviceName, const QByteArray &message) +{ + QHash::Iterator iter = plugins.find(serviceName); + if (iter == plugins.end()) { + qWarning() << "QDeclarativeDebugServer: Message received for missing plugin" << serviceName; + } else { + (*iter)->messageReceived(message); + } +} + QList QDeclarativeDebugServer::services() const { const Q_D(QDeclarativeDebugServer); @@ -367,4 +386,23 @@ void QDeclarativeDebugServer::sendMessage(QDeclarativeDebugService *service, d->connection->send(msg); } +bool QDeclarativeDebugServer::waitForMessage(QDeclarativeDebugService *service) +{ + Q_D(QDeclarativeDebugServer); + + if (!service + || !d->plugins.contains(service->name()) + || !d->waitingForMsgFromService.isEmpty()) + return false; + + d->waitingForMsgFromService = service->name(); + + do { + d->connection->waitForMessage(); + } while (!d->waitingForMsgFromService.isEmpty()); + return true; +} + QT_END_NAMESPACE + +#include "moc_qdeclarativedebugserver_p.cpp" diff --git a/src/declarative/debugger/qdeclarativedebugserver_p.h b/src/declarative/debugger/qdeclarativedebugserver_p.h index 68ea4d8..72c664c 100644 --- a/src/declarative/debugger/qdeclarativedebugserver_p.h +++ b/src/declarative/debugger/qdeclarativedebugserver_p.h @@ -75,10 +75,13 @@ public: void sendMessage(QDeclarativeDebugService *service, const QByteArray &message); void receiveMessage(const QByteArray &message); + bool waitForMessage(QDeclarativeDebugService *service); + private: friend class QDeclarativeDebugService; friend class QDeclarativeDebugServicePrivate; QDeclarativeDebugServer(); + Q_PRIVATE_SLOT(d_func(), void _q_deliverMessage(QString, QByteArray)) }; QT_END_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativedebugserverconnection_p.h b/src/declarative/debugger/qdeclarativedebugserverconnection_p.h index 0c2bdb4..ca267e0 100644 --- a/src/declarative/debugger/qdeclarativedebugserverconnection_p.h +++ b/src/declarative/debugger/qdeclarativedebugserverconnection_p.h @@ -62,6 +62,7 @@ public: virtual bool isConnected() const = 0; virtual void send(const QByteArray &message) = 0; virtual void disconnect() = 0; + virtual bool waitForMessage() = 0; }; Q_DECLARE_INTERFACE(QDeclarativeDebugServerConnection, "com.trolltech.Qt.QDeclarativeDebugServerConnection/1.0") diff --git a/src/declarative/debugger/qdeclarativedebugservice.cpp b/src/declarative/debugger/qdeclarativedebugservice.cpp index 1b39f1c..c7e6615 100644 --- a/src/declarative/debugger/qdeclarativedebugservice.cpp +++ b/src/declarative/debugger/qdeclarativedebugservice.cpp @@ -209,6 +209,16 @@ void QDeclarativeDebugService::sendMessage(const QByteArray &message) d->server->sendMessage(this, message); } +bool QDeclarativeDebugService::waitForMessage() +{ + Q_D(QDeclarativeDebugService); + + if (status() != Enabled) + return false; + + return d->server->waitForMessage(this); +} + void QDeclarativeDebugService::statusChanged(Status) { } diff --git a/src/declarative/debugger/qdeclarativedebugservice_p.h b/src/declarative/debugger/qdeclarativedebugservice_p.h index 5e30350..f3d1919 100644 --- a/src/declarative/debugger/qdeclarativedebugservice_p.h +++ b/src/declarative/debugger/qdeclarativedebugservice_p.h @@ -69,6 +69,7 @@ public: Status status() const; void sendMessage(const QByteArray &); + bool waitForMessage(); static int idForObject(QObject *); static QObject *objectForId(int); @@ -84,6 +85,7 @@ protected: private: friend class QDeclarativeDebugServer; + friend class QDeclarativeDebugServerPrivate; }; QT_END_NAMESPACE diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp index 6f28736..edbbe78 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace.cpp +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -65,9 +65,14 @@ QByteArray QDeclarativeDebugData::toByteArray() const QDeclarativeDebugTrace::QDeclarativeDebugTrace() : QDeclarativeDebugService(QLatin1String("CanvasFrameRate")), - m_enabled(false), m_deferredSend(true) + m_enabled(false), m_deferredSend(true), m_messageReceived(false) { m_timer.start(); + if (status() == Enabled) { + // wait for first message indicating whether to trace or not + while (!m_messageReceived) + waitForMessage(); + } } void QDeclarativeDebugTrace::addEvent(EventType t) @@ -213,6 +218,8 @@ void QDeclarativeDebugTrace::messageReceived(const QByteArray &message) stream >> m_enabled; + m_messageReceived = true; + if (!m_enabled) sendMessages(); } diff --git a/src/declarative/debugger/qdeclarativedebugtrace_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h index ae0653e..c74cbe0 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace_p.h +++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h @@ -120,6 +120,7 @@ private: QPerformanceTimer m_timer; bool m_enabled; bool m_deferredSend; + bool m_messageReceived; QList m_data; }; diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp index 15a14cf..c1034a7 100644 --- a/src/declarative/debugger/qpacketprotocol.cpp +++ b/src/declarative/debugger/qpacketprotocol.cpp @@ -42,6 +42,7 @@ #include "private/qpacketprotocol_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -114,7 +115,7 @@ Q_OBJECT public: QPacketProtocolPrivate(QPacketProtocol * parent, QIODevice * _dev) : QObject(parent), inProgressSize(-1), maxPacketSize(MAX_PACKET_SIZE), - dev(_dev) + waitingForPacket(false), dev(_dev) { Q_ASSERT(4 == sizeof(qint32)); @@ -125,7 +126,7 @@ public: QObject::connect(this, SIGNAL(invalidPacket()), parent, SIGNAL(invalidPacket())); QObject::connect(dev, SIGNAL(readyRead()), - this, SLOT(readyToRead()), Qt::QueuedConnection); + this, SLOT(readyToRead())); QObject::connect(dev, SIGNAL(aboutToClose()), this, SLOT(aboutToClose())); QObject::connect(dev, SIGNAL(bytesWritten(qint64)), @@ -200,6 +201,7 @@ public Q_SLOTS: inProgress.clear(); emit readyRead(); + waitingForPacket = false; // Need to get trailing data readyToRead(); @@ -213,6 +215,7 @@ public: QByteArray inProgress; qint32 inProgressSize; qint32 maxPacketSize; + bool waitingForPacket; QIODevice * dev; }; @@ -324,6 +327,48 @@ QPacket QPacketProtocol::read() return rv; } +/* + Returns the difference between msecs and elapsed. If msecs is -1, + however, -1 is returned. +*/ +static int qt_timeout_value(int msecs, int elapsed) +{ + if (msecs == -1) + return -1; + + int timeout = msecs - elapsed; + return timeout < 0 ? 0 : timeout; +} + +/*! + This function locks until a new packet is available for reading and the + \l{QIODevice::}{readyRead()} signal has been emitted. The function + will timeout after \a msecs milliseconds; the default timeout is + 30000 milliseconds. + + The function returns true if the readyRead() signal is emitted and + there is new data available for reading; otherwise it returns false + (if an error occurred or the operation timed out). + */ + +bool QPacketProtocol::waitForReadyRead(int msecs) +{ + if (!d->packets.isEmpty()) + return true; + + QElapsedTimer stopWatch; + stopWatch.start(); + + d->waitingForPacket = true; + do { + if (!d->dev->waitForReadyRead(msecs)) + return false; + if (!d->waitingForPacket) + return true; + msecs = qt_timeout_value(msecs, stopWatch.elapsed()); + } while (true); +} + /*! Return the QIODevice passed to the QPacketProtocol constructor. */ diff --git a/src/declarative/debugger/qpacketprotocol_p.h b/src/declarative/debugger/qpacketprotocol_p.h index accb8ef..22bc3c2 100644 --- a/src/declarative/debugger/qpacketprotocol_p.h +++ b/src/declarative/debugger/qpacketprotocol_p.h @@ -75,6 +75,8 @@ public: qint64 packetsAvailable() const; QPacket read(); + bool waitForReadyRead(int msecs = 3000); + void clear(); QIODevice * device(); diff --git a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp index 44b2886..1da3043 100644 --- a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp +++ b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.cpp @@ -55,6 +55,7 @@ public: QTcpServerConnectionPrivate(); int port; + bool block; QTcpSocket *socket; QPacketProtocol *protocol; QTcpServer *tcpServer; @@ -64,6 +65,7 @@ public: QTcpServerConnectionPrivate::QTcpServerConnectionPrivate() : port(0), + block(false), socket(0), protocol(0), tcpServer(0), @@ -118,10 +120,17 @@ void QTcpServerConnection::disconnect() d->socket = 0; } +bool QTcpServerConnection::waitForMessage() +{ + Q_D(QTcpServerConnection); + return d->protocol->waitForReadyRead(-1); +} + void QTcpServerConnection::setPort(int port, bool block) { Q_D(QTcpServerConnection); d->port = port; + d->block = block; listen(); if (block) @@ -165,8 +174,11 @@ void QTcpServerConnection::newConnection() d->socket->setParent(this); d->protocol = new QPacketProtocol(d->socket, this); QObject::connect(d->protocol, SIGNAL(readyRead()), this, SLOT(readyRead())); -} + if (d->block) { + d->protocol->waitForReadyRead(-1); + } +} Q_EXPORT_PLUGIN2(tcpserver, QTcpServerConnection) diff --git a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h index 62791d3..dd5a5ec 100644 --- a/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h +++ b/src/plugins/qmltooling/tcpserver/qtcpserverconnection.h @@ -66,6 +66,7 @@ public: bool isConnected() const; void send(const QByteArray &message); void disconnect(); + bool waitForMessage(); void listen(); void waitForConnection(); -- cgit v0.12 From 79bf29e6b324313827042208c7555c568d2ed3d3 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 10 May 2011 12:25:31 +0300 Subject: Update softkeys after orientation switch. This is needed to render the softkeys correctly in case the softkeys have icons. Task-number: QTBUG-19150 Reviewed-by: Sami Merila --- src/gui/kernel/qapplication_s60.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 2221500..d6cafbd 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1509,6 +1509,10 @@ void QSymbianControl::HandleResourceChange(int resourceType) #ifdef Q_WS_S60 case KEikDynamicLayoutVariantSwitch: { +#ifdef QT_SOFTKEYS_ENABLED + // Update needed just in case softkeys contain icons + QSoftKeyManager::updateSoftKeys(); +#endif handleClientAreaChange(); // Send resize event to trigger desktopwidget workAreaResized signal if (qt_desktopWidget) { -- cgit v0.12 From eb07f3c1ad33b208d65d0af550ec279bac390c66 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 10 May 2011 12:46:52 +0300 Subject: Fix softkeys in case a dialog with softkeys that have icons is closed. Icons were not cleared from softkeys properly when a dialog with softkeys that had icons was closed, resulting in having those icons in softkeys that should have been empty or have text. Task-number: QTBUG-19154 Reviewed-by: Sami Merila --- src/gui/kernel/qsoftkeymanager_s60.cpp | 40 +++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/gui/kernel/qsoftkeymanager_s60.cpp b/src/gui/kernel/qsoftkeymanager_s60.cpp index 79ed91a..d80cf8a 100644 --- a/src/gui/kernel/qsoftkeymanager_s60.cpp +++ b/src/gui/kernel/qsoftkeymanager_s60.cpp @@ -278,12 +278,6 @@ bool QSoftKeyManagerPrivateS60::setSoftkeyImage(CEikButtonGroupContainer *cba, EikSoftkeyImage::SetImage(cba, *myimage, left); // Takes myimage ownership cbaHasImage[position] = true; ret = true; - } else { - // Restore softkey to text based - if (cbaHasImage[position]) { - EikSoftkeyImage::SetLabel(cba, left); - cbaHasImage[position] = false; - } } } return ret; @@ -294,7 +288,7 @@ bool QSoftKeyManagerPrivateS60::setSoftkey(CEikButtonGroupContainer &cba, { QAction *action = highestPrioritySoftkey(role); if (action) { - setSoftkeyImage(&cba, *action, position); + bool hasImage = setSoftkeyImage(&cba, *action, position); QString text = softkeyText(*action); TPtrC nativeText = qt_QString2TPtrC(text); int command = S60_COMMAND_START + position; @@ -303,6 +297,11 @@ bool QSoftKeyManagerPrivateS60::setSoftkey(CEikButtonGroupContainer &cba, command = softKeyCommandActions.value(action); #endif setNativeSoftkey(cba, position, command, nativeText); + if (!hasImage && cbaHasImage[position]) { + EikSoftkeyImage::SetLabel(&cba, (position == LSK_POSITION)); + cbaHasImage[position] = false; + } + const bool dimmed = !action->isEnabled() && !QSoftKeyManager::isForceEnabledInSofkeys(action); cba.DimCommand(command, dimmed); realSoftKeyActions.insert(command, action); @@ -313,7 +312,18 @@ bool QSoftKeyManagerPrivateS60::setSoftkey(CEikButtonGroupContainer &cba, bool QSoftKeyManagerPrivateS60::setLeftSoftkey(CEikButtonGroupContainer &cba) { - return setSoftkey(cba, QAction::PositiveSoftKey, LSK_POSITION); + if (!setSoftkey(cba, QAction::PositiveSoftKey, LSK_POSITION)) { + if (cbaHasImage[LSK_POSITION]) { + // Clear any residual icon if LSK has no action. A real softkey + // is needed for SetLabel command to work, so do a temporary dummy + setNativeSoftkey(cba, LSK_POSITION, EAknSoftkeyExit, KNullDesC); + EikSoftkeyImage::SetLabel(&cba, true); + setNativeSoftkey(cba, LSK_POSITION, EAknSoftkeyEmpty, KNullDesC); + cbaHasImage[LSK_POSITION] = false; + } + return false; + } + return true; } bool QSoftKeyManagerPrivateS60::setMiddleSoftkey(CEikButtonGroupContainer &cba) @@ -332,16 +342,26 @@ bool QSoftKeyManagerPrivateS60::setRightSoftkey(CEikButtonGroupContainer &cba) if (windowType != Qt::Dialog && windowType != Qt::Popup) { QString text(QSoftKeyManager::tr("Exit")); TPtrC nativeText = qt_QString2TPtrC(text); + setNativeSoftkey(cba, RSK_POSITION, EAknSoftkeyExit, nativeText); if (cbaHasImage[RSK_POSITION]) { EikSoftkeyImage::SetLabel(&cba, false); cbaHasImage[RSK_POSITION] = false; } - setNativeSoftkey(cba, RSK_POSITION, EAknSoftkeyExit, nativeText); cba.DimCommand(EAknSoftkeyExit, false); return true; + } else { + if (cbaHasImage[RSK_POSITION]) { + // Clear any residual icon if RSK has no action. A real softkey + // is needed for SetLabel command to work, so do a temporary dummy + setNativeSoftkey(cba, RSK_POSITION, EAknSoftkeyExit, KNullDesC); + EikSoftkeyImage::SetLabel(&cba, false); + setNativeSoftkey(cba, RSK_POSITION, EAknSoftkeyEmpty, KNullDesC); + cbaHasImage[RSK_POSITION] = false; + } + return false; } } - return false; + return true; } void QSoftKeyManagerPrivateS60::setSoftkeys(CEikButtonGroupContainer &cba) -- cgit v0.12 From 7acaea8557c1c6a758d9a26eff3fb1b3ec19084f Mon Sep 17 00:00:00 2001 From: Tom Sutcliffe Date: Wed, 11 May 2011 12:09:23 +0200 Subject: QmlDebug: Fix QmlOstPlugin compilation failure Implement waitForMessage()/waitForReadyRead functionality required by bde58ad1e7d2b38d. Reviewed-by: kkoehne --- src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp | 6 ++++ src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h | 1 + src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp | 42 +++++++++++++++++++++- src/plugins/qmltooling/qmldbg_ost/qostdevice.h | 4 ++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp index 1c91c34..3fb7ccf 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp +++ b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp @@ -109,6 +109,12 @@ void QmlOstPlugin::disconnect() d->protocol = 0; } +void QmlOstPlugin::waitForMessage() +{ + Q_D(QmlOstPlugin); + d->protocol->waitForReadyRead(-1); +} + void QmlOstPlugin::setPort(int port, bool block) { Q_UNUSED(port); diff --git a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h index eee6ee1..b4ff377 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h +++ b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h @@ -68,6 +68,7 @@ public: bool isConnected() const; void send(const QByteArray &message); void disconnect(); + bool waitForMessage(); private Q_SLOTS: void readyRead(); diff --git a/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp b/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp index 21b0169..d3b2661 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp +++ b/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp @@ -57,6 +57,8 @@ public: Cancel(); } + TInt& AoFlags() { return ((TInt*)&iStatus)[1]; } + private: void RunL(); void DoCancel(); @@ -65,6 +67,7 @@ private: RUsbOstComm ost; TBuf8<4096> readBuf; QByteArray dataBuf; + TBool inReadyRead; }; QOstDevice::QOstDevice(QObject *parent) : @@ -116,7 +119,11 @@ void QOstDevicePrivate::RunL() ost.ReadMessage(iStatus, readBuf); SetActive(); - emit q->readyRead(); + if (!inReadyRead) { + inReadyRead = true; + emit q->readyRead(); + inReadyRead = false; + } } else { q->setErrorString(QString("Error %1 from RUsbOstComm::ReadMessage()").arg(iStatus.Int())); } @@ -178,3 +185,36 @@ qint64 QOstDevice::bytesAvailable() const Q_D(const QOstDevice); return d->dataBuf.length(); } + +bool QOstDevice::waitForReadyRead(int msecs) +{ + Q_D(QOstDevice); + if (msecs >= 0) { + RTimer timer; + TInt err = timer.CreateLocal(); + if (err) return false; + TRequestStatus timeoutStat; + timer.After(timeoutStat, msecs*1000); + User::WaitForRequest(timeoutStat, d->iStatus); + if (timeoutStat != KRequestPending) { + // Timed out + timer.Close(); + return false; + } else { + // We got data, so cancel timer + timer.Cancel(); + User::WaitForRequest(timeoutStat); + timer.Close(); + // And drop through + } + } else { + // Just wait forever for data + User::WaitForRequest(d->iStatus); + } + + // If we get here we have data + TInt err = d->iStatus.Int(); + d->AoFlags() &= ~3; // This is necessary to clean up the scheduler as you're not supposed to bypass it like this + TRAP_IGNORE(d->RunL()); + return err == KErrNone; +} diff --git a/src/plugins/qmltooling/qmldbg_ost/qostdevice.h b/src/plugins/qmltooling/qmldbg_ost/qostdevice.h index 2c26ff7..200e607 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qostdevice.h +++ b/src/plugins/qmltooling/qmldbg_ost/qostdevice.h @@ -61,10 +61,12 @@ public: bool open(int ostProtocolId); void close(); + bool waitForReadyRead(int msecs); + qint64 bytesAvailable() const; + protected: qint64 readData(char *data, qint64 maxSize); qint64 writeData(const char *data, qint64 maxSize); - qint64 bytesAvailable() const; private: QOstDevicePrivate* d_ptr; -- cgit v0.12 From fab911a64a72d5b7f450f3f3616e38c96d601553 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 11 May 2011 12:24:46 +0200 Subject: fixup for 23e772584531278e3b2a6c735ff9db88f7ffd76e Reviewed-by: TrustMe --- qmake/generators/makefile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index c3d3933..8768861 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -2524,7 +2524,7 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QListtarget << "-" << targetSuffixes.at(suffix) << "-ordered "; if(project->isEmpty("QMAKE_NOFORCE")) t << " FORCE"; - writeSubMakeCall(t, out_directory_cdin, makefilein, out_directory_cdout); + writeSubMakeCall(t, out_directory_cdin, makefilein + " " + s, out_directory_cdout); } t << subtarget->target << "-" << targetSuffixes.at(suffix) << ": " << mkfile; if(!subtarget->depends.isEmpty()) @@ -2532,7 +2532,7 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QListisEmpty("QMAKE_NOFORCE")) t << " FORCE"; - writeSubMakeCall(t, out_directory_cdin, makefilein, out_directory_cdout); + writeSubMakeCall(t, out_directory_cdin, makefilein + " " + s, out_directory_cdout); } } t << endl; -- cgit v0.12 From 68f37a29f911fce5bcdd285b1fc1bc6d4868d78e Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Wed, 11 May 2011 12:32:46 +0200 Subject: Fix GLES2 include path for applications when not using the dash shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backslash escapes normally requires "-e" option to echo Reviewed-by: Jørgen --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 5bdf8af..71f8353 100755 --- a/configure +++ b/configure @@ -8402,7 +8402,7 @@ if [ -n "$QT_CFLAGS_FPU" ]; then fi if [ -n "$QMAKE_INCDIR_OPENGL_ES2" ]; then - echo "\n#Qt opengl include path" >> "$QTCONFIG.tmp" + echo "#Qt opengl include path" >> "$QTCONFIG.tmp" echo "QMAKE_INCDIR_OPENGL_ES2 = \"$QMAKE_INCDIR_OPENGL_ES2\"" >> "$QTCONFIG.tmp" fi -- cgit v0.12 From 5c830ed2a612b940c377fb4e8a2372655f175707 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 12 May 2011 08:33:21 +0200 Subject: QmlDebug: Fix QmlOstPlugin compilation failure Fix signature of waitForMessage. Reviewed-by: Tom Sutcliffe --- src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp index 3fb7ccf..ac32081 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp +++ b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp @@ -109,10 +109,10 @@ void QmlOstPlugin::disconnect() d->protocol = 0; } -void QmlOstPlugin::waitForMessage() +bool QmlOstPlugin::waitForMessage() { Q_D(QmlOstPlugin); - d->protocol->waitForReadyRead(-1); + return d->protocol->waitForReadyRead(-1); } void QmlOstPlugin::setPort(int port, bool block) -- cgit v0.12 From 87b50f0b3615e6c14df8282cbc3ecb2ab03a9b9e Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Thu, 12 May 2011 10:27:03 +0300 Subject: Symbian build failure for Armv5 1. Changed externs to Q_GUI_EXPORTs 2. ABSENTed missing exports from openGL's DEF-file Reviewed-by: Tomi Vihria --- src/gui/painting/qpainter.cpp | 2 +- src/opengl/qpaintengine_opengl.cpp | 4 ++-- src/openvg/qpaintengine_vg.cpp | 4 ++-- src/s60installs/eabi/QtOpenGLu.def | 14 +++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 9e28102..3fd4c5b 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -692,7 +692,7 @@ void QPainterPrivate::updateInvMatrix() invMatrix = state->matrix.inverted(); } -extern bool qt_isExtendedRadialGradient(const QBrush &brush); +Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush); void QPainterPrivate::updateEmulationSpecifier(QPainterState *s) { diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 5fa9f32..58ce6f8 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -2119,7 +2119,7 @@ void QOpenGLPaintEnginePrivate::fillPath(const QPainterPath &path) updateGLMatrix(); } -extern bool qt_isExtendedRadialGradient(const QBrush &brush); +Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush); static inline bool needsEmulation(Qt::BrushStyle style) { @@ -5450,7 +5450,7 @@ void QOpenGLPaintEngine::transformChanged() updateMatrix(state()->matrix); } -extern QPainterPath qt_painterPathFromVectorPath(const QVectorPath &path); +Q_GUI_EXPORT QPainterPath qt_painterPathFromVectorPath(const QVectorPath &path); void QOpenGLPaintEngine::fill(const QVectorPath &path, const QBrush &brush) { diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index 68a6a0b..70e26fb 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -280,7 +280,7 @@ public: inline bool needsEmulation(const QBrush &brush) const { - extern bool qt_isExtendedRadialGradient(const QBrush &brush); + Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush); return qt_isExtendedRadialGradient(brush); } @@ -1579,7 +1579,7 @@ void QVGPaintEngine::draw(const QVectorPath &path) vgDestroyPath(vgpath); } -extern QPainterPath qt_painterPathFromVectorPath(const QVectorPath &path); +Q_GUI_EXPORT QPainterPath qt_painterPathFromVectorPath(const QVectorPath &path); void QVGPaintEngine::fill(const QVectorPath &path, const QBrush &brush) { diff --git a/src/s60installs/eabi/QtOpenGLu.def b/src/s60installs/eabi/QtOpenGLu.def index 44f7306..11ac503 100644 --- a/src/s60installs/eabi/QtOpenGLu.def +++ b/src/s60installs/eabi/QtOpenGLu.def @@ -759,11 +759,11 @@ EXPORTS _ZNK14QGLPaintDevice9isFlippedEv @ 758 NONAME _ZNK16QGLWindowSurface8featuresEv @ 759 NONAME _ZNK26QGLFramebufferObjectFormat6mipmapEv @ 760 NONAME - _ZTI22QGLContextResourceBase @ 761 NONAME - _ZTI27QGLContextGroupResourceBase @ 762 NONAME - _ZTV22QGLContextResourceBase @ 763 NONAME - _ZTV27QGLContextGroupResourceBase @ 764 NONAME - _ZThn104_N20QGLTextureGlyphCacheD0Ev @ 765 NONAME - _ZThn104_N20QGLTextureGlyphCacheD1Ev @ 766 NONAME - _ZThn8_NK16QGLWindowSurface8featuresEv @ 767 NONAME + _ZTI22QGLContextResourceBase @ 761 NONAME ABSENT + _ZTI27QGLContextGroupResourceBase @ 762 NONAME ABSENT + _ZTV22QGLContextResourceBase @ 763 NONAME ABSENT + _ZTV27QGLContextGroupResourceBase @ 764 NONAME ABSENT + _ZThn104_N20QGLTextureGlyphCacheD0Ev @ 765 NONAME ABSENT + _ZThn104_N20QGLTextureGlyphCacheD1Ev @ 766 NONAME ABSENT + _ZThn8_NK16QGLWindowSurface8featuresEv @ 767 NONAME ABSENT -- cgit v0.12 From d7d9a14de00f9391ab0be953357d24713f580675 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 11 May 2011 15:42:25 +0300 Subject: Fix loss of focus and activation when hiding a child widget Don't deactivate the active window when hiding its child if it has another child that currently has the focus. Task-number: QTBUG-19196 Reviewed-by: Sami Merila --- src/gui/kernel/qapplication_s60.cpp | 31 ++++++++++++++++++++----------- src/gui/kernel/qt_s60_p.h | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index d6cafbd..68c1ab5 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1360,6 +1360,23 @@ void QSymbianControl::PositionChanged() } } +// Search recursively if there is a child widget that is both visible and focused. +bool QSymbianControl::hasFocusedAndVisibleChild(QWidget *parentWidget) +{ + for (int i = 0; i < parentWidget->children().size(); ++i) { + QObject *object = parentWidget->children().at(i); + if (object && object->isWidgetType()) { + QWidget *w = static_cast(object); + WId winId = w->internalWinId(); + if (winId && winId->IsFocused() && winId->IsVisible()) + return true; + if (hasFocusedAndVisibleChild(w)) + return true; + } + } + return false; +} + void QSymbianControl::FocusChanged(TDrawNow /* aDrawNow */) { if (m_ignoreFocusChanged || (qwidget->windowType() & Qt::WindowType_Mask) == Qt::Desktop) @@ -1392,17 +1409,9 @@ void QSymbianControl::FocusChanged(TDrawNow /* aDrawNow */) if (qwidget->isWindow()) S60->setRecursiveDecorationsVisibility(qwidget, qwidget->windowState()); #endif - } else if (QApplication::activeWindow() == qwidget->window()) { - bool focusedControlFound = false; - WId winId = 0; - for (QWidget *w = qwidget->parentWidget(); w && (winId = w->internalWinId()); w = w->parentWidget()) { - if (winId->IsFocused() && winId->IsVisible()) { - focusedControlFound = true; - break; - } else if (w->isWindow()) - break; - } - if (!focusedControlFound) { + } else { + QWidget *parentWindow = qwidget->window(); + if (QApplication::activeWindow() == parentWindow && !hasFocusedAndVisibleChild(parentWindow)) { if (CCoeEnv::Static()->AppUi()->IsDisplayingMenuOrDialog() || S60->menuBeingConstructed) { QWidget *fw = QApplication::focusWidget(); if (fw) { diff --git a/src/gui/kernel/qt_s60_p.h b/src/gui/kernel/qt_s60_p.h index c5f7751..4640393 100644 --- a/src/gui/kernel/qt_s60_p.h +++ b/src/gui/kernel/qt_s60_p.h @@ -300,6 +300,7 @@ private: void translateAdvancedPointerEvent(const TAdvancedPointerEvent *event); #endif bool isSplitViewWidget(QWidget *widget); + bool hasFocusedAndVisibleChild(QWidget *parentWidget); public: void handleClientAreaChange(); -- cgit v0.12 From bd7109bd2517de14d10e14c689b07f94f174396f Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 9 Feb 2011 16:00:31 +0100 Subject: Move qmldump from Qt Creator to Qt. Also rename it to qmlplugindump. Qmlplugindump is a tool that loads a QML module and prints type information about the types contained in its plugins to the standard output. Reviewed-by: Aaron Kennedy Change-Id: I7c35c34af23adc1c37453393d71e492dedfc6a9b (cherry picked from b5265d4e99e5c90532e190632951070cf1a2b630) --- tools/qmlplugindump/Info.plist | 16 + tools/qmlplugindump/main.cpp | 574 ++++++++++++++++++++++++++++++++ tools/qmlplugindump/qmlplugindump.pro | 20 ++ tools/qmlplugindump/qmlstreamwriter.cpp | 183 ++++++++++ tools/qmlplugindump/qmlstreamwriter.h | 79 +++++ tools/tools.pro | 5 +- 6 files changed, 876 insertions(+), 1 deletion(-) create mode 100644 tools/qmlplugindump/Info.plist create mode 100644 tools/qmlplugindump/main.cpp create mode 100644 tools/qmlplugindump/qmlplugindump.pro create mode 100644 tools/qmlplugindump/qmlstreamwriter.cpp create mode 100644 tools/qmlplugindump/qmlstreamwriter.h diff --git a/tools/qmlplugindump/Info.plist b/tools/qmlplugindump/Info.plist new file mode 100644 index 0000000..f35846d --- /dev/null +++ b/tools/qmlplugindump/Info.plist @@ -0,0 +1,16 @@ + + + + + CFBundlePackageType + APPL + CFBundleSignature + @TYPEINFO@ + CFBundleExecutable + @EXECUTABLE@ + CFBundleIdentifier + com.nokia.qt.qmlplugindump + LSUIElement + 1 + + diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp new file mode 100644 index 0000000..5ed5e2e --- /dev/null +++ b/tools/qmlplugindump/main.cpp @@ -0,0 +1,574 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "qmlstreamwriter.h" + +#ifdef QT_SIMULATOR +#include +#endif + +#ifdef Q_OS_UNIX +#include +#endif + +void collectReachableMetaObjects(const QMetaObject *meta, QSet *metas) +{ + if (! meta || metas->contains(meta)) + return; + + // dynamic meta objects break things badly, so just ignore them + const QMetaObjectPrivate *mop = reinterpret_cast(meta->d.data); + if (!(mop->flags & DynamicMetaObject)) + metas->insert(meta); + + collectReachableMetaObjects(meta->superClass(), metas); +} + +QString currentProperty; + +void collectReachableMetaObjects(QObject *object, QSet *metas) +{ + if (! object) + return; + + const QMetaObject *meta = object->metaObject(); + qDebug() << "Processing object" << meta->className(); + collectReachableMetaObjects(meta, metas); + + for (int index = 0; index < meta->propertyCount(); ++index) { + QMetaProperty prop = meta->property(index); + if (QDeclarativeMetaType::isQObject(prop.userType())) { + qDebug() << " Processing property" << prop.name(); + currentProperty = QString("%1::%2").arg(meta->className(), prop.name()); + + // if the property was not initialized during construction, + // accessing a member of oo is going to cause a segmentation fault + QObject *oo = QDeclarativeMetaType::toQObject(prop.read(object)); + if (oo && !metas->contains(oo->metaObject())) + collectReachableMetaObjects(oo, metas); + currentProperty.clear(); + } + } +} + +void collectReachableMetaObjects(const QDeclarativeType *ty, QSet *metas) +{ + collectReachableMetaObjects(ty->metaObject(), metas); + if (ty->attachedPropertiesType()) + collectReachableMetaObjects(ty->attachedPropertiesType(), metas); +} + +/* We want to add the MetaObject for 'Qt' to the list, this is a + simple way to access it. +*/ +class FriendlyQObject: public QObject +{ +public: + static const QMetaObject *qtMeta() { return &staticQtMetaObject; } +}; + +/* When we dump a QMetaObject, we want to list all the types it is exported as. + To do this, we need to find the QDeclarativeTypes associated with this + QMetaObject. +*/ +static QHash > qmlTypesByCppName; + +static QHash cppToId; + +/* Takes a C++ type name, such as Qt::LayoutDirection or QString and + maps it to how it should appear in the description file. + + These names need to be unique globally, so we don't change the C++ symbol's + name much. It is mostly used to for explicit translations such as + QString->string and translations for extended QML objects. +*/ +QByteArray convertToId(const QByteArray &cppName) +{ + return cppToId.value(cppName, cppName); +} + +QSet collectReachableMetaObjects(const QString &importCode, QDeclarativeEngine *engine) +{ + QSet metas; + metas.insert(FriendlyQObject::qtMeta()); + + QHash > extensions; + foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { + qmlTypesByCppName[ty->metaObject()->className()].insert(ty); + if (ty->isExtendedType()) { + extensions[ty->typeName()].insert(ty->metaObject()->className()); + } + collectReachableMetaObjects(ty, &metas); + } + + // Adjust ids of extended objects. + // The chain ends up being: + // __extended__.originalname - the base object + // __extension_0_.originalname - first extension + // .. + // __extension_n-2_.originalname - second to last extension + // originalname - last extension + // ### does this actually work for multiple extensions? it seems like the prototypes might be wrong + foreach (const QByteArray &extendedCpp, extensions.keys()) { + cppToId.remove(extendedCpp); + const QByteArray extendedId = convertToId(extendedCpp); + cppToId.insert(extendedCpp, "__extended__." + extendedId); + QSet extensionCppNames = extensions.value(extendedCpp); + int c = 0; + foreach (const QByteArray &extensionCppName, extensionCppNames) { + if (c != extensionCppNames.size() - 1) { + QByteArray adjustedName = QString("__extension__%1.%2").arg(QString::number(c), QString(extendedId)).toAscii(); + cppToId.insert(extensionCppName, adjustedName); + } else { + cppToId.insert(extensionCppName, extendedId); + } + ++c; + } + } + + // find even more QMetaObjects by instantiating QML types and running + // over the instances + foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { + if (ty->isExtendedType()) + continue; + + QByteArray tyName = ty->qmlTypeName(); + tyName = tyName.mid(tyName.lastIndexOf('/') + 1); + + QByteArray code = importCode.toUtf8(); + code += tyName; + code += " {}\n"; + + QDeclarativeComponent c(engine); + c.setData(code, QUrl("typeinstance")); + + QObject *object = c.create(); + if (object) + collectReachableMetaObjects(object, &metas); + else + qDebug() << "Could not create" << tyName << ":" << c.errorString(); + } + + return metas; +} + + +class Dumper +{ + QmlStreamWriter *qml; + QString relocatableModuleUri; + +public: + Dumper(QmlStreamWriter *qml) : qml(qml) {} + + void setRelocatableModuleUri(const QString &uri) + { + relocatableModuleUri = uri; + } + + void dump(const QMetaObject *meta) + { + qml->writeStartObject("Component"); + + QByteArray id = convertToId(meta->className()); + qml->writeScriptBinding(QLatin1String("name"), enquote(id)); + + for (int index = meta->classInfoCount() - 1 ; index >= 0 ; --index) { + QMetaClassInfo classInfo = meta->classInfo(index); + if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) { + qml->writeScriptBinding(QLatin1String("defaultProperty"), enquote(QLatin1String(classInfo.value()))); + break; + } + } + + if (meta->superClass()) + qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass()->className()))); + + QSet qmlTypes = qmlTypesByCppName.value(meta->className()); + if (!qmlTypes.isEmpty()) { + QStringList exports; + + foreach (const QDeclarativeType *qmlTy, qmlTypes) { + QString qmlTyName = qmlTy->qmlTypeName(); + // some qmltype names are missing the actual names, ignore that import + if (qmlTyName.endsWith('/')) + continue; + if (!relocatableModuleUri.isNull() + && qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) { + qmlTyName.remove(0, relocatableModuleUri.size() + 1); + } + exports += enquote(QString("%1 %2.%3").arg( + qmlTyName, + QString::number(qmlTy->majorVersion()), + QString::number(qmlTy->minorVersion()))); + } + + // ensure exports are sorted and don't change order when the plugin is dumped again + exports.removeDuplicates(); + qSort(exports); + + qml->writeArrayBinding(QLatin1String("exports"), exports); + + if (const QMetaObject *attachedType = (*qmlTypes.begin())->attachedPropertiesType()) { + qml->writeScriptBinding(QLatin1String("attachedType"), enquote( + convertToId(attachedType->className()))); + } + } + + for (int index = meta->enumeratorOffset(); index < meta->enumeratorCount(); ++index) + dump(meta->enumerator(index)); + + for (int index = meta->propertyOffset(); index < meta->propertyCount(); ++index) + dump(meta->property(index)); + + for (int index = meta->methodOffset(); index < meta->methodCount(); ++index) + dump(meta->method(index)); + + qml->writeEndObject(); + } + + void writeEasingCurve() + { + qml->writeStartObject("Component"); + qml->writeScriptBinding(QLatin1String("name"), enquote(QLatin1String("QEasingCurve"))); + qml->writeScriptBinding(QLatin1String("prototype"), enquote(QLatin1String("QDeclarativeEasingValueType"))); + qml->writeEndObject(); + } + +private: + static QString enquote(const QString &string) + { + return QString("\"%1\"").arg(string); + } + + /* Removes pointer and list annotations from a type name, returning + what was removed in isList and isPointer + */ + static void removePointerAndList(QByteArray *typeName, bool *isList, bool *isPointer) + { + static QByteArray declListPrefix = "QDeclarativeListProperty<"; + + if (typeName->endsWith('*')) { + *isPointer = true; + typeName->truncate(typeName->length() - 1); + removePointerAndList(typeName, isList, isPointer); + } else if (typeName->startsWith(declListPrefix)) { + *isList = true; + typeName->truncate(typeName->length() - 1); // get rid of the suffix '>' + *typeName = typeName->mid(declListPrefix.size()); + removePointerAndList(typeName, isList, isPointer); + } + + *typeName = convertToId(*typeName); + } + + void writeTypeProperties(QByteArray typeName, bool isWritable) + { + bool isList = false, isPointer = false; + removePointerAndList(&typeName, &isList, &isPointer); + + qml->writeScriptBinding(QLatin1String("type"), enquote(typeName)); + if (isList) + qml->writeScriptBinding(QLatin1String("isList"), QLatin1String("true")); + if (!isWritable) + qml->writeScriptBinding(QLatin1String("isReadonly"), QLatin1String("true")); + if (isPointer) + qml->writeScriptBinding(QLatin1String("isPointer"), QLatin1String("true")); + } + + void dump(const QMetaProperty &prop) + { + qml->writeStartObject("Property"); + + qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(prop.name()))); + writeTypeProperties(prop.typeName(), prop.isWritable()); + + qml->writeEndObject(); + } + + void dump(const QMetaMethod &meth) + { + if (meth.methodType() == QMetaMethod::Signal) { + if (meth.access() != QMetaMethod::Protected) + return; // nothing to do. + } else if (meth.access() != QMetaMethod::Public) { + return; // nothing to do. + } + + QByteArray name = meth.signature(); + int lparenIndex = name.indexOf('('); + if (lparenIndex == -1) { + return; // invalid signature + } + name = name.left(lparenIndex); + + if (meth.methodType() == QMetaMethod::Signal) + qml->writeStartObject(QLatin1String("Signal")); + else + qml->writeStartObject(QLatin1String("Method")); + + qml->writeScriptBinding(QLatin1String("name"), enquote(name)); + + const QString typeName = convertToId(meth.typeName()); + if (! typeName.isEmpty()) + qml->writeScriptBinding(QLatin1String("type"), enquote(typeName)); + + for (int i = 0; i < meth.parameterTypes().size(); ++i) { + QByteArray argName = meth.parameterNames().at(i); + + qml->writeStartObject(QLatin1String("Parameter")); + if (! argName.isEmpty()) + qml->writeScriptBinding(QLatin1String("name"), enquote(argName)); + writeTypeProperties(meth.parameterTypes().at(i), true); + qml->writeEndObject(); + } + + qml->writeEndObject(); + } + + void dump(const QMetaEnum &e) + { + qml->writeStartObject(QLatin1String("Enum")); + qml->writeScriptBinding(QLatin1String("name"), enquote(QString::fromUtf8(e.name()))); + + QList > namesValues; + for (int index = 0; index < e.keyCount(); ++index) { + namesValues.append(qMakePair(enquote(QString::fromUtf8(e.key(index))), QString::number(e.value(index)))); + } + + qml->writeScriptObjectLiteralBinding(QLatin1String("values"), namesValues); + qml->writeEndObject(); + } +}; + + +enum ExitCode { + EXIT_INVALIDARGUMENTS = 1, + EXIT_SEGV = 2, + EXIT_IMPORTERROR = 3 +}; + +#ifdef Q_OS_UNIX +void sigSegvHandler(int) { + fprintf(stderr, "Error: SEGV\n"); + if (!currentProperty.isEmpty()) + fprintf(stderr, "While processing the property '%s', which probably has uninitialized data.\n", currentProperty.toLatin1().constData()); + exit(EXIT_SEGV); +} +#endif + +void printUsage(const QString &appName) +{ + qWarning() << qPrintable(QString( + "Usage: %1 [--notrelocatable] module.uri version [module/import/path]\n" + " %1 --builtins\n" + "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg( + appName)); +} + +int main(int argc, char *argv[]) +{ +#ifdef Q_OS_UNIX + // qmldump may crash, but we don't want any crash handlers to pop up + // therefore we intercept the segfault and just exit() ourselves + struct sigaction action; + + sigemptyset(&action.sa_mask); + action.sa_handler = &sigSegvHandler; + action.sa_flags = 0; + + sigaction(SIGSEGV, &action, 0); +#endif + +#ifdef QT_SIMULATOR + // Running this application would bring up the Qt Simulator (since it links QtGui), avoid that! + QtSimulatorPrivate::SimulatorConnection::createStubInstance(); +#endif + QApplication app(argc, argv); + const QStringList args = app.arguments(); + const QString appName = QFileInfo(app.applicationFilePath()).baseName(); + if (!(args.size() >= 3 || (args.size() == 2 && args.at(1) == QLatin1String("--builtins")))) { + printUsage(appName); + return EXIT_INVALIDARGUMENTS; + } + + QString pluginImportUri; + QString pluginImportVersion; + QString pluginImportPath; + bool relocatable = true; + if (args.size() >= 3) { + QStringList positionalArgs; + foreach (const QString &arg, args) { + if (!arg.startsWith("--")) { + positionalArgs.append(arg); + continue; + } + + if (arg == QLatin1String("--notrelocatable")) { + relocatable = false; + } else { + qWarning() << "Invalid argument: " << arg; + return EXIT_INVALIDARGUMENTS; + } + } + + if (positionalArgs.size() != 3 && positionalArgs.size() != 4) { + qWarning() << "Incorrect number of positional arguments"; + return EXIT_INVALIDARGUMENTS; + } + pluginImportUri = positionalArgs[1]; + pluginImportVersion = positionalArgs[2]; + if (positionalArgs.size() >= 4) + pluginImportPath = positionalArgs[3]; + } + + QDeclarativeView view; + QDeclarativeEngine *engine = view.engine(); + if (!pluginImportPath.isEmpty()) + engine->addImportPath(pluginImportPath); + + // find all QMetaObjects reachable from the builtin module + QByteArray importCode("import QtQuick 1.0\n"); + QSet defaultReachable = collectReachableMetaObjects(importCode, engine); + + // this will hold the meta objects we want to dump information of + QSet metas; + + if (pluginImportUri.isEmpty()) { + metas = defaultReachable; + } else { + // find all QMetaObjects reachable when the specified module is imported + importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii(); + + // create a component with these imports to make sure the imports are valid + // and to populate the declarative meta type system + { + QByteArray code = importCode; + code += "QtObject {}"; + QDeclarativeComponent c(engine); + + c.setData(code, QUrl("typelist")); + c.create(); + if (!c.errors().isEmpty()) { + foreach (const QDeclarativeError &error, c.errors()) + qWarning() << error.toString(); + return EXIT_IMPORTERROR; + } + } + + QSet candidates = collectReachableMetaObjects(importCode, engine); + candidates.subtract(defaultReachable); + + // Also eliminate meta objects with the same classname. + // This is required because extended objects seem not to share + // a single meta object instance. + QSet defaultReachableNames; + foreach (const QMetaObject *mo, defaultReachable) + defaultReachableNames.insert(QByteArray(mo->className())); + foreach (const QMetaObject *mo, candidates) { + if (!defaultReachableNames.contains(mo->className())) + metas.insert(mo); + } + } + + // setup static rewrites of type names + cppToId.insert("QString", "string"); + cppToId.insert("QDeclarativeEasingValueType::Type", "Type"); + + // start dumping data + QByteArray bytes; + QmlStreamWriter qml(&bytes); + + qml.writeStartDocument(); + qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 0); + qml.write("\n" + "// This file describes the plugin-supplied types contained in the library.\n" + "// It is used for QML tooling purposes only.\n" + "\n"); + qml.writeStartObject("Module"); + + // put the metaobjects into a map so they are always dumped in the same order + QMap nameToMeta; + foreach (const QMetaObject *meta, metas) + nameToMeta.insert(convertToId(meta->className()), meta); + + Dumper dumper(&qml); + if (relocatable) + dumper.setRelocatableModuleUri(pluginImportUri); + foreach (const QMetaObject *meta, nameToMeta) { + dumper.dump(meta); + } + + // define QEasingCurve as an extension of QDeclarativeEasingValueType, this way + // properties using the QEasingCurve type get useful type information. + if (pluginImportUri.isEmpty()) + dumper.writeEasingCurve(); + + qml.writeEndObject(); + qml.writeEndDocument(); + + std::cout << bytes.constData(); + + // workaround to avoid crashes on exit + QTimer timer; + timer.setSingleShot(true); + timer.setInterval(0); + QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit())); + timer.start(); + + return app.exec(); +} diff --git a/tools/qmlplugindump/qmlplugindump.pro b/tools/qmlplugindump/qmlplugindump.pro new file mode 100644 index 0000000..53827e2 --- /dev/null +++ b/tools/qmlplugindump/qmlplugindump.pro @@ -0,0 +1,20 @@ +TEMPLATE = app +CONFIG += qt uic console +DESTDIR = ../../bin + +QT += declarative + +TARGET = qmlplugindump + +SOURCES += \ + main.cpp \ + qmlstreamwriter.cpp + +HEADERS += \ + qmlstreamwriter.h + +OTHER_FILES += Info.plist +macx: QMAKE_INFO_PLIST = Info.plist + +target.path = $$[QT_INSTALL_BINS] +INSTALLS += target diff --git a/tools/qmlplugindump/qmlstreamwriter.cpp b/tools/qmlplugindump/qmlstreamwriter.cpp new file mode 100644 index 0000000..d083f7b --- /dev/null +++ b/tools/qmlplugindump/qmlstreamwriter.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlstreamwriter.h" + +#include +#include + +QmlStreamWriter::QmlStreamWriter(QByteArray *array) + : m_indentDepth(0) + , m_pendingLineLength(0) + , m_maybeOneline(false) + , m_stream(new QBuffer(array)) +{ + m_stream->open(QIODevice::WriteOnly); +} + +void QmlStreamWriter::writeStartDocument() +{ +} + +void QmlStreamWriter::writeEndDocument() +{ +} + +void QmlStreamWriter::writeLibraryImport(const QString &uri, int majorVersion, int minorVersion, const QString &as) +{ + m_stream->write(QString("import %1 %2.%3").arg(uri, QString::number(majorVersion), QString::number(minorVersion)).toUtf8()); + if (!as.isEmpty()) + m_stream->write(QString(" as %1").arg(as).toUtf8()); + m_stream->write("\n"); +} + +void QmlStreamWriter::writeStartObject(const QString &component) +{ + flushPotentialLinesWithNewlines(); + writeIndent(); + m_stream->write(QString("%1 {").arg(component).toUtf8()); + ++m_indentDepth; + m_maybeOneline = true; +} + +void QmlStreamWriter::writeEndObject() +{ + if (m_maybeOneline && !m_pendingLines.isEmpty()) { + --m_indentDepth; + for (int i = 0; i < m_pendingLines.size(); ++i) { + m_stream->write(" "); + m_stream->write(m_pendingLines.at(i).trimmed()); + if (i != m_pendingLines.size() - 1) + m_stream->write(";"); + } + m_stream->write(" }\n"); + m_pendingLines.clear(); + m_pendingLineLength = 0; + m_maybeOneline = false; + } else { + if (m_maybeOneline) + flushPotentialLinesWithNewlines(); + --m_indentDepth; + writeIndent(); + m_stream->write("}\n"); + } +} + +void QmlStreamWriter::writeScriptBinding(const QString &name, const QString &rhs) +{ + writePotentialLine(QString("%1: %2").arg(name, rhs).toUtf8()); +} + +void QmlStreamWriter::writeArrayBinding(const QString &name, const QStringList &elements) +{ + flushPotentialLinesWithNewlines(); + writeIndent(); + m_stream->write(QString("%1: [\n").arg(name).toUtf8()); + ++m_indentDepth; + for (int i = 0; i < elements.size(); ++i) { + writeIndent(); + m_stream->write(elements.at(i).toUtf8()); + if (i != elements.size() - 1) { + m_stream->write(",\n"); + } else { + m_stream->write("\n"); + } + } + --m_indentDepth; + writeIndent(); + m_stream->write("]\n"); +} + +void QmlStreamWriter::write(const QString &data) +{ + flushPotentialLinesWithNewlines(); + m_stream->write(data.toUtf8()); +} + +void QmlStreamWriter::writeScriptObjectLiteralBinding(const QString &name, const QList > &keyValue) +{ + flushPotentialLinesWithNewlines(); + writeIndent(); + m_stream->write(QString("%1: {\n").arg(name).toUtf8()); + ++m_indentDepth; + for (int i = 0; i < keyValue.size(); ++i) { + const QString key = keyValue.at(i).first; + const QString value = keyValue.at(i).second; + writeIndent(); + m_stream->write(QString("%1: %2").arg(key, value).toUtf8()); + if (i != keyValue.size() - 1) { + m_stream->write(",\n"); + } else { + m_stream->write("\n"); + } + } + --m_indentDepth; + writeIndent(); + m_stream->write("}\n"); +} + +void QmlStreamWriter::writeIndent() +{ + m_stream->write(QByteArray(m_indentDepth * 4, ' ')); +} + +void QmlStreamWriter::writePotentialLine(const QByteArray &line) +{ + m_pendingLines.append(line); + m_pendingLineLength += line.size(); + if (m_pendingLineLength >= 80) { + flushPotentialLinesWithNewlines(); + } +} + +void QmlStreamWriter::flushPotentialLinesWithNewlines() +{ + if (m_maybeOneline) + m_stream->write("\n"); + foreach (const QByteArray &line, m_pendingLines) { + writeIndent(); + m_stream->write(line); + m_stream->write("\n"); + } + m_pendingLines.clear(); + m_pendingLineLength = 0; + m_maybeOneline = false; +} diff --git a/tools/qmlplugindump/qmlstreamwriter.h b/tools/qmlplugindump/qmlstreamwriter.h new file mode 100644 index 0000000..cd73aad --- /dev/null +++ b/tools/qmlplugindump/qmlstreamwriter.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLSTREAMWRITER_H +#define QMLSTREAMWRITER_H + +#include +#include +#include +#include +#include + +class QmlStreamWriter +{ +public: + QmlStreamWriter(QByteArray *array); + + void writeStartDocument(); + void writeEndDocument(); + void writeLibraryImport(const QString &uri, int majorVersion, int minorVersion, const QString &as = QString()); + //void writeFilesystemImport(const QString &file, const QString &as = QString()); + void writeStartObject(const QString &component); + void writeEndObject(); + void writeScriptBinding(const QString &name, const QString &rhs); + void writeScriptObjectLiteralBinding(const QString &name, const QList > &keyValue); + void writeArrayBinding(const QString &name, const QStringList &elements); + void write(const QString &data); + +private: + void writeIndent(); + void writePotentialLine(const QByteArray &line); + void flushPotentialLinesWithNewlines(); + + int m_indentDepth; + QList m_pendingLines; + int m_pendingLineLength; + bool m_maybeOneline; + QScopedPointer m_stream; +}; + +#endif // QMLSTREAMWRITER_H diff --git a/tools/tools.pro b/tools/tools.pro index f090b86..7eecebd 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -23,7 +23,10 @@ TEMPLATE = subdirs unix:!symbian:!mac:!embedded:!qpa:SUBDIRS += qtconfig win32:!wince*:SUBDIRS += activeqt } - contains(QT_CONFIG, declarative):SUBDIRS += qml + contains(QT_CONFIG, declarative) { + SUBDIRS += qml + !symbian: SUBDIRS += qmlplugindump + } } !wince*:!symbian:SUBDIRS += linguist -- cgit v0.12 From eca261bd3ec4b0ff1e0f9b2220c2168e7f62a227 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 11 Mar 2011 09:14:16 +0100 Subject: qmlplugindump: Allow dumping by path without URI. This migrates b980a9b9646a89b5b24efeca40926408a71334de from the Qt Creator's copy into the qmlplugindump in Qt. Change-Id: I1ab90f491f5df0e6570aa43a91073e7b332e41df (cherry picked from commit 9fcece7b455b6540a67780cc3874b230e586b7c4) --- tools/qmlplugindump/main.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index 5ed5e2e..9dcdf06 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -247,8 +247,7 @@ public: // some qmltype names are missing the actual names, ignore that import if (qmlTyName.endsWith('/')) continue; - if (!relocatableModuleUri.isNull() - && qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) { + if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) { qmlTyName.remove(0, relocatableModuleUri.size() + 1); } exports += enquote(QString("%1 %2.%3").arg( @@ -415,6 +414,7 @@ void printUsage(const QString &appName) { qWarning() << qPrintable(QString( "Usage: %1 [--notrelocatable] module.uri version [module/import/path]\n" + " %1 --path path/to/qmldir/directory [version]\n" " %1 --builtins\n" "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg( appName)); @@ -450,6 +450,7 @@ int main(int argc, char *argv[]) QString pluginImportVersion; QString pluginImportPath; bool relocatable = true; + bool pathImport = false; if (args.size() >= 3) { QStringList positionalArgs; foreach (const QString &arg, args) { @@ -460,20 +461,32 @@ int main(int argc, char *argv[]) if (arg == QLatin1String("--notrelocatable")) { relocatable = false; + } else if (arg == QLatin1String("--path")) { + pathImport = true; } else { qWarning() << "Invalid argument: " << arg; return EXIT_INVALIDARGUMENTS; } } - if (positionalArgs.size() != 3 && positionalArgs.size() != 4) { - qWarning() << "Incorrect number of positional arguments"; - return EXIT_INVALIDARGUMENTS; + if (!pathImport) { + if (positionalArgs.size() != 3 && positionalArgs.size() != 4) { + qWarning() << "Incorrect number of positional arguments"; + return EXIT_INVALIDARGUMENTS; + } + pluginImportUri = positionalArgs[1]; + pluginImportVersion = positionalArgs[2]; + if (positionalArgs.size() >= 4) + pluginImportPath = positionalArgs[3]; + } else { + if (positionalArgs.size() != 2 && positionalArgs.size() != 3) { + qWarning() << "Incorrect number of positional arguments"; + return EXIT_INVALIDARGUMENTS; + } + pluginImportPath = positionalArgs[1]; + if (positionalArgs.size() == 3) + pluginImportVersion = positionalArgs[2]; } - pluginImportUri = positionalArgs[1]; - pluginImportVersion = positionalArgs[2]; - if (positionalArgs.size() >= 4) - pluginImportPath = positionalArgs[3]; } QDeclarativeView view; @@ -488,11 +501,16 @@ int main(int argc, char *argv[]) // this will hold the meta objects we want to dump information of QSet metas; - if (pluginImportUri.isEmpty()) { + if (pluginImportUri.isEmpty() && !pathImport) { metas = defaultReachable; } else { // find all QMetaObjects reachable when the specified module is imported - importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii(); + if (!pathImport) { + importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii(); + } else { + // pluginImportVersion can be empty + importCode += QString("import \"%1\" %2\n").arg(pluginImportPath, pluginImportVersion).toAscii(); + } // create a component with these imports to make sure the imports are valid // and to populate the declarative meta type system -- cgit v0.12 From 5e4d1adbbf3107c04d4238b8396e0380258cc161 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 19 Apr 2011 14:24:35 +0200 Subject: qmlplugindump: Use command line options with a single dash. Keep the old -- options for compatibility. Change-Id: I9c9b0beccc7043cf8b4b654bdba33946abf8c7b6 Task-number: QTBUG-18834 (cherry picked from commit 175382d834142f2a55b4e209af870ab40f741d2d) --- tools/qmlplugindump/main.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index 9dcdf06..848b091 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -413,9 +413,9 @@ void sigSegvHandler(int) { void printUsage(const QString &appName) { qWarning() << qPrintable(QString( - "Usage: %1 [--notrelocatable] module.uri version [module/import/path]\n" - " %1 --path path/to/qmldir/directory [version]\n" - " %1 --builtins\n" + "Usage: %1 [-notrelocatable] module.uri version [module/import/path]\n" + " %1 -path path/to/qmldir/directory [version]\n" + " %1 -builtins\n" "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg( appName)); } @@ -441,7 +441,10 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); const QStringList args = app.arguments(); const QString appName = QFileInfo(app.applicationFilePath()).baseName(); - if (!(args.size() >= 3 || (args.size() == 2 && args.at(1) == QLatin1String("--builtins")))) { + if (!(args.size() >= 3 + || (args.size() == 2 + && (args.at(1) == QLatin1String("--builtins") + || args.at(1) == QLatin1String("-builtins"))))) { printUsage(appName); return EXIT_INVALIDARGUMENTS; } @@ -454,14 +457,16 @@ int main(int argc, char *argv[]) if (args.size() >= 3) { QStringList positionalArgs; foreach (const QString &arg, args) { - if (!arg.startsWith("--")) { + if (!arg.startsWith(QLatin1Char('-'))) { positionalArgs.append(arg); continue; } - if (arg == QLatin1String("--notrelocatable")) { + if (arg == QLatin1String("--notrelocatable") + || arg == QLatin1String("-notrelocatable")) { relocatable = false; - } else if (arg == QLatin1String("--path")) { + } else if (arg == QLatin1String("--path") + || arg == QLatin1String("-path")) { pathImport = true; } else { qWarning() << "Invalid argument: " << arg; -- cgit v0.12 From 7e7be3e5a0441671cdaa9242f6f05871189d0ded Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 9 Feb 2011 16:02:31 +0100 Subject: Allow 'typeinfo ' lines in qmldir. Also add documentation for that change. Reviewed-by: Aaron Kennedy Change-Id: Ifae395bc9b6699c03f9879dcb5407d23a4caab85 (cherry picked from b9839fc1e0e1d98911aef5149a58dd4bdacd8bc1) --- doc/src/declarative/modules.qdoc | 123 ++++++++++++++++++++++++++ src/declarative/qml/qdeclarativedirparser.cpp | 17 ++++ src/declarative/qml/qdeclarativedirparser_p.h | 16 ++++ 3 files changed, 156 insertions(+) diff --git a/doc/src/declarative/modules.qdoc b/doc/src/declarative/modules.qdoc index dbc8806..f2e24f2 100644 --- a/doc/src/declarative/modules.qdoc +++ b/doc/src/declarative/modules.qdoc @@ -310,6 +310,7 @@ It is defined by a plain text file named "qmldir" that contains one or more line [] internal plugin [] +typeinfo \endcode \bold {# } lines are used for comments. They are ignored by the QML engine. @@ -350,6 +351,14 @@ plugin file, or a relative path from the directory containing the \c qmldir file containing the plugin file. By default the engine searches for the plugin library in the directory that contains the \c qmldir file. The plugin search path can be queried with QDeclarativeEngine::pluginPathList() and modified using QDeclarativeEngine::addPluginPath(). When running the \l {QML Viewer}, use the \c -P option to add paths to the plugin search path. +\bold {typeinfo } lines add \l{Writing a qmltypes file}{type description files} to +the module that can be read by QML tools such as Qt Creator to get information about the +types defined by the module's plugins. is the (relative) file name of a .qmltypes +file. + +Without such a file QML tools may be unable to offer features such as code completion +for the types defined in your plugins. + \section1 Debugging @@ -358,5 +367,119 @@ when there are problems with finding and loading modules. See \l{Debugging module imports} for more information. +\section1 Writing a qmltypes file + +QML modules may refer to one or more type information files in their +\l{Writing a qmldir file}{qmldir} file. These usually have the .qmltypes +extension and are read by external tools to gain information about +types defined in plugins. + +As such qmltypes files have no effect on the functionality of a QML module. +Their only use is to allow tools such as Qt Creator to provide code completion, +error checking and other functionality to users of your module. + +Any module that uses plugins should also ship a type description file. + +The best way to create a qmltypes file for your module is to generate it +using the \c qmlplugindump tool that is provided with Qt. + +Example: +If your module is in \c /tmp/imports/My/Module, you could run +\code +qmlplugindump My.Module 1.0 /tmp/imports > /tmp/imports/My/Module/mymodule.qmltypes +\endcode +to generate type information for your module. Afterwards, add the line +\code +typeinfo mymodule.qmltypes +\endcode +to \c /tmp/imports/My/Module/qmldir to register it. + +While the qmldump tool covers most cases, it does not work if: +\list +\o The plugin uses a \l{QDeclarativeCustomParser}. The component that uses + the custom parser will not get its members documented. +\o The plugin can not be loaded. In particular if you cross-compiled + the plugin for a different architecture, qmldump will not be able to + load it. +\endlist + +In case you have to create a qmltypes file manually or need to adjust +an existing one, this is the file format: + +\qml +import QtQuick.tooling 1.0 + +// There always is a single Module object that contains all +// Component objects. +Module { + // A Component object directly corresponds to a type exported + // in a plugin with a call to qmlRegisterType. + Component { + + // The name is a unique identifier used to refer to this type. + // It is recommended you simply use the C++ type name. + name: "QDeclarativeAbstractAnimation" + + // The name of the prototype Component. + prototype: "QObject" + + // The name of the default property. + defaultProperty: "animations" + + // The name of the type containing attached properties + // and methods. + attachedType: "QDeclarativeAnimationAttached" + + // The list of exports determines how a type can be imported. + // Each string has the format "URI/Name version" and matches the + // arguments to qmlRegisterType. Usually types are only exported + // once, if at all. + // If the "URI/" part of the string is missing that means the + // type should be put into the package defined by the URI the + // module was imported with. + // For example if this module was imported with 'import Foo 4.8' + // the Animation object would be found in the package Foo and + // QtQuick. + exports: [ + "Animation 4.7", + "QtQuick/Animation 1.0" + ] + + Property { + name: "animations"; + type: "QDeclarativeAbstractAnimation" + // defaults to false, whether this property is read only + isReadonly: true + // defaults to false, whether the type of this property was a pointer in C++ + isPointer: true + // defaults to false: whether the type actually is a QDeclarativeListProperty + isList: true + } + Property { name: "loops"; type: "int" } + Property { name: "name"; type: "string" } + Property { name: "loopsEnum"; type: "Loops" } + + Enum { + name: "Loops" + values: { + "Infinite": -2, + "OnceOnly": 1 + } + } + + // Signal and Method work the same way. The inner Parameter + // declarations also support the isReadonly, isPointer and isList + // attributes which mean the same as for Property + Method { name: "restart" } + Signal { name: "started" } + Signal { + name: "runningChanged" + Parameter { type: "bool" } + Parameter { name: "foo"; type: "bool" } + } + } +} +\endqml + */ / diff --git a/src/declarative/qml/qdeclarativedirparser.cpp b/src/declarative/qml/qdeclarativedirparser.cpp index b5ad33d..362b99c 100644 --- a/src/declarative/qml/qdeclarativedirparser.cpp +++ b/src/declarative/qml/qdeclarativedirparser.cpp @@ -160,6 +160,16 @@ bool QDeclarativeDirParser::parse() Component entry(sections[1], sections[2], -1, -1); entry.internal = true; _components.append(entry); + } else if (sections[0] == QLatin1String("typeinfo")) { + if (sectionCount != 2) { + reportError(lineNumber, -1, + QString::fromUtf8("typeinfo requires 1 argument, but %1 were provided").arg(sectionCount - 1)); + continue; + } +#ifdef QT_CREATOR + TypeInfo typeInfo(sections[1]); + _typeInfos.append(typeInfo); +#endif } else if (sectionCount == 2) { // No version specified (should only be used for relative qmldir files) @@ -229,4 +239,11 @@ QList QDeclarativeDirParser::components() cons return _components; } +#ifdef QT_CREATOR +QList QDeclarativeDirParser::typeInfos() const +{ + return _typeInfos; +} +#endif + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativedirparser_p.h b/src/declarative/qml/qdeclarativedirparser_p.h index 95f14bc..d09b90e 100644 --- a/src/declarative/qml/qdeclarativedirparser_p.h +++ b/src/declarative/qml/qdeclarativedirparser_p.h @@ -109,6 +109,19 @@ public: QList components() const; QList plugins() const; +#ifdef QT_CREATOR + struct TypeInfo + { + TypeInfo() {} + TypeInfo(const QString &fileName) + : fileName(fileName) {} + + QString fileName; + }; + + QList typeInfos() const; +#endif + private: void reportError(int line, int column, const QString &message); @@ -118,6 +131,9 @@ private: QString _source; QList _components; QList _plugins; +#ifdef QT_CREATOR + QList _typeInfos; +#endif unsigned _isParsed: 1; }; -- cgit v0.12 From 455440996f659ae246536b7450ba9b7900d015d0 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 12 May 2011 12:16:45 +0200 Subject: Disable QtConcurrent for Symbian winscw builds. While QtConcurrent is nowadays usable with RVCT and GCCE compilers, the compiler used for the winscw target has problems with the templates still. To enable building 4.8 on winscw, the patch defines QT_NO_CONCURRENT and QT_NO_QFUTURE in qglobal.h for this target. However this causes further complications in the Q_OBJECT classes of QtConcurrent because moc will be run without having QT_NO_CONCURRENT and QFUTURE defined (as moc is not a Symbian app and for other Symbian targets they must not be defined, which makes differentiation in qglobal.h impossible for the moc run) and having a moc file generated for a class that will be ifdef'ed out during compilation causes build breaks. Therefore additional dummy stubs are provided in QFutureWatcherBase. Reviewed-by: Liang Qi --- src/corelib/concurrent/qfuturewatcher.cpp | 14 +++++++++++++- src/corelib/concurrent/qfuturewatcher.h | 13 +++++++++---- src/corelib/global/qglobal.h | 10 ++++++++++ tests/auto/qfuture/versioncheck.h | 4 ++++ tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/corelib/concurrent/qfuturewatcher.cpp b/src/corelib/concurrent/qfuturewatcher.cpp index ea12bc9..728714a 100644 --- a/src/corelib/concurrent/qfuturewatcher.cpp +++ b/src/corelib/concurrent/qfuturewatcher.cpp @@ -589,4 +589,16 @@ void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event) QT_END_NAMESPACE -#endif // QT_NO_CONCURRENT +#else + +// On Symbian winscw target QT_NO_QFUTURE and QT_NO_CONCURRENT are both defined. +// However moc will be run without having them set, so provide a dummy stub at +// least for the slots to prevent linker errors. + +void QFutureWatcherBase::cancel() { } +void QFutureWatcherBase::setPaused(bool) { } +void QFutureWatcherBase::pause() { } +void QFutureWatcherBase::resume() { } +void QFutureWatcherBase::togglePaused() { } + +#endif // QT_NO_QFUTURE diff --git a/src/corelib/concurrent/qfuturewatcher.h b/src/corelib/concurrent/qfuturewatcher.h index 5fe2007..26e549d 100644 --- a/src/corelib/concurrent/qfuturewatcher.h +++ b/src/corelib/concurrent/qfuturewatcher.h @@ -44,8 +44,6 @@ #include -#ifndef QT_NO_QFUTURE - #include QT_BEGIN_HEADER @@ -56,6 +54,11 @@ QT_MODULE(Core) class QEvent; class QFutureWatcherBasePrivate; + +#ifdef QT_NO_QFUTURE +class QFutureInterfaceBase; +#endif + class Q_CORE_EXPORT QFutureWatcherBase : public QObject { Q_OBJECT @@ -114,6 +117,8 @@ private: virtual QFutureInterfaceBase &futureInterface() = 0; }; +#ifndef QT_NO_QFUTURE + template class QFutureWatcher : public QFutureWatcherBase { @@ -214,9 +219,9 @@ Q_INLINE_TEMPLATE void QFutureWatcher::setFuture(const QFuture &_fut connectOutputInterface(); } +#endif // QT_NO_QFUTURE + QT_END_NAMESPACE QT_END_HEADER -#endif // QT_NO_CONCURRENT - #endif // QFUTUREWATCHER_H diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 49f5f98..3e1f011 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -2545,6 +2545,16 @@ QT3_SUPPORT Q_CORE_EXPORT const char *qInstallPathSysconf(); //Symbian does not support data imports from a DLL #define Q_NO_DATA_RELOCATION +// Winscw compiler is unable to compile QtConcurrent. +#ifdef Q_CC_NOKIAX86 +#ifndef QT_NO_CONCURRENT +#define QT_NO_CONCURRENT +#endif +#ifndef QT_NO_QFUTURE +#define QT_NO_QFUTURE +#endif +#endif + QT_END_NAMESPACE // forward declare std::exception #ifdef __cplusplus diff --git a/tests/auto/qfuture/versioncheck.h b/tests/auto/qfuture/versioncheck.h index 0cf7b76..32a33c8 100644 --- a/tests/auto/qfuture/versioncheck.h +++ b/tests/auto/qfuture/versioncheck.h @@ -47,3 +47,7 @@ #if defined(Q_CC_MSVC) && _MSC_VER < 1400 #define QT_NO_CONCURRENT_TEST #endif + +#if defined(Q_CC_NOKIAX86) +#define QT_NO_CONCURRENT_TEST +#endif diff --git a/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp index f287450..2f1adb4 100644 --- a/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -2418,6 +2418,7 @@ void tst_QtConcurrentMap::incrementalResults() {} void tst_QtConcurrentMap::stressTest() {} void tst_QtConcurrentMap::throttling() {} void tst_QtConcurrentMap::stlContainers() {} +void tst_QtConcurrentMap::qFutureAssignmentLeak() { } void tst_QtConcurrentMap::noDetatch() {} QTEST_NOOP_MAIN -- cgit v0.12 From a5d66497b105e9e8d1a39d24ec643862961ce75c Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 12 May 2011 15:37:04 +0200 Subject: Fix QtOpenGL def file for armv5. Reviewed-by: TRUSTME --- src/s60installs/eabi/QtOpenGLu.def | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/s60installs/eabi/QtOpenGLu.def b/src/s60installs/eabi/QtOpenGLu.def index 11ac503..c252484 100644 --- a/src/s60installs/eabi/QtOpenGLu.def +++ b/src/s60installs/eabi/QtOpenGLu.def @@ -766,4 +766,18 @@ EXPORTS _ZThn104_N20QGLTextureGlyphCacheD0Ev @ 765 NONAME ABSENT _ZThn104_N20QGLTextureGlyphCacheD1Ev @ 766 NONAME ABSENT _ZThn8_NK16QGLWindowSurface8featuresEv @ 767 NONAME ABSENT + _ZN14QGLSignalProxy18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv @ 768 NONAME + _ZN14QGLSignalProxy25staticMetaObjectExtraDataE @ 769 NONAME DATA 8 + _ZN16QGLShaderProgram18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv @ 770 NONAME + _ZN16QGLShaderProgram25staticMetaObjectExtraDataE @ 771 NONAME DATA 8 + _ZN16QGLWindowSurface18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv @ 772 NONAME + _ZN16QGLWindowSurface25staticMetaObjectExtraDataE @ 773 NONAME DATA 8 + _ZN21QGraphicsShaderEffect18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv @ 774 NONAME + _ZN21QGraphicsShaderEffect25staticMetaObjectExtraDataE @ 775 NONAME DATA 8 + _ZN22QGLEngineShaderManager18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv @ 776 NONAME + _ZN22QGLEngineShaderManager25staticMetaObjectExtraDataE @ 777 NONAME DATA 8 + _ZN9QGLShader18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv @ 778 NONAME + _ZN9QGLShader25staticMetaObjectExtraDataE @ 779 NONAME DATA 8 + _ZN9QGLWidget18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv @ 780 NONAME + _ZN9QGLWidget25staticMetaObjectExtraDataE @ 781 NONAME DATA 8 -- cgit v0.12 From dcbd920daf92d80302633f73dd8324437005a10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zaj=C4=85c?= Date: Fri, 13 May 2011 10:39:34 +0200 Subject: Retain ABI and API compatibility when Qt is built with EGL. Author: Felix Geyer Merge-request: 1230 Reviewed-by: ossi --- src/opengl/qgl.h | 2 +- src/opengl/qgl_x11egl.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index c57995d..ab88d9c 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -401,7 +401,7 @@ protected: #if defined(Q_WS_WIN) virtual int choosePixelFormat(void* pfd, HDC pdc); #endif -#if defined(Q_WS_X11) && defined(QT_NO_EGL) +#if defined(Q_WS_X11) virtual void* tryVisual(const QGLFormat& f, int bufDepth = 1); virtual void* chooseVisual(); #endif diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index 2ddfd35..34ca97d 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -257,6 +257,20 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) return true; } +void *QGLContext::chooseVisual() +{ + qFatal("QGLContext::chooseVisual - this method must not be called as Qt is built with EGL support"); + return 0; +} + +void *QGLContext::tryVisual(const QGLFormat& f, int bufDepth) +{ + Q_UNUSED(f); + Q_UNUSED(bufDepth); + qFatal("QGLContext::tryVisual - this method must not be called as Qt is built with EGL support"); + return 0; +} + void QGLWidget::resizeEvent(QResizeEvent *) { Q_D(QGLWidget); -- cgit v0.12 From a45398677309ab905b69c599177b4c2951292b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zaj=C4=85c?= Date: Fri, 13 May 2011 10:40:05 +0200 Subject: X11: Keep the menubar inside the widgetbox window in toplevel mode For now the appmenu protocol does not make it possible to associate a menubar with all application windows. This means in top level mode you can only reach the menubar when the widgetbox window is active. Since this is quite inconvenient, better not use the native menubar in this configuration and keep the menubar in the widgetbox window. Merge-request: 1229 Reviewed-by: denis --- tools/designer/src/designer/qdesigner_workbench.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/designer/src/designer/qdesigner_workbench.cpp b/tools/designer/src/designer/qdesigner_workbench.cpp index ffc4b8c..df679eb 100644 --- a/tools/designer/src/designer/qdesigner_workbench.cpp +++ b/tools/designer/src/designer/qdesigner_workbench.cpp @@ -410,6 +410,9 @@ void QDesignerWorkbench::switchToDockedMode() switchToNeutralMode(); +#ifdef Q_WS_X11 + QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false); +#endif #ifndef Q_WS_MAC QDesignerToolWindow *widgetBoxWrapper = widgetBoxToolWindow(); widgetBoxWrapper->action()->setVisible(true); @@ -477,6 +480,14 @@ void QDesignerWorkbench::switchToTopLevelMode() // The widget box is special, it gets the menubar and gets to be the main widget. m_core->setTopLevel(widgetBoxWrapper); +#ifdef Q_WS_X11 + // For now the appmenu protocol does not make it possible to associate a + // menubar with all application windows. This means in top level mode you + // can only reach the menubar when the widgetbox window is active. Since + // this is quite inconvenient, better not use the native menubar in this + // configuration and keep the menubar in the widgetbox window. + QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); +#endif #ifndef Q_WS_MAC widgetBoxWrapper->setMenuBar(m_globalMenuBar); widgetBoxWrapper->action()->setVisible(false); -- cgit v0.12