diff --git a/examples/applets/testcomponents/contents/ui/IconsPage.qml b/examples/applets/testcomponents/contents/ui/IconsPage.qml index d1d041011..a73e7c9b4 100644 --- a/examples/applets/testcomponents/contents/ui/IconsPage.qml +++ b/examples/applets/testcomponents/contents/ui/IconsPage.qml @@ -91,103 +91,67 @@ PlasmaComponents.Page { Row { spacing: _s - PlasmaCore.IconItem { - id: akonadiIcon - objectName: "akonadiIcon" - source: "akonadi" - width: height - height: _h - //anchors.horizontalCenter: parent.horizontalCenter - Rectangle { color: "orange"; opacity: 0.3; anchors.fill: parent; } - PlasmaCore.ToolTip { - anchors.fill: parent - target: akonadiIcon - icon: "klipper" - mainText: "Fish sighted in the wild, in the wild, a fish was seen." - subText: "A mean-looking grouper swam by." + PlasmaCore.ToolTipArea { + width: childrenRect.width + height: childrenRect.height + icon: "klipper" + mainText: "Fish sighted in the wild, in the wild, a fish was seen." + subText: "A mean-looking grouper swam by." + PlasmaCore.IconItem { + id: akonadiIcon + objectName: "akonadiIcon" + source: "akonadi" + width: height + height: _h + //anchors.horizontalCenter: parent.horizontalCenter + Rectangle { color: "orange"; opacity: 0.3; anchors.fill: parent; } } } - Image { - objectName: "bridgeimage" + PlasmaCore.ToolTipArea { height: _h width: height - fillMode: Image.PreserveAspectFit - source: "../images/bridge.jpg" - PlasmaCore.ToolTip { - target: parent - image: parent.source - mainText: "Bridge" - subText: "Waalbrug." + image: bridgeimage.source + mainText: "Bridge" + subText: "Waalbrug." + Image { + id: bridgeimage + objectName: "bridgeimage" + height: _h + width: height + fillMode: Image.PreserveAspectFit + source: "../images/bridge.jpg" } } - Image { - objectName: "surfboardimage" - height: _h - width: height - fillMode: Image.PreserveAspectFit - source: "../images/surfboard.jpg" - PlasmaCore.ToolTip { - anchors.fill: parent - image: parent.source - mainItem: PlasmaComponents.Label { - text: "Nijmegen North Beach" - anchors.centerIn: parent - } + PlasmaCore.ToolTipArea { + width: childrenRect.width + height: childrenRect.height + mainItem: PlasmaComponents.Label { + text: "Nijmegen North Beach" + anchors.centerIn: parent + } + Image { + objectName: "surfboardimage" + height: _h + width: height + fillMode: Image.PreserveAspectFit + source: "../images/surfboard.jpg" //subText: "A surfboard on the beach.
The photo shows the Waal river's north beach, \ //across the water from Nijmegen, Netherlands. It was taken during the summer festivals a few years back." } } - PlasmaComponents.Button { - text: "Button" - iconSource: "call-start" - PlasmaCore.ToolTip { - target: parent - mainText: "Tooltip on button" - } - } - - - QtExtras.MouseEventListener { - id: task1 - - width: height - height: _h*2 - - hoverEnabled: true - - onContainsMouseChanged: { - if (containsMouse) { - print("Setting target to task1"); - tooltip.target = task1; - tooltip.mainText = "Bridge" - tooltip.subText = "in Nijmegen" - } else { - print("Setting target to null"); - tooltip.target = null; - } - } - Image { - objectName: "bridgeimage1" - anchors.fill: parent - fillMode: Image.PreserveAspectFit - source: "../images/bridge.jpg" - MouseArea { - anchors.fill: parent - onClicked: { - print("bridgeimage1 clicked"); - } - } + PlasmaCore.ToolTipArea { + width: childrenRect.width + height: childrenRect.height + mainText: "Tooltip on button" + PlasmaComponents.Button { + id: button + text: "Button" + iconSource: "call-start" } } } } - - PlasmaCore.ToolTip { - id: tooltip - target: null - } - } diff --git a/src/declarativeimports/core/corebindingsplugin.cpp b/src/declarativeimports/core/corebindingsplugin.cpp index 762e08d6c..b541875a2 100644 --- a/src/declarativeimports/core/corebindingsplugin.cpp +++ b/src/declarativeimports/core/corebindingsplugin.cpp @@ -85,7 +85,7 @@ 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, "ToolTipArea"); qmlRegisterInterface("Service"); qRegisterMetaType("Service"); diff --git a/src/declarativeimports/core/private/DefaultToolTip.qml b/src/declarativeimports/core/private/DefaultToolTip.qml index 83eb1c3f0..a844ea999 100644 --- a/src/declarativeimports/core/private/DefaultToolTip.qml +++ b/src/declarativeimports/core/private/DefaultToolTip.qml @@ -90,7 +90,6 @@ Item { PlasmaExtras.Heading { id: tooltipMaintext level: 3 - width: parent.preferredTextWidth wrapMode: Text.WordWrap text: toolTip ? toolTip.mainText : "" anchors { diff --git a/src/declarativeimports/core/tooltip.cpp b/src/declarativeimports/core/tooltip.cpp index d7f8bb80f..3162b8bfe 100644 --- a/src/declarativeimports/core/tooltip.cpp +++ b/src/declarativeimports/core/tooltip.cpp @@ -35,9 +35,11 @@ ToolTip::ToolTip(QQuickItem *parent) m_showTimer = new QTimer(this); m_showTimer->setSingleShot(true); connect(m_showTimer, &QTimer::timeout, [=]() { - setVisible(true); + showToolTip(); }); + setAcceptHoverEvents(true); + setFiltersChildMouseEvents(true); } ToolTip::~ToolTip() @@ -58,60 +60,26 @@ void ToolTip::setMainItem(QQuickItem *mainItem) } } -QQuickItem *ToolTip::target() const -{ - if (m_target.data()) { - return m_target.data(); - } else { - QQuickItem *qqi = qobject_cast(parent()); - return qqi; - } -} - -void ToolTip::setTarget(QQuickItem *target) -{ - if (m_target.data() == target) { - return; - } - - m_target = target; - setParentItem(target); - - property("anchors").value()->setProperty("fill", QVariant::fromValue(parentItem())); - - emit targetChanged(); -} - -bool ToolTip::isVisible() const +void ToolTip::showToolTip() { ToolTipDialog *dlg = ToolTipDialog::instance(); - return (dlg->mainItem() == mainItem() && mainItem() && mainItem()->isVisible()); -} -void ToolTip::setVisible(const bool visible) -{ - ToolTipDialog *dlg = ToolTipDialog::instance(); - if (visible) { - - if (!mainItem()) { - setMainItem(dlg->loadDefaultItem()); - } - - if (dlg->mainItem()) { - dlg->mainItem()->setVisible(false); - } - - if (mainItem()) { - mainItem()->setProperty("toolTip", QVariant::fromValue(this)); - mainItem()->setVisible(true); - } - - dlg->setMainItem(mainItem()); - dlg->setVisualParent(target()); - dlg->setVisible(true); - } else { - dlg->setVisible(false); + if (!mainItem()) { + setMainItem(dlg->loadDefaultItem()); } + + if (dlg->mainItem()) { + dlg->mainItem()->setVisible(false); + } + + if (mainItem()) { + mainItem()->setProperty("toolTip", QVariant::fromValue(this)); + mainItem()->setVisible(true); + } + + dlg->setMainItem(mainItem()); + dlg->setVisible(true); + dlg->setVisualParent(this); } QString ToolTip::mainText() const @@ -185,24 +153,20 @@ void ToolTip::setImage(const QVariant &image) void ToolTip::hoverEnterEvent(QHoverEvent *event) { if (ToolTipDialog::instance()->isVisible()) { - //FIXME: setVisible needs to be renamed in sync or something like that - setVisible(true); + //FIXME: showToolTip needs to be renamed in sync or something like that + showToolTip(); } else { m_showTimer->start(500); } - - //relay the event - if (window()) { - window()->sendEvent(target(), event); - } } void ToolTip::hoverLeaveEvent(QHoverEvent *event) { m_showTimer->stop(); - - //relay the event - if (window()) { - window()->sendEvent(target(), event); - } } + +bool ToolTip::childMouseEventFilter(QQuickItem *item, QEvent *event) +{ + return QQuickItem::childMouseEventFilter(item, event); +} + diff --git a/src/declarativeimports/core/tooltip.h b/src/declarativeimports/core/tooltip.h index 37d6d8f24..771589cb3 100644 --- a/src/declarativeimports/core/tooltip.h +++ b/src/declarativeimports/core/tooltip.h @@ -43,16 +43,6 @@ class ToolTip : public QQuickItem */ Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged) - /** - * The main QML item that will be displayed in the Dialog - */ - Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged) - - /** - * 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) - /** * The main text of this tooltip */ @@ -81,11 +71,7 @@ public: QQuickItem *mainItem() const; void setMainItem(QQuickItem *mainItem); - QQuickItem *target() const; - void setTarget(QQuickItem *target); - - bool isVisible() const; - void setVisible(const bool visible); + void showToolTip(); QString mainText() const; void setMainText(const QString &mainText); @@ -100,12 +86,12 @@ public: void setImage(const QVariant &image); protected: + bool childMouseEventFilter(QQuickItem *item, QEvent *event); void hoverEnterEvent(QHoverEvent *event); void hoverLeaveEvent(QHoverEvent *event); Q_SIGNALS: void mainItemChanged(); - void targetChanged(); void visibleChanged(); void mainTextChanged(); void subTextChanged(); @@ -114,7 +100,6 @@ Q_SIGNALS: private: QWeakPointer m_mainItem; - QWeakPointer m_target; QTimer *m_showTimer; QString m_mainText; QString m_subText; diff --git a/src/plasmaquick/packageurlinterceptor.cpp b/src/plasmaquick/packageurlinterceptor.cpp index 14e25af1d..293a8f359 100644 --- a/src/plasmaquick/packageurlinterceptor.cpp +++ b/src/plasmaquick/packageurlinterceptor.cpp @@ -60,7 +60,7 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept if (path.scheme() == QStringLiteral("plasmapackage")) { //FIXME: this is incorrect but works around a bug in qml in resolution of urls of qmldir files - if (type == QQmlAbstractUrlInterceptor::QmldirFile) { + if (0&&type == QQmlAbstractUrlInterceptor::QmldirFile) { return QUrl(m_package.filePath(0, path.path())); } else { return QUrl::fromLocalFile(m_package.filePath(0, path.path()));