main
zhuzihcu 2023-04-14 17:07:54 +08:00
parent 935f515a49
commit b28f15c23b
15 changed files with 201 additions and 17 deletions

View File

@ -1,7 +1,25 @@
#include "AppInfo.h" #include "AppInfo.h"
#include "lang/En.h"
#include "lang/Zh.h"
AppInfo::AppInfo(QObject *parent) AppInfo::AppInfo(QObject *parent)
: QObject{parent} : QObject{parent}
{ {
version("1.2.4"); version("1.2.4");
changeLang("En");
}
void AppInfo::changeLang(const QString& locale){
if(_lang){
_lang->deleteLater();
}
if(locale=="Zh"){
lang(new Zh());
}else if(locale=="En"){
lang(new En());
}else {
lang(new En());
}
} }

View File

@ -2,14 +2,17 @@
#define APPINFO_H #define APPINFO_H
#include <QObject> #include <QObject>
#include "lang/Lang.h"
#include "stdafx.h" #include "stdafx.h"
class AppInfo : public QObject class AppInfo : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY_AUTO(QString,version) Q_PROPERTY_AUTO(QString,version)
Q_PROPERTY_AUTO(Lang*,lang)
public: public:
explicit AppInfo(QObject *parent = nullptr); explicit AppInfo(QObject *parent = nullptr);
Q_INVOKABLE void changeLang(const QString& locale);
}; };
#endif // APPINFO_H #endif // APPINFO_H

View File

@ -23,12 +23,12 @@ FluScrollablePage{
ColumnLayout{ ColumnLayout{
spacing: 10 spacing: 10
anchors{ anchors{
verticalCenter: parent.verticalCenter top: parent.top
left: parent.left left: parent.left
} }
FluText{ FluText{
text:"NavigationView Display Mode" text:lang.navigation_view_display_mode
fontStyle: FluText.BodyStrong fontStyle: FluText.BodyStrong
Layout.bottomMargin: 4 Layout.bottomMargin: 4
} }
@ -40,11 +40,49 @@ FluScrollablePage{
selected : MainEvent.displayMode===modelData.mode selected : MainEvent.displayMode===modelData.mode
text:modelData.title text:modelData.title
onClicked:{ onClicked:{
MainEvent.displayMode = modelData.mode MainEvent.displayMode = modelData.mode
} }
} }
} }
} }
} }
FluArea{
Layout.fillWidth: true
Layout.topMargin: 20
height: 168
paddings: 10
ColumnLayout{
spacing: 10
anchors{
top: parent.top
left: parent.left
}
FluText{
text:lang.locale
fontStyle: FluText.BodyStrong
Layout.bottomMargin: 4
}
Flow{
spacing: 5
Repeater{
model: ["Zh","En"]
delegate: FluRadioButton{
selected : appInfo.lang.objectName === modelData
text:modelData
onClicked:{
console.debug(modelData)
appInfo.changeLang(modelData)
}
}
}
}
}
}
} }

View File

@ -3,6 +3,9 @@ CONFIG += c++17
DEFINES += QT_DEPRECATED_WARNINGS QT_NO_WARNING_OUTPUT DEFINES += QT_DEPRECATED_WARNINGS QT_NO_WARNING_OUTPUT
HEADERS += \ HEADERS += \
lang/En.h \
lang/Lang.h \
lang/Zh.h \
stdafx.h \ stdafx.h \
ChatController.h \ ChatController.h \
AppInfo.h AppInfo.h
@ -10,6 +13,9 @@ HEADERS += \
SOURCES += \ SOURCES += \
ChatController.cpp \ ChatController.cpp \
AppInfo.cpp \ AppInfo.cpp \
lang/En.cpp \
lang/Lang.cpp \
lang/Zh.cpp \
main.cpp main.cpp
RESOURCES += qml.qrc RESOURCES += qml.qrc

View File

@ -10,14 +10,14 @@ FluObject{
FluPaneItemSeparator{} FluPaneItemSeparator{}
FluPaneItem{ FluPaneItem{
title:"About" title:lang.about
icon:FluentIcons.Contact icon:FluentIcons.Contact
tapFunc:function(){ tapFunc:function(){
FluApp.navigate("/about") FluApp.navigate("/about")
} }
} }
FluPaneItem{ FluPaneItem{
title:"Settings" title:lang.settings
icon:FluentIcons.Settings icon:FluentIcons.Settings
onTap:{ onTap:{
navigationView.push("qrc:/T_Settings.qml") navigationView.push("qrc:/T_Settings.qml")

View File

@ -8,7 +8,7 @@ FluObject{
property var navigationView property var navigationView
FluPaneItem{ FluPaneItem{
title:"Home" title:lang.home
// icon:FluentIcons.Home // icon:FluentIcons.Home
cusIcon: Image{ cusIcon: Image{
anchors.centerIn: parent anchors.centerIn: parent
@ -23,7 +23,7 @@ FluObject{
} }
FluPaneItemExpander{ FluPaneItemExpander{
title:"Basic input" title:lang.basic_input
icon:FluentIcons.CheckboxComposite icon:FluentIcons.CheckboxComposite
FluPaneItem{ FluPaneItem{
title:"Buttons" title:"Buttons"
@ -61,7 +61,7 @@ FluObject{
} }
FluPaneItemExpander{ FluPaneItemExpander{
title:"Form" title:lang.form
icon:FluentIcons.GridView icon:FluentIcons.GridView
FluPaneItem{ FluPaneItem{
title:"TextBox" title:"TextBox"
@ -96,7 +96,7 @@ FluObject{
} }
FluPaneItemExpander{ FluPaneItemExpander{
title:"Surface" title:lang.surface
icon:FluentIcons.SurfaceHub icon:FluentIcons.SurfaceHub
FluPaneItem{ FluPaneItem{
title:"InfoBar" title:"InfoBar"
@ -152,7 +152,7 @@ FluObject{
} }
FluPaneItemExpander{ FluPaneItemExpander{
title:"Popus" title:lang.popus
icon:FluentIcons.ButtonMenu icon:FluentIcons.ButtonMenu
FluPaneItem{ FluPaneItem{
title:"Dialog" title:"Dialog"
@ -175,7 +175,7 @@ FluObject{
} }
FluPaneItemExpander{ FluPaneItemExpander{
title:"Navigation" title:lang.navigation
icon:FluentIcons.AllApps icon:FluentIcons.AllApps
FluPaneItem{ FluPaneItem{
title:"Pivot" title:"Pivot"
@ -232,7 +232,7 @@ FluObject{
} }
FluPaneItemExpander{ FluPaneItemExpander{
title:"Theming" title:lang.theming
icon:FluentIcons.Brightness icon:FluentIcons.Brightness
FluPaneItem{ FluPaneItem{
title:"Theme" title:"Theme"
@ -255,7 +255,7 @@ FluObject{
} }
FluPaneItemExpander{ FluPaneItemExpander{
title:"Media" title:lang.media
icon:FluentIcons.Media icon:FluentIcons.Media
FluPaneItem{ FluPaneItem{
title:"MediaPlayer" title:"MediaPlayer"

20
example/lang/En.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "En.h"
En::En(QObject *parent)
: Lang{parent}
{
setObjectName("En");
home("Home");
basic_input("Basic Input");
form("Form");
surface("Surfaces");
popus("Popus");
navigation("Navigation");
theming("Theming");
media("Media");
dark_mode("Dark Mode");
search("Search");
about("About");
settings("Settings");
navigation_view_display_mode("NavigationView Display Mode");
}

17
example/lang/En.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef EN_H
#define EN_H
#include <QObject>
#include "Lang.h"
class En : public Lang
{
Q_OBJECT
public:
explicit En(QObject *parent = nullptr);
signals:
};
#endif // EN_H

7
example/lang/Lang.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "Lang.h"
Lang::Lang(QObject *parent)
: QObject{parent}
{
}

29
example/lang/Lang.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef LANG_H
#define LANG_H
#include <QObject>
#include "stdafx.h"
class Lang : public QObject
{
Q_OBJECT
Q_PROPERTY_AUTO(QString,home);
Q_PROPERTY_AUTO(QString,basic_input);
Q_PROPERTY_AUTO(QString,form);
Q_PROPERTY_AUTO(QString,surface);
Q_PROPERTY_AUTO(QString,popus);
Q_PROPERTY_AUTO(QString,navigation);
Q_PROPERTY_AUTO(QString,theming);
Q_PROPERTY_AUTO(QString,media);
Q_PROPERTY_AUTO(QString,dark_mode);
Q_PROPERTY_AUTO(QString,search);
Q_PROPERTY_AUTO(QString,about);
Q_PROPERTY_AUTO(QString,settings);
Q_PROPERTY_AUTO(QString,navigation_view_display_mode);
Q_PROPERTY_AUTO(QString,locale);
public:
explicit Lang(QObject *parent = nullptr);
};
#endif // LANG_H

21
example/lang/zh.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "zh.h"
Zh::Zh(QObject *parent)
: Lang{parent}
{
setObjectName("Zh");
home("首页");
basic_input("基本输入");
form("表单");
surface("表面");
popus("弹窗");
navigation("导航");
theming("主题");
media("媒体");
dark_mode("夜间模式");
search("查找");
about("关于");
settings("设置");
locale("语言环境");
navigation_view_display_mode("导航视图显示模式");
}

17
example/lang/zh.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef ZH_H
#define ZH_H
#include <QObject>
#include "Lang.h"
class Zh : public Lang
{
Q_OBJECT
public:
explicit Zh(QObject *parent = nullptr);
signals:
};
#endif // ZH_H

View File

@ -5,6 +5,7 @@
#include <QQuickWindow> #include <QQuickWindow>
#include <QQuickStyle> #include <QQuickStyle>
#include <QProcess> #include <QProcess>
#include "lang/Lang.h"
#include "AppInfo.h" #include "AppInfo.h"
#include "ChatController.h" #include "ChatController.h"
@ -17,7 +18,14 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
qmlRegisterType<ChatController>("Controller",1,0,"ChatController"); qmlRegisterType<ChatController>("Controller",1,0,"ChatController");
engine.rootContext()->setContextProperty("appInfo",new AppInfo()); AppInfo* appInfo = new AppInfo();
QQmlContext * context = engine.rootContext();
Lang* lang = appInfo->lang();
context->setContextProperty("lang",lang);
QObject::connect(appInfo,&AppInfo::langChanged,&app,[context,appInfo]{
context->setContextProperty("lang",appInfo->lang());
});
context->setContextProperty("appInfo",appInfo);
const QUrl url(QStringLiteral("qrc:/App.qml")); const QUrl url(QStringLiteral("qrc:/App.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) { &app, [url](QObject *obj, const QUrl &objUrl) {

View File

@ -18,7 +18,7 @@ FluWindow {
z:9 z:9
showDark: true showDark: true
width:parent.width width:parent.width
darkText: "Dark Mode" darkText: lang.dark_mode
} }
FluNavigationView{ FluNavigationView{
@ -35,7 +35,7 @@ FluWindow {
anchors.centerIn: parent anchors.centerIn: parent
iconSource: FluentIcons.Search iconSource: FluentIcons.Search
items: ItemsOriginal.getSearchData() items: ItemsOriginal.getSearchData()
placeholderText: "Search" placeholderText: lang.search
onItemClicked: onItemClicked:
(data)=>{ (data)=>{
ItemsOriginal.startPageByItem(data) ItemsOriginal.startPageByItem(data)

View File

@ -71,7 +71,7 @@ void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegist
QString r = pair->property("route").toString(); QString r = pair->property("route").toString();
if(r == route){ if(r == route){
pair->requestActivate(); pair->requestActivate();
delete view; view->deleteLater();
return; return;
} }
} }