Implementation of a proxy to make it easy to declare tooltips in QML, that will use Plasma::ToolTipManager to display tooltips in any item that is declared in QML. The syntax is: import org.kde.plasma.core 0.1 as PlasmaCore PlasmaCore.ToolTip { target: id_of_the_target mainText: "hello" subText: "world" image: "konqueror" } The syntax looks pretty straightforward and simple. "id_of_the_target" is the id of the element which will show the tooltip in case it's hovered. If the target is a QGraphicsWidget, the code path is really simple but if it's a QDeclarativeItem, then we create a wrapper (that is a QGraphicsWidget) and setup that in a way that we set this wrapper as the target on Plasma's API. For libplasma2 we may want to change this so it's more generic (and also put this together with the components). Right now there is two open issues for me: 1) we should use "image" or "icon"? Allowing the use of a image that is a string that identifies the icon for KIconLoader seems simpler and more beautiful to me, but it would be nice to specify a random QPixmap. Besides being able to use the bindings for QIcon it doesn't look very good. Marco, do you have any thoughts on this issue? 2) for touch oriented UIs, the tooltip as it is right now is not very useful. Is there any "touch" scenario where we may want to use them? CCMAIL:mart@kde.org Signed-off-by: Artur Duque de Souza <asouza@kde.org>
77 lines
2.8 KiB
C++
77 lines
2.8 KiB
C++
/***************************************************************************
|
|
* Copyright 2011 Marco Martin <mart@kde.org> *
|
|
* Copyright 2011 Artur Duque de Souza <asouza@kde.org> *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
***************************************************************************/
|
|
|
|
#ifndef TOOLTIP_PROXY_P
|
|
#define TOOLTIP_PROXY_P
|
|
|
|
#include <QObject>
|
|
#include <QWeakPointer>
|
|
|
|
class QGraphicsObject;
|
|
class QGraphicsWidget;
|
|
class DeclarativeItemContainer;
|
|
|
|
class ToolTipProxy : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QGraphicsObject *target READ target WRITE setTarget NOTIFY targetChanged)
|
|
Q_PROPERTY(QString mainText READ mainText WRITE setMainText NOTIFY mainTextChanged)
|
|
Q_PROPERTY(QString subText READ subText WRITE setSubText NOTIFY subTextChanged)
|
|
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
|
|
|
|
public:
|
|
ToolTipProxy(QObject *parent = 0);
|
|
~ToolTipProxy();
|
|
|
|
QGraphicsObject *target() const;
|
|
void setTarget(QGraphicsObject *target);
|
|
|
|
QString mainText() const;
|
|
void setMainText(const QString &text);
|
|
|
|
QString subText() const;
|
|
void setSubText(const QString &text);
|
|
|
|
// SHOULD BE PIXMAP OR QICON
|
|
QString image() const;
|
|
void setImage(const QString &name);
|
|
|
|
Q_SIGNALS:
|
|
void targetChanged();
|
|
void mainTextChanged();
|
|
void subTextChanged();
|
|
void imageChanged();
|
|
|
|
protected Q_SLOTS:
|
|
void syncTarget();
|
|
void updateToolTip();
|
|
|
|
private:
|
|
QString m_mainText;
|
|
QString m_subText;
|
|
QString m_image;
|
|
DeclarativeItemContainer *m_declarativeItemContainer;
|
|
QGraphicsWidget *m_widget;
|
|
QWeakPointer<QGraphicsObject> m_target;
|
|
};
|
|
|
|
#endif
|