diff options
author | hjk <[email protected]> | 2009-06-24 12:31:09 +0200 |
---|---|---|
committer | hjk <[email protected]> | 2009-06-24 12:31:09 +0200 |
commit | 2a959f47a46b4f85563f8b9367ecf5df52245c88 (patch) | |
tree | 56dc7191ce3717dcfba3d04a33e6f651990d1ce7 /src/plugins/debugger/debuggertooltip.cpp | |
parent | 1c5be603ff327f76fa54e84a9f667d986a5a265d (diff) |
debugger: use an expandable tree in the debugger tooltip
Diffstat (limited to 'src/plugins/debugger/debuggertooltip.cpp')
-rw-r--r-- | src/plugins/debugger/debuggertooltip.cpp | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/src/plugins/debugger/debuggertooltip.cpp b/src/plugins/debugger/debuggertooltip.cpp new file mode 100644 index 00000000000..a3ba05304c8 --- /dev/null +++ b/src/plugins/debugger/debuggertooltip.cpp @@ -0,0 +1,211 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation ([email protected]) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#include "debuggertooltip.h" + +#include <QtCore/QPointer> +#include <QtCore/QtDebug> + +#include <QtGui/QApplication> +#include <QtGui/QHBoxLayout> +#include <QtGui/QHeaderView> +#include <QtGui/QKeyEvent> +#include <QtGui/QLabel> +#include <QtGui/QTreeView> +#include <QtGui/QVBoxLayout> +#include <QtGui/QWidget> + + +namespace Debugger { +namespace Internal { + +/////////////////////////////////////////////////////////////////////// +// +// TooltipTreeView +// +/////////////////////////////////////////////////////////////////////// + +class ToolTipTreeView : public QTreeView +{ +public: + ToolTipTreeView(QWidget *parent = 0) : QTreeView(parent) {} + +/* + QSize sizeHint() const { + qDebug() << viewport()->size() + << viewport()->size().boundedTo(QSize(500, 300)); + return viewport()->size().boundedTo(QSize(100, 100)); + } +*/ +}; + +/////////////////////////////////////////////////////////////////////// +// +// TooltipWidget +// +/////////////////////////////////////////////////////////////////////// + +class ToolTipWidget : public QTreeView +{ + Q_OBJECT + +public: + ToolTipWidget(QWidget *parent); + + void done(); + void run(const QPoint &point, QAbstractItemModel *model, + const QModelIndex &index, const QString &msg); + bool eventFilter(QObject *ob, QEvent *ev); + + QSize sizeHint() const { return m_size; } + + int computeHeight(const QModelIndex &index) + { + int s = rowHeight(index); + for (int i = 0; i < model()->rowCount(index); ++i) + s += computeHeight(model()->index(i, 0, index)); + return s; + } + + Q_SLOT void computeSize() + { + int columns = 0; + for (int i = 0; i < 3; ++i) { + resizeColumnToContents(i); + columns += sizeHintForColumn(i); + } + int rows = computeHeight(QModelIndex()); + m_size = QSize(columns + 5, rows + 5); + setMinimumSize(m_size); + setMaximumSize(m_size); + } +private: + QSize m_size; +}; + +static QPointer<ToolTipWidget> theToolTipWidget; + + +ToolTipWidget::ToolTipWidget(QWidget *parent) + : QTreeView(parent) +{ + setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint); + setFocusPolicy(Qt::NoFocus); + + header()->hide(); + + setUniformRowHeights(true); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(computeSize()), + Qt::QueuedConnection); + connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(computeSize()), + Qt::QueuedConnection); + + qApp->installEventFilter(this); +} + +bool ToolTipWidget::eventFilter(QObject *ob, QEvent *ev) +{ + Q_UNUSED(ob); + switch (ev->type()) { + case QEvent::ShortcutOverride: + if (static_cast<QKeyEvent *>(ev)->key() == Qt::Key_Escape) + return true; + break; + case QEvent::KeyPress: + if (static_cast<QKeyEvent *>(ev)->key() == Qt::Key_Escape) { + return true; + } + break; + case QEvent::KeyRelease: + if (static_cast<QKeyEvent *>(ev)->key() == Qt::Key_Escape) { + done(); + return true; + } + break; + case QEvent::WindowDeactivate: + case QEvent::FocusOut: + done(); + break; + default: + break; + } + return false; +} + +void ToolTipWidget::done() +{ + qApp->removeEventFilter(this); + deleteLater(); +} + +void ToolTipWidget::run(const QPoint &point, QAbstractItemModel *model, + const QModelIndex &index, const QString &msg) +{ + move(point); + setModel(model); + setRootIndex(index.parent()); + computeSize(); + setRootIsDecorated(model->hasChildren(index)); + // FIXME: use something more sensible + QPalette pal = palette(); + QColor bg = pal.color(QPalette::Base); + bg.setAlpha(20); + pal.setColor(QPalette::Base, bg); + setPalette(pal); + //viewport()->setPalette(pal); +} + +void showDebuggerToolTip(const QPoint &point, QAbstractItemModel *model, + const QModelIndex &index, const QString &msg) +{ + if (model) { + if (!theToolTipWidget) + theToolTipWidget = new ToolTipWidget(0); + theToolTipWidget->run(point, model, index, msg); + theToolTipWidget->show(); + } else if (theToolTipWidget) { + theToolTipWidget->done(); + theToolTipWidget = 0; + } +} + +void hideDebuggerToolTip(int delay) +{ + Q_UNUSED(delay) + if (theToolTipWidget) + theToolTipWidget->done(); +} + +} // namespace Internal +} // namespace Debugger + +#include "debuggertooltip.moc" |