Merge lp:~gerboland/ubuntu-ui-toolkit/dynamic-grid-unit into lp:ubuntu-ui-toolkit

Proposed by Gerry Boland
Status: Superseded
Proposed branch: lp:~gerboland/ubuntu-ui-toolkit/dynamic-grid-unit
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 124 lines (+51/-1)
4 files modified
src/Ubuntu/Components/plugin/uclabel.cpp (+1/-0)
src/Ubuntu/Components/plugin/uclabel.h (+1/-1)
src/Ubuntu/Components/plugin/ucunits.cpp (+44/-0)
src/Ubuntu/Components/plugin/ucunits.h (+5/-0)
To merge this branch: bzr merge lp:~gerboland/ubuntu-ui-toolkit/dynamic-grid-unit
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu SDK team Pending
Review via email: mp+284827@code.launchpad.net

This proposal has been superseded by a proposal from 2016-04-20.

Commit message

Enable dynamic changing of grid units instigated by the shell

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/Components/plugin/uclabel.cpp'
2--- src/Ubuntu/Components/plugin/uclabel.cpp 2015-12-07 12:09:45 +0000
3+++ src/Ubuntu/Components/plugin/uclabel.cpp 2016-02-03 16:00:05 +0000
4@@ -101,6 +101,7 @@
5
6 connect(this, &UCLabel::fontChanged, this, &UCLabel::_q_updateFontFlag, Qt::DirectConnection);
7 connect(this, &UCLabel::colorChanged, this, &UCLabel::_q_customColor, Qt::DirectConnection);
8+ connect(&UCUnits::instance(), &UCUnits::gridUnitChanged, this, &UCLabel::updatePixelSize, Qt::DirectConnection);
9 }
10
11 void UCLabel::postThemeChanged()
12
13=== modified file 'src/Ubuntu/Components/plugin/uclabel.h'
14--- src/Ubuntu/Components/plugin/uclabel.h 2015-10-20 10:19:10 +0000
15+++ src/Ubuntu/Components/plugin/uclabel.h 2016-02-03 16:00:05 +0000
16@@ -73,7 +73,7 @@
17 void fontSizeChanged();
18
19 private:
20- void updatePixelSize();
21+ Q_SLOT void updatePixelSize();
22 Q_SLOT void _q_updateFontFlag(const QFont &font);
23 Q_SLOT void _q_customColor();
24
25
26=== modified file 'src/Ubuntu/Components/plugin/ucunits.cpp'
27--- src/Ubuntu/Components/plugin/ucunits.cpp 2015-07-10 14:58:54 +0000
28+++ src/Ubuntu/Components/plugin/ucunits.cpp 2016-02-03 16:00:05 +0000
29@@ -27,6 +27,12 @@
30 #include <QtGui/QGuiApplication>
31 #include <QtGui/QScreen>
32
33+#include <QtGui/qpa/qplatformnativeinterface.h>
34+#include <QtGui/qpa/qplatformwindow.h>
35+#include <QtGui/qpa/qplatformscreen.h>
36+
37+#include <QDebug>
38+
39 #define ENV_GRID_UNIT_PX "GRID_UNIT_PX"
40 #define DEFAULT_GRID_UNIT_PX 8
41
42@@ -104,6 +110,10 @@
43 } else {
44 m_gridUnit = DEFAULT_GRID_UNIT_PX * m_devicePixelRatio;
45 }
46+
47+ auto nativeInterface = qGuiApp->platformNativeInterface();
48+ QObject::connect(nativeInterface, &QPlatformNativeInterface::windowPropertyChanged,
49+ this, &UCUnits::windowPropertyChanged);
50 }
51
52 /*!
53@@ -118,8 +128,12 @@
54
55 void UCUnits::setGridUnit(float gridUnit)
56 {
57+ if (qFuzzyCompare(gridUnit, m_gridUnit)) {
58+ return;
59+ }
60 m_gridUnit = gridUnit;
61 Q_EMIT gridUnitChanged();
62+ qDebug() << "GRID UNIT changed to " << m_gridUnit;
63 }
64
65 /*!
66@@ -239,3 +253,33 @@
67 return 0;
68 }
69 }
70+
71+void UCUnits::windowPropertyChanged(QPlatformWindow *window, const QString &propertyName)
72+{
73+ if (propertyName != QStringLiteral("scale")) { //don't care otherwise
74+ return;
75+ }
76+
77+ // I've no idea what my window is, but any messages I get should only be about my window!
78+
79+ // HACK - if multimonitor situation, ignore any scale changes reported by the LVDS screen (unity8-specific policy)
80+ if (qGuiApp->allWindows().count() > 1) {
81+ if (window && window->screen()
82+ && window->screen()->name().contains("LVDS")) {
83+ return;
84+ }
85+ }
86+
87+ auto nativeInterface = qGuiApp->platformNativeInterface();
88+ QVariant scaleVal = nativeInterface->windowProperty(window, "scale");
89+ if (!scaleVal.isValid()) {
90+ return;
91+ }
92+ bool ok;
93+ float scale = scaleVal.toFloat(&ok);
94+ if (!ok || scale <= 0) {
95+ return;
96+ }
97+ // choose integral grid unit value closest to requested scale
98+ setGridUnit(qCeil(scale * DEFAULT_GRID_UNIT_PX) * m_devicePixelRatio);
99+}
100
101=== modified file 'src/Ubuntu/Components/plugin/ucunits.h'
102--- src/Ubuntu/Components/plugin/ucunits.h 2015-05-22 18:51:25 +0000
103+++ src/Ubuntu/Components/plugin/ucunits.h 2016-02-03 16:00:05 +0000
104@@ -21,8 +21,10 @@
105
106 #include <QObject>
107 #include <QtCore/QHash>
108+#include <QtCore/QString>
109 #include <QtCore/QUrl>
110
111+class QPlatformWindow;
112 class UCUnits : public QObject
113 {
114 Q_OBJECT
115@@ -52,6 +54,9 @@
116 QString suffixForGridUnit(float gridUnit);
117 float gridUnitSuffixFromFileName(const QString &fileName);
118
119+private Q_SLOTS:
120+ void windowPropertyChanged(QPlatformWindow *window, const QString &propertyName);
121+
122 private:
123 float m_devicePixelRatio;
124 float m_gridUnit;

Subscribers

People subscribed via source and target branches

to status/vote changes: