QtMvvm  1.0.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
SettingsView.qml
1 import QtQuick 2.10
2 import QtQuick.Controls 2.3
3 import QtQuick.Controls.Material 2.3
4 import QtQuick.Layouts 1.3
5 import de.skycoder42.QtMvvm.Core 1.0
6 import de.skycoder42.QtMvvm.Quick 1.0
7 
17 Page {
18  id: _settingsView
19 
31  property SettingsViewModel viewModel: null
45  property bool fullClose: false
46 
58  function closeAction() {
59  return !fullClose && _settingsStack.closeAction();
60  }
61 
62  header: ContrastToolBar {
63  id: _toolBar
64 
65  RowLayout {
66  id: _toolLayout
67  anchors.fill: parent
68  spacing: 0
69 
70  Item {
71  id: _labelContainer
72 
73  Layout.fillWidth: true
74  Layout.fillHeight: true
75  Layout.leftMargin: 16
76 
77  ToolBarLabel {
78  id: _titleLabel
79  anchors.fill: parent
80  leftPadding: 0
81  text: qsTr("Settings")
82  visible: !_searchField.visible
83  }
84 
85  TextField {
86  id: _searchField
87  horizontalAlignment: Qt.AlignLeft
88  verticalAlignment: Qt.AlignVCenter
89  anchors.right: parent.right
90  anchors.verticalCenter: parent.verticalCenter
91  height: Math.min(implicitHeight, parent.height)
92  width: parent.width
93  }
94  }
95 
96  ActionButton {
97  id: _searchButton
98  visible: _builder.allowSearch
99  text: qsTr("Search in settings")
100  onClicked: toggleSearchState()
101  }
102 
103  ActionButton {
104  id: _restoreButton
105  visible: _builder.allowRestore
106  icon.source: "qrc:/de/skycoder42/qtmvvm/quick/icons/ic_settings_backup_restore.svg"
107  text: qsTr("Restore settings")
108  onClicked: _builder.restoreDefaults()
109  }
110  }
111  }
112 
113  states: [
114  State {
115  name: "title"
116  PropertyChanges {
117  target: _searchButton
118  icon.name: "search"
119  icon.source: "qrc:/de/skycoder42/qtmvvm/quick/icons/ic_search.svg"
120  }
121  PropertyChanges {
122  target: _titleLabel
123  visible: true
124  }
125  PropertyChanges {
126  target: _searchField
127  visible: false
128  width: 0
129  }
130  StateChangeScript {
131  name: "focusScript"
132  script: _searchField.clear();
133  }
134  },
135  State {
136  name: "search"
137  PropertyChanges {
138  target: _searchButton
139  icon.name: "gtk-close"
140  icon.source: "qrc:/de/skycoder42/qtmvvm/quick/icons/ic_close.svg"
141  }
142  PropertyChanges {
143  target: _titleLabel
144  visible: false
145  }
146  PropertyChanges {
147  target: _searchField
148  visible: true
149  width: _labelContainer.width
150  }
151  StateChangeScript {
152  name: "focusScript"
153  script: _searchField.forceActiveFocus();
154  }
155  }
156  ]
157  transitions: [
158  Transition {
159  from: "title"
160  to: "search"
161  SequentialAnimation {
162  PropertyAnimation {
163  target: _searchField
164  property: "visible"
165  duration: 0
166  }
167  PropertyAnimation {
168  target: _searchField
169  property: "width"
170  duration: 250
171  easing.type: Easing.InOutCubic
172  }
173  PropertyAnimation {
174  target: _titleLabel
175  property: "visible"
176  duration: 0
177  }
178  }
179  },
180  Transition {
181  from: "search"
182  to: "title"
183  SequentialAnimation {
184  PropertyAnimation {
185  target: _titleLabel
186  property: "visible"
187  duration: 0
188  }
189  PropertyAnimation {
190  target: _searchField
191  property: "width"
192  duration: 250
193  easing.type: Easing.InOutCubic
194  }
195  PropertyAnimation {
196  target: _searchField
197  property: "visible"
198  duration: 0
199  }
200  }
201  }
202  ]
203 
204  state: "title"
205 
207  function toggleSearchState() {
208  if(state == "title")
209  state = "search";
210  else
211  state = "title";
212  }
213 
215 
216  StackView {
217  id: _settingsStack
218  anchors.fill: parent
219 
220  function closeAction() {
221  if(_settingsStack.depth <= 1)
222  return false;
223  else {
224  _settingsStack.pop();
225  return true;
226  }
227  }
228  }
229 
230  Component {
231  id: _overviewComponent
232 
233  OverviewListView {
234  id: __ovListView
235  builder: _builder
236 
237  Component.onCompleted: _settingsStack.push(__ovListView)
238  }
239  }
240 
241  Component {
242  id: _sectionViewComponent
243 
244  SectionListView {
245  id: __secListView
246  builder: _builder
247 
248  Component.onCompleted: _settingsStack.push(__secListView)
249  }
250  }
251 
252  SettingsUiBuilder {
253  id: _builder
254  buildView: _settingsView
255  viewModel: _settingsView.viewModel
256  filterText: _searchField.text
257 
258  onPresentOverview: _overviewComponent.incubateObject(_settingsStack, {
259  model: model,
260  showSections: hasSections
261  }, Qt.Asynchronous)
262  onPresentSection: _sectionViewComponent.incubateObject(_settingsStack, {
263  model: model
264  }, Qt.Asynchronous)
265 
266  onCloseSettings: {
267  _settingsView.fullClose = true;
269  }
270  }
271 }
A ProgressBar with automatic bindings to the presenters view loading progress.
An extension of the ToolBar for better appearance.
The QML import for the QtMvvmCore QML module.
static void popView()
Pops the current top level view.
An extension of the Label for better appearance when used in a toolbar.
The QML import for the QtMvvmQuick QML module.
Definition: ActionButton.qml:4
An extension of the ToolButton for better appearance.
A QML singleton to access common presenter methods globally.