diff --git a/src/declarativeimports/core/CMakeLists.txt b/src/declarativeimports/core/CMakeLists.txt index 350052973..e109a1b57 100644 --- a/src/declarativeimports/core/CMakeLists.txt +++ b/src/declarativeimports/core/CMakeLists.txt @@ -20,7 +20,6 @@ set(corebindings_SRCS dialog.cpp tooltip.cpp tooltipdialog.cpp - tooltipwindow.cpp dataenginebindings.cpp iconitem.cpp plasmanamespace.cpp diff --git a/src/declarativeimports/core/corebindingsplugin.cpp b/src/declarativeimports/core/corebindingsplugin.cpp index 045bf2125..9b2a9c1ec 100644 --- a/src/declarativeimports/core/corebindingsplugin.cpp +++ b/src/declarativeimports/core/corebindingsplugin.cpp @@ -40,7 +40,6 @@ #include "theme.h" #include "dialog.h" #include "iconitem.h" -#include "tooltipwindow.h" #include "tooltip.h" @@ -84,7 +83,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 2, 0, "FrameSvg"); qmlRegisterType(uri, 2, 0, "SvgItem"); qmlRegisterType(uri, 2, 0, "FrameSvgItem"); - + qmlRegisterType(uri, 2, 0, "Theme"); qmlRegisterType(uri, 2, 0, "DataSource"); @@ -92,7 +91,6 @@ void CoreBindingsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 2, 0, "SortFilterModel"); qmlRegisterType(uri, 2, 0, "Dialog"); - qmlRegisterType(uri, 2, 0, "ToolTipWindow"); qmlRegisterType(uri, 2, 0, "ToolTipProxy"); qmlRegisterInterface("Service"); diff --git a/src/declarativeimports/core/tooltipwindow.cpp b/src/declarativeimports/core/tooltipwindow.cpp deleted file mode 100644 index 87cd5fb65..000000000 --- a/src/declarativeimports/core/tooltipwindow.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/*************************************************************************** - * Copyright 2011 Marco Martin * - * Copyright 2011 Artur Duque de Souza * - * Copyright 2013 Sebastian Kügler * - * * - * 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 -#include -#include - -#include "framesvgitem.h" -#include - -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); -} - -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(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() -{ - resize(mainItem()->width(), mainItem()->height()); - setPosition(popupPosition(visualParent())); - - Plasma::FrameSvgItem *frameSvg = qobject_cast(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(); -} - -QQuickItem *ToolTipWindow::mainItem() const -{ - return m_mainItem.data(); -} - -void ToolTipWindow::setMainItem(QQuickItem *mainItem) -{ - if (m_mainItem.data() != 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) { - 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 Component.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); - - 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) { - syncGeometry(); - raise(); - } - QQuickWindow::setVisible(visible); -} - -QPoint ToolTipWindow::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment) -{ - // FIXME :: Item - if (!item) { - item = qobject_cast(visualParent()); - } - if (item && item->window()) { - QPointF itemScreenPos; - - QPointF pos = item->mapToScene(QPointF(0, 0)); - 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); - } -} - diff --git a/src/declarativeimports/core/tooltipwindow.h b/src/declarativeimports/core/tooltipwindow.h deleted file mode 100644 index cb28bea57..000000000 --- a/src/declarativeimports/core/tooltipwindow.h +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************** - * Copyright 2011 Marco Martin * - * Copyright 2011 Artur Duque de Souza * - * Copyright 2013 Sebastian Kügler * - * * - * 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 -#include -#include -#include - -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(); - -private: - QTimer *m_syncTimer; - QString m_mainText; - QString m_subText; - QVariant m_image; - QGraphicsWidget *m_widget; - QWeakPointer m_mainItem; - QWeakPointer m_visualParent; - QWeakPointer m_declarativeItemContainer; - QWeakPointer m_target; -}; - -#endif