Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d099f8b

Browse files
committedMar 8, 2025
Feat: 添加[DelDrawer]实现.
1 parent 8df26ad commit d099f8b

File tree

6 files changed

+259
-0
lines changed

6 files changed

+259
-0
lines changed
 

‎DelDrawer/CMakeLists.txt

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

‎DelDrawer/DelDrawer.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
SOURCES += \
8+
main.cpp
9+
10+
RESOURCES += qml.qrc
11+
12+
# Additional import path used to resolve QML modules in Qt Creator's code model
13+
QML_IMPORT_PATH =
14+
15+
# Additional import path used to resolve QML modules just for Qt Quick Designer
16+
QML_DESIGNER_IMPORT_PATH =
17+
18+
# Default rules for deployment.
19+
qnx: target.path = /tmp/$${TARGET}/bin
20+
else: unix:!android: target.path = /opt/$${TARGET}/bin
21+
!isEmpty(target.path): INSTALLS += target

‎DelDrawer/DelDrawer.qml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import QtQuick 2.15
2+
import QtQuick.Layouts 1.15
3+
import QtGraphicalEffects 1.15
4+
import QtQuick.Templates 2.15 as T
5+
6+
import "qrc:/../common"
7+
import "qrc:/../DelButton"
8+
import "qrc:/../DelDivider"
9+
10+
T.Drawer {
11+
id: control
12+
13+
titleFont {
14+
family: "微软雅黑"
15+
pixelSize: 18
16+
}
17+
18+
property bool animationEnabled: true
19+
property int drawerSize: 378
20+
property string title: ""
21+
property font titleFont
22+
property color colorTitle: "#000"
23+
property color colorBg: "#fff"
24+
property color colorOverlay: Qt.rgba(0,0,0,0.45)
25+
property Component titleDelegate: Item {
26+
height: 56
27+
28+
Row {
29+
height: parent.height
30+
anchors.left: parent.left
31+
anchors.leftMargin: 15
32+
spacing: 5
33+
34+
DelIconButton {
35+
id: __close
36+
type: DelButton.Type_Text
37+
effectEnabled: false
38+
topPadding: 2
39+
bottomPadding: 2
40+
leftPadding: 4
41+
rightPadding: 4
42+
radiusBg: 4
43+
anchors.verticalCenter: parent.verticalCenter
44+
iconSource: DelIcon.CloseOutlined
45+
colorIcon: hovered ? Qt.rgba(0,0,0,1) : Qt.rgba(0,0,0,0.4)
46+
colorBg: __close.down ? Qt.rgba(0,0,0,0.15) :
47+
__close.hovered ? Qt.rgba(0,0,0,0.06) : Qt.rgba(0,0,0,0)
48+
onClicked: {
49+
control.close();
50+
}
51+
52+
HoverHandler {
53+
cursorShape: Qt.PointingHandCursor
54+
}
55+
}
56+
57+
Text {
58+
anchors.verticalCenter: parent.verticalCenter
59+
text: control.title
60+
font: control.titleFont
61+
color: control.colorTitle
62+
}
63+
}
64+
65+
DelDivider {
66+
width: parent.width
67+
height: 1
68+
anchors.bottom: parent.bottom
69+
}
70+
}
71+
property Component contentDelegate: Item { }
72+
73+
enter: Transition { NumberAnimation { duration: control.animationEnabled ? 200 : 0 } }
74+
exit: Transition { NumberAnimation { duration: control.animationEnabled ? 200 : 0 } }
75+
76+
width: edge == Qt.LeftEdge || edge == Qt.RightEdge ? drawerSize : parent.width
77+
height: edge == Qt.LeftEdge || edge == Qt.RightEdge ? parent.height : drawerSize
78+
edge: Qt.RightEdge
79+
parent: T.Overlay.overlay
80+
modal: true
81+
background: Item {
82+
DropShadow {
83+
anchors.fill: __rect
84+
radius: 8.0
85+
samples: 17
86+
color: "#80000000"
87+
source: __rect
88+
}
89+
Rectangle {
90+
id: __rect
91+
anchors.fill: parent
92+
color: control.colorBg
93+
}
94+
}
95+
contentItem: ColumnLayout {
96+
Loader {
97+
Layout.fillWidth: true
98+
sourceComponent: titleDelegate
99+
}
100+
Loader {
101+
Layout.fillWidth: true
102+
Layout.fillHeight: true
103+
sourceComponent: contentDelegate
104+
}
105+
}
106+
107+
T.Overlay.modal: Rectangle {
108+
color: control.colorOverlay
109+
}
110+
}

‎DelDrawer/main.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <QGuiApplication>
2+
#include <QQmlApplicationEngine>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
7+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
8+
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
9+
#endif
10+
11+
QGuiApplication app(argc, argv);
12+
13+
QQmlApplicationEngine engine;
14+
const QUrl url(QStringLiteral("qrc:/main.qml"));
15+
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
16+
&app, [url](QObject *obj, const QUrl &objUrl) {
17+
if (!obj && url == objUrl)
18+
QCoreApplication::exit(-1);
19+
}, Qt::QueuedConnection);
20+
engine.load(url);
21+
22+
return app.exec();
23+
}

‎DelDrawer/main.qml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import QtQuick 2.15
2+
import QtQuick.Controls 2.15
3+
import QtQuick.Window 2.15
4+
5+
import "qrc:/../common"
6+
import "qrc:/../DelButton"
7+
import "qrc:/../DelRadio"
8+
9+
Window {
10+
width: 640
11+
height: 480
12+
visible: true
13+
title: qsTr("DelegateUI-DelDrawer")
14+
15+
Column {
16+
anchors.centerIn: parent
17+
spacing: 10
18+
19+
Row {
20+
spacing: 10
21+
22+
ButtonGroup { id: radioGroup }
23+
24+
DelRadio {
25+
text: qsTr("")
26+
checked: true
27+
ButtonGroup.group: radioGroup
28+
property int value: Qt.TopEdge
29+
}
30+
31+
DelRadio {
32+
text: qsTr("")
33+
ButtonGroup.group: radioGroup
34+
property int value: Qt.BottomEdge
35+
}
36+
37+
DelRadio {
38+
text: qsTr("")
39+
ButtonGroup.group: radioGroup
40+
property int value: Qt.LeftEdge
41+
}
42+
43+
DelRadio {
44+
text: qsTr("")
45+
ButtonGroup.group: radioGroup
46+
property int value: Qt.RightEdge
47+
}
48+
}
49+
50+
DelButton {
51+
anchors.horizontalCenter: parent.horizontalCenter
52+
type: DelButton.Type_Primary
53+
text: qsTr("打开")
54+
onClicked: drawer.open();
55+
56+
DelDrawer {
57+
id: drawer
58+
drawerSize: 260
59+
edge: radioGroup.checkedButton.value
60+
title: qsTr("Basic Drawer")
61+
contentDelegate: DelCopyableText {
62+
leftPadding: 15
63+
text: "Some contents...\nSome contents...\nSome contents..."
64+
}
65+
}
66+
}
67+
}
68+
}

‎DelDrawer/qml.qrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>DelDrawer.qml</file>
5+
<file>../DelButton/DelIconButton.qml</file>
6+
<file>../DelDivider/DelDivider.qml</file>
7+
<file>../common/DelegateUI-Icons.ttf</file>
8+
<file>../common/DelIcon.qml</file>
9+
<file>../DelButton/DelButton.qml</file>
10+
<file>../DelRadio/DelRadio.qml</file>
11+
<file>../common/DelCopyableText.qml</file>
12+
</qresource>
13+
</RCC>

0 commit comments

Comments
 (0)
Please sign in to comment.