FEATURE: add a new optional component in tooltip data: a qgraphicswidget that will be used to position the tooltip instead of the registered widget, if present, it's useful when you want a different position, like the taskbar group tooltips

svn path=/trunk/KDE/kdelibs/; revision=1165246
This commit is contained in:
Marco Martin 2010-08-18 16:33:32 +00:00
parent c53542ca7d
commit ef873a97a6
3 changed files with 32 additions and 2 deletions

View File

@ -19,6 +19,7 @@
#include "tooltipcontent.h"
#include <QGraphicsWidget>
#include <QHash>
#include <QTextDocument>
@ -58,6 +59,7 @@ public:
QPixmap image;
QList<WId> windowsToPreview;
QHash<QString, ToolTipResource> resources;
QWeakPointer<QGraphicsWidget> graphicsWidget;
bool autohide : 1;
bool clickable : 1;
bool highlightWindows : 1;
@ -235,6 +237,16 @@ bool ToolTipContent::isClickable() const
return d->clickable;
}
void ToolTipContent::setGraphicsWidget(QGraphicsWidget *widget)
{
d->graphicsWidget = widget;
}
QGraphicsWidget *ToolTipContent::graphicsWidget() const
{
return d->graphicsWidget.data();
}
} // namespace Plasma

View File

@ -30,6 +30,7 @@
#include <plasma/plasma_export.h>
class QTextDocument;
class QGraphicsWidget;
/**
* This provides the content for a tooltip.
@ -191,6 +192,18 @@ public:
*/
bool isClickable() const;
/**
* Sets an optional graphicsWidget that will be used for positioning the tooltip
* @since 4.6
*/
void setGraphicsWidget(QGraphicsWidget *widget);
/**
* the graphicsWidget used for positioning the tooltip, if any
* @since 4.6
*/
QGraphicsWidget *graphicsWidget() const;
private:
ToolTipContentPrivate * const d;
};

View File

@ -242,8 +242,12 @@ void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &d
d->tipWidget->setContent(widget, data);
d->tipWidget->prepareShowing();
//look if the data prefers aother graphicswidget, otherwise use the one used as event catcher
QGraphicsWidget *referenceWidget = data.graphicsWidget()?data.graphicsWidget():widget;
if (m_corona) {
d->tipWidget->moveTo(m_corona->popupPosition(widget, d->tipWidget->size(), Qt::AlignCenter));
d->tipWidget->moveTo(m_corona->popupPosition(referenceWidget, d->tipWidget->size(), Qt::AlignCenter));
}
}
}
@ -369,7 +373,8 @@ void ToolTipManagerPrivate::showToolTip()
tipWidget->setContent(currentWidget, tooltip.value());
tipWidget->prepareShowing();
if (q->m_corona) {
tipWidget->moveTo(q->m_corona->popupPosition(currentWidget, tipWidget->size(), Qt::AlignCenter));
QGraphicsWidget *referenceWidget = tooltip.value().graphicsWidget()?tooltip.value().graphicsWidget():currentWidget;
tipWidget->moveTo(q->m_corona->popupPosition(referenceWidget, tipWidget->size(), Qt::AlignCenter));
}
tipWidget->show();
isShown = true; //ToolTip is visible