Warning, /graphics/colord-kde/colord-kcm/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002   SPDX-FileCopyrightLabel: 2022 Han Young <hanyoung@protonmail.com>
0003 
0004   SPDX-License-Identifier: LGPL-3.0-or-later
0005 */
0006 import QtQuick
0007 import QtCore
0008 import QtQuick.Controls as QQC2
0009 import QtQuick.Layouts 1.15
0010 import org.kde.kitemmodels 1.0
0011 import org.kde.kirigami 2.15 as Kirigami
0012 import org.kde.kirigami.delegates as KD
0013 import org.kde.kcmutils as KCM
0014 import QtQuick.Dialogs as QtDialogs
0015 import kcmcolord 1
0016 
0017 KCM.AbstractKCM {
0018     id: root
0019     implicitHeight: Kirigami.Units.gridUnit * 40
0020     implicitWidth: Kirigami.Units.gridUnit * 20
0021     property bool isDeviceView: true
0022     property bool isDeviceDescription: true
0023 
0024     onIsDeviceViewChanged: {
0025         if (isDeviceView) {
0026             kcm.deviceDescription.setDevice(deviceView.currentDevicePath);
0027             kcm.profileDescription.setProfile(deviceView.currentProfilePath, deviceView.canRemoveCurrentProfile);
0028         } else {
0029             kcm.profileDescription.setProfile(profileView.currentProfilePath, profileView.canRemoveCurrentProfile);
0030         }
0031     }
0032 
0033     header: QQC2.ToolBar {
0034         Row {
0035             spacing: Kirigami.Units.largeSpacing
0036             anchors.fill: parent
0037 
0038             QQC2.ButtonGroup {
0039                 id: headerGroup
0040             }
0041 
0042             QQC2.ToolButton {
0043                 text: i18nd("colord-kde", "Devices")
0044                 icon.name: "video-display"
0045                 checkable: true
0046                 checked: true
0047                 display: QQC2.AbstractButton.TextUnderIcon
0048                 onClicked: isDeviceView = true
0049                 QQC2.ButtonGroup.group: headerGroup
0050             }
0051             QQC2.ToolButton {
0052                 text: i18nd("colord-kde", "Profiles")
0053                 icon.name: "color-management"
0054                 checkable: true
0055                 display: QQC2.AbstractButton.TextUnderIcon
0056                 onClicked: isDeviceView = false
0057                 QQC2.ButtonGroup.group: headerGroup
0058             }
0059 
0060             QQC2.ToolSeparator {
0061                 implicitHeight: parent.height
0062             }
0063 
0064             QQC2.ToolButton {
0065                 text: i18nd("colord-kde", "Import Profile")
0066                 icon.name: "document-single"
0067                 display: QQC2.AbstractButton.TextUnderIcon
0068                 onClicked: fileDialog.open()
0069             }
0070 
0071             QQC2.ToolButton {
0072                 text: i18nd("colord-kde", "Assign Profile")
0073                 icon.name: "list-add"
0074                 display: QQC2.AbstractButton.TextUnderIcon
0075                 onClicked: assignProfileMenu.open()
0076                 enabled: isDeviceDescription && assignProfileMenu.count > 0
0077                 QQC2.Menu {
0078                     id: assignProfileMenu
0079                 }
0080 
0081                 Connections {
0082                     target: deviceView
0083                     function onCurrentDevicePathChanged() {
0084                         let oldActionsCount = assignProfileMenu.count;
0085                         while (oldActionsCount--) {
0086                             assignProfileMenu.takeItem(0);
0087                         }
0088 
0089                         let items = kcm.getComboBoxItemsForDevice(deviceView.currentDevicePath);
0090                         for (let i = 0; i < items.length; i++) {
0091                             let action = Qt.createQmlObject(`
0092                                                             import QtQuick.Controls 2.15
0093                                                             Action {
0094                                                             }
0095                                                             `,
0096                                                             assignProfileMenu,
0097                                                             "main.qml"
0098                                                             );
0099                             action.text = items[i].profileName;
0100                             action.triggered.connect((a) => {
0101                                 kcm.assignProfileToDevice(items[i].objectPath, deviceView.currentDevicePath);
0102                             });
0103                             assignProfileMenu.addAction(action);
0104                         }
0105                     }
0106                 }
0107             }
0108 
0109             QQC2.ToolButton {
0110                 enabled: (isDeviceView && deviceView.canRemoveCurrentProfile) || (!isDeviceView && profileView.canRemoveCurrentProfile)
0111                 text: i18nd("colord-kde", "Remove Profile")
0112                 icon.name: "list-remove-symbolic"
0113                 display: QQC2.AbstractButton.TextUnderIcon
0114                 onClicked: removeProfileDialog.open()
0115             }
0116         }
0117     }
0118 
0119     QtDialogs.FileDialog {
0120         id: fileDialog
0121         title: i18ndc("colord-kde", "ICC Profile is a tech term", "Import ICC Profile")
0122         currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0]
0123         onAccepted: {
0124             kcm.importProfile(selectedFile);
0125         }
0126         nameFilters: [i18ndc("colord-kde", "ICC Profile is a tech term", "ICC Profile") + "(*.icc)"]
0127     }
0128 
0129     QtDialogs.MessageDialog {
0130         id: removeProfileDialog
0131         title: i18nd("colord-kde", "Remove Profile")
0132 
0133         text: i18nd("colord-kde", "Are you sure you want to remove this profile?")
0134         buttons: QtDialogs.StandardButton.Yes | QtDialogs.StandardButton.No
0135         onAccepted: {
0136             if (isDeviceView) {
0137                 kcm.deviceModel.removeProfile(deviceView.currentProfilePath, deviceView.currentDevicePath);
0138             } else {
0139                 kcm.removeProfile(profileView.currentProfilePath);
0140             }
0141         }
0142     }
0143 
0144     RowLayout {
0145         anchors.fill: parent
0146         QQC2.Frame {
0147             clip: true
0148             id: profileDeviceViewFrame
0149             Layout.fillWidth: true
0150             Layout.fillHeight: true
0151 
0152             QQC2.ScrollView {
0153 
0154                 anchors.fill: parent
0155 
0156                 TreeView {
0157                     property variant currentProfilePath: null
0158                     property variant currentDevicePath: null
0159                     property bool canRemoveCurrentProfile: false
0160 
0161                     id: deviceView
0162                     visible: isDeviceView
0163                     anchors.fill: parent
0164 
0165                     selectionModel: ItemSelectionModel {
0166                         id: selectionModel
0167                         model: kcm.deviceModel
0168                     }
0169 
0170                     model: kcm.deviceModel
0171                     delegate: QQC2.TreeViewDelegate {
0172                         id: listItem
0173                         implicitWidth: TableView.view.width
0174                         contentItem: RowLayout {
0175                             id: layout
0176                             spacing: Kirigami.Units.smallSpacing
0177 
0178                             QQC2.CheckBox {
0179                                 visible: itemType === "profile"
0180                                 checkState: model.profileCheckState // from model data
0181                                 checkable: !checked
0182                                 onCheckedChanged: {
0183                                     if (checked) {
0184                                         kcm.makeProfileDefault(model.objectPath, model.parentObjectPath);
0185                                     }
0186                                 }
0187                             }
0188 
0189                             KD.IconTitleSubtitle {
0190                                 title: model.title
0191                                 icon.name: model.iconName
0192 
0193                                 Layout.fillWidth: true
0194                             }
0195                         }
0196 
0197                         onCurrentChanged: {
0198                             if (current) {
0199                                 if (itemType === "device") {
0200                                     // is device
0201                                     kcm.deviceDescription.setDevice(objectPath);
0202                                     isDeviceDescription = true;
0203 
0204                                     deviceView.currentDevicePath = model.objectPath;
0205                                     deviceView.currentProfilePath = null;
0206                                     deviceView.canRemoveCurrentProfile = false;
0207                                 } else {
0208                                     // is profile
0209                                     kcm.profileDescription.setProfile(objectPath, model.canRemoveProfile);
0210                                     isDeviceDescription = false;
0211                                     deviceView.currentDevicePath = model.parentObjectPath;
0212                                     deviceView.currentProfilePath = model.objectPath;
0213                                     deviceView.canRemoveCurrentProfile = model.canRemoveProfile;
0214                                 }
0215                             }
0216                         }
0217                     }
0218                 }
0219             }
0220 
0221             QQC2.ScrollView {
0222                 visible: !isDeviceView
0223                 anchors.fill: parent
0224 
0225                 Component.onCompleted: background.visible = true
0226 
0227                 ListView {
0228                     id: profileView
0229 
0230                     property variant currentProfilePath: null
0231                     property bool canRemoveCurrentProfile: false
0232 
0233                     clip: true
0234 
0235                     model: profileSortModel
0236                     delegate: QQC2.ItemDelegate {
0237                         id: delegate
0238 
0239                         text: title
0240                         icon.name: iconName
0241 
0242                         width: ListView.view.width
0243                         highlighted: ListView.isCurrentItem
0244 
0245                         contentItem: KD.IconTitleSubtitle {
0246                             title: delegate.text
0247                             subtitle: fileName
0248                             icon: icon.fromControlsIcon(delegate.icon)
0249                         }
0250 
0251                         onClicked: ListView.view.currentIndex = index
0252 
0253                         ListView.onIsCurrentItemChanged: {
0254                             kcm.profileDescription.setProfile(model.objectPath, model.canRemove);
0255                             profileView.currentProfilePath = model.objectPath;
0256                             profileView.canRemoveCurrentProfile = model.canRemove;
0257                         }
0258                     }
0259                     KSortFilterProxyModel {
0260                         id: profileSortModel
0261                         sourceModel: kcm.profileModel
0262                         sortRoleName: "sortString"
0263                     }
0264                 }
0265             }
0266         }
0267 
0268         QQC2.Frame {
0269             Layout.fillHeight: true
0270             Layout.maximumWidth: parent.width * 0.4
0271             Layout.alignment: Qt.AlignLeft | Qt.AlignTop
0272             clip: true
0273             ColumnLayout {
0274                 anchors.fill: parent
0275                 ColumnLayout {
0276                     id: deviceDescriptionView
0277                     visible: isDeviceDescription && isDeviceView
0278                     Layout.alignment: Qt.AlignLeft | Qt.AlignTop
0279                     Layout.fillHeight: true
0280                     Layout.fillWidth: true
0281                     QQC2.Label {
0282                         text: kcm.deviceDescription.deviceTitle
0283                         font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.5
0284                     }
0285                     QQC2.Label {
0286                         text: kcm.deviceDescription.deviceKind
0287                         Layout.alignment: Qt.AlignLeft
0288                     }
0289                     RowLayout {
0290                         QQC2.Label {
0291                             text: i18nd("colord-kde", "Id: ")
0292                         }
0293                         QQC2.Label {
0294                             text: kcm.deviceDescription.deviceID
0295                         }
0296                     }
0297                     RowLayout {
0298                         QQC2.Label {
0299                             text: i18nd("colord-kde", "Scope: ")
0300                         }
0301                         QQC2.Label {
0302                             text: kcm.deviceDescription.deviceScope
0303                         }
0304                     }
0305                     RowLayout {
0306                         QQC2.Label {
0307                             text: i18nd("colord-kde", "Mode: ")
0308                         }
0309                         QQC2.Label {
0310                             text: kcm.deviceDescription.colorSpace
0311                         }
0312                     }
0313                     RowLayout {
0314                         QQC2.Label {
0315                             text: i18nd("colord-kde", "Current Profile: ")
0316                         }
0317                         QQC2.Label {
0318                             text: kcm.deviceDescription.currentProfileTitle
0319                         }
0320                     }
0321 
0322                     Kirigami.InlineMessage {
0323                         text: kcm.deviceDescription.calibrateTipMessage
0324                         Layout.fillWidth: true
0325                         visible: true
0326                     }
0327                 }
0328                 ProfileMetaDataView {
0329                     id: profileDescriptionView
0330                     visible: !isDeviceView || !isDeviceDescription
0331                     Layout.alignment: Qt.AlignLeft | Qt.AlignTop
0332                     Layout.fillHeight: true
0333                     Layout.fillWidth: true
0334                 }
0335             }
0336         }
0337     }
0338 }