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
This commit is contained in:
Alexis Ménard 2008-08-28 20:23:39 +00:00
parent 5f1f8a5d1f
commit 384f31bf82
4 changed files with 48 additions and 1 deletions

View File

@ -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);

View File

@ -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 *);

View File

@ -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<QGraphicsWidget*, ToolTip *> 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()));

View File

@ -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);