diff --git a/src/declarativeimports/core/tooltip.cpp b/src/declarativeimports/core/tooltip.cpp index 40e0af524..3ffcdbae9 100644 --- a/src/declarativeimports/core/tooltip.cpp +++ b/src/declarativeimports/core/tooltip.cpp @@ -60,6 +60,10 @@ ToolTip::ToolTip(QQuickItem *parent) ToolTip::~ToolTip() { + if (s_dialog && s_dialog->owner() == this) { + s_dialog->setVisible(false); + } + if (m_usingDialog) { --s_dialogUsers; } @@ -109,6 +113,10 @@ void ToolTip::setMainItem(QQuickItem *mainItem) m_mainItem = mainItem; emit mainItemChanged(); + + if (!isValid() && s_dialog && s_dialog->owner() == this) { + s_dialog->setVisible(false); + } } } @@ -145,6 +153,8 @@ void ToolTip::showToolTip() mainItem()->setVisible(true); } + dlg->setOwner(this); + //if the dialog is not currently visible, disable the animated repositioning dlg->setAnimationsEnabled(dlg->isVisible()); dlg->show(); @@ -167,6 +177,10 @@ void ToolTip::setMainText(const QString &mainText) m_mainText = mainText; emit mainTextChanged(); + + if (!isValid() && s_dialog && s_dialog->owner() == this) { + s_dialog->setVisible(false); + } } QString ToolTip::subText() const @@ -182,6 +196,10 @@ void ToolTip::setSubText(const QString &subText) m_subText = subText; emit subTextChanged(); + + if (!isValid() && s_dialog && s_dialog->owner() == this) { + s_dialog->setVisible(false); + } } int ToolTip::textFormat() const @@ -305,9 +323,10 @@ void ToolTip::hoverEnterEvent(QHoverEvent *event) return; } - if (!m_mainItem && mainText().isEmpty() && subText().isEmpty()) { + if (!isValid()) { return; } + if (tooltipDialogInstance()->isVisible()) { // We signal the tooltipmanager that we're "potentially interested, // and ask to keep it open for a bit, so other items get the chance @@ -333,3 +352,7 @@ bool ToolTip::childMouseEventFilter(QQuickItem *item, QEvent *event) return QQuickItem::childMouseEventFilter(item, event); } +bool ToolTip::isValid() const +{ + return m_mainItem || !mainText().isEmpty() || !subText().isEmpty(); +} diff --git a/src/declarativeimports/core/tooltip.h b/src/declarativeimports/core/tooltip.h index 7a58826fd..b8ed61aa7 100644 --- a/src/declarativeimports/core/tooltip.h +++ b/src/declarativeimports/core/tooltip.h @@ -193,6 +193,8 @@ private Q_SLOTS: void settingsChanged(); private: + bool isValid() const; + void loadSettings(); bool m_tooltipsEnabledGlobally; bool m_containsMouse; diff --git a/src/declarativeimports/core/tooltipdialog.cpp b/src/declarativeimports/core/tooltipdialog.cpp index 6c5675e3d..feeacc335 100644 --- a/src/declarativeimports/core/tooltipdialog.cpp +++ b/src/declarativeimports/core/tooltipdialog.cpp @@ -32,7 +32,8 @@ ToolTipDialog::ToolTipDialog(QQuickItem *parent) m_animation(0), m_hideTimeout(4000), m_interactive(false), - m_animationsEnabled(true) + m_animationsEnabled(true), + m_owner(Q_NULLPTR) { setFlags(Qt::ToolTip | Qt::BypassWindowManagerHint); setLocation(Plasma::Types::Floating); @@ -147,6 +148,16 @@ void ToolTipDialog::setAnimationsEnabled(bool enabled) m_animationsEnabled = enabled; } +QObject *ToolTipDialog::owner() const +{ + return m_owner; +} + +void ToolTipDialog::setOwner(QObject *owner) +{ + m_owner = owner; +} + void ToolTipDialog::dismiss() { m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms diff --git a/src/declarativeimports/core/tooltipdialog.h b/src/declarativeimports/core/tooltipdialog.h index d81dadb69..2ea8af9cb 100644 --- a/src/declarativeimports/core/tooltipdialog.h +++ b/src/declarativeimports/core/tooltipdialog.h @@ -66,6 +66,12 @@ public: bool animationsEnabled() const; void setAnimationsEnabled(bool enabled); + /** + * Basically the last one who has shown the dialog + */ + QObject *owner() const; + void setOwner(QObject *owner); + protected: void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE; @@ -82,6 +88,7 @@ private: int m_hideTimeout; bool m_interactive; bool m_animationsEnabled; + QObject *m_owner; }; #endif