kill tooltipwindow implementation
We use a dialog subclass-singleton now. I love the smell of dead code in the morning.
This commit is contained in:
parent
4c21d54980
commit
2cc96aac45
@ -20,7 +20,6 @@ set(corebindings_SRCS
|
|||||||
dialog.cpp
|
dialog.cpp
|
||||||
tooltip.cpp
|
tooltip.cpp
|
||||||
tooltipdialog.cpp
|
tooltipdialog.cpp
|
||||||
tooltipwindow.cpp
|
|
||||||
dataenginebindings.cpp
|
dataenginebindings.cpp
|
||||||
iconitem.cpp
|
iconitem.cpp
|
||||||
plasmanamespace.cpp
|
plasmanamespace.cpp
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "dialog.h"
|
#include "dialog.h"
|
||||||
#include "iconitem.h"
|
#include "iconitem.h"
|
||||||
#include "tooltipwindow.h"
|
|
||||||
|
|
||||||
#include "tooltip.h"
|
#include "tooltip.h"
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
|
|||||||
qmlRegisterType<Plasma::FrameSvg>(uri, 2, 0, "FrameSvg");
|
qmlRegisterType<Plasma::FrameSvg>(uri, 2, 0, "FrameSvg");
|
||||||
qmlRegisterType<Plasma::SvgItem>(uri, 2, 0, "SvgItem");
|
qmlRegisterType<Plasma::SvgItem>(uri, 2, 0, "SvgItem");
|
||||||
qmlRegisterType<Plasma::FrameSvgItem>(uri, 2, 0, "FrameSvgItem");
|
qmlRegisterType<Plasma::FrameSvgItem>(uri, 2, 0, "FrameSvgItem");
|
||||||
|
|
||||||
qmlRegisterType<ThemeProxy>(uri, 2, 0, "Theme");
|
qmlRegisterType<ThemeProxy>(uri, 2, 0, "Theme");
|
||||||
|
|
||||||
qmlRegisterType<Plasma::DataSource>(uri, 2, 0, "DataSource");
|
qmlRegisterType<Plasma::DataSource>(uri, 2, 0, "DataSource");
|
||||||
@ -92,7 +91,6 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
|
|||||||
qmlRegisterType<Plasma::SortFilterModel>(uri, 2, 0, "SortFilterModel");
|
qmlRegisterType<Plasma::SortFilterModel>(uri, 2, 0, "SortFilterModel");
|
||||||
|
|
||||||
qmlRegisterType<DialogProxy>(uri, 2, 0, "Dialog");
|
qmlRegisterType<DialogProxy>(uri, 2, 0, "Dialog");
|
||||||
qmlRegisterType<ToolTipWindow>(uri, 2, 0, "ToolTipWindow");
|
|
||||||
qmlRegisterType<ToolTip>(uri, 2, 0, "ToolTipProxy");
|
qmlRegisterType<ToolTip>(uri, 2, 0, "ToolTipProxy");
|
||||||
|
|
||||||
qmlRegisterInterface<Plasma::Service>("Service");
|
qmlRegisterInterface<Plasma::Service>("Service");
|
||||||
|
@ -1,225 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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<QQuickItem *>(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,129 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
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