Immediately hide tooltip on ToolTipArea destruction or when it becomes empty
When the tooltip is empty (no text, no subtext, and no mainItem) it will not be shown. However, when it becomes empty while it is already shown, it stays there as a small rectangle. This hides the tooltip immediately (so KWin's fadeout animation still has the proper content rather than the empty tooltip) when the TooltipArea that opened the tooltip has been destroyed or its content becomes empty. CHANGELOG: Fixed stray tooltips when temporary owner of tooltip disappeared or became empty REVIEW: 122939
This commit is contained in:
parent
b7e4669db2
commit
4985a4fe65
@ -60,6 +60,10 @@ ToolTip::ToolTip(QQuickItem *parent)
|
|||||||
|
|
||||||
ToolTip::~ToolTip()
|
ToolTip::~ToolTip()
|
||||||
{
|
{
|
||||||
|
if (s_dialog && s_dialog->owner() == this) {
|
||||||
|
s_dialog->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_usingDialog) {
|
if (m_usingDialog) {
|
||||||
--s_dialogUsers;
|
--s_dialogUsers;
|
||||||
}
|
}
|
||||||
@ -109,6 +113,10 @@ void ToolTip::setMainItem(QQuickItem *mainItem)
|
|||||||
m_mainItem = mainItem;
|
m_mainItem = mainItem;
|
||||||
|
|
||||||
emit mainItemChanged();
|
emit mainItemChanged();
|
||||||
|
|
||||||
|
if (!isValid() && s_dialog && s_dialog->owner() == this) {
|
||||||
|
s_dialog->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +153,8 @@ void ToolTip::showToolTip()
|
|||||||
mainItem()->setVisible(true);
|
mainItem()->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dlg->setOwner(this);
|
||||||
|
|
||||||
//if the dialog is not currently visible, disable the animated repositioning
|
//if the dialog is not currently visible, disable the animated repositioning
|
||||||
dlg->setAnimationsEnabled(dlg->isVisible());
|
dlg->setAnimationsEnabled(dlg->isVisible());
|
||||||
dlg->show();
|
dlg->show();
|
||||||
@ -167,6 +177,10 @@ void ToolTip::setMainText(const QString &mainText)
|
|||||||
|
|
||||||
m_mainText = mainText;
|
m_mainText = mainText;
|
||||||
emit mainTextChanged();
|
emit mainTextChanged();
|
||||||
|
|
||||||
|
if (!isValid() && s_dialog && s_dialog->owner() == this) {
|
||||||
|
s_dialog->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ToolTip::subText() const
|
QString ToolTip::subText() const
|
||||||
@ -182,6 +196,10 @@ void ToolTip::setSubText(const QString &subText)
|
|||||||
|
|
||||||
m_subText = subText;
|
m_subText = subText;
|
||||||
emit subTextChanged();
|
emit subTextChanged();
|
||||||
|
|
||||||
|
if (!isValid() && s_dialog && s_dialog->owner() == this) {
|
||||||
|
s_dialog->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ToolTip::textFormat() const
|
int ToolTip::textFormat() const
|
||||||
@ -305,9 +323,10 @@ void ToolTip::hoverEnterEvent(QHoverEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_mainItem && mainText().isEmpty() && subText().isEmpty()) {
|
if (!isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tooltipDialogInstance()->isVisible()) {
|
if (tooltipDialogInstance()->isVisible()) {
|
||||||
// We signal the tooltipmanager that we're "potentially interested,
|
// We signal the tooltipmanager that we're "potentially interested,
|
||||||
// and ask to keep it open for a bit, so other items get the chance
|
// 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);
|
return QQuickItem::childMouseEventFilter(item, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToolTip::isValid() const
|
||||||
|
{
|
||||||
|
return m_mainItem || !mainText().isEmpty() || !subText().isEmpty();
|
||||||
|
}
|
||||||
|
@ -193,6 +193,8 @@ private Q_SLOTS:
|
|||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
bool m_tooltipsEnabledGlobally;
|
bool m_tooltipsEnabledGlobally;
|
||||||
bool m_containsMouse;
|
bool m_containsMouse;
|
||||||
|
@ -32,7 +32,8 @@ ToolTipDialog::ToolTipDialog(QQuickItem *parent)
|
|||||||
m_animation(0),
|
m_animation(0),
|
||||||
m_hideTimeout(4000),
|
m_hideTimeout(4000),
|
||||||
m_interactive(false),
|
m_interactive(false),
|
||||||
m_animationsEnabled(true)
|
m_animationsEnabled(true),
|
||||||
|
m_owner(Q_NULLPTR)
|
||||||
{
|
{
|
||||||
setFlags(Qt::ToolTip | Qt::BypassWindowManagerHint);
|
setFlags(Qt::ToolTip | Qt::BypassWindowManagerHint);
|
||||||
setLocation(Plasma::Types::Floating);
|
setLocation(Plasma::Types::Floating);
|
||||||
@ -147,6 +148,16 @@ void ToolTipDialog::setAnimationsEnabled(bool enabled)
|
|||||||
m_animationsEnabled = enabled;
|
m_animationsEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject *ToolTipDialog::owner() const
|
||||||
|
{
|
||||||
|
return m_owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolTipDialog::setOwner(QObject *owner)
|
||||||
|
{
|
||||||
|
m_owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
void ToolTipDialog::dismiss()
|
void ToolTipDialog::dismiss()
|
||||||
{
|
{
|
||||||
m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms
|
m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms
|
||||||
|
@ -66,6 +66,12 @@ public:
|
|||||||
bool animationsEnabled() const;
|
bool animationsEnabled() const;
|
||||||
void setAnimationsEnabled(bool enabled);
|
void setAnimationsEnabled(bool enabled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basically the last one who has shown the dialog
|
||||||
|
*/
|
||||||
|
QObject *owner() const;
|
||||||
|
void setOwner(QObject *owner);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
|
void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
|
||||||
void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
|
void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
|
||||||
@ -82,6 +88,7 @@ private:
|
|||||||
int m_hideTimeout;
|
int m_hideTimeout;
|
||||||
bool m_interactive;
|
bool m_interactive;
|
||||||
bool m_animationsEnabled;
|
bool m_animationsEnabled;
|
||||||
|
QObject *m_owner;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user