2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
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
|
2023-06-27 19:56:44 +00:00
|
|
|
import StatusQ.Components 0.1
|
2022-09-02 14:56:14 +00:00
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2022-09-15 07:31:38 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
Item {
|
2021-04-21 07:39:05 +00:00
|
|
|
id: root
|
2022-02-09 09:43:23 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
enum Type {
|
|
|
|
Danger,
|
2023-01-18 16:37:36 +00:00
|
|
|
Warning,
|
2022-09-02 14:56:14 +00:00
|
|
|
Success
|
|
|
|
}
|
|
|
|
|
2023-11-02 14:50:58 +00:00
|
|
|
property bool active: false
|
2022-09-02 14:56:14 +00:00
|
|
|
property int type: ModuleWarning.Danger
|
2022-09-15 07:31:38 +00:00
|
|
|
property int progressValue: -1 // 0..100, -1 not visible
|
2021-06-17 18:41:11 +00:00
|
|
|
property string text: ""
|
2022-09-02 14:56:14 +00:00
|
|
|
property alias buttonText: button.text
|
2022-09-15 07:31:38 +00:00
|
|
|
property alias closeBtnVisible: closeImg.visible
|
2023-06-27 19:56:44 +00:00
|
|
|
property string iconName
|
2023-11-02 14:50:58 +00:00
|
|
|
property bool delay: true
|
2022-09-02 14:56:14 +00:00
|
|
|
|
|
|
|
signal clicked()
|
|
|
|
signal closeClicked()
|
|
|
|
signal showStarted()
|
2022-09-27 21:26:26 +00:00
|
|
|
signal showFinished()
|
2022-09-02 14:56:14 +00:00
|
|
|
signal hideStarted()
|
|
|
|
signal hideFinished()
|
2022-02-09 09:43:23 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
function show() {
|
|
|
|
hideTimer.stop()
|
2023-01-30 10:42:26 +00:00
|
|
|
active = true;
|
2022-09-02 14:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2023-07-24 11:31:31 +00:00
|
|
|
root.closeClicked()
|
2022-03-17 16:15:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-15 07:31:38 +00:00
|
|
|
signal linkActivated(string link)
|
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
onActiveChanged: {
|
2023-11-02 14:50:58 +00:00
|
|
|
if (root.active && root.delay) {
|
|
|
|
showTimer.start();
|
|
|
|
}
|
2022-09-02 14:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NumberAnimation {
|
|
|
|
id: showAnimation
|
|
|
|
target: root
|
2023-11-02 14:50:58 +00:00
|
|
|
running: (root.active && !root.delay)
|
2022-09-02 14:56:14 +00:00
|
|
|
property: "implicitHeight"
|
|
|
|
from: 0
|
2023-11-02 14:50:58 +00:00
|
|
|
to: 32
|
2022-09-02 14:56:14 +00:00
|
|
|
duration: 500
|
|
|
|
easing.type: Easing.OutCubic
|
|
|
|
onStarted: {
|
2023-11-02 14:50:58 +00:00
|
|
|
root.visible = true;
|
2022-09-02 14:56:14 +00:00
|
|
|
root.showStarted()
|
2020-11-27 17:32:48 +00:00
|
|
|
}
|
2022-09-02 14:56:14 +00:00
|
|
|
onFinished: {
|
2022-09-27 21:26:26 +00:00
|
|
|
root.showFinished()
|
2022-09-02 14:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-27 17:32:48 +00:00
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
NumberAnimation {
|
|
|
|
id: hideAnimation
|
2023-11-02 14:50:58 +00:00
|
|
|
running: !root.active
|
2022-09-02 14:56:14 +00:00
|
|
|
target: root
|
|
|
|
property: "implicitHeight"
|
2023-11-02 14:50:58 +00:00
|
|
|
from: 32
|
2022-09-02 14:56:14 +00:00
|
|
|
to: 0
|
|
|
|
duration: 500
|
|
|
|
easing.type: Easing.OutCubic
|
|
|
|
onStarted: {
|
|
|
|
root.hideStarted()
|
2023-11-02 14:50:58 +00:00
|
|
|
root.visible = false;
|
2022-09-02 14:56:14 +00:00
|
|
|
}
|
|
|
|
onFinished: {
|
|
|
|
root.hideFinished()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 14:50:58 +00:00
|
|
|
Timer {
|
|
|
|
id: showTimer
|
|
|
|
interval: 3000
|
|
|
|
onTriggered: {
|
|
|
|
if (root.active) {
|
|
|
|
showAnimation.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
Timer {
|
|
|
|
id: hideTimer
|
|
|
|
repeat: false
|
|
|
|
running: false
|
|
|
|
onTriggered: {
|
2023-01-30 10:42:26 +00:00
|
|
|
root.active = false
|
2022-09-02 14:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: content
|
2023-11-02 14:50:58 +00:00
|
|
|
anchors.fill: parent
|
2022-09-02 14:56:14 +00:00
|
|
|
|
|
|
|
readonly property color baseColor: {
|
|
|
|
switch (root.type) {
|
|
|
|
case ModuleWarning.Danger: return Theme.palette.dangerColor1
|
|
|
|
case ModuleWarning.Success: return Theme.palette.successColor1
|
2023-01-18 16:37:36 +00:00
|
|
|
case ModuleWarning.Warning: return Theme.palette.warningColor1
|
2022-09-02 14:56:14 +00:00
|
|
|
default: return Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
color: baseColor
|
|
|
|
|
|
|
|
Behavior on color {
|
|
|
|
ColorAnimation {
|
|
|
|
duration: 150
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
id: layout
|
|
|
|
|
|
|
|
spacing: 12
|
2022-09-15 07:31:38 +00:00
|
|
|
anchors.centerIn: parent
|
2022-09-02 14:56:14 +00:00
|
|
|
|
2023-06-27 19:56:44 +00:00
|
|
|
StatusRoundIcon {
|
|
|
|
Layout.preferredHeight: 16
|
|
|
|
Layout.preferredWidth: 16
|
|
|
|
Layout.rightMargin: -8
|
|
|
|
visible: !!root.iconName
|
|
|
|
asset.name: root.iconName
|
|
|
|
asset.bgColor: Theme.palette.indirectColor1
|
|
|
|
asset.color: content.baseColor
|
|
|
|
}
|
|
|
|
|
2022-09-02 14:56:14 +00:00
|
|
|
StatusBaseText {
|
|
|
|
text: root.text
|
|
|
|
font.pixelSize: 13
|
2022-09-15 07:31:38 +00:00
|
|
|
font.weight: Font.Medium
|
2022-09-02 14:56:14 +00:00
|
|
|
color: Theme.palette.indirectColor1
|
2022-09-15 07:31:38 +00:00
|
|
|
linkColor: color
|
|
|
|
onLinkActivated: root.linkActivated(link)
|
|
|
|
HoverHandler {
|
|
|
|
id: handler1
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.NoButton
|
|
|
|
cursorShape: handler1.hovered && parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
|
|
|
}
|
2022-09-02 14:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: button
|
|
|
|
visible: text != ""
|
2023-04-05 13:25:21 +00:00
|
|
|
focusPolicy: Qt.NoFocus
|
2022-09-02 14:56:14 +00:00
|
|
|
padding: 5
|
|
|
|
onClicked: {
|
|
|
|
root.clicked()
|
|
|
|
}
|
2022-09-15 07:31:38 +00:00
|
|
|
contentItem: StatusBaseText {
|
2022-09-02 14:56:14 +00:00
|
|
|
text: button.text
|
2022-09-15 07:31:38 +00:00
|
|
|
font.pixelSize: 13
|
2020-11-27 17:32:48 +00:00
|
|
|
font.weight: Font.Medium
|
2024-10-15 19:26:12 +00:00
|
|
|
font.family: Theme.baseFont.name
|
2020-11-27 17:32:48 +00:00
|
|
|
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-15 07:31:38 +00:00
|
|
|
StatusBaseText {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: progressBar.left
|
2024-10-15 19:26:12 +00:00
|
|
|
anchors.rightMargin: Theme.halfPadding
|
2022-09-15 07:31:38 +00:00
|
|
|
text: qsTr("%1%").arg(progressBar.value)
|
|
|
|
visible: progressBar.visible
|
|
|
|
font.pixelSize: 12
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
color: Theme.palette.white
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressBar {
|
|
|
|
id: progressBar
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: closeImg.left
|
2024-10-15 19:26:12 +00:00
|
|
|
anchors.rightMargin: Theme.bigPadding
|
2022-09-15 07:31:38 +00:00
|
|
|
from: 0
|
|
|
|
to: 100
|
|
|
|
visible: root.progressValue > -1
|
|
|
|
value: root.progressValue
|
|
|
|
background: Rectangle {
|
|
|
|
implicitWidth: 64
|
|
|
|
implicitHeight: 8
|
|
|
|
radius: 8
|
|
|
|
color: "transparent"
|
|
|
|
border.width: 1
|
|
|
|
border.color: Theme.palette.white
|
|
|
|
}
|
|
|
|
contentItem: Rectangle {
|
|
|
|
width: progressBar.width*progressBar.position
|
|
|
|
implicitHeight: 8
|
|
|
|
radius: 8
|
|
|
|
color: Theme.palette.white
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2021-06-11 13:57:43 +00:00
|
|
|
}
|