Skip to content

Commit

Permalink
Merge branch 'orientation_hint' into 'master'
Browse files Browse the repository at this point in the history
[fingerterm] Update window hint. Fixes JB#35598

Used to be done by Qt-components.

@rainemak

See merge request !14
  • Loading branch information
pvuorela committed Jun 27, 2016
2 parents 4c98a6d + 8f5c1d2 commit 12f8f8e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
12 changes: 6 additions & 6 deletions main.cpp
Expand Up @@ -148,19 +148,19 @@ 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"));

QObject *root = view.rootObject();
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 {
Expand Down
10 changes: 8 additions & 2 deletions qml/Main.qml
Expand Up @@ -27,6 +27,12 @@ Item {
width: 540
height: 960

Binding {
target: util
property: "windowOrientation"
value: page.orientation
}

Binding {
target: util
property: "allowGestures"
Expand All @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions util.cpp
Expand Up @@ -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)
Expand All @@ -67,6 +70,16 @@ QString Util::windowTitle()
return iCurrentWinTitle;
}

int Util::windowOrientation()
{
return iWindow->contentOrientation();
}

void Util::setWindowOrientation(int orientation)
{
iWindow->reportContentOrientationChange(static_cast<Qt::ScreenOrientation>(orientation));
}

void Util::setTerm(Terminal *term)
{
if (iTerm) {
Expand Down
4 changes: 4 additions & 0 deletions util.h
Expand Up @@ -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)

Expand All @@ -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();
Expand Down Expand Up @@ -74,6 +77,7 @@ class Util : public QObject
void notify(QString msg);
void clipboardOrSelectionChanged();
void windowTitleChanged();
void windowOrientationChanged();

private:
Q_DISABLE_COPY(Util)
Expand Down

0 comments on commit 12f8f8e

Please sign in to comment.