shift-shell/applets/notifications/contents/ui/NotificationStripe.qml

207 lines
6 KiB
QML
Raw Normal View History

/*
* Copyright 2014 Aaron Seigo <aseigo@kde.org>
*
* 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.
*/
2015-05-15 16:53:41 +00:00
import QtQuick 2.4
2015-03-18 17:41:26 +00:00
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
MouseArea {
2015-03-19 11:11:17 +00:00
id: notificationItem
2015-05-15 16:53:41 +00:00
height: Math.max(messageLayout.height, icon.height) + background.margins.top + background.margins.bottom + (expanded ? actionsLayout.height : 0)
width: parent.width
anchors.bottomMargin: 10
drag.axis: Drag.XAxis
2015-03-19 11:11:17 +00:00
drag.target: notificationItem
property bool expanded: false
2015-03-19 11:11:17 +00:00
property string source: model.source
property var actions: model.actions
Behavior on x {
2015-05-15 16:26:06 +00:00
NumberAnimation {
easing.type: Easing.InOutQuad
duration: units.longDuration
}
}
onReleased: {
if (drag.active) {
if (x > width / 4 || x < width / -4) {
2015-04-27 09:51:37 +00:00
//if there is an action, execute the first when swiping left
if (x < 0 && actions) {
2015-05-15 16:26:06 +00:00
var action = actions.get(0);
if (action) {
root.executeAction(source, action.id)
}
2015-04-27 09:51:37 +00:00
}
notificationsModel.remove(index);
} else {
x = 0;
}
2015-04-27 09:51:37 +00:00
} else if (body || actions) {
expanded = !expanded;
}
}
2015-03-18 17:41:26 +00:00
PlasmaCore.FrameSvgItem {
id: background
imagePath: "widgets/background"
anchors {
2015-03-18 17:41:26 +00:00
fill: parent
2015-03-19 11:11:17 +00:00
rightMargin: -notificationItem.width
2015-03-18 17:41:26 +00:00
leftMargin: units.gridUnit
}
2015-03-18 17:41:26 +00:00
colorGroup: PlasmaCore.ColorScope.colorGroup
}
2015-03-18 17:41:26 +00:00
PlasmaComponents.ToolButton {
anchors {
2015-03-18 17:41:26 +00:00
left: parent.left
verticalCenter: parent.verticalCenter
leftMargin: units.gridUnit / 2
}
2015-03-18 17:41:26 +00:00
iconSource: "window-close"
flat: false
onClicked: {
notificationsModel.remove(index);
}
2015-03-18 17:41:26 +00:00
}
2015-03-18 17:41:26 +00:00
PlasmaComponents.Label {
2015-05-15 16:53:41 +00:00
id: appLabel
2015-06-19 01:53:17 +00:00
anchors.leftMargin: units.gridUnit * 3
2015-03-18 17:41:26 +00:00
color: PlasmaCore.ColorScope.textColor
text: model.appName
}
2015-05-15 16:53:41 +00:00
Column {
id: messageLayout
anchors {
2015-03-18 17:41:26 +00:00
verticalCenter: parent.verticalCenter
2015-06-19 01:53:17 +00:00
left: parent.left
right: icon.left
leftMargin: units.gridUnit * 3
}
2015-05-15 16:53:41 +00:00
PlasmaComponents.Label {
2015-06-19 01:53:17 +00:00
id: summaryLabel
anchors.right: parent.right
width: messageLayout.width - appLabel.width
2015-05-15 16:53:41 +00:00
horizontalAlignment: Qt.AlignRight
verticalAlignment: Qt.AlignVCenter
2015-06-12 18:23:36 +00:00
text: summary + (!notificationItem.expanded && body ? "..." : "")
2015-05-15 16:53:41 +00:00
wrapMode: Text.WordWrap
}
2015-06-19 01:53:17 +00:00
2015-05-15 16:53:41 +00:00
PlasmaComponents.Label {
2015-06-19 01:53:17 +00:00
id: bodyLabel
2015-05-15 16:53:41 +00:00
anchors {
right: parent.right
left: parent.left
}
2015-06-19 01:57:54 +00:00
visible: height > 0
height: notificationItem.expanded && body != undefined && body ? implicitHeight : 0
clip: true
2015-05-15 16:53:41 +00:00
horizontalAlignment: Qt.AlignRight
verticalAlignment: Qt.AlignVCenter
text: body
wrapMode: Text.WordWrap
2015-06-19 01:57:54 +00:00
Behavior on height {
NumberAnimation {
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
2015-05-15 16:53:41 +00:00
}
2015-03-18 17:41:26 +00:00
}
2015-06-19 01:53:17 +00:00
2015-03-18 17:41:26 +00:00
PlasmaCore.IconItem {
id: icon
anchors {
2015-03-19 11:11:17 +00:00
right: notificationItem.right
2015-03-18 17:41:26 +00:00
verticalCenter: parent.verticalCenter
}
2015-03-18 17:41:26 +00:00
width: units.iconSizes.medium
height: width
2015-05-15 16:53:41 +00:00
source: appIcon && appIcon.length > 0 ? appIcon : "preferences-desktop-notification"
}
2015-03-19 11:11:17 +00:00
RowLayout {
id: actionsLayout
anchors {
2015-05-15 16:53:41 +00:00
right: messageLayout.right
top: messageLayout.bottom
2015-03-19 11:11:17 +00:00
topMargin: units.smallSpacing
}
opacity: notificationItem.expanded && notificationItem.actions && notificationItem.actions.count > 0 ? 1 : 0
Behavior on opacity {
NumberAnimation {
duration: units.shortDuration
easing.type: Easing.InOutQuad
}
}
Repeater {
model: notificationItem.actions
delegate: PlasmaComponents.Button {
text: model.text
2015-04-27 09:51:37 +00:00
onClicked: {
root.executeAction(notificationItem.source, model.id)
notificationsModel.remove(index);
}
2015-03-19 11:11:17 +00:00
}
}
}
2015-06-19 01:53:17 +00:00
states: [
State {
name: "large"
when: appLabel.width + bodyLabel.paintedWidth < messageLayout.width
AnchorChanges {
target: appLabel
anchors {
verticalCenter: parent.verticalCenter
top: undefined
left: parent.left
}
}
PropertyChanges {
}
},
State {
name: "compact"
when: notificationItem.state != "large"
AnchorChanges {
target: appLabel
anchors {
verticalCenter: undefined
top: messageLayout.top
left: parent.left
}
}
}
]
2015-03-18 17:41:26 +00:00
}