• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmacomponents
  • qml
  • private
InlineDialog.qml
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Marco Martin <mart@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Library General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 import QtQuick 1.1
21 import org.kde.plasma.core 0.1 as PlasmaCore
22 import org.kde.plasma.extras 0.1 as PlasmaExtras
23 import org.kde.plasma.components 0.1 as PlasmaComponents
24 
25 Item {
26  id: root
27  property Item visualParent
28  z: 9000
29  property int status: PlasmaComponents.DialogStatus.Closed
30  default property alias data: contentItem.data
31 
32  function open()
33  {
34  if (root.visualParent) {
35  internal.parentPos = root.visualParent.mapToItem(dismissArea.parent, 0, 0)
36  }
37  root.status = PlasmaComponents.DialogStatus.Opening
38  appearAnimation.restart()
39  }
40 
41  function close()
42  {
43  root.status = PlasmaComponents.DialogStatus.Closing
44  appearAnimation.restart()
45  }
46 
47  SequentialAnimation {
48  id: appearAnimation
49  NumberAnimation {
50  duration: 250
51  easing.type: Easing.InOutQuad
52  target: dismissArea
53  properties: "opacity"
54  to: root.status == PlasmaComponents.DialogStatus.Opening ? 1 : 0
55  }
56  ScriptAction {
57  script: root.status == PlasmaComponents.DialogStatus.Opening ? root.status = PlasmaComponents.DialogStatus.Open : PlasmaComponents.DialogStatus.Closed
58  }
59  }
60 
61  MouseArea {
62  id: dismissArea
63  z: 9000
64  anchors.fill: parent
65  opacity: 0
66  //to not pass hover events to the background
67  hoverEnabled: true
68 
69  //FIXME: this is an hack: it's taking the dialog background making sure no opaque or transparent are selected
70  //in Plasma2 we need to have the backingstore blur there as well
71  PlasmaExtras.FallbackComponent {
72  id: fallbackComponent
73  basePath: "desktoptheme"
74  candidates: [theme.themeName, "default"]
75  property string svgPath: fallbackComponent.filePath("/dialogs/background.svgz")
76  }
77  Connections {
78  target: theme
79  //fallback if inline-background doesn't work
80  onThemeChanged: {
81  fallbackComponent.svgPath = fallbackComponent.filePath("/dialogs/background.svgz")
82  shadowFrame.visible = backgroundSvg.hasElement("shadow-top")
83  }
84  }
85  PlasmaCore.FrameSvgItem {
86  id: shadowFrame
87  imagePath: fallbackComponent.svgPath
88  prefix: "shadow"
89  anchors {
90  fill: internal
91  leftMargin: -margins.left
92  topMargin: -margins.top
93  rightMargin: -margins.right
94  bottomMargin: -margins.bottom
95  }
96  Component.onCompleted: shadowFrame.visible = backgroundSvg.hasElement("shadow-top")
97  }
98  PlasmaCore.FrameSvgItem {
99  id: internal
100  property variant parentPos
101  imagePath: fallbackComponent.svgPath
102  property bool under: root.visualParent ? internal.parentPos.y + root.visualParent.height + height < dismissArea.height : true
103  //bindings won't work inside anchers definition
104  onUnderChanged: {
105  if (under) {
106  tipSvg.anchors.top = undefined
107  tipSvg.anchors.bottom = tipSvg.parent.top
108  } else {
109  tipSvg.anchors.bottom = undefined
110  tipSvg.anchors.top = tipSvg.parent.bottom
111  }
112  }
113 
114  x: {
115  if (root.visualParent) {
116  internal.parentPos.x - internal.width/2 + root.visualParent.width/2
117  } else {
118  dismissArea.width/2 - internal.width/2
119  }
120  }
121  y: {
122  if (root.visualParent) {
123  if (under) {
124  internal.parentPos.y + root.visualParent.height
125  } else {
126  internal.parentPos.y - internal.height
127  }
128  } else {
129  dismissArea.height/2 - internal.height/2
130  }
131  }
132  width: contentItem.width + margins.left + margins.right
133  height: contentItem.height + margins.top + margins.bottom
134 
135  PlasmaCore.SvgItem {
136  id: tipSvg
137  visible: root.visualParent != null
138  svg: PlasmaCore.Svg {
139  id: backgroundSvg
140  imagePath: fallbackComponent.svgPath
141  }
142  elementId: internal.under ? "balloon-tip-top" : "balloon-tip-bottom"
143  anchors {
144  horizontalCenter: parent.horizontalCenter
145  bottom: parent.top
146  top: parent.bottom
147  topMargin: -backgroundSvg.elementSize("hint-bottom-shadow").height - 1
148  bottomMargin: -backgroundSvg.elementSize("hint-top-shadow").height - 1
149  }
150  width: naturalSize.width
151  height: naturalSize.height
152  }
153  MouseArea {
154  id: contentItem
155  x: parent.margins.left
156  y: parent.margins.top
157  width: childrenRect.width
158  height: childrenRect.height
159  onClicked: mouse.accepted = true
160  }
161  }
162  onClicked: {
163  root.close()
164  }
165  Component.onCompleted: {
166  var candidate = root
167  while (candidate.parent) {
168  candidate = candidate.parent
169  }
170  if (candidate) {
171  dismissArea.parent = candidate
172  } else {
173  dismissArea.visible = false
174  }
175  internal.parentPos = root.mapToItem(dismissArea.parent, 0, 0)
176  }
177  }
178 }
Item
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaComponents

Skip menu "PlasmaComponents"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal