Purpose

AlternativesView.qml
1/*
2 SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7import QtQuick
8import QtQuick.Layouts
9import QtQuick.Controls
10import org.kde.purpose
11
12StackView {
13 id: stack
14
15 focus: true
16
17 implicitHeight: currentItem.implicitHeight
18
19 property bool running: false
20 property alias pluginType: altsModel.pluginType
21 property alias inputData: altsModel.inputData
22 property Component highlight
23 property Component header
24 property Component footer
25 property var verticalLayoutDirection: ListView.TopToBottom
26 property Component delegate: Component {
27 RowLayout {
28 width: ListView.view.width
29 Label {
30 Layout.fillWidth: true
31 text: display
32 elide: Text.ElideRight
33 }
34 Button {
35 text: i18nd("libpurpose6_quick", "Use")
36 onClicked: createJob(index);
37 }
38 Keys.onReturnPressed: createJob(index)
39 Keys.onEnterPressed: createJob(index)
40 }
41 }
42
43 /**
44 * Signals when the job finishes, reports the
45 * @p error code and a text @p message.
46 *
47 * @p output will specify the output offered by the job
48 */
49 signal finished(var output, int error, string message)
50
51 PurposeAlternativesModel {
52 id: altsModel
53 }
54
55 /**
56 * Adopts the job at the @p index.
57 */
58 function createJob(index) {
59 stack.push(jobComponent, {index: index})
60 }
61
62 /**
63 * Clears and returns back to the initial view.
64 */
65 function reset() {
66 for(; stack.depth>1; stack.pop())
67 {}
68 }
69
70 initialItem: ListView {
71 ScrollBar.vertical: ScrollBar {}
72 focus: true
73 model: altsModel
74
75 implicitHeight: contentHeight
76
77 verticalLayoutDirection: stack.verticalLayoutDirection
78 delegate: stack.delegate
79 highlight: stack.highlight
80 footer: stack.footer
81 header: stack.header
82 }
83
84 Component {
85 id: jobComponent
86
87 JobView {
88 id: jobView
89 model: altsModel
90
91 onStateChanged: {
92 if (state === PurposeJobController.Finished || state === PurposeJobController.Error) {
93 stack.finished(jobView.job.output, jobView.job.error, jobView.job.errorString);
94 } else if (state === PurposeJobController.Cancelled) {
95 stack.pop();
96 }
97 }
98
99 Component.onCompleted: start()
100 }
101 }
102}
Q_SCRIPTABLE Q_NOREPLY void start()
KGuiItem reset()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:19:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.