From da74b8b4e7a622706ab9e9d9cacabd1662f0d74b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 9 Jul 2024 11:10:57 +0200 Subject: Tweak theming a bit - Make image bg transparent, so the configured one can be seen with PNGs - Allow specifying the header background as QSS using "background=" --- src/dialog.cpp | 43 ++++++++------ src/ui/dialog.ui | 167 ++++++++++++++++++++++++++++++++----------------------- 2 files changed, 123 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/dialog.cpp b/src/dialog.cpp index 9dfff00..3eeaf7e 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -428,16 +428,19 @@ void Dialog::startSession(const QString& name) { } void Dialog::setTheme() { - QString label_l_style, label_r_style; - QString backgroundColor, imageLeft, imageRight; + QString backgroundColor, imageLeft, imageRight, backgroundStyle; QString themePathBase, themePathIni, themePathImgLeft, themePathImgRight; if (!Config::isSet(Config::THEME)) return; QString theme(Config::get(Config::THEME)); - themePathBase = QString("%1/%2/").arg(VMCHOOSER_THEME_BASE).arg(theme); - themePathIni = QString("%1%2.ini").arg(themePathBase).arg(theme); + if (theme.startsWith(QStringLiteral("/"))) { + themePathBase = theme + QStringLiteral("/"); + } else { + themePathBase = QStringLiteral("%1/%2/").arg(VMCHOOSER_THEME_BASE).arg(theme); + } + themePathIni = themePathBase + theme + QStringLiteral(".ini"); if (!QFile::exists(themePathIni)) { qDebug() << "Theme config" << themePathIni << "does not exist"; @@ -445,24 +448,28 @@ void Dialog::setTheme() { } QSettings themeSettings(themePathIni, QSettings::IniFormat); + themeSettings.setIniCodec("UTF-8"); backgroundColor = themeSettings.value("background-color").toString(); + backgroundStyle = themeSettings.value("background").toString(); imageLeft = themeSettings.value("image-left").toString(); imageRight = themeSettings.value("image-right").toString(); - themePathImgLeft = QString("%1%2").arg(themePathBase).arg(imageLeft); - themePathImgRight = QString("%1%2").arg(themePathBase).arg(imageRight); - - QRegExp re("(.*background-color:)#[^;]*(;.*)"); - - ui->label_l->setPixmap(QPixmap(themePathImgLeft)); - ui->label_r->setPixmap(QPixmap(themePathImgRight)); - label_l_style = ui->label_l->styleSheet(); - label_r_style = ui->label_r->styleSheet(); - backgroundColor.prepend("\\1").append("\\2"); - label_l_style.replace(re, backgroundColor); - label_r_style.replace(re, backgroundColor); - ui->label_l->setStyleSheet(label_l_style); - ui->label_r->setStyleSheet(label_r_style); + themePathImgLeft = themePathBase + imageLeft; + themePathImgRight = themePathBase + imageRight; + + QPixmap imgLeft(themePathImgLeft); + QPixmap imgRight(themePathImgRight); + ui->label_l->setPixmap(imgLeft); + ui->label_r->setPixmap(imgRight); + ui->label_l->setMinimumSize(imgLeft.size()); + ui->label_r->setMinimumSize(imgRight.size()); + if (!backgroundStyle.isEmpty()) { + qDebug() << "Setting background to" << (backgroundStyle); + ui->headerBg->setStyleSheet(QStringLiteral("#headerBg { %1 }").arg(backgroundStyle)); + } else { + backgroundColor = QStringLiteral("background:") + backgroundColor; + ui->headerBg->setStyleSheet(backgroundColor); + } } diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui index 0e195ea..4e03ebc 100644 --- a/src/ui/dialog.ui +++ b/src/ui/dialog.ui @@ -35,73 +35,100 @@ 6 - - - 0 - - - 0 + + + background: #fff; - - - - - 0 - 110 - - - - #label_l {background-color:#fff; -margin-left:1px; -margin-top:1px; -margin-bottom:0px;} - - - QFrame::Plain - - - - - - :/title_l - - - - - - - - 120 - 110 - - - - - 120 - 16777215 - - - - #label_r {background-color:#fff; -margin-top:1px; -margin-right:1px; -margin-bottom:0px;} - - - QFrame::Plain - - - - - - :/title_r - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 10 + + + + + 0 + 10 + + + + QFrame::Plain + + + + + + :/title_l + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 10 + + + + + 0 + 10 + + + + + 16777215 + 16777215 + + + + QFrame::Plain + + + + + + :/title_r + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + @@ -219,7 +246,7 @@ li.checked::marker { content: "\2612"; } Local - + :/linux:/linux @@ -261,7 +288,7 @@ li.checked::marker { content: "\2612"; } All Classes - + :/vm-mix:/vm-mix @@ -685,6 +712,8 @@ li.checked::marker { content: "\2612"; }
src/vmtree.h
- + + + -- cgit v1.2.3-55-g7522