From 0f2e1526068ed11bb981357fdeb406f5c804717b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 9 Jun 2011 13:30:47 +0200 Subject: [PATCH] QmlInspector: Unified mouse and keyboard event handling Introduced a common AbstractTool interface so that the AbstractViewInspector can forward mouse and keyboard events and also implement the keys to switch tools. The AbstractLiveEditTool still exists as the base class for all QDeclarativeView based tools. Change-Id: I7c00b05fba58828378543645e32732ad5f9fd5d0 --- .../qmltooling/qmldbg_inspector/abstracttool.cpp | 54 ++++++ .../qmltooling/qmldbg_inspector/abstracttool.h | 85 ++++++++++ .../qmldbg_inspector/abstractviewinspector.cpp | 121 +++++++++++++ .../qmldbg_inspector/abstractviewinspector.h | 20 +++ .../editor/abstractliveedittool.cpp | 8 +- .../qmldbg_inspector/editor/abstractliveedittool.h | 15 +-- .../qmldbg_inspector/qdeclarativeviewinspector.cpp | 177 +++----------------- .../qmldbg_inspector/qdeclarativeviewinspector.h | 11 +- .../qmldbg_inspector/qdeclarativeviewinspector_p.h | 3 - .../qmldbg_inspector/qmldbg_inspector.pro | 4 +- .../qmltooling/qmldbg_inspector/sgabstracttool.cpp | 54 ------ .../qmltooling/qmldbg_inspector/sgabstracttool.h | 85 ---------- .../qmldbg_inspector/sgselectiontool.cpp | 7 +- .../qmltooling/qmldbg_inspector/sgselectiontool.h | 6 +- .../qmldbg_inspector/sgviewinspector.cpp | 105 +----------- .../qmltooling/qmldbg_inspector/sgviewinspector.h | 15 -- 16 files changed, 330 insertions(+), 440 deletions(-) create mode 100644 src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp create mode 100644 src/plugins/qmltooling/qmldbg_inspector/abstracttool.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.h diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp new file mode 100644 index 0000000..39ced2a --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "abstracttool.h" + +#include "abstractviewinspector.h" + +namespace QmlJSDebugger { + +AbstractTool::AbstractTool(AbstractViewInspector *inspector) : + QObject(inspector), + m_inspector(inspector) +{ +} + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.h b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.h new file mode 100644 index 0000000..0a216bf --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ABSTRACTTOOL_H +#define ABSTRACTTOOL_H + +#include + +QT_BEGIN_NAMESPACE +class QMouseEvent; +class QKeyEvent; +class QWheelEvent; +QT_END_NAMESPACE + +namespace QmlJSDebugger { + +class AbstractViewInspector; + +class AbstractTool : public QObject +{ + Q_OBJECT + +public: + explicit AbstractTool(AbstractViewInspector *inspector); + + AbstractViewInspector *inspector() const { return m_inspector; } + + virtual void leaveEvent(QEvent *event) = 0; + + 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; + +private: + AbstractViewInspector *m_inspector; +}; + +} // namespace QmlJSDebugger + +#endif // ABSTRACTTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp index a698819..3323d54 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp @@ -41,6 +41,7 @@ #include "abstractviewinspector.h" +#include "abstracttool.h" #include "editor/qmltoolbar.h" #include "qdeclarativeinspectorprotocol.h" @@ -50,6 +51,7 @@ #include "QtDeclarative/private/qdeclarativeinspectorservice_p.h" #include +#include #include static inline void initEditorResource() { Q_INIT_RESOURCE(editor); } @@ -99,6 +101,7 @@ ToolBox::~ToolBox() AbstractViewInspector::AbstractViewInspector(QObject *parent) : QObject(parent), m_toolBox(0), + m_currentTool(0), m_showAppOnTop(false), m_designModeBehavior(false), m_animationPaused(false), @@ -284,6 +287,124 @@ void AbstractViewInspector::changeToMarqueeSelectTool() changeTool(InspectorProtocol::SelectMarqueeTool); } +bool AbstractViewInspector::eventFilter(QObject *obj, QEvent *event) +{ + if (!designModeBehavior()) + return QObject::eventFilter(obj, event); + + 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; + } + + return QObject::eventFilter(obj, event); +} + +bool AbstractViewInspector::leaveEvent(QEvent *event) +{ + m_currentTool->leaveEvent(event); + return true; +} + +bool AbstractViewInspector::mousePressEvent(QMouseEvent *event) +{ + m_currentTool->mousePressEvent(event); + return true; +} + +bool AbstractViewInspector::mouseMoveEvent(QMouseEvent *event) +{ + if (event->buttons()) { + m_currentTool->mouseMoveEvent(event); + } else { + m_currentTool->hoverMoveEvent(event); + } + return true; +} + +bool AbstractViewInspector::mouseReleaseEvent(QMouseEvent *event) +{ + m_currentTool->mouseReleaseEvent(event); + return true; +} + +bool AbstractViewInspector::keyPressEvent(QKeyEvent *event) +{ + m_currentTool->keyPressEvent(event); + return true; +} + +bool AbstractViewInspector::keyReleaseEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_V: + changeTool(InspectorProtocol::SelectTool); + break; +// disabled because multiselection does not do anything useful without design mode +// case Qt::Key_M: +// changeTool(InspectorProtocol::SelectMarqueeTool); +// break; + case Qt::Key_I: + changeTool(InspectorProtocol::ColorPickerTool); + break; + case Qt::Key_Z: + changeTool(InspectorProtocol::ZoomTool); + break; + case Qt::Key_Space: + setAnimationPaused(!animationPaused()); + break; + default: + break; + } + + m_currentTool->keyReleaseEvent(event); + return true; +} + +bool AbstractViewInspector::mouseDoubleClickEvent(QMouseEvent *event) +{ + m_currentTool->mouseDoubleClickEvent(event); + return true; +} + +bool AbstractViewInspector::wheelEvent(QWheelEvent *event) +{ + m_currentTool->wheelEvent(event); + return true; +} + void AbstractViewInspector::handleMessage(const QByteArray &message) { QDataStream ds(message); diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h index 0a56ead..7202bcc 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h +++ b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h @@ -53,10 +53,14 @@ QT_BEGIN_NAMESPACE class QDeclarativeEngine; class QDeclarativeInspectorService; +class QKeyEvent; +class QMouseEvent; +class QWheelEvent; QT_END_NAMESPACE namespace QmlJSDebugger { +class AbstractTool; class ToolBox; /* @@ -131,6 +135,21 @@ signals: void animationSpeedChanged(qreal factor); void animationPausedChanged(bool paused); +protected: + bool eventFilter(QObject *, QEvent *); + + virtual bool leaveEvent(QEvent *); + virtual bool mousePressEvent(QMouseEvent *event); + virtual bool mouseMoveEvent(QMouseEvent *event); + virtual bool mouseReleaseEvent(QMouseEvent *event); + virtual bool keyPressEvent(QKeyEvent *event); + virtual bool keyReleaseEvent(QKeyEvent *keyEvent); + virtual bool mouseDoubleClickEvent(QMouseEvent *event); + virtual bool wheelEvent(QWheelEvent *event); + + AbstractTool *currentTool() const { return m_currentTool; } + void setCurrentTool(AbstractTool *tool) { m_currentTool = tool; } + private slots: void handleMessage(const QByteArray &message); @@ -142,6 +161,7 @@ private: void createToolBox(); ToolBox *m_toolBox; + AbstractTool *m_currentTool; bool m_showAppOnTop; bool m_designModeBehavior; diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp index 4353e97..dce147c 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp @@ -51,7 +51,7 @@ namespace QmlJSDebugger { AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewInspector *editorView) - : QObject(editorView), m_inspector(editorView) + : AbstractTool(editorView) { } @@ -62,12 +62,12 @@ AbstractLiveEditTool::~AbstractLiveEditTool() QDeclarativeViewInspector *AbstractLiveEditTool::inspector() const { - return m_inspector; + return static_cast(AbstractTool::inspector()); } QDeclarativeView *AbstractLiveEditTool::view() const { - return m_inspector->declarativeView(); + return inspector()->declarativeView(); } QGraphicsScene* AbstractLiveEditTool::scene() const @@ -175,7 +175,7 @@ QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item) QDeclarativeItem *declarativeItem = qobject_cast(gfxObject); if (declarativeItem) { - objectStringId = m_inspector->idStringForObject(declarativeItem); + objectStringId = inspector()->idStringForObject(declarativeItem); } if (!objectStringId.isEmpty()) { diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.h b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.h index accec79..04b5f4e 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.h @@ -43,7 +43,7 @@ #define ABSTRACTLIVEEDITTOOL_H #include -#include +#include "../abstracttool.h" QT_BEGIN_NAMESPACE class QMouseEvent; @@ -60,7 +60,7 @@ namespace QmlJSDebugger { class QDeclarativeViewInspector; -class AbstractLiveEditTool : public QObject +class AbstractLiveEditTool : public AbstractTool { Q_OBJECT public: @@ -68,16 +68,8 @@ public: 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; + void leaveEvent(QEvent *) {} - 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; @@ -104,7 +96,6 @@ protected: QGraphicsScene *scene() const; private: - QDeclarativeViewInspector *m_inspector; QList m_itemList; }; diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp index 462fd19..67a581d 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp @@ -49,13 +49,9 @@ #include "editor/boundingrecthighlighter.h" #include -#include -#include -#include #include #include #include -#include namespace QmlJSDebugger { @@ -79,7 +75,7 @@ QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view, data->zoomTool = new ZoomTool(this); data->colorPickerTool = new ColorPickerTool(this); data->boundingRectHighlighter = new BoundingRectHighlighter(this); - data->currentTool = data->selectionTool; + setCurrentTool(data->selectionTool); // to capture ChildRemoved event when viewport changes data->view->installEventFilter(this); @@ -142,6 +138,11 @@ void QDeclarativeViewInspector::changeTool(InspectorProtocol::Tool tool) } } +AbstractLiveEditTool *QDeclarativeViewInspector::currentTool() const +{ + return static_cast(AbstractViewInspector::currentTool()); +} + QDeclarativeEngine *QDeclarativeViewInspector::declarativeEngine() const { return data->view->engine(); @@ -181,143 +182,39 @@ bool QDeclarativeViewInspector::eventFilter(QObject *obj, QEvent *event) 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); + return AbstractViewInspector::eventFilter(obj, event); } -bool QDeclarativeViewInspector::leaveEvent(QEvent * /*event*/) +bool QDeclarativeViewInspector::leaveEvent(QEvent *event) { - if (!designModeBehavior()) - return false; data->clearHighlight(); - return true; + return AbstractViewInspector::leaveEvent(event); } bool QDeclarativeViewInspector::mousePressEvent(QMouseEvent *event) { - if (!designModeBehavior()) - return false; data->cursorPos = event->pos(); - data->currentTool->mousePressEvent(event); - return true; + return AbstractViewInspector::mousePressEvent(event); } bool QDeclarativeViewInspector::mouseMoveEvent(QMouseEvent *event) { - if (!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())); + declarativeView()->setToolTip(currentTool()->titleForItem(selItems.first())); } else { declarativeView()->setToolTip(QString()); } - if (event->buttons()) { - data->currentTool->mouseMoveEvent(event); - } else { - data->currentTool->hoverMoveEvent(event); - } - return true; + + return AbstractViewInspector::mouseMoveEvent(event); } bool QDeclarativeViewInspector::mouseReleaseEvent(QMouseEvent *event) { - if (!designModeBehavior()) - return false; - data->cursorPos = event->pos(); - data->currentTool->mouseReleaseEvent(event); - return true; -} - -bool QDeclarativeViewInspector::keyPressEvent(QKeyEvent *event) -{ - if (!designModeBehavior()) - return false; - - data->currentTool->keyPressEvent(event); - return true; -} - -bool QDeclarativeViewInspector::keyReleaseEvent(QKeyEvent *event) -{ - if (!designModeBehavior()) - return false; - - switch (event->key()) { - case Qt::Key_V: - changeTool(InspectorProtocol::SelectTool); - break; -// disabled because multiselection does not do anything useful without design mode -// case Qt::Key_M: -// changeTool(InspectorProtocol::SelectMarqueeTool); -// break; - case Qt::Key_I: - changeTool(InspectorProtocol::ColorPickerTool); - break; - case Qt::Key_Z: - changeTool(InspectorProtocol::ZoomTool); - break; - case Qt::Key_Space: - setAnimationPaused(!animationPaused()); - break; - default: - break; - } - - data->currentTool->keyReleaseEvent(event); - return true; + return AbstractViewInspector::mouseReleaseEvent(event); } void QDeclarativeViewInspector::reparentQmlObject(QObject *object, QObject *newParent) @@ -340,22 +237,6 @@ void QDeclarativeViewInspectorPrivate::_q_removeFromSelection(QObject *obj) setSelectedItems(items); } -bool QDeclarativeViewInspector::mouseDoubleClickEvent(QMouseEvent * /*event*/) -{ - if (!designModeBehavior()) - return false; - - return true; -} - -bool QDeclarativeViewInspector::wheelEvent(QWheelEvent *event) -{ - if (!designModeBehavior()) - return false; - data->currentTool->wheelEvent(event); - return true; -} - void QDeclarativeViewInspectorPrivate::setSelectedItemsForTools(const QList &items) { foreach (const QWeakPointer &obj, currentSelection) { @@ -378,7 +259,7 @@ void QDeclarativeViewInspectorPrivate::setSelectedItemsForTools(const QListupdateSelectedItems(); + q->currentTool()->updateSelectedItems(); } void QDeclarativeViewInspectorPrivate::setSelectedItems(const QList &items) @@ -468,7 +349,6 @@ QList QDeclarativeViewInspectorPrivate::selectableItems( void QDeclarativeViewInspectorPrivate::changeToSingleSelectTool() { - currentToolMode = Constants::SelectionToolMode; selectionTool->setRubberbandSelectionMode(false); changeToSelectTool(); @@ -479,19 +359,18 @@ void QDeclarativeViewInspectorPrivate::changeToSingleSelectTool() void QDeclarativeViewInspectorPrivate::changeToSelectTool() { - if (currentTool == selectionTool) + if (q->currentTool() == selectionTool) return; - currentTool->clear(); - currentTool = selectionTool; - currentTool->clear(); - currentTool->updateSelectedItems(); + q->currentTool()->clear(); + q->setCurrentTool(selectionTool); + q->currentTool()->clear(); + q->currentTool()->updateSelectedItems(); } void QDeclarativeViewInspectorPrivate::changeToMarqueeSelectTool() { changeToSelectTool(); - currentToolMode = Constants::MarqueeSelectionToolMode; selectionTool->setRubberbandSelectionMode(true); emit q->marqueeSelectToolActivated(); @@ -500,10 +379,9 @@ void QDeclarativeViewInspectorPrivate::changeToMarqueeSelectTool() void QDeclarativeViewInspectorPrivate::changeToZoomTool() { - currentToolMode = Constants::ZoomMode; - currentTool->clear(); - currentTool = zoomTool; - currentTool->clear(); + q->currentTool()->clear(); + q->setCurrentTool(zoomTool); + q->currentTool()->clear(); emit q->zoomToolActivated(); q->sendCurrentTool(Constants::ZoomMode); @@ -511,13 +389,12 @@ void QDeclarativeViewInspectorPrivate::changeToZoomTool() void QDeclarativeViewInspectorPrivate::changeToColorPickerTool() { - if (currentTool == colorPickerTool) + if (q->currentTool() == colorPickerTool) return; - currentToolMode = Constants::ColorPickerMode; - currentTool->clear(); - currentTool = colorPickerTool; - currentTool->clear(); + q->currentTool()->clear(); + q->setCurrentTool(colorPickerTool); + q->currentTool()->clear(); emit q->colorPickerActivated(); q->sendCurrentTool(Constants::ColorPickerMode); diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.h index c08ef54..3cd53ff 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.h +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.h @@ -50,12 +50,9 @@ #include #include -QT_FORWARD_DECLARE_CLASS(QDeclarativeItem) -QT_FORWARD_DECLARE_CLASS(QMouseEvent) -QT_FORWARD_DECLARE_CLASS(QToolBar) - namespace QmlJSDebugger { +class AbstractLiveEditTool; class QDeclarativeViewInspectorPrivate; class QDeclarativeViewInspector : public AbstractViewInspector @@ -88,12 +85,8 @@ protected: 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); + AbstractLiveEditTool *currentTool() const; private: Q_DISABLE_COPY(QDeclarativeViewInspector) diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h index cd8d749..a6e6a3c 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h @@ -73,9 +73,6 @@ public: QPointF cursorPos; QList > currentSelection; - Constants::DesignTool currentToolMode; - AbstractLiveEditTool *currentTool; - LiveSelectionTool *selectionTool; ZoomTool *zoomTool; ColorPickerTool *colorPickerTool; diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro index 9d717a0..355395c 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro +++ b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro @@ -25,7 +25,7 @@ SOURCES += \ editor/colorpickertool.cpp \ editor/qmltoolbar.cpp \ editor/toolbarcolorbox.cpp \ - sgabstracttool.cpp \ + abstracttool.cpp \ sgviewinspector.cpp \ sgselectiontool.cpp @@ -49,7 +49,7 @@ HEADERS += \ editor/colorpickertool.h \ editor/qmltoolbar.h \ editor/toolbarcolorbox.h \ - sgabstracttool.h \ + abstracttool.h \ sgviewinspector.h \ sgselectiontool.h diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.cpp deleted file mode 100644 index 4394419..0000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "sgabstracttool.h" - -#include "sgviewinspector.h" - -namespace QmlJSDebugger { - -SGAbstractTool::SGAbstractTool(SGViewInspector *inspector) : - QObject(inspector), - m_inspector(inspector) -{ -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.h b/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.h deleted file mode 100644 index 5b0dc14..0000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** 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. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SGABSTRACTTOOL_H -#define SGABSTRACTTOOL_H - -#include - -QT_BEGIN_NAMESPACE -class QMouseEvent; -class QKeyEvent; -class QWheelEvent; -QT_END_NAMESPACE - -namespace QmlJSDebugger { - -class SGViewInspector; - -class SGAbstractTool : public QObject -{ - Q_OBJECT - -public: - explicit SGAbstractTool(SGViewInspector *inspector); - - SGViewInspector *inspector() const { return m_inspector; } - - virtual void leaveEvent(QEvent *event) = 0; - - 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; - -private: - SGViewInspector *m_inspector; -}; - -} // namespace QmlJSDebugger - -#endif // SGABSTRACTTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp index 828e64a..c233cf6 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp @@ -86,7 +86,7 @@ static QSGItem *itemAt(QSGItem *item, const QPointF &pos, QSGItem *overlay) SGSelectionTool::SGSelectionTool(SGViewInspector *inspector) : - SGAbstractTool(inspector), + AbstractTool(inspector), m_hoverHighlight(new QSGRectangle(inspector->overlay())) { m_hoverHighlight->border()->setColor(QColor(64, 128, 255)); @@ -100,9 +100,10 @@ void SGSelectionTool::leaveEvent(QEvent *) void SGSelectionTool::hoverMoveEvent(QMouseEvent *event) { - QSGItem *root = inspector()->view()->rootItem(); + SGViewInspector *sgInspector = static_cast(inspector()); + QSGItem *root = sgInspector->view()->rootItem(); QPointF mappedPos = root->mapFromScene(event->pos()); - QSGItem *item = itemAt(root, mappedPos, inspector()->overlay()); + QSGItem *item = itemAt(root, mappedPos, sgInspector->overlay()); if (!item || item == root) { m_hoverHighlight->setVisible(false); return; diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h index 10a4428..f794691 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h +++ b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h @@ -42,7 +42,7 @@ #ifndef SGSELECTIONTOOL_H #define SGSELECTIONTOOL_H -#include "sgabstracttool.h" +#include "abstracttool.h" #include @@ -50,7 +50,9 @@ QT_FORWARD_DECLARE_CLASS(QSGRectangle) namespace QmlJSDebugger { -class SGSelectionTool : public SGAbstractTool +class SGViewInspector; + +class SGSelectionTool : public AbstractTool { Q_OBJECT public: diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp index 7a4eaf5..ec68ef9 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp @@ -42,8 +42,6 @@ #include "sgviewinspector.h" #include "qdeclarativeinspectorprotocol.h" - -#include "sgabstracttool.h" #include "sgselectiontool.h" #include @@ -61,7 +59,6 @@ SGViewInspector::SGViewInspector(QSGView *view, QObject *parent) : AbstractViewInspector(parent), m_view(view), m_overlay(new QSGItem), - m_currentTool(0), m_selectionTool(new SGSelectionTool(this)), m_designMode(true) { @@ -75,7 +72,7 @@ SGViewInspector::SGViewInspector(QSGView *view, QObject *parent) : m_overlay->setParentItem(root); view->installEventFilter(this); - m_currentTool = m_selectionTool; + setCurrentTool(m_selectionTool); } void SGViewInspector::changeCurrentObjects(const QList &objects) @@ -118,7 +115,7 @@ void SGViewInspector::changeTool(InspectorProtocol::Tool tool) emit marqueeSelectToolActivated(); break; case InspectorProtocol::SelectTool: - m_currentTool = m_selectionTool; + setCurrentTool(m_selectionTool); emit selectToolActivated(); break; case InspectorProtocol::ZoomTool: @@ -180,104 +177,10 @@ void SGViewInspector::removeFromSelectedItems(QObject *object) bool SGViewInspector::eventFilter(QObject *obj, QEvent *event) { - if (obj != m_view || !m_designMode) + if (obj != m_view) return QObject::eventFilter(obj, event); - 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; - } - - return QObject::eventFilter(obj, event); -} - -bool SGViewInspector::leaveEvent(QEvent *event) -{ - m_currentTool->leaveEvent(event); - return true; -} - -bool SGViewInspector::mousePressEvent(QMouseEvent *event) -{ - m_currentTool->mousePressEvent(event); - return true; -} - -bool SGViewInspector::mouseMoveEvent(QMouseEvent *event) -{ - if (event->buttons()) { - m_currentTool->mouseMoveEvent(event); - } else { - m_currentTool->hoverMoveEvent(event); - } - return true; -} - -bool SGViewInspector::mouseReleaseEvent(QMouseEvent *event) -{ - m_currentTool->mouseReleaseEvent(event); - return true; -} - -bool SGViewInspector::keyPressEvent(QKeyEvent *event) -{ - m_currentTool->keyPressEvent(event); - return true; -} - -bool SGViewInspector::keyReleaseEvent(QKeyEvent *event) -{ - switch (event->key()) { - default: - break; - } - - m_currentTool->keyReleaseEvent(event); - return true; -} - -bool SGViewInspector::mouseDoubleClickEvent(QMouseEvent *event) -{ - m_currentTool->mouseDoubleClickEvent(event); - return true; -} - -bool SGViewInspector::wheelEvent(QWheelEvent *event) -{ - m_currentTool->wheelEvent(event); - return true; + return AbstractViewInspector::eventFilter(obj, event); } } // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h index 6173c49..2a7cb6c 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h +++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h @@ -47,17 +47,12 @@ #include QT_BEGIN_NAMESPACE -class QMouseEvent; -class QKeyEvent; -class QWheelEvent; - class QSGView; class QSGItem; QT_END_NAMESPACE namespace QmlJSDebugger { -class SGAbstractTool; class SGSelectionTool; class SGViewInspector : public AbstractViewInspector @@ -86,18 +81,8 @@ private slots: void removeFromSelectedItems(QObject *); private: - 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); - QSGView *m_view; QSGItem *m_overlay; - SGAbstractTool *m_currentTool; SGSelectionTool *m_selectionTool; -- 1.7.2.5