Skip to content

Commit 7abf955

Browse files
committed
Feat: 添加[DelTag]实现.
1 parent b8ddd5e commit 7abf955

File tree

12 files changed

+755
-5
lines changed

12 files changed

+755
-5
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ add_subdirectory(DelPopup)
5151
add_subdirectory(DelSelect)
5252
add_subdirectory(DelPagination)
5353
add_subdirectory(DelTimeline)
54+
add_subdirectory(DelTag)
5455

5556
# Deploy Script
5657
if(CMAKE_BUILD_TYPE MATCHES "Release")
@@ -100,6 +101,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Release")
100101
COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/package/DelSelect.app -qmldir=DelSelect
101102
COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/package/DelPagination.app -qmldir=DelPagination
102103
COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/package/DelTimeline.app -qmldir=DelTimeline
104+
COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/package/DelTag.app -qmldir=DelTag
103105
COMMENT "MacOs Deploying Qt Dependencies After Build........."
104106
SOURCES ${CMAKE_SOURCE_DIR}/CMakeLists.txt
105107
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@@ -151,6 +153,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Release")
151153
COMMAND ${QT_DEPLOY_QT} --qmldir=DelSelect --no-translations --compiler-runtime ${CMAKE_SOURCE_DIR}/package/DelSelect.exe
152154
COMMAND ${QT_DEPLOY_QT} --qmldir=DelPagination --no-translations --compiler-runtime ${CMAKE_SOURCE_DIR}/package/DelPagination.exe
153155
COMMAND ${QT_DEPLOY_QT} --qmldir=DelTimeline --no-translations --compiler-runtime ${CMAKE_SOURCE_DIR}/package/DelTimeline.exe
156+
COMMAND ${QT_DEPLOY_QT} --qmldir=DelTag --no-translations --compiler-runtime ${CMAKE_SOURCE_DIR}/package/DelTag.exe
154157
COMMENT "Windows Deploying Qt Dependencies After Build........."
155158
SOURCES ${CMAKE_SOURCE_DIR}/CMakeLists.txt
156159
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}

DelTag/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(DelTag VERSION 1.0 LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_AUTOMOC ON)
8+
set(CMAKE_AUTORCC ON)
9+
10+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick)
11+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick)
12+
13+
set(SOURCES main.cpp delcolorgenerator.h delcolorgenerator.cpp)
14+
15+
qt5_add_resources(SOURCES qml.qrc)
16+
17+
add_executable(${PROJECT_NAME} ${SOURCES} "${CMAKE_SOURCE_DIR}/common/QmlControls_Resource.rc")
18+
19+
set_target_properties(${PROJECT_NAME} PROPERTIES
20+
WIN32_EXECUTABLE TRUE
21+
RUNTIME_OUTPUT_DIRECTORY $<IF:$<BOOL:${BUILD_OUTPUT_DIRECTORY}>,${BUILD_OUTPUT_DIRECTORY},${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>
22+
)
23+
24+
target_link_libraries(${PROJECT_NAME} PRIVATE
25+
Qt::Quick
26+
)

DelTag/DelTag.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
QT += quick
2+
3+
# You can make your code fail to compile if it uses deprecated APIs.
4+
# In order to do so, uncomment the following line.
5+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
6+
7+
HEADERS += \
8+
delcolorgenerator.h
9+
10+
SOURCES += \
11+
delcolorgenerator.cpp \
12+
main.cpp
13+
14+
RESOURCES += qml.qrc
15+
16+
# Additional import path used to resolve QML modules in Qt Creator's code model
17+
QML_IMPORT_PATH =
18+
19+
# Additional import path used to resolve QML modules just for Qt Quick Designer
20+
QML_DESIGNER_IMPORT_PATH =
21+
22+
# Default rules for deployment.
23+
qnx: target.path = /tmp/$${TARGET}/bin
24+
else: unix:!android: target.path = /opt/$${TARGET}/bin
25+
!isEmpty(target.path): INSTALLS += target

DelTag/DelTag.qml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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

Comments
 (0)