Commit 20636f52 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Unified the three fake tooltip copies

Reviewed-by: mae
parent 990ec1be
/**************************************************************************
**
** 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
/**************************************************************************
**
** 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
......@@ -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 \
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment