RibbonConfig, RibbonSingleton: Added.
|
@ -1 +1 @@
|
||||||
Subproject commit fd7734e79071d0acc1286004dc53db8c9b8c5a1a
|
Subproject commit 489650df0eea78db580c9338406abd4dd9718780
|
|
@ -45,7 +45,7 @@ endif()
|
||||||
add_subdirectory(lib_source)
|
add_subdirectory(lib_source)
|
||||||
|
|
||||||
if (RIBBONUI_BUILD_EXAMPLES)
|
if (RIBBONUI_BUILD_EXAMPLES)
|
||||||
add_subdirectory(example)
|
add_subdirectory(RibbonUIAPP)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message("---------------------------- RibbonUI ----------------------------")
|
message("---------------------------- RibbonUI ----------------------------")
|
||||||
|
|
|
@ -37,7 +37,12 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Quick LinguistTools REQUIRED)
|
||||||
set(ts_files i18n/${PROJECT_NAME}_zh_CN.ts i18n/${PROJECT_NAME}_en_US.ts)
|
set(ts_files i18n/${PROJECT_NAME}_zh_CN.ts i18n/${PROJECT_NAME}_en_US.ts)
|
||||||
|
|
||||||
# Source and QML files
|
# Source and QML files
|
||||||
set(sources_files example.cpp)
|
set(sources_files
|
||||||
|
source/example.cpp
|
||||||
|
)
|
||||||
|
set(module_sources_files
|
||||||
|
include/localization.h source/localization.cpp
|
||||||
|
)
|
||||||
set(qml_files example.qml about.qml SplashScreen.qml
|
set(qml_files example.qml about.qml SplashScreen.qml
|
||||||
components/RibbonMessageListViewExample.qml
|
components/RibbonMessageListViewExample.qml
|
||||||
pages/SettingsMenuPage.qml components/TabBar.qml)
|
pages/SettingsMenuPage.qml components/TabBar.qml)
|
||||||
|
@ -127,6 +132,15 @@ endif()
|
||||||
# Include Qt5 QML plugin for Qt versions less than 6
|
# Include Qt5 QML plugin for Qt versions less than 6
|
||||||
if (${QT_VERSION_MAJOR} LESS 6)
|
if (${QT_VERSION_MAJOR} LESS 6)
|
||||||
include(Qt5QMLPlugin)
|
include(Qt5QMLPlugin)
|
||||||
|
else()
|
||||||
|
# Update QML_IMPORT_PATH (cached variable)
|
||||||
|
if(NOT QML_IMPORT_PATH MATCHES "(^|;)${CMAKE_CURRENT_BINARY_DIR}($|;)")
|
||||||
|
if(QML_IMPORT_PATH)
|
||||||
|
set(QML_IMPORT_PATH "${QML_IMPORT_PATH};${CMAKE_CURRENT_BINARY_DIR}" CACHE STRING "Set for Qt Creator" FORCE)
|
||||||
|
else()
|
||||||
|
set(QML_IMPORT_PATH "${CMAKE_CURRENT_BINARY_DIR}" CACHE STRING "Set for Qt Creator" FORCE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Define the QML module
|
# Define the QML module
|
||||||
|
@ -135,6 +149,7 @@ qt_add_qml_module(${PROJECT_NAME}
|
||||||
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||||
RESOURCE_PREFIX "/qt/qml/"
|
RESOURCE_PREFIX "/qt/qml/"
|
||||||
QML_FILES ${qml_files}
|
QML_FILES ${qml_files}
|
||||||
|
SOURCES ${module_sources_files}
|
||||||
RESOURCES resources/imgs/heart.png resources/imgs/search.png
|
RESOURCES resources/imgs/heart.png resources/imgs/search.png
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -183,4 +198,11 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
|
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR})
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
|
${PROJECT_SOURCE_DIR}
|
||||||
|
${PROJECT_SOURCE_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE QT_QML_DEBUG)
|
||||||
|
endif()
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef LOCALIZATION_H
|
||||||
|
#define LOCALIZATION_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
#include "ribbonlocalization.h"
|
||||||
|
|
||||||
|
class Localization : public RibbonLocalization
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
QML_SINGLETON
|
||||||
|
|
||||||
|
RIBBON_SINGLETON(Localization)
|
||||||
|
public:
|
||||||
|
virtual void loadCurrentLanguage() override;
|
||||||
|
virtual void saveCurrentLanguage(const QString &language)override;
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
public:
|
||||||
|
#else
|
||||||
|
private:
|
||||||
|
#endif
|
||||||
|
Localization() = default;
|
||||||
|
~Localization() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOCALIZATION_H
|
|
@ -1,5 +1,6 @@
|
||||||
import QtQuick 2.15
|
import QtQuick 2.15
|
||||||
import RibbonUI 1.1
|
import RibbonUI 1.1
|
||||||
|
import RibbonUIAPP 1.1
|
||||||
|
|
||||||
RibbonSplashScreen {
|
RibbonSplashScreen {
|
||||||
id: root
|
id: root
|
||||||
|
@ -23,4 +24,9 @@ RibbonSplashScreen {
|
||||||
root.showLoadingLog(qsTr("Loading...Remain %1s...").arg(remainSeconds), {})
|
root.showLoadingLog(qsTr("Loading...Remain %1s...").arg(remainSeconds), {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
RibbonUI.autoLoadLanguage = true
|
||||||
|
RibbonUI.setTranslator(Localization)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.15
|
||||||
import QtQuick.Layouts 1.11
|
import QtQuick.Layouts 1.11
|
||||||
import QtQuick.Window 2.15
|
import QtQuick.Window 2.15
|
||||||
import RibbonUI 1.1
|
import RibbonUI 1.1
|
||||||
|
import RibbonUIAPP 1.1
|
||||||
import "components"
|
import "components"
|
||||||
|
|
||||||
RibbonWindow {
|
RibbonWindow {
|
||||||
|
@ -145,6 +146,7 @@ RibbonWindow {
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
RibbonUI.autoLoadLanguage = true
|
RibbonUI.autoLoadLanguage = true
|
||||||
|
RibbonUI.setTranslator(Localization)
|
||||||
tour.open()
|
tour.open()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Layouts 1.11
|
||||||
import QtQuick.Controls 2.15
|
import QtQuick.Controls 2.15
|
||||||
import QtQuick.Window 2.15
|
import QtQuick.Window 2.15
|
||||||
import RibbonUI 1.1
|
import RibbonUI 1.1
|
||||||
|
import RibbonUIAPP 1.1
|
||||||
|
|
||||||
RibbonBackStagePage{
|
RibbonBackStagePage{
|
||||||
id: page
|
id: page
|
||||||
|
@ -118,23 +119,24 @@ RibbonBackStagePage{
|
||||||
textRole: "text"
|
textRole: "text"
|
||||||
iconSource: RibbonIcons.LocalLanguage
|
iconSource: RibbonIcons.LocalLanguage
|
||||||
Component.onCompleted: update_state()
|
Component.onCompleted: update_state()
|
||||||
onActivated: RibbonLocalization.currentLanguage = model.get(currentIndex).value
|
onActivated: Localization.currentLanguage = model.get(currentIndex).value
|
||||||
Connections{
|
Connections{
|
||||||
target: RibbonLocalization
|
target: Localization
|
||||||
function onCurrentLanguageChanged(){
|
function onCurrentLanguageChanged(){
|
||||||
lang_combo.update_state()
|
lang_combo.update_state()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function update_state(){
|
function update_state(){
|
||||||
model.clear()
|
model.clear()
|
||||||
let langs = RibbonLocalization.languageList()
|
let langs = Localization.languageList()
|
||||||
for(let i = 0; i < langs.length; i++){
|
for(let i = 0; i < langs.length; i++){
|
||||||
model.append({
|
model.append({
|
||||||
text:RibbonLocalization.languageTranslate(langs[i]),
|
text:Localization.languageTranslate(langs[i]),
|
||||||
value:langs[i]
|
value:langs[i]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
currentIndex = find(RibbonLocalization.languageTranslate(RibbonLocalization.currentLanguage))
|
|
||||||
|
currentIndex = find(Localization.languageTranslate(Localization.currentLanguage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import RibbonUI
|
import RibbonUI
|
||||||
|
import RibbonUIAPP
|
||||||
|
|
||||||
RibbonSplashScreen {
|
RibbonSplashScreen {
|
||||||
id: root
|
id: root
|
||||||
|
@ -23,4 +24,9 @@ RibbonSplashScreen {
|
||||||
root.showLoadingLog(qsTr("Loading...Remain %1s...").arg(remainSeconds), {})
|
root.showLoadingLog(qsTr("Loading...Remain %1s...").arg(remainSeconds), {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
RibbonUI.autoLoadLanguage = true
|
||||||
|
RibbonUI.setTranslator(Localization)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import QtQuick.Window
|
import QtQuick.Window
|
||||||
import RibbonUI
|
import RibbonUI
|
||||||
|
import RibbonUIAPP
|
||||||
import "components"
|
import "components"
|
||||||
|
|
||||||
RibbonWindow {
|
RibbonWindow {
|
||||||
|
@ -145,6 +146,7 @@ RibbonWindow {
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
RibbonUI.autoLoadLanguage = true
|
RibbonUI.autoLoadLanguage = true
|
||||||
|
RibbonUI.setTranslator(Localization)
|
||||||
tour.open()
|
tour.open()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Layouts
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Window
|
import QtQuick.Window
|
||||||
import RibbonUI
|
import RibbonUI
|
||||||
|
import RibbonUIAPP
|
||||||
|
|
||||||
RibbonBackStagePage{
|
RibbonBackStagePage{
|
||||||
id: page
|
id: page
|
||||||
|
@ -118,23 +119,24 @@ RibbonBackStagePage{
|
||||||
textRole: "text"
|
textRole: "text"
|
||||||
iconSource: RibbonIcons.LocalLanguage
|
iconSource: RibbonIcons.LocalLanguage
|
||||||
Component.onCompleted: update_state()
|
Component.onCompleted: update_state()
|
||||||
onActivated: RibbonLocalization.currentLanguage = model.get(currentIndex).value
|
onActivated: Localization.currentLanguage = model.get(currentIndex).value
|
||||||
Connections{
|
Connections{
|
||||||
target: RibbonLocalization
|
target: Localization
|
||||||
function onCurrentLanguageChanged(){
|
function onCurrentLanguageChanged(){
|
||||||
lang_combo.update_state()
|
lang_combo.update_state()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function update_state(){
|
function update_state(){
|
||||||
model.clear()
|
model.clear()
|
||||||
let langs = RibbonLocalization.languageList()
|
let langs = Localization.languageList()
|
||||||
for(let i = 0; i < langs.length; i++){
|
for(let i = 0; i < langs.length; i++){
|
||||||
model.append({
|
model.append({
|
||||||
text:RibbonLocalization.languageTranslate(langs[i]),
|
text:Localization.languageTranslate(langs[i]),
|
||||||
value:langs[i]
|
value:langs[i]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
currentIndex = find(RibbonLocalization.languageTranslate(RibbonLocalization.currentLanguage))
|
|
||||||
|
currentIndex = find(Localization.languageTranslate(Localization.currentLanguage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
|
@ -0,0 +1,11 @@
|
||||||
|
#include "localization.h"
|
||||||
|
#include "ribbonconfig.h"
|
||||||
|
|
||||||
|
void Localization::loadCurrentLanguage(){
|
||||||
|
QString language = RibbonConfig::getInstance()->get("Settings", "Current Language").toString();
|
||||||
|
setCurrentLanguage(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Localization::saveCurrentLanguage(const QString &language){
|
||||||
|
RibbonConfig::getInstance()->set("Settings", "Current Language", language);
|
||||||
|
}
|
|
@ -67,7 +67,10 @@ set (source_files
|
||||||
include/definitions.h
|
include/definitions.h
|
||||||
include/ribbontheme.h source/ribbontheme.cpp
|
include/ribbontheme.h source/ribbontheme.cpp
|
||||||
include/platformsupport.h
|
include/platformsupport.h
|
||||||
include/ribbonlocalization.h source/ribbonlocalization.cpp)
|
include/ribbonlocalization.h source/ribbonlocalization.cpp
|
||||||
|
include/ribbonsingleton.h
|
||||||
|
include/ribbonconfig.h source/ribbonconfig.cpp
|
||||||
|
)
|
||||||
|
|
||||||
# Configure version header
|
# Configure version header
|
||||||
set(__ribbonui_project_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
set(__ribbonui_project_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||||
|
@ -171,5 +174,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
${PROJECT_BINARY_DIR}
|
${PROJECT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE QT_QML_DEBUG)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Install QML plugin directory
|
# Install QML plugin directory
|
||||||
install(DIRECTORY ${RIBBONUI_QML_PLUGIN_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/imports)
|
install(DIRECTORY ${RIBBONUI_QML_PLUGIN_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/imports)
|
||||||
|
|
|
@ -1,26 +1,17 @@
|
||||||
#ifndef PLATFORMSUPPORT_H
|
#ifndef PLATFORMSUPPORT_H
|
||||||
#define PLATFORMSUPPORT_H
|
#define PLATFORMSUPPORT_H
|
||||||
#include <QQuickItem>
|
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QMutex>
|
#include "ribbonsingleton.h"
|
||||||
|
|
||||||
class PlatformSupport : public QObject
|
class PlatformSupport : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
QML_SINGLETON
|
QML_SINGLETON
|
||||||
public:
|
|
||||||
static PlatformSupport* create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return instance();}
|
|
||||||
static PlatformSupport* instance(){
|
|
||||||
static QMutex mutex;
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
|
|
||||||
static PlatformSupport *singleton = nullptr;
|
RIBBON_SINGLETON(PlatformSupport)
|
||||||
if (!singleton) {
|
public:
|
||||||
singleton = new PlatformSupport();
|
|
||||||
}
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
Q_INVOKABLE void showSystemTitleBtns(QWindow *window, bool enable);
|
Q_INVOKABLE void showSystemTitleBtns(QWindow *window, bool enable);
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,9 +19,9 @@ public:
|
||||||
public:
|
public:
|
||||||
#else
|
#else
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY_MOVE(PlatformSupport)
|
|
||||||
#endif
|
#endif
|
||||||
PlatformSupport(QObject *parent = nullptr) : QObject(parent){}
|
PlatformSupport(QObject *parent = nullptr) : QObject(parent){}
|
||||||
|
private:
|
||||||
|
bool bindEngine(){return bindEngineBegin();};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLATFORMSUPPORT_H
|
#endif // PLATFORMSUPPORT_H
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef RIBBONCONFIG_H
|
||||||
|
#define RIBBONCONFIG_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QSettings>
|
||||||
|
#include "ribbonsingleton.h"
|
||||||
|
|
||||||
|
class RibbonConfig : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
QML_SINGLETON
|
||||||
|
|
||||||
|
RIBBON_SINGLETON(RibbonConfig)
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE void set(QString qstrnodename,QString qstrkeyname,QVariant qvarvalue);
|
||||||
|
Q_INVOKABLE void setArray(QString qstrnodename,QString qstrkeyname,QVariant qvarvalue);
|
||||||
|
Q_INVOKABLE QVariant get(QString qstrnodename,QString qstrkeyname);
|
||||||
|
Q_INVOKABLE QVariant getArray(QString qstrnodename,QString qstrkeyname);
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
public:
|
||||||
|
#else
|
||||||
|
private:
|
||||||
|
#endif
|
||||||
|
explicit RibbonConfig(QString qstrfilename = "");
|
||||||
|
~RibbonConfig() override;
|
||||||
|
protected:
|
||||||
|
virtual bool bindEngine(){return bindEngineBegin();};
|
||||||
|
QString qstrFileName;
|
||||||
|
QSettings *setting=nullptr;
|
||||||
|
QMutex mutex;
|
||||||
|
};
|
||||||
|
#endif // RIBBONCONFIG_H
|
||||||
|
|
|
@ -1,41 +1,42 @@
|
||||||
#ifndef RIBBONLOCALIZATION_H
|
#ifndef RIBBONLOCALIZATION_H
|
||||||
#define RIBBONLOCALIZATION_H
|
#define RIBBONLOCALIZATION_H
|
||||||
|
|
||||||
#include <QQuickItem>
|
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
#include "ribbonsingleton.h"
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
class RibbonLocalization : public QQuickItem
|
class RibbonLocalization : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
QML_SINGLETON
|
QML_SINGLETON
|
||||||
Q_PROPERTY(QString currentLanguage READ currentLanguage WRITE setCurrentLanguage NOTIFY currentLanguageChanged FINAL)
|
Q_PROPERTY(QString currentLanguage READ currentLanguage WRITE setCurrentLanguage NOTIFY currentLanguageChanged FINAL)
|
||||||
|
Q_PROPERTY_RW(bool, enabled);
|
||||||
|
RIBBON_SINGLETON(RibbonLocalization)
|
||||||
public:
|
public:
|
||||||
typedef QPair<QString, QString> LangItem; // example: <"zh_CN", "qrc://i18n/xxx_zh_CN.qm">
|
typedef QPair<QString, QString> LangItem; // example: <"zh_CN", "qrc://i18n/xxx_zh_CN.qm">
|
||||||
typedef QMap<QString, QSharedPointer<QTranslator>> Translator; // example: <"main", mainTranslator>
|
typedef QMap<QString, QSharedPointer<QTranslator>> Translator; // example: <"main", mainTranslator>
|
||||||
typedef QMap<LangItem, QString> ModuleTranslator; // example: <zhItem, "main">
|
typedef QMap<LangItem, QString> ModuleTranslator; // example: <zhItem, "main">
|
||||||
static RibbonLocalization* create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return instance();}
|
|
||||||
static RibbonLocalization* instance();
|
|
||||||
Q_INVOKABLE bool registerLanguage(QString langName, QString path, QString moduleName);
|
Q_INVOKABLE bool registerLanguage(QString langName, QString path, QString moduleName);
|
||||||
Q_INVOKABLE bool removeLanguage(QString langName, QString path);
|
Q_INVOKABLE bool removeLanguage(QString langName, QString path);
|
||||||
Q_INVOKABLE void bindEngine();
|
|
||||||
Q_INVOKABLE QList<QString> languageList();
|
Q_INVOKABLE QList<QString> languageList();
|
||||||
Q_INVOKABLE QString languageTranslate(QString langStr);
|
Q_INVOKABLE QString languageTranslate(QString langStr);
|
||||||
QString currentLanguage();
|
QString currentLanguage();
|
||||||
bool setCurrentLanguage(QString langName);
|
bool setCurrentLanguage(QString langName);
|
||||||
// Use if you need to directly save/load language from config files
|
// Use if you need to directly save/load language from config files
|
||||||
Q_INVOKABLE virtual void loadCurrentLanguage(){};
|
virtual void loadCurrentLanguage(){};
|
||||||
virtual bool saveCurrentLanguage(const QString &language){return false;};
|
virtual void saveCurrentLanguage(const QString &language){};
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
public:
|
public:
|
||||||
#else
|
#else
|
||||||
private:
|
protected:
|
||||||
Q_DISABLE_COPY_MOVE(RibbonLocalization)
|
|
||||||
#endif
|
#endif
|
||||||
RibbonLocalization();
|
RibbonLocalization();
|
||||||
~RibbonLocalization();
|
virtual ~RibbonLocalization() override;
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool bindEngine();
|
||||||
|
virtual void switchState();
|
||||||
ModuleTranslator moduleLangList;
|
ModuleTranslator moduleLangList;
|
||||||
Translator transList;
|
Translator transList;
|
||||||
QString _currentLang;
|
QString _currentLang;
|
||||||
|
@ -47,6 +48,6 @@ protected:
|
||||||
};
|
};
|
||||||
signals:
|
signals:
|
||||||
void currentLanguageChanged();
|
void currentLanguageChanged();
|
||||||
|
void registerLanguageFinished();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RIBBONLOCALIZATION_H
|
#endif // RIBBONLOCALIZATION_H
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
#ifndef RIBBONSINGLETON_H
|
||||||
|
#define RIBBONSINGLETON_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QTimer>
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
#include "ribbonui_version.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
#define RIBBON_SINGLETON(X) \
|
||||||
|
public: \
|
||||||
|
static X* create (QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();} \
|
||||||
|
static X* getInstance(){ \
|
||||||
|
static QMutex mutex; \
|
||||||
|
QMutexLocker locker(&mutex); \
|
||||||
|
static X *singleton = nullptr; \
|
||||||
|
if (!singleton || needRefresh) { \
|
||||||
|
needRefresh() = false; \
|
||||||
|
if(getTypeId() == -1 || !getEngine()) \
|
||||||
|
singleton = new X(); \
|
||||||
|
else \
|
||||||
|
singleton = getEngine()->singletonInstance<X *>(getTypeId()); \
|
||||||
|
} \
|
||||||
|
return singleton; \
|
||||||
|
}; \
|
||||||
|
static void destroy(){ \
|
||||||
|
needRefresh() = true; \
|
||||||
|
X::getInstance()->~X(); \
|
||||||
|
}; \
|
||||||
|
protected: \
|
||||||
|
static int getTypeId(){ \
|
||||||
|
static int typeId = -1; \
|
||||||
|
if(typeId == -1){ \
|
||||||
|
QString version(RIBBONUI_VERSION); \
|
||||||
|
QStringList versionList = version.split('.'); \
|
||||||
|
typeId = qmlTypeId("RibbonUI", versionList[0].toInt(), \
|
||||||
|
versionList[1].toInt(), staticMetaObject.className()); \
|
||||||
|
} \
|
||||||
|
return typeId; \
|
||||||
|
}; \
|
||||||
|
static QQmlApplicationEngine*& getEngine(){ \
|
||||||
|
static QQmlApplicationEngine* engine = nullptr; \
|
||||||
|
return engine; \
|
||||||
|
} \
|
||||||
|
static bool& needRefresh(){ \
|
||||||
|
static bool need = false; \
|
||||||
|
return need; \
|
||||||
|
} \
|
||||||
|
bool bindEngineBegin(){ \
|
||||||
|
QQmlApplicationEngine* &engine = getEngine(); \
|
||||||
|
engine = dynamic_cast<QQmlApplicationEngine*>(qmlEngine(this)); \
|
||||||
|
if (!engine){ \
|
||||||
|
dynamic_cast<X*>(this)->~X(); \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
return true; \
|
||||||
|
}; \
|
||||||
|
void initialBind(){ \
|
||||||
|
QTimer::singleShot(1, this, &X::bindEngine); \
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
#define RIBBON_SINGLETON(X) \
|
||||||
|
public: \
|
||||||
|
static X* create (QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();} \
|
||||||
|
static X* getInstance(){ \
|
||||||
|
static QMutex mutex; \
|
||||||
|
QMutexLocker locker(&mutex); \
|
||||||
|
static X *singleton = nullptr; \
|
||||||
|
if (!singleton) { \
|
||||||
|
singleton = new X(); \
|
||||||
|
} \
|
||||||
|
return singleton; \
|
||||||
|
}; \
|
||||||
|
static void destroy(){ \
|
||||||
|
X::getInstance()->~X(); \
|
||||||
|
}; \
|
||||||
|
protected: \
|
||||||
|
bool bindEngineBegin(){ \
|
||||||
|
QQmlApplicationEngine *engine = dynamic_cast<QQmlApplicationEngine*>(qmlEngine(this)); \
|
||||||
|
if (!engine){ \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
return true; \
|
||||||
|
}; \
|
||||||
|
void initialBind(){QTimer::singleShot(1000, this, &X::bindEngine);}; \
|
||||||
|
private: \
|
||||||
|
Q_DISABLE_COPY_MOVE(X)
|
||||||
|
#endif
|
||||||
|
#endif // RIBBONSINGLETON_H
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef RIBBONTHEME_H
|
#ifndef RIBBONTHEME_H
|
||||||
#define RIBBONTHEME_H
|
#define RIBBONTHEME_H
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include "ribbonsingleton.h"
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
|
|
||||||
class RibbonTheme : public QQuickItem
|
class RibbonTheme : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
@ -14,21 +14,21 @@ class RibbonTheme : public QQuickItem
|
||||||
Q_PROPERTY_RW(RibbonThemeType::ThemeMode,themeMode)
|
Q_PROPERTY_RW(RibbonThemeType::ThemeMode,themeMode)
|
||||||
Q_PROPERTY_RW(bool,modernStyle)
|
Q_PROPERTY_RW(bool,modernStyle)
|
||||||
Q_PROPERTY_RW(bool,nativeText)
|
Q_PROPERTY_RW(bool,nativeText)
|
||||||
|
|
||||||
|
RIBBON_SINGLETON(RibbonTheme)
|
||||||
public:
|
public:
|
||||||
static RibbonTheme* create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return instance();}
|
|
||||||
static RibbonTheme* instance();
|
|
||||||
Q_SIGNAL void isDarkModeChanged();
|
Q_SIGNAL void isDarkModeChanged();
|
||||||
bool isDarkMode();
|
bool isDarkMode();
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
public:
|
public:
|
||||||
#else
|
#else
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY_MOVE(RibbonTheme)
|
|
||||||
#endif
|
#endif
|
||||||
RibbonTheme();
|
RibbonTheme();
|
||||||
|
private:
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
bool bindEngine(){return bindEngineBegin();};
|
||||||
RibbonThemeType::ThemeMode currentTheme();
|
RibbonThemeType::ThemeMode currentTheme();
|
||||||
RibbonThemeType::ThemeMode _system_themeMode;
|
RibbonThemeType::ThemeMode _system_themeMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RIBBONTHEME_H
|
#endif // RIBBONTHEME_H
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef RIBBONUI_H
|
#ifndef RIBBONUI_H
|
||||||
#define RIBBONUI_H
|
#define RIBBONUI_H
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include "ribbonsingleton.h"
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "ribbonlocalization.h"
|
#include "ribbonlocalization.h"
|
||||||
|
|
||||||
class RibbonUI : public QQuickItem
|
class RibbonUI : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
@ -16,12 +16,12 @@ class RibbonUI : public QQuickItem
|
||||||
Q_PROPERTY_R(int, isWin11)
|
Q_PROPERTY_R(int, isWin11)
|
||||||
Q_PROPERTY_RW(QVariantMap, windowsSet)
|
Q_PROPERTY_RW(QVariantMap, windowsSet)
|
||||||
Q_PROPERTY(bool autoLoadLanguage READ autoLoadLanguage WRITE setAutoLoadLanguage NOTIFY autoLoadLanguageChanged FINAL)
|
Q_PROPERTY(bool autoLoadLanguage READ autoLoadLanguage WRITE setAutoLoadLanguage NOTIFY autoLoadLanguageChanged FINAL)
|
||||||
|
|
||||||
|
RIBBON_SINGLETON(RibbonUI)
|
||||||
public:
|
public:
|
||||||
static RibbonUI* instance();
|
|
||||||
static RibbonUI* create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return instance();}
|
|
||||||
RIBBONUI_API static void init();
|
RIBBONUI_API static void init();
|
||||||
RIBBONUI_API static void registerTypes(const char *uri);
|
RIBBONUI_API static void registerTypes(const char *uri);
|
||||||
RIBBONUI_API Q_INVOKABLE void setTranslator(RibbonLocalization *translator = RibbonLocalization::instance());
|
RIBBONUI_API Q_INVOKABLE void setTranslator(RibbonLocalization *translator = RibbonLocalization::getInstance());
|
||||||
Q_INVOKABLE void initTranslator();
|
Q_INVOKABLE void initTranslator();
|
||||||
bool autoLoadLanguage(){return _autoLoadLanguage;};
|
bool autoLoadLanguage(){return _autoLoadLanguage;};
|
||||||
void setAutoLoadLanguage(bool value);
|
void setAutoLoadLanguage(bool value);
|
||||||
|
@ -31,15 +31,16 @@ public:
|
||||||
public:
|
public:
|
||||||
#else
|
#else
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY_MOVE(RibbonUI)
|
|
||||||
#endif
|
#endif
|
||||||
explicit RibbonUI(QQuickItem *parent = nullptr);
|
explicit RibbonUI(QObject *parent = nullptr);
|
||||||
private:
|
private:
|
||||||
RibbonLocalization* _translator;
|
bool bindEngine(){return bindEngineBegin();};
|
||||||
|
RibbonLocalization* _translator = nullptr;
|
||||||
bool _autoLoadLanguage = false;
|
bool _autoLoadLanguage = false;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void autoLoadLanguageChanged();
|
void autoLoadLanguageChanged();
|
||||||
|
void initTranslatorFinished();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RIBBONUI_H
|
#endif // RIBBONUI_H
|
||||||
|
|
|
@ -70,9 +70,7 @@ Window {
|
||||||
{
|
{
|
||||||
windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.isDarkMode ? "dark" : "light" : "none")
|
windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.isDarkMode ? "dark" : "light" : "none")
|
||||||
}
|
}
|
||||||
RibbonLocalization.bindEngine();
|
|
||||||
RibbonUI.setTranslator(RibbonLocalization)
|
RibbonUI.setTranslator(RibbonLocalization)
|
||||||
|
|
||||||
window.visible = true
|
window.visible = true
|
||||||
windowAgent.centralize()
|
windowAgent.centralize()
|
||||||
raise()
|
raise()
|
||||||
|
|
|
@ -70,9 +70,7 @@ Window {
|
||||||
{
|
{
|
||||||
windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.isDarkMode ? "dark" : "light" : "none")
|
windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.isDarkMode ? "dark" : "light" : "none")
|
||||||
}
|
}
|
||||||
RibbonLocalization.bindEngine();
|
|
||||||
RibbonUI.setTranslator(RibbonLocalization)
|
RibbonUI.setTranslator(RibbonLocalization)
|
||||||
|
|
||||||
window.visible = true
|
window.visible = true
|
||||||
windowAgent.centralize()
|
windowAgent.centralize()
|
||||||
raise()
|
raise()
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
#include "ribbonconfig.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
RibbonConfig::RibbonConfig(QString qstrfilename):
|
||||||
|
QObject(nullptr)
|
||||||
|
{
|
||||||
|
if (qstrfilename.isEmpty())
|
||||||
|
{
|
||||||
|
qstrFileName = QCoreApplication::applicationDirPath() + "/config.ini";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qstrFileName = qstrfilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
setting = new QSettings(qstrFileName, QSettings::IniFormat);
|
||||||
|
initialBind();
|
||||||
|
}
|
||||||
|
|
||||||
|
RibbonConfig::~RibbonConfig()
|
||||||
|
{
|
||||||
|
delete setting;
|
||||||
|
setting = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RibbonConfig::set(QString qstrnodename,QString qstrkeyname,QVariant qvarvalue)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex);
|
||||||
|
setting->setValue(QString("/%1/%2").arg(qstrnodename, qstrkeyname), qvarvalue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RibbonConfig::setArray(QString qstrnodename,QString qstrkeyname,QVariant qvarvalue)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex);
|
||||||
|
setting->beginWriteArray(QString("/%1/%2").arg(qstrnodename, qstrkeyname));
|
||||||
|
QList<QVariant> list = qvarvalue.toList();
|
||||||
|
for (int i = 0; i< list.length(); i++)
|
||||||
|
{
|
||||||
|
setting->setArrayIndex(i);
|
||||||
|
setting->setValue(qstrkeyname, list.at(i));
|
||||||
|
}
|
||||||
|
setting->endArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant RibbonConfig::get(QString qstrnodename,QString qstrkeyname)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex);
|
||||||
|
QVariant qvar = setting->value(QString("/%1/%2").arg(qstrnodename, qstrkeyname));
|
||||||
|
return qvar;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant RibbonConfig::getArray(QString qstrnodename,QString qstrkeyname)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex);
|
||||||
|
QList<QVariant> list;
|
||||||
|
int size = setting->beginReadArray(QString("/%1/%2").arg(qstrnodename, qstrkeyname));
|
||||||
|
for (int i = 0; i< size; i++)
|
||||||
|
{
|
||||||
|
setting->setArrayIndex(i);
|
||||||
|
list.append(setting->value(qstrkeyname));
|
||||||
|
}
|
||||||
|
setting->endArray();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RibbonConfig::clear()
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex);
|
||||||
|
setting->clear();
|
||||||
|
}
|
|
@ -1,28 +1,20 @@
|
||||||
#include "ribbonlocalization.h"
|
#include "ribbonlocalization.h"
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QTimer>
|
||||||
|
|
||||||
RibbonLocalization::RibbonLocalization() {
|
RibbonLocalization::RibbonLocalization(){
|
||||||
_currentLang = "en_US";
|
_currentLang = "en_US";
|
||||||
|
_enabled = true;
|
||||||
|
initialBind();
|
||||||
|
connect(this, &RibbonLocalization::enabledChanged, this, &RibbonLocalization::switchState);
|
||||||
}
|
}
|
||||||
|
|
||||||
RibbonLocalization::~RibbonLocalization() {
|
RibbonLocalization::~RibbonLocalization() {
|
||||||
for (auto item : transList)
|
for (auto item : std::as_const(transList))
|
||||||
item.clear();
|
item.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
RibbonLocalization* RibbonLocalization::instance(){
|
|
||||||
static QMutex mutex;
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
|
|
||||||
static RibbonLocalization *singleton = nullptr;
|
|
||||||
if (!singleton) {
|
|
||||||
singleton = new RibbonLocalization();
|
|
||||||
}
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RibbonLocalization::registerLanguage(QString langName, QString path, QString moduleName){
|
bool RibbonLocalization::registerLanguage(QString langName, QString path, QString moduleName){
|
||||||
LangItem temp(langName, path);
|
LangItem temp(langName, path);
|
||||||
if(!moduleLangList.contains(temp)){
|
if(!moduleLangList.contains(temp)){
|
||||||
|
@ -34,8 +26,10 @@ bool RibbonLocalization::registerLanguage(QString langName, QString path, QStrin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moduleLangList.insert(temp, moduleName);
|
moduleLangList.insert(temp, moduleName);
|
||||||
|
emit registerLanguageFinished();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
emit registerLanguageFinished();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +56,13 @@ QString RibbonLocalization::currentLanguage(){
|
||||||
bool RibbonLocalization::setCurrentLanguage(QString langName){
|
bool RibbonLocalization::setCurrentLanguage(QString langName){
|
||||||
bool hasChanged = false;
|
bool hasChanged = false;
|
||||||
QMap<QString, bool> isNeeded;
|
QMap<QString, bool> isNeeded;
|
||||||
for(auto langItem : moduleLangList.keys()){
|
auto keys = moduleLangList.keys();
|
||||||
|
for(auto &langItem : keys){
|
||||||
if(langItem.first == langName){
|
if(langItem.first == langName){
|
||||||
isNeeded[moduleLangList[langItem]] = true;
|
isNeeded[moduleLangList[langItem]] = true;
|
||||||
Q_UNUSED(transList[moduleLangList[langItem]].get()->load(langItem.second));
|
Q_UNUSED(transList[moduleLangList[langItem]].get()->load(langItem.second));
|
||||||
_currentLang = langName;
|
_currentLang = langName;
|
||||||
qApp->installTranslator(transList[moduleLangList[langItem]].get());;
|
qApp->installTranslator(transList[moduleLangList[langItem]].get());
|
||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -83,23 +78,31 @@ bool RibbonLocalization::setCurrentLanguage(QString langName){
|
||||||
return hasChanged;
|
return hasChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RibbonLocalization::bindEngine(){
|
bool RibbonLocalization::bindEngine(){
|
||||||
QQmlApplicationEngine * engine = dynamic_cast<QQmlApplicationEngine*>(qmlEngine(this));
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
Q_ASSERT(engine);
|
QQmlApplicationEngine* &engine = getEngine();
|
||||||
if (!engine)
|
engine = dynamic_cast<QQmlApplicationEngine*>(qmlEngine(this));
|
||||||
return;
|
#else
|
||||||
QObject::connect(this, &RibbonLocalization::currentLanguageChanged, engine, [engine]() -> void {
|
QQmlApplicationEngine *engine = dynamic_cast<QQmlApplicationEngine*>(qmlEngine(this));
|
||||||
engine->retranslate();
|
#endif
|
||||||
});
|
if(bindEngineBegin()){
|
||||||
|
QObject::connect(this, &RibbonLocalization::currentLanguageChanged, engine, [engine]() -> void {
|
||||||
|
engine->retranslate();
|
||||||
|
});
|
||||||
|
loadCurrentLanguage();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> RibbonLocalization::languageList(){
|
QList<QString> RibbonLocalization::languageList(){
|
||||||
QList<QString> list;
|
QList<QString> list;
|
||||||
QSet<QString> set;
|
QSet<QString> set;
|
||||||
for(auto langItem : moduleLangList.keys()){
|
auto keys = moduleLangList.keys();
|
||||||
|
for(auto &langItem : keys){
|
||||||
set.insert(langItem.first);
|
set.insert(langItem.first);
|
||||||
}
|
}
|
||||||
for(auto setItem : set){
|
for(auto &setItem : set){
|
||||||
list.append(setItem);
|
list.append(setItem);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
@ -112,3 +115,17 @@ QString RibbonLocalization::languageTranslate(QString langStr){
|
||||||
else
|
else
|
||||||
return tr("Not Found");
|
return tr("Not Found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RibbonLocalization::switchState(){
|
||||||
|
if(_enabled){
|
||||||
|
setCurrentLanguage(_currentLang);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
auto keys = moduleLangList.keys();
|
||||||
|
for(auto &langItem : keys){
|
||||||
|
if(langItem.first == _currentLang){
|
||||||
|
qApp->removeTranslator(transList[moduleLangList[langItem]].get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,17 +21,7 @@ RibbonTheme::RibbonTheme()
|
||||||
modernStyle(false);
|
modernStyle(false);
|
||||||
nativeText(true);
|
nativeText(true);
|
||||||
qApp->installEventFilter(this);
|
qApp->installEventFilter(this);
|
||||||
}
|
initialBind();
|
||||||
|
|
||||||
RibbonTheme* RibbonTheme::instance(){
|
|
||||||
static QMutex mutex;
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
|
|
||||||
static RibbonTheme *singleton = nullptr;
|
|
||||||
if (!singleton) {
|
|
||||||
singleton = new RibbonTheme();
|
|
||||||
}
|
|
||||||
return singleton;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RibbonTheme::eventFilter(QObject *obj, QEvent *event)
|
bool RibbonTheme::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
|
|
@ -7,24 +7,14 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include "ribbonui_version.h"
|
#include "ribbonui_version.h"
|
||||||
|
|
||||||
RibbonUI::RibbonUI(QQuickItem *parent)
|
RibbonUI::RibbonUI(QObject *parent)
|
||||||
: QQuickItem(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
_version = RIBBONUI_VERSION;
|
_version = RIBBONUI_VERSION;
|
||||||
_qtVersion = QString(qVersion()).replace('.',"").toInt();
|
_qtVersion = QString(qVersion()).replace('.',"").toInt();
|
||||||
_isWin11 = QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 22000);
|
_isWin11 = QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 22000);
|
||||||
_translator = RibbonLocalization::instance();
|
_translator = RibbonLocalization::getInstance();
|
||||||
}
|
initialBind();
|
||||||
|
|
||||||
RibbonUI* RibbonUI::instance(){
|
|
||||||
static QMutex mutex;
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
|
|
||||||
static RibbonUI *singleton = nullptr;
|
|
||||||
if (!singleton) {
|
|
||||||
singleton = new RibbonUI();
|
|
||||||
}
|
|
||||||
return singleton;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RibbonUI::init()
|
void RibbonUI::init()
|
||||||
|
@ -49,7 +39,9 @@ void RibbonUI::registerTypes(const char *uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
void RibbonUI::setTranslator(RibbonLocalization *translator){
|
void RibbonUI::setTranslator(RibbonLocalization *translator){
|
||||||
|
_translator->enabled(false);
|
||||||
_translator = translator;
|
_translator = translator;
|
||||||
|
_translator->enabled(true);
|
||||||
initTranslator();
|
initTranslator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +51,7 @@ void RibbonUI::initTranslator(){
|
||||||
filters<<"*.qm";
|
filters<<"*.qm";
|
||||||
dir.setNameFilters(filters);
|
dir.setNameFilters(filters);
|
||||||
QStringList matchedFiles = dir.entryList();
|
QStringList matchedFiles = dir.entryList();
|
||||||
for(auto file : matchedFiles){
|
for(auto &file : std::as_const(matchedFiles)){
|
||||||
QString project, lang;
|
QString project, lang;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end = file.indexOf('_');
|
int end = file.indexOf('_');
|
||||||
|
@ -79,6 +71,7 @@ void RibbonUI::initTranslator(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
emit initTranslatorFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RibbonUI::setAutoLoadLanguage(bool value){
|
void RibbonUI::setAutoLoadLanguage(bool value){
|
||||||
|
|