Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lipstick] Use QOrientationSensor to get updates about current device or... #90

Merged
merged 1 commit into from Oct 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpm/lipstick-qt5.spec
Expand Up @@ -21,12 +21,12 @@ Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Gui)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(Qt5Xml)
BuildRequires: pkgconfig(Qt5Sql)
BuildRequires: pkgconfig(Qt5SystemInfo)
BuildRequires: pkgconfig(Qt5Test)
BuildRequires: pkgconfig(Qt5Sensors)
BuildRequires: pkgconfig(contentaction5)
BuildRequires: pkgconfig(mlite5) >= 0.0.6
BuildRequires: pkgconfig(mce) >= 1.12.2
Expand Down
42 changes: 42 additions & 0 deletions src/compositor/lipstickcompositor.cpp
Expand Up @@ -19,6 +19,7 @@

#include <QWaylandInputDevice>
#include <QDesktopServices>
#include <QtSensors/QOrientationSensor>
#include "homeapplication.h"
#include "windowmodel.h"
#include "lipstickcompositorprocwindow.h"
Expand All @@ -40,6 +41,14 @@ LipstickCompositor::LipstickCompositor()
connect(m_displayState, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)), this, SLOT(reactOnDisplayStateChanges(MeeGo::QmDisplayState::DisplayState)));
QObject::connect(HomeApplication::instance(), SIGNAL(aboutToDestroy()), this, SLOT(homeApplicationAboutToDestroy()));

m_orientationSensor = new QOrientationSensor(this);
QObject::connect(m_orientationSensor, SIGNAL(readingChanged()), this, SLOT(setScreenOrientationFromSensor()));
if (!m_orientationSensor->connectToBackend()) {
qWarning() << "Could not connect to the orientation sensor backend";
} else {
if (!m_orientationSensor->start())
qWarning() << "Could not start the orientation sensor";
}
emit HomeApplication::instance()->homeActiveChanged();

QDesktopServices::setUrlHandler("http", this, "openUrl");
Expand Down Expand Up @@ -460,6 +469,10 @@ QQmlComponent *LipstickCompositor::shaderEffectComponent()
void LipstickCompositor::setScreenOrientation(Qt::ScreenOrientation screenOrientation)
{
if (m_screenOrientation != screenOrientation) {

if (debug())
qDebug() << "Setting screen orientation on QWaylandCompositor";

QWaylandCompositor::setScreenOrientation(screenOrientation);

m_screenOrientation = screenOrientation;
Expand All @@ -475,3 +488,32 @@ void LipstickCompositor::reactOnDisplayStateChanges(MeeGo::QmDisplayState::Displ
emit displayOff();
}
}

void LipstickCompositor::setScreenOrientationFromSensor()
{
QOrientationReading* reading = m_orientationSensor->reading();

if (debug())
qDebug() << "Screen orientation changed " << reading->orientation();

switch (reading->orientation()) {
case QOrientationReading::TopUp:
setScreenOrientation(Qt::PortraitOrientation);
break;
case QOrientationReading::TopDown:
setScreenOrientation(Qt::InvertedPortraitOrientation);
break;
case QOrientationReading::LeftUp:
setScreenOrientation(Qt::InvertedLandscapeOrientation);
break;
case QOrientationReading::RightUp:
setScreenOrientation(Qt::LandscapeOrientation);
break;
case QOrientationReading::Undefined:
case QOrientationReading::FaceUp:
case QOrientationReading::FaceDown:
default:
setScreenOrientation(Qt::PrimaryOrientation);
break;
}
}
3 changes: 3 additions & 0 deletions src/compositor/lipstickcompositor.h
Expand Up @@ -26,6 +26,7 @@
class WindowModel;
class LipstickCompositorWindow;
class LipstickCompositorProcWindow;
class QOrientationSensor;

class LIPSTICK_EXPORT LipstickCompositor : public QQuickWindow, public QWaylandCompositor,
public QQmlParserStatus
Expand Down Expand Up @@ -121,6 +122,7 @@ private slots:
void openUrl(const QUrl &);
void reactOnDisplayStateChanges(MeeGo::QmDisplayState::DisplayState state);
void homeApplicationAboutToDestroy();
void setScreenOrientationFromSensor();

private:
friend class LipstickCompositorWindow;
Expand Down Expand Up @@ -157,6 +159,7 @@ private slots:
Qt::ScreenOrientation m_screenOrientation;
MeeGo::QmDisplayState *m_displayState;
QAtomicInt m_updateRequestPosted;
QOrientationSensor* m_orientationSensor;
};

#endif // LIPSTICKCOMPOSITOR_H
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -116,7 +116,7 @@ packagesExist(contextkit-statefs) {
warning("Contextsubscriber not found")
}

QT += dbus xml qml quick sql gui gui-private
QT += dbus xml qml quick sql gui gui-private sensors

QMAKE_CXXFLAGS += \
-Werror \
Expand Down
9 changes: 8 additions & 1 deletion tests/stubs/lipstickcompositor_stub.h
Expand Up @@ -46,6 +46,7 @@ class LipstickCompositorStub : public StubBase {
virtual void windowDestroyed();
virtual void windowPropertyChanged(const QString &);
virtual void reactOnDisplayStateChanges(MeeGo::QmDisplayState::DisplayState);
virtual void setScreenOrientationFromSensor();
};

// 2. IMPLEMENT STUB
Expand Down Expand Up @@ -239,7 +240,9 @@ void LipstickCompositorStub::reactOnDisplayStateChanges(MeeGo::QmDisplayState::D
stubMethodEntered("reactOnDisplayStateChanges",params);
}


void LipstickCompositorStub::setScreenOrientationFromSensor( ) {
stubMethodEntered("setScreenOrientationFromSensor");
}

// 3. CREATE A STUB INSTANCE
LipstickCompositorStub gDefaultLipstickCompositorStub;
Expand Down Expand Up @@ -398,6 +401,10 @@ void LipstickCompositor::reactOnDisplayStateChanges(MeeGo::QmDisplayState::Displ
void LipstickCompositor::homeApplicationAboutToDestroy() {
}

void LipstickCompositor::setScreenOrientationFromSensor() {
gLipstickCompositorStub->setScreenOrientationFromSensor();
}

QWaylandCompositor::QWaylandCompositor(QWindow *, const char *)
{
}
Expand Down