This commit is contained in:
zhuzihcu 2023-05-25 17:00:48 +08:00
parent a123dfbccf
commit 0dbbba56da
10 changed files with 136 additions and 116 deletions

View File

@ -18,6 +18,10 @@ FluWindow {
launchMode: FluWindow.SingleTask launchMode: FluWindow.SingleTask
visible: true visible: true
Component.onCompleted: {
// FluApp.init(window)
}
FluNavigationView2{ FluNavigationView2{
id:nav_view id:nav_view
anchors.fill: parent anchors.fill: parent

View File

@ -24,6 +24,11 @@ FluExpander{
color:FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1) color:FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1)
border.color: FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,229/255,234/255,1) border.color: FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,229/255,234/255,1)
border.width: 1 border.width: 1
Behavior on color{
ColorAnimation {
duration: 300
}
}
} }
} }
@ -42,91 +47,91 @@ FluExpander{
} }
function htmlEncode(e){ function htmlEncode(e){
var i,s; var i,s;
for(i in s={ for(i in s={
"&":/&/g,//""//":/"/g,"'":/'/g, "&":/&/g,//""//":/"/g,"'":/'/g,
"<":/</g,">":/>/g,"<br/>":/\n/g, "<":/</g,">":/>/g,"<br/>":/\n/g,
" ":/ /g," ":/\t/g " ":/ /g," ":/\t/g
})e=e.replace(s[i],i); })e=e.replace(s[i],i);
return e; return e;
} }
function highlightQmlCode(code) { function highlightQmlCode(code) {
// QML // QML
var qmlKeywords = [ var qmlKeywords = [
"FluTextButton", "FluTextButton",
"FluAppBar", "FluAppBar",
"FluAutoSuggestBox", "FluAutoSuggestBox",
"FluBadge", "FluBadge",
"FluButton", "FluButton",
"FluCalendarPicker", "FluCalendarPicker",
"FluCalendarView", "FluCalendarView",
"FluCarousel", "FluCarousel",
"FluCheckBox", "FluCheckBox",
"FluColorPicker", "FluColorPicker",
"FluColorView", "FluColorView",
"FluComboBox", "FluComboBox",
"FluContentDialog", "FluContentDialog",
"FluContentPage", "FluContentPage",
"FluDatePicker", "FluDatePicker",
"FluDivider", "FluDivider",
"FluDropDownButton", "FluDropDownButton",
"FluExpander", "FluExpander",
"FluFilledButton", "FluFilledButton",
"FluFlipView", "FluFlipView",
"FluFocusRectangle", "FluFocusRectangle",
"FluIcon", "FluIcon",
"FluIconButton", "FluIconButton",
"FluInfoBar", "FluInfoBar",
"FluItem", "FluItem",
"FluMediaPlayer", "FluMediaPlayer",
"FluMenu", "FluMenu",
"FluMenuItem", "FluMenuItem",
"FluMultilineTextBox", "FluMultilineTextBox",
"FluNavigationView", "FluNavigationView",
"FluObject", "FluObject",
"FluPaneItem", "FluPaneItem",
"FluPaneItemExpander", "FluPaneItemExpander",
"FluPaneItemHeader", "FluPaneItemHeader",
"FluPaneItemSeparator", "FluPaneItemSeparator",
"FluPivot", "FluPivot",
"FluPivotItem", "FluPivotItem",
"FluProgressBar", "FluProgressBar",
"FluProgressRing", "FluProgressRing",
"FluRadioButton", "FluRadioButton",
"FluRectangle", "FluRectangle",
"FluScrollablePage", "FluScrollablePage",
"FluScrollBar", "FluScrollBar",
"FluShadow", "FluShadow",
"FluSlider", "FluSlider",
"FluTabView", "FluTabView",
"FluText", "FluText",
"FluTextArea", "FluTextArea",
"FluTextBox", "FluTextBox",
"FluTextBoxBackground", "FluTextBoxBackground",
"FluTextBoxMenu", "FluTextBoxMenu",
"FluTextButton", "FluTextButton",
"FluTextFiled", "FluTextFiled",
"FluTimePicker", "FluTimePicker",
"FluToggleSwitch", "FluToggleSwitch",
"FluTooltip", "FluTooltip",
"FluTreeView", "FluTreeView",
"FluWindow", "FluWindow",
"FluWindowResize", "FluWindowResize",
"FluToggleButton", "FluToggleButton",
"FluTableView", "FluTableView",
"FluColors", "FluColors",
"FluTheme", "FluTheme",
"FluStatusView", "FluStatusView",
"FluRatingControl", "FluRatingControl",
"FluPasswordBox", "FluPasswordBox",
"FluBreadcrumbBar", "FluBreadcrumbBar",
"FluCopyableText", "FluCopyableText",
"FluAcrylic" "FluAcrylic"
]; ];
code = code.replace(/\n/g, "<br>"); code = code.replace(/\n/g, "<br>");
code = code.replace(/ /g, "&nbsp;"); code = code.replace(/ /g, "&nbsp;");
return code.replace(RegExp("\\b(" + qmlKeywords.join("|") + ")\\b", "g"), "<span style='color: #c23a80'>$1</span>"); return code.replace(RegExp("\\b(" + qmlKeywords.join("|") + ")\\b", "g"), "<span style='color: #c23a80'>$1</span>");
} }

View File

@ -1,7 +1,9 @@
#include "AppInfo.h" #include "AppInfo.h"
#include <QQmlContext>
#include <QDebug>
#include "lang/En.h" #include "lang/En.h"
#include "lang/Zh.h" #include "lang/Zh.h"
#include <QDebug>
#define STR(x) #x #define STR(x) #x
#define VER_JOIN(a,b,c,d) STR(a.b.c.d) #define VER_JOIN(a,b,c,d) STR(a.b.c.d)
@ -15,6 +17,16 @@ AppInfo::AppInfo(QObject *parent)
lang(new En()); lang(new En());
} }
void AppInfo::init(QQmlApplicationEngine *engine){
QQmlContext * context = engine->rootContext();
Lang* lang = this->lang();
context->setContextProperty("lang",lang);
QObject::connect(this,&AppInfo::langChanged,this,[=]{
context->setContextProperty("lang",this->lang());
});
context->setContextProperty("appInfo",this);
}
void AppInfo::changeLang(const QString& locale){ void AppInfo::changeLang(const QString& locale){
if(_lang){ if(_lang){
_lang->deleteLater(); _lang->deleteLater();
@ -27,3 +39,18 @@ void AppInfo::changeLang(const QString& locale){
lang(new En()); lang(new En());
} }
} }
bool AppInfo::isOwnerProcess(IPC *ipc){
QString activeWindowEvent = "activeWindow";
if(!ipc->isCurrentOwner()){
ipc->postEvent(activeWindowEvent,QString().toUtf8(),0);
return false;
}
if(ipc->isAttached()){
ipc->registerEventHandler(activeWindowEvent,[=](const QByteArray&){
Q_EMIT this->activeWindow();
return true;
});
}
return true;
}

View File

@ -2,6 +2,8 @@
#define APPINFO_H #define APPINFO_H
#include <QObject> #include <QObject>
#include <QQmlApplicationEngine>
#include "tool/IPC.h"
#include "lang/Lang.h" #include "lang/Lang.h"
#include "stdafx.h" #include "stdafx.h"
@ -12,6 +14,8 @@ class AppInfo : public QObject
Q_PROPERTY_AUTO(Lang*,lang) Q_PROPERTY_AUTO(Lang*,lang)
public: public:
explicit AppInfo(QObject *parent = nullptr); explicit AppInfo(QObject *parent = nullptr);
void init(QQmlApplicationEngine *engine);
bool isOwnerProcess(IPC *ipc);
Q_INVOKABLE void changeLang(const QString& locale); Q_INVOKABLE void changeLang(const QString& locale);
Q_SIGNAL void activeWindow(); Q_SIGNAL void activeWindow();
}; };

View File

@ -6,13 +6,11 @@
#include <QProcess> #include <QProcess>
#include <FramelessHelper/Quick/framelessquickmodule.h> #include <FramelessHelper/Quick/framelessquickmodule.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h> #include <FramelessHelper/Core/private/framelessconfig_p.h>
#include "lang/Lang.h"
#include "AppInfo.h" #include "AppInfo.h"
#include "tool/IPC.h"
FRAMELESSHELPER_USE_NAMESPACE FRAMELESSHELPER_USE_NAMESPACE
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
//将样式设置为Basic不然会导致组件显示异常 //将样式设置为Basic不然会导致组件显示异常
qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
@ -31,28 +29,13 @@ FRAMELESSHELPER_USE_NAMESPACE
#endif #endif
AppInfo* appInfo = new AppInfo(); AppInfo* appInfo = new AppInfo();
IPC ipc(0); IPC ipc(0);
QString activeWindowEvent = "activeWindow"; if(!appInfo->isOwnerProcess(&ipc)){
if(!ipc.isCurrentOwner()){
ipc.postEvent(activeWindowEvent,QString().toUtf8(),0);
delete appInfo;
return 0; return 0;
} }
if(ipc.isAttached()){
ipc.registerEventHandler(activeWindowEvent,[&appInfo](const QByteArray&){
Q_EMIT appInfo->activeWindow();
return true;
});
}
app.setQuitOnLastWindowClosed(false); app.setQuitOnLastWindowClosed(false);
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
FramelessHelper::Quick::registerTypes(&engine); FramelessHelper::Quick::registerTypes(&engine);
QQmlContext * context = engine.rootContext(); appInfo->init(&engine);
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:/example/qml/App.qml")); const QUrl url(QStringLiteral("qrc:/example/qml/App.qml"));
// const QUrl url(QStringLiteral("qrc:/example/qml/TestWindow.qml")); // const QUrl url(QStringLiteral("qrc:/example/qml/TestWindow.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,

View File

@ -23,11 +23,9 @@ FluApp *FluApp::getInstance()
FluApp::FluApp(QObject *parent) FluApp::FluApp(QObject *parent)
: QObject{parent} : QObject{parent}
{ {
QFontDatabase::addApplicationFont(":/FluentUI/Font/Segoe_Fluent_Icons.ttf");
} }
FluApp::~FluApp(){ FluApp::~FluApp(){
} }
void FluApp::init(QQuickWindow *window){ void FluApp::init(QQuickWindow *window){

View File

@ -27,6 +27,7 @@ class FluApp : public QObject
*/ */
Q_PROPERTY_AUTO(QJsonObject,routes); Q_PROPERTY_AUTO(QJsonObject,routes);
QML_FOREIGN(FluApp)
QML_NAMED_ELEMENT(FluApp) QML_NAMED_ELEMENT(FluApp)
QML_SINGLETON QML_SINGLETON
private: private:

View File

@ -4,9 +4,4 @@ import FluentUI
Rectangle { Rectangle {
color: FluTheme.dark ? Window.active ? Qt.rgba(55/255,55/255,55/255,1):Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,230/255,234/255,1) color: FluTheme.dark ? Window.active ? Qt.rgba(55/255,55/255,55/255,1):Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,230/255,234/255,1)
Behavior on color{
ColorAnimation {
duration: 300
}
}
} }

View File

@ -13,4 +13,9 @@ Text {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
color: iconColor color: iconColor
text: (String.fromCharCode(iconSource).toString(16)) text: (String.fromCharCode(iconSource).toString(16))
FontLoader{
source: "../Font/Segoe_Fluent_Icons.ttf"
}
} }

View File

@ -51,17 +51,15 @@ Button {
} }
} }
contentItem: Item{ contentItem: Item{
Text { FluIcon {
id:text_icon id:text_icon
font.family: "Segoe Fluent Icons"
font.pixelSize: iconSize font.pixelSize: iconSize
width: iconSize iconSize: control.iconSize
height: iconSize
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
anchors.centerIn: parent anchors.centerIn: parent
color:control.iconColor iconColor: control.iconColor
text: (String.fromCharCode(iconSource).toString(16)); iconSource: control.iconSource;
} }
FluTooltip{ FluTooltip{
id:tool_tip id:tool_tip