|
| 1 | +import QtQuick 2.15 |
| 2 | +import DelegateUI.Theme 1.0 |
| 3 | + |
| 4 | +import "qrc:/../common" |
| 5 | + |
| 6 | +Rectangle { |
| 7 | + id: control |
| 8 | + |
| 9 | + enum State { |
| 10 | + State_Default = 0, |
| 11 | + State_Success = 1, |
| 12 | + State_Processing = 2, |
| 13 | + State_Error = 3, |
| 14 | + State_Warning = 4 |
| 15 | + } |
| 16 | + |
| 17 | + signal close(); |
| 18 | + |
| 19 | + property bool animationEnabled: true |
| 20 | + property int tagState: DelTag.State_Default |
| 21 | + property string text: "" |
| 22 | + property font font |
| 23 | + property bool rotating: false |
| 24 | + property int iconSource: 0 |
| 25 | + property int iconSize: 14 |
| 26 | + property int closeIconSource: 0 |
| 27 | + property int closeIconSize: 14 |
| 28 | + property alias spacing: __row.spacing |
| 29 | + property string presetColor: "" |
| 30 | + property color colorText: presetColor == "" ? "#000" : __private.isCustom ? "#fff" : __private.colorArray[5] |
| 31 | + property color colorBg: presetColor == "" ? Qt.rgba(0,0,0,0.04) : __private.isCustom ? presetColor : __private.colorArray[0] |
| 32 | + property color colorBorder: presetColor == "" ? Qt.rgba(0,0,0,0.2) : __private.isCustom ? "transparent" : __private.colorArray[2] |
| 33 | + property color colorIcon: colorText |
| 34 | + |
| 35 | + onTagStateChanged: { |
| 36 | + switch (tagState) { |
| 37 | + case DelTag.State_Success: presetColor = "#52c41a"; break; |
| 38 | + case DelTag.State_Processing: presetColor = "#1677ff"; break; |
| 39 | + case DelTag.State_Error: presetColor = "#ff4d4f"; break; |
| 40 | + case DelTag.State_Warning: presetColor = "#faad14"; break; |
| 41 | + case DelTag.State_Default: |
| 42 | + default: presetColor = ""; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + onPresetColorChanged: { |
| 47 | + let preset = -1; |
| 48 | + switch (presetColor) { |
| 49 | + case "red": preset = DelColorGenerator.Preset_Red; break; |
| 50 | + case "volcano": preset = DelColorGenerator.Preset_Volcano; break; |
| 51 | + case "orange": preset = DelColorGenerator.Preset_Orange; break; |
| 52 | + case "gold": preset = DelColorGenerator.Preset_Gold; break; |
| 53 | + case "yellow": preset = DelColorGenerator.Preset_Yellow; break; |
| 54 | + case "lime": preset = DelColorGenerator.Preset_Lime; break; |
| 55 | + case "green": preset = DelColorGenerator.Preset_Green; break; |
| 56 | + case "cyan": preset = DelColorGenerator.Preset_Cyan; break; |
| 57 | + case "blue": preset = DelColorGenerator.Preset_Blue; break; |
| 58 | + case "geekblue": preset = DelColorGenerator.Preset_Geekblue; break; |
| 59 | + case "purple": preset = DelColorGenerator.Preset_Purple; break; |
| 60 | + case "magenta": preset = DelColorGenerator.Preset_Magenta; break; |
| 61 | + } |
| 62 | + |
| 63 | + if (tagState == DelTag.State_Default) { |
| 64 | + __private.isCustom = preset == -1 ? true : false; |
| 65 | + __private.presetColor = preset == -1 ? "#000" : delColorGenerator.presetToColor(preset); |
| 66 | + } else { |
| 67 | + __private.isCustom = false; |
| 68 | + __private.presetColor = presetColor; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + implicitWidth: __row.implicitWidth + 16 |
| 73 | + implicitHeight: Math.max(__icon.implicitHeight, __text.implicitHeight, __closeIcon.implicitHeight) + 8 |
| 74 | + font.family: "微软雅黑" |
| 75 | + font.pixelSize: 12 |
| 76 | + color: colorBg |
| 77 | + border.color: colorBorder |
| 78 | + radius: 4 |
| 79 | + |
| 80 | + Behavior on color { enabled: control.animationEnabled; ColorAnimation { duration: 100 } } |
| 81 | + |
| 82 | + DelColorGenerator { |
| 83 | + id: delColorGenerator |
| 84 | + } |
| 85 | + |
| 86 | + QtObject { |
| 87 | + id: __private |
| 88 | + property bool isCustom: false |
| 89 | + property color presetColor: "#000" |
| 90 | + property var colorArray: delColorGenerator.generate(presetColor, true, "#fff") |
| 91 | + } |
| 92 | + |
| 93 | + Row { |
| 94 | + id: __row |
| 95 | + anchors.centerIn: parent |
| 96 | + spacing: 5 |
| 97 | + |
| 98 | + DelIconText { |
| 99 | + id: __icon |
| 100 | + anchors.verticalCenter: parent.verticalCenter |
| 101 | + color: control.colorIcon |
| 102 | + iconSize: control.iconSize |
| 103 | + iconSource: control.iconSource |
| 104 | + verticalAlignment: Text.AlignVCenter |
| 105 | + visible: iconSource != 0 |
| 106 | + |
| 107 | + Behavior on color { enabled: control.animationEnabled; ColorAnimation { duration: 100 } } |
| 108 | + |
| 109 | + NumberAnimation on rotation { |
| 110 | + id: __animation |
| 111 | + running: control.rotating |
| 112 | + from: 0 |
| 113 | + to: 360 |
| 114 | + loops: Animation.Infinite |
| 115 | + duration: 1000 |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + DelCopyableText { |
| 120 | + id: __text |
| 121 | + anchors.verticalCenter: parent.verticalCenter |
| 122 | + text: control.text |
| 123 | + font: control.font |
| 124 | + color: control.colorText |
| 125 | + |
| 126 | + Behavior on color { enabled: control.animationEnabled; ColorAnimation { duration: 100 } } |
| 127 | + } |
| 128 | + |
| 129 | + DelIconText { |
| 130 | + id: __closeIcon |
| 131 | + anchors.verticalCenter: parent.verticalCenter |
| 132 | + color: hovered ? Qt.rgba(0,0,0,0.88) : Qt.rgba(0,0,0,0.45) |
| 133 | + iconSize: control.closeIconSize |
| 134 | + iconSource: control.closeIconSource |
| 135 | + verticalAlignment: Text.AlignVCenter |
| 136 | + visible: iconSource != 0 |
| 137 | + |
| 138 | + property alias hovered: __hoverHander.hovered |
| 139 | + property alias down: __tapHander.pressed |
| 140 | + |
| 141 | + Behavior on color { enabled: control.animationEnabled; ColorAnimation { duration: 100 } } |
| 142 | + |
| 143 | + HoverHandler { |
| 144 | + id: __hoverHander |
| 145 | + cursorShape: Qt.PointingHandCursor |
| 146 | + } |
| 147 | + |
| 148 | + TapHandler { |
| 149 | + id: __tapHander |
| 150 | + onTapped: control.close(); |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments