-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathuicontextconfiguration.cpp
More file actions
85 lines (72 loc) · 2.25 KB
/
uicontextconfiguration.cpp
File metadata and controls
85 lines (72 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2026 MuseScore Limited and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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, see <https://www.gnu.org/licenses/>.
*/
#include "uicontextconfiguration.h"
#include <QApplication>
#include <QScreen>
#ifdef Q_OS_WIN
#include <QOperatingSystemVersion>
#endif
using namespace muse::ui;
constexpr double DEFAULT_DPI = 96;
QScreen* UiContextConfiguration::screen() const
{
if (!mainWindow()) {
return QApplication::primaryScreen();
}
return mainWindow()->screen();
}
double UiContextConfiguration::guiScaling() const
{
const QScreen* s = screen();
return s ? s->devicePixelRatio() : 1;
}
double UiContextConfiguration::physicalDpi() const
{
if (configuration()->customPhysicalDotsPerInch()) {
return configuration()->customPhysicalDotsPerInch().value();
}
const QScreen* screen = this->screen();
if (!screen) {
return DEFAULT_DPI;
}
auto physicalSize = screen->physicalSize();
// Work around xrandr reporting a 1x1mm size if
// the screen doesn't have a valid physical size
if (physicalSize.height() <= 1 && physicalSize.width() <= 1) {
return DEFAULT_DPI;
}
#ifdef Q_OS_WIN
//! NOTE: copied from MU3, `MuseScore::MuseScore()`
if (QOperatingSystemVersion::current() <= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 7)) {
return screen->logicalDotsPerInch() * screen->devicePixelRatio();
}
#endif
return screen->physicalDotsPerInch();
}
double UiContextConfiguration::logicalDpi() const
{
const QScreen* screen = this->screen();
if (!screen) {
return DEFAULT_DPI;
}
return screen->logicalDotsPerInch();
}