Warning, /utilities/skanpage/src/qml/OptionDelegate.qml is written in an unsupported language. File is not indexed.

0001 /**
0002  * SPDX-FileCopyrightText: 2021 by Alexander Stippich <a.stippich@gmx.net>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Controls 2.15
0009 import QtQuick.Layouts 1.1
0010 
0011 import org.kde.kirigami 2.5 as Kirigami
0012 import org.kde.skanpage 1.0
0013 
0014 Item {
0015     id: optionDelegate
0016 
0017     property var modelItem
0018     property bool editMode: false
0019     
0020     implicitHeight: column.implicitHeight
0021     implicitWidth: column.implicitWidth
0022     
0023     Loader {
0024         active: editMode
0025         visible: active
0026 
0027         anchors.fill: parent
0028 
0029         sourceComponent:  Rectangle {
0030             color: model.quickAccess || mouseArea.hovered ? Kirigami.Theme.highlightColor : 'transparent'
0031 
0032             Kirigami.Separator {
0033                 anchors.bottom: parent.bottom
0034                 width: parent.width
0035             }
0036 
0037             MouseArea {
0038                 id: mouseArea
0039                 anchors.fill: parent
0040                 hoverEnabled: true
0041                 onClicked: model.quickAccess = !model.quickAccess
0042             }
0043         }
0044     }
0045 
0046     Column {
0047         id: column
0048         anchors.fill: parent
0049 
0050         spacing: Kirigami.Units.smallSpacing
0051         padding: Kirigami.Units.smallSpacing
0052       
0053         Label {
0054             visible: modelItem.type !== KSaneOption.TypeBool && modelItem.type !== KSaneOption.TypeGamma
0055             text: i18n("%1:", model.title)
0056         }
0057 
0058         RowLayout {
0059             enabled: !editMode
0060 
0061             Loader {
0062                 active: modelItem.type === KSaneOption.TypeInteger
0063                 visible: active
0064 
0065                 sourceComponent: IntegerSpinBoxWithSuffix {
0066                     id: integerSpinBox
0067 
0068                     stepSize: modelItem.step
0069                     from: modelItem.minimum
0070                     to: modelItem.maximum
0071                     suffix: getUnitString(modelItem.unit)
0072                     value: modelItem.value
0073                     editable: true
0074 
0075                     onValueModified: {
0076                         if (value !== modelItem.value) {
0077                             modelItem.value = value
0078                         }
0079                     }
0080                 }
0081             }
0082 
0083             Loader {
0084                 active: modelItem.type === KSaneOption.TypeDouble
0085                 visible: active
0086 
0087                 sourceComponent: DoubleSpinBoxWithSuffix {
0088                     id: doubleSpinBox
0089 
0090                     stepSize: modelItem.step
0091                     from: modelItem.minimum
0092                     to: modelItem.maximum
0093 
0094                     suffix: getUnitString(modelItem.unit)
0095                     Binding on value {value: modelItem.value}
0096                     editable: true
0097 
0098                     onValueModified: {
0099                         if (!doubleSpinBox.approxeq(value, modelItem.value, stepSize / 1000)) {
0100                             modelItem.value = value
0101                         }
0102                     }
0103                 }
0104             }
0105 
0106             Loader {
0107                 active: modelItem.type === KSaneOption.TypeString
0108                 visible: active
0109 
0110                 sourceComponent: TextField {
0111                     text: modelItem.value
0112                     onTextChanged:  {
0113                         if (text !== modelItem.value) {
0114                             modelItem.value = value
0115                         }
0116                     }
0117                 }
0118             }
0119 
0120             Loader {
0121                 active: modelItem.type === KSaneOption.TypeBool
0122                 visible: active
0123 
0124                 sourceComponent: CheckBox {
0125                     text: modelItem.title
0126                     checked: modelItem.value
0127                     onClicked: modelItem.value = !modelItem.value
0128                 }
0129             }
0130 
0131             Loader {
0132                 active: modelItem.type === KSaneOption.TypeAction
0133                 visible: active
0134 
0135                 sourceComponent: Button {
0136                     text: modelItem.title
0137                     onClicked: modelItem.value = 1
0138                 }
0139             }
0140 
0141             Loader {
0142                 active: modelItem.type === KSaneOption.TypeGamma
0143                 visible: active
0144 
0145                 sourceComponent: ColumnLayout {
0146                     readonly property bool isDefaultConfig:
0147                         modelItem.value[0] === 0 && modelItem.value[1] === 0 && modelItem.value[2] === 100
0148                     RowLayout {
0149                         Label {
0150                             text: i18nc("Add ':' to make a header text", "%1:", model.title)
0151                         }
0152                         CheckBox {
0153                             id: gammaEnableCheckbox
0154                             text: i18nc("@option:check a noun, as in 'the default setting'", "Default")
0155                             checked: isDefaultConfig
0156                             onClicked: {
0157                                 if (checked) modelItem.value = [0, 0, 100]
0158                                 else checked = false // Remove binding
0159                             }
0160                         }
0161                     }
0162                     Frame {
0163                         visible: !gammaEnableCheckbox.checked
0164                         ColumnLayout {
0165                             property int tmpVal: 0 // KSaneCore accepts int, Slider gives floats
0166                             spacing: Kirigami.Units.smallSpacing
0167                             Label {
0168                                 text: i18nc("%1 is a numeric value", "Brightness: %1", modelItem.value[0])
0169                             }
0170                             Slider {
0171                                 implicitWidth: 10 * Kirigami.Units.gridUnit
0172                                 from: -50; to: 50
0173                                 value: modelItem.value[0]
0174                                 onMoved: {
0175                                     gammaEnableCheckbox.checked = false // Remove binding
0176                                     parent.tmpVal = value
0177                                     modelItem.value = [parent.tmpVal, modelItem.value[1], modelItem.value[2]]
0178                                 }
0179                             }
0180                             Label {
0181                                 text: i18nc("%1 is a numeric value", "Contrast: %1", modelItem.value[1])
0182                             }
0183                             Slider {
0184                                 implicitWidth: 10 * Kirigami.Units.gridUnit
0185                                 from: -50; to: 50
0186                                 value: modelItem.value[1]
0187                                 onMoved: {
0188                                     gammaEnableCheckbox.checked = false // Remove binding
0189                                     parent.tmpVal = value
0190                                     modelItem.value = [modelItem.value[0], parent.tmpVal, modelItem.value[2]]
0191                                 }
0192                             }
0193                             Label {
0194                                 text: i18nc("%1 is a numeric value", "Gamma: %1", modelItem.value[2])
0195                             }
0196                             Slider {
0197                                 implicitWidth: 10 * Kirigami.Units.gridUnit
0198                                 from: 30; to: 300
0199                                 value: modelItem.value[2]
0200                                 onMoved: {
0201                                     gammaEnableCheckbox.checked = false // Remove binding
0202                                     parent.tmpVal = value
0203                                     modelItem.value = [modelItem.value[0], modelItem.value[1], parent.tmpVal]
0204                                 }
0205                             }
0206                         }
0207                     }
0208                 }
0209             }
0210 
0211             Loader {
0212                 id: comboLoader
0213                 active: modelItem.type === KSaneOption.TypeValueList
0214                 visible: active
0215 
0216                 property var entries: modelItem.valueList
0217                 property var modelValue: modelItem.value
0218                 property string unitSuffix: getUnitString(modelItem.unit)
0219 
0220                 sourceComponent: ComboBox {
0221                     id: combo
0222 
0223                     model: entries
0224                     displayText: unitSuffix === "" || currentText === "" ? currentText : i18nc("Adding unit suffix","%1 %2", currentText, unitSuffix)
0225                     currentIndex: indexOfValue(modelItem.value)
0226 
0227                     onCurrentValueChanged: {
0228                         if (combo.currentValue !== modelItem.value) {
0229                             modelItem.value = combo.currentValue
0230                         }
0231                     }
0232 
0233                     Connections {
0234                         target: comboLoader
0235                         function onModelValueChanged() {
0236                             currentIndex = indexOfValue(modelItem.value)
0237                         }
0238                     }
0239 
0240                     Component.onCompleted: currentIndex = indexOfValue(modelItem.value)
0241                 }
0242             }
0243         }
0244     }
0245 
0246     function getUnitString(unitType) {
0247         switch (unitType) {
0248             case KSaneOption.UnitBit:
0249                 return i18nc("Unit suffix for bit", "bit");
0250                 break;
0251             case KSaneOption.UnitDPI:
0252                 return i18nc("Unit suffix for DPI", "DPI");
0253                 break;
0254             case KSaneOption.UnitMicroSecond:
0255                 return i18nc("Unit suffix for microsecond", "µs");
0256                 break;
0257             case KSaneOption.UnitSecond:
0258                 return i18nc("Unit suffix for second", "s");
0259                 break;
0260             case KSaneOption.UnitMilliMeter:
0261                 return i18nc("Unit suffix for millimeter", "mm");
0262                 break;
0263             case KSaneOption.UnitPercent:
0264                 return i18nc("Unit suffix for percent", "%");
0265                 break;
0266             case KSaneOption.UnitPixel:
0267                 return i18nc("Unit suffix for pixel", "px");
0268                 break;
0269             default:
0270                 return "";
0271         }
0272     }
0273 }