mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-07-04 09:05:30 +08:00
update
This commit is contained in:
28
example/src/helper/InitalizrHelper.cpp
Normal file
28
example/src/helper/InitalizrHelper.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "InitalizrHelper.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
InitalizrHelper::InitalizrHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
InitalizrHelper::~InitalizrHelper() = default;
|
||||
|
||||
|
||||
void InitalizrHelper::generate(const QString& name,const QString& path){
|
||||
if(name.isEmpty()){
|
||||
error(tr("The name cannot be empty"));
|
||||
return;
|
||||
}
|
||||
if(path.isEmpty()){
|
||||
error(tr("The creation path cannot be empty"));
|
||||
return;
|
||||
}
|
||||
QDir projectDir(path);
|
||||
if(!projectDir.exists()){
|
||||
error(tr("The path does not exist"));
|
||||
return;
|
||||
}
|
||||
return success();
|
||||
}
|
21
example/src/helper/InitalizrHelper.h
Normal file
21
example/src/helper/InitalizrHelper.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef INITALIZRHELPER_H
|
||||
#define INITALIZRHELPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
#include "src/singleton.h"
|
||||
|
||||
class InitalizrHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
explicit InitalizrHelper(QObject* parent = nullptr);
|
||||
public:
|
||||
SINGLETON(InitalizrHelper)
|
||||
~InitalizrHelper() override;
|
||||
Q_INVOKABLE void generate(const QString& name,const QString& path);
|
||||
Q_SIGNAL void error(const QString& message);
|
||||
Q_SIGNAL void success();
|
||||
};
|
||||
|
||||
#endif // INITALIZRHELPER_H
|
@ -168,7 +168,7 @@ static inline void messageHandler(const QtMsgType type, const QMessageLogContext
|
||||
}
|
||||
}
|
||||
|
||||
void Log::setup(const QString &app,int level)
|
||||
void Log::setup(char *argv[],const QString &app,int level)
|
||||
{
|
||||
Q_ASSERT(!app.isEmpty());
|
||||
if (app.isEmpty()) {
|
||||
@ -179,6 +179,7 @@ void Log::setup(const QString &app,int level)
|
||||
if (once) {
|
||||
return;
|
||||
}
|
||||
QString applicationPath = QString::fromStdString(argv[0]);
|
||||
once = true;
|
||||
g_app = app;
|
||||
const QString logFileName = QString("%1_%2.log").arg(g_app,QDateTime::currentDateTime().toString("yyyyMMdd"));
|
||||
@ -192,6 +193,7 @@ void Log::setup(const QString &app,int level)
|
||||
qInfo()<<"===================================================";
|
||||
qInfo()<<"[AppName]"<<g_app;
|
||||
qInfo()<<"[AppVersion]"<<APPLICATION_VERSION;
|
||||
qInfo()<<"[AppPath]"<<applicationPath;
|
||||
qInfo()<<"[QtVersion]"<<QT_VERSION_STR;
|
||||
#ifdef WIN32
|
||||
qInfo()<<"[ProcessId]"<<QString::number(_getpid());
|
||||
|
@ -5,7 +5,7 @@
|
||||
namespace Log
|
||||
{
|
||||
QString prettyProductInfoWrapper();
|
||||
void setup(const QString &app,int level = 4);
|
||||
void setup(char *argv[], const QString &app,int level = 4);
|
||||
}
|
||||
|
||||
#endif // LOG_H
|
||||
|
@ -24,7 +24,7 @@ QVariant SettingsHelper::get(const QString& key,QVariant def){
|
||||
}
|
||||
|
||||
void SettingsHelper::init(char *argv[]){
|
||||
auto applicationPath = QString::fromStdString(argv[0]);
|
||||
QString applicationPath = QString::fromStdString(argv[0]);
|
||||
const QFileInfo fileInfo(applicationPath);
|
||||
const QString iniFileName = fileInfo.completeBaseName() + ".ini";
|
||||
const QString iniFilePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + iniFileName;
|
||||
|
@ -23,6 +23,8 @@ public:
|
||||
Q_INVOKABLE int getDarkMode(){return get("darkMode",QVariant(0)).toInt();}
|
||||
Q_INVOKABLE void saveUseSystemAppBar(bool useSystemAppBar){save("useSystemAppBar",useSystemAppBar);}
|
||||
Q_INVOKABLE bool getUseSystemAppBar(){return get("useSystemAppBar",QVariant(false)).toBool();}
|
||||
Q_INVOKABLE void saveLanguage(QString language){save("language",language);}
|
||||
Q_INVOKABLE QString getLanguage(){return get("language",QVariant("en")).toString();}
|
||||
private:
|
||||
void save(const QString& key,QVariant val);
|
||||
QVariant get(const QString& key,QVariant def={});
|
||||
|
27
example/src/helper/TranslateHelper.cpp
Normal file
27
example/src/helper/TranslateHelper.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "TranslateHelper.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "SettingsHelper.h"
|
||||
|
||||
TranslateHelper::TranslateHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
_languages<<"en";
|
||||
_languages<<"zh";
|
||||
_current = SettingsHelper::getInstance()->getLanguage();
|
||||
}
|
||||
|
||||
TranslateHelper::~TranslateHelper() = default;
|
||||
|
||||
void TranslateHelper::init(QQmlEngine* engine){
|
||||
_engine = engine;
|
||||
_translator = new QTranslator(this);
|
||||
qApp->installTranslator(_translator);
|
||||
QString translatorPath = QGuiApplication::applicationDirPath()+"/i18n";
|
||||
#ifdef Q_OS_MACX
|
||||
translatorPath.append("/../Resources/");
|
||||
#endif
|
||||
_translator->load(QString::fromStdString("%1/example_%2.qm").arg(translatorPath,_current));
|
||||
_engine->retranslate();
|
||||
}
|
26
example/src/helper/TranslateHelper.h
Normal file
26
example/src/helper/TranslateHelper.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef TRANSLATEHELPER_H
|
||||
#define TRANSLATEHELPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QTranslator>
|
||||
#include "src/singleton.h"
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class TranslateHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString,current)
|
||||
Q_PROPERTY_READONLY_AUTO(QStringList,languages)
|
||||
private:
|
||||
explicit TranslateHelper(QObject* parent = nullptr);
|
||||
public:
|
||||
SINGLETON(TranslateHelper)
|
||||
~TranslateHelper() override;
|
||||
void init(QQmlEngine* engine);
|
||||
private:
|
||||
QQmlEngine* _engine = nullptr;
|
||||
QTranslator* _translator = nullptr;
|
||||
};
|
||||
|
||||
#endif // TRANSLATEHELPER_H
|
@ -15,6 +15,8 @@
|
||||
#include "src/component/FileWatcher.h"
|
||||
#include "src/component/FpsItem.h"
|
||||
#include "src/helper/SettingsHelper.h"
|
||||
#include "src/helper/InitalizrHelper.h"
|
||||
#include "src/helper/TranslateHelper.h"
|
||||
|
||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 0))
|
||||
@ -50,7 +52,7 @@ int main(int argc, char *argv[])
|
||||
QGuiApplication::setApplicationDisplayName("FluentUI Exmaple");
|
||||
QGuiApplication::setApplicationVersion(APPLICATION_VERSION);
|
||||
SettingsHelper::getInstance()->init(argv);
|
||||
Log::setup("example");
|
||||
Log::setup(argv,"example");
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
|
||||
#endif
|
||||
@ -63,8 +65,11 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
QGuiApplication app(argc, argv);
|
||||
QQmlApplicationEngine engine;
|
||||
TranslateHelper::getInstance()->init(&engine);
|
||||
engine.rootContext()->setContextProperty("AppInfo",AppInfo::getInstance());
|
||||
engine.rootContext()->setContextProperty("SettingsHelper",SettingsHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("InitalizrHelper",InitalizrHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("TranslateHelper",TranslateHelper::getInstance());
|
||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||
FluentUI::getInstance()->registerTypes(&engine);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user