Strip down tooltip so it builds

This commit is contained in:
Sebastian Kügler 2013-04-03 00:50:00 +02:00
parent 76ced6ff80
commit 0bac65e374
3 changed files with 47 additions and 48 deletions

View File

@ -18,7 +18,7 @@ set(corebindings_SRCS
svgitem.cpp svgitem.cpp
framesvgitem.cpp framesvgitem.cpp
dialog.cpp dialog.cpp
# tooltip.cpp tooltip.cpp
dataenginebindings.cpp dataenginebindings.cpp
iconitem.cpp iconitem.cpp
plasmanamespace.cpp plasmanamespace.cpp

View File

@ -19,23 +19,21 @@
***************************************************************************/ ***************************************************************************/
#include "tooltip.h" #include "tooltip.h"
#include "declarativeitemcontainer_p.h"
#include <QQuickItem> #include <QQuickItem>
#include <QGraphicsObject> // #include <QGraphicsWidget>
#include <QGraphicsWidget> // #include <QGraphicsScene>
#include <QGraphicsScene>
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
#include <KDE/KIcon> //#include <KIcon>
#include <KDE/KIconLoader> // #include <KIconLoader>
#include <KDE/Plasma/ToolTipContent> // #include <Plasma/ToolTipContent>
#include <KDE/Plasma/ToolTipManager> // #include <Plasma/ToolTipManager>
ToolTipProxy::ToolTipProxy(QObject *parent) ToolTipWindow::ToolTipWindow(QWindow *parent)
: QObject(parent), m_mainText(""), m_subText(""), m_widget(0) : QQuickWindow(parent), m_mainText(""), m_subText(""), m_widget(0)
{ {
connect(this, SIGNAL(targetChanged()), this, SLOT(updateToolTip())); connect(this, SIGNAL(targetChanged()), this, SLOT(updateToolTip()));
connect(this, SIGNAL(mainTextChanged()), this, SLOT(updateToolTip())); connect(this, SIGNAL(mainTextChanged()), this, SLOT(updateToolTip()));
@ -43,33 +41,34 @@ ToolTipProxy::ToolTipProxy(QObject *parent)
connect(this, SIGNAL(imageChanged()), this, SLOT(updateToolTip())); connect(this, SIGNAL(imageChanged()), this, SLOT(updateToolTip()));
} }
ToolTipProxy::~ToolTipProxy() ToolTipWindow::~ToolTipWindow()
{ {
} }
QGraphicsObject *ToolTipProxy::target() const QQuickItem *ToolTipWindow::target() const
{ {
return m_target.data(); return m_target.data();
} }
void ToolTipProxy::setTarget(QGraphicsObject *target) void ToolTipWindow::setTarget(QQuickItem *target)
{ {
if (m_target.data() != target) { if (m_target.data() != target) {
m_target = target; m_target = target;
/*
m_widget = qobject_cast<QGraphicsWidget*>(m_target.data()); m_widget = qobject_cast<QGraphicsWidget*>(m_target.data());
if (!m_widget) { if (!m_widget) {
// if this is called in Compenent.onCompleted we have to // if this is called in Compenent.onCompleted we have to
// wait a loop for the item to be added to a scene // wait a loop for the item to be added to a scene
QTimer::singleShot(0, this, SLOT(syncTarget())); QTimer::singleShot(0, this, SLOT(syncTarget()));
return; return;
} }*/
emit targetChanged(); emit targetChanged();
} }
} }
void ToolTipProxy::syncTarget() void ToolTipWindow::syncTarget()
{ {
/*
if (!m_target) { if (!m_target) {
return; return;
} }
@ -78,7 +77,7 @@ void ToolTipProxy::syncTarget()
if (!scene) { if (!scene) {
QObject *parent = m_target.data(); QObject *parent = m_target.data();
while ((parent = parent->parent())) { while ((parent = parent->parent())) {
QGraphicsObject *qo = qobject_cast<QGraphicsObject*>(parent); QQuickItem *qo = qobject_cast<QQuickItem*>(parent);
if (qo && qo->scene()) { if (qo && qo->scene()) {
scene = qo->scene(); scene = qo->scene();
scene->addItem(m_target.data()); scene->addItem(m_target.data());
@ -93,7 +92,7 @@ void ToolTipProxy::syncTarget()
} }
if (!m_declarativeItemContainer && scene) { if (!m_declarativeItemContainer && scene) {
m_declarativeItemContainer = QWeakPointer<DeclarativeItemContainer>(new DeclarativeItemContainer()); m_declarativeItemContainer = QWeakPointer<QQuickItem>(new QQuickItem());
m_declarativeItemContainer.data()->setObjectName("DIContainer"); m_declarativeItemContainer.data()->setObjectName("DIContainer");
scene->addItem(m_declarativeItemContainer.data()); scene->addItem(m_declarativeItemContainer.data());
} }
@ -106,14 +105,15 @@ void ToolTipProxy::syncTarget()
m_widget = m_declarativeItemContainer.data(); m_widget = m_declarativeItemContainer.data();
emit targetChanged(); emit targetChanged();
} }
*/
} }
QString ToolTipProxy::mainText() const QString ToolTipWindow::mainText() const
{ {
return m_mainText; return m_mainText;
} }
void ToolTipProxy::setMainText(const QString &text) void ToolTipWindow::setMainText(const QString &text)
{ {
if (text == m_mainText) { if (text == m_mainText) {
return; return;
@ -123,12 +123,12 @@ void ToolTipProxy::setMainText(const QString &text)
emit mainTextChanged(); emit mainTextChanged();
} }
QString ToolTipProxy::subText() const QString ToolTipWindow::subText() const
{ {
return m_subText; return m_subText;
} }
void ToolTipProxy::setSubText(const QString &text) void ToolTipWindow::setSubText(const QString &text)
{ {
if (text == m_subText) { if (text == m_subText) {
return; return;
@ -138,12 +138,12 @@ void ToolTipProxy::setSubText(const QString &text)
emit subTextChanged(); emit subTextChanged();
} }
QVariant ToolTipProxy::image() const QVariant ToolTipWindow::image() const
{ {
return m_image; return m_image;
} }
void ToolTipProxy::setImage(QVariant name) void ToolTipWindow::setImage(QVariant name)
{ {
if (name == m_image) { if (name == m_image) {
return; return;
@ -153,24 +153,24 @@ void ToolTipProxy::setImage(QVariant name)
emit imageChanged(); emit imageChanged();
} }
void ToolTipProxy::updateToolTip() void ToolTipWindow::updateToolTip()
{ {
if (!m_widget) { if (!m_widget) {
return; return;
} }
Plasma::ToolTipContent data; // Plasma::ToolTipContent data;
data.setMainText(m_mainText); // data.setMainText(m_mainText);
data.setSubText(m_subText); // data.setSubText(m_subText);
// set image // set image
switch (m_image.type()) { switch (m_image.type()) {
case QVariant::String: { case QVariant::String: {
QString name = m_image.toString(); QString name = m_image.toString();
if (!name.isEmpty()) { if (!name.isEmpty()) {
KIcon icon(name); QIcon icon = QIcon::fromTheme(name);
if (!icon.isNull()) { if (!icon.isNull()) {
data.setImage(icon.pixmap(IconSize(KIconLoader::Desktop))); // data.setImage(icon.pixmap(IconSize(KIconLoader::Desktop)));
} }
} }
break; break;
@ -178,21 +178,21 @@ void ToolTipProxy::updateToolTip()
case QVariant::Icon: { case QVariant::Icon: {
QIcon icon = m_image.value<QIcon>(); QIcon icon = m_image.value<QIcon>();
data.setImage(icon); // data.setImage(icon);
break; break;
} }
case QVariant::Pixmap: { case QVariant::Pixmap: {
QPixmap pixmap = m_image.value<QPixmap>(); QPixmap pixmap = m_image.value<QPixmap>();
data.setImage(pixmap); // data.setImage(pixmap);
break; break;
} }
default: default:
break; break;
} }
Plasma::ToolTipManager::self()->setContent(m_widget, data); //Plasma::ToolTipManager::self()->setContent(m_widget, data);
} }
#include "tooltip.moc" //#include "tooltip.moc"

View File

@ -18,30 +18,29 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/ ***************************************************************************/
#ifndef TOOLTIP_PROXY_P #ifndef TOOLTIP_WINDOW_P
#define TOOLTIP_PROXY_P #define TOOLTIP_WINDOW_P
#include <QObject> #include <QQuickWindow>
#include <QWeakPointer> #include <QWeakPointer>
#include <QtCore/QVariant> #include <QtCore/QVariant>
class QGraphicsObject; class QQuickItem;
class QGraphicsWidget; class QGraphicsWidget;
class DeclarativeItemContainer;
/** /**
* QML wrapper for kdelibs Plasma::ToolTip * QML wrapper for kdelibs Plasma::ToolTip
* *
* Exposed as `ToolTip` in QML. * Exposed as `ToolTip` in QML.
*/ */
class ToolTipProxy : public QObject class ToolTipWindow : public QQuickWindow
{ {
Q_OBJECT Q_OBJECT
/** /**
* The item that will display this tooltip on mouse over * The item that will display this tooltip on mouse over
*/ */
Q_PROPERTY(QGraphicsObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
/** /**
* The title of the tooltip, not more that 2-3 words * The title of the tooltip, not more that 2-3 words
@ -59,11 +58,11 @@ class ToolTipProxy : public QObject
Q_PROPERTY(QVariant image READ image WRITE setImage NOTIFY imageChanged) Q_PROPERTY(QVariant image READ image WRITE setImage NOTIFY imageChanged)
public: public:
ToolTipProxy(QObject *parent = 0); ToolTipWindow(QWindow *parent = 0);
~ToolTipProxy(); ~ToolTipWindow();
QGraphicsObject *target() const; QQuickItem *target() const;
void setTarget(QGraphicsObject *target); void setTarget(QQuickItem *target);
QString mainText() const; QString mainText() const;
void setMainText(const QString &text); void setMainText(const QString &text);
@ -89,8 +88,8 @@ private:
QString m_subText; QString m_subText;
QVariant m_image; QVariant m_image;
QGraphicsWidget *m_widget; QGraphicsWidget *m_widget;
QWeakPointer<DeclarativeItemContainer> m_declarativeItemContainer; QWeakPointer<QQuickItem> m_declarativeItemContainer;
QWeakPointer<QGraphicsObject> m_target; QWeakPointer<QQuickItem> m_target;
}; };
#endif #endif