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 <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <KIcon>
|
#include <KDE/KIcon>
|
||||||
#include <KIconLoader>
|
#include <KDE/KIconLoader>
|
||||||
#include <Plasma/ToolTipContent>
|
#include <KDE/Plasma/ToolTipContent>
|
||||||
#include <Plasma/ToolTipManager>
|
#include <KDE/Plasma/ToolTipManager>
|
||||||
|
|
||||||
|
|
||||||
ToolTipProxy::ToolTipProxy(QObject *parent)
|
ToolTipProxy::ToolTipProxy(QObject *parent)
|
||||||
@ -138,13 +138,12 @@ void ToolTipProxy::setSubText(const QString &text)
|
|||||||
emit subTextChanged();
|
emit subTextChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ###TODO: SHOULD BE PIXMAP OR QICON??
|
QVariant ToolTipProxy::image() const
|
||||||
QString ToolTipProxy::image() const
|
|
||||||
{
|
{
|
||||||
return m_image;
|
return m_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipProxy::setImage(const QString &name)
|
void ToolTipProxy::setImage(QVariant name)
|
||||||
{
|
{
|
||||||
if (name == m_image) {
|
if (name == m_image) {
|
||||||
return;
|
return;
|
||||||
@ -163,11 +162,34 @@ void ToolTipProxy::updateToolTip()
|
|||||||
Plasma::ToolTipContent data;
|
Plasma::ToolTipContent data;
|
||||||
data.setMainText(m_mainText);
|
data.setMainText(m_mainText);
|
||||||
data.setSubText(m_subText);
|
data.setSubText(m_subText);
|
||||||
if (!m_image.isEmpty()) {
|
|
||||||
KIcon icon(m_image);
|
// set image
|
||||||
if (!icon.isNull()) {
|
switch (m_image.type()) {
|
||||||
data.setImage(icon.pixmap(IconSize(KIconLoader::Desktop)));
|
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);
|
Plasma::ToolTipManager::self()->setContent(m_widget, data);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QWeakPointer>
|
#include <QWeakPointer>
|
||||||
|
#include <QtCore/QVariant>
|
||||||
|
|
||||||
class QGraphicsObject;
|
class QGraphicsObject;
|
||||||
class QGraphicsWidget;
|
class QGraphicsWidget;
|
||||||
@ -48,9 +49,9 @@ class ToolTipProxy : public QObject
|
|||||||
Q_PROPERTY(QString subText READ subText WRITE setSubText NOTIFY subTextChanged)
|
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:
|
public:
|
||||||
ToolTipProxy(QObject *parent = 0);
|
ToolTipProxy(QObject *parent = 0);
|
||||||
@ -65,9 +66,8 @@ public:
|
|||||||
QString subText() const;
|
QString subText() const;
|
||||||
void setSubText(const QString &text);
|
void setSubText(const QString &text);
|
||||||
|
|
||||||
// SHOULD BE PIXMAP OR QICON
|
QVariant image() const;
|
||||||
QString image() const;
|
void setImage(QVariant name);
|
||||||
void setImage(const QString &name);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void targetChanged();
|
void targetChanged();
|
||||||
@ -82,7 +82,7 @@ protected Q_SLOTS:
|
|||||||
private:
|
private:
|
||||||
QString m_mainText;
|
QString m_mainText;
|
||||||
QString m_subText;
|
QString m_subText;
|
||||||
QString m_image;
|
QVariant m_image;
|
||||||
QGraphicsWidget *m_widget;
|
QGraphicsWidget *m_widget;
|
||||||
QWeakPointer<DeclarativeItemContainer> m_declarativeItemContainer;
|
QWeakPointer<DeclarativeItemContainer> m_declarativeItemContainer;
|
||||||
QWeakPointer<QGraphicsObject> m_target;
|
QWeakPointer<QGraphicsObject> m_target;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user