Warning, /education/kstars/kstars/kstarslite/qml/modules/KSListView.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 import QtQuick 2.6 0005 import QtQuick.Layouts 1.1 0006 import QtQuick.Controls 2.0 0007 import "../constants/" 1.0 0008 0009 ListView { 0010 id: listView 0011 clip: true 0012 property bool checkCurrent: false 0013 property bool checkable: false 0014 property bool onClickCheck: true //true if the item should be be mapped with a blue rectangle when clicked 0015 0016 property int maxWidth: 0 0017 property bool modelIsChanged: false 0018 implicitWidth: maxWidth 0019 //To skip the case when contentItem.height equals to 99000+ 0020 implicitHeight: contentItem.height >= window.height ? window.height : contentItem.height 0021 0022 //For some reason we can't use num constant inside states so we wrap sysPalette as property 0023 property SystemPalette sysPalette: Num.sysPalette 0024 0025 onCountChanged: { 0026 for(var child in listView.contentItem.children) { 0027 var childWidth = listView.contentItem.children[child].textWidth 0028 if(childWidth == undefined) childWidth = 0 0029 maxWidth = maxWidth > childWidth ? maxWidth : childWidth 0030 } 0031 } 0032 0033 ScrollIndicator.vertical: ScrollIndicator { } 0034 property string textRole: "" 0035 0036 signal clicked(var text, var index, var checked) 0037 property bool modelIsArray: false 0038 0039 onModelChanged: { 0040 modelIsArray = !model ? model.constructor === Array : false 0041 } 0042 0043 delegate: Rectangle { 0044 id: delegateRect 0045 width: parent.width 0046 height: objName.contentHeight + 30 0047 property int textWidth: objRow.width + objRow.anchors.leftMargin*2 0048 property bool checked: false 0049 property string visibleText: objName.text 0050 color: sysPalette.base 0051 0052 border { 0053 color: Num.sysPalette.light//"#becad5" 0054 width: 1 0055 } 0056 0057 Behavior on color { 0058 ColorAnimation { duration: 200 } 0059 } 0060 0061 states: [ 0062 State { 0063 name: "hovered" 0064 PropertyChanges { 0065 target: delegateRect 0066 color: sysPalette.highlight //"#d0e8fa" 0067 } 0068 PropertyChanges { 0069 target: objName 0070 color: sysPalette.highlightedText //"#31363b" 0071 } 0072 }, 0073 State { 0074 name: "selected" 0075 PropertyChanges { 0076 target: delegateRect 0077 color: sysPalette.button//"#2196F3" 0078 } 0079 PropertyChanges { 0080 target: objName 0081 color: sysPalette.buttonText//"#eff0fa" 0082 } 0083 }, 0084 State { 0085 name: "default" 0086 PropertyChanges { 0087 target: delegateRect 0088 color: sysPalette.base//"white" 0089 } 0090 PropertyChanges { 0091 target: objName 0092 color: sysPalette.text//"black" 0093 } 0094 } 0095 ] 0096 0097 MouseArea { 0098 id: delMouseArea 0099 anchors.fill: parent 0100 hoverEnabled: true 0101 0102 function hoveredColor() { 0103 if(pressed) { 0104 delegateRect.state = "selected" 0105 } else { 0106 if(containsMouse) { 0107 delegateRect.state = "hovered" 0108 } else { 0109 delegateRect.state = "default" 0110 } 0111 } 0112 } 0113 0114 onContainsMouseChanged: { 0115 hoveredColor() 0116 } 0117 0118 onPressedChanged: { 0119 hoveredColor() 0120 } 0121 0122 onClicked: { 0123 if(onClickCheck) listView.currentIndex = model.index 0124 if(checkable) delegateRect.checked = !delegateRect.checked 0125 listView.clicked(objName.text, model.index, delegateRect.checked) 0126 } 0127 } 0128 0129 RowLayout { 0130 id: objRow 0131 0132 anchors { 0133 verticalCenter: parent.verticalCenter 0134 left: parent.left 0135 leftMargin: 20 0136 } 0137 0138 Rectangle { 0139 visible: (checkCurrent && listView.currentIndex == model.index) || (checkable && delegateRect.checked) 0140 color: objName.color //"#2173f3" 0141 width: height 0142 height: objName.font.pixelSize/2 0143 radius: width * 0.5 0144 } 0145 0146 KSText { 0147 id: objName 0148 0149 text: textRole == "" ? modelData : listView.modelIsArray ? modelData[textRole] : model[textRole] 0150 wrapMode: Text.WrapAnywhere 0151 0152 Behavior on color { 0153 ColorAnimation { duration: 200 } 0154 } 0155 } 0156 } 0157 } 0158 }