forked from qt-creator/qt-creator
Utils: Replace Tooltip hack with another tooltip hack
Instead of fooling moc into believing it operates on a class called QTipLabel and create a "QTipLabel" class name from that, create a metaobject with the "QTipLabel" class name directly. This trades messing around with namespaces for assumptions on the stability of QMetaObject class layout. Given that this is an exported class in Qt Core, that's unlikely to break soon. Change-Id: Iad24dd2a8a7f492e4b238d390888f89c6dd29ea9 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -46,24 +46,41 @@
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
QTipLabel::QTipLabel(QWidget *parent) :
|
TipLabel::TipLabel(QWidget *parent) :
|
||||||
QLabel(parent, Qt::ToolTip | Qt::BypassGraphicsProxyWidget)
|
QLabel(parent, Qt::ToolTip | Qt::BypassGraphicsProxyWidget)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void QTipLabel::setHelpId(const QString &id)
|
void TipLabel::setHelpId(const QString &id)
|
||||||
{
|
{
|
||||||
m_helpId = id;
|
m_helpId = id;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTipLabel::helpId() const
|
QString TipLabel::helpId() const
|
||||||
{
|
{
|
||||||
return m_helpId;
|
return m_helpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QMetaObject *TipLabel::metaObject() const
|
||||||
|
{
|
||||||
|
// CSS Tooltip styling depends on a the name of this class.
|
||||||
|
// So set up a minimalist QMetaObject to fake a class name "QTipLabel":
|
||||||
|
static const uint tip_label_meta_data[15] = { 8 /* moc revision */ };
|
||||||
|
static const QMetaObject tipMetaObject {
|
||||||
|
&QLabel::staticMetaObject,
|
||||||
|
QByteArrayLiteral("QTipLabel").data_ptr(),
|
||||||
|
tip_label_meta_data,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
return &tipMetaObject;
|
||||||
|
}
|
||||||
|
|
||||||
ColorTip::ColorTip(QWidget *parent)
|
ColorTip::ColorTip(QWidget *parent)
|
||||||
: QTipLabel(parent)
|
: TipLabel(parent)
|
||||||
{
|
{
|
||||||
resize(40, 40);
|
resize(40, 40);
|
||||||
}
|
}
|
||||||
@@ -101,7 +118,7 @@ bool ColorTip::equals(int typeId, const QVariant &other, const QString &otherHel
|
|||||||
|
|
||||||
void ColorTip::paintEvent(QPaintEvent *event)
|
void ColorTip::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QTipLabel::paintEvent(event);
|
TipLabel::paintEvent(event);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setBrush(m_color);
|
painter.setBrush(m_color);
|
||||||
@@ -115,7 +132,7 @@ void ColorTip::paintEvent(QPaintEvent *event)
|
|||||||
painter.drawRect(borderRect);
|
painter.drawRect(borderRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextTip::TextTip(QWidget *parent) : QTipLabel(parent)
|
TextTip::TextTip(QWidget *parent) : TipLabel(parent)
|
||||||
{
|
{
|
||||||
setForegroundRole(QPalette::ToolTipText);
|
setForegroundRole(QPalette::ToolTipText);
|
||||||
setBackgroundRole(QPalette::ToolTipBase);
|
setBackgroundRole(QPalette::ToolTipBase);
|
||||||
@@ -210,7 +227,7 @@ void TextTip::resizeEvent(QResizeEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WidgetTip::WidgetTip(QWidget *parent) :
|
WidgetTip::WidgetTip(QWidget *parent) :
|
||||||
QTipLabel(parent), m_layout(new QVBoxLayout)
|
TipLabel(parent), m_layout(new QVBoxLayout)
|
||||||
{
|
{
|
||||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||||
setLayout(m_layout);
|
setLayout(m_layout);
|
||||||
@@ -267,8 +284,5 @@ bool WidgetTip::equals(int typeId, const QVariant &other, const QString &otherHe
|
|||||||
&& other.value<QWidget *>() == m_widget;
|
&& other.value<QWidget *>() == m_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to include it here to force it to be inside the namespaces
|
|
||||||
#include "moc_tips.cpp"
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -33,17 +33,13 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#ifndef Q_MOC_RUN
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
#endif
|
|
||||||
|
|
||||||
// Please do not change the name of this class. Detailed comments in tooltip.h.
|
class TipLabel : public QLabel
|
||||||
class QTipLabel : public QLabel
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
QTipLabel(QWidget *parent);
|
TipLabel(QWidget *parent);
|
||||||
|
|
||||||
virtual void setContent(const QVariant &content) = 0;
|
virtual void setContent(const QVariant &content) = 0;
|
||||||
virtual bool isInteractive() const { return false; }
|
virtual bool isInteractive() const { return false; }
|
||||||
@@ -54,11 +50,14 @@ public:
|
|||||||
virtual void setHelpId(const QString &id);
|
virtual void setHelpId(const QString &id);
|
||||||
virtual QString helpId() const;
|
virtual QString helpId() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const QMetaObject *metaObject() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_helpId;
|
QString m_helpId;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextTip : public QTipLabel
|
class TextTip : public TipLabel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextTip(QWidget *parent);
|
TextTip(QWidget *parent);
|
||||||
@@ -76,7 +75,7 @@ private:
|
|||||||
QString m_text;
|
QString m_text;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ColorTip : public QTipLabel
|
class ColorTip : public TipLabel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ColorTip(QWidget *parent);
|
ColorTip(QWidget *parent);
|
||||||
@@ -93,7 +92,7 @@ private:
|
|||||||
QPixmap m_tilePixmap;
|
QPixmap m_tilePixmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WidgetTip : public QTipLabel
|
class WidgetTip : public TipLabel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -113,7 +112,5 @@ private:
|
|||||||
QVBoxLayout *m_layout;
|
QVBoxLayout *m_layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef Q_MOC_RUN
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class QWidget;
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
namespace Internal { class QTipLabel; }
|
namespace Internal { class TipLabel; }
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT ToolTip : public QObject
|
class QTCREATOR_UTILS_EXPORT ToolTip : public QObject
|
||||||
{
|
{
|
||||||
@@ -110,7 +110,7 @@ private:
|
|||||||
void showTip();
|
void showTip();
|
||||||
void hideTipWithDelay();
|
void hideTipWithDelay();
|
||||||
|
|
||||||
QPointer<Internal::QTipLabel> m_tip;
|
QPointer<Internal::TipLabel> m_tip;
|
||||||
QWidget *m_widget;
|
QWidget *m_widget;
|
||||||
QRect m_rect;
|
QRect m_rect;
|
||||||
QTimer m_showTimer;
|
QTimer m_showTimer;
|
||||||
|
|||||||
Reference in New Issue
Block a user