153 lines
5.0 KiB
C++
Raw Normal View History

/***************************************************************************
* 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 "tooltip.h"
#include "tooltipdialog.h"
#include <QQuickItem>
#include <QDebug>
#include <QTimer>
#include "framesvgitem.h"
#include <kwindoweffects.h>
2013-04-04 22:14:56 +02:00
ToolTip::ToolTip(QObject *parent)
: QObject(parent)
{
}
2013-04-04 22:14:56 +02:00
ToolTip::~ToolTip()
{
}
2013-04-04 22:14:56 +02:00
QQuickItem *ToolTip::target() const
{
return m_target.data();
}
2013-04-04 22:14:56 +02:00
void ToolTip::setTarget(QQuickItem *target)
{
if (m_target.data() != target) {
m_target = target;
emit targetChanged();
}
}
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
{
return m_mainItem.data();
}
2013-04-04 22:14:56 +02:00
void ToolTip::setMainItem(QQuickItem *mainItem)
{
qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
if (m_mainItem.data() != mainItem) {
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);
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);
qDebug() << "XXX new mainITem connected";
2013-04-04 22:14:56 +02:00
//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();
}
}
2013-04-04 22:14:56 +02:00
QQuickItem *ToolTip::visualParent() const
{
return m_visualParent.data();
}
2013-04-04 22:14:56 +02:00
void ToolTip::setVisualParent(QQuickItem *visualParent)
{
if (m_visualParent.data() == visualParent) {
return;
}
if (visualParent) {
2013-04-04 22:14:56 +02:00
//setPosition(popupPosition(visualParent, Qt::AlignCenter));
}
emit visualParentChanged();
}
2013-04-04 22:14:56 +02:00
bool ToolTip::isVisible() const
{
2013-04-04 22:14:56 +02:00
//return QQuickWindow::isVisible();
return true;
}
2013-04-04 22:14:56 +02:00
void ToolTip::setVisible(const bool visible)
{
ToolTipDialog *dlg = ToolTipDialog::instance();
qDebug() << visible;
if (visible) {
//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();
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();
} else {
dlg->setVisible(false);
//dlg->mainItem()->deleteLater();
}
2013-04-04 22:14:56 +02:00
//QQuickWindow::setVisible(visible);
}