diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/applicationinfo.cpp | 17 | ||||
-rw-r--r-- | src/applicationinfo.h | 4 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/applicationinfo.cpp b/src/applicationinfo.cpp index f70f35a..901f80e 100644 --- a/src/applicationinfo.cpp +++ b/src/applicationinfo.cpp @@ -92,7 +92,7 @@ ApplicationInfo::ApplicationInfo(WeatherImageProvider *provider) m_currentIndexDay = -1; if (m_isMobile) - connect(qApp->primaryScreen(), SIGNAL(physicalSizeChanged(QSizeF)), this, SLOT(notifyPortraitMode())); + connect(qApp->primaryScreen(), SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), this, SLOT(notifyPortraitMode(Qt::ScreenOrientation))); // Search in English // In order to use yr.no weather data service, refer to their terms @@ -135,11 +135,18 @@ QString ApplicationInfo::getImagePath(const QString image) return QString("qrc:/weatherapp/qml/touch/images/%1").arg(image); } -void ApplicationInfo::notifyPortraitMode() +void ApplicationInfo::notifyPortraitMode(Qt::ScreenOrientation orientation) { - int width = qApp->primaryScreen()->geometry().width(); - int height = qApp->primaryScreen()->geometry().height(); - setIsPortraitMode(height > width); + switch (orientation) { + case Qt::LandscapeOrientation: + case Qt::InvertedLandscapeOrientation: + setIsPortraitMode(false); + break; + case Qt::PortraitOrientation: + case Qt::InvertedPortraitOrientation: + setIsPortraitMode(true); + break; + } } void ApplicationInfo::setIsPortraitMode(const bool newMode) diff --git a/src/applicationinfo.h b/src/applicationinfo.h index 0774af9..f8924b8 100644 --- a/src/applicationinfo.h +++ b/src/applicationinfo.h @@ -57,6 +57,7 @@ class ApplicationInfo : public QObject { Q_OBJECT Q_PROPERTY(int applicationWidth READ applicationWidth WRITE setApplicationWidth NOTIFY applicationWidthChanged) + Q_PROPERTY(bool isMobile READ isMobile CONSTANT) Q_PROPERTY(QObject *colors READ colors CONSTANT) Q_PROPERTY(QObject *constants READ constants CONSTANT) Q_PROPERTY(bool isPortraitMode READ isPortraitMode WRITE setIsPortraitMode NOTIFY portraitModeChanged) @@ -72,6 +73,7 @@ class ApplicationInfo : public QObject public: ApplicationInfo(WeatherImageProvider *provider); + bool isMobile() const { return m_isMobile; } QQmlPropertyMap *colors() const { return m_colors; } QQmlPropertyMap *constants() const { return m_constants; } @@ -99,7 +101,7 @@ public: Q_INVOKABLE void queryCities(const QString input); protected slots: - void notifyPortraitMode(); + void notifyPortraitMode(Qt::ScreenOrientation); private slots: void replyFinished(QNetworkReply *reply); |