Plasma

Sheet.qml
1 /*
2  SPDX-FileCopyrightText: 2011 Marco Martin <[email protected]>
3  SPDX-FileCopyrightText: 2011 Nokia Corporation and /or its subsidiary(-ies) <[email protected]>
4 
5  This file is part of the Qt Components project.
6 
7  SPDX-License-Identifier: BSD-3-Clause
8 */
9 
10 import QtQuick 2.1
11 import org.kde.plasma.core 2.0 as PlasmaCore
12 import "private/AppManager.js" as Utils
13 import "." 2.0 as PlasmaComponents
14 
15 /**
16  * Provides a top-level window for short-term tasks and brief interaction with
17  * the user.
18  *
19  * It is intended to be used for interaction more complex and bigger in size
20  * than Dialog. On the desktop its looks is almost identical to Dialog, on
21  * touch interfaces it is an almost fullscreen sliding Sheet. It is provided
22  * mostly for compatibility with mobile implementations.
23  *
24  * @inherit QtQuick.Item
25  */
26 Item {
27  id: root
28 
29  /**
30  * type:string
31  * The title text of this Sheet.
32  */
33  property alias title: titleLabel.text
34 
35  /**
36  * type:list<Item>
37  * A list of items in the dialog's content area. You can use any component
38  * that is based on Item. For example, you can use ListView, so that the
39  * user can select from a list of names.
40  */
41  property alias content: contentItem.children
42 // property alias visualParent: dialog.visualParent
43 
44  /**
45  * Indicates the dialog's phase in its life cycle. The values are as follows:
46  *
47  * - DialogStatus.Opening - the dialog is opening
48  * - DialogStatus.Open - the dialog is open and visible to the user
49  * - DialogStatus.Closing - the dialog is closing
50  * - DialogStatus.Closed - the dialog is closed and not visible to the user
51  *
52  * The dialog's initial status is DialogStatus.Closed.
53  */
54  property int status: PlasmaComponents.DialogStatus.Closed
55  property alias acceptButtonText: acceptButton.text
56  property alias rejectButtonText: rejectButton.text
57  /**
58  * type:Button
59  * button that when pressed will close the dialog, representing the user
60  * accepting it, accepted() will be called
61  */
62  property alias acceptButton: acceptButton
63 
64  /**
65  * type:Button
66  * button that when pressed will close the dialog, representing the user rejecting it, rejected() will be called
67  */
68  property alias rejectButton: rejectButton
69 
70  property alias privateTitleHeight: titleBar.height
71  property alias privateButtonsHeight: buttonsRow.height
72 
73  /**
74  * Emitted when the user accepts the dialog's request or the accept()
75  * method is called.
76  */
77  signal accepted
78 
79  /**
80  * Emitted when the user rejects the dialog's request or the reject()
81  * method is called.
82  *
83  * @see accepted()
84  */
85  signal rejected
86 
87  /**
88  * Emitted when the user taps in the area that is inside the dialog's
89  * visual parent area but outside the dialog's area. Normally the visual
90  * parent is the root object. In that case this signal is emitted if the
91  * user taps anywhere outside the dialog's area.
92  */
93  signal clickedOutside
94 
95  /**
96  * Shows the dialog to the user.
97  */
98  function open()
99  {
100  dialog.visible = true
101  dialog.requestActivate()
102  }
103 
104  /**
105  * Accepts the dialog's request without any user interaction. The method
106  * emits the accepted() signal and closes the dialog.
107  *
108  * @see reject()
109  */
110  function accept()
111  {
112  if (status == DialogStatus.Open) {
113  dialog.visible = false
114  accepted()
115  }
116  }
117 
118  /**
119  * Rejects the dialog's request without any user interaction. The method
120  * emits the rejected() signal and closes the dialog.
121  *
122  * @see accept()
123  */
124  function reject() {
125  if (status == DialogStatus.Open) {
126  dialog.visible = false
127  rejected()
128  }
129  }
130 
131  /**
132  * Closes the dialog without any user interaction.
133  */
134  function close() {
135  dialog.visible = false
136  }
137 
138  visible: false
139 
140  PlasmaCore.Dialog {
141  id: dialog
142  flags: Qt.Dialog
143  location: PlasmaCore.Types.BottomEdge
144 
145 
146  //onFaderClicked: root.clickedOutside()
147  property Item rootItem
148 
149  //state: "Hidden"
150  visible: false
151  onVisibleChanged: {
152  if (visible) {
153  status = PlasmaComponents.DialogStatus.Open
154  } else {
155  status = PlasmaComponents.DialogStatus.Closed
156  }
157  }
158 
159  mainItem: Item {
160  id: mainItem
161  width: PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).width * 40
162  height: Math.max(titleBar.childrenRect.height + contentItem.childrenRect.height + buttonsRow.childrenRect.height + 8, PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height * 25)
163 
164  // Consume all key events that are not processed by children
165  Keys.onPressed: event.accepted = true
166  Keys.onReleased: event.accepted = true
167 
168  PlasmaCore.FrameSvgItem {
169  id: titleBar
170  imagePath: "widgets/extender-dragger"
171  prefix: "root"
172  anchors.left: parent.left
173  anchors.right: parent.right
174  //FIXME: +5 because of Plasma::Dialog margins
175  height: titleLabel.paintedHeight + margins.top + margins.bottom
176 
177  Column {
178  id: titleLayoutHelper // needed to make the text mirror correctly
179 
180  anchors {
181  right: parent.right
182  left: parent.left
183  top: parent.top
184  bottom: parent.bottom
185  leftMargin: parent.margins.left
186  rightMargin: parent.margins.right
187  topMargin: parent.margins.top
188  bottomMargin: parent.margins.bottom
189  }
190 
191  PlasmaComponents.Label {
192  id: titleLabel
193  elide: Text.ElideRight
194  height: paintedHeight
195  font.pointSize: PlasmaCore.Theme.defaultFont.pointSize * 1.1
196  font.weight: Font.Bold
197  style: Text.Raised
198  styleColor: Qt.rgba(1,1,1,0.8)
199  anchors {
200  left: parent.left
201  right: parent.right
202  }
203  horizontalAlignment: Text.AlignHCenter
204  verticalAlignment: Text.AlignVCenter
205  }
206  }
207  }
208 
209  Item {
210  id: contentItem
211 
212  onChildrenRectChanged: mainItem.width = Math.max(childrenRect.width, buttonsRow.childrenRect.width)
213 
214  clip: true
215  anchors {
216  top: titleBar.bottom
217  left: parent.left
218  right: parent.right
219  bottom: buttonsRow.top
220  bottomMargin: 8
221  }
222  }
223 
224  Row {
225  id: buttonsRow
226  spacing: 8
227  anchors {
228  bottom: parent.bottom
229  horizontalCenter: parent.horizontalCenter
230  //the bottom margin is disabled but we want it anyways
231  bottomMargin: PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height*0.6
232  }
233 
234  PlasmaComponents.Button {
235  id: acceptButton
236  onClicked: accept()
237  }
238 
239  PlasmaComponents.Button {
240  id: rejectButton
241  onClicked: reject()
242  }
243  }
244  }
245 
246  Component.onCompleted: {
247  rootItem = Utils.rootObject(this)
248  }
249  }
250 }
QTextStream & left(QTextStream &s)
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Mar 8 2021 22:41:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.