From 384f31bf82b17dd6a43525902e3e50a919bd949a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9nard?= Date: Thu, 28 Aug 2008 20:23:39 +0000 Subject: [PATCH] add an activate method to specify if the tooltip has to be displayed or not. Use-case : Display it on demand, when hovering. ie Kickoff svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=854098 --- private/tooltip.cpp | 12 ++++++++++++ private/tooltip_p.h | 2 ++ tooltipmanager.cpp | 22 +++++++++++++++++++++- tooltipmanager.h | 13 +++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/private/tooltip.cpp b/private/tooltip.cpp index 5be4a028a..c22f5e45d 100644 --- a/private/tooltip.cpp +++ b/private/tooltip.cpp @@ -46,6 +46,7 @@ class ToolTipPrivate , preview(0) , windowToPreview(0) , source(s) + , isActivated(true) { } QLabel *label; @@ -54,6 +55,7 @@ class ToolTipPrivate WId windowToPreview; PanelSvg *background; QObject *source; + bool isActivated; }; void ToolTip::showEvent(QShowEvent *e) @@ -139,6 +141,16 @@ void ToolTip::prepareShowing() } +void ToolTip::setActivated(bool value) +{ + d->isActivated = value; +} + +bool ToolTip::isActivated() +{ + return d->isActivated; +} + void ToolTip::resizeEvent(QResizeEvent *e) { QWidget::resizeEvent(e); diff --git a/private/tooltip_p.h b/private/tooltip_p.h index 2b2743b75..9518fb3f9 100644 --- a/private/tooltip_p.h +++ b/private/tooltip_p.h @@ -40,6 +40,8 @@ public: void updateTheme(); void setContent(const ToolTipManager::ToolTipContent &data); void prepareShowing(); + void setActivated(bool value); + bool isActivated(); protected: void showEvent(QShowEvent *); diff --git a/tooltipmanager.cpp b/tooltipmanager.cpp index 60d55181e..3a0655d7f 100644 --- a/tooltipmanager.cpp +++ b/tooltipmanager.cpp @@ -233,6 +233,26 @@ bool ToolTipManager::widgetHasToolTip(QGraphicsWidget *widget) const return d->tooltips.contains(widget); } +void ToolTipManager::setToolTipActivated(QGraphicsWidget *widget, bool enable) +{ + if (!d->tooltips.contains(widget)) { + registerWidget(widget); + } + + ToolTip *tooltip = d->tooltips.value(widget); + tooltip->setActivated(enable); +} + +bool ToolTipManager::isToolTipActivated(QGraphicsWidget *widget) +{ + if (!d->tooltips.contains(widget)) { + registerWidget(widget); + } + + ToolTip *tooltip = d->tooltips.value(widget); + return tooltip->isActivated(); +} + void ToolTipManagerPrivate::themeUpdated() { QMapIterator iterator(tooltips); @@ -300,7 +320,7 @@ void ToolTipManagerPrivate::showToolTip() } ToolTip *tooltip = tooltips.value(currentWidget); - if (tooltip) { + if (tooltip && tooltip->isActivated()) { tooltip->setVisible(false); tooltip->prepareShowing(); tooltip->move(popupPosition(currentWidget, tooltip->size())); diff --git a/tooltipmanager.h b/tooltipmanager.h index 663e9a4be..fa95cc0a1 100644 --- a/tooltipmanager.h +++ b/tooltipmanager.h @@ -188,6 +188,19 @@ public: */ bool widgetHasToolTip(QGraphicsWidget *widget) const; + /** + * Enable/or disable a Tooltip, this method is usefull is we want + * to have a tooltip activated on demand. + * @param widget the widget to change tooltip behaviour + * @param enable if we need the tooltip or not + */ + void setToolTipActivated(QGraphicsWidget *widget, bool enable); + + /** + * Return true is the tooltip will be displayed, false otherwise + */ + bool isToolTipActivated(QGraphicsWidget *widget); + private: friend class ToolTipManagerSingleton; bool eventFilter(QObject *watched, QEvent *event);