init stylesheet before mainwindow is shown

This commit is contained in:
Le Tan 2025-04-02 22:00:29 +08:00
parent a5a9b32ea3
commit b0b51570b0
12 changed files with 15 additions and 62 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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 {

View File

@ -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"] {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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);