Warning, /plasma/plasma-desktop/desktoppackage/contents/activitymanager/ActivityItem.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2014-2020 Ivan Cukic <ivan.cukic(at)kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.0
0008 
0009 import org.kde.plasma.components 3.0 as PlasmaComponents
0010 import org.kde.plasma.activityswitcher as ActivitySwitcher
0011 import org.kde.kirigami 2.20 as Kirigami
0012 
0013 import org.kde.kcmutils  // KCMLauncher
0014 
0015 import "static.js" as S
0016 
0017 Item {
0018     id: root
0019 
0020     property int innerPadding  : Kirigami.Units.gridUnit
0021 
0022     property bool current      : false
0023     property bool selected     : false
0024     property bool stoppable    : true
0025 
0026     property alias title       : title.text
0027     property alias icon        : icon.source
0028     property alias hasWindows  : hasWindowsIndicator.visible
0029 
0030     z : current  ? 10 :
0031         selected ?  5 : 0
0032 
0033     property string activityId : ""
0034 
0035     property string background : ""
0036 
0037     onBackgroundChanged: if (background[0] !== '#') {
0038         // We have a proper wallpaper, hurroo!
0039         backgroundColor.visible = false;
0040 
0041     } else {
0042         // We have only a color
0043         backgroundColor.color = background;
0044         backgroundColor.visible = true;
0045     }
0046 
0047     signal clicked
0048 
0049     width  : 200
0050     height : width * 9.0 / 16.0
0051 
0052     Item {
0053         anchors {
0054             fill: parent
0055         }
0056 
0057         // Background until we get something real
0058         Rectangle {
0059             id: backgroundColor
0060 
0061             anchors.fill: parent
0062             // This is intentional - while waiting for the wallpaper,
0063             // we are showing a semi-transparent black background
0064             color: "black"
0065 
0066             opacity: root.selected ? .8 : .5
0067         }
0068 
0069         Image {
0070             id: backgroundWallpaper
0071 
0072             anchors.fill: parent
0073 
0074             visible: !backgroundColor.visible
0075             source: "image://wallpaperthumbnail/" + background
0076             sourceSize: Qt.size(width, height)
0077         }
0078 
0079         // Title and the icon
0080 
0081         Rectangle {
0082             id: shade
0083 
0084             width: parent.height
0085             height: parent.width
0086 
0087             anchors.centerIn: parent
0088             rotation: 90
0089 
0090             gradient: Gradient {
0091                 GradientStop { position: 1.0; color: "black" }
0092                 GradientStop { position: 0.0; color: "transparent" }
0093             }
0094 
0095             opacity : root.selected ? 0.5 : 1.0
0096         }
0097 
0098         Rectangle {
0099             id: currentActivityHighlight
0100 
0101             visible:  root.current
0102 
0103             border.width: root.current ? Kirigami.Units.smallSpacing : 0
0104             border.color: Kirigami.Theme.highlightColor
0105 
0106             z: 10
0107 
0108             anchors {
0109                 fill: parent
0110                 // Hide the rounding error on the bottom of the rectangle
0111                 bottomMargin: -1
0112             }
0113 
0114             color: "transparent"
0115         }
0116 
0117         Item {
0118             id: titleBar
0119 
0120             anchors {
0121                 top   : parent.top
0122                 left  : parent.left
0123                 right : parent.right
0124 
0125                 leftMargin : 2 * Kirigami.Units.smallSpacing + 2
0126                 topMargin  : 2 * Kirigami.Units.smallSpacing
0127             }
0128 
0129             Text {
0130                 id: title
0131 
0132                 color   : "white"
0133                 elide   : Text.ElideRight
0134                 visible : shade.visible
0135 
0136                 font.bold : true
0137 
0138                 anchors {
0139                     top   : parent.top
0140                     left  : parent.left
0141                     right : icon.left
0142                 }
0143             }
0144 
0145             Text {
0146                 id: description
0147 
0148                 color   : "white"
0149                 elide   : Text.ElideRight
0150                 text    : model.description
0151                 opacity : .6
0152 
0153                 anchors {
0154                     top   : title.bottom
0155                     left  : parent.left
0156                     right : icon.left
0157                 }
0158             }
0159 
0160             Kirigami.Icon {
0161                 id: icon
0162 
0163                 width   : Kirigami.Units.iconSizes.medium
0164                 height  : width
0165 
0166                 anchors {
0167                     right       : parent.right
0168                     rightMargin : 2 * Kirigami.Units.smallSpacing
0169                 }
0170             }
0171         }
0172 
0173         Column {
0174             id: statsBar
0175 
0176             height: childrenRect.height + Kirigami.Units.smallSpacing
0177 
0178             anchors {
0179                 bottom : controlBar.top
0180                 left   : parent.left
0181                 right  : parent.right
0182 
0183                 leftMargin   : 2 * Kirigami.Units.smallSpacing + 2
0184                 rightMargin  : 2 * Kirigami.Units.smallSpacing
0185                 bottomMargin : Kirigami.Units.smallSpacing
0186             }
0187 
0188             Kirigami.Icon {
0189                 id      : hasWindowsIndicator
0190                 source  : "window-duplicate"
0191                 width   : 16
0192                 height  : width
0193                 opacity : .6
0194                 visible : false
0195             }
0196 
0197             Text {
0198                 id: lastUsedDate
0199 
0200                 color   : "white"
0201                 elide   : Text.ElideRight
0202                 opacity : .6
0203 
0204                 text: root.current ?
0205                         i18nd("plasma_shell_org.kde.plasma.desktop", "Currently being used") :
0206                         model.lastTimeUsedString
0207             }
0208         }
0209 
0210         Rectangle {
0211             id: dropHighlight
0212             visible: moveDropAction.isHovered || copyDropAction.isHovered
0213 
0214             onVisibleChanged: {
0215                 ActivitySwitcher.Backend.setDropMode(visible);
0216                 if (visible) {
0217                     root.state = "dropAreasShown";
0218                 } else {
0219                     root.state = "plain";
0220                 }
0221             }
0222 
0223             anchors {
0224                 fill: parent
0225                 topMargin: icon.height + 3 * Kirigami.Units.smallSpacing
0226             }
0227 
0228             opacity: .75
0229             color: Kirigami.Theme.backgroundColor
0230         }
0231 
0232         TaskDropArea {
0233             id: moveDropAction
0234 
0235             anchors {
0236                 right: parent.horizontalCenter
0237                 left: parent.left
0238                 top: parent.top
0239                 bottom: parent.bottom
0240             }
0241 
0242             topPadding: icon.height + 3 * Kirigami.Units.smallSpacing
0243             actionVisible: dropHighlight.visible
0244 
0245             actionTitle: i18nd("plasma_shell_org.kde.plasma.desktop", "Move to\nthis activity")
0246 
0247             onTaskDropped: {
0248                 ActivitySwitcher.Backend.dropMove(mimeData, root.activityId);
0249             }
0250 
0251             onClicked: {
0252                 root.clicked();
0253             }
0254 
0255             onEntered: {
0256                 S.showActivityItemActionsBar(root);
0257             }
0258 
0259             visible: ActivitySwitcher.Backend.dropEnabled
0260         }
0261 
0262         TaskDropArea {
0263             id: copyDropAction
0264 
0265             topPadding: icon.height + 3 * Kirigami.Units.smallSpacing
0266             actionVisible: dropHighlight.visible
0267 
0268             anchors {
0269                 right: parent.right
0270                 left: parent.horizontalCenter
0271                 top: parent.top
0272                 bottom: parent.bottom
0273             }
0274 
0275             actionTitle: i18nd("plasma_shell_org.kde.plasma.desktop", "Show also\nin this activity")
0276 
0277             onTaskDropped: {
0278                 ActivitySwitcher.Backend.dropCopy(mimeData, root.activityId);
0279             }
0280 
0281             onClicked: {
0282                 root.clicked();
0283             }
0284 
0285             onEntered: {
0286                 S.showActivityItemActionsBar(root);
0287             }
0288 
0289             visible: ActivitySwitcher.Backend.dropEnabled
0290 
0291         }
0292 
0293         // Controls
0294         Item {
0295             id: controlBar
0296 
0297             height: root.state == "showingControls" ?
0298                         (configButton.height + 4 * Kirigami.Units.smallSpacing) :
0299                         0
0300 
0301             Behavior on height {
0302                 NumberAnimation {
0303                     duration: Kirigami.Units.longDuration
0304                 }
0305             }
0306 
0307             Behavior on opacity {
0308                 NumberAnimation {
0309                     duration: Kirigami.Units.shortDuration
0310                 }
0311             }
0312 
0313             clip: true
0314 
0315             anchors {
0316                 bottom : parent.bottom
0317                 left   : parent.left
0318                 right  : parent.right
0319             }
0320 
0321             Rectangle {
0322                 anchors {
0323                     fill: parent
0324                     margins: - 2 * Kirigami.Units.smallSpacing
0325                 }
0326 
0327                 opacity: .75
0328                 color: Kirigami.Theme.backgroundColor
0329             }
0330 
0331             PlasmaComponents.Button {
0332                 id: configButton
0333 
0334                 icon.name: "configure"
0335                 PlasmaComponents.ToolTip.delay: Kirigami.Units.toolTipDelay
0336                 PlasmaComponents.ToolTip.visible: hovered
0337                 PlasmaComponents.ToolTip.text: i18nd("plasma_shell_org.kde.plasma.desktop", "Configure")
0338 
0339                 onClicked: KCMLauncher.openSystemSettings("kcm_activities", root.activityId);
0340 
0341                 anchors {
0342                     left       : parent.left
0343                     top        : parent.top
0344                     leftMargin : 2 * Kirigami.Units.smallSpacing + 2
0345                     topMargin  : 2 * Kirigami.Units.smallSpacing
0346                 }
0347             }
0348 
0349             PlasmaComponents.Button {
0350                 id: stopButton
0351 
0352                 visible: stoppable
0353                 icon.name: "process-stop"
0354                 PlasmaComponents.ToolTip.delay: Kirigami.Units.toolTipDelay
0355                 PlasmaComponents.ToolTip.visible: hovered
0356                 PlasmaComponents.ToolTip.text: i18nd("plasma_shell_org.kde.plasma.desktop", "Stop activity")
0357 
0358                 onClicked: ActivitySwitcher.Backend.stopActivity(activityId);
0359 
0360                 anchors {
0361                     right       : parent.right
0362                     top         : parent.top
0363                     rightMargin : 2 * Kirigami.Units.smallSpacing + 2
0364                     topMargin   : 2 * Kirigami.Units.smallSpacing
0365                 }
0366             }
0367         }
0368     }
0369 
0370     states: [
0371         State {
0372             name: "plain"
0373             PropertyChanges { target: shade; visible: true }
0374             PropertyChanges { target: controlBar; opacity: 0 }
0375         },
0376         State {
0377             name: "showingControls"
0378             PropertyChanges { target: shade; visible: true }
0379             PropertyChanges { target: controlBar; opacity: 1 }
0380         },
0381         State {
0382             name: "dropAreasShown"
0383             // PropertyChanges { target: shade; visible: false }
0384             PropertyChanges { target: statsBar; visible: false }
0385             PropertyChanges { target: controlBar; opacity: 0 }
0386         }
0387     ]
0388 
0389     transitions: [
0390         Transition {
0391             NumberAnimation {
0392                 properties : "opacity"
0393                 duration   : Kirigami.Units.shortDuration
0394             }
0395         }
0396     ]
0397 }