Skip to content

Commit

Permalink
feat: 支持切换深浅色
Browse files Browse the repository at this point in the history
  • Loading branch information
mhduiy committed Jan 12, 2025
1 parent 2d17408 commit c39cb78
Show file tree
Hide file tree
Showing 23 changed files with 350 additions and 115 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_executable(${EXE_NAME}
)

add_subdirectory(${CMAKE_SOURCE_DIR}/src/cpp/adb)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/cpp/app)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/cpp/appPageTool)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/cpp/components)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/cpp/controlPageTool)
Expand Down
21 changes: 12 additions & 9 deletions src/MFloat/Controls/ColorConstants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import QtQuick
import QtQuick.Controls

QtObject {
property color suggestBackColor: Qt.rgba(219 / 255,242 / 255,255 / 255, 0.65)
property color suggestHoverColor: Qt.rgba(147 / 255,217 / 255,255 / 255, 0.65)
property color suggestClickedColor: Qt.rgba(0 / 255,165 / 255,255 / 255, 0.65)
property color ordinaryBackColor: Qt.rgba(232 / 255,232 / 255,232 / 255, 0.65)
property color ordinaryHoverColor: Qt.rgba(175 / 255,175 / 255,175 / 255, 0.65)
property color ordinaryClickedColor: Qt.rgba(0 / 255,0 / 255,0 / 255, 0.65)
property color warningBackColor: Qt.rgba(255 / 255,231 / 255,231 / 255, 0.65)
property color warningHoverColor: Qt.rgba(255 / 255,169 / 255,169 / 255, 0.65)
property color warningClickedColor: Qt.rgba(214 / 255,62 / 255,62 / 255, 0.65)
property color suggestBackColor: Qt.rgba(0, 125 / 255, 200 / 255, 0.1)
property color suggestHoverColor: Qt.rgba(0, 125 / 255, 200 / 255, 0.3)
property color suggestClickedColor: Qt.rgba(0, 125 / 255, 200 / 255, 0.8)
property color ordinaryBackColor: Qt.rgba(0, 0, 0, 0.1)
property color ordinaryHoverColor: Qt.rgba(0, 0, 0, 0.3)
property color ordinaryClickedColor: Qt.rgba(0, 0, 0, 0.8)
property color warningBackColor: Qt.rgba(215 / 255, 80 / 255, 80 / 255, 0.1)
property color warningHoverColor: Qt.rgba(215 / 255, 80 / 255, 80 / 255, 0.3)
property color warningClickedColor: Qt.rgba(215 / 255, 80 / 255, 80 / 255, 0.8)

property color lightTextColor: ordinaryClickedColor
property color darkTextColor: Qt.rgba(1, 1, 1, 0.8)
}
36 changes: 21 additions & 15 deletions src/MFloat/Controls/MButton.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick
import QtQuick.Controls
import App

Item {
id: root
Expand All @@ -23,10 +24,6 @@ Item {
property int fontSize: 12
signal clicked

ColorConstants {
id: colorConstants
}

Rectangle {
id: btnRect
width: root.width
Expand All @@ -38,19 +35,19 @@ Item {
property int mouseClickCenterX: 0
property int mouseClickCenterY: 0
property var backgroundColorMap: [
{ key: MButton.FBtnType.Ordinary, value: colorConstants.ordinaryBackColor},
{ key: MButton.FBtnType.Suggest, value: colorConstants.suggestBackColor},
{ key: MButton.FBtnType.Warning, value: colorConstants.warningBackColor}
{ key: MButton.FBtnType.Ordinary, value: App.normalColorWeight1 },
{ key: MButton.FBtnType.Suggest, value: App.suggestColorWeight1 },
{ key: MButton.FBtnType.Warning, value: App.warningColorWeight1 }
]
property var hoverColorMap: [
{ key: MButton.FBtnType.Ordinary, value: colorConstants.ordinaryHoverColor},
{ key: MButton.FBtnType.Suggest, value: colorConstants.suggestHoverColor},
{ key: MButton.FBtnType.Warning, value: colorConstants.warningHoverColor}
{ key: MButton.FBtnType.Ordinary, value: App.normalColorWeight2 },
{ key: MButton.FBtnType.Suggest, value: App.suggestColorWeight2 },
{ key: MButton.FBtnType.Warning, value: App.warningColorWeight2 }
]
property var clickedColorMap: [
{ key: MButton.FBtnType.Ordinary, value: colorConstants.ordinaryClickedColor},
{ key: MButton.FBtnType.Suggest, value: colorConstants.suggestClickedColor},
{ key: MButton.FBtnType.Warning, value: colorConstants.warningClickedColor}
{ key: MButton.FBtnType.Ordinary, value: App.normalColorWeight3 },
{ key: MButton.FBtnType.Suggest, value: App.suggestColorWeight3 },
{ key: MButton.FBtnType.Warning, value: App.warningColorWeight3 }
]

color: {
Expand All @@ -61,8 +58,12 @@ Item {
}
}

border.width: 2
border.color: clickedColorMap[btnType].value
Behavior on color {
ColorAnimation{
duration: 200
}
}

radius: 10

Behavior on color {
Expand Down Expand Up @@ -108,6 +109,11 @@ Item {
color: btnRect.clickedColorMap[btnRect.btnType].value
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Behavior on color {
ColorAnimation{
duration: 200
}
}
}

Rectangle {
Expand Down
44 changes: 28 additions & 16 deletions src/MFloat/Controls/MLineEdit.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick
import QtQuick.Controls
import App

Item {

Expand All @@ -11,32 +12,31 @@ Item {
property alias editItem: edit
property string placeholderText: ""

ColorConstants {
id: colorConstants
}

Rectangle {
id: warpper
anchors.fill: parent
color: colorConstants.ordinaryBackColor
color: App.normalColorWeight1
radius: 10
border.width: 2
border.color: colorConstants.ordinaryClickedColor

state: "unInput"

Behavior on color {
ColorAnimation{
duration: 200
}
}

states: [
State {
name: "unInput"
PropertyChanges { target: placeholderItemRect; color: edit.length !== 0 ? colorConstants.ordinaryClickedColor: "transparent"; x: edit.length !== 0 ? 15 : 5; y: edit.length !== 0 ? (-((placeholderItem.height + 5) / 2)) : (root.height / 2 - placeholderItemRect.height / 2)}
PropertyChanges { target: placeholderItem; color: edit.length !== 0 ? "white" : "gray"}
PropertyChanges { target: warpper; color: colorConstants.ordinaryBackColor; border.color: colorConstants.ordinaryClickedColor}
PropertyChanges { target: placeholderItemRect; color: edit.length !== 0 ? App.baseColor: "transparent"; x: edit.length !== 0 ? 15 : 5; y: edit.length !== 0 ? (-((placeholderItem.height + 5) / 2)) : (root.height / 2 - placeholderItemRect.height / 2)}
PropertyChanges { target: placeholderItem; color: App.windowTextColor}
PropertyChanges { target: warpper; color: App.normalColorWeight1;}
},
State {
name: "input"
PropertyChanges { target: placeholderItemRect; color: colorConstants.suggestClickedColor; x: 15; y: -((placeholderItem.height + 5) / 2)}
PropertyChanges { target: placeholderItem; color: "white"}
PropertyChanges { target: warpper; color: colorConstants.suggestBackColor; border.color: colorConstants.suggestClickedColor}
PropertyChanges { target: placeholderItemRect; color: App.suggestColorWeight3; x: 15; y: -((placeholderItem.height + 5) / 2)}
PropertyChanges { target: placeholderItem; color: App.windowTextColor}
PropertyChanges { target: warpper; color: App.suggestColorWeight2;}
}
]

Expand All @@ -61,16 +61,22 @@ Item {
id: placeholderItemRect
height: placeholderItem.height + 5
width: placeholderItem.width + 5
color: colorConstants.ordinaryClickedColor
color: App.normalColorWeight3
radius: 5
Text {
id: placeholderItem
anchors.centerIn: parent
clip: true
text: placeholderText
verticalAlignment: Text.AlignVCenter
color: "white"
color: App.windowTextColor
font.pixelSize: 10

Behavior on color {
ColorAnimation{
duration: 200
}
}
}
}

Expand All @@ -80,6 +86,12 @@ Item {
anchors.margins: 5
clip: true
verticalAlignment: Text.AlignVCenter
color: App.windowTextColor
Behavior on color {
ColorAnimation{
duration: 200
}
}

onFocusChanged: {
if (focus) {
Expand Down
7 changes: 4 additions & 3 deletions src/MFloat/Controls/MLoadIndicator.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick
import QtQuick.Controls
import App

Item {
width: 30
Expand All @@ -18,8 +19,8 @@ Item {
opacity: 0.0
onPaint: {
var ctx = getContext("2d");
ctx.strokeStyle = "black";
ctx.lineWidth = 2;
ctx.strokeStyle = App.normalColorWeight3;
ctx.lineWidth = 1;
ctx.imageSmoothingEnabled = true;
antialiasing: true

Expand All @@ -32,7 +33,7 @@ Item {
ctx.stroke();

var smallRadius = 4;
ctx.fillStyle = "black";
ctx.fillStyle = App.normalColorWeight3;
ctx.beginPath();
ctx.arc(centerX, 10, smallRadius, 0, 2 * Math.PI);
ctx.fill();
Expand Down
1 change: 1 addition & 0 deletions src/MFloat/Controls/MNotificationBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import QtQuick.Layouts
import QtQuick.Effects

import NotificationController
import App

Item {
id: root
Expand Down
11 changes: 3 additions & 8 deletions src/MFloat/Controls/MSwitchButton.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import QtQuick
import App

Item {
id: root
Expand All @@ -7,15 +8,9 @@ Item {

property bool status: false

ColorConstants {
id: colorConstants
}

Rectangle {
anchors.fill: parent
color: status ? colorConstants.suggestBackColor : colorConstants.ordinaryBackColor
border.width: 2
border.color: status ? colorConstants.suggestClickedColor : colorConstants.ordinaryClickedColor
color: status ? App.suggestColorWeight1 : App.normalColorWeight1
radius: width / 2

Behavior on color {
Expand All @@ -37,7 +32,7 @@ Item {
width: height
radius: width / 2
scale: 1.0
color: status ? colorConstants.suggestClickedColor : colorConstants.ordinaryClickedColor
color: status ? App.suggestColorWeight3 : App.adjustColorOpacity(App.normalColorWeight3, 0.6)

Component.onCompleted: {
x = status ? parent.width - width - 3 : 3
Expand Down
28 changes: 25 additions & 3 deletions src/MFloat/Controls/MWrapper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import OtherSettingsHandler
import App

Control {
id: control
Expand All @@ -24,9 +25,15 @@ Control {
visible: active
Layout.alignment: Qt.AlignTop
sourceComponent: Text {
color: App.windowTextColor
text: control.title
font.bold: true
font.pixelSize: 18
Behavior on color {
ColorAnimation{
duration: 200
}
}
}
}

Expand All @@ -35,9 +42,14 @@ Control {
visible: active
Layout.alignment: Qt.AlignTop
sourceComponent: Text {
color: App.windowTextAssitColor
text: control.description
font.pixelSize: 12
opacity: 0.6
Behavior on color {
ColorAnimation{
duration: 200
}
}
}
}
}
Expand All @@ -60,8 +72,18 @@ Control {

background: Rectangle {
radius: 10
color: Qt.rgba(255, 255, 255, alpha)
border.color: colorConstants.ordinaryHoverColor
color: Qt.rgba(255, 255, 255, control.alpha)
border.color: App.borderColor
border.width: 1
Behavior on color {
ColorAnimation{
duration: 200
}
}
Behavior on border.color {
ColorAnimation{
duration: 200
}
}
}
}
8 changes: 8 additions & 0 deletions src/cpp/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(APP_SRC
${CMAKE_CURRENT_SOURCE_DIR}/appglobal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/appglobal.h
)

target_sources(${EXE_NAME} PRIVATE ${APP_SRC})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Loading

0 comments on commit c39cb78

Please sign in to comment.