Warning, /utilities/kalk/src/qml/HistoryView.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020 cahfofpai 0004 * 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 import QtQuick 0008 import QtQuick.Controls 0009 import QtQuick.Layouts 0010 import org.kde.kirigami as Kirigami 0011 import org.kde.kirigamiaddons.delegates as Delegates 0012 0013 Kirigami.ScrollablePage { 0014 id: page 0015 title: i18n("History") 0016 0017 property int historyIndex 0018 0019 Connections { 0020 target: pageStack 0021 function onCurrentItemChanged () { 0022 const index = listView.atYEnd ? 0 : listView.indexAt(listView.contentX, listView.contentY) 0023 inputManager.setHistoryIndex(index); 0024 } 0025 } 0026 0027 actions: Kirigami.Action { 0028 icon.name: "edit-clear-history" 0029 text: i18n("Clear history") 0030 onTriggered: promptDialog.open() 0031 } 0032 0033 ListView { 0034 id: listView 0035 0036 property int flexPointSize: Math.min(Kirigami.Theme.defaultFont.pointSize * 2, Math.max(width / 30, 7)) 0037 0038 Component.onCompleted: { 0039 if (page.historyIndex && page.historyIndex < listView.count) { 0040 positionViewAtIndex(page.historyIndex, ListView.Beginning) 0041 } else { 0042 positionViewAtEnd() 0043 } 0044 } 0045 0046 currentIndex: -1 0047 model: historyManager 0048 delegate: Delegates.RoundedItemDelegate { 0049 id: historyDelegate 0050 0051 required property int index 0052 required property var model 0053 0054 highlighted: false 0055 0056 contentItem: RowLayout { 0057 id: item 0058 spacing: Kirigami.Units.smallSpacing 0059 0060 property var parts: model.display.split("=") 0061 0062 Button { 0063 Layout.maximumWidth: listView.width / 2.5 0064 Layout.alignment: Qt.AlignLeft 0065 focusPolicy: Qt.NoFocus 0066 flat: true 0067 onClicked: { 0068 inputManager.fromHistory(item.parts[0].trim()); 0069 if (applicationWindow().pageStack.visibleItems.length === 1) { 0070 applicationWindow().pageStack.pop(); 0071 } 0072 } 0073 contentItem: Label { 0074 font { 0075 pointSize: listView.flexPointSize 0076 weight: Font.Light 0077 } 0078 text: item.parts[0].trim() 0079 elide: Text.ElideRight 0080 } 0081 0082 ToolTip.visible: contentItem.truncated && hovered 0083 ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval 0084 ToolTip.text: contentItem.text 0085 } 0086 0087 Label { 0088 Layout.alignment: Qt.AlignLeft 0089 font { 0090 pointSize: listView.flexPointSize 0091 weight: Font.Light 0092 } 0093 text: "=" 0094 } 0095 0096 Button { 0097 Layout.fillWidth: true 0098 Layout.alignment: Qt.AlignLeft 0099 focusPolicy: Qt.NoFocus 0100 flat: true 0101 onClicked: { 0102 inputManager.fromHistory(item.parts[1].trim()); 0103 if (applicationWindow().pageStack.visibleItems.length === 1) { 0104 applicationWindow().pageStack.pop(); 0105 } 0106 } 0107 contentItem: Label { 0108 font { 0109 pointSize: listView.flexPointSize 0110 weight: Font.Light 0111 } 0112 text: item.parts[1].trim() 0113 elide: Text.ElideRight 0114 } 0115 0116 ToolTip.visible: contentItem.truncated && hovered 0117 ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval 0118 ToolTip.text: contentItem.text 0119 } 0120 0121 Button { 0122 Layout.alignment: Qt.AlignRight 0123 icon.name: "delete" 0124 onClicked: historyManager.deleteFromHistory(model.index); 0125 focusPolicy: Qt.NoFocus 0126 flat: true 0127 } 0128 } 0129 } 0130 0131 Kirigami.PlaceholderMessage { 0132 anchors.centerIn: parent 0133 text: i18n("History is empty") 0134 visible: listView.count === 0 0135 width: parent.width - Kirigami.Units.gridUnit * 4 0136 } 0137 } 0138 0139 Kirigami.PromptDialog { 0140 id: promptDialog 0141 title: i18nc("Delete all items from a list", "Clear All History?") 0142 subtitle: i18nc("Deleted items cannot be recovered", "This is permanent and cannot be undone") 0143 standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel 0144 onAccepted: historyManager.clearHistory(); 0145 onRejected: close() 0146 } 0147 }