Start rewrite of tooltip
ToolTipProxy is now a QQuickWindow and renamed to ToolTipWindow. This is done in C++. ToolTip itself is a QML file, which internally uses tooltipwindow to display the attached item. Basic showing / hiding and embedding an Item works, positioning, margins, etc are not implemented yet. Neither are special windowmanager hints and flags.
This commit is contained in:
parent
1c5faf9271
commit
a6526d7bbe
@ -38,6 +38,6 @@ target_link_libraries(corebindingsplugin
|
||||
plasma)
|
||||
|
||||
install(TARGETS corebindingsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/core)
|
||||
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/core)
|
||||
install(FILES qmldir ToolTip.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/core)
|
||||
|
||||
#add_subdirectory(tests)
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "theme.h"
|
||||
#include "dialog.h"
|
||||
#include "iconitem.h"
|
||||
// #include "tooltip.h"
|
||||
#include "tooltip.h"
|
||||
// #include "dataenginebindings_p.h"
|
||||
#include "plasmanamespace.h"
|
||||
|
||||
@ -89,8 +89,8 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
|
||||
qmlRegisterType<Plasma::SortFilterModel>(uri, 2, 0, "SortFilterModel");
|
||||
|
||||
qmlRegisterType<DialogProxy>(uri, 2, 0, "Dialog");
|
||||
// qmlRegisterType<ToolTipProxy>(uri, 2, 0, "ToolTip");
|
||||
//
|
||||
qmlRegisterType<ToolTipWindow>(uri, 2, 0, "ToolTipWindow");
|
||||
|
||||
qmlRegisterInterface<Plasma::Service>("Service");
|
||||
qRegisterMetaType<Plasma::Service*>("Service");
|
||||
qmlRegisterInterface<Plasma::ServiceJob>("ServiceJob");
|
||||
|
@ -1,3 +1,6 @@
|
||||
module org.kde.plasma.core
|
||||
plugin corebindingsplugin
|
||||
|
||||
ToolTip 2.0 ToolTip.qml
|
||||
|
||||
|
||||
|
@ -35,6 +35,22 @@
|
||||
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::FramelessWindowHint);
|
||||
// tooltipDialog.setAttribute(Qt.WA_X11NetWmWindowTypeToolTip, true)
|
||||
// tooltipDialog.windowFlags = Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint
|
||||
|
||||
//m_flags = flags();
|
||||
|
||||
m_syncTimer = new QTimer(this);
|
||||
m_syncTimer->setSingleShot(true);
|
||||
m_syncTimer->setInterval(250);
|
||||
// connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize);
|
||||
|
||||
connect(this, SIGNAL(targetChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(mainTextChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(subTextChanged()), this, SLOT(updateToolTip()));
|
||||
@ -194,5 +210,91 @@ void ToolTipWindow::updateToolTip()
|
||||
//Plasma::ToolTipManager::self()->setContent(m_widget, data);
|
||||
}
|
||||
|
||||
QQuickItem *ToolTipWindow::mainItem() const
|
||||
{
|
||||
return m_mainItem.data();
|
||||
}
|
||||
|
||||
void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
||||
{
|
||||
qDebug() << "mainitem changed: " << mainItem->width() << mainItem->height();
|
||||
|
||||
//resize(mainItem->width(), mainItem->height());
|
||||
|
||||
resize(200, 200);
|
||||
if (m_mainItem.data() != mainItem) {
|
||||
if (m_mainItem) {
|
||||
m_mainItem.data()->setParent(parent());
|
||||
}
|
||||
|
||||
m_mainItem = mainItem;
|
||||
|
||||
if (mainItem) {
|
||||
//mainItem->setParentItem(0);
|
||||
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));
|
||||
}
|
||||
|
||||
m_visualParent = visualParent;
|
||||
emit visualParentChanged();
|
||||
}
|
||||
|
||||
|
||||
bool ToolTipWindow::isVisible() const
|
||||
{
|
||||
return QQuickWindow::isVisible();
|
||||
|
||||
}
|
||||
|
||||
void ToolTipWindow::setVisible(const bool visible)
|
||||
{
|
||||
qDebug() << visible;
|
||||
if (visible) {
|
||||
setPosition(popupPosition());
|
||||
raise();
|
||||
}
|
||||
QQuickWindow::setVisible(visible);
|
||||
}
|
||||
|
||||
QPoint ToolTipWindow::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
||||
{
|
||||
// FIXME :: Item
|
||||
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
|
||||
if (parentItem && parentItem->window()) {
|
||||
qDebug() << "NO visual parent ... Centering at " << (parentItem->window()->geometry().center() - QPoint(width()/2, height()/2));
|
||||
qDebug() << parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
||||
return parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
||||
} else {
|
||||
qDebug() << "No QQuickItem as parent found";
|
||||
return QPoint();
|
||||
}
|
||||
}
|
||||
//#include "tooltip.moc"
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#ifndef TOOLTIP_WINDOW_P
|
||||
#define TOOLTIP_WINDOW_P
|
||||
|
||||
#include <QTimer>
|
||||
#include <QQuickWindow>
|
||||
#include <QWeakPointer>
|
||||
#include <QtCore/QVariant>
|
||||
@ -57,6 +58,22 @@ class ToolTipWindow : public QQuickWindow
|
||||
*/
|
||||
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();
|
||||
@ -73,21 +90,38 @@ public:
|
||||
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 syncTarget();
|
||||
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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user