lot of API changes for more clarity, fix some bugs

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=833276
This commit is contained in:
Alexis Ménard 2008-07-16 15:18:02 +00:00
parent 44c8ede79e
commit 6a9bf59888
5 changed files with 61 additions and 22 deletions

View File

@ -1437,14 +1437,14 @@ bool Applet::sceneEvent(QEvent *event)
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(this)) {
if (Plasma::ToolTipManager::self()->isWidgetToolTipDisplayed(this)) {
break;
}
case QEvent::GraphicsSceneHoverEnter:
{
// Check that there is a tooltip to show
if (!Plasma::ToolTipManager::self()->hasToolTip(this)) {
if (!Plasma::ToolTipManager::self()->widgetHasToolTip(this)) {
break;
}

View File

@ -105,7 +105,7 @@ ToolTip::~ToolTip()
delete d;
}
void ToolTip::setData(const ToolTipManager::ToolTipData &data)
void ToolTip::setContent(const ToolTipManager::ToolTipContent &data)
{
//reset our size
d->label->setText("<qt><b>" + data.mainText + "</b><br>" + data.subText + "</qt>");

View File

@ -46,7 +46,7 @@ public:
ToolTip();
~ToolTip();
void updateTheme();
void setData(const ToolTipManager::ToolTipData &data);
void setContent(const ToolTipManager::ToolTipContent &data);
void prepareShowing();
protected:

View File

@ -42,9 +42,9 @@ class ToolTipManagerPrivate
{
public :
ToolTipManagerPrivate()
: showTimer(0)
: currentWidget(0)
, showTimer(0)
, hideTimer(0)
, currentWidget(0)
{
}
@ -122,7 +122,7 @@ void ToolTipManager::showToolTip(QGraphicsWidget *widget)
}
}
bool ToolTipManager::isVisible(QGraphicsWidget *widget)
bool ToolTipManager::isWidgetToolTipDisplayed(QGraphicsWidget *widget)
{
ToolTip * tooltip = d->tooltips.value(widget);
if (tooltip) {
@ -151,18 +151,17 @@ void ToolTipManager::hideToolTip(QGraphicsWidget *widget)
}
}
void ToolTipManager::registerToolTipData(QGraphicsWidget *widget,const ToolTipManager::ToolTipData &data)
void ToolTipManager::registerWidget(QGraphicsWidget *widget)
{
if (!d->tooltips.contains(widget)) {
//the tooltip is not registered we add it in our map of tooltips
d->tooltips.insert(widget,new ToolTip());
ToolTip * tooltip = d->tooltips.value(widget);
tooltip->setData(data);
tooltip->updateTheme();
//connect to object destruction
connect(widget,SIGNAL(destroyed(QObject *)),this,SLOT(onWidgetDestroyed(QObject *)));
}
}
void ToolTipManager::unregisterToolTip(QGraphicsWidget *widget)
void ToolTipManager::unregisterWidget(QGraphicsWidget *widget)
{
if (d->tooltips.contains(widget)) {
ToolTip * tooltip = d->tooltips.take(widget);
@ -172,18 +171,19 @@ void ToolTipManager::unregisterToolTip(QGraphicsWidget *widget)
}
}
void ToolTipManager::updateToolTipData(QGraphicsWidget *widget,const ToolTipData &data)
void ToolTipManager::setWidgetToolTipContent(QGraphicsWidget *widget,const ToolTipContent &data)
{
if (!d->tooltips.contains(widget)) {
return;
}
else {
ToolTip * tooltip = d->tooltips.value(widget);
tooltip->setData(data);
tooltip->setContent(data);
tooltip->updateTheme();
}
}
bool ToolTipManager::hasToolTip(QGraphicsWidget *widget)
bool ToolTipManager::widgetHasToolTip(QGraphicsWidget *widget)
{
return d->tooltips.contains(widget);
}
@ -197,6 +197,26 @@ void ToolTipManager::themeUpdated()
}
}
void ToolTipManager::onWidgetDestroyed(QObject * object)
{
if (object) {
QMapIterator<QGraphicsWidget*, ToolTip *> iterator(d->tooltips);
while (iterator.hasNext()) {
iterator.next();
if (iterator.key() == object) {
ToolTip * tooltip = iterator.value();
d->tooltips.remove(iterator.key());
kDebug()<<"Tooltip destroyed"<<(int)object;
d->showTimer->stop(); // stop the timer to show the tooltip
d->delayedHide = false;
d->currentWidget = 0;
tooltip->hide();
delete tooltip;
}
}
}
}
void ToolTipManagerPrivate::resetShownState()
{
if (currentWidget) {

View File

@ -51,33 +51,52 @@ namespace Plasma
{
Q_OBJECT
public:
struct ToolTipData
struct ToolTipContent
{
ToolTipData() : windowToPreview( 0 ) {}
ToolTipContent() : windowToPreview( 0 ) {}
QString mainText; //Important information
QString subText; //Elaborates on the Main Text
QPixmap image; // Icon to show;
WId windowToPreview; // Id of window to show preview
};
/**
*
* @return The singleton instance of the manager.
**/
static ToolTipManager *self();
/**
* Default constructor. Usually you want to use the singleton instead.
*/
explicit ToolTipManager(QObject* parent = 0);
/**
* Default destructor.
*/
~ToolTipManager();
void showToolTip(QGraphicsWidget *widget);
bool isVisible(QGraphicsWidget *widget);
bool isWidgetToolTipDisplayed(QGraphicsWidget *widget);
void delayedHideToolTip();
void hideToolTip(QGraphicsWidget *widget);
void registerToolTipData(QGraphicsWidget *widget,const ToolTipData &data);
void unregisterToolTip(QGraphicsWidget *widget);
void updateToolTipData(QGraphicsWidget *widget,const ToolTipData &data);
bool hasToolTip(QGraphicsWidget *widget);
void registerWidget(QGraphicsWidget *widget);
void unregisterWidget(QGraphicsWidget *widget);
void setWidgetToolTipContent(QGraphicsWidget *widget,const ToolTipContent &data);
bool widgetHasToolTip(QGraphicsWidget *widget);
static QPoint popupPosition(const QGraphicsItem * item, const QSize &s);
private Q_SLOTS:
void themeUpdated();
void onWidgetDestroyed(QObject * object);
private:
friend class ToolTipManagerSingleton;