Warning, /plasma/wacomtablet/src/applet/package/contents/ui/FullRepresentation.qml is written in an unsupported language. File is not indexed.

0001 // -*- coding: iso-8859-1 -*-
0002 /*
0003  *   Copyright 2015 Weng Xuetian <wengxt@gmail.com>
0004  *
0005  *   This program is free software; you can redistribute it and/or modify
0006  *   it under the terms of the GNU Library General Public License as
0007  *   published by the Free Software Foundation; either version 2 or
0008  *   (at your option) any later version.
0009  *
0010  *   This program is distributed in the hope that it will be useful,
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  *   GNU General Public License for more details
0014  *
0015  *   You should have received a copy of the GNU Library General Public
0016  *   License along with this program; if not, write to the
0017  *   Free Software Foundation, Inc.,
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0019  */
0020 
0021 import QtQuick
0022 import QtQuick.Layouts
0023 import org.kde.plasma.plasmoid
0024 import org.kde.plasma.components as PC3
0025 import org.kde.ksvg as KSvg
0026 import org.kde.kirigami as Kirigami
0027 
0028 Item {
0029     function defaultValue(value, d) {
0030         return (typeof value == 'undefined') ? d : value;
0031     }
0032 
0033     function deviceLabel() {
0034         if (dataSource.data["wacomtablet"]["serviceAvailable"]) {
0035             if (dataModel.count == 0) {
0036                 return i18n("Graphic Tablet - Device not detected.");
0037             } else {
0038                 if (tabletComboBox.currentIndex >= 0) {
0039                     return dataModel.get(tabletComboBox.currentIndex).name;
0040                 }
0041                 return "";
0042             }
0043         }
0044 
0045         return i18n("Error - Tablet service not available.");
0046     }
0047     
0048     Row {
0049         id: title
0050         anchors {
0051             top: parent.top
0052             left: parent.left
0053             right: parent.right
0054         }
0055         spacing: Kirigami.Units.smallSpacing
0056         
0057         Kirigami.Icon {
0058             id: titleIcon
0059             source: "input-tablet"
0060             width: Kirigami.Units.iconSizes.medium
0061             height: width
0062         }
0063         PC3.Label {
0064             id: deviceNameLabel
0065             anchors.verticalCenter: parent.verticalCenter
0066             width: parent.width - titleIcon.width - parent.spacing
0067             text: deviceLabel()
0068             wrapMode: Text.Wrap
0069         }
0070     }
0071 
0072     KSvg.SvgItem {
0073         id: separator
0074         anchors {
0075             top: title.bottom
0076             left: parent.left
0077             right: parent.right
0078         }
0079         elementId: "horizontal-line"
0080         svg: lineSvg
0081         height: lineSvg.elementSize("horizontal-line").height
0082     }
0083 
0084     Row {
0085         anchors {
0086             top: separator.bottom
0087             bottom: parent.bottom
0088             left: parent.left
0089             right: parent.right
0090             topMargin: Kirigami.Units.smallSpacing
0091             leftMargin: Kirigami.Units.smallSpacing
0092         }
0093         visible: !root.active
0094         spacing: Kirigami.Units.smallSpacing * 2
0095         
0096         Kirigami.Icon {
0097             id: errorIcon
0098             width: Kirigami.Units.iconSizes.medium
0099             height: width
0100             source: "dialog-warning"
0101         }
0102         PC3.Label {
0103             id: errorLabel
0104             width: parent.width - errorIcon.width - parent.spacing
0105             text: dataSource.data["wacomtablet"]["serviceAvailable"] ?
0106                 i18n("This widget is inactive because your tablet device is not connected or currently not supported.") :
0107                 i18n("Please start the KDE wacom tablet service.\nThe service is required for tablet detection and profile support.")
0108             wrapMode: Text.Wrap
0109         }
0110     }
0111 
0112     function setProfile() {
0113         profileComboBox.currentIndex = dataModel.get(tabletComboBox.currentIndex).currentProfile;
0114     }
0115 
0116     GridLayout {
0117         id: selector
0118         anchors {
0119             left: parent.left
0120             right: parent.right
0121             top: separator.bottom
0122             topMargin: Kirigami.Units.smallSpacing
0123         }
0124         visible: root.active
0125         columns: 2
0126         PC3.Label {
0127             text: i18n("Select Tablet:")
0128         }
0129 
0130         PC3.ComboBox {
0131             id: tabletComboBox
0132             Layout.fillWidth: true
0133             model: dataModel
0134             textRole: "name"
0135             onCurrentIndexChanged: {
0136                 profileModel.clear();
0137                 profileComboBox.currentIndex = -1;
0138                 if (tabletComboBox.currentIndex < 0) {
0139                     return;
0140                 }
0141 
0142                 var profiles = dataModel.get(tabletComboBox.currentIndex).profiles;
0143                 if (typeof profiles == "undefined") {
0144                     return;
0145                 }
0146                 for (var i = 0; i < profiles.length; i++) {
0147                     profileModel.append({"name" : profiles[i]});
0148                 }
0149 
0150                 setProfile();
0151             }
0152         }
0153 
0154         PC3.Label {
0155             text: i18n("Select Profile:")
0156         }
0157 
0158         ListModel {
0159             id: profileModel
0160         }
0161 
0162         PC3.ComboBox {
0163             id: profileComboBox
0164             Layout.fillWidth: true
0165             model: profileModel
0166             textRole: "name"
0167 
0168             onActivated: {
0169                 if (tabletComboBox.currentIndex < 0) {
0170                     return;
0171                 }
0172                 var service = dataSource.serviceForSource("wacomtablet");
0173                 var operation = service.operationDescription("SetProfile");
0174                 operation.tabletId = dataModel.get(tabletComboBox.currentIndex).id;
0175                 operation.profile = profileModel.get(index).name;
0176                 service.startOperationCall(operation);
0177             }
0178         }
0179     }
0180 
0181     Connections {
0182         target: dataSource
0183         function onConnectedSourcesChanged() {
0184             tabletComboBox.currentIndex = -1;
0185             if (dataModel.count > 0) {
0186                 tabletComboBox.currentIndex = 0;
0187             }
0188         }
0189 
0190         function onNewData() {
0191             if (tabletComboBox.currentIndex < 0) {
0192                 return;
0193             }
0194 
0195             var current = dataModel.get(tabletComboBox.currentIndex)
0196             if (sourceName == current.DataEngineSource) {
0197                 setProfile();
0198             }
0199         }
0200     }
0201 
0202     PC3.GroupBox {
0203         visible: root.active
0204         anchors {
0205             left: parent.left
0206             right: parent.right
0207             top: selector.bottom
0208             bottom: parent.bottom
0209             topMargin: Kirigami.Units.smallSpacing
0210         }
0211         title: i18nc( "Groupbox Settings for the applet to change some values on the fly", "Settings" )
0212         GridLayout {
0213             columns: 2
0214             PC3.Label {
0215                 visible: defaultValue(dataModel.get(tabletComboBox.currentIndex).hasTouch, false)
0216                 text: i18nc( "Toggle between touch on/off", "Touch:" )
0217             }
0218 
0219             PC3.CheckBox {
0220                 visible: defaultValue(dataModel.get(tabletComboBox.currentIndex).hasTouch, false);
0221                 checked: defaultValue(dataModel.get(tabletComboBox.currentIndex).touch, false);
0222             }
0223 
0224 
0225             PC3.Label {
0226                 text: i18nc( "Rotation of the tablet pad", "Rotation:" )
0227             }
0228 
0229             RowLayout {
0230                 RotationButton {
0231                     rotation: "none"
0232                     icon.name: "input-tablet"
0233                     PC3.ToolTip.text: i18nc("Either no orientation or the current screen orientation is applied to the tablet.", "Default Orientation");
0234                     PC3.ToolTip.delay: Kirigami.Units.toolTipDelay
0235                     PC3.ToolTip.visible: hovered
0236                 }
0237                 RotationButton {
0238                     rotation: "cw"
0239                     icon.name: "object-rotate-left"
0240                     PC3.ToolTip.text: i18nc("The tablet will be rotated clockwise.", "Rotate Tablet Clockwise")
0241                     PC3.ToolTip.delay: Kirigami.Units.toolTipDelay
0242                     PC3.ToolTip.visible: hovered
0243                 }
0244                 RotationButton {
0245                     rotation: "ccw"
0246                     icon.name: "object-rotate-right"
0247                     PC3.ToolTip.text: i18nc("The tablet will be rotated counterclockwise.", "Rotate Tablet Counterclockwise")
0248                     PC3.ToolTip.delay: Kirigami.Units.toolTipDelay
0249                     PC3.ToolTip.visible: hovered
0250                 }
0251                 RotationButton {
0252                     rotation: "half"
0253                     icon.name: "object-flip-vertical"
0254                     PC3.ToolTip.text: i18nc("The tablet will be rotated up side down.", "Rotate Tablet Upside-Down")
0255                     PC3.ToolTip.delay: Kirigami.Units.toolTipDelay
0256                     PC3.ToolTip.visible: hovered
0257                 }
0258             }
0259             PC3.Label {
0260                 text: i18nc( "Toggle between absolute/relative penmode", "Mode:" )
0261             }
0262             RowLayout {
0263                 PC3.RadioButton {
0264                     text: i18nc( "absolute pen movement (pen mode)", "Absolute" )
0265                     checked: defaultValue(dataModel.get(tabletComboBox.currentIndex).stylusMode, true);
0266                     onClicked : {
0267                         if (tabletComboBox.currentIndex < 0) {
0268                             return;
0269                         }
0270                         var service = dataSource.serviceForSource("wacomtablet");
0271                         var operation = service.operationDescription("SetStylusMode");
0272                         operation.tabletId = dataModel.get(tabletComboBox.currentIndex).id;
0273                         operation.mode = "absolute";
0274                         service.startOperationCall(operation);
0275                     }
0276                 }
0277                 PC3.RadioButton {
0278                     text: i18nc( "relative pen movement (mouse mode)", "Relative" )
0279                     onClicked : {
0280                         if (tabletComboBox.currentIndex < 0) {
0281                             return;
0282                         }
0283                         var service = dataSource.serviceForSource("wacomtablet");
0284                         var operation = service.operationDescription("SetStylusMode");
0285                         operation.tabletId = dataModel.get(tabletComboBox.currentIndex).id;
0286                         operation.mode = "relative";
0287                         service.startOperationCall(operation);
0288                     }
0289                 }
0290             }
0291         }
0292     }
0293 
0294 }