summaryrefslogtreecommitdiff
path: root/src/hdpisupport.cpp
diff options
context:
space:
mode:
authorMateusz Łukasik <mati75@linuxmint.pl>2016-06-15 20:23:58 +0200
committerMateusz Łukasik <mati75@linuxmint.pl>2016-06-15 20:23:58 +0200
commit42be0eb4f1d7a25dca97e8e2eb4ec4d03b7931fb (patch)
treefae3347b0c924378c57862feea2708766d159771 /src/hdpisupport.cpp
parent1a2f0c9c1087899a00298db8fa70518d3c1e69f8 (diff)
Imported Upstream version 16.6.0~ds0
Diffstat (limited to 'src/hdpisupport.cpp')
-rw-r--r--src/hdpisupport.cpp160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/hdpisupport.cpp b/src/hdpisupport.cpp
new file mode 100644
index 0000000..68bbf2e
--- /dev/null
+++ b/src/hdpisupport.cpp
@@ -0,0 +1,160 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "hdpisupport.h"
+#include <QSettings>
+#include <QApplication>
+
+#if QT_VERSION >= 0x050000
+#include <QStandardPaths>
+#else
+#include <QDesktopServices>
+#endif
+
+//#define DEBUG
+
+#ifdef DEBUG
+#include <QDebug>
+#endif
+
+HDPISupport * HDPISupport::instance_obj = 0;
+
+HDPISupport * HDPISupport::instance() {
+ if (instance_obj == 0) {
+ instance_obj = new HDPISupport();
+ }
+ return instance_obj;
+}
+
+HDPISupport::HDPISupport(const QString & config_path)
+#ifdef Q_OS_WIN
+ : enabled(true)
+#else
+ : enabled(false)
+#endif
+ , auto_scale(true)
+ , scale_factor(1)
+ , pixel_ratio(2)
+{
+ instance_obj = this;
+
+#ifdef HDPI_STORE_DATA
+ set = 0;
+ if (!config_path.isEmpty()) {
+ setConfigPath(config_path);
+ } else {
+ #if QT_VERSION >= 0x050000
+ setConfigPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
+ #else
+ setConfigPath(QDesktopServices::storageLocation(QDesktopServices::TempLocation));
+ #endif
+ }
+#else
+ apply();
+#endif
+}
+
+HDPISupport::~HDPISupport() {
+#ifdef HDPI_STORE_DATA
+ if (set) {
+ save();
+ delete set;
+ }
+#endif
+ instance_obj = 0;
+}
+
+#ifdef HDPI_STORE_DATA
+void HDPISupport::setConfigPath(const QString & config_path) {
+ #ifdef DEBUG
+ qDebug() << "HDPISupport::setConfigPath:" << config_path;
+ #endif
+
+ if (set) {
+ delete set;
+ set = 0;
+ }
+
+ if (!config_path.isEmpty()) {
+ ini_file = config_path + "/smplayerhdpi.ini";
+ #ifdef DEBUG
+ qDebug() << "HDPISupport::setConfigPath: ini file:" << ini_file;
+ #endif
+ set = new QSettings(ini_file, QSettings::IniFormat);
+ load();
+ }
+
+ apply();
+}
+
+bool HDPISupport::load() {
+ #ifdef DEBUG
+ qDebug("HDPISupport::load");
+ #endif
+
+ if (!set) return false;
+
+ set->beginGroup("hdpisupport");
+ enabled = set->value("enabled", enabled).toBool();
+ auto_scale = set->value("auto_scale", auto_scale).toBool();
+ scale_factor = set->value("scale_factor", scale_factor).toDouble();
+ pixel_ratio = set->value("pixel_ratio", pixel_ratio).toInt();
+ set->endGroup();
+
+ return true;
+}
+
+bool HDPISupport::save() {
+ #ifdef DEBUG
+ qDebug("HDPISupport::save");
+ #endif
+
+ if (!set) return false;
+
+ set->beginGroup("hdpisupport");
+ set->setValue("enabled", enabled);
+ set->setValue("auto_scale", auto_scale);
+ set->setValue("scale_factor", scale_factor);
+ set->setValue("pixel_ratio", pixel_ratio);
+ set->endGroup();
+
+ return true;
+}
+#endif
+
+void HDPISupport::apply() {
+ #ifdef DEBUG
+ qDebug("HDPISupport::apply");
+ #endif
+
+ if (enabled) {
+ #if QT_VERSION >= 0x050400 && QT_VERSION < 0x050600
+ if (qgetenv("QT_DEVICE_PIXEL_RATIO").isEmpty()) {
+ qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray("auto"));
+ }
+ if (!auto_scale) {
+ qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray::number(pixel_ratio));
+ }
+ #elif QT_VERSION >= 0x050600
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ if (!auto_scale) {
+ qputenv("QT_SCALE_FACTOR", QByteArray::number(scale_factor));
+ }
+ #endif
+ }
+}