Commit e8cf752a authored by Andrea Bernabei's avatar Andrea Bernabei

[components] Add Nemo's ApplicationWindow and rotation handling

We may consider renaming the component, but anyway:
ApplicationWindow includes a page stack (StackView) which handles
the pages of the application.

ApplicationWindow includes an Item handling UI rotations,
and offers allowedOrientations (and other useful properties)
to help the dev handle rotation locking.
parent 4194c25d
......@@ -45,6 +45,7 @@
#include <QtQml>
#include <QtQuick/QQuickView>
#include <QtCore/QString>
#include <QScreen>
#ifndef QT_NO_WIDGETS
#include <QtWidgets/QApplication>
......@@ -64,6 +65,13 @@ QT_BEGIN_NAMESPACE
int main(int argc, char *argv[]) \
{ \
Application app(argc, argv); \
QScreen* sc = app.primaryScreen(); \
if(sc){ \
sc->setOrientationUpdateMask(Qt::LandscapeOrientation \
| Qt::PortraitOrientation \
| Qt::InvertedLandscapeOrientation \
| Qt::InvertedPortraitOrientation); \
} \
QQmlApplicationEngine engine(QUrl(#url)); \
QObject *topLevel = engine.rootObjects().value(0); \
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel); \
......
......@@ -39,6 +39,7 @@
****************************************************************************/
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Controls.Nemo 1.0
import QtQuick.Controls.Styles.Nemo 1.0
import QtQuick.Window 2.1
......@@ -46,62 +47,20 @@ import "content"
ApplicationWindow {
width: 854
height: 480
Rectangle {
color: "#212126"
anchors.fill: parent
}
contentOrientation: Qt.PortraitOrientation
id: appWindow
contentOrientation: Screen.orientation
// Implements back key navigation
Keys.onReleased: {
if (event.key === Qt.Key_Back) {
if (stackView.depth > 1) {
stackView.pop();
if (pageStack.depth > 1) {
pageStack.pop();
event.accepted = true;
} else { Qt.quit(); }
}
}
toolBar: ToolBar {
width: parent.width
height: 100
Rectangle {
id: backButton
width: opacity ? 60 : 0
anchors.left: parent.left
anchors.leftMargin: 20
opacity: stackView.depth > 1 ? 1 : 0
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
height: 60
radius: 4
color: backmouse.pressed ? "#222" : "transparent"
Behavior on opacity { NumberAnimation{} }
Image {
anchors.verticalCenter: parent.verticalCenter
source: "images/navigation_previous_item.png"
}
MouseArea {
id: backmouse
anchors.fill: parent
anchors.margins: -10
onClicked: stackView.pop()
}
}
Text {
font.pixelSize: 42
Behavior on x { NumberAnimation{ easing.type: Easing.OutCubic} }
x: backButton.x + backButton.width + 20
anchors.verticalCenter: parent.verticalCenter
color: "white"
text: "Widget Gallery"
}
}
ListModel {
id: pageModel
ListElement {
......@@ -130,22 +89,61 @@ ApplicationWindow {
}
}
StackView {
id: stackView
anchors.fill: parent
initialItem: Item {
width: parent.width
height: parent.height
ListView {
model: pageModel
anchors.fill: parent
delegate: AndroidDelegate {
text: title
onClicked: stackView.push(Qt.resolvedUrl(page))
initialPage: Rectangle {
id: pageItem
width: parent.width
height: parent.height
color: "black"
ToolBar {
id: toolbar
anchors.top: parent.top
Rectangle {
id: backButton
width: opacity ? 60 : 0
anchors.left: parent.left
anchors.leftMargin: 20
opacity: pageItem.Stack.view.depth > 1 ? 1 : 0
anchors.verticalCenter: parent.verticalCenter
antialiasing: true
height: 60
radius: 4
color: backmouse.pressed ? "#222" : "transparent"
Behavior on opacity { NumberAnimation{} }
Image {
anchors.verticalCenter: parent.verticalCenter
source: "images/navigation_previous_item.png"
}
MouseArea {
id: backmouse
anchors.fill: parent
anchors.margins: -10
onClicked: pageItem.Stack.view.pop()
}
}
Text {
font.pixelSize: 42
Behavior on x { NumberAnimation{ easing.type: Easing.OutCubic} }
x: backButton.x + backButton.width + 20
anchors.verticalCenter: parent.verticalCenter
color: "white"
text: "Widget Gallery"
}
}
ListView {
model: pageModel
anchors { top: toolbar.bottom; left: parent.left; right: parent.right; bottom: parent.bottom }
clip: true
delegate: AndroidDelegate {
text: title
onClicked: pageItem.Stack.view.push(Qt.resolvedUrl(page))
}
}
}
}
......@@ -9,9 +9,11 @@ Source0: %{name}-%{version}.tar.xz
BuildRequires: qt5-qtcore-devel
BuildRequires: qt5-qtgui-devel
BuildRequires: qt5-qtdeclarative-devel
BuildRequires: qt5-qtopengl-devel
BuildRequires: qt5-qtdeclarative-qtquick-devel
BuildRequires: qt5-qtv8-devel
BuildRequires: qt5-qmake
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: fdupes
Requires: qt5-qtquickcontrols
Requires: qt5-qtgraphicaleffects
......
This diff is collapsed.
......@@ -7,18 +7,21 @@ THEME_IMPORT_PATH = QtQuick/Controls/Styles/Nemo/themes
# Added/Reimplemented Controls
QML_FILES += \
Button.qml
Button.qml \
ApplicationWindow.qml
OTHER_FILES += qmldir \
$$QML_FILES
HEADERS += \
qquicknemocontrolsextensionplugin.h \
hacks.h
hacks.h \
nemowindow.h
SOURCES += \
qquicknemocontrolsextensionplugin.cpp \
hacks.cpp
hacks.cpp \
nemowindow.cpp
target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
......
/*
* Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "nemowindow.h"
#include <QDebug>
NemoWindow::NemoWindow(QWindow *parent) :
QQuickWindow(parent)
{
}
Qt::ScreenOrientations NemoWindow::allowedOrientations() const {
return m_allowedOrientations;
}
void NemoWindow::setAllowedOrientations(Qt::ScreenOrientations allowed) {
//This way no invalid values can get assigned to allowedOrientations
//README: This is needed because otherwise you could assign it
//things like (Qt.PortraitOrientation | 444) from QML
Qt::ScreenOrientations max = (Qt::PortraitOrientation | Qt::LandscapeOrientation
| Qt::InvertedPortraitOrientation | Qt::InvertedLandscapeOrientation);
if (m_allowedOrientations != allowed && allowed <= max) {
m_allowedOrientations = allowed;
emit allowedOrientationsChanged();
}
}
#ifndef NEMOWINDOW_H
#define NEMOWINDOW_H
/*
* Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <QQuickWindow>
#include <QtCore/qnamespace.h>
class NemoWindow : public QQuickWindow
{
Q_OBJECT
Q_ENUMS(Orientation)
Q_PROPERTY(Qt::ScreenOrientations allowedOrientations READ allowedOrientations WRITE setAllowedOrientations NOTIFY allowedOrientationsChanged)
public:
explicit NemoWindow(QWindow *parent = 0);
Qt::ScreenOrientations allowedOrientations() const;
void setAllowedOrientations(Qt::ScreenOrientations allowed);
signals:
void allowedOrientationsChanged();
public slots:
private:
Qt::ScreenOrientations m_allowedOrientations;
};
#endif // NEMOWINDOW_H
......@@ -9,6 +9,7 @@ plugin nemocontrolsplugin
# GlacierSlider 1.0 GlacierSlider.qml
Button 1.0 Button.qml
ApplicationWindow 1.0 ApplicationWindow.qml
# MIRRORED CONTROLS:
# These are the controls that we take directly from official QQC.
......@@ -19,7 +20,6 @@ Button 1.0 Button.qml
# case Nemo plugin doesn't provide an overridden component)
# NOTE: "../" here is assumed to be the relative path to the official QQC!!
ApplicationWindow 1.0 ../ApplicationWindow.qml
CheckBox 1.0 ../CheckBox.qml
ComboBox 1.0 ../ComboBox.qml
GroupBox 1.0 ../GroupBox.qml
......
......@@ -21,6 +21,7 @@
#include "qquicknemocontrolsextensionplugin.h"
#include <QtQml>
#include "hacks.h"
#include "nemowindow.h"
QQuickNemoControlsExtensionPlugin::QQuickNemoControlsExtensionPlugin(QObject *parent) :
QQmlExtensionPlugin(parent)
......@@ -37,7 +38,7 @@ void QQuickNemoControlsExtensionPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("QtQuick.Controls.Nemo"));
qmlRegisterSingletonType<QObject>(uri, 1, 0, "NemoHacks", nemo_hacks_singletontype_provider);
qmlRegisterType<NemoWindow>(uri, 1, 0, "NemoWindow");
}
void QQuickNemoControlsExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
......
......@@ -43,6 +43,7 @@ NemoTheme::NemoTheme(QObject *parent)
, m_groove(new NemoThemeGroove(this))
, m_textField(new NemoThemeTextField(this))
, m_toolBar(new NemoThemeToolBar(this))
, m_window(new NemoThemeWindow(this))
{
loadFromFile(GLACIER_THEME);
int id = QFontDatabase::addApplicationFont("/usr/share/fonts/google-opensans/OpenSans-Regular.ttf");
......@@ -105,6 +106,11 @@ NemoThemeToolBar * NemoTheme::toolBar() const
return m_toolBar;
}
NemoThemeWindow * NemoTheme::window() const
{
return m_window;
}
QString NemoTheme::fontFamily() const
{
return m_fontFamily;
......@@ -312,4 +318,7 @@ void NemoTheme::loadFromFile(const QString &fileName)
// Setting properties for toolBar
QJsonObject stylesToolBar = styles.value("toolBar").toObject();
m_toolBar->setBackground(jsonToColor(jsonValue(stylesToolBar, "background", "toolBar"), defines));
// Setting properties for window
QJsonObject stylesWindow = styles.value("window").toObject();
m_window->setBackground(jsonToColor(jsonValue(stylesWindow, "background", "window"), defines));
}
......@@ -29,6 +29,7 @@
#include "nemothemegroove.h"
#include "nemothemetextfield.h"
#include "nemothemetoolbar.h"
#include "nemothemewindow.h"
class NemoTheme: public QObject
{
......@@ -40,6 +41,7 @@ class NemoTheme: public QObject
Q_PROPERTY(NemoThemeGroove * groove READ groove CONSTANT)
Q_PROPERTY(NemoThemeTextField * textField READ textField CONSTANT)
Q_PROPERTY(NemoThemeToolBar * toolBar READ toolBar CONSTANT)
Q_PROPERTY(NemoThemeWindow * window READ window CONSTANT)
Q_PROPERTY(QString fontFamily READ fontFamily CONSTANT)
public:
explicit NemoTheme(QObject *parent = 0);
......@@ -52,6 +54,7 @@ public:
NemoThemeGroove * groove() const;
NemoThemeTextField * textField() const;
NemoThemeToolBar * toolBar() const;
NemoThemeWindow * window() const;
QString fontFamily() const;
public Q_SLOTS:
void loadFromFile(const QString &fileName);
......@@ -66,6 +69,7 @@ private:
NemoThemeGroove * m_groove;
NemoThemeTextField * m_textField;
NemoThemeToolBar * m_toolBar;
NemoThemeWindow * m_window;
QString m_fontFamily;
};
......
/*
* Copyright (C) 2013 Lucien Xu <sfietkonstantin@free.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// This class is autogenerated using themehelper.py
// Any modification done in this file will be overridden
#include "nemothemewindow.h"
NemoThemeWindow::NemoThemeWindow(QObject *parent)
: QObject(parent)
{
}
QColor NemoThemeWindow::background() const
{
return m_background;
}
void NemoThemeWindow::setBackground(const QColor &background)
{
if (m_background != background) {
m_background = background;
emit backgroundChanged();
}
}
/*
* Copyright (C) 2013 Lucien Xu <sfietkonstantin@free.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// This class is autogenerated using themehelper.py
// Any modification done in this file will be overridden
#ifndef NEMOTHEMEWINDOW_H
#define NEMOTHEMEWINDOW_H
#include <QtCore/QObject>
#include <QtGui/QColor>
class NemoThemeWindow: public QObject
{
Q_OBJECT
Q_PROPERTY(QColor background READ background NOTIFY backgroundChanged)
public:
explicit NemoThemeWindow(QObject *parent = 0);
QColor background() const;
void setBackground(const QColor &background);
Q_SIGNALS:
void backgroundChanged();
private:
QColor m_background;
};
#endif //NEMOTHEMEWINDOW_H
......@@ -46,6 +46,7 @@ void QQuickNemoStyleExtensionPlugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<NemoThemeGroove>(uri, 1, 0, "NemoThemeGroove", reason);
qmlRegisterUncreatableType<NemoThemeTextField>(uri, 1, 0, "NemoThemeTextField", reason);
qmlRegisterUncreatableType<NemoThemeToolBar>(uri, 1, 0, "NemoThemeToolBar", reason);
qmlRegisterUncreatableType<NemoThemeWindow>(uri, 1, 0, "NemoThemeWindow", reason);
qmlRegisterSingletonType<QObject>(uri, 1, 0, "Theme", nemo_theme_provider);
}
......
......@@ -85,7 +85,8 @@ HEADERS += \
autogenerated/nemothemefont.h \
autogenerated/nemothemegroove.h \
autogenerated/nemothemetextfield.h \
autogenerated/nemothemetoolbar.h
autogenerated/nemothemetoolbar.h \
autogenerated/nemothemewindow.h
SOURCES += \
qquicknemostyleextensionplugin.cpp \
......@@ -96,7 +97,8 @@ SOURCES += \
autogenerated/nemothemefont.cpp \
autogenerated/nemothemegroove.cpp \
autogenerated/nemothemetextfield.cpp \
autogenerated/nemothemetoolbar.cpp
autogenerated/nemothemetoolbar.cpp \
autogenerated/nemothemewindow.cpp
INSTALLS += target images qmlfiles themes
......
......@@ -40,6 +40,9 @@
},
"toolBar": {
"background": "#000000"
},
"window": {
"background": "#000000"
}
}
}
......@@ -37,6 +37,9 @@
"textField": {
"selectedTextColor": "#ffffff",
"selectionColor": "#0091e5"
},
"window": {
"background": "#000000"
}
}
}
......@@ -53,6 +53,15 @@
}
]
},
{
"name": "Window",
"properties": [
{
"name": "background",
"type": "QColor"
}
]
},
......@@ -141,6 +150,10 @@
{
"name": "toolBar",
"object": "ToolBar"
},
{
"name": "window",
"object": "Window"
}
],
"font": "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment