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
=== modified file 'src/Ubuntu/Components/plugin/uclabel.cpp'
--- src/Ubuntu/Components/plugin/uclabel.cpp 2015-12-07 12:09:45 +0000
+++ src/Ubuntu/Components/plugin/uclabel.cpp 2016-02-03 16:00:05 +0000
@@ -101,6 +101,7 @@
101101
102 connect(this, &UCLabel::fontChanged, this, &UCLabel::_q_updateFontFlag, Qt::DirectConnection);102 connect(this, &UCLabel::fontChanged, this, &UCLabel::_q_updateFontFlag, Qt::DirectConnection);
103 connect(this, &UCLabel::colorChanged, this, &UCLabel::_q_customColor, Qt::DirectConnection);103 connect(this, &UCLabel::colorChanged, this, &UCLabel::_q_customColor, Qt::DirectConnection);
104 connect(&UCUnits::instance(), &UCUnits::gridUnitChanged, this, &UCLabel::updatePixelSize, Qt::DirectConnection);
104}105}
105106
106void UCLabel::postThemeChanged()107void UCLabel::postThemeChanged()
107108
=== modified file 'src/Ubuntu/Components/plugin/uclabel.h'
--- src/Ubuntu/Components/plugin/uclabel.h 2015-10-20 10:19:10 +0000
+++ src/Ubuntu/Components/plugin/uclabel.h 2016-02-03 16:00:05 +0000
@@ -73,7 +73,7 @@
73 void fontSizeChanged();73 void fontSizeChanged();
7474
75private:75private:
76 void updatePixelSize();76 Q_SLOT void updatePixelSize();
77 Q_SLOT void _q_updateFontFlag(const QFont &font);77 Q_SLOT void _q_updateFontFlag(const QFont &font);
78 Q_SLOT void _q_customColor();78 Q_SLOT void _q_customColor();
7979
8080
=== modified file 'src/Ubuntu/Components/plugin/ucunits.cpp'
--- src/Ubuntu/Components/plugin/ucunits.cpp 2015-07-10 14:58:54 +0000
+++ src/Ubuntu/Components/plugin/ucunits.cpp 2016-02-03 16:00:05 +0000
@@ -27,6 +27,12 @@
27#include <QtGui/QGuiApplication>27#include <QtGui/QGuiApplication>
28#include <QtGui/QScreen>28#include <QtGui/QScreen>
2929
30#include <QtGui/qpa/qplatformnativeinterface.h>
31#include <QtGui/qpa/qplatformwindow.h>
32#include <QtGui/qpa/qplatformscreen.h>
33
34#include <QDebug>
35
30#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"36#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"
31#define DEFAULT_GRID_UNIT_PX 837#define DEFAULT_GRID_UNIT_PX 8
3238
@@ -104,6 +110,10 @@
104 } else {110 } else {
105 m_gridUnit = DEFAULT_GRID_UNIT_PX * m_devicePixelRatio;111 m_gridUnit = DEFAULT_GRID_UNIT_PX * m_devicePixelRatio;
106 }112 }
113
114 auto nativeInterface = qGuiApp->platformNativeInterface();
115 QObject::connect(nativeInterface, &QPlatformNativeInterface::windowPropertyChanged,
116 this, &UCUnits::windowPropertyChanged);
107}117}
108118
109/*!119/*!
@@ -118,8 +128,12 @@
118128
119void UCUnits::setGridUnit(float gridUnit)129void UCUnits::setGridUnit(float gridUnit)
120{130{
131 if (qFuzzyCompare(gridUnit, m_gridUnit)) {
132 return;
133 }
121 m_gridUnit = gridUnit;134 m_gridUnit = gridUnit;
122 Q_EMIT gridUnitChanged();135 Q_EMIT gridUnitChanged();
136 qDebug() << "GRID UNIT changed to " << m_gridUnit;
123}137}
124138
125/*!139/*!
@@ -239,3 +253,33 @@
239 return 0;253 return 0;
240 }254 }
241}255}
256
257void UCUnits::windowPropertyChanged(QPlatformWindow *window, const QString &propertyName)
258{
259 if (propertyName != QStringLiteral("scale")) { //don't care otherwise
260 return;
261 }
262
263 // I've no idea what my window is, but any messages I get should only be about my window!
264
265 // HACK - if multimonitor situation, ignore any scale changes reported by the LVDS screen (unity8-specific policy)
266 if (qGuiApp->allWindows().count() > 1) {
267 if (window && window->screen()
268 && window->screen()->name().contains("LVDS")) {
269 return;
270 }
271 }
272
273 auto nativeInterface = qGuiApp->platformNativeInterface();
274 QVariant scaleVal = nativeInterface->windowProperty(window, "scale");
275 if (!scaleVal.isValid()) {
276 return;
277 }
278 bool ok;
279 float scale = scaleVal.toFloat(&ok);
280 if (!ok || scale <= 0) {
281 return;
282 }
283 // choose integral grid unit value closest to requested scale
284 setGridUnit(qCeil(scale * DEFAULT_GRID_UNIT_PX) * m_devicePixelRatio);
285}
242286
=== modified file 'src/Ubuntu/Components/plugin/ucunits.h'
--- src/Ubuntu/Components/plugin/ucunits.h 2015-05-22 18:51:25 +0000
+++ src/Ubuntu/Components/plugin/ucunits.h 2016-02-03 16:00:05 +0000
@@ -21,8 +21,10 @@
2121
22#include <QObject>22#include <QObject>
23#include <QtCore/QHash>23#include <QtCore/QHash>
24#include <QtCore/QString>
24#include <QtCore/QUrl>25#include <QtCore/QUrl>
2526
27class QPlatformWindow;
26class UCUnits : public QObject28class UCUnits : public QObject
27{29{
28 Q_OBJECT30 Q_OBJECT
@@ -52,6 +54,9 @@
52 QString suffixForGridUnit(float gridUnit);54 QString suffixForGridUnit(float gridUnit);
53 float gridUnitSuffixFromFileName(const QString &fileName);55 float gridUnitSuffixFromFileName(const QString &fileName);
5456
57private Q_SLOTS:
58 void windowPropertyChanged(QPlatformWindow *window, const QString &propertyName);
59
55private:60private:
56 float m_devicePixelRatio;61 float m_devicePixelRatio;
57 float m_gridUnit;62 float m_gridUnit;

Subscribers

People subscribed via source and target branches

to status/vote changes: