2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com>
|
|
|
|
* Copyright 2008 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 by Alexis Ménard <darktears31@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tooltipmanager.h"
|
|
|
|
|
|
|
|
//Qt
|
2008-11-10 03:01:47 +01:00
|
|
|
#include <QCoreApplication>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QGraphicsView>
|
2009-09-22 20:31:36 +02:00
|
|
|
#include <QGraphicsSceneHoverEvent>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//KDE
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kwindowsystem.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//X11
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
#include <QtGui/QX11Info>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <fixx11h.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//Plasma
|
2008-12-30 03:14:33 +01:00
|
|
|
#include "plasma/applet.h"
|
|
|
|
#include "plasma/containment.h"
|
|
|
|
#include "plasma/corona.h"
|
|
|
|
#include "plasma/framesvg.h"
|
|
|
|
#include "plasma/popupapplet.h"
|
|
|
|
#include "plasma/theme.h"
|
|
|
|
#include "plasma/view.h"
|
|
|
|
#include "plasma/private/tooltip_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class ToolTipManagerPrivate
|
|
|
|
{
|
|
|
|
public :
|
2009-06-02 19:12:35 +02:00
|
|
|
ToolTipManagerPrivate(ToolTipManager *manager)
|
|
|
|
: q(manager),
|
|
|
|
currentWidget(0),
|
2010-06-11 19:18:34 +02:00
|
|
|
showTimer(new QTimer(manager)),
|
|
|
|
hideTimer(new QTimer(manager)),
|
2010-09-23 03:04:45 +02:00
|
|
|
tipWidget(0),
|
2008-11-04 00:08:39 +01:00
|
|
|
state(ToolTipManager::Activated),
|
|
|
|
isShown(false),
|
2009-06-26 08:40:15 +02:00
|
|
|
delayedHide(false),
|
|
|
|
clickable(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~ToolTipManagerPrivate()
|
|
|
|
{
|
2008-11-10 03:01:47 +01:00
|
|
|
if (!QCoreApplication::closingDown()) {
|
|
|
|
delete tipWidget;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void showToolTip();
|
|
|
|
void resetShownState();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called when a widget inside the tooltip manager is deleted
|
|
|
|
*/
|
|
|
|
void onWidgetDestroyed(QObject * object);
|
2009-06-26 08:40:15 +02:00
|
|
|
void removeWidget(QGraphicsWidget *w, bool canSafelyAccess = true);
|
2008-11-04 00:08:39 +01:00
|
|
|
void clearTips();
|
|
|
|
void doDelayedHide();
|
2009-06-26 08:40:15 +02:00
|
|
|
void toolTipHovered(bool);
|
2010-09-23 03:04:45 +02:00
|
|
|
void createTipWidget();
|
|
|
|
void hideTipWidget();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-06-02 19:12:35 +02:00
|
|
|
ToolTipManager *q;
|
2008-11-04 00:08:39 +01:00
|
|
|
QGraphicsWidget *currentWidget;
|
|
|
|
QTimer *showTimer;
|
|
|
|
QTimer *hideTimer;
|
|
|
|
QHash<QGraphicsWidget *, ToolTipContent> tooltips;
|
|
|
|
ToolTip *tipWidget;
|
|
|
|
ToolTipManager::State state;
|
|
|
|
bool isShown : 1;
|
|
|
|
bool delayedHide : 1;
|
2009-06-26 08:40:15 +02:00
|
|
|
bool clickable : 1;
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//TOOLTIP IMPLEMENTATION
|
|
|
|
class ToolTipManagerSingleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ToolTipManagerSingleton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
ToolTipManager self;
|
|
|
|
};
|
|
|
|
K_GLOBAL_STATIC(ToolTipManagerSingleton, privateInstance)
|
|
|
|
|
|
|
|
ToolTipManager *ToolTipManager::self()
|
|
|
|
{
|
|
|
|
return &privateInstance->self;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTipManager::ToolTipManager(QObject *parent)
|
|
|
|
: QObject(parent),
|
2009-06-02 19:12:35 +02:00
|
|
|
d(new ToolTipManagerPrivate(this)),
|
|
|
|
m_corona(0)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
d->showTimer->setSingleShot(true);
|
|
|
|
connect(d->showTimer, SIGNAL(timeout()), SLOT(showToolTip()));
|
2010-06-11 19:18:34 +02:00
|
|
|
|
|
|
|
d->hideTimer->setSingleShot(true);
|
2008-11-04 00:08:39 +01:00
|
|
|
connect(d->hideTimer, SIGNAL(timeout()), SLOT(resetShownState()));
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTipManager::~ToolTipManager()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManager::show(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
if (!d->tooltips.contains(widget)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-06 22:42:46 +01:00
|
|
|
d->delayedHide = false;
|
|
|
|
d->hideTimer->stop();
|
|
|
|
d->showTimer->stop();
|
|
|
|
const int defaultDelay = Theme::defaultTheme()->toolTipDelay();
|
2011-04-26 20:43:40 +02:00
|
|
|
|
2011-12-06 22:42:46 +01:00
|
|
|
if (defaultDelay < 0) {
|
|
|
|
return;
|
2010-05-07 02:18:40 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 22:42:46 +01:00
|
|
|
ToolTipContent content = d->tooltips[widget];
|
|
|
|
qreal delay = content.isInstantPopup() ? 0.0 : defaultDelay;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->currentWidget = widget;
|
|
|
|
|
|
|
|
if (d->isShown) {
|
|
|
|
// small delay to prevent unnecessary showing when the mouse is moving quickly across items
|
|
|
|
// which can be too much for less powerful CPUs to keep up with
|
|
|
|
d->showTimer->start(200);
|
|
|
|
} else {
|
2010-05-07 02:18:40 +02:00
|
|
|
d->showTimer->start(delay * 1000);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToolTipManager::isVisible(QGraphicsWidget *widget) const
|
|
|
|
{
|
2010-09-23 03:04:45 +02:00
|
|
|
return d->currentWidget == widget && d->tipWidget && d->tipWidget->isVisible();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManagerPrivate::doDelayedHide()
|
|
|
|
{
|
|
|
|
showTimer->stop(); // stop the timer to show the tooltip
|
|
|
|
delayedHide = true;
|
2009-06-26 08:40:15 +02:00
|
|
|
|
|
|
|
if (isShown && clickable) {
|
|
|
|
// leave enough time for user to choose
|
|
|
|
hideTimer->start(1000);
|
|
|
|
} else {
|
|
|
|
hideTimer->start(250);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManager::hide(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
if (d->currentWidget != widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-01 01:49:36 +01:00
|
|
|
d->currentWidget = 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
d->showTimer->stop(); // stop the timer to show the tooltip
|
|
|
|
d->delayedHide = false;
|
2010-09-23 03:04:45 +02:00
|
|
|
d->hideTipWidget();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManager::registerWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
if (d->state == Deactivated || d->tooltips.contains(widget)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//the tooltip is not registered we add it in our map of tooltips
|
|
|
|
d->tooltips.insert(widget, ToolTipContent());
|
|
|
|
widget->installEventFilter(this);
|
|
|
|
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(onWidgetDestroyed(QObject*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManager::unregisterWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
if (!d->tooltips.contains(widget)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-06 22:42:46 +01:00
|
|
|
if (widget == d->currentWidget) {
|
|
|
|
d->currentWidget = 0;
|
|
|
|
d->showTimer->stop(); // stop the timer to show the tooltip
|
|
|
|
d->delayedHide = false;
|
|
|
|
d->hideTipWidget();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
widget->removeEventFilter(this);
|
2009-01-09 02:15:39 +01:00
|
|
|
d->removeWidget(widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &data)
|
|
|
|
{
|
2009-06-02 19:12:35 +02:00
|
|
|
if (d->state == Deactivated || !widget) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
registerWidget(widget);
|
2009-06-02 19:12:35 +02:00
|
|
|
d->tooltips.insert(widget, data);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-09-23 03:04:45 +02:00
|
|
|
if (d->currentWidget == widget && d->tipWidget && d->tipWidget->isVisible()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
if (data.isEmpty()) {
|
2010-10-08 13:33:48 +02:00
|
|
|
// after this call, d->tipWidget will be null
|
2008-11-04 00:08:39 +01:00
|
|
|
hide(widget);
|
2008-12-26 21:43:53 +01:00
|
|
|
} else {
|
|
|
|
d->delayedHide = data.autohide();
|
2009-06-26 08:40:15 +02:00
|
|
|
d->clickable = data.isClickable();
|
2008-12-26 21:43:53 +01:00
|
|
|
if (d->delayedHide) {
|
|
|
|
//kDebug() << "starting authoide";
|
|
|
|
d->hideTimer->start(3000);
|
|
|
|
} else {
|
|
|
|
d->hideTimer->stop();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-10-08 13:33:48 +02:00
|
|
|
if (d->tipWidget) {
|
|
|
|
d->tipWidget->setContent(widget, data);
|
|
|
|
d->tipWidget->prepareShowing();
|
2010-08-18 18:33:32 +02:00
|
|
|
|
2011-07-30 20:18:07 +02:00
|
|
|
//look if the data prefers aother graphicswidget, otherwise use the one used as event catcher
|
|
|
|
QGraphicsWidget *referenceWidget = data.graphicsWidget() ? data.graphicsWidget() : widget;
|
|
|
|
Corona *corona = qobject_cast<Corona *>(referenceWidget->scene());
|
2011-12-02 19:01:46 +01:00
|
|
|
if (!corona) {
|
|
|
|
// fallback to the corona we were given
|
|
|
|
corona = m_corona;
|
|
|
|
}
|
|
|
|
|
2011-07-30 20:18:07 +02:00
|
|
|
if (corona) {
|
|
|
|
d->tipWidget->moveTo(corona->popupPosition(referenceWidget, d->tipWidget->size(), Qt::AlignCenter));
|
2010-10-08 13:33:48 +02:00
|
|
|
}
|
2009-06-02 19:12:35 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManager::clearContent(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
setContent(widget, ToolTipContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-23 03:04:45 +02:00
|
|
|
void ToolTipManagerPrivate::createTipWidget()
|
|
|
|
{
|
|
|
|
if (tipWidget) {
|
|
|
|
return;
|
|
|
|
}
|
2010-09-24 20:14:29 +02:00
|
|
|
|
2010-09-23 03:04:45 +02:00
|
|
|
tipWidget = new ToolTip(0);
|
|
|
|
QObject::connect(tipWidget, SIGNAL(activateWindowByWId(WId,Qt::MouseButtons,Qt::KeyboardModifiers,QPoint)),
|
|
|
|
q, SIGNAL(windowPreviewActivated(WId,Qt::MouseButtons,Qt::KeyboardModifiers,QPoint)));
|
|
|
|
QObject::connect(tipWidget, SIGNAL(linkActivated(QString,Qt::MouseButtons,Qt::KeyboardModifiers,QPoint)),
|
|
|
|
q, SIGNAL(linkActivated(QString,Qt::MouseButtons,Qt::KeyboardModifiers,QPoint)));
|
|
|
|
QObject::connect(tipWidget, SIGNAL(hovered(bool)), q, SLOT(toolTipHovered(bool)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManagerPrivate::hideTipWidget()
|
|
|
|
{
|
|
|
|
if (tipWidget) {
|
|
|
|
tipWidget->hide();
|
2010-09-24 20:14:29 +02:00
|
|
|
tipWidget->deleteLater();
|
2010-09-23 03:04:45 +02:00
|
|
|
tipWidget = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void ToolTipManagerPrivate::onWidgetDestroyed(QObject *object)
|
|
|
|
{
|
|
|
|
if (!object) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we do a static_cast here since it really isn't a QGraphicsWidget by this
|
|
|
|
// point anymore since we are in the QObject dtor. we don't actually
|
|
|
|
// try and do anything with it, we just need the value of the pointer
|
|
|
|
// so this unsafe looking code is actually just fine.
|
|
|
|
//
|
|
|
|
// NOTE: DO NOT USE THE w VARIABLE FOR ANYTHING OTHER THAN COMPARING
|
|
|
|
// THE ADDRESS! ACTUALLY USING THE OBJECT WILL RESULT IN A CRASH!!!
|
|
|
|
QGraphicsWidget *w = static_cast<QGraphicsWidget*>(object);
|
2009-06-26 08:40:15 +02:00
|
|
|
removeWidget(w, false);
|
2009-01-09 02:15:39 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-06-26 08:40:15 +02:00
|
|
|
void ToolTipManagerPrivate::removeWidget(QGraphicsWidget *w, bool canSafelyAccess)
|
2009-01-09 02:15:39 +01:00
|
|
|
{
|
2009-06-26 08:40:15 +02:00
|
|
|
if (currentWidget == w && currentWidget) {
|
2008-11-04 00:08:39 +01:00
|
|
|
currentWidget = 0;
|
|
|
|
showTimer->stop(); // stop the timer to show the tooltip
|
2010-09-23 03:04:45 +02:00
|
|
|
hideTipWidget();
|
2008-11-04 00:08:39 +01:00
|
|
|
delayedHide = false;
|
|
|
|
}
|
|
|
|
|
2010-07-29 05:26:06 +02:00
|
|
|
if (w && canSafelyAccess) {
|
|
|
|
QObject::disconnect(q, 0, w, 0);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
tooltips.remove(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManagerPrivate::clearTips()
|
|
|
|
{
|
|
|
|
tooltips.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManagerPrivate::resetShownState()
|
|
|
|
{
|
2011-12-06 22:42:46 +01:00
|
|
|
if (!tipWidget || !tipWidget->isVisible() || delayedHide) {
|
|
|
|
//One might have moused out and back in again
|
|
|
|
showTimer->stop();
|
|
|
|
delayedHide = false;
|
|
|
|
isShown = false;
|
|
|
|
currentWidget = 0;
|
|
|
|
hideTipWidget();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipManagerPrivate::showToolTip()
|
|
|
|
{
|
|
|
|
if (state != ToolTipManager::Activated ||
|
|
|
|
!currentWidget ||
|
|
|
|
QApplication::activePopupWidget() ||
|
|
|
|
QApplication::activeModalWidget()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-30 03:14:33 +01:00
|
|
|
PopupApplet *popup = qobject_cast<PopupApplet*>(currentWidget);
|
|
|
|
if (popup && popup->isPopupShowing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-27 23:18:32 +01:00
|
|
|
if (currentWidget->metaObject()->indexOfMethod("toolTipAboutToShow()") != -1) {
|
|
|
|
// toolTipAboutToShow may call into methods such as setContent which play
|
|
|
|
// with the current widget; so let's just pretend for a moment that we don't have
|
|
|
|
// a current widget
|
|
|
|
QGraphicsWidget *temp = currentWidget;
|
|
|
|
currentWidget = 0;
|
|
|
|
QMetaObject::invokeMethod(temp, "toolTipAboutToShow");
|
|
|
|
currentWidget = temp;
|
|
|
|
}
|
2009-06-02 19:12:35 +02:00
|
|
|
|
2008-11-14 07:06:15 +01:00
|
|
|
QHash<QGraphicsWidget *, ToolTipContent>::const_iterator tooltip = tooltips.constFind(currentWidget);
|
|
|
|
|
2008-12-30 03:04:35 +01:00
|
|
|
if (tooltip == tooltips.constEnd() || tooltip.value().isEmpty()) {
|
2009-06-28 01:17:52 +02:00
|
|
|
if (isShown) {
|
|
|
|
delayedHide = true;
|
|
|
|
hideTimer->start(250);
|
|
|
|
}
|
|
|
|
|
2008-11-14 07:06:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-23 03:04:45 +02:00
|
|
|
createTipWidget();
|
|
|
|
|
2008-12-23 20:38:52 +01:00
|
|
|
Containment *c = dynamic_cast<Containment *>(currentWidget->topLevelItem());
|
2008-12-30 03:04:35 +01:00
|
|
|
//kDebug() << "about to show" << (QObject*)c;
|
2008-12-23 20:38:52 +01:00
|
|
|
if (c) {
|
2008-12-26 21:38:59 +01:00
|
|
|
tipWidget->setDirection(Plasma::locationToDirection(c->location()));
|
2008-12-23 20:38:52 +01:00
|
|
|
}
|
|
|
|
|
2009-06-26 08:40:15 +02:00
|
|
|
clickable = tooltip.value().isClickable();
|
2008-11-14 07:06:15 +01:00
|
|
|
tipWidget->setContent(currentWidget, tooltip.value());
|
2008-12-30 03:04:35 +01:00
|
|
|
tipWidget->prepareShowing();
|
2011-07-30 20:18:07 +02:00
|
|
|
QGraphicsWidget *referenceWidget = tooltip.value().graphicsWidget() ? tooltip.value().graphicsWidget() : currentWidget;
|
|
|
|
Corona *corona = qobject_cast<Corona *>(referenceWidget->scene());
|
2011-12-02 19:01:46 +01:00
|
|
|
if (!corona) {
|
|
|
|
// fallback to the corona we were given
|
|
|
|
corona = q->m_corona;
|
|
|
|
}
|
|
|
|
|
2011-07-30 20:18:07 +02:00
|
|
|
if (corona) {
|
|
|
|
tipWidget->moveTo(corona->popupPosition(referenceWidget, tipWidget->size(), Qt::AlignCenter));
|
2009-06-02 19:12:35 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
tipWidget->show();
|
|
|
|
isShown = true; //ToolTip is visible
|
|
|
|
|
2008-11-14 07:06:15 +01:00
|
|
|
delayedHide = tooltip.value().autohide();
|
2008-11-04 00:08:39 +01:00
|
|
|
if (delayedHide) {
|
|
|
|
//kDebug() << "starting authoide";
|
|
|
|
hideTimer->start(3000);
|
2008-12-26 21:43:53 +01:00
|
|
|
} else {
|
|
|
|
hideTimer->stop();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-26 08:40:15 +02:00
|
|
|
void ToolTipManagerPrivate::toolTipHovered(bool hovered)
|
|
|
|
{
|
|
|
|
if (!clickable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hovered) {
|
|
|
|
hideTimer->stop();
|
2009-06-26 12:00:16 +02:00
|
|
|
} else {
|
2009-06-26 08:40:15 +02:00
|
|
|
hideTimer->start(500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
bool ToolTipManager::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsWidget * widget = dynamic_cast<QGraphicsWidget *>(watched);
|
|
|
|
if (d->state != Activated || !widget) {
|
|
|
|
return QObject::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::GraphicsSceneHoverMove:
|
|
|
|
// If the tooltip isn't visible, run through showing the tooltip again
|
|
|
|
// so that it only becomes visible after a stationary hover
|
|
|
|
if (Plasma::ToolTipManager::self()->isVisible(widget)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't restart the show timer on a mouse move event if there hasn't
|
|
|
|
// been an enter event or the current widget has been cleared by a click
|
|
|
|
// or wheel event.
|
2009-09-22 20:31:36 +02:00
|
|
|
{
|
|
|
|
QGraphicsSceneHoverEvent *me = static_cast<QGraphicsSceneHoverEvent *>(event);
|
|
|
|
//FIXME: seems that wheel events generate hovermoves as well, with 0 delta
|
|
|
|
if (!d->currentWidget || (me->pos() == me->lastPos())) {
|
|
|
|
break;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case QEvent::GraphicsSceneHoverEnter:
|
|
|
|
{
|
|
|
|
// Check that there is a tooltip to show
|
|
|
|
if (!d->tooltips.contains(widget)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-05 19:48:44 +02:00
|
|
|
show(widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case QEvent::GraphicsSceneHoverLeave:
|
2009-06-26 08:40:15 +02:00
|
|
|
if (d->currentWidget == widget) {
|
|
|
|
d->doDelayedHide();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::GraphicsSceneMousePress:
|
2009-06-26 08:40:15 +02:00
|
|
|
if (d->currentWidget == widget) {
|
|
|
|
hide(widget);
|
|
|
|
}
|
|
|
|
break;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-04-16 05:52:35 +02:00
|
|
|
case QEvent::GraphicsSceneWheel:
|
2008-11-04 00:08:39 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QObject::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "tooltipmanager.moc"
|
|
|
|
|