2011-04-27 19:33:29 -03:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright 2011 Marco Martin <mart@kde.org> *
|
|
|
|
* Copyright 2011 Artur Duque de Souza <asouza@kde.org> *
|
2013-04-04 05:02:51 +02:00
|
|
|
* Copyright 2013 Sebastian Kügler <sebas@kde.org> *
|
2011-04-27 19:33:29 -03:00
|
|
|
* *
|
|
|
|
* 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 "tooltip.h"
|
2013-04-05 01:10:53 +02:00
|
|
|
#include "tooltipdialog.h"
|
2011-04-27 19:33:29 -03:00
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
#include <QQuickItem>
|
2011-04-27 19:33:29 -03:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2013-04-04 16:00:57 +02:00
|
|
|
#include "framesvgitem.h"
|
|
|
|
#include <kwindoweffects.h>
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
ToolTip::ToolTip(QObject *parent)
|
|
|
|
: QObject(parent)
|
2011-04-27 19:33:29 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
ToolTip::~ToolTip()
|
2011-04-27 19:33:29 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
QQuickItem *ToolTip::target() const
|
2011-04-27 19:33:29 -03:00
|
|
|
{
|
|
|
|
return m_target.data();
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
void ToolTip::setTarget(QQuickItem *target)
|
2011-04-27 19:33:29 -03:00
|
|
|
{
|
|
|
|
if (m_target.data() != target) {
|
|
|
|
m_target = target;
|
|
|
|
emit targetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-05 04:27:52 +02:00
|
|
|
QQmlComponent* ToolTip::mainComponent() const
|
|
|
|
{
|
|
|
|
return m_mainComponent.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTip::setMainComponent(QQmlComponent* mainComponent)
|
|
|
|
{
|
|
|
|
m_mainComponent = mainComponent;
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
QQuickItem *ToolTip::mainItem() const
|
2013-04-03 02:23:22 +02:00
|
|
|
{
|
|
|
|
return m_mainItem.data();
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
void ToolTip::setMainItem(QQuickItem *mainItem)
|
2013-04-03 02:23:22 +02:00
|
|
|
{
|
2013-04-04 01:46:02 +02:00
|
|
|
qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
|
2013-04-03 02:23:22 +02:00
|
|
|
|
|
|
|
if (m_mainItem.data() != mainItem) {
|
2013-04-04 01:46:02 +02:00
|
|
|
qDebug() << " XXX new mainItem";
|
2013-04-04 22:14:56 +02:00
|
|
|
// disconnect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTip::syncGeometry);
|
|
|
|
// disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTip::syncGeometry);
|
2013-04-03 02:23:22 +02:00
|
|
|
if (m_mainItem) {
|
|
|
|
m_mainItem.data()->setParent(parent());
|
|
|
|
}
|
|
|
|
m_mainItem = mainItem;
|
|
|
|
|
|
|
|
if (mainItem) {
|
|
|
|
//mainItem->setParentItem(0);
|
2013-04-04 22:14:56 +02:00
|
|
|
// connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTip::syncGeometry);
|
|
|
|
// connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTip::syncGeometry);
|
2013-04-04 01:46:02 +02:00
|
|
|
qDebug() << "XXX new mainITem connected";
|
2013-04-04 22:14:56 +02:00
|
|
|
//mainItem->setParent(contentItem());
|
|
|
|
//mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
|
2013-04-03 02:23:22 +02:00
|
|
|
|
2013-04-05 04:27:52 +02:00
|
|
|
// 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()));
|
|
|
|
// }
|
2013-04-03 02:23:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene
|
|
|
|
emit mainItemChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
QQuickItem *ToolTip::visualParent() const
|
2013-04-03 02:23:22 +02:00
|
|
|
{
|
|
|
|
return m_visualParent.data();
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
void ToolTip::setVisualParent(QQuickItem *visualParent)
|
2013-04-03 02:23:22 +02:00
|
|
|
{
|
|
|
|
if (m_visualParent.data() == visualParent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visualParent) {
|
2013-04-04 22:14:56 +02:00
|
|
|
//setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
2013-04-03 02:23:22 +02:00
|
|
|
}
|
|
|
|
emit visualParentChanged();
|
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
bool ToolTip::isVisible() const
|
2013-04-03 02:23:22 +02:00
|
|
|
{
|
2013-04-04 22:14:56 +02:00
|
|
|
//return QQuickWindow::isVisible();
|
|
|
|
return true;
|
2013-04-03 02:23:22 +02:00
|
|
|
}
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
void ToolTip::setVisible(const bool visible)
|
2013-04-03 02:23:22 +02:00
|
|
|
{
|
2013-04-05 01:10:53 +02:00
|
|
|
ToolTipDialog *dlg = ToolTipDialog::instance();
|
2013-04-03 02:23:22 +02:00
|
|
|
qDebug() << visible;
|
|
|
|
if (visible) {
|
2013-04-05 04:27:52 +02:00
|
|
|
//dlg->mainItem()->deleteLater();
|
|
|
|
|
|
|
|
// QObject *myObject = m_mainComponent.data()->create();
|
|
|
|
// QQuickItem *item = qobject_cast<QQuickItem*>(myObject);
|
|
|
|
qDebug() << "XXX Setting visible: " << mainItem();
|
|
|
|
setMainItem(mainItem());
|
|
|
|
|
|
|
|
qDebug() << "XXX showing tooltip: " << ToolTipDialog::instance();
|
2013-04-05 01:10:53 +02:00
|
|
|
dlg->setMainItem(mainItem());
|
|
|
|
dlg->setVisualParent(m_visualParent.data());
|
|
|
|
dlg->setPosition(dlg->popupPosition(visualParent()));
|
|
|
|
dlg->setVisible(true);
|
|
|
|
|
2013-04-04 22:14:56 +02:00
|
|
|
// syncGeometry();
|
|
|
|
// raise();
|
2013-04-05 01:10:53 +02:00
|
|
|
} else {
|
|
|
|
dlg->setVisible(false);
|
2013-04-05 04:27:52 +02:00
|
|
|
//dlg->mainItem()->deleteLater();
|
2013-04-03 02:23:22 +02:00
|
|
|
}
|
2013-04-04 22:14:56 +02:00
|
|
|
//QQuickWindow::setVisible(visible);
|
2013-04-03 02:23:22 +02:00
|
|
|
}
|
2011-04-27 19:33:29 -03:00
|
|
|
|