Debugger: Inspector code cleanup
[profile/ivi/qtdeclarative.git] / src / plugins / qmltooling / qmldbg_inspector / abstractviewinspector.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef ABSTRACTVIEWINSPECTOR_H
43 #define ABSTRACTVIEWINSPECTOR_H
44
45 #include <QtCore/QHash>
46 #include <QtCore/QObject>
47 #include <QtCore/QStringList>
48 #include <QtGui/QColor>
49
50 #include "qdeclarativeinspectorprotocol.h"
51 #include "qmlinspectorconstants.h"
52
53 QT_BEGIN_NAMESPACE
54 class QDeclarativeEngine;
55 class QDeclarativeInspectorService;
56 class QKeyEvent;
57 class QMouseEvent;
58 class QWheelEvent;
59 QT_END_NAMESPACE
60
61 namespace QmlJSDebugger {
62
63 class AbstractTool;
64
65 /*
66  * The common code between QQuickView and QDeclarativeView inspectors lives here,
67  */
68 class AbstractViewInspector : public QObject
69 {
70     Q_OBJECT
71
72 public:
73     explicit AbstractViewInspector(QObject *parent = 0);
74
75     void createQmlObject(const QString &qml, QObject *parent,
76                          const QStringList &importList,
77                          const QString &filename = QString());
78     void clearComponentCache();
79
80     bool showAppOnTop() const { return m_showAppOnTop; }
81     bool designModeBehavior() const { return m_designModeBehavior; }
82
83     bool animationPaused() const { return m_animationPaused; }
84     qreal slowDownFactor() const { return m_slowDownFactor; }
85
86     void sendCurrentObjects(const QList<QObject*> &);
87     void sendAnimationSpeed(qreal slowDownFactor);
88     void sendAnimationPaused(bool paused);
89     void sendCurrentTool(Constants::DesignTool toolId);
90     void sendReloaded();
91     void sendShowAppOnTop(bool showAppOnTop);
92
93     QString idStringForObject(QObject *obj) const;
94
95     virtual void changeCurrentObjects(const QList<QObject*> &objects) = 0;
96     virtual void reloadView() = 0;
97     virtual void reparentQmlObject(QObject *object, QObject *newParent) = 0;
98     virtual void changeTool(InspectorProtocol::Tool tool) = 0;
99     virtual Qt::WindowFlags windowFlags() const = 0;
100     virtual void setWindowFlags(Qt::WindowFlags flags) = 0;
101     virtual QDeclarativeEngine *declarativeEngine() const = 0;
102
103 signals:
104     void designModeBehaviorChanged(bool inDesignMode);
105     void showAppOnTopChanged(bool showAppOnTop);
106     void reloadRequested();
107     void marqueeSelectToolActivated();
108     void selectToolActivated();
109     void zoomToolActivated();
110     void colorPickerActivated();
111     void selectedColorChanged(const QColor &color);
112
113     void animationSpeedChanged(qreal factor);
114     void animationPausedChanged(bool paused);
115
116 protected:
117     AbstractTool *currentTool() const { return m_currentTool; }
118     void setCurrentTool(AbstractTool *tool) { m_currentTool = tool; }
119     bool eventFilter(QObject *, QEvent *);
120
121     virtual bool leaveEvent(QEvent *);
122     virtual bool mousePressEvent(QMouseEvent *event);
123     virtual bool mouseMoveEvent(QMouseEvent *event);
124     virtual bool mouseReleaseEvent(QMouseEvent *event);
125     virtual bool keyPressEvent(QKeyEvent *event);
126     virtual bool keyReleaseEvent(QKeyEvent *keyEvent);
127     virtual bool mouseDoubleClickEvent(QMouseEvent *event);
128     virtual bool wheelEvent(QWheelEvent *event);
129
130 private slots:
131     void handleMessage(const QByteArray &message);
132     void sendColorChanged(const QColor &color);
133
134 private:
135     void sendDesignModeBehavior(bool inDesignMode);
136
137     void changeToColorPickerTool();
138     void changeToZoomTool();
139     void changeToSingleSelectTool();
140     void changeToMarqueeSelectTool();
141
142     virtual void setDesignModeBehavior(bool value);
143
144     void setShowAppOnTop(bool appOnTop);
145
146     void setAnimationSpeed(qreal factor);
147     void setAnimationPaused(bool paused);
148
149     void animationSpeedChangeRequested(qreal factor);
150     void animationPausedChangeRequested(bool paused);
151
152     AbstractTool *m_currentTool;
153
154     bool m_showAppOnTop;
155     bool m_designModeBehavior;
156
157     bool m_animationPaused;
158     qreal m_slowDownFactor;
159
160     QHash<int, QString> m_stringIdForObjectId;
161     QDeclarativeInspectorService *m_debugService;
162 };
163
164 } // namespace QmlJSDebugger
165
166 #endif // ABSTRACTVIEWINSPECTOR_H