2#include <QCoreApplication>
3#include <QGuiApplication>
7#include <QFontDatabase>
9#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
10#include <MauiMan3/thememanager.h>
11#include <MauiMan3/backgroundmanager.h>
12#include <MauiMan3/accessibilitymanager.h>
14#include <MauiMan4/thememanager.h>
15#include <MauiMan4/backgroundmanager.h>
16#include <MauiMan4/accessibilitymanager.h>
22#include "mauiandroid.h"
25Q_GLOBAL_STATIC(
Style, styleInstance)
27void Style::styleChanged()
32 auto *style = qApp->style();
37 Q_ASSERT(style !=
sender());
42 Q_EMIT currentIconThemeChanged(m_currentIconTheme);
45 Q_EMIT monospacedFontChanged();
50 ,m_iconSizes (new
GroupSizes(8,16, 22, 32, 48, 64, 128, this))
51 ,m_space( new
GroupSizes(4, 6, 8, 16, 24, 32, 40, this))
53 ,m_units(new
Units(this))
54 ,m_accentColor(
QColor(
"#26c6da"))
55 ,m_themeSettings( new
MauiMan::ThemeManager(this))
56 ,m_backgroundSettings( new
MauiMan::BackgroundManager(this))
57 ,m_accessibilitySettings( new
MauiMan::AccessibilityManager(this))
63 Q_EMIT defaultFontChanged();
65 Q_EMIT fontSizesChanged();
66 Q_EMIT h1FontChanged();
67 Q_EMIT h2FontChanged();
71#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
72 connect(m_themeSettings, &MauiMan::ThemeManager::styleTypeChanged, [
this](
int type)
74 if(m_styleType_blocked)
78 Q_EMIT styleTypeChanged(m_styleType);
84 qDebug() <<
"Color schem style type changed<<"<<
type;
85 if(m_styleType_blocked)
90 case Qt::ColorScheme::Unknown:
93 case Qt::ColorScheme::Light:
96 case Qt::ColorScheme::Dark:
101 Q_EMIT styleTypeChanged(m_styleType);
104 connect(m_themeSettings, &MauiMan::ThemeManager::styleTypeChanged, [
this](
int type)
106 if(m_styleType_blocked)
110 Q_EMIT styleTypeChanged(m_styleType);
115 connect(m_themeSettings, &MauiMan::ThemeManager::accentColorChanged, [
this](
QString color)
117 m_accentColor = color;
118 Q_EMIT this->accentColorChanged(m_accentColor);
121 connect(m_themeSettings, &MauiMan::ThemeManager::borderRadiusChanged, [
this](uint radius)
124 Q_EMIT this->radiusVChanged(m_radiusV);
127 connect(m_themeSettings, &MauiMan::ThemeManager::iconSizeChanged, [
this](uint size)
130 Q_EMIT this->iconSizeChanged(m_iconSize);
133 connect(m_themeSettings, &MauiMan::ThemeManager::paddingSizeChanged, [
this](uint size)
135 m_defaultPadding = size;
136 Q_EMIT this->defaultPaddingChanged();
139 connect(m_themeSettings, &MauiMan::ThemeManager::marginSizeChanged, [
this](uint size)
141 qDebug() <<
"ContentMARGINS CHANGED" << size;
142 m_contentMargins = size;
143 Q_EMIT this->contentMarginsChanged();
146 connect(m_themeSettings, &MauiMan::ThemeManager::spacingSizeChanged, [
this](uint size)
148 m_defaultSpacing = size;
149 Q_EMIT this->defaultSpacingChanged();
152 connect(m_themeSettings, &MauiMan::ThemeManager::enableEffectsChanged, [
this](
bool value)
154 m_enableEffects = value;
155 Q_EMIT this->enableEffectsChanged(m_enableEffects);
158 connect(m_backgroundSettings, &MauiMan::BackgroundManager::wallpaperSourceChanged, [
this](
QString source)
161 Q_EMIT this->adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
164 connect(m_themeSettings, &MauiMan::ThemeManager::enableEffectsChanged, [
this](
bool value)
166 m_enableEffects = value;
167 Q_EMIT this->enableEffectsChanged(m_enableEffects);
170 connect(m_accessibilitySettings, &MauiMan::AccessibilityManager::scrollBarPolicyChanged, [
this](uint state)
172 qDebug() <<
"SCROLBAR POLICY CHANGED" << state;
173 Q_EMIT scrollBarPolicyChanged(state);
178 connect(m_themeSettings, &MauiMan::ThemeManager::iconThemeChanged, [
this](
QString name)
180 qDebug() <<
"Ask to change the icon theme";
181 m_currentIconTheme =
name;
182 Q_EMIT currentIconThemeChanged(m_currentIconTheme);
194 m_defaultFont = qGuiApp->font();
198 m_radiusV = m_themeSettings->borderRadius();
199 m_iconSize = m_themeSettings->iconSize();
200 m_accentColor = m_themeSettings->accentColor();
202 m_contentMargins = m_themeSettings->marginSize();
203 m_defaultPadding = m_themeSettings->paddingSize();
204 m_defaultSpacing = m_themeSettings->spacingSize();
210#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
214 m_styleType = android.darkModeEnabled() ? StyleType::Dark : StyleType::Light;
225 case Qt::ColorScheme::Unknown:
228 case Qt::ColorScheme::Light:
231 case Qt::ColorScheme::Dark:
243 m_enableEffects = m_themeSettings->enableEffects();
246void Style::setFontSizes()
248 qDebug() << m_defaultFont << m_defaultFont.
pointSize();
250 m_defaultFontSize = m_defaultFont.
pointSize ();
252 m_fontSizes->m_tiny = m_defaultFont.
pointSize ()-2;
253 m_fontSizes->m_small = m_defaultFont.
pointSize ()-1;
254 m_fontSizes->m_medium = m_defaultFont.
pointSize ();
255 m_fontSizes->m_big = m_defaultFont.
pointSize ()+1;
256 m_fontSizes->m_large = m_defaultFont.
pointSize ()+2;
257 m_fontSizes->m_huge = m_defaultFont.
pointSize ()+3;
258 m_fontSizes->m_enormous = m_defaultFont.
pointSize ()+4;
269void Style::setRadiusV(
const uint& radius)
271 if(m_radiusV == radius)
277 Q_EMIT radiusVChanged(m_radiusV);
282 return m_enableEffects;
287 return m_translucencyAvailable;
290void Style::setTranslucencyAvailable(
const bool &value)
292 if(value == m_translucencyAvailable)
297 m_translucencyAvailable = value;
298 Q_EMIT this->translucencyAvailableChanged(m_translucencyAvailable);
305 return Style::instance();
308Style *Style::instance()
310 return styleInstance();
313int getClosest(
int,
int,
int);
316int findClosest(
int arr[],
int n,
int target)
319 if (target <= arr[0])
321 if (target >= arr[n - 1])
325 int i = 0, j = n, mid = 0;
329 if (arr[mid] == target)
334 if (target < arr[mid]) {
338 if (mid > 0 && target > arr[mid - 1])
339 return getClosest(arr[mid - 1],
348 if (mid < n - 1 && target < arr[mid + 1])
349 return getClosest(arr[mid],
350 arr[mid + 1], target);
365int getClosest(
int val1,
int val2,
368 if (target - val1 >= val2 - target)
377 int values[] = {8, 16, 22, 32, 48, 64, 128};
378 int n =
sizeof(values) /
sizeof(values[0]);
379 return findClosest (values, n, size);
382GroupSizes::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)
389 ,m_enormous(enormous)
402 return m_adaptiveColorSchemeSource;
405void Style::setAdaptiveColorSchemeSource(
const QVariant& source)
407 m_adaptiveColorSchemeSource_blocked =
true;
408 if(source == m_adaptiveColorSchemeSource)
413 m_adaptiveColorSchemeSource = source;
414 Q_EMIT adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
417void Style::unsetAdaptiveColorSchemeSource()
419 m_adaptiveColorSchemeSource_blocked =
false;
421 Q_EMIT adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
426 return m_accentColor;
429void Style::setAccentColor(
const QColor& color)
431 m_accentColor_blocked =
true;
433 if(m_accentColor == color)
438 m_accentColor = color;
439 Q_EMIT accentColorChanged(m_accentColor);
442void Style::unsetAccentColor()
444 m_accentColor_blocked =
false;
446 Q_EMIT accentColorChanged(m_accentColor);
456 m_styleType_blocked =
true;
458 if (m_styleType == type)
462 Q_EMIT styleTypeChanged(m_styleType);
465void Style::unsetStyeType()
467 m_styleType_blocked =
false;
469 Q_EMIT styleTypeChanged(m_styleType);
474 , m_gridUnit(m_fontMetrics.height())
475 , m_veryLongDuration(400)
476 , m_longDuration(200)
477 , m_shortDuration(100)
478 , m_veryShortDuration(50)
479 , m_humanMoment(2000)
480 , m_toolTipDelay(700)
492 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.
Type type(const QSqlDatabase &db)
QString name(StandardShortcut id)
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)
QObject * sender() const const
void colorSchemeChanged(Qt::ColorScheme colorScheme)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toLocalFile() const const