* 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
This commit is contained in:
Aaron J. Seigo 2008-10-21 01:58:01 +00:00
parent 7abb5164a5
commit fae76869af
2 changed files with 62 additions and 5 deletions

View File

@ -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<QGraphicsWidget *, ToolTip *> 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<QGraphicsWidget*, ToolTip *> 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<QGraphicsWidget *>(watched);
if (!widget) {
if (d->state != Activated || !widget) {
return QObject::eventFilter(watched, event);
}

View File

@ -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 <Plasma/ToolTipManager>
*
@ -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.