-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q scale factor from preferences #3960
Changes from 12 commits
a147a63
6fe8dfe
3a41380
ca9e1b8
efbfb27
27e66c9
3cbfba0
6bb1451
a6942b5
2aee818
72cd0b3
03422cd
d3fabee
28581b9
46182d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#include <QApplication> | ||
#include <QDir> | ||
#include <QSettings> | ||
#include <QString> | ||
#include <QStringList> | ||
#include <QTextCodec> | ||
#include <QThread> | ||
#include <QtDebug> | ||
|
||
#include "config.h" | ||
#include "coreservices.h" | ||
#include "errordialoghandler.h" | ||
#include "mixxxapplication.h" | ||
|
@@ -22,6 +24,9 @@ namespace { | |
constexpr int kFatalErrorOnStartupExitCode = 1; | ||
constexpr int kParseCmdlineArgsErrorExitCode = 2; | ||
|
||
constexpr char kScaleFactorEnvVar[] = "QT_SCALE_FACTOR"; | ||
const QString kScaleFactorConfigKey = QStringLiteral("ScaleFactor"); | ||
|
||
int runMixxx(MixxxApplication* pApp, const CmdlineArgs& args) { | ||
const auto pCoreServices = std::make_shared<mixxx::CoreServices>(args, pApp); | ||
|
||
|
@@ -48,6 +53,41 @@ int runMixxx(MixxxApplication* pApp, const CmdlineArgs& args) { | |
} | ||
} | ||
|
||
void adjustScaleFactor(CmdlineArgs* pArgs) { | ||
if (qEnvironmentVariableIsSet(kScaleFactorEnvVar)) { | ||
bool ok; | ||
const double f = qgetenv(kScaleFactorEnvVar).toDouble(&ok); | ||
if (ok && f > 0) { | ||
// The environment variable overrides the preferences option | ||
qDebug() << "Using" << kScaleFactorEnvVar << f; | ||
pArgs->storeScaleFactor(f); | ||
return; | ||
} | ||
} | ||
// We cannot use ConfigObject, because it depends on MixxxApplication | ||
// but the scale factor is read during it's constructor. | ||
// QHighDpiScaling can not be used afterwards because it is private. | ||
auto cfgFile = QFile(QDir(pArgs->getSettingsPath()).filePath(MIXXX_SETTINGS_FILE)); | ||
if (cfgFile.open(QFile::ReadOnly | QFile::Text)) { | ||
QTextStream in(&cfgFile); | ||
QString strScaleFactor; | ||
QString line = in.readLine(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better use |
||
while (!line.isNull()) { | ||
if (line.startsWith(kScaleFactorConfigKey)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, unfortunately the attempt failed because QSettings expects a "=" between key and value, which is not used in our ini file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. It looks like only the constructor depends on QApplication to construct file paths. Can you just add a ConfigObject static method like |
||
strScaleFactor = line.mid(kScaleFactorConfigKey.size() + 1); | ||
break; | ||
} | ||
line = in.readLine(); | ||
} | ||
double scaleFactor = strScaleFactor.toDouble(); | ||
if (scaleFactor > 0) { | ||
qDebug() << "Using preferences ScaleFactor" << scaleFactor; | ||
qputenv(kScaleFactorEnvVar, strScaleFactor.toLocal8Bit()); | ||
pArgs->storeScaleFactor(scaleFactor); | ||
} | ||
} | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
int main(int argc, char * argv[]) { | ||
|
@@ -99,6 +139,8 @@ int main(int argc, char * argv[]) { | |
Sandbox::checkSandboxed(); | ||
#endif | ||
|
||
adjustScaleFactor(&args); | ||
|
||
MixxxApplication app(argc, argv); | ||
|
||
#ifdef __APPLE__ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QSettings seems to be unused and a left-over from previous experiments?