Warning, /plasma/plasma-bigscreen/kcms/bigscreen-settings/ui/delegates/ThemePreview.qml is written in an unsupported language. File is not indexed.

0001 /*
0002    Copyright (c) 2016 David Rosca <nowrep@gmail.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License version 2 as published by the Free Software Foundation.
0007 
0008    This library is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011    Library General Public License for more details.
0012 
0013    You should have received a copy of the GNU Library General Public License
0014    along with this library; see the file COPYING.LIB.  If not, write to
0015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016    Boston, MA 02110-1301, USA.
0017 */
0018 import QtQuick 2.4
0019 import QtQuick.Layouts 1.1
0020 import org.kde.kirigami as Kirigami
0021 import org.kde.ksvg as KSvg
0022 
0023 Item {
0024     id: root
0025     property string themeName
0026 
0027     Item {
0028         id: backgroundMask
0029         anchors.fill: parent
0030         clip: true
0031 
0032         KSvg.FrameSvgItem { 
0033             id: background
0034             // Normalize margins around background.
0035             // Some themes like "Air" have huge transparent margins which would result in too small container area.
0036             // Sadly all of the breathing, shadow and border sizes are in one single margin value,
0037             // but for typical themes the border is the smaller part the margin and should be in the size of
0038             // Units.largeSpacing, to which we add another Units.largeSpacing for margin of the visual content
0039             // Ideally Plasma::FrameSvg exposes the transparent margins one day.
0040             readonly property int generalMargin: 2 * Kirigami.Units.largeSpacing
0041             anchors {
0042                 fill: parent
0043                 topMargin: -margins.top + generalMargin
0044                 bottomMargin: -margins.bottom + generalMargin
0045                 leftMargin: -margins.left + generalMargin
0046                 rightMargin: -margins.right + generalMargin
0047             }
0048             imagePath: "widgets/background"
0049         }
0050     }
0051 
0052     RowLayout {
0053         id: contents
0054         spacing: 0
0055         anchors {
0056             fill: parent
0057             topMargin: background.generalMargin
0058             bottomMargin: background.generalMargin
0059             leftMargin: background.generalMargin
0060             rightMargin: background.generalMargin
0061         }
0062 
0063         // Icons
0064         ColumnLayout {
0065             id: icons
0066             Layout.fillHeight: true
0067 
0068             Kirigami.Icon {
0069                 id: computerIcon
0070                 Layout.fillHeight: true
0071                 source: "computer"
0072             }
0073 
0074             Kirigami.Icon {
0075                 id: applicationsIcon
0076                 Layout.fillHeight: true
0077                 source: "applications-other"
0078             }
0079 
0080             Kirigami.Icon {
0081                 id: logoutIcon
0082                 Layout.fillHeight: true
0083                 source: "system-log-out"
0084             }
0085         }
0086 
0087         // Analog clock
0088         Item {
0089             id: clock
0090             Layout.fillHeight: true
0091             Layout.fillWidth: true
0092             Layout.preferredWidth: height
0093             Layout.alignment: Qt.AlignHCenter
0094             property int hours: 9
0095             property int minutes: 5
0096 
0097             readonly property double svgScale: face.width / face.naturalSize.width
0098             readonly property double horizontalShadowOffset:
0099                 Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) + Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) % 2
0100             readonly property double verticalShadowOffset:
0101                 Math.round(clockSvg.naturalVerticalHandShadowOffset * svgScale) + Math.round(clockSvg.naturalVerticalHandShadowOffset * svgScale) % 2
0102 
0103             KSvg.Svg {
0104                 id: clockSvg
0105                 imagePath: "widgets/clock"
0106                 function estimateHorizontalHandShadowOffset() {
0107                     var id = "hint-hands-shadow-offset-to-west";
0108                     if (hasElement(id)) {
0109                         return -elementSize(id).width;
0110                     }
0111                     id = "hint-hands-shadows-offset-to-east";
0112                     if (hasElement(id)) {
0113                         return elementSize(id).width;
0114                     }
0115                     return 0;
0116                 }
0117                 function estimateVerticalHandShadowOffset() {
0118                     var id = "hint-hands-shadow-offset-to-north";
0119                     if (hasElement(id)) {
0120                         return -elementSize(id).height;
0121                     }
0122                     id = "hint-hands-shadow-offset-to-south";
0123                     if (hasElement(id)) {
0124                         return elementSize(id).height;
0125                     }
0126                     return 0;
0127                 }
0128                 property double naturalHorizontalHandShadowOffset: estimateHorizontalHandShadowOffset()
0129                 property double naturalVerticalHandShadowOffset: estimateVerticalHandShadowOffset()
0130                 onRepaintNeeded: {
0131                     naturalHorizontalHandShadowOffset = estimateHorizontalHandShadowOffset();
0132                     naturalVerticalHandShadowOffset = estimateVerticalHandShadowOffset();
0133                 }
0134             }
0135 
0136             KSvg.SvgItem {
0137                 id: face
0138                 anchors.centerIn: parent
0139                 width: Math.min(parent.width, parent.height)
0140                 height: Math.min(parent.width, parent.height)
0141                 svg: clockSvg
0142                 elementId: "ClockFace"
0143             }
0144 
0145             Hand {
0146                 elementId: "HourHand"
0147                 rotationCenterHintId: "hint-hourhand-rotation-center-offset"
0148                 rotation: 180 + clock.hours * 30 + (clock.minutes/2)
0149                 svgScale: clock.svgScale
0150             }
0151 
0152             Hand {
0153                 elementId: "MinuteHand"
0154                 rotationCenterHintId: "hint-minutehand-rotation-center-offset"
0155                 rotation: 180 + clock.minutes * 6
0156                 svgScale: clock.svgScale
0157             }
0158 
0159             KSvg.SvgItem {
0160                 id: center
0161                 width: naturalSize.width * clock.svgScale
0162                 height: naturalSize.height * clock.svgScale
0163                 anchors.centerIn: clock
0164                 svg: clockSvg
0165                 elementId: "HandCenterScrew"
0166                 z: 1000
0167             }
0168 
0169             KSvg.SvgItem {
0170                 anchors.fill: face
0171                 svg: clockSvg
0172                 elementId: "Glass"
0173                 width: naturalSize.width * clock.svgScale
0174                 height: naturalSize.height * clock.svgScale
0175             }
0176         }
0177     }
0178 
0179     Component.onCompleted: {
0180         kcm.applyPlasmaTheme(root, themeName);
0181     }
0182 }