Record which tooltip is being shown so that tooltip data updates don't change

which to another widget's tooltip.

BUG: 154719

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=754590
This commit is contained in:
Jason Stubbs 2007-12-30 10:17:33 +00:00
parent 2e58716f0c
commit f3e52b76cb
3 changed files with 23 additions and 12 deletions

View File

@ -34,6 +34,7 @@ class ToolTip::Private
Private()
: label(0)
, imageLabel(0)
, currentWidget(0)
, isShown(false)
, showTimer(0)
, hideTimer(0)
@ -41,6 +42,7 @@ class ToolTip::Private
QLabel *label;
QLabel *imageLabel;
Plasma::Widget *currentWidget;
bool isShown;
QTimer *showTimer;
QTimer *hideTimer;
@ -58,9 +60,10 @@ ToolTip *ToolTip::instance()
return &privateInstance->self;
}
void ToolTip::show(const QPoint &location, const Plasma::ToolTipData &data)
void ToolTip::show(const QPoint &location, Plasma::Widget *widget)
{
setData(data);
d->currentWidget = widget;
setData(widget->toolTip());
move(location.x(), location.y() - sizeHint().height());
if (d->isShown) {
// Don't delay if the tooltip is already shown(i.e. moving from one task to another)
@ -68,14 +71,14 @@ void ToolTip::show(const QPoint &location, const Plasma::ToolTipData &data)
// immediately show it again
setVisible(false);
d->showTimer->start(0);
}
else {
} else {
d->showTimer->start(1000); //Shown after a one second delay.
}
}
void ToolTip::hide()
{
d->currentWidget = 0;
d->showTimer->stop(); //Mouse out, stop the timer to show the tooltip
if (!isVisible()) {
d->isShown = false;
@ -84,6 +87,11 @@ void ToolTip::hide()
d->hideTimer->start(500); //500 ms delay before we are officially "gone" to allow for the time to move between widgets
}
Plasma::Widget *ToolTip::currentWidget() const
{
return d->currentWidget;
}
//PRIVATE FUNCTIONS
void ToolTip::slotShowToolTip()
{

View File

@ -44,9 +44,11 @@ public:
~ToolTip();
static ToolTip *instance();
void show(const QPoint &location, const Plasma::ToolTipData &data);
void show(const QPoint &location, Plasma::Widget *widget);
void hide();
Plasma::Widget *currentWidget() const;
private Q_SLOTS:
void slotResetTimer();
void slotShowToolTip();

View File

@ -498,10 +498,10 @@ ToolTipData Widget::toolTip() const
void Widget::setToolTip(const ToolTipData &tip)
{
d->toolTip = tip;
if (ToolTip::instance()->isVisible()) {
if (ToolTip::instance()->currentWidget() == this) {
QPoint viewPos = view()->mapFromScene(scenePos());
QPoint globalPos = view()->mapToGlobal(viewPos);
ToolTip::instance()->show(globalPos, d->toolTip);
ToolTip::instance()->show(globalPos, this);
}
}
@ -557,9 +557,6 @@ void Widget::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
return; //Nothing to show
}
if (view()->mouseGrabber()) {
return; // Someone has the mouse (eg. a context menu)
}
// If the mouse is in the widget's area at the time that it is being created
// the widget can receive a hover event before it is fully initialized, in
@ -570,9 +567,13 @@ void Widget::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
return;
}
if (parentView->mouseGrabber()) {
return; // Someone has the mouse (eg. a context menu)
}
QPoint viewPos = parentView->mapFromScene(scenePos());
QPoint globalPos = parentView->mapToGlobal(viewPos);
ToolTip::instance()->show(globalPos, d->toolTip);
ToolTip::instance()->show(globalPos, this);
}
void Widget::hoverLeaveEvent(QGraphicsSceneHoverEvent *e)