diff --git a/src/declarativeimports/core/CMakeLists.txt b/src/declarativeimports/core/CMakeLists.txt index ac7ff4abd..ea30753f3 100644 --- a/src/declarativeimports/core/CMakeLists.txt +++ b/src/declarativeimports/core/CMakeLists.txt @@ -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) diff --git a/src/declarativeimports/core/corebindingsplugin.cpp b/src/declarativeimports/core/corebindingsplugin.cpp index 6ce4b6aa6..103645adf 100644 --- a/src/declarativeimports/core/corebindingsplugin.cpp +++ b/src/declarativeimports/core/corebindingsplugin.cpp @@ -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(uri, 2, 0, "SortFilterModel"); qmlRegisterType(uri, 2, 0, "Dialog"); -// qmlRegisterType(uri, 2, 0, "ToolTip"); -// + qmlRegisterType(uri, 2, 0, "ToolTipWindow"); + qmlRegisterInterface("Service"); qRegisterMetaType("Service"); qmlRegisterInterface("ServiceJob"); diff --git a/src/declarativeimports/core/qmldir b/src/declarativeimports/core/qmldir index fcc172494..ce00c421d 100644 --- a/src/declarativeimports/core/qmldir +++ b/src/declarativeimports/core/qmldir @@ -1,3 +1,6 @@ module org.kde.plasma.core plugin corebindingsplugin +ToolTip 2.0 ToolTip.qml + + diff --git a/src/declarativeimports/core/tooltip.cpp b/src/declarativeimports/core/tooltip.cpp index f9fe6e4cf..398a92307 100644 --- a/src/declarativeimports/core/tooltip.cpp +++ b/src/declarativeimports/core/tooltip.cpp @@ -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(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" diff --git a/src/declarativeimports/core/tooltip.h b/src/declarativeimports/core/tooltip.h index c42c6d226..1fabe82bf 100644 --- a/src/declarativeimports/core/tooltip.h +++ b/src/declarativeimports/core/tooltip.h @@ -21,6 +21,7 @@ #ifndef TOOLTIP_WINDOW_P #define TOOLTIP_WINDOW_P +#include #include #include #include @@ -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 m_mainItem; + QWeakPointer m_visualParent; QWeakPointer m_declarativeItemContainer; QWeakPointer m_target; };