aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Gottfried <sebastiangottfried@web.de>2016-09-29 15:30:39 (GMT)
committerSebastian Gottfried <sebastiangottfried@web.de>2016-09-29 15:30:54 (GMT)
commit9b3d7ca0cfd4618bcc58dbc80b9a9b11c115dc77 (patch)
tree6c8786fddcb1baba8bfe89e34587e6b2e309a9e2
parent9f74db1af586f43d5bc1b177b6e9dc90704b26a9 (diff)
Qt5: Port Balloon.qml
-rw-r--r--images/CMakeLists.txt1
-rw-r--r--images/balloontip.svgzbin0 -> 1065 bytes
-rw-r--r--src/qml/Balloon.qml249
3 files changed, 125 insertions, 125 deletions
diff --git a/images/CMakeLists.txt b/images/CMakeLists.txt
index 99bf298..6949444 100644
--- a/images/CMakeLists.txt
+++ b/images/CMakeLists.txt
@@ -2,6 +2,7 @@ set(image_files
accuracymeter-background.png
accuracymeter-scale.png
accuracymeter-hand.png
+ balloontip.svgz
charactersperminutemeter-background.png
charactersperminutemeter-scale.png
charactersperminutemeter-hand.png
diff --git a/images/balloontip.svgz b/images/balloontip.svgz
new file mode 100644
index 0000000..95dc239
--- /dev/null
+++ b/images/balloontip.svgz
Binary files differ
diff --git a/src/qml/Balloon.qml b/src/qml/Balloon.qml
index 0969c1f..333d566 100644
--- a/src/qml/Balloon.qml
+++ b/src/qml/Balloon.qml
@@ -1,5 +1,6 @@
/*
* Copyright 2012 Marco Martin <mart@kde.org>
+ * Copyright 2015 Sebastian Gottfried <sebastiangottfried@web.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@@ -17,156 +18,154 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import QtQuick 1.1
-import org.kde.plasma.core 0.1 as PlasmaCore
-import org.kde.plasma.extras 0.1 as PlasmaExtras
-import org.kde.plasma.components 0.1 as PlasmaComponents
+import QtQuick 2.4
+import QtGraphicalEffects 1.0
-Item {
+Loader {
id: root
property Item visualParent
- z: 9000
- property int status: PlasmaComponents.DialogStatus.Closed
- default property alias data: contentItem.data
+ property string status: 'closed'
+ default property Item data
+ active: status != 'closed'
function open()
{
- if (root.visualParent) {
- internal.parentPos = root.visualParent.mapToItem(dismissArea.parent, 0, 0)
- }
- root.status = PlasmaComponents.DialogStatus.Opening
- appearAnimation.restart()
+ root.status = 'loading'
}
function close()
{
- root.status = PlasmaComponents.DialogStatus.Closing
- appearAnimation.restart()
+ root.status = 'closing'
}
- SequentialAnimation {
- id: appearAnimation
- NumberAnimation {
- duration: 250
- easing.type: Easing.InOutQuad
- target: dismissArea
- properties: "opacity"
- to: root.status == PlasmaComponents.DialogStatus.Opening ? 1 : 0
- }
- ScriptAction {
- script: root.status == PlasmaComponents.DialogStatus.Opening ? root.status = PlasmaComponents.DialogStatus.Open : PlasmaComponents.DialogStatus.Closed
- }
- }
+ sourceComponent: Component {
+ MouseArea {
+ id: dismissArea
+ anchors.fill: parent
+ opacity: root.active && (root.status == 'open' || root.status =='opening')? 1 : 0
- MouseArea {
- id: dismissArea
- z: 9000
- anchors.fill: parent
- opacity: 0
-
- //FIXME: this is an hack: it's taking the dialog background making sure no opaque or transparent are selected
- //in Plasma2 we need to have the backingstore blur there as well
- PlasmaExtras.FallbackComponent {
- id: fallbackComponent
- basePath: "desktoptheme"
- candidates: [theme.themeName, "default"]
- property string svgPath: fallbackComponent.filePath("/dialogs/background.svgz")
- }
- Connections {
- target: theme
- //fallback if inline-background doesn't work
- onThemeChanged: {
- fallbackComponent.svgPath = fallbackComponent.filePath("/dialogs/background.svgz")
- shadowFrame.visible = backgroundSvg.hasElement("shadow-top")
- }
- }
- PlasmaCore.FrameSvgItem {
- id: shadowFrame
- imagePath: fallbackComponent.svgPath
- prefix: "shadow"
- anchors {
- fill: internal
- leftMargin: -margins.left
- topMargin: -margins.top
- rightMargin: -margins.right
- bottomMargin: -margins.bottom
- }
- Component.onCompleted: shadowFrame.visible = backgroundSvg.hasElement("shadow-top")
- }
- PlasmaCore.FrameSvgItem {
- id: internal
- property variant parentPos
- imagePath: fallbackComponent.svgPath
- property bool under: root.visualParent ? internal.parentPos.y + root.visualParent.height + height < dismissArea.height : true
- //bindings won't work inside anchers definition
- onUnderChanged: {
- if (under) {
- tipSvg.anchors.top = undefined
- tipSvg.anchors.bottom = tipSvg.parent.top
- } else {
- tipSvg.anchors.bottom = undefined
- tipSvg.anchors.top = tipSvg.parent.bottom
+ Behavior on opacity {
+ SequentialAnimation {
+ NumberAnimation {
+ duration: 250
+ easing.type: Easing.InOutQuad
+ properties: "opacity"
+ }
+ ScriptAction {
+ script: {
+ root.status = root.status == 'opening' ? 'open' : 'closed'
+ }
+
+ }
}
}
- property int preferedX: internal.parentPos.x - internal.width/2 + root.visualParent.width/2
- x: Math.max(shadowFrame.margins.left, Math.min(dismissArea.width - internal.width - shadowFrame.margins.right, preferedX))
- y: {
- if (root.visualParent) {
- if (under) {
- internal.parentPos.y + root.visualParent.height + tipSvg.height
- } else {
- internal.parentPos.y - internal.height - tipSvg.height
+ SystemPalette {
+ id: palette
+ colorGroup: SystemPalette.Active
+ }
+
+ Item {
+ id: internalWrapper
+ anchors.fill: parent
+ visible: false
+
+ Rectangle {
+ id: internal
+ color: palette.alternateBase
+ radius: 5
+
+ property variant parentPos: root.visualParent? root.visualParent.mapToItem(dismissArea, 0, 0): Qt.point(0, 0)
+ property bool under: root.visualParent ? internal.parentPos.y + root.visualParent.height + height < dismissArea.height : true
+
+ //bindings won't work inside anchors definition
+ onUnderChanged: {
+ if (under) {
+ balloonTip.anchors.top = undefined
+ balloonTip.anchors.bottom = balloonTip.parent.top
+ } else {
+ balloonTip.anchors.bottom = undefined
+ balloonTip.anchors.top = balloonTip.parent.bottom
+ }
+ }
+
+ property int preferedX: internal.parentPos.x - internal.width/2 + root.visualParent.width/2
+ x: Math.round(Math.max(radius, Math.min(dismissArea.width - internal.width - radius, preferedX)))
+ y: {
+ if (root.visualParent) {
+ if (under) {
+ Math.round(internal.parentPos.y + root.visualParent.height + balloonTip.height + radius)
+ } else {
+ Math.round(internal.parentPos.y - internal.height - balloonTip.height - radius)
+ }
+ } else {
+ Math.round(dismissArea.height/2 - internal.height/2)
+ }
+ }
+ width: contentItem.width + 2 * internal.radius
+ height: contentItem.height + 2 * internal.radius
+
+ Rectangle {
+ id: balloonTip
+ color: internal.color
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ horizontalCenterOffset: internal.preferedX - internal.x
+ }
+ width: 10
+ height: 10
+ visible: false
+ }
+
+ Image {
+ id: balloonTipMask
+ anchors.fill: balloonTip
+ visible: false
+ source: utils.findImage("balloontip.svgz")
+ sourceSize: Qt.size(width, height)
+ }
+
+ OpacityMask {
+ anchors.fill: balloonTip
+ visible: root.visualParent != null
+ source: balloonTip
+ maskSource: balloonTipMask
}
- } else {
- dismissArea.height/2 - internal.height/2
}
}
- width: contentItem.width + margins.left + margins.right
- height: contentItem.height + margins.top + margins.bottom
-
- PlasmaCore.SvgItem {
- id: tipSvg
- visible: root.visualParent != null
- svg: PlasmaCore.Svg {
- id: backgroundSvg
- imagePath: fallbackComponent.svgPath
- }
- elementId: internal.under ? "balloon-tip-top" : "balloon-tip-bottom"
- anchors {
- horizontalCenter: parent.horizontalCenter
- horizontalCenterOffset: internal.preferedX - internal.x
- bottom: parent.top
- top: parent.bottom
- topMargin: -backgroundSvg.elementSize("hint-bottom-shadow").height - 1
- bottomMargin: -backgroundSvg.elementSize("hint-top-shadow").height - 1
- }
- width: naturalSize.width
- height: naturalSize.height
+
+ DropShadow {
+ anchors.fill: parent
+ source: internalWrapper
+ radius: 5
+ samples: 11
}
- MouseArea {
+
+ Item {
id: contentItem
- x: parent.margins.left
- y: parent.margins.top
+ x: internal.x + internal.radius
+ y: internal.y + internal.radius
width: childrenRect.width
- height: childrenRect.height
- onClicked: mouse.accepted = true
+ height: childrenRect.height + 2
+ data: root.data
}
- }
- onClicked: {
- root.close()
- }
- Component.onCompleted: {
- var candidate = root
- while (candidate.parent) {
- candidate = candidate.parent
+
+ onClicked: {
+ root.close()
}
- if (candidate) {
- dismissArea.parent = candidate
- } else {
- dismissArea.visible = false
+
+ Component.onCompleted: {
+ var candidate = root
+ while (candidate.parent.parent) {
+ candidate = candidate.parent
+ }
+ if (candidate) {
+ dismissArea.parent = candidate
+ }
+ root.status = 'opening'
}
- internal.parentPos = root.mapToItem(dismissArea.parent, 0, 0)
+
}
+
}
}