Allow to get tooltips to popup instantly on hover

Add an "instant popup" property on ToolTipContent allowing to control
for a given tooltip to popup immediately when the corresponding widget
is hovered. The default is the usual behavior though.

The ToolTipManager behavior itself got adjusted to take care of the
instant popup flag.
This commit is contained in:
Kevin Ottens 2011-04-26 20:43:40 +02:00
parent 955137bf2f
commit 7fa4dff47b
3 changed files with 38 additions and 5 deletions

View File

@ -51,6 +51,7 @@ class ToolTipContentPrivate
public: public:
ToolTipContentPrivate() ToolTipContentPrivate()
: autohide(true), : autohide(true),
instantPopup(false),
clickable(false), clickable(false),
highlightWindows(false) highlightWindows(false)
{ {
@ -63,6 +64,7 @@ public:
QHash<QString, ToolTipResource> resources; QHash<QString, ToolTipResource> resources;
QWeakPointer<QGraphicsWidget> graphicsWidget; QWeakPointer<QGraphicsWidget> graphicsWidget;
bool autohide : 1; bool autohide : 1;
bool instantPopup : 1;
bool clickable : 1; bool clickable : 1;
bool highlightWindows : 1; bool highlightWindows : 1;
}; };
@ -200,6 +202,16 @@ bool ToolTipContent::autohide() const
return d->autohide; return d->autohide;
} }
void ToolTipContent::setInstantPopup(bool enabled)
{
d->instantPopup = enabled;
}
bool ToolTipContent::isInstantPopup() const
{
return d->instantPopup;
}
void ToolTipContent::addResource(ResourceType type, const QUrl &path, const QVariant &resource) void ToolTipContent::addResource(ResourceType type, const QUrl &path, const QVariant &resource)
{ {
d->resources.insert(path.toString(), ToolTipResource(type, resource)); d->resources.insert(path.toString(), ToolTipResource(type, resource));

View File

@ -166,6 +166,22 @@ public:
*/ */
bool autohide() const; bool autohide() const;
/**
* Sets whether or not the tooltip should popup instantly when
* the widget is hovered, defaults to false.
*
* @since 4.7
*/
void setInstantPopup(bool enabled);
/**
* Whether or not the tooltip should popup instantly when
* the widget is hovered, defaults to false.
*
* @since 4.7
*/
bool isInstantPopup() const;
/** /**
* Adds a resource that can then be referenced from the text elements * Adds a resource that can then be referenced from the text elements
* using rich text * using rich text

View File

@ -140,11 +140,16 @@ void ToolTipManager::show(QGraphicsWidget *widget)
return; return;
} }
KConfig config("plasmarc"); qreal delay = 0.0;
KConfigGroup cg(&config, "PlasmaToolTips"); ToolTipContent content = d->tooltips[widget];
qreal delay = cg.readEntry("Delay", qreal(0.7));
if (delay < 0) { if (!content.isInstantPopup()) {
return; KConfig config("plasmarc");
KConfigGroup cg(&config, "PlasmaToolTips");
delay = cg.readEntry("Delay", qreal(0.7));
if (delay < 0) {
return;
}
} }
d->hideTimer->stop(); d->hideTimer->stop();