From 7e6d750f2a2864889c2f940ca096ad404fca8317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Thu, 4 Apr 2013 01:46:02 +0200 Subject: [PATCH] Window size synching with tooltip content --- src/declarativeimports/core/ToolTip.qml | 35 ++++++----- src/declarativeimports/core/tooltip.cpp | 60 +++++-------------- src/declarativeimports/core/tooltip.h | 2 +- .../contents/ui/IconsPage.qml | 2 + 4 files changed, 39 insertions(+), 60 deletions(-) diff --git a/src/declarativeimports/core/ToolTip.qml b/src/declarativeimports/core/ToolTip.qml index fa7d91f11..6dc5b84cb 100644 --- a/src/declarativeimports/core/ToolTip.qml +++ b/src/declarativeimports/core/ToolTip.qml @@ -39,27 +39,32 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras */ MouseArea { + property alias mainText: tooltipWindow.mainText + property alias subText: tooltipWindow.subText + property alias image: tooltipWindow.image + + property int _s: theme.iconSizes.small / 2 hoverEnabled: true onEntered: { print("entere"); - toolTipWindow.visible = true; - toolTipHideTimer.running = false; - print(" ttsvg: w " + toolTipSvg.width); - print(" ttsvg: h " + toolTipSvg.height); + tooltipWindow.visible = true; + tooltipHideTimer.running = false; + print(" ttsvg: w " + tooltipSvg.width); + print(" ttsvg: h " + tooltipSvg.height); } onExited: { print("exit"); - toolTipHideTimer.running = true + tooltipHideTimer.running = true } Timer { - id: toolTipHideTimer + id: tooltipHideTimer running: false repeat: false interval: 100 @@ -67,15 +72,15 @@ MouseArea { onTriggered: { print("Hiding tooltip ..."); - toolTipWindow.visible = false; + tooltipWindow.visible = false; } } PlasmaCore.ToolTipWindow { - id: toolTipWindow + id: tooltipWindow mainItem: PlasmaCore.FrameSvgItem { - id: toolTipSvg + id: tooltipSvg imagePath: "widgets/tooltip" width: childrenRect.width + margins.left + margins.right height: childrenRect.height + margins.top + margins.bottom @@ -84,9 +89,9 @@ MouseArea { onChildrenRectChanged: print("XXXX childrenRect chagned" + childrenRect.width + " " + childrenRect.height) Item { - id: toolTipContentItem - x: toolTipSvg.margins.left - y: toolTipSvg.margins.top + id: tooltipContentItem + x: tooltipSvg.margins.left + y: tooltipSvg.margins.top width: childrenRect.width height: childrenRect.height anchors { @@ -95,6 +100,8 @@ MouseArea { //fill: parent } + // FIXME: Image { source: tooltipWindow.image } + PlasmaCore.IconItem { id: tooltipIcon width: theme.iconSizes.desktop @@ -108,7 +115,7 @@ MouseArea { PlasmaExtras.Heading { id: tooltipMaintext level: 4 - text: "Emperor fish sighted" + text: tooltipWindow.mainText anchors { left: tooltipIcon.right leftMargin: _s @@ -118,7 +125,7 @@ MouseArea { } PlasmaComponents.Label { id: tooltipSubtext - text: "You've come across a beautiful sea creature" + text: tooltipWindow.subText anchors { left: tooltipIcon.right leftMargin: _s diff --git a/src/declarativeimports/core/tooltip.cpp b/src/declarativeimports/core/tooltip.cpp index 60f6767bd..76896f06e 100644 --- a/src/declarativeimports/core/tooltip.cpp +++ b/src/declarativeimports/core/tooltip.cpp @@ -40,7 +40,7 @@ ToolTipWindow::ToolTipWindow(QWindow *parent) setFormat(format); setClearBeforeRendering(true); setColor(QColor(Qt::transparent)); - setFlags(Qt::FramelessWindowHint); +// setFlags(Qt::FramelessWindowHint); // tooltipDialog.setAttribute(Qt.WA_X11NetWmWindowTypeToolTip, true) // tooltipDialog.windowFlags = Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint @@ -82,46 +82,12 @@ void ToolTipWindow::setTarget(QQuickItem *target) } } -void ToolTipWindow::syncTarget() +void ToolTipWindow::syncGeometry() { - /* - if (!m_target) { - return; - } - // find the scene - QGraphicsScene *scene = m_target.data()->scene(); - if (!scene) { - QObject *parent = m_target.data(); - while ((parent = parent->parent())) { - QQuickItem *qo = qobject_cast(parent); - if (qo && qo->scene()) { - scene = qo->scene(); - scene->addItem(m_target.data()); - break; - } - } - } - - QQuickItem *item = qobject_cast(m_target.data()); - if (!item) { - return; - } - - if (!m_declarativeItemContainer && scene) { - m_declarativeItemContainer = QWeakPointer(new QQuickItem()); - m_declarativeItemContainer.data()->setObjectName("DIContainer"); - scene->addItem(m_declarativeItemContainer.data()); - } - - if (m_declarativeItemContainer) { - m_target.data()->setObjectName("Original Item"); - m_declarativeItemContainer.data()->setDeclarativeItem(item, false); - m_declarativeItemContainer.data()->setAcceptHoverEvents(true); - m_declarativeItemContainer.data()->setParentItem(m_target.data()); - m_widget = m_declarativeItemContainer.data(); - emit targetChanged(); - } - */ + qDebug() << " XXX synching geometry"; + qDebug() << "XXXX mainitem : " << mainItem()->width() << mainItem()->height(); + resize(mainItem()->width(), mainItem()->height()); + setPosition(100, 100); } QString ToolTipWindow::mainText() const @@ -217,20 +183,24 @@ QQuickItem *ToolTipWindow::mainItem() const void ToolTipWindow::setMainItem(QQuickItem *mainItem) { - qDebug() << "mainitem changed: " << mainItem->width() << mainItem->height(); + qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height(); - //resize(mainItem->width(), mainItem->height()); - - resize(400, 200); +// resize(400, 200); if (m_mainItem.data() != mainItem) { + qDebug() << " XXX new 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) { //mainItem->setParentItem(0); + 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())); diff --git a/src/declarativeimports/core/tooltip.h b/src/declarativeimports/core/tooltip.h index 1fabe82bf..856eea4c1 100644 --- a/src/declarativeimports/core/tooltip.h +++ b/src/declarativeimports/core/tooltip.h @@ -111,7 +111,7 @@ Q_SIGNALS: void visibleChanged(); protected Q_SLOTS: - void syncTarget(); + void syncGeometry(); void updateToolTip(); private: diff --git a/src/shell/applets/testcomponentsapplet/contents/ui/IconsPage.qml b/src/shell/applets/testcomponentsapplet/contents/ui/IconsPage.qml index c9d5855e8..13d119d56 100644 --- a/src/shell/applets/testcomponentsapplet/contents/ui/IconsPage.qml +++ b/src/shell/applets/testcomponentsapplet/contents/ui/IconsPage.qml @@ -97,6 +97,8 @@ PlasmaComponents.Page { PlasmaCore.ToolTip { anchors.fill: parent + mainText: "Fish sighted" + subText: "A mean-looking grouper swam by" } }