Add a property to tooltip to enable/disable tooltips

This is useful to be able to disable tooltips when a dialog exists.

We don't use the QQuickItem::enabled property as this propagates onto
children and has side effects.

REVIEW: 115623
This commit is contained in:
David Edmundson 2014-02-10 13:27:14 +01:00
parent 0d138bf2fb
commit 66d10d5c5a
2 changed files with 25 additions and 1 deletions

View File

@ -32,7 +32,8 @@
ToolTip::ToolTip(QQuickItem *parent)
: QQuickItem(parent),
m_containsMouse(false),
m_location(Plasma::Types::Floating)
m_location(Plasma::Types::Floating),
m_active(true)
{
m_showTimer = new QTimer(this);
m_showTimer->setSingleShot(true);
@ -64,6 +65,10 @@ void ToolTip::setMainItem(QQuickItem *mainItem)
void ToolTip::showToolTip()
{
if (!m_active) {
return;
}
ToolTipDialog *dlg = ToolTipDialog::instance();
if (!mainItem()) {
@ -166,6 +171,19 @@ void ToolTip::setLocation(Plasma::Types::Location location)
emit locationChanged();
}
void ToolTip::setActive(bool active)
{
if (m_active == active) {
return;
}
m_active = active;
if (!active) {
ToolTipDialog::instance()->dismiss();
}
emit activeChanged();
}
QVariant ToolTip::icon() const
{
if (m_icon.isValid()) {

View File

@ -101,6 +101,8 @@ class ToolTip : public QQuickItem
*/
Q_PROPERTY(QVariant image READ image WRITE setImage NOTIFY imageChanged)
Q_PROPERTY(bool active MEMBER m_active WRITE setActive NOTIFY activeChanged)
public:
ToolTip(QQuickItem *parent = 0);
~ToolTip();
@ -128,6 +130,8 @@ public:
bool containsMouse() const;
void setContainsMouse(bool contains);
void setActive(bool active);
protected:
bool childMouseEventFilter(QQuickItem *item, QEvent *event);
void hoverEnterEvent(QHoverEvent *event);
@ -142,6 +146,7 @@ Q_SIGNALS:
void imageChanged();
void containsMouseChanged();
void locationChanged();
void activeChanged();
private:
bool m_containsMouse;
@ -152,6 +157,7 @@ private:
QString m_subText;
QVariant m_image;
QVariant m_icon;
bool m_active;
};
#endif