Skip to content

Commit

Permalink
feat: impl combobox and slider
Browse files Browse the repository at this point in the history
  • Loading branch information
mhduiy committed Jan 17, 2025
1 parent ef1cf47 commit dca8b3e
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 33 deletions.
112 changes: 112 additions & 0 deletions src/MFloat/Controls/MComboBox.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
pragma ComponentBehavior: Bound

import QtQuick
import QtQuick.Controls
import QtQuick.Controls.impl
import App
import QtQuick.Templates as T

T.ComboBox {
id: control

implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
implicitContentHeight + topPadding + bottomPadding,
implicitIndicatorHeight + topPadding + bottomPadding)

leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)

delegate: ItemDelegate {
required property var model
required property int index

width: ListView.view.width
text: model[control.textRole]
palette.text: App.windowTextColor
palette.highlightedText: App.windowTextColor
font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal
highlighted: control.highlightedIndex === index
hoverEnabled: control.hoverEnabled
background: Rectangle {
color: App.suggestColorWeight3
radius: 5
visible: parent.hovered
}
}

indicator: ColorImage {
x: control.mirrored ? control.padding : control.width - width - control.padding
y: control.topPadding + (control.availableHeight - height) / 2
color: App.windowTextColor
defaultColor: App.windowTextColor
source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/double-arrow.png"
opacity: 0.5
scale: 0.7
}

contentItem: T.TextField {
leftPadding: !control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1
rightPadding: control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1
topPadding: 6 - control.padding
bottomPadding: 6 - control.padding

text: control.editable ? control.editText : control.displayText

enabled: control.editable
autoScroll: control.editable
readOnly: control.down
inputMethodHints: control.inputMethodHints
validator: control.validator
selectByMouse: control.selectTextByMouse

color: App.windowTextColor
selectionColor: control.palette.highlight
selectedTextColor: control.palette.highlightedText
verticalAlignment: Text.AlignVCenter

background: Rectangle {
visible: control.enabled && control.editable && !control.flat
border.width: parent && parent.activeFocus ? 2 : 1
border.color: parent && parent.activeFocus ? control.palette.highlight : control.palette.button
color: control.palette.base
}
}

background: Rectangle {
implicitWidth: 140
implicitHeight: 30
radius: 5

color: App.normalColorWeight1
border.color: control.palette.highlight
border.width: !control.editable && control.visualFocus ? 2 : 0
visible: !control.flat || control.down
}

popup: T.Popup {
y: control.height
width: control.width
height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin)
topMargin: 6
bottomMargin: 6
palette: control.palette

contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: control.delegateModel
currentIndex: control.highlightedIndex
highlightMoveDuration: 0

T.ScrollIndicator.vertical: ScrollIndicator { }
}

background: Rectangle {
color: App.normalColorWeight1
border.color: App.borderColor
radius: 5
}
}
}
8 changes: 8 additions & 0 deletions src/MFloat/Controls/MLoadIndicator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ Item {
}
}
}

Connections {
target: App
function onThemeTypeChanged() {
canvas.requestPaint()
}
}

RotationAnimation {
id: rotationAnimation
target: canvas
Expand Down
30 changes: 30 additions & 0 deletions src/MFloat/Controls/MSlider.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Templates as T
import App

T.Slider {
id: control

implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitHandleWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
implicitHandleHeight + topPadding + bottomPadding)


background: Rectangle {
// implicitWidth: 200
implicitHeight: 10
color: App.adjustColorOpacity(App.normalColorWeight3, 0.15)
radius: 4
}

handle: Rectangle {
color: App.adjustColorOpacity(App.suggestColorWeight3, 1.0)
width: 15
height: 20
radius: 4
x: control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2)
y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height))
}
}
20 changes: 2 additions & 18 deletions src/MFloat/Controls/MSwitchButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,14 @@ Item {

SequentialAnimation {
id: scaleAni
NumberAnimation {
target: thumb
from: 1.0
to: 0.6
duration: 80
property: "scale"
}

NumberAnimation{
target: thumb
from: status ? 3 : thumb.parent.width - thumb.width
from: status ? 3 : thumb.parent.width - thumb.width - 3
to: status ? thumb.parent.width - thumb.width - 3 : 3
duration: 150
duration: 200
property: "x"
easing.type: Easing.InOutCirc
}

NumberAnimation {
target: thumb
from: 0.6
to: 1.0
duration: 80
property: "scale"
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MFloat/Controls/MWrapper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Control {

background: Rectangle {
radius: 10
color: Qt.rgba(255, 255, 255, control.alpha)
color: App.adjustColorOpacity(App.baseColor, control.alpha)
border.color: App.borderColor
border.width: 1
Behavior on color {
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/app/appglobal.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "appglobal.h"
#include "src/cpp/utils/constants.h"
#include "src/cpp/utils/globalsetting.h"
#include <QDebug>

Expand Down Expand Up @@ -30,7 +31,7 @@ const QColor DarkBorderColor = QColor(255, 255, 255, 0.2 * 255);
AppGlobal::AppGlobal(QObject *parent)
: QObject(parent)
{
m_themeType = (ThemeType)AppSettings->readConfig(Other_Section, Theme_Type_Key, ThemeType::Light).toInt();
m_themeType = (ThemeType)AppSettings->readConfig(Other_Section, Theme_Type_Key, DEFAULT_APP_THEME_TYPE).toInt();
reload();
}

Expand Down
5 changes: 3 additions & 2 deletions src/cpp/settingPageTool/othersettingshandler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "othersettingshandler.h"
#include "../utils/globalsetting.h"
#include "src/cpp/utils/constants.h"

static auto constexpr Other_Section = "other";
static auto constexpr Wrapper_opacity_key = "wrapperOpacity";
Expand All @@ -8,10 +9,10 @@ static auto constexpr Use_OpenGL_Key = "useOpenGL";
OtherSettingsHandler::OtherSettingsHandler(QObject *parent)
: QObject(parent)
{
double configWrapperOpacity = AppSettings->readConfig(Other_Section, Wrapper_opacity_key, 0.3).toDouble();
double configWrapperOpacity = AppSettings->readConfig(Other_Section, Wrapper_opacity_key, DEFAULT_WRAPPER_OPACITY).toDouble();
setWrapperOpacity(configWrapperOpacity);

bool useOpenGL = AppSettings->readConfig(Other_Section, Use_OpenGL_Key, false).toBool();
bool useOpenGL = AppSettings->readConfig(Other_Section, Use_OpenGL_Key, DEFAULT_USE_OPENGL).toBool();
setUseOpenGL(useOpenGL);
}

Expand Down
8 changes: 4 additions & 4 deletions src/cpp/settingPageTool/wallpaperhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ WallpaperHelper::WallpaperHelper(QObject *parent)
, m_triggerTimer(new QTimer(this))
{
GlobalSetting::instance()->checkConfig("wallpaper", "url", "qrc:/res/backgroundImage.jpeg");
GlobalSetting::instance()->checkConfig("wallpaper", "opacity", 0.2);
GlobalSetting::instance()->checkConfig("wallpaper", "blurRadius", 10);
GlobalSetting::instance()->checkConfig("wallpaper", "opacity", DEFAULT_WALLPAPER_OPACITY);
GlobalSetting::instance()->checkConfig("wallpaper", "blurRadius", DEFAULT_WALLPAPER_BLUR_RADIUS);
// 获取壁纸配置
QString cutWallpaperUrl = GlobalSetting::instance()->readConfig("wallpaper", "url").toString();
if (cutWallpaperUrl.isEmpty()) {
Expand All @@ -24,9 +24,9 @@ WallpaperHelper::WallpaperHelper(QObject *parent)
setWallPaper(cutWallpaperUrl);
}

qreal wallpaperOpacity = GlobalSetting::instance()->readConfig("wallpaper", "opacity", 0.2).toReal();
qreal wallpaperOpacity = GlobalSetting::instance()->readConfig("wallpaper", "opacity", DEFAULT_WALLPAPER_OPACITY).toReal();
setOpacity(wallpaperOpacity);
int wallpaperBlurRadius = GlobalSetting::instance()->readConfig("wallpaper", "blurRadius", 10).toInt();
int wallpaperBlurRadius = GlobalSetting::instance()->readConfig("wallpaper", "blurRadius", DEFAULT_WALLPAPER_BLUR_RADIUS).toInt();
setBlurRadius(wallpaperBlurRadius);

connect(m_triggerTimer, &QTimer::timeout, this, &WallpaperHelper::writeValueToConfig);
Expand Down
11 changes: 10 additions & 1 deletion src/cpp/utils/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
#include <QApplication>
#include <QStandardPaths>

const QString WALLPAPERCACHEJSONPATH = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() + "AndroidTools" + QDir::separator() + "wallpaperCache.json";
const static QString WALLPAPERCACHEJSONPATH = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() + "AndroidTools" + QDir::separator() + "wallpaperCache.json";

// default values
const static double DEFAULT_WALLPAPER_OPACITY = 0.6;
const static QString DEFAULT_WALLPAPER = "";
const static int DEFAULT_WALLPAPER_BLUR_RADIUS = 50;
const static bool DEFAULT_USE_OPENGL = false;
const static double DEFAULT_WRAPPER_OPACITY = 0.4;
const static int DEFAULT_APP_THEME_TYPE = 0;

class constants
{
public:
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "cpp/components/fpsitem.h"
#include "cpp/utils/globalsetting.h"
#include "cpp/app/appglobal.h"
#include "src/cpp/utils/constants.h"

bool checkADB() {
QProcess process;
Expand Down Expand Up @@ -117,7 +118,7 @@ int main(int argc, char *argv[])
qmlRegisterType<FpsItem>( "FpsItem", 1, 0, "FpsItem");
qmlRegisterSingletonInstance("App", 1, 0, "App", App);

AppSettings->checkConfig("other", "useOpenGL", QVariant::fromValue(false));
AppSettings->checkConfig("other", "useOpenGL", DEFAULT_USE_OPENGL);
bool useOpenGL = GlobalSetting::instance()->readConfig("other", "useOpenGL").toBool();
if (useOpenGL) {
qInfo() << "force use OpenGL";
Expand Down
18 changes: 18 additions & 0 deletions src/qml/components/TitleBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Rectangle {
Layout.fillHeight: true
color: "transparent"
Canvas {
id: minCanvas
anchors.fill: parent
onPaint: {
var ctx = getContext("2d");
Expand All @@ -145,6 +146,14 @@ Rectangle {
ctx.stroke();
}
}

Connections {
target: App
function onThemeTypeChanged() {
minCanvas.requestPaint()
}
}

Behavior on scale {
NumberAnimation {
duration: 300
Expand All @@ -171,6 +180,7 @@ Rectangle {
Layout.fillHeight: true
color: "transparent"
Canvas {
id: closeCanvas
anchors.fill: parent
onPaint: {
var ctx = getContext("2d");
Expand All @@ -184,6 +194,14 @@ Rectangle {
ctx.stroke();
}
}

Connections {
target: App
function onThemeTypeChanged() {
closeCanvas.requestPaint()
}
}

Behavior on scale {
NumberAnimation {
duration: 300
Expand Down
2 changes: 1 addition & 1 deletion src/qml/pages/DeviceAppPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ItemPage {
Layout.preferredWidth: parent.width * 0.4
Layout.fillHeight: true
title: "软件列表"
titleRightContent: ComboBox {
titleRightContent: MComboBox {
id: softListComboBox
Layout.minimumWidth: 80
model: ["第三方应用", "系统应用", "所有应用"]
Expand Down
8 changes: 4 additions & 4 deletions src/qml/pages/SettingPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ItemPage {
id: wallpaperListView
anchors.fill: parent
model: WallPaperModel
spacing: 4
spacing: 5
orientation: ListView.Horizontal
clip: true
focus: true
Expand Down Expand Up @@ -140,7 +140,7 @@ ItemPage {
SettingItem {
title: "壁纸不透明度"
description: "设置壁纸白色遮罩的透明度"
controlItem: Slider {
controlItem: MSlider {
id: slider
width: 200
from: 0
Expand All @@ -157,7 +157,7 @@ ItemPage {
SettingItem {
title: "壁纸模糊度"
description: "设置壁纸的模糊半径"
controlItem: Slider {
controlItem: MSlider {
width: 200
from: 0
value: WallpaperHelper.blurRadius
Expand All @@ -174,7 +174,7 @@ ItemPage {
SettingItem {
title: "模块背景透明度"
description: "设置每一个功能模块区域的透明度"
controlItem: Slider {
controlItem: MSlider {
width: 200
from: 0
value: OtherSettingsHandler.wrapperOpacity
Expand Down

0 comments on commit dca8b3e

Please sign in to comment.