From 8f5c1d220b47901257b4234199aaf37608532398 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Mon, 27 Jun 2016 13:12:57 +0300 Subject: [PATCH] [fingerterm] Update window hint. Fixes JB#35598 Used to be done by Qt-components. --- main.cpp | 12 ++++++------ qml/Main.qml | 10 ++++++++-- util.cpp | 13 +++++++++++++ util.h | 4 ++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index f64eb05..adbd762 100644 --- a/main.cpp +++ b/main.cpp @@ -148,6 +148,12 @@ int main(int argc, char *argv[]) context->setContextProperty( "keyLoader", &keyLoader ); context->setContextProperty( "startupErrorMessage", startupErrorMsg); + term.setWindow(&view); + util.setWindow(&view); + util.setTerm(&term); + + QObject::connect(view.engine(),SIGNAL(quit()),&app,SLOT(quit())); + view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:/qml/Main.qml")); @@ -155,12 +161,6 @@ int main(int argc, char *argv[]) if(!root) qFatal("no root object - qml error"); - term.setWindow(&view); - util.setWindow(&view); - util.setTerm(&term); - - QObject::connect(view.engine(),SIGNAL(quit()),&app,SLOT(quit())); - if (fullscreen) { view.showFullScreen(); } else { diff --git a/qml/Main.qml b/qml/Main.qml index e2704e3..e669ac7 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -27,6 +27,12 @@ Item { width: 540 height: 960 + Binding { + target: util + property: "windowOrientation" + value: page.orientation + } + Binding { target: util property: "allowGestures" @@ -39,13 +45,13 @@ Item { property bool forceOrientation property int forcedOrientation + property int orientation: forceOrientation ? forcedOrientation : Screen.orientation property bool portrait: rotation % 180 == 0 width: portrait ? root.width : root.height height: portrait ? root.height : root.width anchors.centerIn: parent - rotation: Screen.angleBetween((forceOrientation ? forcedOrientation : Screen.orientation), - Screen.primaryOrientation) + rotation: Screen.angleBetween(orientation, Screen.primaryOrientation) focus: true Keys.onPressed: { term.keyPress(event.key,event.modifiers,event.text); diff --git a/util.cpp b/util.cpp index 26f5f7c..bb3b82c 100644 --- a/util.cpp +++ b/util.cpp @@ -50,9 +50,12 @@ Util::~Util() void Util::setWindow(QQuickView* win) { + if (iWindow) + qFatal("Should set window property only once"); iWindow = win; if(!iWindow) qFatal("invalid main window"); + connect(win, SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)), this, SIGNAL(windowOrientationChanged())); } void Util::setWindowTitle(QString title) @@ -67,6 +70,16 @@ QString Util::windowTitle() return iCurrentWinTitle; } +int Util::windowOrientation() +{ + return iWindow->contentOrientation(); +} + +void Util::setWindowOrientation(int orientation) +{ + iWindow->reportContentOrientationChange(static_cast(orientation)); +} + void Util::setTerm(Terminal *term) { if (iTerm) { diff --git a/util.h b/util.h index 0428c13..8345f67 100644 --- a/util.h +++ b/util.h @@ -31,6 +31,7 @@ class Util : public QObject Q_OBJECT Q_PROPERTY(bool allowGestures READ allowGestures WRITE setAllowGestures NOTIFY allowGesturesChanged) Q_PROPERTY(QString windowTitle READ windowTitle NOTIFY windowTitleChanged) + Q_PROPERTY(int windowOrientation READ windowOrientation WRITE setWindowOrientation NOTIFY windowOrientationChanged) Q_PROPERTY(bool canPaste READ canPaste NOTIFY clipboardOrSelectionChanged) Q_PROPERTY(bool terminalHasSelection READ terminalHasSelection NOTIFY clipboardOrSelectionChanged) @@ -41,6 +42,8 @@ class Util : public QObject void setWindow(QQuickView* win); void setWindowTitle(QString title); QString windowTitle(); + int windowOrientation(); + void setWindowOrientation(int orientation); void setTerm(Terminal* term); Q_INVOKABLE void openNewWindow(); @@ -74,6 +77,7 @@ class Util : public QObject void notify(QString msg); void clipboardOrSelectionChanged(); void windowTitleChanged(); + void windowOrientationChanged(); private: Q_DISABLE_COPY(Util)