source: smplayer/vendor/current/src/hdpisupport.cpp

Last change on this file was 186, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update vendor to 17.1.0

File size: 3.3 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "hdpisupport.h"
20#include <QSettings>
21#include <QApplication>
22
23//#define DEBUG
24
25#ifdef DEBUG
26#include <QDebug>
27#endif
28
29HDPISupport * HDPISupport::instance_obj = 0;
30
31HDPISupport * HDPISupport::instance() {
32 if (instance_obj == 0) {
33 instance_obj = new HDPISupport();
34 }
35 return instance_obj;
36}
37
38HDPISupport::HDPISupport(const QString & config_path)
39#ifdef Q_OS_WIN
40 : enabled(true)
41#else
42 : enabled(false)
43#endif
44 , auto_scale(true)
45 , scale_factor(1)
46 , pixel_ratio(2)
47{
48 instance_obj = this;
49
50#ifdef HDPI_STORE_DATA
51 set = 0;
52 setConfigPath(config_path);
53#else
54 apply();
55#endif
56}
57
58HDPISupport::~HDPISupport() {
59#ifdef HDPI_STORE_DATA
60 if (set) {
61 save();
62 delete set;
63 }
64#endif
65 instance_obj = 0;
66}
67
68#ifdef HDPI_STORE_DATA
69void HDPISupport::setConfigPath(const QString & config_path) {
70 #ifdef DEBUG
71 qDebug() << "HDPISupport::setConfigPath:" << config_path;
72 #endif
73
74 if (set) {
75 delete set;
76 set = 0;
77 }
78
79 if (!config_path.isEmpty()) {
80 QString inifile = config_path + "/hdpi.ini";
81 #ifdef DEBUG
82 qDebug() << "HDPISupport::setConfigPath: ini file:" << inifile;
83 #endif
84 set = new QSettings(inifile, QSettings::IniFormat);
85 load();
86 }
87
88 apply();
89}
90
91bool HDPISupport::load() {
92 #ifdef DEBUG
93 qDebug("HDPISupport::load");
94 #endif
95
96 if (!set) return false;
97
98 set->beginGroup("hdpisupport");
99 enabled = set->value("enabled", enabled).toBool();
100 auto_scale = set->value("auto_scale", auto_scale).toBool();
101 scale_factor = set->value("scale_factor", scale_factor).toDouble();
102 pixel_ratio = set->value("pixel_ratio", pixel_ratio).toInt();
103 set->endGroup();
104
105 return true;
106}
107
108bool HDPISupport::save() {
109 #ifdef DEBUG
110 qDebug("HDPISupport::save");
111 #endif
112
113 if (!set) return false;
114
115 set->beginGroup("hdpisupport");
116 set->setValue("enabled", enabled);
117 set->setValue("auto_scale", auto_scale);
118 set->setValue("scale_factor", scale_factor);
119 set->setValue("pixel_ratio", pixel_ratio);
120 set->endGroup();
121
122 return true;
123}
124#endif
125
126void HDPISupport::apply() {
127 #ifdef DEBUG
128 qDebug("HDPISupport::apply");
129 #endif
130
131 if (enabled) {
132 #if QT_VERSION >= 0x050400 && QT_VERSION < 0x050600
133 if (qgetenv("QT_DEVICE_PIXEL_RATIO").isEmpty()) {
134 qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray("auto"));
135 }
136 if (!auto_scale) {
137 qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray::number(pixel_ratio));
138 }
139 #elif QT_VERSION >= 0x050600
140 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
141 if (!auto_scale) {
142 qputenv("QT_SCALE_FACTOR", QByteArray::number(scale_factor));
143 }
144 #endif
145 }
146}
Note: See TracBrowser for help on using the repository browser.