From fae76869af5b3abfdc46b8bd86900bb35206ad41 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 21 Oct 2008 01:58:01 +0000 Subject: [PATCH] * make it possible to activate/deactivate/inhibit tooltips globally * delete all the tips; not an important leak as it only gets destroyed on app close, but still... svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=874248 --- tooltipmanager.cpp | 49 +++++++++++++++++++++++++++++++++++++++++----- tooltipmanager.h | 18 +++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/tooltipmanager.cpp b/tooltipmanager.cpp index 4686e5e5f..9679847a3 100644 --- a/tooltipmanager.cpp +++ b/tooltipmanager.cpp @@ -55,14 +55,16 @@ public : : currentWidget(0), showTimer(0), hideTimer(0), + state(ToolTipManager::Activated), isShown(false), delayedHide(false) { } + ~ToolTipManagerPrivate() { - + clearTips(); } void showToolTip(); @@ -77,10 +79,13 @@ public : */ void onWidgetDestroyed(QObject * object); + void clearTips(); + QGraphicsWidget *currentWidget; QTimer *showTimer; QTimer *hideTimer; QHash tooltips; + ToolTipManager::State state; bool isShown : 1; bool delayedHide : 1; }; @@ -186,7 +191,7 @@ void ToolTipManager::hide(QGraphicsWidget *widget) void ToolTipManager::registerWidget(QGraphicsWidget *widget) { - if (d->tooltips.contains(widget)) { + if (d->state == Deactivated || d->tooltips.contains(widget)) { return; } @@ -212,6 +217,10 @@ void ToolTipManager::unregisterWidget(QGraphicsWidget *widget) void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &data) { + if (d->state == Deactivated) { + return; + } + registerWidget(widget); ToolTip *tooltip = d->tooltips.value(widget); @@ -233,6 +242,27 @@ void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &d tooltip->updateTheme(); } +void ToolTipManager::setState(ToolTipManager::State state) +{ + d->state = state; + + switch (state) { + case Activated: + break; + case Deactivated: + d->clearTips(); + //fallthrough + case Inhibited: + d->resetShownState(); + break; + } +} + +ToolTipManager::State ToolTipManager::state() const +{ + return d->state; +} + void ToolTipManagerPrivate::themeUpdated() { QHashIterator iterator(tooltips); @@ -282,6 +312,15 @@ void ToolTipManagerPrivate::onWidgetDestroyed(QObject *object) } } +void ToolTipManagerPrivate::clearTips() +{ + foreach (ToolTip *tip, tooltips) { + delete tip; + } + + tooltips.clear(); +} + void ToolTipManagerPrivate::resetShownState() { if (currentWidget) { @@ -292,13 +331,13 @@ void ToolTipManagerPrivate::resetShownState() isShown = false; tooltip->hide(); currentWidget = 0; - } + } } } void ToolTipManagerPrivate::showToolTip() { - if (!currentWidget) { + if (state != ToolTipManager::Activated || !currentWidget) { return; } @@ -329,7 +368,7 @@ void ToolTipManagerPrivate::showToolTip() bool ToolTipManager::eventFilter(QObject *watched, QEvent *event) { QGraphicsWidget * widget = dynamic_cast(watched); - if (!widget) { + if (d->state != Activated || !widget) { return QObject::eventFilter(watched, event); } diff --git a/tooltipmanager.h b/tooltipmanager.h index d9b599a40..ce6f708f9 100644 --- a/tooltipmanager.h +++ b/tooltipmanager.h @@ -67,6 +67,12 @@ class PLASMA_EXPORT ToolTipManager : public QObject Q_OBJECT public: + enum State { + Activated = 0 /**<< Will accept tooltip data and show tooltips */, + Inhibited /**<< Will accept tooltip data, but not show tooltips */, + Deactivated /**<< Will discard tooltip data, and not attempt to show them */ + }; + /** * @struct ToolTipContent plasma/tooltipmanager.h * @@ -168,6 +174,18 @@ public: void setContent(QGraphicsWidget *widget, const ToolTipContent &data = ToolTipContent()); + /** + * Sets the current state of the manager. + * @see State + * @arg state the state to put the manager in + */ + void setState(ToolTipManager::State state); + + /** + * @return the current state of the manager; @see State + */ + ToolTipManager::State state() const; + private: /** * Default constructor.