Kstars

PassiveNotification.qml
1 /*
2  SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 import QtQuick 2.5
8 import QtQuick.Controls 2.0 as Controls
9 import QtQuick.Layouts 1.2
10 import QtGraphicalEffects 1.0
11 import "../../constants" 1.0
12 import "../../modules"
13 
14 MouseArea {
15  id: root
16  z: 9999
17  width: background.width
18  height: background.height
19  opacity: 0
20  enabled: appearAnimation.appear
21 
22  anchors {
23  horizontalCenter: parent.horizontalCenter
24  bottom: parent.bottom
25  bottomMargin: units.gridUnit * 4
26  }
27 
28  function showNotification(message, timeout, actionText, callBack) {
29  if (!message) {
30  return;
31  }
32  appearAnimation.running = false;
33  appearAnimation.appear = true;
34  appearAnimation.running = true;
35  if (timeout == "short") {
36  timer.interval = 1000;
37  } else if (timeout == "long") {
38  timer.interval = 4500;
39  } else if (timeout > 0) {
40  timer.interval = timeout;
41  } else {
42  timer.interval = 3000;
43  }
44  messageLabel.text = message ? message : "";
45  actionButton.text = actionText ? actionText : "";
46  actionButton.callBack = callBack ? callBack : "";
47 
48  timer.restart();
49  }
50 
51  function hideNotification() {
52  appearAnimation.running = false;
53  appearAnimation.appear = false;
54  appearAnimation.running = true;
55  }
56 
57 
58  onClicked: {
59  appearAnimation.appear = false;
60  appearAnimation.running = true;
61  }
62 
63  transform: Translate {
64  id: transform
65  y: root.height
66  }
67 
68  Timer {
69  id: timer
70  interval: 4000
71  onTriggered: {
72  appearAnimation.appear = false;
73  appearAnimation.running = true;
74  }
75  }
76  ParallelAnimation {
77  id: appearAnimation
78  property bool appear: true
79  NumberAnimation {
80  target: root
81  properties: "opacity"
82  to: appearAnimation.appear ? 1 : 0
83  duration: units.longDuration
84  easing.type: Easing.InOutQuad
85  }
86  NumberAnimation {
87  target: transform
88  properties: "y"
89  to: appearAnimation.appear ? 0 : background.height
90  duration: units.longDuration
91  easing.type: appearAnimation.appear ? Easing.OutQuad : Easing.InQuad
92  }
93  }
94 
95  Item {
96  id: background
97  width: backgroundRect.width + units.gridUnit
98  height: backgroundRect.height + units.gridUnit
99 
100  Rectangle {
101  id: backgroundRect
102  anchors.centerIn: parent
103  radius: units.smallSpacing
104  color: Num.sysPalette.base
105  border.color: Num.sysPalette.light
106  border.width: 1
107  opacity: 0.6
108  width: mainLayout.width + Math.round((height - mainLayout.height))
109  height: Math.max(mainLayout.height + units.smallSpacing*2, units.gridUnit*2)
110  }
111 
112  RowLayout {
113  id: mainLayout
114  anchors.centerIn: parent
115  KSLabel {
116  id: messageLabel
117  width: Math.min(root.parent.width - units.largeSpacing*2, implicitWidth)
118  }
119  Controls.Button {
120  id: actionButton
121  property var callBack
122  visible: text != ""
123  onClicked: {
124  appearAnimation.appear = false;
125  appearAnimation.running = true;
126  if (callBack) {
127  callBack();
128  }
129  }
130  }
131  }
132 
133  layer.enabled: true
134  layer.effect: DropShadow {
135  horizontalOffset: 0
136  verticalOffset: 0
137  radius: units.gridUnit
138  samples: 32
139  color: Num.sysPalette.shadow//Qt.rgba(0, 0, 0, 0.5)
140  }
141  }
142 }
143 
KDOCTOOLS_EXPORT QString transform(const QString &file, const QString &stylesheet, const QVector< const char * > &params=QVector< const char * >())
KGuiItem properties()
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.