* 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:
parent
7abb5164a5
commit
fae76869af
@ -55,14 +55,16 @@ public :
|
|||||||
: currentWidget(0),
|
: currentWidget(0),
|
||||||
showTimer(0),
|
showTimer(0),
|
||||||
hideTimer(0),
|
hideTimer(0),
|
||||||
|
state(ToolTipManager::Activated),
|
||||||
isShown(false),
|
isShown(false),
|
||||||
delayedHide(false)
|
delayedHide(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ToolTipManagerPrivate()
|
~ToolTipManagerPrivate()
|
||||||
{
|
{
|
||||||
|
clearTips();
|
||||||
}
|
}
|
||||||
|
|
||||||
void showToolTip();
|
void showToolTip();
|
||||||
@ -77,10 +79,13 @@ public :
|
|||||||
*/
|
*/
|
||||||
void onWidgetDestroyed(QObject * object);
|
void onWidgetDestroyed(QObject * object);
|
||||||
|
|
||||||
|
void clearTips();
|
||||||
|
|
||||||
QGraphicsWidget *currentWidget;
|
QGraphicsWidget *currentWidget;
|
||||||
QTimer *showTimer;
|
QTimer *showTimer;
|
||||||
QTimer *hideTimer;
|
QTimer *hideTimer;
|
||||||
QHash<QGraphicsWidget *, ToolTip *> tooltips;
|
QHash<QGraphicsWidget *, ToolTip *> tooltips;
|
||||||
|
ToolTipManager::State state;
|
||||||
bool isShown : 1;
|
bool isShown : 1;
|
||||||
bool delayedHide : 1;
|
bool delayedHide : 1;
|
||||||
};
|
};
|
||||||
@ -186,7 +191,7 @@ void ToolTipManager::hide(QGraphicsWidget *widget)
|
|||||||
|
|
||||||
void ToolTipManager::registerWidget(QGraphicsWidget *widget)
|
void ToolTipManager::registerWidget(QGraphicsWidget *widget)
|
||||||
{
|
{
|
||||||
if (d->tooltips.contains(widget)) {
|
if (d->state == Deactivated || d->tooltips.contains(widget)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +217,10 @@ void ToolTipManager::unregisterWidget(QGraphicsWidget *widget)
|
|||||||
|
|
||||||
void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &data)
|
void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &data)
|
||||||
{
|
{
|
||||||
|
if (d->state == Deactivated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
registerWidget(widget);
|
registerWidget(widget);
|
||||||
|
|
||||||
ToolTip *tooltip = d->tooltips.value(widget);
|
ToolTip *tooltip = d->tooltips.value(widget);
|
||||||
@ -233,6 +242,27 @@ void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &d
|
|||||||
tooltip->updateTheme();
|
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()
|
void ToolTipManagerPrivate::themeUpdated()
|
||||||
{
|
{
|
||||||
QHashIterator<QGraphicsWidget*, ToolTip *> iterator(tooltips);
|
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()
|
void ToolTipManagerPrivate::resetShownState()
|
||||||
{
|
{
|
||||||
if (currentWidget) {
|
if (currentWidget) {
|
||||||
@ -292,13 +331,13 @@ void ToolTipManagerPrivate::resetShownState()
|
|||||||
isShown = false;
|
isShown = false;
|
||||||
tooltip->hide();
|
tooltip->hide();
|
||||||
currentWidget = 0;
|
currentWidget = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManagerPrivate::showToolTip()
|
void ToolTipManagerPrivate::showToolTip()
|
||||||
{
|
{
|
||||||
if (!currentWidget) {
|
if (state != ToolTipManager::Activated || !currentWidget) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +368,7 @@ void ToolTipManagerPrivate::showToolTip()
|
|||||||
bool ToolTipManager::eventFilter(QObject *watched, QEvent *event)
|
bool ToolTipManager::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
QGraphicsWidget * widget = dynamic_cast<QGraphicsWidget *>(watched);
|
QGraphicsWidget * widget = dynamic_cast<QGraphicsWidget *>(watched);
|
||||||
if (!widget) {
|
if (d->state != Activated || !widget) {
|
||||||
return QObject::eventFilter(watched, event);
|
return QObject::eventFilter(watched, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,12 @@ class PLASMA_EXPORT ToolTipManager : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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>
|
* @struct ToolTipContent plasma/tooltipmanager.h <Plasma/ToolTipManager>
|
||||||
*
|
*
|
||||||
@ -168,6 +174,18 @@ public:
|
|||||||
void setContent(QGraphicsWidget *widget,
|
void setContent(QGraphicsWidget *widget,
|
||||||
const ToolTipContent &data = ToolTipContent());
|
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:
|
private:
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
|
Loading…
Reference in New Issue
Block a user