2020-11-27 17:32:48 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2021-04-21 07:39:05 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2021-09-28 15:04:06 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-14 11:35:37 +00:00
|
|
|
import "../"
|
2021-10-14 12:14:11 +00:00
|
|
|
import "./"
|
2020-11-27 17:32:48 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
Item {
|
2021-04-21 07:39:05 +00:00
|
|
|
id: root
|
2022-08-05 19:52:34 +00:00
|
|
|
objectName: "moduleWarningBanner"
|
2022-02-09 09:43:23 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
enum Type {
|
|
|
|
Danger,
|
|
|
|
Success
|
|
|
|
}
|
|
|
|
|
|
|
|
property bool active: false
|
|
|
|
property int type: ModuleWarning.Danger
|
2021-06-17 18:41:11 +00:00
|
|
|
property string text: ""
|
2022-09-02 14:56:14 +00:00
|
|
|
property alias buttonText: button.text
|
|
|
|
|
|
|
|
signal clicked()
|
|
|
|
signal closeClicked()
|
|
|
|
signal showStarted()
|
|
|
|
signal showFinihsed()
|
|
|
|
signal hideStarted()
|
|
|
|
signal hideFinished()
|
2022-02-09 09:43:23 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
function show() {
|
|
|
|
hideTimer.stop()
|
|
|
|
active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function showFor(duration = 5000) {
|
|
|
|
show();
|
|
|
|
hide(duration);
|
|
|
|
}
|
2021-04-21 07:39:05 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
function hide(timeout = 0) {
|
|
|
|
hideTimer.interval = timeout
|
|
|
|
hideTimer.start()
|
|
|
|
}
|
2022-03-03 21:00:52 +00:00
|
|
|
|
2022-03-17 16:15:38 +00:00
|
|
|
function close() {
|
2022-09-02 14:56:14 +00:00
|
|
|
closeButtonMouseArea.clicked(null)
|
2022-03-17 16:15:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
implicitHeight: root.active ? content.implicitHeight : 0
|
|
|
|
visible: implicitHeight > 0
|
2020-11-27 17:32:48 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
onActiveChanged: {
|
|
|
|
active ? showAnimation.start() : hideAnimation.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberAnimation {
|
|
|
|
id: showAnimation
|
|
|
|
target: root
|
|
|
|
property: "implicitHeight"
|
|
|
|
from: 0
|
|
|
|
to: content.implicitHeight
|
|
|
|
duration: 500
|
|
|
|
easing.type: Easing.OutCubic
|
|
|
|
onStarted: {
|
|
|
|
root.showStarted()
|
2020-11-27 17:32:48 +00:00
|
|
|
}
|
2022-09-02 14:56:14 +00:00
|
|
|
onFinished: {
|
|
|
|
root.showFinihsed()
|
|
|
|
}
|
|
|
|
}
|
2020-11-27 17:32:48 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
NumberAnimation {
|
|
|
|
id: hideAnimation
|
|
|
|
target: root
|
|
|
|
property: "implicitHeight"
|
|
|
|
to: 0
|
|
|
|
from: content.implicitHeight
|
|
|
|
duration: 500
|
|
|
|
easing.type: Easing.OutCubic
|
|
|
|
onStarted: {
|
|
|
|
root.hideStarted()
|
|
|
|
}
|
|
|
|
onFinished: {
|
|
|
|
root.hideFinished()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: hideTimer
|
|
|
|
repeat: false
|
|
|
|
running: false
|
|
|
|
onTriggered: {
|
|
|
|
root.active = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: content
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
width: parent.width
|
|
|
|
implicitHeight: 32
|
|
|
|
|
|
|
|
readonly property color baseColor: {
|
|
|
|
switch (root.type) {
|
|
|
|
case ModuleWarning.Danger: return Theme.palette.dangerColor1
|
|
|
|
case ModuleWarning.Success: return Theme.palette.successColor1
|
|
|
|
default: return Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
color: baseColor
|
|
|
|
|
|
|
|
Behavior on color {
|
|
|
|
ColorAnimation {
|
|
|
|
duration: 150
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
id: layout
|
|
|
|
|
|
|
|
spacing: 12
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
text: root.text
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Theme.palette.indirectColor1
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: button
|
|
|
|
visible: text != ""
|
|
|
|
padding: 5
|
|
|
|
onClicked: {
|
|
|
|
root.clicked()
|
|
|
|
}
|
|
|
|
contentItem: Text {
|
|
|
|
text: button.text
|
|
|
|
font.pixelSize: 12
|
2020-11-27 17:32:48 +00:00
|
|
|
font.weight: Font.Medium
|
|
|
|
font.family: Style.current.fontRegular.name
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2022-09-02 14:56:14 +00:00
|
|
|
color: Theme.palette.indirectColor1
|
|
|
|
}
|
|
|
|
background: Rectangle {
|
|
|
|
radius: 4
|
|
|
|
border.width: 1
|
|
|
|
border.color: Theme.palette.indirectColor3
|
|
|
|
color: Theme.palette.getColor("white", button.hovered ? 0.4 : 0.1)
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.NoButton
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
2020-11-27 17:32:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
StatusIcon {
|
|
|
|
id: closeImg
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 18
|
|
|
|
height: 20
|
|
|
|
width: 20
|
|
|
|
icon: "close-circle"
|
|
|
|
color: Theme.palette.indirectColor1
|
|
|
|
opacity: closeButtonMouseArea.containsMouse ? 1 : 0.7
|
2022-03-03 21:00:52 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
MouseArea {
|
|
|
|
id: closeButtonMouseArea
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
|
|
|
root.closeClicked()
|
|
|
|
}
|
2022-03-03 21:00:52 +00:00
|
|
|
}
|
2021-04-21 07:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-02 14:56:14 +00:00
|
|
|
|
2021-06-11 13:57:43 +00:00
|
|
|
}
|