Warning, /sdk/rust-qt-binding-generator/examples/todos/main.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.9 0002 import QtQuick.Controls 2.2 0003 import QtQuick.Layouts 1.3 0004 import RustCode 1.0; 0005 0006 ApplicationWindow { 0007 visible: true 0008 width: 450 0009 height: 580 0010 header: ToolBar { 0011 Label { 0012 anchors.fill: parent 0013 text: qsTr("todos") 0014 font.pixelSize: 30 0015 horizontalAlignment: Text.AlignHCenter 0016 verticalAlignment: Text.AlignVCenter 0017 } 0018 } 0019 0020 Component.onCompleted: { 0021 input.forceActiveFocus() 0022 } 0023 0024 Todos { 0025 id: todoModel 0026 0027 Component.onCompleted: { 0028 add("write bindings.json") 0029 add("run rust_qt_binding_generator") 0030 add("check bindings.h") 0031 add("check bindings.cpp") 0032 add("check interface.rs") 0033 add("write implementation.rs") 0034 add("write main.qml") 0035 } 0036 } 0037 0038 Component { 0039 id: todoDelegate 0040 RowLayout { 0041 // the active tab determines if this item should be shown 0042 // 0: all, 1: active, 2: completed 0043 property bool show: filter.currentIndex === 0 0044 || (filter.currentIndex === 1 && !completed) 0045 || (filter.currentIndex === 2 && completed) 0046 visible: show 0047 width: parent.width 0048 height: show ? implicitHeight : 0 0049 CheckBox { 0050 checked: completed 0051 onToggled: todoModel.setCompleted(index, checked) 0052 } 0053 Item { 0054 Layout.fillWidth: true 0055 Layout.fillHeight: true 0056 Label { 0057 id: label 0058 visible: !editInput.visible 0059 text: description 0060 anchors.fill: parent 0061 verticalAlignment: Text.AlignVCenter 0062 font.strikeout: completed 0063 font.pixelSize: 20 0064 } 0065 MouseArea { 0066 id: mouse 0067 anchors.fill: parent 0068 hoverEnabled: true 0069 onDoubleClicked: { 0070 editInput.text = label.text 0071 editInput.visible = true 0072 editInput.forceActiveFocus() 0073 } 0074 } 0075 Button { 0076 text: 'X' 0077 visible: (mouse.containsMouse && !editInput.visible) 0078 || closeMouse.containsMouse 0079 anchors.right: parent.right 0080 MouseArea { 0081 id: closeMouse 0082 anchors.fill: parent 0083 hoverEnabled: true 0084 onClicked: todoModel.remove(index) 0085 } 0086 } 0087 TextField { 0088 id: editInput 0089 visible: false 0090 anchors.fill: parent 0091 text: description 0092 font.pixelSize: label.font.pixelSize 0093 onAccepted: { 0094 todoModel.setDescription(index, text) 0095 visible = false 0096 } 0097 onActiveFocusChanged: { 0098 // hide when focus is lost 0099 if (!activeFocus) { 0100 visible = false 0101 } 0102 } 0103 Keys.onPressed: { 0104 // on escape, set value, hide (and lose focus) 0105 if (event.key === Qt.Key_Escape) { 0106 todoModel.setDescription(index, text) 0107 visible = false 0108 event.accepted = true 0109 } 0110 } 0111 } 0112 } 0113 } 0114 } 0115 0116 Pane { 0117 anchors.fill: parent 0118 leftPadding: 0 0119 Page { 0120 anchors.fill: parent 0121 header: RowLayout { 0122 CheckBox { 0123 tristate: true 0124 // if there are no todos, do not show this checkbox 0125 // but let it take up the same space 0126 enabled: todoModel.count > 0 0127 opacity: todoModel.count === 0 ? 0 : 1 0128 checkState: { 0129 if (todoModel.activeCount === 0) { 0130 return Qt.Checked 0131 } else if (todoModel.activeCount >= todoModel.count) { 0132 return Qt.Unchecked 0133 } 0134 return Qt.PartiallyChecked 0135 } 0136 onCheckStateChanged: { 0137 // if the change is triggered by a user action on this 0138 // checkbox, check or uncheck all todos 0139 // otherwise, do nothing 0140 // (onToggle does not emit for tristate buttons) 0141 if (activeFocus) { 0142 var checked = checkState !== Qt.Unchecked 0143 todoModel.setAll(checked) 0144 } 0145 } 0146 } 0147 TextField { 0148 id: input 0149 Layout.fillWidth: true 0150 placeholderText: qsTr("What needs to be done?") 0151 onAccepted: { 0152 const todo = text.trim() 0153 if (todo) { 0154 todoModel.add(todo) 0155 } 0156 input.clear() 0157 } 0158 } 0159 } 0160 Flickable { 0161 anchors.fill: parent 0162 ListView { 0163 anchors.fill: parent 0164 model: todoModel 0165 delegate: todoDelegate 0166 } 0167 } 0168 } 0169 } 0170 0171 footer: Pane { 0172 padding: 0 0173 ColumnLayout { 0174 width: parent.width 0175 TabBar { 0176 id: filter 0177 Layout.fillWidth: true 0178 visible: todoModel.count > 0 0179 TabButton { 0180 text: qsTr("All") 0181 checked: true 0182 } 0183 TabButton { 0184 text: qsTr("Active") 0185 } 0186 TabButton { 0187 text: qsTr("Completed") 0188 } 0189 } 0190 RowLayout { 0191 visible: todoModel.count > 0 0192 width: parent.width 0193 Label { 0194 Layout.fillWidth: true 0195 text: (todoModel.activeCount === 1) 0196 ? qsTr("1 item left") 0197 : todoModel.activeCount + qsTr(" items left") 0198 } 0199 Button { 0200 enabled: todoModel.count > todoModel.activeCount 0201 opacity: enabled 0202 text: qsTr("Clear completed") 0203 onClicked: todoModel.clearCompleted() 0204 } 0205 } 0206 } 0207 } 0208 }