~mir-team/qtmir/trunk

« back to all changes in this revision

Viewing changes to src/modules/Unity/Application/mirsurfaceitem.cpp

  • Committer: CI bot
  • Author(s): Gerry Boland
  • Date: 2014-09-22 17:38:23 UTC
  • mfrom: (232.1.13 expose-orientation)
  • Revision ID: ps-jenkins@lists.canonical.com-20140922173823-wh2jev0n0tkpzup9
Expose Mir surface orientation property to QML Fixes: 1288332, 1363920
Approved by: Daniel d'Andrada, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
// Qt
32
32
#include <QDebug>
 
33
#include <QGuiApplication>
33
34
#include <QQmlEngine>
34
35
#include <QQuickWindow>
 
36
#include <QScreen>
35
37
#include <QSGSimpleTextureNode>
36
38
#include <QSGTextureProvider>
37
39
#include <QTimer>
243
245
    , m_session(session)
244
246
    , m_firstFrameDrawn(false)
245
247
    , m_live(true)
 
248
    , m_orientation(Qt::PortraitOrientation)
246
249
    , m_textureProvider(nullptr)
247
250
    , m_lastTouchEvent(nullptr)
248
251
{
349
352
    return static_cast<MirSurfaceItem::State>(m_surface->state());
350
353
}
351
354
 
 
355
Qt::ScreenOrientation MirSurfaceItem::orientation() const
 
356
{
 
357
    return m_orientation;
 
358
}
 
359
 
 
360
void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation)
 
361
{
 
362
    qCDebug(QTMIR_SURFACES) << "MirSurfaceItem::setOrientation - orientation=" << orientation;
 
363
 
 
364
    if (m_orientation == orientation)
 
365
        return;
 
366
 
 
367
    MirOrientation mirOrientation;
 
368
    Qt::ScreenOrientation nativeOrientation = QGuiApplication::primaryScreen()->nativeOrientation();
 
369
    const bool landscapeNativeOrientation = (nativeOrientation == Qt::LandscapeOrientation);
 
370
 
 
371
    Qt::ScreenOrientation requestedOrientation = orientation;
 
372
    if (orientation == Qt::PrimaryOrientation) { // means orientation equals native orientation, set it as such
 
373
        requestedOrientation = nativeOrientation;
 
374
    }
 
375
 
 
376
    switch(requestedOrientation) {
 
377
    case Qt::PortraitOrientation:
 
378
        mirOrientation = (landscapeNativeOrientation) ? mir_orientation_right : mir_orientation_normal;
 
379
        break;
 
380
    case Qt::LandscapeOrientation:
 
381
        mirOrientation = (landscapeNativeOrientation) ? mir_orientation_normal : mir_orientation_left;
 
382
        break;
 
383
    case Qt::InvertedPortraitOrientation:
 
384
        mirOrientation = (landscapeNativeOrientation) ? mir_orientation_left : mir_orientation_inverted;
 
385
        break;
 
386
    case Qt::InvertedLandscapeOrientation:
 
387
        mirOrientation = (landscapeNativeOrientation) ? mir_orientation_inverted : mir_orientation_right;
 
388
        break;
 
389
    default:
 
390
        qWarning("Unrecognized Qt::ScreenOrientation!");
 
391
        return;
 
392
    }
 
393
 
 
394
    m_surface->set_orientation(mirOrientation);
 
395
 
 
396
    m_orientation = orientation;
 
397
    Q_EMIT orientationChanged();
 
398
}
 
399
 
352
400
QString MirSurfaceItem::name() const
353
401
{
354
402
    //FIXME - how to listen to change in this property?