Install event filter is better than reimplement sceneEvent.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=833521
This commit is contained in:
parent
92c7ffc9df
commit
24d494fd5a
43
applet.cpp
43
applet.cpp
@ -1382,49 +1382,6 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
|||||||
return QGraphicsWidget::itemChange(change, value);
|
return QGraphicsWidget::itemChange(change, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Applet::sceneEvent(QEvent *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()->isWidgetToolTipDisplayed(this)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QEvent::GraphicsSceneHoverEnter:
|
|
||||||
{
|
|
||||||
// Check that there is a tooltip to show
|
|
||||||
if (!Plasma::ToolTipManager::self()->widgetHasToolTip(this)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
QGraphicsView *parentView = view();
|
|
||||||
if (parentView) {
|
|
||||||
Plasma::ToolTipManager::self()->showToolTip(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QEvent::GraphicsSceneHoverLeave:
|
|
||||||
Plasma::ToolTipManager::self()->delayedHideToolTip();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QEvent::GraphicsSceneMousePress:
|
|
||||||
case QEvent::GraphicsSceneWheel:
|
|
||||||
Plasma::ToolTipManager::self()->hideToolTip(this);
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QGraphicsWidget::sceneEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
QPainterPath Applet::shape() const
|
QPainterPath Applet::shape() const
|
||||||
{
|
{
|
||||||
if (d->script) {
|
if (d->script) {
|
||||||
|
5
applet.h
5
applet.h
@ -728,11 +728,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
*/
|
*/
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Reimplemented from QGraphicsItem
|
|
||||||
*/
|
|
||||||
bool sceneEvent(QEvent *event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reimplemented from QGraphicsItem
|
* Reimplemented from QGraphicsItem
|
||||||
*/
|
*/
|
||||||
|
@ -166,6 +166,7 @@ void ToolTipManager::registerWidget(QGraphicsWidget *widget)
|
|||||||
if (!d->tooltips.contains(widget)) {
|
if (!d->tooltips.contains(widget)) {
|
||||||
//the tooltip is not registered we add it in our map of tooltips
|
//the tooltip is not registered we add it in our map of tooltips
|
||||||
d->tooltips.insert(widget,new ToolTip());
|
d->tooltips.insert(widget,new ToolTip());
|
||||||
|
widget->installEventFilter(this);
|
||||||
//connect to object destruction
|
//connect to object destruction
|
||||||
connect(widget,SIGNAL(destroyed(QObject *)),this,SLOT(onWidgetDestroyed(QObject *)));
|
connect(widget,SIGNAL(destroyed(QObject *)),this,SLOT(onWidgetDestroyed(QObject *)));
|
||||||
}
|
}
|
||||||
@ -176,7 +177,7 @@ void ToolTipManager::unregisterWidget(QGraphicsWidget *widget)
|
|||||||
if (!d->tooltips.contains(widget)) {
|
if (!d->tooltips.contains(widget)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
widget->removeEventFilter(this);
|
||||||
ToolTip * tooltip = d->tooltips.take(widget);
|
ToolTip * tooltip = d->tooltips.take(widget);
|
||||||
if (tooltip) {
|
if (tooltip) {
|
||||||
delete tooltip;
|
delete tooltip;
|
||||||
@ -269,7 +270,56 @@ void ToolTipManagerPrivate::showToolTip()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint ToolTipManager::popupPosition(const QGraphicsItem * item, const QSize &s)
|
bool ToolTipManager::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
QGraphicsWidget * widget = dynamic_cast<QGraphicsWidget *>(watched);
|
||||||
|
if (!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()->isWidgetToolTipDisplayed(widget)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QEvent::GraphicsSceneHoverEnter:
|
||||||
|
{
|
||||||
|
// Check that there is a tooltip to show
|
||||||
|
if (!widgetHasToolTip(widget)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
const Applet * applet = ToolTipManager::getItemItsApplet(widget);
|
||||||
|
if (!applet) break;
|
||||||
|
QGraphicsView *parentView = applet->view();
|
||||||
|
if (parentView) {
|
||||||
|
showToolTip(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QEvent::GraphicsSceneHoverLeave:
|
||||||
|
delayedHideToolTip();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QEvent::GraphicsSceneMousePress:
|
||||||
|
case QEvent::GraphicsSceneWheel:
|
||||||
|
hideToolTip(widget);
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QObject::eventFilter(watched,event);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Applet * ToolTipManager::getItemItsApplet(const QGraphicsItem * item)
|
||||||
{
|
{
|
||||||
const Plasma::Applet * applet = dynamic_cast<const Applet *>(item);
|
const Plasma::Applet * applet = dynamic_cast<const Applet *>(item);
|
||||||
if (!applet) {
|
if (!applet) {
|
||||||
@ -279,8 +329,15 @@ QPoint ToolTipManager::popupPosition(const QGraphicsItem * item, const QSize &s)
|
|||||||
currentItem=currentItem->parentItem();
|
currentItem=currentItem->parentItem();
|
||||||
}
|
}
|
||||||
applet = dynamic_cast<const Applet *>(currentItem);
|
applet = dynamic_cast<const Applet *>(currentItem);
|
||||||
if (!applet) return QPoint(0,0);
|
if (!applet) return 0;
|
||||||
}
|
}
|
||||||
|
return applet;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint ToolTipManager::popupPosition(const QGraphicsItem * item, const QSize &s)
|
||||||
|
{
|
||||||
|
const Applet * applet = ToolTipManager::getItemItsApplet(item);
|
||||||
|
if (!applet) return QPoint(0,0);
|
||||||
QGraphicsView *v = applet->view();
|
QGraphicsView *v = applet->view();
|
||||||
Q_ASSERT(v);
|
Q_ASSERT(v);
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
class ToolTipManagerPrivate;
|
class ToolTipManagerPrivate;
|
||||||
|
class Applet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @short The class to manage tooltips on QGraphicsWidget in Plasma
|
* @short The class to manage tooltips on QGraphicsWidget in Plasma
|
||||||
@ -140,8 +141,19 @@ namespace Plasma
|
|||||||
*/
|
*/
|
||||||
static QPoint popupPosition(const QGraphicsItem * item, const QSize &s);
|
static QPoint popupPosition(const QGraphicsItem * item, const QSize &s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take an item and return its owning applet
|
||||||
|
* @param item the item on which we search an applet return NULL if no parent plasma applet
|
||||||
|
* found
|
||||||
|
*/
|
||||||
|
static const Applet * getItemItsApplet(const QGraphicsItem * item);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ToolTipManagerSingleton;
|
friend class ToolTipManagerSingleton;
|
||||||
|
|
||||||
|
bool eventFilter(QObject * watched, QEvent * event);
|
||||||
|
|
||||||
ToolTipManagerPrivate* const d;
|
ToolTipManagerPrivate* const d;
|
||||||
Q_PRIVATE_SLOT(d, void showToolTip())
|
Q_PRIVATE_SLOT(d, void showToolTip())
|
||||||
Q_PRIVATE_SLOT(d, void resetShownState())
|
Q_PRIVATE_SLOT(d, void resetShownState())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user