| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2018-07-25 10:49:48 -07:00
										 |  |  | #include "core/subsurface-string.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-14 12:25:15 +02:00
										 |  |  | #include "qPrefDisplay.h"
 | 
					
						
							| 
									
										
										
										
											2018-07-17 15:22:51 +02:00
										 |  |  | #include "qPrefPrivate.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QFont>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 15:22:51 +02:00
										 |  |  | static const QString group = QStringLiteral("Display"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | QPointF qPrefDisplay::st_tooltip_position; | 
					
						
							|  |  |  | static const QPointF st_tooltip_position_default = QPointF(0,0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString qPrefDisplay::st_lastDir; | 
					
						
							| 
									
										
										
										
											2019-04-01 23:17:17 +02:00
										 |  |  | static const QString st_lastDir_default; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | QString qPrefDisplay::st_theme; | 
					
						
							| 
									
										
										
										
											2019-04-01 23:15:23 +02:00
										 |  |  | static const QString st_theme_default = QStringLiteral("Blue"); | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | QByteArray qPrefDisplay::st_mainSplitter; | 
					
						
							| 
									
										
										
										
											2019-04-01 23:17:17 +02:00
										 |  |  | static const QByteArray st_mainSplitter_default; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | QByteArray qPrefDisplay::st_topSplitter; | 
					
						
							| 
									
										
										
										
											2019-04-01 23:17:17 +02:00
										 |  |  | static const QByteArray st_topSplitter_default; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | QByteArray qPrefDisplay::st_bottomSplitter; | 
					
						
							| 
									
										
										
										
											2019-04-01 23:17:17 +02:00
										 |  |  | static const QByteArray st_bottomSplitter_default; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool qPrefDisplay::st_maximized; | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | static bool st_maximized_default = false; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | QByteArray qPrefDisplay::st_geometry; | 
					
						
							| 
									
										
										
										
											2019-04-01 23:17:17 +02:00
										 |  |  | static const QByteArray st_geometry_default; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | QByteArray qPrefDisplay::st_windowState; | 
					
						
							| 
									
										
										
										
											2019-04-01 23:17:17 +02:00
										 |  |  | static const QByteArray st_windowState_default; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | int qPrefDisplay::st_lastState; | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | static int st_lastState_default = false; | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-08 11:08:03 -08:00
										 |  |  | bool qPrefDisplay::st_singleColumnPortrait; | 
					
						
							|  |  |  | static bool st_singleColumnPortrait_default = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | qPrefDisplay *qPrefDisplay::instance() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static qPrefDisplay *self = new qPrefDisplay; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qPrefDisplay::loadSync(bool doSync) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 	disk_animation_speed(doSync); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 	disk_divelist_font(doSync); | 
					
						
							|  |  |  | 	disk_font_size(doSync); | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 	disk_mobile_scale(doSync); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 	disk_display_invalid_dives(doSync); | 
					
						
							|  |  |  | 	disk_show_developer(doSync); | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 	if (!doSync) { | 
					
						
							|  |  |  | 		load_tooltip_position(); | 
					
						
							|  |  |  | 		load_theme(); | 
					
						
							| 
									
										
										
										
											2018-08-29 16:55:35 +02:00
										 |  |  | 		load_mainSplitter(); | 
					
						
							|  |  |  | 		load_topSplitter(); | 
					
						
							|  |  |  | 		load_bottomSplitter(); | 
					
						
							|  |  |  | 		load_maximized(); | 
					
						
							|  |  |  | 		load_geometry(); | 
					
						
							|  |  |  | 		load_windowState(); | 
					
						
							|  |  |  | 		load_lastState(); | 
					
						
							| 
									
										
										
										
											2020-02-08 11:08:03 -08:00
										 |  |  | 		load_singleColumnPortrait(); | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 10:49:48 -07:00
										 |  |  | void qPrefDisplay::set_divelist_font(const QString &value) | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QString newValue = value; | 
					
						
							|  |  |  | 	if (value.contains(",")) | 
					
						
							|  |  |  | 		newValue = value.left(value.indexOf(",")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (newValue != prefs.divelist_font && | 
					
						
							| 
									
										
										
										
											2018-07-25 10:49:48 -07:00
										 |  |  | 	    !subsurface_ignore_font(qPrintable(newValue))) { | 
					
						
							| 
									
										
										
										
											2018-07-18 20:47:59 +02:00
										 |  |  | 		qPrefPrivate::copy_txt(&prefs.divelist_font, value); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 		disk_divelist_font(true); | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		qApp->setFont(QFont(newValue)); | 
					
						
							| 
									
										
										
										
											2018-09-02 13:58:04 +02:00
										 |  |  | 		emit instance()->divelist_fontChanged(value); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | void qPrefDisplay::disk_divelist_font(bool doSync) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 	if (doSync) | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | 		qPrefPrivate::propSetValue(keyFromGroupAndName(group, "divelist_font"), prefs.divelist_font, default_prefs.divelist_font); | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | 		setCorrectFont(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void qPrefDisplay::set_font_size(double value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-25 12:28:53 +02:00
										 |  |  | 	if (!IS_FP_SAME(value, prefs.font_size)) { | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 		prefs.font_size = value; | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 		disk_font_size(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 		QFont defaultFont = qApp->font(); | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 		defaultFont.setPointSizeF(prefs.font_size * prefs.mobile_scale); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 		qApp->setFont(defaultFont); | 
					
						
							| 
									
										
										
										
											2018-09-02 13:58:04 +02:00
										 |  |  | 		emit instance()->font_sizeChanged(value); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | void qPrefDisplay::disk_font_size(bool doSync) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 	// inverted logic compared to the other disk_xxx functions
 | 
					
						
							|  |  |  | 	if (!doSync) | 
					
						
							|  |  |  | 		setCorrectFont(); | 
					
						
							|  |  |  | #if !defined(SUBSURFACE_MOBILE)
 | 
					
						
							|  |  |  | 	// we never want to save the font_size to disk - we always want to grab that from the system default
 | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 		qPrefPrivate::propSetValue(keyFromGroupAndName(group, "font_size"), prefs.font_size, default_prefs.font_size); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qPrefDisplay::set_mobile_scale(double value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!IS_FP_SAME(value, prefs.mobile_scale)) { | 
					
						
							|  |  |  | 		prefs.mobile_scale = value; | 
					
						
							|  |  |  | 		disk_mobile_scale(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		QFont defaultFont = qApp->font(); | 
					
						
							|  |  |  | 		defaultFont.setPointSizeF(prefs.font_size * prefs.mobile_scale); | 
					
						
							|  |  |  | 		qApp->setFont(defaultFont); | 
					
						
							|  |  |  | 		emit instance()->mobile_scaleChanged(value); | 
					
						
							|  |  |  | 		emit instance()->font_sizeChanged(value); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qPrefDisplay::disk_mobile_scale(bool doSync) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (doSync) { | 
					
						
							|  |  |  | 		qPrefPrivate::propSetValue(keyFromGroupAndName(group, "mobile_scale"), prefs.mobile_scale, default_prefs.mobile_scale); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		prefs.mobile_scale = qPrefPrivate::propValue(keyFromGroupAndName(group, "mobile_scale"), default_prefs.mobile_scale).toDouble(); | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | 		setCorrectFont(); | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | //JAN static const QString group = QStringLiteral("Animations");
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | HANDLE_PREFERENCE_INT(Display, "animation_speed", animation_speed); | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | HANDLE_PREFERENCE_BOOL(Display, "displayinvalid", display_invalid_dives); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | HANDLE_PREFERENCE_BOOL(Display, "show_developer", show_developer); | 
					
						
							| 
									
										
										
										
											2018-06-15 10:53:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | void qPrefDisplay::setCorrectFont() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// get the font from the settings or our defaults
 | 
					
						
							|  |  |  | 	// respect the system default font size if none is explicitly set
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | 	QFont defaultFont = qPrefPrivate::propValue(keyFromGroupAndName(group, "divelist_font"), prefs.divelist_font).value<QFont>(); | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | 	if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) { | 
					
						
							|  |  |  | 		prefs.font_size = qApp->font().pointSizeF(); | 
					
						
							|  |  |  | 		system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | 	prefs.font_size = qPrefPrivate::propValue(keyFromGroupAndName(group, "font_size"), prefs.font_size).toFloat(); | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | 	// painful effort to ignore previous default fonts on Windows - ridiculous
 | 
					
						
							|  |  |  | 	QString fontName = defaultFont.toString(); | 
					
						
							|  |  |  | 	if (fontName.contains(",")) | 
					
						
							|  |  |  | 		fontName = fontName.left(fontName.indexOf(",")); | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 	if (subsurface_ignore_font(qPrintable(fontName))) { | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | 		defaultFont = QFont(prefs.divelist_font); | 
					
						
							| 
									
										
										
										
											2018-07-15 10:27:35 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		free((void *)prefs.divelist_font); | 
					
						
							|  |  |  | 		prefs.divelist_font = copy_qstring(fontName); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-22 16:09:31 -07:00
										 |  |  | 	defaultFont.setPointSizeF(prefs.font_size * prefs.mobile_scale); | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | 	qApp->setFont(defaultFont); | 
					
						
							| 
									
										
										
										
											2018-07-18 22:52:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | 	prefs.display_invalid_dives = qPrefPrivate::propValue(keyFromGroupAndName(group, "displayinvalid"), default_prefs.display_invalid_dives).toBool(); | 
					
						
							| 
									
										
										
										
											2018-07-04 22:46:59 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-08-20 11:51:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QSTRING(Display, "FileDialog/LastDir", lastDir); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QSTRING(Display, "Theme/currentTheme", theme); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QPOINTF(Display, "ProfileMap/tooltip_position", tooltip_position); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/mainSplitter", mainSplitter); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/topSplitter", topSplitter); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/bottomSplitter", bottomSplitter); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_BOOL(Display, "MainWindow/maximized", maximized); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/geometry", geometry); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/windowState", windowState); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_INT(Display, "MainWindow/lastState", lastState); | 
					
						
							| 
									
										
										
										
											2020-02-08 11:08:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | HANDLE_PROP_BOOL(Display, "singleColumnPortrait", singleColumnPortrait); |