diff --git a/widgets/tooltip.cpp b/widgets/tooltip.cpp index 37b5a0918..e84ffdcbe 100644 --- a/widgets/tooltip.cpp +++ b/widgets/tooltip.cpp @@ -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() { diff --git a/widgets/tooltip_p.h b/widgets/tooltip_p.h index 7aa4e4ea4..ace9d23f6 100644 --- a/widgets/tooltip_p.h +++ b/widgets/tooltip_p.h @@ -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(); diff --git a/widgets/widget.cpp b/widgets/widget.cpp index 450509566..e07f75ee7 100644 --- a/widgets/widget.cpp +++ b/widgets/widget.cpp @@ -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,10 +557,7 @@ 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 // which case view() will return 0. @@ -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)