| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | #include "themeinterface.h"
 | 
					
						
							| 
									
										
										
										
											2022-08-30 18:13:13 +02:00
										 |  |  | #include "core/subsurface-float.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-14 13:10:07 +01:00
										 |  |  | #include "qmlmanager.h"
 | 
					
						
							|  |  |  | #include "core/metrics.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | #include "core/settings/qPrefDisplay.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:07:54 +02:00
										 |  |  | static const QColor BLUE_BACKGROUND_COLOR = "#eff0f1"; | 
					
						
							|  |  |  | static const QColor BLUE_CONTRAST_ACCENT_COLOR = "#FF5722"; | 
					
						
							|  |  |  | static const QColor BLUE_DARKER_PRIMARY_COLOR = "#303F9f"; | 
					
						
							|  |  |  | static const QColor BLUE_DARKER_PRIMARY_TEXT_COLOR = "#ECECEC"; | 
					
						
							|  |  |  | static const QColor BLUE_DRAWER_COLOR = "#FFFFFF"; | 
					
						
							|  |  |  | static const QColor BLUE_LIGHT_DRAWER_COLOR = "#FFFFFF"; | 
					
						
							|  |  |  | static const QColor BLUE_LIGHT_PRIMARY_COLOR = "#C5CAE9"; | 
					
						
							|  |  |  | static const QColor BLUE_LIGHT_PRIMARY_TEXT_COLOR = "#212121"; | 
					
						
							|  |  |  | static const QColor BLUE_PRIMARY_COLOR = "#3F51B5"; | 
					
						
							|  |  |  | static const QColor BLUE_PRIMARY_TEXT_COLOR = "#FFFFFF"; | 
					
						
							|  |  |  | static const QColor BLUE_SECONDARY_TEXT_COLOR = "#757575"; | 
					
						
							|  |  |  | static const QColor BLUE_TEXT_COLOR = "#212121"; | 
					
						
							| 
									
										
										
										
											2020-01-28 22:56:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:07:54 +02:00
										 |  |  | static const QColor PINK_BACKGROUND_COLOR = "#eff0f1"; | 
					
						
							|  |  |  | static const QColor PINK_CONTRAST_ACCENT_COLOR = "#FF5722"; | 
					
						
							|  |  |  | static const QColor PINK_DARKER_PRIMARY_COLOR = "#C2185B"; | 
					
						
							|  |  |  | static const QColor PINK_DARKER_PRIMARY_TEXT_COLOR = "#ECECEC"; | 
					
						
							|  |  |  | static const QColor PINK_DRAWER_COLOR = "#FFFFFF"; | 
					
						
							|  |  |  | static const QColor PINK_LIGHT_DRAWER_COLOR = "#FFFFFF"; | 
					
						
							|  |  |  | static const QColor PINK_LIGHT_PRIMARY_COLOR = "#FFDDF4"; | 
					
						
							|  |  |  | static const QColor PINK_LIGHT_PRIMARY_TEXT_COLOR = "#212121"; | 
					
						
							|  |  |  | static const QColor PINK_PRIMARY_COLOR = "#FF69B4"; | 
					
						
							|  |  |  | static const QColor PINK_PRIMARY_TEXT_COLOR = "#212121"; | 
					
						
							|  |  |  | static const QColor PINK_SECONDARY_TEXT_COLOR = "#757575"; | 
					
						
							|  |  |  | static const QColor PINK_TEXT_COLOR = "#212121"; | 
					
						
							| 
									
										
										
										
											2020-01-28 22:56:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:07:54 +02:00
										 |  |  | static const QColor DARK_BACKGROUND_COLOR = "#303030"; | 
					
						
							|  |  |  | static const QColor DARK_CONTRAST_ACCENT_COLOR = "#FF5722"; | 
					
						
							|  |  |  | static const QColor DARK_DARKER_PRIMARY_COLOR = "#303F9f"; | 
					
						
							|  |  |  | static const QColor DARK_DARKER_PRIMARY_TEXT_COLOR = "#ECECEC"; | 
					
						
							|  |  |  | static const QColor DARK_DRAWER_COLOR = "#424242"; | 
					
						
							|  |  |  | static const QColor DARK_LIGHT_DRAWER_COLOR = "#FFFFFF"; | 
					
						
							| 
									
										
										
										
											2020-12-18 12:42:08 -08:00
										 |  |  | static const QColor DARK_LIGHT_PRIMARY_COLOR = "#303050"; | 
					
						
							| 
									
										
										
										
											2020-03-30 21:07:54 +02:00
										 |  |  | static const QColor DARK_LIGHT_PRIMARY_TEXT_COLOR = "#ECECEC"; | 
					
						
							|  |  |  | static const QColor DARK_PRIMARY_COLOR = "#3F51B5"; | 
					
						
							|  |  |  | static const QColor DARK_PRIMARY_TEXT_COLOR = "#ECECEC"; | 
					
						
							|  |  |  | static const QColor DARK_SECONDARY_TEXT_COLOR = "#757575"; | 
					
						
							|  |  |  | static const QColor DARK_TEXT_COLOR = "#ECECEC"; | 
					
						
							| 
									
										
										
										
											2020-01-28 22:56:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:09:18 +02:00
										 |  |  | ThemeInterface *ThemeInterface::instance() | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-30 21:09:18 +02:00
										 |  |  | 	static ThemeInterface *self = new ThemeInterface; | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 18:26:19 +01:00
										 |  |  | ThemeInterface::ThemeInterface() : | 
					
						
							|  |  |  | 	m_basePointSize(-1.0), // simply a placeholder to declare 'this isn't set, yet'
 | 
					
						
							|  |  |  | 	m_currentTheme(qPrefDisplay::theme()), | 
					
						
							|  |  |  | 	m_needSignals(true) // make sure the signals fire the first time
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	// get current theme
 | 
					
						
							| 
									
										
										
										
											2020-01-28 22:56:20 +01:00
										 |  |  | 	update_theme(); | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:09:18 +02:00
										 |  |  | void ThemeInterface::set_currentTheme(const QString &theme) | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_currentTheme = theme; | 
					
						
							|  |  |  | 	qPrefDisplay::set_theme(m_currentTheme); | 
					
						
							| 
									
										
										
										
											2020-03-30 21:01:54 +02:00
										 |  |  | 	update_theme(); | 
					
						
							| 
									
										
										
										
											2020-03-30 21:20:49 +02:00
										 |  |  | 	emit currentThemeChanged(); | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 17:08:13 -08:00
										 |  |  | void ThemeInterface::setInitialFontSize(double fontSize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_basePointSize = fontSize; | 
					
						
							|  |  |  | 	set_currentScale(qPrefDisplay::mobile_scale()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:09:18 +02:00
										 |  |  | double ThemeInterface::currentScale() | 
					
						
							| 
									
										
										
										
											2020-01-14 19:30:47 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	return qPrefDisplay::mobile_scale(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-03-30 21:20:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:09:18 +02:00
										 |  |  | void ThemeInterface::set_currentScale(double newScale) | 
					
						
							| 
									
										
										
										
											2020-01-14 19:30:47 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-08-30 17:55:43 +02:00
										 |  |  | 	if (!nearly_equal(newScale, qPrefDisplay::mobile_scale())) { | 
					
						
							| 
									
										
										
										
											2020-01-14 19:30:47 +01:00
										 |  |  | 		qPrefDisplay::set_mobile_scale(newScale); | 
					
						
							| 
									
										
										
										
											2020-03-30 21:20:49 +02:00
										 |  |  | 		emit currentScaleChanged(); | 
					
						
							| 
									
										
										
										
											2022-01-05 18:26:19 +01:00
										 |  |  | 		m_needSignals = true; | 
					
						
							| 
									
										
										
										
											2021-01-14 04:05:38 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-05 18:26:19 +01:00
										 |  |  | 	if (m_needSignals) { | 
					
						
							| 
									
										
										
										
											2021-01-14 17:08:13 -08:00
										 |  |  | 		// adjust all used font sizes
 | 
					
						
							|  |  |  | 		m_regularPointSize = m_basePointSize * newScale; | 
					
						
							|  |  |  | 		defaultModelFont().setPointSizeF(m_regularPointSize); | 
					
						
							|  |  |  | 		emit regularPointSizeChanged(); | 
					
						
							| 
									
										
										
										
											2020-01-14 19:30:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 17:08:13 -08:00
										 |  |  | 		m_headingPointSize = m_regularPointSize * 1.2; | 
					
						
							|  |  |  | 		emit headingPointSizeChanged(); | 
					
						
							| 
									
										
										
										
											2020-01-14 19:30:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 17:08:13 -08:00
										 |  |  | 		m_smallPointSize = m_regularPointSize * 0.8; | 
					
						
							|  |  |  | 		emit smallPointSizeChanged(); | 
					
						
							| 
									
										
										
										
											2020-01-14 19:30:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 17:08:13 -08:00
										 |  |  | 		m_titlePointSize = m_regularPointSize * 1.5; | 
					
						
							|  |  |  | 		emit titlePointSizeChanged(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 18:26:19 +01:00
										 |  |  | 		m_needSignals = false; | 
					
						
							| 
									
										
										
										
											2021-01-14 17:08:13 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-01-14 19:30:47 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 21:09:18 +02:00
										 |  |  | void ThemeInterface::update_theme() | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (m_currentTheme == "Blue") { | 
					
						
							| 
									
										
										
										
											2020-01-28 22:56:20 +01:00
										 |  |  | 		m_backgroundColor = BLUE_BACKGROUND_COLOR; | 
					
						
							|  |  |  | 		m_contrastAccentColor = BLUE_CONTRAST_ACCENT_COLOR; | 
					
						
							|  |  |  | 		m_darkerPrimaryColor = BLUE_DARKER_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_darkerPrimaryTextColor = BLUE_DARKER_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_drawerColor = BLUE_DRAWER_COLOR; | 
					
						
							|  |  |  | 		m_lightDrawerColor = BLUE_LIGHT_DRAWER_COLOR; | 
					
						
							|  |  |  | 		m_lightPrimaryColor = BLUE_LIGHT_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_lightPrimaryTextColor = BLUE_LIGHT_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_primaryColor = BLUE_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_primaryTextColor = BLUE_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_secondaryTextColor = BLUE_SECONDARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_textColor = BLUE_TEXT_COLOR; | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | 	} else if (m_currentTheme == "Pink") { | 
					
						
							| 
									
										
										
										
											2020-01-28 22:56:20 +01:00
										 |  |  | 		m_backgroundColor = PINK_BACKGROUND_COLOR; | 
					
						
							|  |  |  | 		m_contrastAccentColor = PINK_CONTRAST_ACCENT_COLOR; | 
					
						
							|  |  |  | 		m_darkerPrimaryColor = PINK_DARKER_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_darkerPrimaryTextColor = PINK_DARKER_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_drawerColor = PINK_DRAWER_COLOR; | 
					
						
							|  |  |  | 		m_lightDrawerColor = PINK_LIGHT_DRAWER_COLOR; | 
					
						
							|  |  |  | 		m_lightPrimaryColor = PINK_LIGHT_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_lightPrimaryTextColor = PINK_LIGHT_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_primaryColor = PINK_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_primaryTextColor = PINK_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_secondaryTextColor = PINK_SECONDARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_textColor = PINK_TEXT_COLOR; | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-01-28 22:56:20 +01:00
										 |  |  | 		m_backgroundColor = DARK_BACKGROUND_COLOR; | 
					
						
							|  |  |  | 		m_contrastAccentColor = DARK_CONTRAST_ACCENT_COLOR; | 
					
						
							|  |  |  | 		m_darkerPrimaryColor = DARK_DARKER_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_darkerPrimaryTextColor = DARK_DARKER_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_drawerColor = DARK_DRAWER_COLOR; | 
					
						
							|  |  |  | 		m_lightDrawerColor = DARK_LIGHT_DRAWER_COLOR; | 
					
						
							|  |  |  | 		m_lightPrimaryColor = DARK_LIGHT_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_lightPrimaryTextColor = DARK_LIGHT_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_primaryColor = DARK_PRIMARY_COLOR; | 
					
						
							|  |  |  | 		m_primaryTextColor = DARK_PRIMARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_secondaryTextColor = DARK_SECONDARY_TEXT_COLOR; | 
					
						
							|  |  |  | 		m_textColor = DARK_TEXT_COLOR; | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-03-30 21:20:49 +02:00
										 |  |  | 	emit backgroundColorChanged(); | 
					
						
							|  |  |  | 	emit contrastAccentColorChanged(); | 
					
						
							|  |  |  | 	emit darkerPrimaryColorChanged(); | 
					
						
							|  |  |  | 	emit darkerPrimaryTextColorChanged(); | 
					
						
							|  |  |  | 	emit drawerColorChanged(); | 
					
						
							|  |  |  | 	emit lightDrawerColorChanged(); | 
					
						
							|  |  |  | 	emit lightPrimaryColorChanged(); | 
					
						
							|  |  |  | 	emit lightPrimaryTextColorChanged(); | 
					
						
							|  |  |  | 	emit primaryColorChanged(); | 
					
						
							|  |  |  | 	emit primaryTextColorChanged(); | 
					
						
							|  |  |  | 	emit secondaryTextColorChanged(); | 
					
						
							|  |  |  | 	emit textColorChanged(); | 
					
						
							| 
									
										
										
										
											2019-02-11 16:13:01 +01:00
										 |  |  | } |