OSDN Git Service

8c01605701fb03b030de80eec5272b2247f01f52
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / debuggertooltipmanager.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef DEBUGGER_DEBUGGERTOOLTIPMANAGER_H
35 #define DEBUGGER_DEBUGGERTOOLTIPMANAGER_H
36
37 #include "debuggerconstants.h"
38
39 #include <QtGui/QTreeView>
40
41 #include <QtCore/QPointer>
42 #include <QtCore/QPoint>
43 #include <QtCore/QList>
44 #include <QtCore/QXmlStreamWriter>
45 #include <QtCore/QXmlStreamReader>
46 #include <QtCore/QDate>
47
48 QT_BEGIN_NAMESPACE
49 class QVBoxLayout;
50 class QToolButton;
51 class QSortFilterProxyModel;
52 class QStandardItemModel;
53 class QPlainTextEdit;
54 class QLabel;
55 class QToolBar;
56 class QDebug;
57 QT_END_NAMESPACE
58
59 namespace Core {
60 class IEditor;
61 class IMode;
62 }
63
64 namespace TextEditor {
65 class ITextEditor;
66 }
67
68 namespace Debugger {
69 class DebuggerEngine;
70
71 namespace Internal {
72 class DraggableLabel;
73 class DebuggerToolTipEditor;
74
75 class PinnableToolTipWidget : public QWidget
76 {
77     Q_OBJECT
78
79 public:
80     enum PinState
81     {
82         Unpinned,
83         Pinned
84     };
85
86     explicit PinnableToolTipWidget(QWidget *parent = 0);
87
88     PinState pinState() const  { return m_pinState; }
89
90     void addWidget(QWidget *w);
91     void addToolBarWidget(QWidget *w);
92
93 public slots:
94     void pin();
95
96 signals:
97     void pinned();
98
99 private slots:
100     void toolButtonClicked();
101
102 private:
103     virtual void doPin();
104
105     PinState m_pinState;
106     QVBoxLayout *m_mainVBoxLayout;
107     QToolBar *m_toolBar;
108     QToolButton *m_toolButton;
109 };
110
111 class DebuggerToolTipContext
112 {
113 public:
114     DebuggerToolTipContext();
115     static DebuggerToolTipContext fromEditor(Core::IEditor *ed, int pos);
116     bool isValid() const { return !fileName.isEmpty(); }
117
118     QString fileName;
119     int position;
120     int line;
121     int column;
122     QString function; //!< Optional function. This must be set by the engine as it is language-specific.
123 };
124
125 QDebug operator<<(QDebug, const DebuggerToolTipContext &);
126
127 class AbstractDebuggerToolTipWidget : public PinnableToolTipWidget
128 {
129     Q_OBJECT
130
131 public:
132     explicit AbstractDebuggerToolTipWidget(QWidget *parent = 0);
133     bool engineAcquired() const { return m_engineAcquired; }
134
135     QString fileName() const { return m_context.fileName; }
136     QString function() const { return m_context.function; }
137     int position() const { return m_context.position; }
138     // Check for a match at position.
139     bool matches(const QString &fileName,
140                  const QString &engineType = QString(),
141                  const QString &function= QString()) const;
142
143     const DebuggerToolTipContext &context() const { return m_context; }
144     void setContext(const DebuggerToolTipContext &c) { m_context = c; }
145
146     QString engineType() const { return m_engineType; }
147     void setEngineType(const QString &e) { m_engineType = e; }
148
149     QDate creationDate() const { return m_creationDate; }
150     void setCreationDate(const QDate &d) { m_creationDate = d; }
151
152     QPoint offset() const { return m_offset; }
153     void setOffset(const QPoint &o) { m_offset = o; }
154
155     static AbstractDebuggerToolTipWidget *loadSessionData(QXmlStreamReader &r);
156
157 public slots:
158     void saveSessionData(QXmlStreamWriter &w) const;
159
160     void acquireEngine(Debugger::DebuggerEngine *engine);
161     void releaseEngine();
162     void copy();
163     bool positionShow(const DebuggerToolTipEditor &pe);
164
165 private slots:
166     virtual void doPin();
167     void slotDragged(const QPoint &p);
168
169 protected:
170     virtual void doAcquireEngine(Debugger::DebuggerEngine *engine) = 0;
171     virtual void doReleaseEngine() = 0;
172     virtual void doSaveSessionData(QXmlStreamWriter &w) const = 0;
173     virtual void doLoadSessionData(QXmlStreamReader &r) = 0;
174     // Return a string suitable for copying contents
175     virtual QString clipboardContents() const { return QString(); }
176
177 private:
178     static AbstractDebuggerToolTipWidget *loadSessionDataI(QXmlStreamReader &r);
179     DraggableLabel *m_titleLabel;
180     bool m_engineAcquired;
181     QString m_engineType;
182     DebuggerToolTipContext m_context;
183     QDate m_creationDate;
184     QPoint m_offset; //!< Offset to text cursor position (user dragging).
185 };
186
187 class DebuggerToolTipTreeView : public QTreeView
188 {
189     Q_OBJECT
190
191 public:
192     explicit DebuggerToolTipTreeView(QWidget *parent = 0);
193
194     QAbstractItemModel *swapModel(QAbstractItemModel *model);
195
196     QSize sizeHint() const { return m_size; }
197
198     int computeHeight(const QModelIndex &index) const;
199
200 public slots:
201     void computeSize();
202
203 private:
204     void init(QAbstractItemModel *model);
205
206     QSize m_size;
207 };
208
209 class DebuggerTreeViewToolTipWidget : public AbstractDebuggerToolTipWidget
210 {
211     Q_OBJECT
212
213 public:
214     explicit DebuggerTreeViewToolTipWidget(QWidget *parent = 0);
215
216     int debuggerModel() const { return m_debuggerModel; }
217     void setDebuggerModel(int m) { m_debuggerModel = m; }
218     QString expression() const { return m_expression; }
219     void setExpression(const QString &e) { m_expression = e; }
220
221     static QString treeModelClipboardContents(const QAbstractItemModel *m);
222
223 protected:
224     virtual void doAcquireEngine(Debugger::DebuggerEngine *engine);
225     virtual void doReleaseEngine();
226     virtual void doSaveSessionData(QXmlStreamWriter &w) const;
227     virtual void doLoadSessionData(QXmlStreamReader &r);
228     virtual QString clipboardContents() const;
229
230 private:
231     static void restoreTreeModel(QXmlStreamReader &r, QStandardItemModel *m);
232
233     int m_debuggerModel;
234     QString m_expression;
235
236     DebuggerToolTipTreeView *m_treeView;
237     QStandardItemModel *m_defaultModel;
238 };
239
240 class DebuggerToolTipManager : public QObject
241 {
242     Q_OBJECT
243
244 public:
245     explicit DebuggerToolTipManager(QObject *parent = 0);
246     virtual ~DebuggerToolTipManager();
247
248     static DebuggerToolTipManager *instance() { return m_instance; }
249     void registerEngine(DebuggerEngine *engine);
250     bool hasToolTips() const { return !m_pinnedTooltips.isEmpty(); }
251
252     // Collect all expressions of DebuggerTreeViewToolTipWidget
253     QStringList treeWidgetExpressions(const QString &fileName,
254                                       const QString &engineType = QString(),
255                                       const QString &function= QString()) const;
256
257     void showToolTip(const QPoint &p, Core::IEditor *editor, AbstractDebuggerToolTipWidget *);
258
259     virtual bool eventFilter(QObject *, QEvent *);
260
261     static bool debug();
262
263 public slots:
264     void debugModeEntered();
265     void leavingDebugMode();
266     void sessionAboutToChange();
267     void loadSessionData();
268     void saveSessionData();
269     void closeAllToolTips();
270     void hide()
271 ;
272
273 private slots:
274     void slotUpdateVisibleToolTips();
275     void slotDebuggerStateChanged(Debugger::DebuggerState);
276     void slotStackFrameCompleted();
277     void slotEditorOpened(Core::IEditor *);
278     void slotPinnedFirstTime();
279     void slotTooltipOverrideRequested(TextEditor::ITextEditor *editor,
280             const QPoint &point, int pos, bool *handled);
281
282 private:
283     typedef QList<QPointer<AbstractDebuggerToolTipWidget> > DebuggerToolTipWidgetList;
284
285     void registerToolTip(AbstractDebuggerToolTipWidget *toolTipWidget);
286     void moveToolTipsBy(const QPoint &distance);
287     // Purge out closed (null) tooltips and return list for convenience
288     DebuggerToolTipWidgetList &purgeClosedToolTips();
289
290     static DebuggerToolTipManager *m_instance;
291
292     DebuggerToolTipWidgetList m_pinnedTooltips;
293     bool m_debugModeActive;
294     QPoint m_lastToolTipPoint;
295     Core::IEditor *m_lastToolTipEditor;
296 };
297
298 } // namespace Internal
299 } // namespace Debugger
300
301 #endif // DEBUGGER_INTERNAL_DEBUGGERTOOLTIPMANAGER_H