split tooltip and tooltipwindow
This commit is contained in:
parent
f9adc7a598
commit
95dddcea35
@ -19,6 +19,7 @@ set(corebindings_SRCS
|
||||
framesvgitem.cpp
|
||||
dialog.cpp
|
||||
tooltip.cpp
|
||||
tooltipwindow.cpp
|
||||
dataenginebindings.cpp
|
||||
iconitem.cpp
|
||||
plasmanamespace.cpp
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "theme.h"
|
||||
#include "dialog.h"
|
||||
#include "iconitem.h"
|
||||
#include "tooltip.h"
|
||||
#include "tooltipwindow.h"
|
||||
// #include "dataenginebindings_p.h"
|
||||
#include "plasmanamespace.h"
|
||||
|
||||
|
@ -28,178 +28,53 @@
|
||||
#include "framesvgitem.h"
|
||||
#include <kwindoweffects.h>
|
||||
|
||||
ToolTipWindow::ToolTipWindow(QWindow *parent)
|
||||
: QQuickWindow(parent), m_mainText(""), m_subText(""), m_widget(0)
|
||||
{
|
||||
QSurfaceFormat format;
|
||||
format.setAlphaBufferSize(8);
|
||||
setFormat(format);
|
||||
setClearBeforeRendering(true);
|
||||
setColor(QColor(Qt::transparent));
|
||||
setFlags(Qt::ToolTip);
|
||||
|
||||
m_syncTimer = new QTimer(this);
|
||||
m_syncTimer->setSingleShot(true);
|
||||
m_syncTimer->setInterval(250);
|
||||
connect(m_syncTimer, &QTimer::timeout, this, &ToolTipWindow::syncGeometry);
|
||||
|
||||
connect(this, SIGNAL(targetChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(mainTextChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(subTextChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(imageChanged()), this, SLOT(updateToolTip()));
|
||||
}
|
||||
|
||||
ToolTipWindow::~ToolTipWindow()
|
||||
ToolTip::ToolTip(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QQuickItem *ToolTipWindow::target() const
|
||||
ToolTip::~ToolTip()
|
||||
{
|
||||
}
|
||||
|
||||
QQuickItem *ToolTip::target() const
|
||||
{
|
||||
return m_target.data();
|
||||
}
|
||||
|
||||
void ToolTipWindow::setTarget(QQuickItem *target)
|
||||
void ToolTip::setTarget(QQuickItem *target)
|
||||
{
|
||||
if (m_target.data() != target) {
|
||||
m_target = target;
|
||||
/*
|
||||
m_widget = qobject_cast<QGraphicsWidget*>(m_target.data());
|
||||
if (!m_widget) {
|
||||
// if this is called in Compenent.onCompleted we have to
|
||||
// wait a loop for the item to be added to a scene
|
||||
QTimer::singleShot(0, this, SLOT(syncTarget()));
|
||||
return;
|
||||
}*/
|
||||
emit targetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ToolTipWindow::syncGeometry()
|
||||
{
|
||||
qDebug() << " XXX synching geometry";
|
||||
qDebug() << "XXXX mainitem : " << mainItem()->width() << mainItem()->height();
|
||||
resize(mainItem()->width(), mainItem()->height());
|
||||
setPosition(popupPosition(visualParent()));
|
||||
|
||||
Plasma::FrameSvgItem *frameSvg = qobject_cast<Plasma::FrameSvgItem*>(mainItem());
|
||||
if (frameSvg) {
|
||||
KWindowEffects::enableBlurBehind(winId(), true, frameSvg->frameSvg()->mask());
|
||||
}
|
||||
}
|
||||
|
||||
QString ToolTipWindow::mainText() const
|
||||
{
|
||||
return m_mainText;
|
||||
}
|
||||
|
||||
void ToolTipWindow::setMainText(const QString &text)
|
||||
{
|
||||
if (text == m_mainText) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_mainText = text;
|
||||
emit mainTextChanged();
|
||||
}
|
||||
|
||||
QString ToolTipWindow::subText() const
|
||||
{
|
||||
return m_subText;
|
||||
}
|
||||
|
||||
void ToolTipWindow::setSubText(const QString &text)
|
||||
{
|
||||
if (text == m_subText) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_subText = text;
|
||||
emit subTextChanged();
|
||||
}
|
||||
|
||||
QVariant ToolTipWindow::image() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void ToolTipWindow::setImage(QVariant name)
|
||||
{
|
||||
if (name == m_image) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_image = name;
|
||||
emit imageChanged();
|
||||
}
|
||||
|
||||
void ToolTipWindow::updateToolTip()
|
||||
{
|
||||
if (!m_widget) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Plasma::ToolTipContent data;
|
||||
// data.setMainText(m_mainText);
|
||||
// data.setSubText(m_subText);
|
||||
|
||||
// set image
|
||||
switch (m_image.type()) {
|
||||
case QVariant::String: {
|
||||
QString name = m_image.toString();
|
||||
if (!name.isEmpty()) {
|
||||
QIcon icon = QIcon::fromTheme(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);
|
||||
}
|
||||
|
||||
QQuickItem *ToolTipWindow::mainItem() const
|
||||
QQuickItem *ToolTip::mainItem() const
|
||||
{
|
||||
return m_mainItem.data();
|
||||
}
|
||||
|
||||
void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
||||
void ToolTip::setMainItem(QQuickItem *mainItem)
|
||||
{
|
||||
qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
|
||||
|
||||
// resize(400, 200);
|
||||
if (m_mainItem.data() != mainItem) {
|
||||
qDebug() << " XXX new mainItem";
|
||||
disconnect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
|
||||
disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
||||
// disconnect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTip::syncGeometry);
|
||||
// disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTip::syncGeometry);
|
||||
if (m_mainItem) {
|
||||
m_mainItem.data()->setParent(parent());
|
||||
}
|
||||
m_mainItem = mainItem;
|
||||
|
||||
|
||||
if (mainItem) {
|
||||
//mainItem->setParentItem(0);
|
||||
connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
|
||||
connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
||||
// connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTip::syncGeometry);
|
||||
// connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTip::syncGeometry);
|
||||
qDebug() << "XXX new mainITem connected";
|
||||
mainItem->setParent(contentItem());
|
||||
mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
|
||||
//mainItem->setParent(contentItem());
|
||||
//mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
|
||||
|
||||
if (mainItem->metaObject()->indexOfSignal("widthChanged")) {
|
||||
connect(mainItem, SIGNAL(widthChanged()), m_syncTimer, SIGNAL(start()));
|
||||
@ -214,70 +89,37 @@ void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
||||
}
|
||||
}
|
||||
|
||||
QQuickItem *ToolTipWindow::visualParent() const
|
||||
QQuickItem *ToolTip::visualParent() const
|
||||
{
|
||||
return m_visualParent.data();
|
||||
}
|
||||
|
||||
void ToolTipWindow::setVisualParent(QQuickItem *visualParent)
|
||||
void ToolTip::setVisualParent(QQuickItem *visualParent)
|
||||
{
|
||||
if (m_visualParent.data() == visualParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (visualParent) {
|
||||
setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
||||
//setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
||||
}
|
||||
disconnect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||
disconnect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
//disconnect(visualParent, &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
|
||||
m_visualParent = visualParent;
|
||||
connect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||
connect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
emit visualParentChanged();
|
||||
}
|
||||
|
||||
|
||||
bool ToolTipWindow::isVisible() const
|
||||
bool ToolTip::isVisible() const
|
||||
{
|
||||
return QQuickWindow::isVisible();
|
||||
|
||||
//return QQuickWindow::isVisible();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ToolTipWindow::setVisible(const bool visible)
|
||||
void ToolTip::setVisible(const bool visible)
|
||||
{
|
||||
qDebug() << visible;
|
||||
if (visible) {
|
||||
//setPosition(popupPosition());
|
||||
syncGeometry();
|
||||
raise();
|
||||
// syncGeometry();
|
||||
// raise();
|
||||
}
|
||||
QQuickWindow::setVisible(visible);
|
||||
//QQuickWindow::setVisible(visible);
|
||||
}
|
||||
|
||||
QPoint ToolTipWindow::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
||||
{
|
||||
// FIXME :: Item
|
||||
if (!item) {
|
||||
item = qobject_cast<QQuickItem *>(visualParent());
|
||||
}
|
||||
if (item && item->window()) {
|
||||
QPointF itemScreenPos;
|
||||
|
||||
QPointF pos = item->mapToScene(QPointF(0, 0));
|
||||
//qDebug() << "I've an Item at " << pos;
|
||||
if (item->window() && item->window()->screen()) {
|
||||
pos = item->window()->mapToGlobal(pos.toPoint());
|
||||
} else {
|
||||
}
|
||||
itemScreenPos = QPoint(pos.x() + (item->width() - mainItem()->width())/2, pos.y()-mainItem()->height());
|
||||
qDebug() << "XXX Centering at visualParent" << itemScreenPos;
|
||||
return itemScreenPos.toPoint();
|
||||
} else {
|
||||
qDebug() << "XXX No QQuickItem visualParent found";
|
||||
return QPoint(100, 100);
|
||||
}
|
||||
}
|
||||
//#include "tooltip.moc"
|
||||
|
||||
|
@ -19,8 +19,8 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TOOLTIP_WINDOW_P
|
||||
#define TOOLTIP_WINDOW_P
|
||||
#ifndef TOOLTIPOBJECT_H
|
||||
#define TOOLTIPOBJECT_H
|
||||
|
||||
#include <QTimer>
|
||||
#include <QQuickWindow>
|
||||
@ -35,7 +35,7 @@ class QGraphicsWidget;
|
||||
*
|
||||
* Exposed as `ToolTip` in QML.
|
||||
*/
|
||||
class ToolTipWindow : public QQuickWindow
|
||||
class ToolTip : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -44,21 +44,6 @@ class ToolTipWindow : public QQuickWindow
|
||||
*/
|
||||
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
|
||||
|
||||
/**
|
||||
* The title of the tooltip, not more that 2-3 words
|
||||
*/
|
||||
Q_PROPERTY(QString mainText READ mainText WRITE setMainText NOTIFY mainTextChanged)
|
||||
|
||||
/**
|
||||
* subtitle of the tooltip. needed if a longer description is needed
|
||||
*/
|
||||
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 or QIcon or QPixmap
|
||||
*/
|
||||
Q_PROPERTY(QVariant image READ image WRITE setImage NOTIFY imageChanged)
|
||||
|
||||
/**
|
||||
* The main QML item that will be displayed in the Dialog
|
||||
*/
|
||||
@ -76,21 +61,12 @@ class ToolTipWindow : public QQuickWindow
|
||||
|
||||
|
||||
public:
|
||||
ToolTipWindow(QWindow *parent = 0);
|
||||
~ToolTipWindow();
|
||||
ToolTip(QObject *parent = 0);
|
||||
~ToolTip();
|
||||
|
||||
QQuickItem *target() const;
|
||||
void setTarget(QQuickItem *target);
|
||||
|
||||
QString mainText() const;
|
||||
void setMainText(const QString &text);
|
||||
|
||||
QString subText() const;
|
||||
void setSubText(const QString &text);
|
||||
|
||||
QVariant image() const;
|
||||
void setImage(QVariant name);
|
||||
|
||||
QQuickItem *mainItem() const;
|
||||
void setMainItem(QQuickItem *mainItem);
|
||||
|
||||
@ -104,23 +80,12 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
void targetChanged();
|
||||
void mainTextChanged();
|
||||
void subTextChanged();
|
||||
void imageChanged();
|
||||
void mainItemChanged();
|
||||
void visualParentChanged();
|
||||
void visibleChanged();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void syncGeometry();
|
||||
void updateToolTip();
|
||||
|
||||
private:
|
||||
QTimer *m_syncTimer;
|
||||
QString m_mainText;
|
||||
QString m_subText;
|
||||
QVariant m_image;
|
||||
QGraphicsWidget *m_widget;
|
||||
QWeakPointer<QQuickItem> m_mainItem;
|
||||
QWeakPointer<QQuickItem> m_visualParent;
|
||||
QWeakPointer<QQuickItem> m_declarativeItemContainer;
|
||||
|
282
src/declarativeimports/core/tooltipwindow.cpp
Normal file
282
src/declarativeimports/core/tooltipwindow.cpp
Normal file
@ -0,0 +1,282 @@
|
||||
/***************************************************************************
|
||||
* Copyright 2011 Marco Martin <mart@kde.org> *
|
||||
* Copyright 2011 Artur Duque de Souza <asouza@kde.org> *
|
||||
* Copyright 2013 Sebastian Kügler <sebas@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 . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "tooltipwindow.h"
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
#include "framesvgitem.h"
|
||||
#include <kwindoweffects.h>
|
||||
|
||||
ToolTipWindow::ToolTipWindow(QWindow *parent)
|
||||
: QQuickWindow(parent), m_mainText(""), m_subText(""), m_widget(0)
|
||||
{
|
||||
QSurfaceFormat format;
|
||||
format.setAlphaBufferSize(8);
|
||||
setFormat(format);
|
||||
setClearBeforeRendering(true);
|
||||
setColor(QColor(Qt::transparent));
|
||||
setFlags(Qt::ToolTip);
|
||||
|
||||
m_syncTimer = new QTimer(this);
|
||||
m_syncTimer->setSingleShot(true);
|
||||
m_syncTimer->setInterval(250);
|
||||
connect(m_syncTimer, &QTimer::timeout, this, &ToolTipWindow::syncGeometry);
|
||||
|
||||
connect(this, SIGNAL(targetChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(mainTextChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(subTextChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(imageChanged()), this, SLOT(updateToolTip()));
|
||||
}
|
||||
|
||||
ToolTipWindow::~ToolTipWindow()
|
||||
{
|
||||
}
|
||||
|
||||
QQuickItem *ToolTipWindow::target() const
|
||||
{
|
||||
return m_target.data();
|
||||
}
|
||||
|
||||
void ToolTipWindow::setTarget(QQuickItem *target)
|
||||
{
|
||||
if (m_target.data() != target) {
|
||||
m_target = target;
|
||||
/*
|
||||
m_widget = qobject_cast<QGraphicsWidget*>(m_target.data());
|
||||
if (!m_widget) {
|
||||
// if this is called in Compenent.onCompleted we have to
|
||||
// wait a loop for the item to be added to a scene
|
||||
QTimer::singleShot(0, this, SLOT(syncTarget()));
|
||||
return;
|
||||
}*/
|
||||
emit targetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ToolTipWindow::syncGeometry()
|
||||
{
|
||||
qDebug() << " XXX synching geometry";
|
||||
qDebug() << "XXXX mainitem : " << mainItem()->width() << mainItem()->height();
|
||||
resize(mainItem()->width(), mainItem()->height());
|
||||
setPosition(popupPosition(visualParent()));
|
||||
|
||||
Plasma::FrameSvgItem *frameSvg = qobject_cast<Plasma::FrameSvgItem*>(mainItem());
|
||||
if (frameSvg) {
|
||||
KWindowEffects::enableBlurBehind(winId(), true, frameSvg->frameSvg()->mask());
|
||||
}
|
||||
}
|
||||
|
||||
QString ToolTipWindow::mainText() const
|
||||
{
|
||||
return m_mainText;
|
||||
}
|
||||
|
||||
void ToolTipWindow::setMainText(const QString &text)
|
||||
{
|
||||
if (text == m_mainText) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_mainText = text;
|
||||
emit mainTextChanged();
|
||||
}
|
||||
|
||||
QString ToolTipWindow::subText() const
|
||||
{
|
||||
return m_subText;
|
||||
}
|
||||
|
||||
void ToolTipWindow::setSubText(const QString &text)
|
||||
{
|
||||
if (text == m_subText) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_subText = text;
|
||||
emit subTextChanged();
|
||||
}
|
||||
|
||||
QVariant ToolTipWindow::image() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void ToolTipWindow::setImage(QVariant name)
|
||||
{
|
||||
if (name == m_image) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_image = name;
|
||||
emit imageChanged();
|
||||
}
|
||||
|
||||
void ToolTipWindow::updateToolTip()
|
||||
{
|
||||
if (!m_widget) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Plasma::ToolTipContent data;
|
||||
// data.setMainText(m_mainText);
|
||||
// data.setSubText(m_subText);
|
||||
|
||||
// set image
|
||||
switch (m_image.type()) {
|
||||
case QVariant::String: {
|
||||
QString name = m_image.toString();
|
||||
if (!name.isEmpty()) {
|
||||
QIcon icon = QIcon::fromTheme(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);
|
||||
}
|
||||
|
||||
QQuickItem *ToolTipWindow::mainItem() const
|
||||
{
|
||||
return m_mainItem.data();
|
||||
}
|
||||
|
||||
void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
||||
{
|
||||
qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
|
||||
|
||||
// resize(400, 200);
|
||||
if (m_mainItem.data() != mainItem) {
|
||||
qDebug() << " XXX new mainItem";
|
||||
disconnect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
|
||||
disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
||||
if (m_mainItem) {
|
||||
m_mainItem.data()->setParent(parent());
|
||||
}
|
||||
m_mainItem = mainItem;
|
||||
|
||||
|
||||
if (mainItem) {
|
||||
//mainItem->setParentItem(0);
|
||||
connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
|
||||
connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
||||
qDebug() << "XXX new mainITem connected";
|
||||
mainItem->setParent(contentItem());
|
||||
mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
|
||||
|
||||
if (mainItem->metaObject()->indexOfSignal("widthChanged")) {
|
||||
connect(mainItem, SIGNAL(widthChanged()), m_syncTimer, SIGNAL(start()));
|
||||
}
|
||||
if (mainItem->metaObject()->indexOfSignal("heightChanged")) {
|
||||
connect(mainItem, SIGNAL(heightChanged()), m_syncTimer, SIGNAL(start()));
|
||||
}
|
||||
}
|
||||
|
||||
//if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene
|
||||
emit mainItemChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QQuickItem *ToolTipWindow::visualParent() const
|
||||
{
|
||||
return m_visualParent.data();
|
||||
}
|
||||
|
||||
void ToolTipWindow::setVisualParent(QQuickItem *visualParent)
|
||||
{
|
||||
if (m_visualParent.data() == visualParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (visualParent) {
|
||||
setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
||||
}
|
||||
disconnect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||
disconnect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
//disconnect(visualParent, &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
|
||||
m_visualParent = visualParent;
|
||||
connect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||
connect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
emit visualParentChanged();
|
||||
}
|
||||
|
||||
|
||||
bool ToolTipWindow::isVisible() const
|
||||
{
|
||||
return QQuickWindow::isVisible();
|
||||
|
||||
}
|
||||
|
||||
void ToolTipWindow::setVisible(const bool visible)
|
||||
{
|
||||
qDebug() << visible;
|
||||
if (visible) {
|
||||
//setPosition(popupPosition());
|
||||
syncGeometry();
|
||||
raise();
|
||||
}
|
||||
QQuickWindow::setVisible(visible);
|
||||
}
|
||||
|
||||
QPoint ToolTipWindow::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
||||
{
|
||||
// FIXME :: Item
|
||||
if (!item) {
|
||||
item = qobject_cast<QQuickItem *>(visualParent());
|
||||
}
|
||||
if (item && item->window()) {
|
||||
QPointF itemScreenPos;
|
||||
|
||||
QPointF pos = item->mapToScene(QPointF(0, 0));
|
||||
//qDebug() << "I've an Item at " << pos;
|
||||
if (item->window() && item->window()->screen()) {
|
||||
pos = item->window()->mapToGlobal(pos.toPoint());
|
||||
} else {
|
||||
}
|
||||
itemScreenPos = QPoint(pos.x() + (item->width() - mainItem()->width())/2, pos.y()-mainItem()->height());
|
||||
qDebug() << "XXX Centering at visualParent" << itemScreenPos;
|
||||
return itemScreenPos.toPoint();
|
||||
} else {
|
||||
qDebug() << "XXX No QQuickItem visualParent found";
|
||||
return QPoint(100, 100);
|
||||
}
|
||||
}
|
||||
|
130
src/declarativeimports/core/tooltipwindow.h
Normal file
130
src/declarativeimports/core/tooltipwindow.h
Normal file
@ -0,0 +1,130 @@
|
||||
/***************************************************************************
|
||||
* Copyright 2011 Marco Martin <mart@kde.org> *
|
||||
* Copyright 2011 Artur Duque de Souza <asouza@kde.org> *
|
||||
* Copyright 2013 Sebastian Kügler <sebas@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_WINDOW_P
|
||||
#define TOOLTIP_WINDOW_P
|
||||
|
||||
#include <QTimer>
|
||||
#include <QQuickWindow>
|
||||
#include <QWeakPointer>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
class QQuickItem;
|
||||
class QGraphicsWidget;
|
||||
|
||||
/**
|
||||
* QML wrapper for kdelibs Plasma::ToolTip
|
||||
*
|
||||
* Exposed as `ToolTip` in QML.
|
||||
*/
|
||||
class ToolTipWindow : public QQuickWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/**
|
||||
* The item that will display this tooltip on mouse over
|
||||
*/
|
||||
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
|
||||
|
||||
/**
|
||||
* The title of the tooltip, not more that 2-3 words
|
||||
*/
|
||||
Q_PROPERTY(QString mainText READ mainText WRITE setMainText NOTIFY mainTextChanged)
|
||||
|
||||
/**
|
||||
* subtitle of the tooltip. needed if a longer description is needed
|
||||
*/
|
||||
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 or QIcon or QPixmap
|
||||
*/
|
||||
Q_PROPERTY(QVariant image READ image WRITE setImage NOTIFY imageChanged)
|
||||
|
||||
/**
|
||||
* The main QML item that will be displayed in the Dialog
|
||||
*/
|
||||
Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
|
||||
|
||||
/**
|
||||
* The main QML item that will be displayed in the Dialog
|
||||
*/
|
||||
Q_PROPERTY(QQuickItem *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged)
|
||||
|
||||
/**
|
||||
* Visibility of the Dialog window. Doesn't have anything to do with the visibility of the mainItem.
|
||||
*/
|
||||
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
|
||||
|
||||
|
||||
public:
|
||||
ToolTipWindow(QWindow *parent = 0);
|
||||
~ToolTipWindow();
|
||||
|
||||
QQuickItem *target() const;
|
||||
void setTarget(QQuickItem *target);
|
||||
|
||||
QString mainText() const;
|
||||
void setMainText(const QString &text);
|
||||
|
||||
QString subText() const;
|
||||
void setSubText(const QString &text);
|
||||
|
||||
QVariant image() const;
|
||||
void setImage(QVariant name);
|
||||
|
||||
QQuickItem *mainItem() const;
|
||||
void setMainItem(QQuickItem *mainItem);
|
||||
|
||||
QQuickItem *visualParent() const;
|
||||
void setVisualParent(QQuickItem *visualParent);
|
||||
|
||||
bool isVisible() const;
|
||||
void setVisible(const bool visible);
|
||||
|
||||
QPoint popupPosition(QQuickItem *item = 0, Qt::AlignmentFlag alignment=Qt::AlignCenter) ;
|
||||
|
||||
Q_SIGNALS:
|
||||
void targetChanged();
|
||||
void mainTextChanged();
|
||||
void subTextChanged();
|
||||
void imageChanged();
|
||||
void mainItemChanged();
|
||||
void visualParentChanged();
|
||||
void visibleChanged();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void syncGeometry();
|
||||
void updateToolTip();
|
||||
|
||||
private:
|
||||
QTimer *m_syncTimer;
|
||||
QString m_mainText;
|
||||
QString m_subText;
|
||||
QVariant m_image;
|
||||
QGraphicsWidget *m_widget;
|
||||
QWeakPointer<QQuickItem> m_mainItem;
|
||||
QWeakPointer<QQuickItem> m_visualParent;
|
||||
QWeakPointer<QQuickItem> m_declarativeItemContainer;
|
||||
QWeakPointer<QQuickItem> m_target;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user