1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef DEBUGGER_DEBUGGERTOOLTIPMANAGER_H
35 #define DEBUGGER_DEBUGGERTOOLTIPMANAGER_H
37 #include "debuggerconstants.h"
39 #include <QtGui/QTreeView>
41 #include <QtCore/QPointer>
42 #include <QtCore/QPoint>
43 #include <QtCore/QList>
44 #include <QtCore/QXmlStreamWriter>
45 #include <QtCore/QXmlStreamReader>
46 #include <QtCore/QDate>
51 class QSortFilterProxyModel;
52 class QStandardItemModel;
64 namespace TextEditor {
73 class DebuggerToolTipEditor;
75 class PinnableToolTipWidget : public QWidget
86 explicit PinnableToolTipWidget(QWidget *parent = 0);
88 PinState pinState() const { return m_pinState; }
90 void addWidget(QWidget *w);
91 void addToolBarWidget(QWidget *w);
100 void toolButtonClicked();
103 virtual void doPin();
106 QVBoxLayout *m_mainVBoxLayout;
108 QToolButton *m_toolButton;
111 class DebuggerToolTipContext
114 DebuggerToolTipContext();
115 static DebuggerToolTipContext fromEditor(Core::IEditor *ed, int pos);
116 bool isValid() const { return !fileName.isEmpty(); }
122 QString function; //!< Optional function. This must be set by the engine as it is language-specific.
125 QDebug operator<<(QDebug, const DebuggerToolTipContext &);
127 class AbstractDebuggerToolTipWidget : public PinnableToolTipWidget
132 explicit AbstractDebuggerToolTipWidget(QWidget *parent = 0);
133 bool engineAcquired() const { return m_engineAcquired; }
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;
143 const DebuggerToolTipContext &context() const { return m_context; }
144 void setContext(const DebuggerToolTipContext &c) { m_context = c; }
146 QString engineType() const { return m_engineType; }
147 void setEngineType(const QString &e) { m_engineType = e; }
149 QDate creationDate() const { return m_creationDate; }
150 void setCreationDate(const QDate &d) { m_creationDate = d; }
152 QPoint offset() const { return m_offset; }
153 void setOffset(const QPoint &o) { m_offset = o; }
155 static AbstractDebuggerToolTipWidget *loadSessionData(QXmlStreamReader &r);
158 void saveSessionData(QXmlStreamWriter &w) const;
160 void acquireEngine(Debugger::DebuggerEngine *engine);
161 void releaseEngine();
163 bool positionShow(const DebuggerToolTipEditor &pe);
166 virtual void doPin();
167 void slotDragged(const QPoint &p);
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(); }
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).
187 class DebuggerToolTipTreeView : public QTreeView
192 explicit DebuggerToolTipTreeView(QWidget *parent = 0);
194 QAbstractItemModel *swapModel(QAbstractItemModel *model);
196 QSize sizeHint() const { return m_size; }
198 int computeHeight(const QModelIndex &index) const;
204 void init(QAbstractItemModel *model);
209 class DebuggerTreeViewToolTipWidget : public AbstractDebuggerToolTipWidget
214 explicit DebuggerTreeViewToolTipWidget(QWidget *parent = 0);
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; }
221 static QString treeModelClipboardContents(const QAbstractItemModel *m);
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;
231 static void restoreTreeModel(QXmlStreamReader &r, QStandardItemModel *m);
234 QString m_expression;
236 DebuggerToolTipTreeView *m_treeView;
237 QStandardItemModel *m_defaultModel;
240 class DebuggerToolTipManager : public QObject
245 explicit DebuggerToolTipManager(QObject *parent = 0);
246 virtual ~DebuggerToolTipManager();
248 static DebuggerToolTipManager *instance() { return m_instance; }
249 void registerEngine(DebuggerEngine *engine);
250 bool hasToolTips() const { return !m_pinnedTooltips.isEmpty(); }
252 // Collect all expressions of DebuggerTreeViewToolTipWidget
253 QStringList treeWidgetExpressions(const QString &fileName,
254 const QString &engineType = QString(),
255 const QString &function= QString()) const;
257 void showToolTip(const QPoint &p, Core::IEditor *editor, AbstractDebuggerToolTipWidget *);
259 virtual bool eventFilter(QObject *, QEvent *);
264 void debugModeEntered();
265 void leavingDebugMode();
266 void sessionAboutToChange();
267 void loadSessionData();
268 void saveSessionData();
269 void closeAllToolTips();
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);
283 typedef QList<QPointer<AbstractDebuggerToolTipWidget> > DebuggerToolTipWidgetList;
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();
290 static DebuggerToolTipManager *m_instance;
292 DebuggerToolTipWidgetList m_pinnedTooltips;
293 bool m_debugModeActive;
294 QPoint m_lastToolTipPoint;
295 Core::IEditor *m_lastToolTipEditor;
298 } // namespace Internal
299 } // namespace Debugger
301 #endif // DEBUGGER_INTERNAL_DEBUGGERTOOLTIPMANAGER_H