Support of QIcon and QPixmap for QML item PlasmaCore.Tooltip
This commit is contained in:
parent
d7e77f5074
commit
46e7b8065f
@ -28,10 +28,10 @@
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KIcon>
|
||||
#include <KIconLoader>
|
||||
#include <Plasma/ToolTipContent>
|
||||
#include <Plasma/ToolTipManager>
|
||||
#include <KDE/KIcon>
|
||||
#include <KDE/KIconLoader>
|
||||
#include <KDE/Plasma/ToolTipContent>
|
||||
#include <KDE/Plasma/ToolTipManager>
|
||||
|
||||
|
||||
ToolTipProxy::ToolTipProxy(QObject *parent)
|
||||
@ -138,13 +138,12 @@ void ToolTipProxy::setSubText(const QString &text)
|
||||
emit subTextChanged();
|
||||
}
|
||||
|
||||
// ###TODO: SHOULD BE PIXMAP OR QICON??
|
||||
QString ToolTipProxy::image() const
|
||||
QVariant ToolTipProxy::image() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void ToolTipProxy::setImage(const QString &name)
|
||||
void ToolTipProxy::setImage(QVariant name)
|
||||
{
|
||||
if (name == m_image) {
|
||||
return;
|
||||
@ -163,12 +162,35 @@ void ToolTipProxy::updateToolTip()
|
||||
Plasma::ToolTipContent data;
|
||||
data.setMainText(m_mainText);
|
||||
data.setSubText(m_subText);
|
||||
if (!m_image.isEmpty()) {
|
||||
KIcon icon(m_image);
|
||||
|
||||
// set image
|
||||
switch (m_image.type()) {
|
||||
case QVariant::String: {
|
||||
QString name = m_image.toString();
|
||||
if (!name.isEmpty()) {
|
||||
KIcon icon(name);
|
||||
if (!icon.isNull()) {
|
||||
data.setImage(icon.pixmap(IconSize(KIconLoader::Desktop)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case QVariant::Icon: {
|
||||
QIcon icon = m_image.value<QIcon>();
|
||||
data.setImage(icon);
|
||||
break;
|
||||
}
|
||||
|
||||
case QVariant::Pixmap: {
|
||||
QPixmap pixmap = m_image.value<QPixmap>();
|
||||
data.setImage(pixmap);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Plasma::ToolTipManager::self()->setContent(m_widget, data);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QWeakPointer>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
class QGraphicsObject;
|
||||
class QGraphicsWidget;
|
||||
@ -48,9 +49,9 @@ class ToolTipProxy : public QObject
|
||||
Q_PROPERTY(QString subText READ subText WRITE setSubText NOTIFY subTextChanged)
|
||||
|
||||
/**
|
||||
* Image to display in the tooltip, can be an image full path or a Freedesktop icon name
|
||||
* Image to display in the tooltip, can be an image full path or a Freedesktop icon name or QIcon or QPixmap
|
||||
*/
|
||||
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
|
||||
Q_PROPERTY(QVariant image READ image WRITE setImage NOTIFY imageChanged)
|
||||
|
||||
public:
|
||||
ToolTipProxy(QObject *parent = 0);
|
||||
@ -65,9 +66,8 @@ public:
|
||||
QString subText() const;
|
||||
void setSubText(const QString &text);
|
||||
|
||||
// SHOULD BE PIXMAP OR QICON
|
||||
QString image() const;
|
||||
void setImage(const QString &name);
|
||||
QVariant image() const;
|
||||
void setImage(QVariant name);
|
||||
|
||||
Q_SIGNALS:
|
||||
void targetChanged();
|
||||
@ -82,7 +82,7 @@ protected Q_SLOTS:
|
||||
private:
|
||||
QString m_mainText;
|
||||
QString m_subText;
|
||||
QString m_image;
|
||||
QVariant m_image;
|
||||
QGraphicsWidget *m_widget;
|
||||
QWeakPointer<DeclarativeItemContainer> m_declarativeItemContainer;
|
||||
QWeakPointer<QGraphicsObject> m_target;
|
||||
|
Loading…
x
Reference in New Issue
Block a user