From 58ef035603b8e3bf9299b4bddcdebcc653ea8810 Mon Sep 17 00:00:00 2001
From: SineStriker <trueful@163.com>
Date: 周五, 29 12月 2023 11:50:33 +0800
Subject: [PATCH] Window bar support I18N

---
 examples/shared/widgetframe/windowbar.cpp |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/examples/shared/widgetframe/windowbar.cpp b/examples/shared/widgetframe/windowbar.cpp
index a39ab4f..a171600 100644
--- a/examples/shared/widgetframe/windowbar.cpp
+++ b/examples/shared/widgetframe/windowbar.cpp
@@ -1,7 +1,8 @@
-#include "WindowBar.h"
-#include "WindowBar_p.h"
+#include "windowbar.h"
+#include "windowbar_p.h"
 
 #include <QtCore/QDebug>
+#include <QtCore/QLocale>
 #include <QtGui/QtEvents>
 
 namespace QWK {
@@ -12,12 +13,15 @@
         autoIcon = false;
     }
 
-    WindowBarPrivate::~WindowBarPrivate() {
-    }
+    WindowBarPrivate::~WindowBarPrivate() = default;
 
     void WindowBarPrivate::init() {
         Q_Q(WindowBar);
         layout = new QHBoxLayout();
+        if (QLocale::system().textDirection() == Qt::RightToLeft) {
+            layout->setDirection(QBoxLayout::RightToLeft);
+        }
+        
         layout->setContentsMargins(QMargins());
         layout->setSpacing(0);
         for (int i = IconButton; i <= CloseButton; ++i) {
@@ -54,8 +58,7 @@
     WindowBar::WindowBar(QWidget *parent) : WindowBar(*new WindowBarPrivate(), parent) {
     }
 
-    WindowBar::~WindowBar() {
-    }
+    WindowBar::~WindowBar() = default;
 
     QMenuBar *WindowBar::menuBar() const {
         Q_D(const WindowBar);
@@ -248,23 +251,26 @@
             QLabel *label = titleLabel();
             QAbstractButton *maxBtn = maxButton();
             switch (event->type()) {
-                case QEvent::WindowIconChange:
+                case QEvent::WindowIconChange: {
                     if (d_ptr->autoIcon && iconBtn) {
                         iconBtn->setIcon(w->windowIcon());
                         iconChanged(w->windowIcon());
                     }
                     break;
-                case QEvent::WindowTitleChange:
+                }
+                case QEvent::WindowTitleChange: {
                     if (d_ptr->autoTitle && label) {
                         label->setText(w->windowTitle());
                         titleChanged(w->windowTitle());
                     }
                     break;
-                case QEvent::WindowStateChange:
+                }
+                case QEvent::WindowStateChange: {
                     if (maxBtn) {
                         maxBtn->setChecked(w->isMaximized());
                     }
                     break;
+                }
                 default:
                     break;
             }

--
Gitblit v1.9.1