diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/utils/faketooltip.cpp | 74 | ||||
-rw-r--r-- | src/libs/utils/faketooltip.h | 57 | ||||
-rw-r--r-- | src/libs/utils/utils.pro | 6 | ||||
-rw-r--r-- | src/plugins/cpptools/cppcodecompletion.cpp | 52 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljscodecompletion.cpp | 53 | ||||
-rw-r--r-- | src/plugins/texteditor/completionwidget.cpp | 42 |
6 files changed, 163 insertions, 121 deletions
diff --git a/src/libs/utils/faketooltip.cpp b/src/libs/utils/faketooltip.cpp new file mode 100644 index 0000000000..c84b5631b6 --- /dev/null +++ b/src/libs/utils/faketooltip.cpp @@ -0,0 +1,74 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "faketooltip.h" + +#include <QtGui/QStyleOption> +#include <QtGui/QStylePainter> + +namespace Utils { + +FakeToolTip::FakeToolTip(QWidget *parent) : + QWidget(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint) +{ + setFocusPolicy(Qt::NoFocus); + setAttribute(Qt::WA_DeleteOnClose); + + // Set the window and button text to the tooltip text color, since this + // widget draws the background as a tooltip. + QPalette p = palette(); + const QColor toolTipTextColor = p.color(QPalette::Inactive, QPalette::ToolTipText); + p.setColor(QPalette::Inactive, QPalette::WindowText, toolTipTextColor); + p.setColor(QPalette::Inactive, QPalette::ButtonText, toolTipTextColor); + setPalette(p); + + const int margin = 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this); + setContentsMargins(margin + 1, margin, margin, margin); + setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / 255.0); +} + +void FakeToolTip::paintEvent(QPaintEvent *) +{ + QStylePainter p(this); + QStyleOptionFrame opt; + opt.init(this); + p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); + p.end(); +} + +void FakeToolTip::resizeEvent(QResizeEvent *) +{ + QStyleHintReturnMask frameMask; + QStyleOption option; + option.init(this); + if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option, this, &frameMask)) + setMask(frameMask.region); +} + +} // namespace Utils diff --git a/src/libs/utils/faketooltip.h b/src/libs/utils/faketooltip.h new file mode 100644 index 0000000000..29666e7331 --- /dev/null +++ b/src/libs/utils/faketooltip.h @@ -0,0 +1,57 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef FAKETOOLTIP_H +#define FAKETOOLTIP_H + +#include "utils_global.h" + +#include <QWidget> + +namespace Utils { + +/** + * A widget that pretends to be a tooltip. By default it has + * Qt::WA_DeleteOnClose set. + */ +class QTCREATOR_UTILS_EXPORT FakeToolTip : public QWidget +{ + Q_OBJECT + +public: + explicit FakeToolTip(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *e); + void resizeEvent(QResizeEvent *e); +}; + +} // namespace Utils + +#endif // FAKETOOLTIP_H diff --git a/src/libs/utils/utils.pro b/src/libs/utils/utils.pro index 74c5b3039b..bf2691171b 100644 --- a/src/libs/utils/utils.pro +++ b/src/libs/utils/utils.pro @@ -39,7 +39,8 @@ SOURCES += reloadpromptutils.cpp \ detailsbutton.cpp \ detailswidget.cpp \ changeset.cpp \ - filterlineedit.cpp + filterlineedit.cpp \ + faketooltip.cpp win32 { SOURCES += abstractprocess_win.cpp \ consoleprocess_win.cpp \ @@ -91,7 +92,8 @@ HEADERS += utils_global.h \ detailsbutton.h \ detailswidget.h \ changeset.h \ - filterlineedit.h + filterlineedit.h \ + faketooltip.h FORMS += filewizardpage.ui \ projectintropage.ui \ newclasswidget.ui \ diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index b7b26caf1b..a01e63b18d 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -60,6 +60,8 @@ #include <texteditor/itexteditable.h> #include <texteditor/basetexteditor.h> #include <projectexplorer/projectexplorer.h> + +#include <utils/faketooltip.h> #include <utils/qtcassert.h> #include <QtCore/QDebug> @@ -70,8 +72,7 @@ #include <QtGui/QDesktopWidget> #include <QtGui/QKeyEvent> #include <QtGui/QLabel> -#include <QtGui/QStyleOption> -#include <QtGui/QStylePainter> +#include <QtGui/QStyle> #include <QtGui/QTextDocument> // Qt::escape() #include <QtGui/QToolButton> #include <QtGui/QVBoxLayout> @@ -81,29 +82,6 @@ using namespace CPlusPlus; namespace CppTools { namespace Internal { -class FakeToolTipFrame : public QWidget -{ -public: - FakeToolTipFrame(QWidget *parent = 0) : - QWidget(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint) - { - setFocusPolicy(Qt::NoFocus); - setAttribute(Qt::WA_DeleteOnClose); - - // Set the window and button text to the tooltip text color, since this - // widget draws the background as a tooltip. - QPalette p = palette(); - const QColor toolTipTextColor = p.color(QPalette::Inactive, QPalette::ToolTipText); - p.setColor(QPalette::Inactive, QPalette::WindowText, toolTipTextColor); - p.setColor(QPalette::Inactive, QPalette::ButtonText, toolTipTextColor); - setPalette(p); - } - -protected: - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); -}; - class FunctionArgumentWidget : public QLabel { Q_OBJECT @@ -137,7 +115,7 @@ private: QWidget *m_pager; QLabel *m_numberLabel; - FakeToolTipFrame *m_popupFrame; + Utils::FakeToolTip *m_popupFrame; QList<Function *> m_items; LookupContext m_context; }; @@ -238,24 +216,6 @@ using namespace CppTools::Internal; Q_DECLARE_METATYPE(CompleteFunctionDeclaration) -void FakeToolTipFrame::paintEvent(QPaintEvent *) -{ - QStylePainter p(this); - QStyleOptionFrame opt; - opt.init(this); - p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); - p.end(); -} - -void FakeToolTipFrame::resizeEvent(QResizeEvent *) -{ - QStyleHintReturnMask frameMask; - QStyleOption option; - option.init(this); - if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option, this, &frameMask)) - setMask(frameMask.region); -} - FunctionArgumentWidget::FunctionArgumentWidget(): m_startpos(-1), @@ -265,7 +225,7 @@ FunctionArgumentWidget::FunctionArgumentWidget(): QObject *editorObject = Core::EditorManager::instance()->currentEditor(); m_editor = qobject_cast<TextEditor::ITextEditor *>(editorObject); - m_popupFrame = new FakeToolTipFrame(m_editor->widget()); + m_popupFrame = new Utils::FakeToolTip(m_editor->widget()); QToolButton *downArrow = new QToolButton; downArrow->setArrowType(Qt::DownArrow); @@ -300,8 +260,6 @@ FunctionArgumentWidget::FunctionArgumentWidget(): connect(downArrow, SIGNAL(clicked()), SLOT(nextPage())); setTextFormat(Qt::RichText); - setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this)); - setIndent(1); qApp->installEventFilter(this); } diff --git a/src/plugins/qmljseditor/qmljscodecompletion.cpp b/src/plugins/qmljseditor/qmljscodecompletion.cpp index a074fee00c..11f3438bee 100644 --- a/src/plugins/qmljseditor/qmljscodecompletion.cpp +++ b/src/plugins/qmljseditor/qmljscodecompletion.cpp @@ -43,6 +43,8 @@ #include <coreplugin/icore.h> #include <coreplugin/editormanager/editormanager.h> +#include <utils/faketooltip.h> + #include <QtCore/QFile> #include <QtCore/QFileInfo> #include <QtCore/QDir> @@ -51,8 +53,7 @@ #include <QtGui/QPainter> #include <QtGui/QLabel> -#include <QtGui/QStylePainter> -#include <QtGui/QStyleOption> +#include <QtGui/QStyle> #include <QtGui/QToolButton> #include <QtGui/QHBoxLayout> #include <QtGui/QApplication> @@ -263,29 +264,6 @@ private: namespace QmlJSEditor { namespace Internal { -class FakeToolTipFrame : public QWidget -{ -public: - FakeToolTipFrame(QWidget *parent = 0) : - QWidget(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint) - { - setFocusPolicy(Qt::NoFocus); - setAttribute(Qt::WA_DeleteOnClose); - - // Set the window and button text to the tooltip text color, since this - // widget draws the background as a tooltip. - QPalette p = palette(); - const QColor toolTipTextColor = p.color(QPalette::Inactive, QPalette::ToolTipText); - p.setColor(QPalette::Inactive, QPalette::WindowText, toolTipTextColor); - p.setColor(QPalette::Inactive, QPalette::ButtonText, toolTipTextColor); - setPalette(p); - } - -protected: - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); -}; - class FunctionArgumentWidget : public QLabel { public: @@ -313,27 +291,9 @@ private: QWidget *m_pager; QLabel *m_numberLabel; - FakeToolTipFrame *m_popupFrame; + Utils::FakeToolTip *m_popupFrame; }; -void FakeToolTipFrame::paintEvent(QPaintEvent *) -{ - QStylePainter p(this); - QStyleOptionFrame opt; - opt.init(this); - p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); - p.end(); -} - -void FakeToolTipFrame::resizeEvent(QResizeEvent *) -{ - QStyleHintReturnMask frameMask; - QStyleOption option; - option.init(this); - if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option, this, &frameMask)) - setMask(frameMask.region); -} - FunctionArgumentWidget::FunctionArgumentWidget(): m_minimumArgumentCount(0), @@ -344,7 +304,7 @@ FunctionArgumentWidget::FunctionArgumentWidget(): QObject *editorObject = Core::EditorManager::instance()->currentEditor(); m_editor = qobject_cast<TextEditor::ITextEditor *>(editorObject); - m_popupFrame = new FakeToolTipFrame(m_editor->widget()); + m_popupFrame = new Utils::FakeToolTip(m_editor->widget()); setParent(m_popupFrame); setFocusPolicy(Qt::NoFocus); @@ -364,8 +324,6 @@ FunctionArgumentWidget::FunctionArgumentWidget(): m_popupFrame->setLayout(layout); setTextFormat(Qt::RichText); - setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this)); - setIndent(1); qApp->installEventFilter(this); } @@ -399,7 +357,6 @@ void FunctionArgumentWidget::updateArgumentHighlight() updateHintText(); - QString str = m_editor->textAt(m_startpos, curpos - m_startpos); int argnr = 0; int parcount = 0; diff --git a/src/plugins/texteditor/completionwidget.cpp b/src/plugins/texteditor/completionwidget.cpp index 9b076e4a33..8c0b4f19e6 100644 --- a/src/plugins/texteditor/completionwidget.cpp +++ b/src/plugins/texteditor/completionwidget.cpp @@ -32,6 +32,8 @@ #include "icompletioncollector.h" #include <texteditor/itexteditable.h> + +#include <utils/faketooltip.h> #include <utils/qtcassert.h> #include <QtCore/QEvent> @@ -73,37 +75,29 @@ private: }; -class CompletionInfoFrame : public QLabel { +class CompletionInfoFrame : public Utils::FakeToolTip +{ public: - CompletionInfoFrame(QWidget *parent = 0) : - QLabel(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint) + Utils::FakeToolTip(parent), + m_label(new QLabel(this)) { - setFocusPolicy(Qt::NoFocus); - setAttribute(Qt::WA_DeleteOnClose); - setForegroundRole(QPalette::ToolTipText); - setBackgroundRole(QPalette::ToolTipBase); - setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this)); - setIndent(1); - } + QVBoxLayout *layout = new QVBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(m_label); - void paintEvent(QPaintEvent *e) { - QStylePainter p(this); - QStyleOptionFrame opt; - opt.init(this); - p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); - p.end(); - QLabel::paintEvent(e); + m_label->setForegroundRole(QPalette::ToolTipText); + m_label->setBackgroundRole(QPalette::ToolTipBase); } - void resizeEvent(QResizeEvent *e) + + void setText(const QString &text) { - QStyleHintReturnMask frameMask; - QStyleOption option; - option.init(this); - if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option, this, &frameMask)) - setMask(frameMask.region); - QLabel::resizeEvent(e); + m_label->setText(text); } + +private: + QLabel *m_label; }; |