Unified the three fake tooltip copies

Reviewed-by: mae
This commit is contained in:
Thorbjørn Lindeijer
2010-04-14 17:24:29 +02:00
parent 990ec1be91
commit 20636f529b
6 changed files with 163 additions and 121 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -39,7 +39,8 @@ SOURCES += reloadpromptutils.cpp \
detailsbutton.cpp \ detailsbutton.cpp \
detailswidget.cpp \ detailswidget.cpp \
changeset.cpp \ changeset.cpp \
filterlineedit.cpp filterlineedit.cpp \
faketooltip.cpp
win32 { win32 {
SOURCES += abstractprocess_win.cpp \ SOURCES += abstractprocess_win.cpp \
consoleprocess_win.cpp \ consoleprocess_win.cpp \
@@ -91,7 +92,8 @@ HEADERS += utils_global.h \
detailsbutton.h \ detailsbutton.h \
detailswidget.h \ detailswidget.h \
changeset.h \ changeset.h \
filterlineedit.h filterlineedit.h \
faketooltip.h
FORMS += filewizardpage.ui \ FORMS += filewizardpage.ui \
projectintropage.ui \ projectintropage.ui \
newclasswidget.ui \ newclasswidget.ui \

View File

@@ -60,6 +60,8 @@
#include <texteditor/itexteditable.h> #include <texteditor/itexteditable.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <utils/faketooltip.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QtCore/QDebug> #include <QtCore/QDebug>
@@ -70,8 +72,7 @@
#include <QtGui/QDesktopWidget> #include <QtGui/QDesktopWidget>
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QStyleOption> #include <QtGui/QStyle>
#include <QtGui/QStylePainter>
#include <QtGui/QTextDocument> // Qt::escape() #include <QtGui/QTextDocument> // Qt::escape()
#include <QtGui/QToolButton> #include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
@@ -81,29 +82,6 @@ using namespace CPlusPlus;
namespace CppTools { namespace CppTools {
namespace Internal { 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 class FunctionArgumentWidget : public QLabel
{ {
Q_OBJECT Q_OBJECT
@@ -137,7 +115,7 @@ private:
QWidget *m_pager; QWidget *m_pager;
QLabel *m_numberLabel; QLabel *m_numberLabel;
FakeToolTipFrame *m_popupFrame; Utils::FakeToolTip *m_popupFrame;
QList<Function *> m_items; QList<Function *> m_items;
LookupContext m_context; LookupContext m_context;
}; };
@@ -238,24 +216,6 @@ using namespace CppTools::Internal;
Q_DECLARE_METATYPE(CompleteFunctionDeclaration) 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(): FunctionArgumentWidget::FunctionArgumentWidget():
m_startpos(-1), m_startpos(-1),
@@ -265,7 +225,7 @@ FunctionArgumentWidget::FunctionArgumentWidget():
QObject *editorObject = Core::EditorManager::instance()->currentEditor(); QObject *editorObject = Core::EditorManager::instance()->currentEditor();
m_editor = qobject_cast<TextEditor::ITextEditor *>(editorObject); 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; QToolButton *downArrow = new QToolButton;
downArrow->setArrowType(Qt::DownArrow); downArrow->setArrowType(Qt::DownArrow);
@@ -300,8 +260,6 @@ FunctionArgumentWidget::FunctionArgumentWidget():
connect(downArrow, SIGNAL(clicked()), SLOT(nextPage())); connect(downArrow, SIGNAL(clicked()), SLOT(nextPage()));
setTextFormat(Qt::RichText); setTextFormat(Qt::RichText);
setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
setIndent(1);
qApp->installEventFilter(this); qApp->installEventFilter(this);
} }

View File

@@ -43,6 +43,8 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <utils/faketooltip.h>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDir> #include <QtCore/QDir>
@@ -51,8 +53,7 @@
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QStylePainter> #include <QtGui/QStyle>
#include <QtGui/QStyleOption>
#include <QtGui/QToolButton> #include <QtGui/QToolButton>
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QApplication> #include <QtGui/QApplication>
@@ -263,29 +264,6 @@ private:
namespace QmlJSEditor { namespace QmlJSEditor {
namespace Internal { 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 class FunctionArgumentWidget : public QLabel
{ {
public: public:
@@ -313,27 +291,9 @@ private:
QWidget *m_pager; QWidget *m_pager;
QLabel *m_numberLabel; 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(): FunctionArgumentWidget::FunctionArgumentWidget():
m_minimumArgumentCount(0), m_minimumArgumentCount(0),
@@ -344,7 +304,7 @@ FunctionArgumentWidget::FunctionArgumentWidget():
QObject *editorObject = Core::EditorManager::instance()->currentEditor(); QObject *editorObject = Core::EditorManager::instance()->currentEditor();
m_editor = qobject_cast<TextEditor::ITextEditor *>(editorObject); 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); setParent(m_popupFrame);
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
@@ -364,8 +324,6 @@ FunctionArgumentWidget::FunctionArgumentWidget():
m_popupFrame->setLayout(layout); m_popupFrame->setLayout(layout);
setTextFormat(Qt::RichText); setTextFormat(Qt::RichText);
setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
setIndent(1);
qApp->installEventFilter(this); qApp->installEventFilter(this);
} }
@@ -399,7 +357,6 @@ void FunctionArgumentWidget::updateArgumentHighlight()
updateHintText(); updateHintText();
QString str = m_editor->textAt(m_startpos, curpos - m_startpos); QString str = m_editor->textAt(m_startpos, curpos - m_startpos);
int argnr = 0; int argnr = 0;
int parcount = 0; int parcount = 0;

View File

@@ -32,6 +32,8 @@
#include "icompletioncollector.h" #include "icompletioncollector.h"
#include <texteditor/itexteditable.h> #include <texteditor/itexteditable.h>
#include <utils/faketooltip.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QtCore/QEvent> #include <QtCore/QEvent>
@@ -73,37 +75,29 @@ private:
}; };
class CompletionInfoFrame : public QLabel { class CompletionInfoFrame : public Utils::FakeToolTip
{
public: public:
CompletionInfoFrame(QWidget *parent = 0) : CompletionInfoFrame(QWidget *parent = 0) :
QLabel(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint) Utils::FakeToolTip(parent),
m_label(new QLabel(this))
{ {
setFocusPolicy(Qt::NoFocus); QVBoxLayout *layout = new QVBoxLayout(this);
setAttribute(Qt::WA_DeleteOnClose); layout->setMargin(0);
setForegroundRole(QPalette::ToolTipText); layout->setSpacing(0);
setBackgroundRole(QPalette::ToolTipBase); layout->addWidget(m_label);
setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
setIndent(1); m_label->setForegroundRole(QPalette::ToolTipText);
m_label->setBackgroundRole(QPalette::ToolTipBase);
} }
void paintEvent(QPaintEvent *e) { void setText(const QString &text)
QStylePainter p(this);
QStyleOptionFrame opt;
opt.init(this);
p.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
p.end();
QLabel::paintEvent(e);
}
void resizeEvent(QResizeEvent *e)
{ {
QStyleHintReturnMask frameMask; m_label->setText(text);
QStyleOption option;
option.init(this);
if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option, this, &frameMask))
setMask(frameMask.region);
QLabel::resizeEvent(e);
} }
private:
QLabel *m_label;
}; };