2#include <QCoreApplication>
3#include <QGuiApplication>
7#include <QFontDatabase>
10#include <MauiMan4/thememanager.h>
11#include <MauiMan4/backgroundmanager.h>
12#include <MauiMan4/accessibilitymanager.h>
15#include "mauiandroid.h"
18Q_GLOBAL_STATIC(
Style, styleInstance)
20void Style::styleChanged()
25 auto *style = qApp->style();
30 Q_ASSERT(style !=
sender());
35 Q_EMIT currentIconThemeChanged(m_currentIconTheme);
38 Q_EMIT monospacedFontChanged();
43 ,m_iconSizes (new
GroupSizes(8,16, 22, 32, 48, 64, 128, this))
44 ,m_space( new
GroupSizes(4, 6, 8, 16, 24, 32, 40, this))
46 ,m_units(new
Units(this))
47 ,m_accentColor(
QColor(
"#26c6da"))
48 ,m_themeSettings( new
MauiMan::ThemeManager(this))
49 ,m_backgroundSettings( new
MauiMan::BackgroundManager(this))
50 ,m_accessibilitySettings( new
MauiMan::AccessibilityManager(this))
56 Q_EMIT defaultFontChanged();
58 Q_EMIT fontSizesChanged();
59 Q_EMIT h1FontChanged();
60 Q_EMIT h2FontChanged();
66 qDebug() <<
"Color schem style type changed<<"<<
type;
67 if(m_styleType_blocked)
72 case Qt::ColorScheme::Unknown:
75 case Qt::ColorScheme::Light:
78 case Qt::ColorScheme::Dark:
83 Q_EMIT styleTypeChanged(m_styleType);
86 connect(m_themeSettings, &MauiMan::ThemeManager::styleTypeChanged, [
this](
int type)
88 if(m_styleType_blocked)
92 Q_EMIT styleTypeChanged(m_styleType);
95 connect(m_themeSettings, &MauiMan::ThemeManager::accentColorChanged, [
this](
QString color)
97 m_accentColor = color;
98 Q_EMIT this->accentColorChanged(m_accentColor);
101 connect(m_themeSettings, &MauiMan::ThemeManager::borderRadiusChanged, [
this](uint radius)
104 Q_EMIT this->radiusVChanged(m_radiusV);
107 connect(m_themeSettings, &MauiMan::ThemeManager::iconSizeChanged, [
this](uint size)
110 Q_EMIT this->iconSizeChanged(m_iconSize);
113 connect(m_themeSettings, &MauiMan::ThemeManager::paddingSizeChanged, [
this](uint size)
115 m_defaultPadding = size;
116 Q_EMIT this->defaultPaddingChanged();
119 connect(m_themeSettings, &MauiMan::ThemeManager::marginSizeChanged, [
this](uint size)
121 qDebug() <<
"ContentMARGINS CHANGED" << size;
122 m_contentMargins = size;
123 Q_EMIT this->contentMarginsChanged();
126 connect(m_themeSettings, &MauiMan::ThemeManager::spacingSizeChanged, [
this](uint size)
128 m_defaultSpacing = size;
129 Q_EMIT this->defaultSpacingChanged();
132 connect(m_themeSettings, &MauiMan::ThemeManager::enableEffectsChanged, [
this](
bool value)
134 m_enableEffects = value;
135 Q_EMIT this->enableEffectsChanged(m_enableEffects);
138 connect(m_backgroundSettings, &MauiMan::BackgroundManager::wallpaperSourceChanged, [
this](
QString source)
141 Q_EMIT this->adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
144 connect(m_themeSettings, &MauiMan::ThemeManager::enableEffectsChanged, [
this](
bool value)
146 m_enableEffects = value;
147 Q_EMIT this->enableEffectsChanged(m_enableEffects);
150 connect(m_accessibilitySettings, &MauiMan::AccessibilityManager::scrollBarPolicyChanged, [
this](uint state)
152 qDebug() <<
"SCROLBAR POLICY CHANGED" << state;
153 Q_EMIT scrollBarPolicyChanged(state);
158 connect(m_themeSettings, &MauiMan::ThemeManager::iconThemeChanged, [
this](
QString name)
160 qDebug() <<
"Ask to change the icon theme";
161 m_currentIconTheme =
name;
162 Q_EMIT currentIconThemeChanged(m_currentIconTheme);
174 m_defaultFont = qGuiApp->font();
178 m_radiusV = m_themeSettings->borderRadius();
179 m_iconSize = m_themeSettings->iconSize();
180 m_accentColor = m_themeSettings->accentColor();
182 m_contentMargins = m_themeSettings->marginSize();
183 m_defaultPadding = m_themeSettings->paddingSize();
184 m_defaultSpacing = m_themeSettings->spacingSize();
195 case Qt::ColorScheme::Unknown:
198 case Qt::ColorScheme::Light:
201 case Qt::ColorScheme::Dark:
212 m_enableEffects = m_themeSettings->enableEffects();
215void Style::setFontSizes()
217 qDebug() << m_defaultFont << m_defaultFont.
pointSize();
219 m_defaultFontSize = m_defaultFont.
pointSize ();
221 m_fontSizes->m_tiny = m_defaultFont.
pointSize ()-2;
222 m_fontSizes->m_small = m_defaultFont.
pointSize ()-1;
223 m_fontSizes->m_medium = m_defaultFont.
pointSize ();
224 m_fontSizes->m_big = m_defaultFont.
pointSize ()+1;
225 m_fontSizes->m_large = m_defaultFont.
pointSize ()+2;
226 m_fontSizes->m_huge = m_defaultFont.
pointSize ()+3;
227 m_fontSizes->m_enormous = m_defaultFont.
pointSize ()+4;
238void Style::setRadiusV(
const uint& radius)
240 if(m_radiusV == radius)
246 Q_EMIT radiusVChanged(m_radiusV);
251 return m_enableEffects;
256 return m_translucencyAvailable;
259void Style::setTranslucencyAvailable(
const bool &value)
261 if(value == m_translucencyAvailable)
266 m_translucencyAvailable = value;
267 Q_EMIT this->translucencyAvailableChanged(m_translucencyAvailable);
274 return Style::instance();
277Style *Style::instance()
279 return styleInstance();
282int getClosest(
int,
int,
int);
285int findClosest(
int arr[],
int n,
int target)
288 if (target <= arr[0])
290 if (target >= arr[n - 1])
294 int i = 0, j = n, mid = 0;
298 if (arr[mid] == target)
303 if (target < arr[mid]) {
307 if (mid > 0 && target > arr[mid - 1])
308 return getClosest(arr[mid - 1],
317 if (mid < n - 1 && target < arr[mid + 1])
318 return getClosest(arr[mid],
319 arr[mid + 1], target);
334int getClosest(
int val1,
int val2,
337 if (target - val1 >= val2 - target)
346 int values[] = {8, 16, 22, 32, 48, 64, 128};
347 int n =
sizeof(values) /
sizeof(values[0]);
348 return findClosest (values, n, size);
351GroupSizes::GroupSizes(
const uint tiny,
const uint small,
const uint medium,
const uint big,
const uint large,
const uint huge,
const uint enormous,
QObject *parent) :
QObject(parent)
358 ,m_enormous(enormous)
371 return m_adaptiveColorSchemeSource;
374void Style::setAdaptiveColorSchemeSource(
const QVariant& source)
376 m_adaptiveColorSchemeSource_blocked =
true;
377 if(source == m_adaptiveColorSchemeSource)
382 m_adaptiveColorSchemeSource = source;
383 Q_EMIT adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
386void Style::unsetAdaptiveColorSchemeSource()
388 m_adaptiveColorSchemeSource_blocked =
false;
390 Q_EMIT adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
395 return m_accentColor;
398void Style::setAccentColor(
const QColor& color)
400 m_accentColor_blocked =
true;
402 if(m_accentColor == color)
407 m_accentColor = color;
408 Q_EMIT accentColorChanged(m_accentColor);
411void Style::unsetAccentColor()
413 m_accentColor_blocked =
false;
415 Q_EMIT accentColorChanged(m_accentColor);
425 m_styleType_blocked =
true;
427 if (m_styleType == type)
431 Q_EMIT styleTypeChanged(m_styleType);
434void Style::unsetStyeType()
436 m_styleType_blocked =
false;
438 Q_EMIT styleTypeChanged(m_styleType);
443 , m_gridUnit(m_fontMetrics.height())
444 , m_veryLongDuration(400)
445 , m_longDuration(200)
446 , m_shortDuration(100)
447 , m_veryShortDuration(50)
448 , m_humanMoment(2000)
449 , m_toolTipDelay(700)
461 return m_currentIconTheme;
The sizes group for some Style properties, such as Style::iconSize, Style::space, etc.
static bool isMauiSession()
The MauiKit Style preferences singleton object.
QString currentIconTheme
The current system icon theme picked up by the user.
QVariant adaptiveColorSchemeSource
The source for picking up the application color palette when the style type is set to Style....
uint iconSize
The preferred size for painting the icons in places, such as menus, buttons and delegates.
bool menusHaveIcons
Whether the menu entries should display the icon image.
bool playSounds
Whether the user desires for the application to play sounds or not.
bool enableEffects
Whether special effects are desired.
StyleType
The different options for the color scheme style.
@ Light
A light variant designed for Maui.
@ Dark
A dark variant designed for Maui.
uint scrollBarPolicy
The preferred scroll bars policy for displaying them or not.
int mapToIconSizes(const int &size)
Given a size as argument this function will return the best fitted icon size from the standard icon s...
StyleType styleType
The preferred style type for setting the color scheme of the application.
bool translucencyAvailable
Whether the application window surface should be transparent and request the compositor to blur the b...
QColor accentColor
Sets the color to be used for highlighted, active, checked and such states of the UI elements.
The Unit group properties.
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QCoreApplication * instance()
int pointSize() const const
void setBold(bool enable)
void setPointSize(int pointSize)
void setWeight(Weight weight)
QFont systemFont(SystemFont type)
void fontChanged(const QFont &font)
QStyleHints * styleHints()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
T qobject_cast(QObject *object)
QObject * sender() const const
void colorSchemeChanged(Qt::ColorScheme colorScheme)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toLocalFile() const const