Skip to content

Commit

Permalink
Merge pull request #2296 from MarcSabatella/gui-scaling
Browse files Browse the repository at this point in the history
fix gui scaling regressions for high DPI displays
  • Loading branch information
wschweer committed Jan 4, 2016
2 parents 313f17d + 3957c59 commit e842ec0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
14 changes: 8 additions & 6 deletions mscore/exampleview.cpp
Expand Up @@ -31,9 +31,10 @@ ExampleView::ExampleView(QWidget* parent)
_score = 0;
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
double mag = 1.0;
qreal _spatium = SPATIUM20;
_matrix = QTransform(mag, 0.0, 0.0, mag, _spatium, -_spatium * 6);
double mag = 0.9 * guiScaling * (DPI_DISPLAY / DPI); // 90% of nominal
qreal _spatium = SPATIUM20 * mag;
// example would normally be 10sp from top of page; this leaves 3sp margin above
_matrix = QTransform(mag, 0.0, 0.0, mag, _spatium, -_spatium * 7.0);
imatrix = _matrix.inverted();
}

Expand Down Expand Up @@ -336,9 +337,10 @@ void ExampleView::mousePressEvent(QMouseEvent* event)

QSize ExampleView::sizeHint() const
{
return QSize(
1000 * guiScaling * (DPI / 90),
80 * guiScaling * (DPI / 90));
qreal mag = 0.9 * guiScaling * (DPI_DISPLAY / DPI);
qreal _spatium = SPATIUM20 * mag;
// staff is 4sp tall with 3sp margin above; this leaves 3sp margin below
return QSize(1000 * mag, _spatium * 10.0);
}


Expand Down
5 changes: 3 additions & 2 deletions mscore/globals.h
Expand Up @@ -95,8 +95,9 @@ struct MidiRemote {

extern const char* stateName(ScoreState);

static constexpr qreal DPMM_DISPLAY = 4; // 100 DPI
static constexpr qreal PALETTE_SPATIUM = 1.9 * DPMM_DISPLAY;
static constexpr qreal DPI_DISPLAY = 96.0; // 96 DPI nominal resolution
static constexpr qreal DPMM_DISPLAY = DPI_DISPLAY / 25.4;
static constexpr qreal PALETTE_SPATIUM = 1.764 * DPMM_DISPLAY;

extern QPaintDevice* pdev;

Expand Down
18 changes: 16 additions & 2 deletions mscore/musescore.cpp
Expand Up @@ -130,7 +130,7 @@ bool externalIcons = false;
bool pluginMode = false;
static bool startWithNewScore = false;
double converterDpi = 0;
double guiScaling = 1.0;
double guiScaling = 0.0;
int trimMargin = -1;
bool noWebView = false;
bool exportScoreParts = false;
Expand Down Expand Up @@ -347,8 +347,22 @@ MuseScore::MuseScore()
: QMainWindow()
{
QScreen* screen = QGuiApplication::primaryScreen();
#if defined(Q_OS_WIN)
if (QSysInfo::WindowsVersion <= QSysInfo::WV_WINDOWS7)
_physicalDotsPerInch = screen->logicalDotsPerInch() * screen->devicePixelRatio();
else
_physicalDotsPerInch = screen->physicalDotsPerInch(); // physical resolution
#else
_physicalDotsPerInch = screen->physicalDotsPerInch(); // physical resolution
_physicalDotsPerInch *= guiScaling;
#endif
if (guiScaling == 0.0) {
// set scale for icons, palette elements, window sizes, etc
// the default values are hard coded in pixel sizes and assume ~96 DPI
if (qAbs(_physicalDotsPerInch - DPI_DISPLAY) > 6.0)
guiScaling = _physicalDotsPerInch / DPI_DISPLAY;
else
guiScaling = 1.0;
}

_sstate = STATE_INIT;
setWindowTitle(QString(MUSESCORE_NAME_VERSION));
Expand Down
6 changes: 3 additions & 3 deletions mscore/note_groups.ui
Expand Up @@ -47,7 +47,7 @@
<item row="1" column="2">
<widget class="Ms::ExampleView" name="view16">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -152,7 +152,7 @@
<item row="2" column="2">
<widget class="Ms::ExampleView" name="view32">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -238,7 +238,7 @@
<item row="0" column="2">
<widget class="Ms::ExampleView" name="view8">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down

0 comments on commit e842ec0

Please sign in to comment.