Warning, /plasma/kdeplasma-addons/applets/comic/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2012 Reza Fatahilah Shah <rshah0385@kireihana.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.1
0008 import QtQuick.Layouts 1.1
0009 
0010 import org.kde.plasma.plasmoid 2.0
0011 import org.kde.plasma.core as PlasmaCore
0012 import org.kde.kirigami 2.20 as Kirigami
0013 import org.kde.plasma.components 3.0 as PlasmaComponents3
0014 import org.kde.kquickcontrolsaddons 2.0
0015 
0016 PlasmoidItem {
0017     id: mainWindow
0018 
0019     readonly property int implicitWidth: Kirigami.Units.gridUnit * 40
0020     readonly property int implicitHeight: Kirigami.Units.gridUnit * 15
0021     Plasmoid.backgroundHints: PlasmaCore.Types.DefaultBackground | PlasmaCore.Types.ConfigurableBackground
0022     switchWidth: {
0023         if (centerLayout.comicData.image) {
0024             return Math.max(minimumWidth, Math.min(centerLayout.comicData.image.nativeWidth * 0.6, implicitWidth));
0025         } else {
0026             return Kirigami.Units.gridUnit * 8;
0027         }
0028     }
0029     switchHeight: {
0030         if (centerLayout.comicData.image) {
0031             return Math.max(minimumHeight, Math.min(centerLayout.comicData.image.nativeHeight * 0.6, implicitHeight));
0032         } else {
0033             return Kirigami.Units.gridUnit * 8;
0034         }
0035     }
0036     Plasmoid.icon: "face-laughing"
0037 
0038     width: implicitWidth
0039     height: implicitHeight
0040 
0041     readonly property int minimumWidth: Kirigami.Units.gridUnit * 8
0042     readonly property int minimumHeight: Kirigami.Units.gridUnit * 8
0043     readonly property bool showComicAuthor: plasmoid.showComicAuthor
0044     readonly property bool showComicTitle: plasmoid.showComicTitle
0045     readonly property bool showErrorPicture: plasmoid.showErrorPicture
0046     readonly property bool middleClick: plasmoid.middleClick
0047 
0048     Connections {
0049         target: plasmoid
0050 
0051         function onComicsModelChanged() {
0052             comicTabbar.currentTab = comicTabbar.layout.children[1];
0053         }
0054 
0055         function onTabHighlightRequest(id, highlight) {
0056             for (var i = 0; i < comicTabbar.layout.children.length; ++i) {
0057                 var button = comicTabbar.layout.children[i];
0058 
0059                 if (button.key !== undefined && button.key == id) {
0060                     button.highlighted = highlight;
0061                 }
0062             }
0063         }
0064 
0065         function onShowNextNewStrip() {
0066             var firstButton = undefined;
0067 
0068             for (var i = 0; i < comicTabbar.layout.children.length; ++i) {
0069                 var button = comicTabbar.layout.children[i];
0070                 if (button.key !== undefined && button.highlighted == true) {
0071                     //key is ordered
0072                     if (button.key > comicTabbar.currentTab.key) {
0073                         comicTabbar.currentTab = button;
0074                         return;
0075                     } else if (firstButton === undefined){
0076                         firstButton = button;
0077                     }
0078                 }
0079             }
0080 
0081             if (firstButton !== undefined) {
0082                 comicTabbar.currentTab = firstButton;
0083             }
0084         }
0085     }
0086 
0087     Item {
0088         anchors.fill: parent
0089         PlasmaComponents3.TabBar {
0090             id: comicTabbar
0091 
0092             anchors {
0093                 left: parent.left
0094                 right: parent.right
0095             }
0096 
0097             visible: plasmoid.tabIdentifiers.length > 1
0098 
0099             onCurrentIndexChanged: {
0100                 console.log("onCurrentTabChanged:" + comicTabbar.currentItem.key);
0101                 plasmoid.tabChanged(comicTabbar.currentItem.key);
0102             }
0103 
0104             Repeater {
0105                 model: plasmoid.comicsModel
0106                 delegate:  PlasmaComponents3.TabButton {
0107                     id: tabButton
0108 
0109                     readonly property string key: model.key
0110                     property bool highlighted: model.highlight
0111 
0112                     text: model.title
0113                     icon.source: model.icon
0114                 }
0115             }
0116         }
0117 
0118         PlasmaComponents3.Label {
0119             id: topInfo
0120 
0121             anchors {
0122                 top: comicTabbar.visible ? comicTabbar.bottom : parent.top
0123                 left: parent.left
0124                 right: parent.right
0125             }
0126 
0127             visible: (topInfo.text.length > 0)
0128             horizontalAlignment: Text.AlignHCenter
0129             text: (showComicAuthor || showComicTitle) ? getTopInfo() : ""
0130             textFormat: Text.PlainText
0131 
0132             function getTopInfo() {
0133                 var tempTop = "";
0134 
0135                 if ( showComicTitle ) {
0136                     tempTop = plasmoid.comicData.title;
0137                     tempTop += ( ( (plasmoid.comicData.stripTitle.length > 0) && (plasmoid.comicData.title.length > 0) ) ? " - " : "" ) + plasmoid.comicData.stripTitle;
0138                 }
0139 
0140                 if ( showComicAuthor &&
0141                     (plasmoid.comicData.author != undefined || plasmoid.comicData.author.length > 0) ) {
0142                     tempTop = ( tempTop.length > 0 ? plasmoid.comicData.author + ": " + tempTop : plasmoid.comicData.author );
0143                 }
0144 
0145                 return tempTop;
0146             }
0147         }
0148 
0149         ComicCentralView {
0150             id: centerLayout
0151 
0152             anchors {
0153                 left: parent.left
0154                 right: parent.right
0155                 bottom: (bottomInfo.visible) ? bottomInfo.top : parent.bottom
0156                 top: (topInfo.visible) ? topInfo.bottom : (comicTabbar.visible ? comicTabbar.bottom : parent.top)
0157                 topMargin: (comicTabbar.visible) ? 3 : 0
0158             }
0159 
0160             visible: plasmoid.tabIdentifiers.length > 0
0161             comicData: plasmoid.comicData
0162         }
0163 
0164         ComicBottomInfo {
0165             id:bottomInfo
0166 
0167             anchors {
0168                 left: parent.left
0169                 right: parent.right
0170                 bottom: parent.bottom
0171             }
0172 
0173             comicData: plasmoid.comicData
0174             showUrl: plasmoid.showComicUrl
0175             showIdentifier: plasmoid.showComicIdentifier
0176         }
0177     }
0178 
0179     states: [
0180         State {
0181             name: "topInfoVisible"
0182             when: topInfo.visible && !bottomInfo.visible
0183             AnchorChanges {
0184                 target: centerLayout
0185                 anchors.top: topInfo.bottom
0186             }
0187         },
0188         State {
0189             name: "bottomInfoVisible"
0190             when: bottomInfo.visible && !topInfo.visible
0191             AnchorChanges {
0192                 target: centerLayout
0193                 anchors.bottom: bottomInfo.top
0194             }
0195         },
0196         State {
0197             name: "topBottomInfoVisible"
0198             when: bottomInfo.visible && topInfo.visible
0199             AnchorChanges {
0200                 target: centerLayout
0201                 anchors.top: topInfo.bottom
0202                 anchors.bottom: bottomInfo.top
0203             }
0204         }
0205     ]
0206 
0207     transitions:
0208         Transition {
0209             AnchorAnimation {
0210                 duration: Kirigami.Units.veryLongDuration
0211                 easing.type: Easing.InOutQuad
0212             }
0213         }
0214 }