2#include <QCoreApplication>
3#include <QGuiApplication>
7#include <QFontDatabase>
13#include <MauiMan4/thememanager.h>
14#include <MauiMan4/backgroundmanager.h>
15#include <MauiMan4/accessibilitymanager.h>
17Q_GLOBAL_STATIC(
Style, styleInstance)
19void Style::styleChanged()
23 qDebug() <<
"STYLE HAS CHANGED EMITTED";
27 auto *style = qApp->style();
32 Q_ASSERT(style !=
sender());
37 Q_EMIT currentIconThemeChanged(m_currentIconTheme);
40 Q_EMIT monospacedFontChanged();
44 ,m_iconSizes (new
GroupSizes(8,16, 22, 32, 48, 64, 128, this))
45 ,m_space( new
GroupSizes(4, 6, 8, 16, 24, 32, 40, this))
47 ,m_units(new
Units(this))
48 ,m_accentColor(
QColor(
"#26c6da"))
49 ,m_themeSettings( new
MauiMan::ThemeManager(this))
50 ,m_backgroundSettings( new
MauiMan::BackgroundManager(this))
51 ,m_accessibilitySettings( new
MauiMan::AccessibilityManager(this))
58 Q_EMIT defaultFontChanged();
60 Q_EMIT fontSizesChanged();
61 Q_EMIT h1FontChanged();
62 Q_EMIT h2FontChanged();
63 Q_EMIT monospacedFontChanged();
68 if(m_styleType_blocked)
73 case Qt::ColorScheme::Unknown:
76 case Qt::ColorScheme::Light:
79 case Qt::ColorScheme::Dark:
83 qDebug() <<
"Color schem style type changed<<"<<
type << m_styleType;
85 Q_EMIT styleTypeChanged(m_styleType);
88 connect(m_themeSettings, &MauiMan::ThemeManager::styleTypeChanged, [
this](
int type)
90 if(m_styleType_blocked)
94 Q_EMIT styleTypeChanged(m_styleType);
97 connect(m_themeSettings, &MauiMan::ThemeManager::accentColorChanged, [
this](
QString color)
99 m_accentColor = color;
100 Q_EMIT this->accentColorChanged(m_accentColor);
103 connect(m_themeSettings, &MauiMan::ThemeManager::borderRadiusChanged, [
this](uint radius)
106 Q_EMIT this->radiusVChanged(m_radiusV);
109 connect(m_themeSettings, &MauiMan::ThemeManager::iconSizeChanged, [
this](uint size)
112 Q_EMIT this->iconSizeChanged(m_iconSize);
115 connect(m_themeSettings, &MauiMan::ThemeManager::paddingSizeChanged, [
this](uint size)
117 m_defaultPadding = size;
118 Q_EMIT this->defaultPaddingChanged();
121 connect(m_themeSettings, &MauiMan::ThemeManager::marginSizeChanged, [
this](uint size)
123 qDebug() <<
"ContentMARGINS CHANGED" << size;
124 m_contentMargins = size;
125 Q_EMIT this->contentMarginsChanged();
128 connect(m_themeSettings, &MauiMan::ThemeManager::spacingSizeChanged, [
this](uint size)
130 m_defaultSpacing = size;
131 Q_EMIT this->defaultSpacingChanged();
134 connect(m_themeSettings, &MauiMan::ThemeManager::enableEffectsChanged, [
this](
bool value)
136 m_enableEffects = value;
137 Q_EMIT this->enableEffectsChanged(m_enableEffects);
140 connect(m_backgroundSettings, &MauiMan::BackgroundManager::wallpaperSourceChanged, [
this](
QString source)
143 Q_EMIT this->adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
146 connect(m_themeSettings, &MauiMan::ThemeManager::enableEffectsChanged, [
this](
bool value)
148 m_enableEffects = value;
149 Q_EMIT this->enableEffectsChanged(m_enableEffects);
152 connect(m_accessibilitySettings, &MauiMan::AccessibilityManager::scrollBarPolicyChanged, [
this](uint state)
154 qDebug() <<
"SCROLBAR POLICY CHANGED" << state;
155 Q_EMIT scrollBarPolicyChanged(state);
160 connect(m_themeSettings, &MauiMan::ThemeManager::iconThemeChanged, [
this](
QString name)
162 qDebug() <<
"Ask to change the icon theme";
163 m_currentIconTheme =
name;
164 Q_EMIT currentIconThemeChanged(m_currentIconTheme);
176 m_defaultFont = qGuiApp->font();
180 m_radiusV = m_themeSettings->borderRadius();
181 m_iconSize = m_themeSettings->iconSize();
182 m_accentColor = m_themeSettings->accentColor();
184 m_contentMargins = m_themeSettings->marginSize();
185 m_defaultPadding = m_themeSettings->paddingSize();
186 m_defaultSpacing = m_themeSettings->spacingSize();
197 case Qt::ColorScheme::Unknown:
200 case Qt::ColorScheme::Light:
203 case Qt::ColorScheme::Dark:
214 m_enableEffects = m_themeSettings->enableEffects();
217void Style::setFontSizes()
219 qDebug() << m_defaultFont << m_defaultFont.
pointSize();
223 m_fontSizes->m_tiny = m_defaultFontSize-2;
224 m_fontSizes->m_small = m_defaultFontSize-1;
225 m_fontSizes->m_medium = m_defaultFontSize;
226 m_fontSizes->m_big = m_defaultFontSize+1;
227 m_fontSizes->m_large = m_defaultFontSize+2;
228 m_fontSizes->m_huge = m_defaultFontSize+3;
229 m_fontSizes->m_enormous = m_defaultFontSize+4;
240void Style::setRadiusV(
const uint& radius)
242 if(m_radiusV == radius)
248 Q_EMIT radiusVChanged(m_radiusV);
253 return m_enableEffects;
258 return m_translucencyAvailable;
261void Style::setTranslucencyAvailable(
const bool &value)
263 if(value == m_translucencyAvailable)
268 m_translucencyAvailable = value;
269 Q_EMIT this->translucencyAvailableChanged(m_translucencyAvailable);
276 return Style::instance();
279Style *Style::instance()
281 return styleInstance();
284int getClosest(
int,
int,
int);
287int findClosest(
int arr[],
int n,
int target)
290 if (target <= arr[0])
292 if (target >= arr[n - 1])
296 int i = 0, j = n, mid = 0;
300 if (arr[mid] == target)
305 if (target < arr[mid]) {
309 if (mid > 0 && target > arr[mid - 1])
310 return getClosest(arr[mid - 1],
319 if (mid < n - 1 && target < arr[mid + 1])
320 return getClosest(arr[mid],
321 arr[mid + 1], target);
336int getClosest(
int val1,
int val2,
339 if (target - val1 >= val2 - target)
348 int values[] = {8, 16, 22, 32, 48, 64, 128};
349 int n =
sizeof(values) /
sizeof(values[0]);
350 return findClosest (values, n, size);
353GroupSizes::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)
360 ,m_enormous(enormous)
373 return m_adaptiveColorSchemeSource;
376void Style::setAdaptiveColorSchemeSource(
const QVariant& source)
378 m_adaptiveColorSchemeSource_blocked =
true;
379 if(source == m_adaptiveColorSchemeSource)
384 m_adaptiveColorSchemeSource = source;
385 Q_EMIT adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
388void Style::unsetAdaptiveColorSchemeSource()
390 m_adaptiveColorSchemeSource_blocked =
false;
392 Q_EMIT adaptiveColorSchemeSourceChanged(m_adaptiveColorSchemeSource);
397 return m_accentColor;
400void Style::setAccentColor(
const QColor& color)
402 m_accentColor_blocked =
true;
404 if(m_accentColor == color)
409 m_accentColor = color;
410 Q_EMIT accentColorChanged(m_accentColor);
413void Style::unsetAccentColor()
415 m_accentColor_blocked =
false;
417 Q_EMIT accentColorChanged(m_accentColor);
427 m_styleType_blocked =
true;
429 if (m_styleType == type)
433 Q_EMIT styleTypeChanged(m_styleType);
436void Style::unsetStyeType()
438 m_styleType_blocked =
false;
440 Q_EMIT styleTypeChanged(m_styleType);
445 , m_gridUnit(m_fontMetrics.height())
446 , m_veryLongDuration(400)
447 , m_longDuration(200)
448 , m_shortDuration(100)
449 , m_veryShortDuration(50)
450 , m_humanMoment(2000)
451 , m_toolTipDelay(700)
463 return m_currentIconTheme;
492 Q_EMIT currentIconThemeChanged( m_currentIconTheme);
493 qDebug() <<
"ICON THEME CHANGED" << 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(StandardAction id)
QCoreApplication * instance()
int pixelSize() const const
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)
virtual bool event(QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
void installEventFilter(QObject *filterObj)
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