support for tooltips in collapsed popupapplets

This commit is contained in:
Marco Martin 2012-08-22 12:03:27 +02:00
parent c761a1078e
commit c36c2f88aa
2 changed files with 66 additions and 0 deletions

View File

@ -39,6 +39,7 @@
#include <Plasma/Corona> #include <Plasma/Corona>
#include <Plasma/Context> #include <Plasma/Context>
#include <Plasma/Package> #include <Plasma/Package>
#include <Plasma/ToolTipManager>
Q_DECLARE_METATYPE(AppletInterface*) Q_DECLARE_METATYPE(AppletInterface*)
@ -472,6 +473,7 @@ PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent)
: APPLETSUPERCLASS(parent) : APPLETSUPERCLASS(parent)
{ {
connect(m_appletScriptEngine, SIGNAL(popupEvent(bool)), this, SIGNAL(popupEvent(bool))); connect(m_appletScriptEngine, SIGNAL(popupEvent(bool)), this, SIGNAL(popupEvent(bool)));
connect(m_appletScriptEngine, SIGNAL(popupEvent(bool)), this, SLOT(sourceAppletPopupEvent(bool)));
} }
void PopupAppletInterface::setPopupIcon(const QIcon &icon) void PopupAppletInterface::setPopupIcon(const QIcon &icon)
@ -489,6 +491,44 @@ void PopupAppletInterface::setPopupIconByName(const QString &name)
return popupApplet()->setPopupIcon(name); return popupApplet()->setPopupIcon(name);
} }
void PopupAppletInterface::setPopupIconToolTip(const QVariantHash &data)
{
if (data == m_rawToolTipData) {
return;
} else if (!data.contains("image") && !data.contains("mainText") &&
!data.contains("subText")) {
m_rawToolTipData = QVariantHash();
Plasma::ToolTipManager::self()->clearContent(popupApplet());
Plasma::ToolTipManager::self()->unregisterWidget(popupApplet());
emit popupIconToolTipChanged();
return;
}
Plasma::ToolTipContent content(data.value("mainText").toString(), data.value("subText").toString());
const QVariant image = data.value("image");
if (image.canConvert<QIcon>()) {
content.setImage(image.value<QIcon>());
} else if (image.canConvert<QPixmap>()) {
content.setImage(image.value<QPixmap>());
} else if (image.canConvert<QImage>()) {
content.setImage(QPixmap::fromImage(image.value<QImage>()));
} else if (image.canConvert<QString>()) {
content.setImage(KIcon(image.toString()));
}
Plasma::ToolTipManager::self()->registerWidget(popupApplet());
Plasma::ToolTipManager::self()->setContent(popupApplet(), content);
m_rawToolTipData = data;
m_toolTipData = content;
emit popupIconToolTipChanged();
}
QVariantHash PopupAppletInterface::popupIconToolTip() const
{
return m_rawToolTipData;
}
void PopupAppletInterface::setPassivePopup(bool passive) void PopupAppletInterface::setPassivePopup(bool passive)
{ {
popupApplet()->setPassivePopup(passive); popupApplet()->setPassivePopup(passive);
@ -529,6 +569,19 @@ QGraphicsWidget *PopupAppletInterface::popupWidget()
return popupApplet()->graphicsWidget(); return popupApplet()->graphicsWidget();
} }
void PopupAppletInterface::sourceAppletPopupEvent(bool show)
{
if (show) {
Plasma::ToolTipManager::self()->clearContent(popupApplet());
} else {
Plasma::ToolTipManager::self()->registerWidget(popupApplet());
Plasma::ToolTipManager::self()->setContent(popupApplet(), m_toolTipData);
}
}
///////////// ContainmentInterface
ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent) ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
: APPLETSUPERCLASS(parent), : APPLETSUPERCLASS(parent),
m_movableApplets(true) m_movableApplets(true)

View File

@ -32,6 +32,7 @@
#include <Plasma/PopupApplet> #include <Plasma/PopupApplet>
#include <Plasma/DataEngine> #include <Plasma/DataEngine>
#include <Plasma/Theme> #include <Plasma/Theme>
#include <Plasma/ToolTipContent>
#include "abstractjsappletscript.h" #include "abstractjsappletscript.h"
@ -363,6 +364,7 @@ class PopupAppletInterface : public APPLETSUPERCLASS
Q_PROPERTY(QIcon popupIcon READ popupIcon WRITE setPopupIcon) Q_PROPERTY(QIcon popupIcon READ popupIcon WRITE setPopupIcon)
Q_PROPERTY(bool passivePopup READ isPassivePopup WRITE setPassivePopup) Q_PROPERTY(bool passivePopup READ isPassivePopup WRITE setPassivePopup)
Q_PROPERTY(QGraphicsWidget *popupWidget READ popupWidget WRITE setPopupWidget) Q_PROPERTY(QGraphicsWidget *popupWidget READ popupWidget WRITE setPopupWidget)
Q_PROPERTY(QVariantHash popupIconToolTip READ popupIconToolTip WRITE setPopupIconToolTip NOTIFY popupIconToolTipChanged)
public: public:
PopupAppletInterface(AbstractJsAppletScript *parent); PopupAppletInterface(AbstractJsAppletScript *parent);
@ -370,6 +372,9 @@ public:
void setPopupIcon(const QIcon &icon); void setPopupIcon(const QIcon &icon);
QIcon popupIcon(); QIcon popupIcon();
void setPopupIconToolTip(const QVariantHash &data);
QVariantHash popupIconToolTip() const;
inline Plasma::PopupApplet *popupApplet() const { return static_cast<Plasma::PopupApplet *>(m_appletScriptEngine->applet()); } inline Plasma::PopupApplet *popupApplet() const { return static_cast<Plasma::PopupApplet *>(m_appletScriptEngine->applet()); }
void setPassivePopup(bool passive); void setPassivePopup(bool passive);
@ -380,6 +385,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void popupEvent(bool); void popupEvent(bool);
void popupIconToolTipChanged();
public Q_SLOTS: public Q_SLOTS:
void setPopupIconByName(const QString &name); void setPopupIconByName(const QString &name);
@ -387,6 +393,13 @@ public Q_SLOTS:
void hidePopup(); void hidePopup();
void showPopup(); void showPopup();
void showPopup(int timeout); void showPopup(int timeout);
private Q_SLOTS:
void sourceAppletPopupEvent(bool show);
private:
QVariantHash m_rawToolTipData;
Plasma::ToolTipContent m_toolTipData;
}; };