Changeset View
Changeset View
Standalone View
Standalone View
src/controls/InlineMessage.qml
Show All 14 Lines | |||||
15 | * | 15 | * | ||
16 | * You should have received a copy of the GNU Library General Public | 16 | * You should have received a copy of the GNU Library General Public | ||
17 | * License along with this program; if not, write to the | 17 | * License along with this program; if not, write to the | ||
18 | * Free Software Foundation, Inc., | 18 | * Free Software Foundation, Inc., | ||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. | 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | import QtQuick 2.7 | 22 | import QtQuick 2.7 | ||
23 | import QtGraphicalEffects 1.0 | | |||
24 | import QtQuick.Layouts 1.0 | | |||
25 | import QtQuick.Controls 2.0 as Controls | | |||
26 | import org.kde.kirigami 2.5 as Kirigami | 23 | import org.kde.kirigami 2.5 as Kirigami | ||
27 | import "private" | 24 | import "private" | ||
28 | 25 | | |||
29 | import "templates" as T | 26 | import "templates" as T | ||
30 | 27 | | |||
31 | /** | 28 | /** | ||
32 | * An inline message item with support for informational, positive, | 29 | * An inline message item with support for informational, positive, | ||
33 | * warning and error types, and with support for associated actions. | 30 | * warning and error types, and with support for associated actions. | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
75 | * @endcode | 72 | * @endcode | ||
76 | * | 73 | * | ||
77 | * @since 5.45 | 74 | * @since 5.45 | ||
78 | */ | 75 | */ | ||
79 | 76 | | |||
80 | T.InlineMessage { | 77 | T.InlineMessage { | ||
81 | id: root | 78 | id: root | ||
82 | 79 | | |||
83 | implicitHeight: visible ? contentLayout.implicitHeight + (2 * (background.border.width + Kirigami.Units.smallSpacing)) : 0 | | |||
84 | | ||||
85 | property bool _animating: false | | |||
86 | | ||||
87 | leftPadding: background.border.width + Kirigami.Units.smallSpacing | | |||
88 | topPadding: background.border.width + Kirigami.Units.smallSpacing | | |||
89 | rightPadding: background.border.width + Kirigami.Units.smallSpacing | | |||
90 | bottomPadding: background.border.width + Kirigami.Units.smallSpacing | | |||
91 | | ||||
92 | Behavior on implicitHeight { | | |||
93 | enabled: !root.visible | | |||
94 | | ||||
95 | SequentialAnimation { | | |||
96 | PropertyAction { targets: root; property: "_animating"; value: true } | | |||
97 | NumberAnimation { duration: Kirigami.Units.longDuration } | | |||
98 | } | | |||
99 | } | | |||
100 | | ||||
101 | onVisibleChanged: { | | |||
102 | if (!visible) { | | |||
103 | contentLayout.opacity = 0.0; | | |||
104 | } | | |||
105 | } | | |||
106 | | ||||
107 | opacity: visible ? 1.0 : 0.0 | | |||
108 | | ||||
109 | Behavior on opacity { | | |||
110 | enabled: !root.visible | | |||
111 | | ||||
112 | NumberAnimation { duration: Kirigami.Units.shortDuration } | | |||
113 | } | | |||
114 | | ||||
115 | onOpacityChanged: { | | |||
116 | if (opacity == 0.0) { | | |||
117 | contentLayout.opacity = 0.0; | | |||
118 | } else if (opacity == 1.0) { | | |||
119 | contentLayout.opacity = 1.0; | | |||
120 | } | | |||
121 | } | | |||
122 | | ||||
123 | onImplicitHeightChanged: { | | |||
124 | height = implicitHeight; | | |||
125 | } | | |||
126 | | ||||
127 | background: Rectangle { | 80 | background: Rectangle { | ||
128 | id: bgBorderRect | 81 | id: bgBorderRect | ||
129 | 82 | | |||
130 | color: { | 83 | color: { | ||
131 | if (root.type == Kirigami.MessageType.Positive) { | 84 | if (root.type == Kirigami.MessageType.Positive) { | ||
132 | return Kirigami.Theme.positiveTextColor; | 85 | return Kirigami.Theme.positiveTextColor; | ||
133 | } else if (root.type == Kirigami.MessageType.Warning) { | 86 | } else if (root.type == Kirigami.MessageType.Warning) { | ||
134 | return Kirigami.Theme.neutralTextColor; | 87 | return Kirigami.Theme.neutralTextColor; | ||
Show All 21 Lines | 108 | Rectangle { | |||
156 | anchors.fill: bgFillRect | 109 | anchors.fill: bgFillRect | ||
157 | 110 | | |||
158 | color: bgBorderRect.color | 111 | color: bgBorderRect.color | ||
159 | 112 | | |||
160 | opacity: 0.20 | 113 | opacity: 0.20 | ||
161 | 114 | | |||
162 | radius: bgFillRect.radius | 115 | radius: bgFillRect.radius | ||
163 | } | 116 | } | ||
164 | | ||||
165 | layer.enabled: true | | |||
166 | layer.effect: DropShadow { | | |||
167 | horizontalOffset: 0 | | |||
168 | verticalOffset: 1 | | |||
169 | radius: 12 | | |||
170 | samples: 32 | | |||
171 | color: Qt.rgba(0, 0, 0, 0.5) | | |||
172 | } | | |||
173 | } | | |||
174 | | ||||
175 | contentItem: GridLayout { | | |||
176 | id: contentLayout | | |||
177 | | ||||
178 | // Used to defer opacity animation until we know if InlineMessage was | | |||
179 | // initialized visible. | | |||
180 | property bool complete: false | | |||
181 | | ||||
182 | Behavior on opacity { | | |||
183 | enabled: root.visible && contentLayout.complete | | |||
184 | | ||||
185 | SequentialAnimation { | | |||
186 | NumberAnimation { duration: Kirigami.Units.shortDuration * 2 } | | |||
187 | PropertyAction { targets: root; property: "_animating"; value: false } | | |||
188 | } | | |||
189 | } | | |||
190 | | ||||
191 | rowSpacing: Kirigami.Units.largeSpacing | | |||
192 | columnSpacing: Kirigami.Units.smallSpacing | | |||
193 | | ||||
194 | Kirigami.Icon { | | |||
195 | id: icon | | |||
196 | | ||||
197 | width: Kirigami.Units.iconSizes.smallMedium | | |||
198 | height: width | | |||
199 | | ||||
200 | Layout.alignment: text.lineCount > 1 ? Qt.AlignTop : Qt.AlignVCenter | | |||
201 | | ||||
202 | Layout.minimumWidth: width | | |||
203 | Layout.minimumHeight: height | | |||
204 | | ||||
205 | source: { | | |||
206 | if (root.icon.source) { | | |||
207 | return root.icon.source; | | |||
208 | } | | |||
209 | | ||||
210 | if (root.type == Kirigami.MessageType.Positive) { | | |||
211 | return "dialog-positive"; | | |||
212 | } else if (root.type == Kirigami.MessageType.Warning) { | | |||
213 | return "dialog-warning"; | | |||
214 | } else if (root.type == Kirigami.MessageType.Error) { | | |||
215 | return "dialog-error"; | | |||
216 | } | | |||
217 | | ||||
218 | return "dialog-information"; | | |||
219 | } | | |||
220 | | ||||
221 | color: root.icon.color | | |||
222 | } | | |||
223 | | ||||
224 | MouseArea { | | |||
225 | implicitHeight: text.implicitHeight | | |||
226 | | ||||
227 | Layout.fillWidth: true | | |||
228 | Layout.alignment: text.lineCount > 1 ? Qt.AlignTop : Qt.AlignVCenter | | |||
229 | Layout.row: 0 | | |||
230 | Layout.column: 1 | | |||
231 | | ||||
232 | cursorShape: text.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor | | |||
233 | | ||||
234 | Controls.Label { | | |||
235 | id: text | | |||
236 | | ||||
237 | width: parent.width | | |||
238 | | ||||
239 | color: Kirigami.Theme.textColor | | |||
240 | wrapMode: Text.WordWrap | | |||
241 | elide: Text.ElideRight | | |||
242 | | ||||
243 | text: root.text | | |||
244 | | ||||
245 | onLinkHovered: root.linkHovered(link) | | |||
246 | onLinkActivated: root.linkActivated(link) | | |||
247 | } | | |||
248 | //this must be child of an item which doesn't try to resize it | | |||
249 | TextMetrics { | | |||
250 | id: messageTextMetrics | | |||
251 | | ||||
252 | font: text.font | | |||
253 | text: text.text | | |||
254 | } | | |||
255 | } | | |||
256 | | ||||
257 | Kirigami.ActionToolBar { | | |||
258 | id: actionsLayout | | |||
259 | | ||||
260 | flat: false | | |||
261 | actions: root.actions | | |||
262 | visible: root.actions.length | | |||
263 | | ||||
264 | Layout.alignment: Qt.AlignRight | | |||
265 | | ||||
266 | Layout.row: { | | |||
267 | if (messageTextMetrics.width + Kirigami.Units.smallSpacing > | | |||
268 | (contentLayout.width - icon.width - actionsLayout.width | | |||
269 | - closeButton.width - (3 * contentLayout.columnSpacing))) { | | |||
270 | return 1; | | |||
271 | } | | |||
272 | return 0; | | |||
273 | } | | |||
274 | Layout.column: Layout.row ? 0 : 2 | | |||
275 | Layout.columnSpan: Layout.row ? (closeButton.visible ? 3 : 2) : 1 | | |||
276 | } | | |||
277 | | ||||
278 | Controls.ToolButton { | | |||
279 | id: closeButton | | |||
280 | | ||||
281 | visible: root.showCloseButton | | |||
282 | | ||||
283 | Layout.alignment: text.lineCount > 1 || actionsLayout.Layout.row ? Qt.AlignTop : Qt.AlignVCenter | | |||
284 | Layout.row: 0 | | |||
285 | Layout.column: actionsLayout.Layout.row ? 2 : 3 | | |||
286 | | ||||
287 | //TODO: use toolbuttons icons when we can depend from Qt 5.10 | | |||
288 | Kirigami.Icon { | | |||
289 | anchors.centerIn: parent | | |||
290 | source: "dialog-close" | | |||
291 | width: Kirigami.Units.iconSizes.smallMedium | | |||
292 | height: width | | |||
293 | } | | |||
294 | | ||||
295 | onClicked: root.visible = false | | |||
296 | } | | |||
297 | | ||||
298 | Component.onCompleted: complete = true | | |||
299 | } | 117 | } | ||
300 | } | 118 | } |