Changeset View
Standalone View
src/qtquick/qml/Dialog.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | * | ||||
20 | */ | ||||
21 | | ||||
22 | /** | ||||
23 | * @brief A dialog which has a NewStuff.Page at the base | ||||
24 | * | ||||
25 | * This component is equivalent to the old DownloadDialog, but you should consider | ||||
26 | * using NewStuff.Page instead for a more modern style of integration into your | ||||
27 | * application's flow. | ||||
28 | * @see KNewStuff::DownloadDialog | ||||
29 | * @since 5.63 | ||||
30 | */ | ||||
31 | | ||||
32 | import QtQuick 2.11 | ||||
33 | import QtQuick.Controls 2.5 as QtControls | ||||
34 | import QtQuick.Layouts 1.11 as QtLayouts | ||||
35 | import QtQuick.Dialogs 1.3 as QtDialogs | ||||
ahiemstra: If you're using a Qt 5.12 import anyway, might want to unify the other imports to also use .12… | |||||
Don't actually need 5.12 ones... so i'll scale back to 5.11, but also a bunch of cleanup elsewhere, and also actually /require/ 5.11 because of that other bit of handy functionality with checkIndex :) leinir: Don't actually need 5.12 ones... so i'll scale back to 5.11, but also a bunch of cleanup… | |||||
36 | | ||||
37 | import org.kde.newstuff 1.62 as NewStuff | ||||
38 | | ||||
39 | QtDialogs.Dialog { | ||||
40 | id: component | ||||
41 | | ||||
42 | /** | ||||
43 | * The configuration file to use for this button | ||||
44 | */ | ||||
45 | property alias configFile: newStuffPage.configFile | ||||
46 | | ||||
47 | /** | ||||
48 | * Set the text that should appear as the dialog's title. Will be set as | ||||
49 | * i18n("Download New %1"). | ||||
50 | * | ||||
51 | * @default The name defined by your knsrc config file | ||||
52 | * @note For the sake of consistency, you should NOT override the text propety, just set this one | ||||
53 | */ | ||||
54 | property string downloadNewWhat: engine.name | ||||
55 | title: i18n("Download New %1").arg(component.downloadNewWhat) | ||||
56 | | ||||
57 | /** | ||||
58 | * The engine which handles the content in this dialog | ||||
59 | */ | ||||
60 | property alias engine: newStuffPage.engine | ||||
61 | | ||||
62 | /** | ||||
63 | * The default view mode of the dialog spawned by this button. This should be | ||||
64 | * set using the NewStuff.Page.ViewMode enum | ||||
65 | * @see NewStuff.Page.ViewMode | ||||
66 | */ | ||||
67 | property alias viewMode: newStuffPage.viewMode | ||||
68 | | ||||
69 | /** | ||||
70 | * emitted when the Hot New Stuff dialog is about to be shown, usually | ||||
71 | * as a result of the user having click on the button | ||||
72 | */ | ||||
73 | signal aboutToShowDialog(); | ||||
74 | | ||||
75 | /** | ||||
76 | * Contains the entries which have been changed. | ||||
77 | * @note This is cleared when the dialog is shown, so the changed entries are those | ||||
Any particular reason for using a signal parameter here instead of just setting a property on the dialog? Using a property generally allows for more declarative use of the item. ahiemstra: Any particular reason for using a signal parameter here instead of just setting a property on… | |||||
Because a changedEntries property would logically be for the lifetime of the component instance, where dialogFinished is for this specific time the dialog was opened... The property would reasonably also be useful, but it would be semantically different (unless it's documented as being cleared when the dialog is shown, and then filled with whatever's changed once the dialog has been closed... which we could do, but kind of feels uglier than this signal) leinir: Because a changedEntries property would logically be for the lifetime of the component instance… | |||||
It would match with the FileDialog API (https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html#fileUrls-prop) however, which also has this behaviour. My main problem with signal parameters is that you cannot bind to them, so using the result gets trickier. ahiemstra: It would match with the FileDialog API (https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog. | |||||
Hmm, so it would. I guess documentation helps anyway, i'll switch to doing it like that :) leinir: Hmm, so it would. I guess documentation helps anyway, i'll switch to doing it like that :) | |||||
78 | * changed since the dialog was opened most recently (rather than the lifetime | ||||
79 | * of the instance of the Dialog component) | ||||
80 | */ | ||||
81 | property alias changedEntries: component.engine.changedEntries | ||||
82 | | ||||
83 | onVisibleChanged: { | ||||
84 | if (visible === true) { | ||||
85 | newStuffPage.engine.resetChangedEntries(); | ||||
86 | } | ||||
87 | } | ||||
88 | | ||||
89 | contentItem: QtLayouts.ColumnLayout { | ||||
90 | NewStuff.DialogContent { | ||||
91 | id: newStuffPage | ||||
92 | QtLayouts.Layout.fillWidth: true | ||||
93 | QtLayouts.Layout.fillHeight: true | ||||
94 | downloadNewWhat: component.downloadNewWhat | ||||
95 | } | ||||
96 | QtControls.DialogButtonBox { | ||||
97 | QtLayouts.Layout.fillWidth: true | ||||
98 | QtControls.Button { | ||||
99 | action: QtControls.Action { | ||||
100 | text: i18n("Close") | ||||
101 | shortcut: "esc" | ||||
102 | onTriggered: { | ||||
103 | component.close(); | ||||
104 | } | ||||
105 | } | ||||
106 | QtControls.DialogButtonBox.buttonRole: QtControls.DialogButtonBox.RejectRole // this is a close button, dialog close buttons have a rejection role... | ||||
107 | } | ||||
108 | } | ||||
109 | } | ||||
110 | } |
If you're using a Qt 5.12 import anyway, might want to unify the other imports to also use .12 versions.