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 "lang/En.h"
#include "lang/Zh.h"
AppInfo::AppInfo(QObject *parent)
: QObject{parent}
{
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
#include <QObject>
#include "lang/Lang.h"
#include "stdafx.h"
class AppInfo : public QObject
{
Q_OBJECT
Q_PROPERTY_AUTO(QString,version)
Q_PROPERTY_AUTO(Lang*,lang)
public:
explicit AppInfo(QObject *parent = nullptr);
Q_INVOKABLE void changeLang(const QString& locale);
};
#endif // APPINFO_H

View File

@ -23,12 +23,12 @@ FluScrollablePage{
ColumnLayout{
spacing: 10
anchors{
verticalCenter: parent.verticalCenter
top: parent.top
left: parent.left
}
FluText{
text:"NavigationView Display Mode"
text:lang.navigation_view_display_mode
fontStyle: FluText.BodyStrong
Layout.bottomMargin: 4
}
@ -40,11 +40,49 @@ FluScrollablePage{
selected : MainEvent.displayMode===modelData.mode
text:modelData.title
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
HEADERS += \
lang/En.h \
lang/Lang.h \
lang/Zh.h \
stdafx.h \
ChatController.h \
AppInfo.h
@ -10,6 +13,9 @@ HEADERS += \
SOURCES += \
ChatController.cpp \
AppInfo.cpp \
lang/En.cpp \
lang/Lang.cpp \
lang/Zh.cpp \
main.cpp
RESOURCES += qml.qrc

View File

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

View File

@ -8,7 +8,7 @@ FluObject{
property var navigationView
FluPaneItem{
title:"Home"
title:lang.home
// icon:FluentIcons.Home
cusIcon: Image{
anchors.centerIn: parent
@ -23,7 +23,7 @@ FluObject{
}
FluPaneItemExpander{
title:"Basic input"
title:lang.basic_input
icon:FluentIcons.CheckboxComposite
FluPaneItem{
title:"Buttons"
@ -61,7 +61,7 @@ FluObject{
}
FluPaneItemExpander{
title:"Form"
title:lang.form
icon:FluentIcons.GridView
FluPaneItem{
title:"TextBox"
@ -96,7 +96,7 @@ FluObject{
}
FluPaneItemExpander{
title:"Surface"
title:lang.surface
icon:FluentIcons.SurfaceHub
FluPaneItem{
title:"InfoBar"
@ -152,7 +152,7 @@ FluObject{
}
FluPaneItemExpander{
title:"Popus"
title:lang.popus
icon:FluentIcons.ButtonMenu
FluPaneItem{
title:"Dialog"
@ -175,7 +175,7 @@ FluObject{
}
FluPaneItemExpander{
title:"Navigation"
title:lang.navigation
icon:FluentIcons.AllApps
FluPaneItem{
title:"Pivot"
@ -232,7 +232,7 @@ FluObject{
}
FluPaneItemExpander{
title:"Theming"
title:lang.theming
icon:FluentIcons.Brightness
FluPaneItem{
title:"Theme"
@ -255,7 +255,7 @@ FluObject{
}
FluPaneItemExpander{
title:"Media"
title:lang.media
icon:FluentIcons.Media
FluPaneItem{
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 <QQuickStyle>
#include <QProcess>
#include "lang/Lang.h"
#include "AppInfo.h"
#include "ChatController.h"
@ -17,7 +18,14 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
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"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {

View File

@ -18,7 +18,7 @@ FluWindow {
z:9
showDark: true
width:parent.width
darkText: "Dark Mode"
darkText: lang.dark_mode
}
FluNavigationView{
@ -35,7 +35,7 @@ FluWindow {
anchors.centerIn: parent
iconSource: FluentIcons.Search
items: ItemsOriginal.getSearchData()
placeholderText: "Search"
placeholderText: lang.search
onItemClicked:
(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();
if(r == route){
pair->requestActivate();
delete view;
view->deleteLater();
return;
}
}