* ensure we only ever call the about to show method once

* attempt to tip if the widget is registered, even if it has no tip associated with it

this allows for 100% on-demand tips; important as some of our tips are expensive

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=862469
This commit is contained in:
Aaron J. Seigo 2008-09-18 21:55:09 +00:00
parent 832782fa73
commit 15da8e1555

View File

@ -54,11 +54,11 @@ class ToolTipManagerPrivate
{ {
public : public :
ToolTipManagerPrivate() ToolTipManagerPrivate()
: currentWidget(0) : currentWidget(0),
, isShown(false) showTimer(0),
, delayedHide(false) hideTimer(0),
, showTimer(0) isShown(false),
, hideTimer(0) delayedHide(false)
{ {
} }
@ -81,11 +81,11 @@ public :
QGraphicsWidget *currentWidget; QGraphicsWidget *currentWidget;
bool isShown;
bool delayedHide;
QTimer *showTimer; QTimer *showTimer;
QTimer *hideTimer; QTimer *hideTimer;
QHash<QGraphicsWidget *, ToolTip *> tooltips; QHash<QGraphicsWidget *, ToolTip *> tooltips;
bool isShown : 1;
bool delayedHide : 1;
}; };
//TOOLTIP IMPLEMENTATION //TOOLTIP IMPLEMENTATION
@ -137,15 +137,19 @@ ToolTipManager::~ToolTipManager()
void ToolTipManager::showToolTip(QGraphicsWidget *widget) void ToolTipManager::showToolTip(QGraphicsWidget *widget)
{ {
ToolTip *tooltip = d->tooltips.value(widget); if (!d->tooltips.contains(widget)) {
if (tooltip) { return;
}
if (d->currentWidget) { if (d->currentWidget) {
hideToolTip(d->currentWidget); hideToolTip(d->currentWidget);
} }
d->hideTimer->stop(); d->hideTimer->stop();
d->delayedHide = false; d->delayedHide = false;
d->showTimer->stop(); d->showTimer->stop();
d->currentWidget = widget; d->currentWidget = widget;
if (d->isShown) { if (d->isShown) {
// small delay to prevent unnecessary showing when the mouse is moving quickly across items // small delay to prevent unnecessary showing when the mouse is moving quickly across items
// which can be too much for less powerful CPUs to keep up with // which can be too much for less powerful CPUs to keep up with
@ -153,7 +157,6 @@ void ToolTipManager::showToolTip(QGraphicsWidget *widget)
} else { } else {
d->showTimer->start(500); d->showTimer->start(500);
} }
}
} }
bool ToolTipManager::isWidgetToolTipDisplayed(QGraphicsWidget *widget) bool ToolTipManager::isWidgetToolTipDisplayed(QGraphicsWidget *widget)
@ -205,7 +208,9 @@ void ToolTipManager::unregisterWidget(QGraphicsWidget *widget)
widget->removeEventFilter(this); widget->removeEventFilter(this);
ToolTip *tooltip = d->tooltips.take(widget); ToolTip *tooltip = d->tooltips.take(widget);
delete tooltip; if (tooltip) {
tooltip->deleteLater();
}
} }
void ToolTipManager::setToolTipContent(QGraphicsWidget *widget, const ToolTipContent &data) void ToolTipManager::setToolTipContent(QGraphicsWidget *widget, const ToolTipContent &data)
@ -215,7 +220,9 @@ void ToolTipManager::setToolTipContent(QGraphicsWidget *widget, const ToolTipCon
ToolTip *tooltip = d->tooltips.value(widget); ToolTip *tooltip = d->tooltips.value(widget);
if (data.isEmpty()) { if (data.isEmpty()) {
delete tooltip; if (tooltip) {
tooltip->deleteLater();
}
d->tooltips.insert(widget, 0); d->tooltips.insert(widget, 0);
return; return;
} }
@ -299,7 +306,7 @@ void ToolTipManagerPrivate::onWidgetDestroyed(QObject *object)
if (tooltip) { if (tooltip) {
//kDebug() << "deleting the tooltip!"; //kDebug() << "deleting the tooltip!";
tooltip->hide(); tooltip->hide();
delete tooltip; tooltip->deleteLater();
} }
return; return;
} }
@ -327,9 +334,24 @@ void ToolTipManagerPrivate::showToolTip()
} }
ToolTip *tooltip = tooltips.value(currentWidget); ToolTip *tooltip = tooltips.value(currentWidget);
if (tooltip && tooltip->isActivated()) { bool justCreated = false;
if (!tooltip) {
// give the object a chance for delayed loading of the tip
QMetaObject::invokeMethod(currentWidget, "toolTipAboutToShow");
tooltip = tooltips.value(currentWidget);
if (tooltip) {
justCreated = true;
} else {
currentWidget = 0;
return;
}
}
if (tooltip->isActivated()) {
tooltip->setVisible(false); tooltip->setVisible(false);
tooltip->prepareShowing(); //kDebug() << "about to show" << justCreated;
tooltip->prepareShowing(!justCreated);
tooltip->move(popupPosition(currentWidget, tooltip->size())); tooltip->move(popupPosition(currentWidget, tooltip->size()));
isShown = true; //ToolTip is visible isShown = true; //ToolTip is visible
tooltip->setVisible(true); tooltip->setVisible(true);