Improve PlasmaCore.ToolTip

- Derive from MouseEventListener as to let input through
- react to target changes: reparent the MEL accordingly
- kill a bunch of warnings

This "helps" a bit, but still filters out input events since the MEL
only passes events down to children, but the tooltip's target becomes
its parent.

Reparenting the target crashes, and it seems a pretty ugly thing to do,
anyway, since we don't want to mess with the scenegraph structure just
to filter events out for tooltips. Grmblz.
This commit is contained in:
Sebastian Kügler 2014-01-05 04:26:29 +01:00
parent 23b9dd14f1
commit 8c797fce42

View File

@ -21,6 +21,7 @@ import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.qtextracomponents 2.0 as QtExtras
/**
* An Item managing a Plasma-themed tooltip. It is rendered in its own window.
@ -53,7 +54,7 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
* @endcode
*
*/
MouseArea {
QtExtras.MouseEventListener {
id: tooltip
property string mainText // title text of the tooltip
@ -65,8 +66,22 @@ MouseArea {
hoverEnabled: true
onEntered: show();
onExited: hide();
onContainsMouseChanged: {
// hide immediately, show after a while
tooltipTimer.interval = tooltip.containsMouse ? 500 : 0;
tooltipTimer.start();
}
Timer {
id: tooltipTimer
onTriggered: {
if (tooltip.containsMouse) {
show();
} else {
hide();
}
}
}
function show() {
var mi = tooltip.mainItem;
@ -85,7 +100,9 @@ MouseArea {
function hide() {
tooltipWindow.visible = false;
tooltipWindow.mainItem.destroy();
if (tooltipWindow.mainItem != null) {
tooltipWindow.mainItem.destroy();
}
}
Component {
@ -115,11 +132,11 @@ MouseArea {
PlasmaCore.IconItem {
id: tooltipIcon
width: theme.iconSizes.desktop
width: iconSource != "" ? theme.iconSizes.desktop : 0
height: width
source: iconSource
anchors {
leftMargin: _s
leftMargin: width != 0 ? _s : 0
}
}
PlasmaExtras.Heading {
@ -153,4 +170,10 @@ MouseArea {
id: tooltipWindow
visualParent: tooltip.target
}
onTargetChanged: {
print("Target changed");
tooltip.parent = target;
//target.visualParent = tooltip
anchors.fill = target
}
}