• 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
Dialog.qml
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Marco Martin <mart@kde.org>
4 **
5 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 ** All rights reserved.
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** This file is part of the Qt Components project.
10 **
11 ** $QT_BEGIN_LICENSE:BSD$
12 ** You may use this file under the terms of the BSD license as follows:
13 **
14 ** "Redistribution and use in source and binary forms, with or without
15 ** modification, are permitted provided that the following conditions are
16 ** met:
17 ** * Redistributions of source code must retain the above copyright
18 ** notice, this list of conditions and the following disclaimer.
19 ** * Redistributions in binary form must reproduce the above copyright
20 ** notice, this list of conditions and the following disclaimer in
21 ** the documentation and/or other materials provided with the
22 ** distribution.
23 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
24 ** the names of its contributors may be used to endorse or promote
25 ** products derived from this software without specific prior written
26 ** permission.
27 **
28 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42 
43 import QtQuick 1.0
44 import org.kde.plasma.core 0.1 as PlasmaCore
45 import "private/AppManager.js" as Utils
46 import "." 0.1
47 import "private" as Private
48 
57 Item {
58  id: root
59 
65  property alias title: titleBar.children
66 
72  property alias content: contentItem.children
73 
79  property alias buttons: buttonItem.children
80 
85  property Item visualParent
86 
97  property int status: DialogStatus.Closed
98 
99 
100  property alias privateTitleHeight: titleBar.height
101  property alias privateButtonsHeight: buttonItem.height
102 
109  signal accepted
110 
119  signal rejected
120 
129  signal clickedOutside
130 
134  function open() {
135  dialogLayout.parent = internalLoader.item.mainItem
136 
137  if (internalLoader.dialog) {
138  var pos = internalLoader.dialog.popupPosition(root.visualParent, Qt.AlignCenter)
139  internalLoader.dialog.x = pos.x
140  internalLoader.dialog.y = pos.y
141 
142  internalLoader.dialog.visible = true
143  internalLoader.dialog.activateWindow()
144  } else {
145  internalLoader.inlineDialog.open()
146  }
147  }
148 
155  function accept() {
156  if (status == DialogStatus.Open) {
157  if (internalLoader.dialog) {
158  internalLoader.dialog.visible = false
159  } else {
160  internalLoader.inlineDialog.close()
161  }
162  accepted()
163  }
164  }
165 
172  function reject() {
173  if (status == DialogStatus.Open) {
174  if (internalLoader.dialog) {
175  internalLoader.dialog.visible = false
176  } else {
177  internalLoader.inlineDialog.close()
178  }
179  rejected()
180  }
181  }
182 
186  function close() {
187  if (internalLoader.dialog) {
188  internalLoader.dialog.visible = false
189  } else {
190  internalLoader.inlineDialog.close()
191  }
192  }
193 
194  visible: false
195 
196  Loader {
197  id: internalLoader
198  //the root item of the scene. Determines if there is enough room for an inline dialog
199  property Item rootItem
200 
201  //this is when the dialog is a separate window
202  property Item dialog: sourceComponent == dialogComponent ? item : null
203  //this is when the dialog is inline
204  property Item inlineDialog: sourceComponent == inlineDialogComponent ? item : null
205 
206  property bool loadCompleted: false
207 
208  Component.onCompleted: {
209  rootItem = Utils.rootObject()
210  loadCompleted = true
211  }
212 
213  sourceComponent: {
214  if (loadCompleted) {
215  if (rootItem == null || dialogLayout.width > rootItem.width || dialogLayout.height > rootItem.height) {
216  dialogComponent
217  } else {
218  inlineDialogComponent
219  }
220  }
221  }
222  }
223 
224  Component {
225  id: dialogComponent
226  PlasmaCore.Dialog {
227  id: dialogItem
228  windowFlags: Qt.Popup
229 
230  //state: "Hidden"
231  visible: false
232  onVisibleChanged: {
233  if (visible) {
234  root.status = DialogStatus.Open
235  } else {
236  root.status = DialogStatus.Closed
237  }
238  }
239 
240  mainItem: Item {
241  id: dialogMainItem
242  width: dialogLayout.width
243  height: dialogLayout.height + theme.defaultFont.mSize.height * 2
244  }
245 
246  Component.onCompleted: dialogLayout.parent = dialogMainItem
247  Component.onDestruction: dialogLayout.parent = root
248  }
249  }
250 
251  Component {
252  id: inlineDialogComponent
253  Private.InlineDialog {
254  id: inlineDialog
255  visualParent: root.visualParent
256  property Item mainItem: inlineDialogMainItem
257  onStatusChanged: root.status = status
258 
259  Item {
260  id: inlineDialogMainItem
261  width: dialogLayout.width
262  height: dialogLayout.height
263  }
264 
265  Component.onCompleted: {
266  dialogLayout.parent = inlineDialogMainItem
267  }
268  Component.onDestruction: dialogLayout.parent = root
269  }
270  }
271 
272  Item {
273  id: dialogLayout
274  width: Math.max(buttonItem.childrenRect.width, contentItem.childrenRect.width)
275  height: titleBar.height + contentItem.childrenRect.height + buttonItem.childrenRect.height + 10
276 
277  parent: internalLoader.dialog ? internalLoader.dialog : internalLoader.inlineDialog
278  // Consume all key events that are not processed by children
279  Keys.onPressed: event.accepted = true
280  Keys.onReleased: event.accepted = true
281 
282  Item {
283  id: titleBar
284 
285  height: children.length > 0 && children[0].visible ? childrenRect.height : 0
286  anchors {
287  top: parent.top
288  left: parent.left
289  right: parent.right
290  }
291  }
292 
293  Item {
294  id: contentItem
295 
296  clip: true
297  anchors {
298  top: titleBar.bottom
299  left: parent.left
300  right: parent.right
301  bottom: buttonItem.top
302  bottomMargin: 6
303  }
304  }
305 
306  Item {
307  id: buttonItem
308 
309  height: childrenRect.height
310  anchors {
311  left: parent.left
312  right: parent.right
313  bottom: parent.bottom
314  bottomMargin: 4
315  }
316  }
317  }
318 }
DialogStatus::Closed
Definition: enums.h:37
DialogStatus::Open
Definition: enums.h:35
Item
DialogStatus
Definition: enums.h:27
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