AbstractItem.qml 4.84 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1 2
/*
 *   Copyright 2016 Marco Martin <mart@kde.org>
3
 *   Copyright 2020 Konrad Materka <materka@gmail.com>
Marco Martin's avatar
Marco Martin committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

21
import QtQuick 2.2
Marco Martin's avatar
Marco Martin committed
22 23 24 25 26 27
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents

PlasmaCore.ToolTipArea {
    id: abstractItem

28 29
    height: inVisibleLayout ? visibleLayout.cellHeight : hiddenLayout.iconItemHeight
    width: inVisibleLayout ? visibleLayout.cellWidth : hiddenLayout.width
Marco Martin's avatar
Marco Martin committed
30

31 32
    property var model: itemModel

33
    property string itemId
Marco Martin's avatar
Marco Martin committed
34
    property alias text: label.text
35
    property alias iconContainer: iconContainer
36 37
    property int /*PlasmaCore.Types.ItemStatus*/ status: model.status || PlasmaCore.Types.UnknownStatus
    property int /*PlasmaCore.Types.ItemStatus*/ effectiveStatus: model.effectiveStatus || PlasmaCore.Types.UnknownStatus
38 39
    readonly property bool inHiddenLayout: effectiveStatus === PlasmaCore.Types.PassiveStatus
    readonly property bool inVisibleLayout: effectiveStatus === PlasmaCore.Types.ActiveStatus
40

Marco Martin's avatar
Marco Martin committed
41
    signal clicked(var mouse)
42
    signal pressed(var mouse)
Marco Martin's avatar
Marco Martin committed
43
    signal wheel(var wheel)
44
    signal contextMenu(var mouse)
Marco Martin's avatar
Marco Martin committed
45

46
    /* subclasses need to assign to this tooltip properties
Marco Martin's avatar
Marco Martin committed
47 48
    mainText:
    subText:
49
    icon:
Marco Martin's avatar
Marco Martin committed
50 51
    */

52
    location: {
53
        if (inHiddenLayout) {
54 55 56
            if (LayoutMirroring.enabled && plasmoid.location !== PlasmaCore.Types.RightEdge) {
                return PlasmaCore.Types.LeftEdge;
            } else if (plasmoid.location !== PlasmaCore.Types.LeftEdge) {
Marco Martin's avatar
Marco Martin committed
57
                return PlasmaCore.Types.RightEdge;
58 59 60 61 62
            }
        }

        return plasmoid.location;
    }
Marco Martin's avatar
Marco Martin committed
63

64 65
//BEGIN CONNECTIONS

Marco Martin's avatar
Marco Martin committed
66
    onContainsMouseChanged: {
67
        if (inHiddenLayout && containsMouse) {
68
            root.hiddenLayout.currentIndex = index
Marco Martin's avatar
Marco Martin committed
69 70
        }
    }
71 72 73

//END CONNECTIONS

74
    PulseAnimation {
75
        targetItem: iconContainer
76 77 78 79 80
        running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus ||
            abstractItem.status === PlasmaCore.Types.RequiresAttentionStatus ) &&
            units.longDuration > 0
    }

81 82 83 84 85 86 87 88 89
    function activated() {
        activatedAnimation.start()
    }

    SequentialAnimation {
        id: activatedAnimation
        loops: 1

        ScaleAnimator {
90
            target: iconContainer
91 92 93 94 95 96 97
            from: 1
            to: 0.5
            duration: units.shortDuration
            easing.type: Easing.InQuad
        }

        ScaleAnimator {
98
            target: iconContainer
99 100 101 102 103 104 105
            from: 0.5
            to: 1
            duration: units.shortDuration
            easing.type: Easing.OutQuad
        }
    }

Marco Martin's avatar
Marco Martin committed
106
    MouseArea {
107
        anchors.fill: abstractItem
Marco Martin's avatar
Marco Martin committed
108
        hoverEnabled: true
Marco Martin's avatar
Marco Martin committed
109
        drag.filterChildren: true
110
        acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
111
        onClicked: abstractItem.clicked(mouse)
112
        onPressed: {
113
            abstractItem.hideToolTip()
114
            abstractItem.pressed(mouse)
115
        }
116 117 118
        onPressAndHold: {
            abstractItem.contextMenu(mouse)
        }
119 120 121 122 123 124
        onWheel: {
            abstractItem.wheel(wheel);
            //Don't accept the event in order to make the scrolling by mouse wheel working
            //for the parent scrollview this icon is in.
            wheel.accepted = false;
        }
Marco Martin's avatar
Marco Martin committed
125
    }
126

127 128 129 130 131 132 133 134 135 136
    Row {
        spacing: units.smallSpacing
        anchors.horizontalCenter: inVisibleLayout ? parent.horizontalCenter : undefined
        Item {
            id: iconContainer
            anchors.verticalCenter: parent.verticalCenter
            width: Math.min(abstractItem.width, abstractItem.height)
            height: width
            property alias inHiddenLayout: abstractItem.inHiddenLayout
            property alias inVisibleLayout: abstractItem.inVisibleLayout
137
        }
138 139 140 141 142 143 144 145 146 147
        PlasmaComponents.Label {
            id: label
            anchors.verticalCenter: parent.verticalCenter
            visible: abstractItem.inHiddenLayout && !root.activeApplet
            opacity: visible ? 1 : 0
            Behavior on opacity {
                NumberAnimation {
                    duration: units.longDuration
                    easing.type: Easing.InOutQuad
                }
148 149 150
            }
        }
    }
Marco Martin's avatar
Marco Martin committed
151
}
Marco Martin's avatar
Marco Martin committed
152