20
20
#include " gnomesettings.h"
21
21
#include " gnomesettings_p.h"
22
22
23
+ #if QT_VERSION >= 0x060000
24
+ #include < AdwaitaQt6/adwaitacolors.h>
25
+ #else
23
26
#include < AdwaitaQt/adwaitacolors.h>
27
+ #endif
24
28
25
29
// QtCore
26
30
#include < QDir>
@@ -102,6 +106,11 @@ bool GnomeSettings::isGtkThemeDarkVariant()
102
106
return gnomeSettingsGlobal->isGtkThemeDarkVariant ();
103
107
}
104
108
109
+ bool GnomeSettings::isGtkThemeHighContrastVariant ()
110
+ {
111
+ return gnomeSettingsGlobal->isGtkThemeHighContrastVariant ();
112
+ }
113
+
105
114
QString GnomeSettings::gtkTheme ()
106
115
{
107
116
return gnomeSettingsGlobal->gtkTheme ();
@@ -210,7 +219,11 @@ GnomeSettingsPrivate::GnomeSettingsPrivate(QObject *parent)
210
219
loadTheme ();
211
220
loadTitlebar ();
212
221
213
- m_palette = new QPalette (Adwaita::Colors::palette (m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita));
222
+ if (m_gtkThemeHighContrastVariant) {
223
+ m_palette = new QPalette (Adwaita::Colors::palette (m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaHighcontrastInverse : Adwaita::ColorVariant::AdwaitaHighcontrast));
224
+ } else {
225
+ m_palette = new QPalette (Adwaita::Colors::palette (m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita));
226
+ }
214
227
215
228
if (m_canUseFileChooserPortal) {
216
229
QTimer::singleShot (0 , this , [this ] () {
@@ -290,6 +303,11 @@ bool GnomeSettingsPrivate::isGtkThemeDarkVariant() const
290
303
return m_gtkThemeDarkVariant;
291
304
}
292
305
306
+ bool GnomeSettingsPrivate::isGtkThemeHighContrastVariant () const
307
+ {
308
+ return m_gtkThemeHighContrastVariant;
309
+ }
310
+
293
311
QString GnomeSettingsPrivate::gtkTheme () const
294
312
{
295
313
return QString (m_gtkTheme);
@@ -472,7 +490,11 @@ void GnomeSettingsPrivate::loadTheme()
472
490
} else {
473
491
qCDebug (QGnomePlatform) << " Theme name: " << m_gtkTheme;
474
492
475
- if (m_gtkTheme.toLower ().contains (" -dark" )) {
493
+ if (m_gtkTheme.toLower ().startsWith (" highcontrast" )) {
494
+ m_gtkThemeHighContrastVariant = true ;
495
+ }
496
+
497
+ if (m_gtkTheme.toLower ().contains (" -dark" ) || m_gtkTheme.toLower ().endsWith (" inverse" )) {
476
498
m_gtkThemeDarkVariant = true ;
477
499
}
478
500
@@ -481,7 +503,11 @@ void GnomeSettingsPrivate::loadTheme()
481
503
} else {
482
504
qCDebug (QGnomePlatform) << " Theme name: " << styleOverride;
483
505
484
- if (styleOverride.toLower ().contains (" -dark" )) {
506
+ if (styleOverride.toLower ().startsWith (" highcontrast" )) {
507
+ m_gtkThemeHighContrastVariant = true ;
508
+ }
509
+
510
+ if (styleOverride.toLower ().contains (" -dark" ) || styleOverride.toLower ().endsWith (" inverse" )) {
485
511
m_gtkThemeDarkVariant = true ;
486
512
}
487
513
@@ -517,6 +543,53 @@ void GnomeSettingsPrivate::loadTheme()
517
543
m_hints[QPlatformTheme::StyleNames] = styleNames;
518
544
}
519
545
546
+ // FIXME: duplicate
547
+ static QFont* qt_fontFromString (const QString &name)
548
+ {
549
+ QFont *font = new QFont (QLatin1String (" Sans" ), 10 );
550
+
551
+ PangoFontDescription *desc = pango_font_description_from_string (name.toUtf8 ());
552
+ font->setPointSizeF (static_cast <float >(pango_font_description_get_size (desc)) / PANGO_SCALE);
553
+
554
+ QString family = QString::fromUtf8 (pango_font_description_get_family (desc));
555
+ if (!family.isEmpty ()) {
556
+ font->setFamily (family);
557
+ }
558
+
559
+ const int weight = pango_font_description_get_weight (desc);
560
+ if (weight >= PANGO_WEIGHT_HEAVY) {
561
+ font->setWeight (QFont::Black);
562
+ } else if (weight >= PANGO_WEIGHT_ULTRABOLD) {
563
+ font->setWeight (QFont::ExtraBold);
564
+ } else if (weight >= PANGO_WEIGHT_BOLD) {
565
+ font->setWeight (QFont::Bold);
566
+ } else if (weight >= PANGO_WEIGHT_SEMIBOLD) {
567
+ font->setWeight (QFont::DemiBold);
568
+ } else if (weight >= PANGO_WEIGHT_MEDIUM) {
569
+ font->setWeight (QFont::Medium);
570
+ } else if (weight >= PANGO_WEIGHT_NORMAL) {
571
+ font->setWeight (QFont::Normal);
572
+ } else if (weight >= PANGO_WEIGHT_LIGHT) {
573
+ font->setWeight (QFont::Light);
574
+ } else if (weight >= PANGO_WEIGHT_ULTRALIGHT) {
575
+ font->setWeight (QFont::ExtraLight);
576
+ } else {
577
+ font->setWeight (QFont::Thin);
578
+ }
579
+
580
+ PangoStyle style = pango_font_description_get_style (desc);
581
+ if (style == PANGO_STYLE_ITALIC) {
582
+ font->setStyle (QFont::StyleItalic);
583
+ } else if (style == PANGO_STYLE_OBLIQUE) {
584
+ font->setStyle (QFont::StyleOblique);
585
+ } else {
586
+ font->setStyle (QFont::StyleNormal);
587
+ }
588
+
589
+ pango_font_description_free (desc);
590
+ return font;
591
+ }
592
+
520
593
void GnomeSettingsPrivate::loadFonts ()
521
594
{
522
595
qDeleteAll (m_fonts);
@@ -529,41 +602,17 @@ void GnomeSettingsPrivate::loadFonts()
529
602
if (fontName.isEmpty ()) {
530
603
qCWarning (QGnomePlatform) << " Couldn't get " << fontType;
531
604
} else {
532
- bool bold = false ;
533
- int fontSize;
534
- QString name;
535
- QRegExp re (" ^([^,]+)[, \t ]+([0-9]+)$" );
536
- if (re.indexIn (fontName) == 0 ) {
537
- fontSize = re.cap (2 ).toInt ();
538
- name = re.cap (1 );
539
- // Bold is most likely not part of the name
540
- if (name.endsWith (QStringLiteral (" Bold" ))) {
541
- bold = true ;
542
- name = name.remove (QStringLiteral (" Bold" ));
543
- }
544
-
545
- QFont *font = new QFont (name, fontSize, bold ? QFont::Bold : QFont::Normal);
546
- if (fontType == QStringLiteral (" font-name" )) {
547
- m_fonts[QPlatformTheme::SystemFont] = font;
548
- qCDebug (QGnomePlatform) << " Font name: " << name << " (size " << fontSize << " )" ;
549
- } else if (fontType == QStringLiteral (" monospace-font-name" )) {
550
- m_fonts[QPlatformTheme::FixedFont] = font;
551
- qCDebug (QGnomePlatform) << " Monospace font name: " << name << " (size " << fontSize << " )" ;
552
- } else if (fontType == QStringLiteral (" titlebar-font" )) {
553
- m_fonts[QPlatformTheme::TitleBarFont] = font;
554
- qCDebug (QGnomePlatform) << " TitleBar font name: " << name << " (size " << fontSize << " )" ;
555
- }
556
- } else {
557
- if (fontType == QStringLiteral (" font-name" )) {
558
- m_fonts[QPlatformTheme::SystemFont] = new QFont (fontName);
559
- qCDebug (QGnomePlatform) << " Font name: " << fontName;
560
- } else if (fontType == QStringLiteral (" monospace-font-name" )) {
561
- m_fonts[QPlatformTheme::FixedFont] = new QFont (fontName);
562
- qCDebug (QGnomePlatform) << " Monospace font name: " << fontName;
563
- } else if (fontType == QStringLiteral (" titlebar-font" )) {
564
- m_fonts[QPlatformTheme::TitleBarFont] = new QFont (fontName);
565
- qCDebug (QGnomePlatform) << " TitleBar font name: " << fontName;
566
- }
605
+ qCDebug (QGnomePlatform) << " String name: " << fontName;
606
+ QFont *font = qt_fontFromString (fontName);
607
+ if (fontType == QStringLiteral (" font-name" )) {
608
+ m_fonts[QPlatformTheme::SystemFont] = font;
609
+ qCDebug (QGnomePlatform) << " Font name: " << font->family () << " (size " << font->pointSize () << " )" ;
610
+ } else if (fontType == QStringLiteral (" monospace-font-name" )) {
611
+ m_fonts[QPlatformTheme::FixedFont] = font;
612
+ qCDebug (QGnomePlatform) << " Monospace font name: " << font->family () << " (size " << font->pointSize () << " )" ;
613
+ } else if (fontType == QStringLiteral (" titlebar-font" )) {
614
+ m_fonts[QPlatformTheme::TitleBarFont] = font;
615
+ qCDebug (QGnomePlatform) << " TitleBar font name: " << font->family () << " (size " << font->pointSize () << " )" ;
567
616
}
568
617
}
569
618
}
0 commit comments