Merge lp:~jhodapp/qtubuntu/qtubuntu_add-live-orientation into lp:qtubuntu

Proposed by Jim Hodapp
Status: Merged
Approved by: Loïc Molinari
Approved revision: 120
Merged at revision: 119
Proposed branch: lp:~jhodapp/qtubuntu/qtubuntu_add-live-orientation
Merge into: lp:qtubuntu
Diff against target: 188 lines (+99/-5)
4 files modified
debian/control (+6/-2)
src/platforms/ubuntu/screen.cc (+77/-1)
src/platforms/ubuntu/screen.h (+15/-1)
src/platforms/ubuntu/ubuntu.pro (+1/-1)
To merge this branch: bzr merge lp:~jhodapp/qtubuntu/qtubuntu_add-live-orientation
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Loïc Molinari (community) Approve
Review via email: mp+150809@code.launchpad.net

Commit message

* Implements live orientation support for client applications using the QtSensors OrientationSensor backend.
* Add qtsensors5-dev as a package build dependency.
* Update the binary package dependencies to include the sensor related libraries.

Description of the change

* Implements live orientation support for client applications using the QtSensors OrientationSensor backend.
* Add qtsensors5-dev as a package build dependency.
* Update the binary package dependencies to include the sensor related libraries.

To post a comment you must log in.
118. By Jim Hodapp

Don't need to include QObject header file in base/screen.h

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
119. By Jim Hodapp

Fix compile error when setting debug config via: qmake CONFIG+=debug

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Loïc Molinari (loic.molinari) wrote :

Hi Jim,

That is good, code is working well.

I only have a few coding style remarks, it's not written anywhere in the project but QtUbuntu respects the coding guidelines from Google (http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml):

- Not sure about the "Depends" change in debian/control, might need to be validated by ricmm.

- No need to test for orientationSensor_ validity in ~QUbuntuScreen, just delete it. "delete" takes care of NULL pointers and the sensor is stopped in its destructor.

 - Add DLOGs in OrientationReadingEvent constructor and destructor as it's done in src/modules/application/application_image.cc for instance.

 - Add DLOGs in onOrientationReadingChanged() and customEvent() at the beginning as it's done in every other methods.

 - I think using a single switch in customEvent() would make the code easier to read and maintain (also Google coding guidelines recommend to use brackets for cases, 2 spaces indentation, 4 spaces line wrap), something like that:

  switch (oReadingEvent->orientation_) {
    case QOrientationReading::LeftUp: {
      currentOrientation_ = (nativeOrientation_ == Qt::LandscapeOrientation) ?
          Qt::InvertedPortraitOrientation : Qt::LandscapeOrientation;;
      break;
    }
    case ...
  }

 - QtUbuntu uses full include paths for Qt5 classes (QtCore/QObject, QtSensors/QOrientationSensor, QtGui/QScreen, QtCore/QThread, etc). If you don't know where a class is located, "find /usr/include/qt5 -name QFoo" can help you.

 - Open curly brace should be on the same line than the last parameter of a function or the last initialization parameter of a constructor (see lines 47, 87, 98 and 143 in screen.cc). Google coding guidelines recommend Egyptian brackets (http://www.codinghorror.com/blog/2012/07/new-programming-jargon.html).

 - "Qt::ScreenOrientation QUbuntuScreen::orientation() const" should be defined in the header.

 - Bad indentation in QUbuntuScreen: QOBJECT macro and methods should be indented 2 spaces, private, public and protected keywords should be indented 1 space.

 - For pointer declarations, space is following the asterisk.

 - I'd remove the comment on line 73 in screen.cc, code is explicit enough.

review: Needs Fixing
120. By Jim Hodapp

Code [style] cleanup per a merge request review by loicm.

Revision history for this message
Loïc Molinari (loic.molinari) wrote :

Excellent, thanks.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-02-12 16:56:42 +0000
3+++ debian/control 2013-03-01 14:53:21 +0000
4@@ -15,7 +15,8 @@
5 libfontconfig1-dev,
6 libfreetype6-dev,
7 libdbus-1-dev,
8- libatspi2.0-dev
9+ libatspi2.0-dev,
10+ qtsensors5-dev
11 Standards-Version: 3.9.3
12 Section: libs
13
14@@ -24,7 +25,10 @@
15 Breaks: qthybris (<< 0.37)
16 Section: libs
17 Architecture: armel armhf
18-Depends: ${shlibs:Depends}, ${misc:Depends}
19+Depends: ${shlibs:Depends}, ${misc:Depends},
20+ libqt5sensors5,
21+ qtubuntu-sensors[armel],
22+ qtubuntu-sensors[armhf],
23 Description: Qt plugins for Ubuntu Platform API
24 QtUbuntu is a set of Qt5 components for the Ubuntu Platform API. It
25 contains a QPA (Qt Platform Abstraction) plugin based on the Ubuntu
26
27=== modified file 'src/platforms/ubuntu/screen.cc'
28--- src/platforms/ubuntu/screen.cc 2013-02-26 01:03:00 +0000
29+++ src/platforms/ubuntu/screen.cc 2013-03-01 14:53:21 +0000
30@@ -17,9 +17,32 @@
31
32 #include "screen.h"
33 #include "base/logging.h"
34+#include <QtCore/QCoreApplication>
35 #include <QtCore/qmath.h>
36+#include <QtSensors/QOrientationSensor>
37+#include <QtSensors/QOrientationReading>
38+#include <QtGui/QScreen>
39+#include <QtCore/QThread>
40+#include <qpa/qwindowsysteminterface.h>
41 #include <ubuntu/application/ui/ubuntu_application_ui.h>
42
43+class OrientationReadingEvent : public QEvent {
44+ public:
45+ OrientationReadingEvent(QEvent::Type type, QOrientationReading::Orientation orientation)
46+ : QEvent(type)
47+ , orientation_(orientation) {
48+ DLOG("OrientationReadingEvent::OrientationReadingEvent()");
49+ }
50+ ~OrientationReadingEvent() {
51+ DLOG("OrientationReadingEvent::~OrientationReadingEvent()");
52+ }
53+ static const QEvent::Type type_;
54+ QOrientationReading::Orientation orientation_;
55+};
56+
57+const QEvent::Type OrientationReadingEvent::type_ =
58+ static_cast<QEvent::Type>(QEvent::registerEventType());
59+
60 // Grid unit used if GRID_UNIT_PX is not in the environment.
61 const int kDefaultGridUnit = 8;
62
63@@ -79,11 +102,20 @@
64 DLOG("QUbuntuScreen::QUbuntuScreen (this=%p)", this);
65
66 // Set the default orientation based on the initial screen dimmensions.
67- nativeOrientation_ = kScreenWidth >= kScreenHeight ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
68+ nativeOrientation_ = (kScreenWidth >= kScreenHeight) ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
69+
70+ // If it's a landscape device (i.e. some tablets), start in landscape, otherwise portrait
71+ currentOrientation_ = (nativeOrientation_ == Qt::LandscapeOrientation) ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
72+
73+ orientationSensor_ = new QOrientationSensor();
74+ QObject::connect(orientationSensor_, SIGNAL(readingChanged()), this, SLOT(onOrientationReadingChanged()));
75+ orientationSensor_->start();
76 }
77
78 QUbuntuScreen::~QUbuntuScreen() {
79 DLOG("QUbuntuScreen::~QUbuntuScreen");
80+
81+ delete orientationSensor_;
82 }
83
84 int QUbuntuScreen::gridUnitToPixel(int value) const {
85@@ -100,3 +132,47 @@
86 return static_cast<int>(qRound(value * densityPixelRatio_));
87 }
88 }
89+
90+void QUbuntuScreen::customEvent(QEvent* event) {
91+ DLOG("QUbuntuScreen::customEvent (event: %p)", event);
92+ DASSERT(QThread::currentThread() == thread());
93+
94+ OrientationReadingEvent* oReadingEvent = static_cast<OrientationReadingEvent*>(event);
95+ switch (oReadingEvent->orientation_) {
96+ case QOrientationReading::LeftUp: {
97+ currentOrientation_ = (nativeOrientation_ == Qt::LandscapeOrientation) ?
98+ Qt::InvertedPortraitOrientation : Qt::LandscapeOrientation;
99+ break;
100+ }
101+ case QOrientationReading::TopUp: {
102+ currentOrientation_ = (nativeOrientation_ == Qt::LandscapeOrientation) ?
103+ Qt::LandscapeOrientation : Qt::PortraitOrientation;
104+ break;
105+ }
106+ case QOrientationReading::RightUp: {
107+ currentOrientation_ = (nativeOrientation_ == Qt::LandscapeOrientation) ?
108+ Qt::PortraitOrientation : Qt::InvertedLandscapeOrientation;
109+ break;
110+ }
111+ case QOrientationReading::TopDown: {
112+ currentOrientation_ = (nativeOrientation_ == Qt::LandscapeOrientation) ?
113+ Qt::InvertedLandscapeOrientation : Qt::InvertedPortraitOrientation;
114+ break;
115+ }
116+ default: {
117+ DLOG("Unknown orientation.");
118+ }
119+ }
120+
121+ // Raise the event signal so that client apps know the orientation changed
122+ QWindowSystemInterface::handleScreenOrientationChange(screen(), currentOrientation_);
123+}
124+
125+void QUbuntuScreen::onOrientationReadingChanged() {
126+ DLOG("QUbuntuScreen::onOrientationReadingChanged");
127+ DASSERT(orientationSensor_ != NULL);
128+
129+ // Make sure to switch to the main Qt thread context
130+ QCoreApplication::postEvent(this, new OrientationReadingEvent(
131+ OrientationReadingEvent::type_, orientationSensor_->reading()->orientation()));
132+}
133
134=== modified file 'src/platforms/ubuntu/screen.h'
135--- src/platforms/ubuntu/screen.h 2013-02-14 16:31:33 +0000
136+++ src/platforms/ubuntu/screen.h 2013-03-01 14:53:21 +0000
137@@ -18,7 +18,12 @@
138
139 #include "base/screen.h"
140
141-class QUbuntuScreen : public QUbuntuBaseScreen {
142+#include <QObject>
143+
144+class QOrientationSensor;
145+
146+class QUbuntuScreen : public QObject, public QUbuntuBaseScreen {
147+ Q_OBJECT
148 public:
149 QUbuntuScreen();
150 ~QUbuntuScreen();
151@@ -28,15 +33,24 @@
152 QRect availableGeometry() const { return availableGeometry_; }
153
154 Qt::ScreenOrientation nativeOrientation() const { return nativeOrientation_; }
155+ Qt::ScreenOrientation orientation() const { return currentOrientation_; }
156 int gridUnitToPixel(int value) const;
157 int densityPixelToPixel(int value) const;
158
159+ // QObject methods.
160+ void customEvent(QEvent* event);
161+
162+ public Q_SLOTS:
163+ void onOrientationReadingChanged();
164+
165 private:
166 QRect geometry_;
167 QRect availableGeometry_;
168 int gridUnit_;
169 float densityPixelRatio_;
170 Qt::ScreenOrientation nativeOrientation_;
171+ Qt::ScreenOrientation currentOrientation_;
172+ QOrientationSensor* orientationSensor_;
173 };
174
175 #endif // QUBUNTUSCREEN_H
176
177=== modified file 'src/platforms/ubuntu/ubuntu.pro'
178--- src/platforms/ubuntu/ubuntu.pro 2013-02-07 13:54:11 +0000
179+++ src/platforms/ubuntu/ubuntu.pro 2013-03-01 14:53:21 +0000
180@@ -1,7 +1,7 @@
181 TARGET = qubuntu
182 TEMPLATE = lib
183
184-QT += core-private gui-private platformsupport-private
185+QT += core-private gui-private platformsupport-private sensors-private
186
187 DEFINES += MESA_EGL_NO_X11_HEADERS
188 QMAKE_CXXFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden

Subscribers

People subscribed via source and target branches