فهرست منبع

init stylesheet before mainwindow is shown

Le Tan 6 ماه پیش
والد
کامیت
b0b51570b0

+ 0 - 35
src/core/theme.cpp

@@ -258,7 +258,6 @@ QString Theme::fetchQtStyleSheet() const
     translateStyleByPalette(m_palette, style);
     translateUrlToAbsolute(m_themeFolderPath, style);
     translateFontFamilyList(style);
-    translateScaledSize(WidgetUtils::calculateScaleFactor(), style);
     return style;
 }
 
@@ -355,40 +354,6 @@ void Theme::translateFontFamilyList(QString &p_style)
     }
 }
 
-void Theme::translateScaledSize(qreal p_factor, QString &p_style)
-{
-    QRegularExpression scaleRe("(\\s|:)\\$([+-]?)(\\d+)(?=\\D)");
-    const int prefixCapturedIdx = 1;
-    const int signCapturedIdx = 2;
-    const int numCapturedIdx = 3;
-
-    qDebug() << "translateScaledSize of Qt style sheet" << p_factor;
-
-    int pos = 0;
-    QRegularExpressionMatch match;
-    while (pos < p_style.size()) {
-        int idx = p_style.indexOf(scaleRe, pos, &match);
-        if (idx == -1) {
-            break;
-        }
-
-        auto numStr = match.captured(numCapturedIdx);
-        bool ok = false;
-        int val = numStr.toInt(&ok);
-        if (!ok) {
-            pos = idx + match.capturedLength();
-            continue;
-        }
-
-        val = val * p_factor + 0.5;
-        auto newStr = QStringLiteral("%1%2%3").arg(match.captured(prefixCapturedIdx),
-                                            match.captured(signCapturedIdx),
-                                            QString::number(val));
-        p_style.replace(idx, match.capturedLength(), newStr);
-        pos = idx + newStr.size();
-    }
-}
-
 QString Theme::paletteColor(const QString &p_name) const
 {
     auto val = findValueByKeyPath(m_palette, p_name).toString();

+ 0 - 2
src/core/theme.h

@@ -113,8 +113,6 @@ namespace vnotex
         // Thus we need to choose one available font from the list.
         static void translateFontFamilyList(QString &p_style);
 
-        static void translateScaledSize(qreal p_factor, QString &p_style);
-
         static QJsonObject readJsonFile(const QString &p_filePath);
 
         static QJsonObject readPaletteFile(const QString &p_folder);

+ 1 - 2
src/data/extra/themes/moonlight/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -586,7 +585,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 0 - 1
src/data/extra/themes/native/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget[HitSettingWidget="true"] {

+ 1 - 2
src/data/extra/themes/pure/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -624,7 +623,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 1 - 2
src/data/extra/themes/solarized-dark/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -582,7 +581,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 1 - 2
src/data/extra/themes/solarized-light/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -582,7 +581,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 1 - 2
src/data/extra/themes/vscode-dark/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -582,7 +581,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 1 - 2
src/data/extra/themes/vue-dark/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -587,7 +586,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 1 - 2
src/data/extra/themes/vue-light/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -624,7 +623,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 1 - 2
src/data/extra/themes/vx-idea/interface.qss

@@ -5,7 +5,6 @@
  * same specificity and the rule that appears last takes precedence.
  * VNote specific syntax:
  *  - @widgets#toolbox#title#border: reference to a color defined in palette.ini;
- *  - $2px: 2 will be scaled by multiplying current display scaled factor.
  */
 
 QWidget {
@@ -643,7 +642,7 @@ QTabBar::close-button:hover {
 }
 
 QTabBar::scroller {
-    width: $20px;
+    width: 20px;
 }
 
 QTabBar QToolButton {

+ 7 - 8
src/main.cpp

@@ -157,6 +157,13 @@ int main(int argc, char *argv[])
     // Should set the correct locale before VNoteX::getInst().
     loadTranslators(app);
 
+    if (app.styleSheet().isEmpty()) {
+        auto style = VNoteX::getInst().getThemeMgr().fetchQtStyleSheet();
+        if (!style.isEmpty()) {
+            app.setStyleSheet(style);
+        }
+    }
+
     MainWindow window;
     window.show();
 
@@ -173,14 +180,6 @@ int main(int argc, char *argv[])
     // Let MainWindow show first to decide the screen on which app is running.
     WidgetUtils::calculateScaleFactor(window.windowHandle()->screen());
 
-    if (app.styleSheet().isEmpty()) {
-        auto style = VNoteX::getInst().getThemeMgr().fetchQtStyleSheet();
-        if (!style.isEmpty()) {
-            app.setStyleSheet(style);
-            WidgetUtils::updateStyle(&window);
-        }
-    }
-
     VNoteX::getInst().getThemeMgr().setBaseBackground(window.palette().color(QPalette::Base));
 
     window.kickOffOnStart(cmdOptions.m_pathsToOpen);