Kirigami2

controls/templates/InlineMessage.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Eike Hein <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.7
8 import QtQuick.Templates 2.0 as T2
9 import QtQuick.Controls 2.0 as Controls
10 import QtQuick.Layouts 1.0
11 import org.kde.kirigami 2.5 as Kirigami
12 import "private"
13 
63 T2.Control {
64  id: root
65 
66  visible: false
67 
72  signal linkHovered(string link)
73 
74 
78  signal linkActivated(string link)
79 
86  property int type: Kirigami.MessageType.Information
87 
96  property IconPropertiesGroup icon: IconPropertiesGroup {}
97 
102  property string text
103 
109  property bool showCloseButton: false
110 
117  property list<QtObject> actions
118 
123  readonly property bool animating: root.hasOwnProperty("_animating") && _animating
124 
125  implicitHeight: visible ? contentLayout.implicitHeight + (2 * (background.border.width + Kirigami.Units.smallSpacing)) : 0
126 
127  property bool _animating: false
128 
129  leftPadding: background.border.width + Kirigami.Units.smallSpacing
130  topPadding: background.border.width + Kirigami.Units.smallSpacing
131  rightPadding: background.border.width + Kirigami.Units.smallSpacing
132  bottomPadding: background.border.width + Kirigami.Units.smallSpacing
133 
134  Behavior on implicitHeight {
135  enabled: !root.visible
136 
137  SequentialAnimation {
138  PropertyAction { targets: root; property: "_animating"; value: true }
139  NumberAnimation { duration: Kirigami.Units.longDuration }
140  }
141  }
142 
143  onVisibleChanged: {
144  if (!visible) {
145  contentLayout.opacity = 0.0;
146  }
147  }
148 
149  opacity: visible ? 1.0 : 0.0
150 
151  Behavior on opacity {
152  enabled: !root.visible
153 
154  NumberAnimation { duration: Kirigami.Units.shortDuration }
155  }
156 
157  onOpacityChanged: {
158  if (opacity == 0.0) {
159  contentLayout.opacity = 0.0;
160  } else if (opacity == 1.0) {
161  contentLayout.opacity = 1.0;
162  }
163  }
164 
165  onImplicitHeightChanged: {
166  height = implicitHeight;
167  }
168 
169  contentItem: GridLayout {
170  id: contentLayout
171 
172  // Used to defer opacity animation until we know if InlineMessage was
173  // initialized visible.
174  property bool complete: false
175 
176  Behavior on opacity {
177  enabled: root.visible && contentLayout.complete
178 
179  SequentialAnimation {
180  NumberAnimation { duration: Kirigami.Units.shortDuration * 2 }
181  PropertyAction { targets: root; property: "_animating"; value: false }
182  }
183  }
184 
185  rowSpacing: Kirigami.Units.largeSpacing
186  columnSpacing: Kirigami.Units.smallSpacing
187 
188  Kirigami.Icon {
189  id: icon
190 
191  width: Kirigami.Units.iconSizes.smallMedium
192  height: width
193 
194  Layout.alignment: text.lineCount > 1 ? Qt.AlignTop : Qt.AlignVCenter
195 
196  Layout.minimumWidth: width
197  Layout.minimumHeight: height
198 
199  source: {
200  if (root.icon.source) {
201  return root.icon.source;
202  }
203 
204  if (root.type == Kirigami.MessageType.Positive) {
205  return "dialog-positive";
206  } else if (root.type == Kirigami.MessageType.Warning) {
207  return "dialog-warning";
208  } else if (root.type == Kirigami.MessageType.Error) {
209  return "dialog-error";
210  }
211 
212  return "dialog-information";
213  }
214 
215  color: root.icon.color
216  }
217 
218  MouseArea {
219  implicitHeight: text.implicitHeight
220 
221  Layout.fillWidth: true
222  Layout.alignment: text.lineCount > 1 ? Qt.AlignTop : Qt.AlignVCenter
223  Layout.row: 0
224  Layout.column: 1
225 
226  cursorShape: text.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
227 
228  Controls.Label {
229  id: text
230 
231  width: parent.width
232 
233  color: Kirigami.Theme.textColor
234  wrapMode: Text.WordWrap
235  elide: Text.ElideRight
236 
237  text: root.text
238 
239  onLinkHovered: root.linkHovered(link)
240  onLinkActivated: root.linkActivated(link)
241  }
242  //this must be child of an item which doesn't try to resize it
243  TextMetrics {
244  id: messageTextMetrics
245 
246  font: text.font
247  text: text.text
248  }
249  }
250 
251  Kirigami.ActionToolBar {
252  id: actionsLayout
253 
254  flat: false
255  actions: root.actions
256  visible: root.actions.length
257  alignment: Qt.AlignRight
258 
259  Layout.alignment: Qt.AlignRight
260  Layout.maximumWidth: maximumContentWidth
261  Layout.fillWidth: true
262 
263  Layout.row: {
264  var width = contentLayout.width - icon.width - actionsLayout.maximumContentWidth
265  - (closeButton.visible ? closeButton.width : 0)
266  - 3 * contentLayout.columnSpacing
267 
268  if (messageTextMetrics.width + Kirigami.Units.smallSpacing > width) {
269  return 1;
270  }
271  return 0;
272  }
273  Layout.column: Layout.row ? 0 : 2
274  Layout.columnSpan: Layout.row ? (closeButton.visible ? 3 : 2) : 1
275  }
276 
277  Controls.ToolButton {
278  id: closeButton
279 
280  visible: root.showCloseButton
281 
282  Layout.alignment: text.lineCount > 1 || actionsLayout.Layout.row ? Qt.AlignTop : Qt.AlignVCenter
283  Layout.row: 0
284  Layout.column: actionsLayout.Layout.row ? 2 : 3
285 
286  icon.name: "dialog-close"
287 
288  onClicked: root.visible = false
289  }
290 
291  Component.onCompleted: complete = true
292  }
293 }
Definition: icon.h:19
if(recurs()&&!first)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 22:39:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.