Changeset View
Changeset View
Standalone View
Standalone View
src/controls/templates/InlineMessage.qml
- This file was copied to src/styles/Material/InlineMessage.qml.
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.7 | 20 | import QtQuick 2.7 | ||
21 | import QtQuick.Templates 2.0 as T2 | 21 | import QtQuick.Templates 2.0 as T2 | ||
22 | import org.kde.kirigami 2.4 as Kirigami | 22 | import QtQuick.Controls 2.0 as Controls | ||
23 | import QtQuick.Layouts 1.0 | ||||
24 | import org.kde.kirigami 2.5 as Kirigami | ||||
23 | import "private" | 25 | import "private" | ||
24 | 26 | | |||
25 | /** | 27 | /** | ||
26 | * An inline message item with support for informational, positive, | 28 | * An inline message item with support for informational, positive, | ||
27 | * warning and error types, and with support for associated actions. | 29 | * warning and error types, and with support for associated actions. | ||
28 | * | 30 | * | ||
29 | * InlineMessage can be used to give information to the user or | 31 | * InlineMessage can be used to give information to the user or | ||
30 | * interact with the user, without requiring the use of a dialog. | 32 | * interact with the user, without requiring the use of a dialog. | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 76 | T2.Control { | |||
127 | */ | 129 | */ | ||
128 | property list<QtObject> actions | 130 | property list<QtObject> actions | ||
129 | 131 | | |||
130 | /** | 132 | /** | ||
131 | * animating: bool | 133 | * animating: bool | ||
132 | * True while the message item is animating. | 134 | * True while the message item is animating. | ||
133 | */ | 135 | */ | ||
134 | readonly property bool animating: hasOwnProperty("_animating") && _animating | 136 | readonly property bool animating: hasOwnProperty("_animating") && _animating | ||
137 | | ||||
138 | implicitHeight: visible ? contentLayout.implicitHeight + (2 * (background.border.width + Kirigami.Units.smallSpacing)) : 0 | ||||
139 | | ||||
140 | property bool _animating: false | ||||
141 | | ||||
142 | leftPadding: background.border.width + Kirigami.Units.smallSpacing | ||||
143 | topPadding: background.border.width + Kirigami.Units.smallSpacing | ||||
144 | rightPadding: background.border.width + Kirigami.Units.smallSpacing | ||||
145 | bottomPadding: background.border.width + Kirigami.Units.smallSpacing | ||||
146 | | ||||
147 | Behavior on implicitHeight { | ||||
148 | enabled: !root.visible | ||||
149 | | ||||
150 | SequentialAnimation { | ||||
151 | PropertyAction { targets: root; property: "_animating"; value: true } | ||||
152 | NumberAnimation { duration: Kirigami.Units.longDuration } | ||||
153 | } | ||||
154 | } | ||||
155 | | ||||
156 | onVisibleChanged: { | ||||
157 | if (!visible) { | ||||
158 | contentLayout.opacity = 0.0; | ||||
159 | } | ||||
160 | } | ||||
161 | | ||||
162 | opacity: visible ? 1.0 : 0.0 | ||||
163 | | ||||
164 | Behavior on opacity { | ||||
165 | enabled: !root.visible | ||||
166 | | ||||
167 | NumberAnimation { duration: Kirigami.Units.shortDuration } | ||||
168 | } | ||||
169 | | ||||
170 | onOpacityChanged: { | ||||
171 | if (opacity == 0.0) { | ||||
172 | contentLayout.opacity = 0.0; | ||||
173 | } else if (opacity == 1.0) { | ||||
174 | contentLayout.opacity = 1.0; | ||||
175 | } | ||||
176 | } | ||||
177 | | ||||
178 | onImplicitHeightChanged: { | ||||
179 | height = implicitHeight; | ||||
180 | } | ||||
181 | contentItem: GridLayout { | ||||
182 | id: contentLayout | ||||
183 | | ||||
184 | // Used to defer opacity animation until we know if InlineMessage was | ||||
185 | // initialized visible. | ||||
186 | property bool complete: false | ||||
187 | | ||||
188 | Behavior on opacity { | ||||
189 | enabled: root.visible && contentLayout.complete | ||||
190 | | ||||
191 | SequentialAnimation { | ||||
192 | NumberAnimation { duration: Kirigami.Units.shortDuration * 2 } | ||||
193 | PropertyAction { targets: root; property: "_animating"; value: false } | ||||
194 | } | ||||
195 | } | ||||
196 | | ||||
197 | rowSpacing: Kirigami.Units.largeSpacing | ||||
198 | columnSpacing: Kirigami.Units.smallSpacing | ||||
199 | | ||||
200 | Kirigami.Icon { | ||||
201 | id: icon | ||||
202 | | ||||
203 | width: Kirigami.Units.iconSizes.smallMedium | ||||
204 | height: width | ||||
205 | | ||||
206 | Layout.alignment: text.lineCount > 1 ? Qt.AlignTop : Qt.AlignVCenter | ||||
207 | | ||||
208 | Layout.minimumWidth: width | ||||
209 | Layout.minimumHeight: height | ||||
210 | | ||||
211 | source: { | ||||
212 | if (root.icon.source) { | ||||
213 | return root.icon.source; | ||||
214 | } | ||||
215 | | ||||
216 | if (root.type == Kirigami.MessageType.Positive) { | ||||
217 | return "dialog-positive"; | ||||
218 | } else if (root.type == Kirigami.MessageType.Warning) { | ||||
219 | return "dialog-warning"; | ||||
220 | } else if (root.type == Kirigami.MessageType.Error) { | ||||
221 | return "dialog-error"; | ||||
222 | } | ||||
223 | | ||||
224 | return "dialog-information"; | ||||
225 | } | ||||
226 | | ||||
227 | color: root.icon.color | ||||
228 | } | ||||
229 | | ||||
230 | MouseArea { | ||||
231 | implicitHeight: text.implicitHeight | ||||
232 | | ||||
233 | Layout.fillWidth: true | ||||
234 | Layout.alignment: text.lineCount > 1 ? Qt.AlignTop : Qt.AlignVCenter | ||||
235 | Layout.row: 0 | ||||
236 | Layout.column: 1 | ||||
237 | | ||||
238 | cursorShape: text.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor | ||||
239 | | ||||
240 | Controls.Label { | ||||
241 | id: text | ||||
242 | | ||||
243 | width: parent.width | ||||
244 | | ||||
245 | color: Kirigami.Theme.textColor | ||||
246 | wrapMode: Text.WordWrap | ||||
247 | elide: Text.ElideRight | ||||
248 | | ||||
249 | text: root.text | ||||
250 | | ||||
251 | onLinkHovered: root.linkHovered(link) | ||||
252 | onLinkActivated: root.linkActivated(link) | ||||
253 | } | ||||
254 | //this must be child of an item which doesn't try to resize it | ||||
255 | TextMetrics { | ||||
256 | id: messageTextMetrics | ||||
257 | | ||||
258 | font: text.font | ||||
259 | text: text.text | ||||
260 | } | ||||
261 | } | ||||
262 | | ||||
263 | Kirigami.ActionToolBar { | ||||
264 | id: actionsLayout | ||||
265 | | ||||
266 | flat: false | ||||
267 | actions: root.actions | ||||
268 | visible: root.actions.length | ||||
269 | | ||||
270 | Layout.alignment: Qt.AlignRight | ||||
271 | | ||||
272 | Layout.row: { | ||||
273 | if (messageTextMetrics.width + Kirigami.Units.smallSpacing > | ||||
274 | (contentLayout.width - icon.width - actionsLayout.width | ||||
275 | - closeButton.width - (3 * contentLayout.columnSpacing))) { | ||||
276 | return 1; | ||||
277 | } | ||||
278 | return 0; | ||||
279 | } | ||||
280 | Layout.column: Layout.row ? 0 : 2 | ||||
281 | Layout.columnSpan: Layout.row ? (closeButton.visible ? 3 : 2) : 1 | ||||
282 | } | ||||
283 | | ||||
284 | Controls.ToolButton { | ||||
285 | id: closeButton | ||||
286 | | ||||
287 | visible: root.showCloseButton | ||||
288 | | ||||
289 | Layout.alignment: text.lineCount > 1 || actionsLayout.Layout.row ? Qt.AlignTop : Qt.AlignVCenter | ||||
290 | Layout.row: 0 | ||||
291 | Layout.column: actionsLayout.Layout.row ? 2 : 3 | ||||
292 | | ||||
293 | //TODO: use toolbuttons icons when we can depend from Qt 5.10 | ||||
294 | Kirigami.Icon { | ||||
295 | anchors.centerIn: parent | ||||
296 | source: "dialog-close" | ||||
297 | width: Kirigami.Units.iconSizes.smallMedium | ||||
298 | height: width | ||||
299 | } | ||||
300 | | ||||
301 | onClicked: root.visible = false | ||||
302 | } | ||||
303 | | ||||
304 | Component.onCompleted: complete = true | ||||
305 | } | ||||
135 | } | 306 | } |