From d87734d37a0c9689647b4eaaef1eeda318c3f8be Mon Sep 17 00:00:00 2001 From: Alexandra Betouni Date: Tue, 20 Nov 2018 12:49:37 +0100 Subject: Demo application clean up Minor improvements in pro file for demo app Also update .gitignore to ignore DS_Store files Removed unecessary code and files --- DemoApplication/CNButton.qml | 18 ----- DemoApplication/DemoApplication.pro | 14 ++-- DemoApplication/HomeForm.qml | 14 ---- DemoApplication/Page1Form.qml | 84 ----------------------- DemoApplication/Page2Form.qml | 116 -------------------------------- DemoApplication/Page3Form.qml | 96 -------------------------- DemoApplication/controls/CNButton.qml | 38 +++++++++++ DemoApplication/main.cpp | 17 ----- DemoApplication/main.qml | 81 +++++++--------------- DemoApplication/pages/Page1.qml | 78 ++++++++++++++++++++++ DemoApplication/pages/Page2.qml | 122 ++++++++++++++++++++++++++++++++++ DemoApplication/pages/Page3.qml | 93 ++++++++++++++++++++++++++ DemoApplication/qml.qrc | 11 --- DemoApplication/qtquickcontrols2.conf | 6 -- DemoApplication/src/main.cpp | 17 +++++ 15 files changed, 380 insertions(+), 425 deletions(-) delete mode 100644 DemoApplication/CNButton.qml delete mode 100644 DemoApplication/HomeForm.qml delete mode 100644 DemoApplication/Page1Form.qml delete mode 100644 DemoApplication/Page2Form.qml delete mode 100644 DemoApplication/Page3Form.qml create mode 100644 DemoApplication/controls/CNButton.qml delete mode 100644 DemoApplication/main.cpp create mode 100644 DemoApplication/pages/Page1.qml create mode 100644 DemoApplication/pages/Page2.qml create mode 100644 DemoApplication/pages/Page3.qml delete mode 100644 DemoApplication/qml.qrc delete mode 100644 DemoApplication/qtquickcontrols2.conf create mode 100644 DemoApplication/src/main.cpp (limited to 'DemoApplication') diff --git a/DemoApplication/CNButton.qml b/DemoApplication/CNButton.qml deleted file mode 100644 index b4b28bf..0000000 --- a/DemoApplication/CNButton.qml +++ /dev/null @@ -1,18 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Controls 2.2 -import CursorNavigation 1.0 - -Button { - id: button - CursorNavigation.acceptsCursor: true - property bool hasCursor: CursorNavigation.hasCursor - - Rectangle { - border.width: 2 - border.color: "red" - anchors.fill: parent - visible: button.hasCursor - color: "transparent" - } - -} diff --git a/DemoApplication/DemoApplication.pro b/DemoApplication/DemoApplication.pro index 6ad5a8e..736fb47 100644 --- a/DemoApplication/DemoApplication.pro +++ b/DemoApplication/DemoApplication.pro @@ -8,20 +8,24 @@ CONFIG += c++11 DEFINES += QT_DEPRECATED_WARNINGS TARGET = demo -DESTDIR = .. +DESTDIR = $$OUT_PWD/ +macos:CONFIG -= app_bundle # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - main.cpp + src/main.cpp -RESOURCES += qml.qrc +qml.files = main.qml $$PWD/controls $$PWD/pages +qml.path = $$OUT_PWD +INSTALLS += qml + +OTHER_FILES += $$files($$PWD/*.qml, true) +OTHER_FILES += $$files($$PWD/*.qmldir, true) # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = -# Additional import path used to resolve QML modules just for Qt Quick Designer -QML_DESIGNER_IMPORT_PATH = diff --git a/DemoApplication/HomeForm.qml b/DemoApplication/HomeForm.qml deleted file mode 100644 index 83412a6..0000000 --- a/DemoApplication/HomeForm.qml +++ /dev/null @@ -1,14 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.2 - -Page { - width: 600 - height: 400 - - title: qsTr("Home") - - Label { - text: qsTr("You are on the home page.") - anchors.centerIn: parent - } -} diff --git a/DemoApplication/Page1Form.qml b/DemoApplication/Page1Form.qml deleted file mode 100644 index fb7f09e..0000000 --- a/DemoApplication/Page1Form.qml +++ /dev/null @@ -1,84 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Layouts 1.3 -import CursorNavigation 1.0 - -Page { - width: 600 - height: 400 - - title: qsTr("Page 1") - - FocusScope { - CursorNavigation.acceptsCursor: true - - anchors.fill: parent - - //this seems to be the way to force focus on a newly opened dialog? - Component.onCompleted: forceActiveFocus() - - Label { - text: qsTr("You are on Page 1.") - anchors.centerIn: parent - } - - CNButton { - id: button - x: 52 - y: 50 - text: qsTr("Button") - } - - CNButton { - id: button1 - x: 110 - y: 138 - text: qsTr("Button") - } - - CNButton { - id: button2 - x: 202 - y: 241 - text: qsTr("Button with default focus") - focus: true - } - - CNButton { - id: button3 - x: 383 - y: 241 - text: qsTr("Button") - } - - CNButton { - id: button4 - x: 383 - y: 322 - text: qsTr("Button") - } - - CNButton { - id: button5 - x: 383 - y: 138 - text: qsTr("Button") - } - - CNButton { - id: button6 - x: 383 - y: 50 - text: qsTr("Button") - } - - CNButton { - id: button7 - x: 62 - y: 241 - text: qsTr("Button") - } - - } - -} diff --git a/DemoApplication/Page2Form.qml b/DemoApplication/Page2Form.qml deleted file mode 100644 index 891f8cc..0000000 --- a/DemoApplication/Page2Form.qml +++ /dev/null @@ -1,116 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.2 -import CursorNavigation 1.0 - -Page { - width: 600 - height: 400 - - title: qsTr("Page 2") - - Label { - text: qsTr("You are on Page 2.") - anchors.centerIn: parent - } - - FocusScope { - CursorNavigation.acceptsCursor: true - x: 385 - y: 19 - width: 198 - height: 359 - ListView { - id: listView - anchors.fill: parent - spacing: 4 - focus: true - - Rectangle { - border.width: 2 - border.color: "red" - anchors.fill: parent - visible: listView.activeFocus - color: "transparent" - } - - highlight: Rectangle { - border.width: 2 - border.color: "red" - color: "grey" - } - - delegate: Item { - x: 5 - width: listView.width - height: 40 - - Row { - id: row1 - Rectangle { - width: 40 - height: 40 - color: colorCode - } - - Text { - text: name - anchors.verticalCenter: parent.verticalCenter - font.bold: true - } - spacing: 10 - } - } - - model: ListModel { - ListElement { - name: "Grey" - colorCode: "grey" - } - - ListElement { - name: "Red" - colorCode: "red" - } - - ListElement { - name: "Blue" - colorCode: "blue" - } - - ListElement { - name: "Green" - colorCode: "green" - } - } - } - } - - CNButton { - id: button - x: 95 - y: 54 - text: qsTr("Button") - } - - CNButton { - id: button1 - x: 95 - y: 158 - text: qsTr("Button") - } - - CNButton { - id: button2 - x: 95 - y: 266 - text: qsTr("Button") - } - - CNButton { - id: button3 - x: 400 - y: 400 - text: qsTr("Button") - } - -} diff --git a/DemoApplication/Page3Form.qml b/DemoApplication/Page3Form.qml deleted file mode 100644 index f7d65e8..0000000 --- a/DemoApplication/Page3Form.qml +++ /dev/null @@ -1,96 +0,0 @@ -import QtQuick 2.0 -import CursorNavigation 1.0 - -Item { - FocusScope { - id: rootScope - Row { - spacing: 10 - - CNButton { - width: 100 - height: 100 - text: "alone!" - } - - Rectangle { - - width: 250 - height: 200 - - Grid { - spacing: 5 - columns: 2 - rows: 2 - - CNButton { - text: "b1" - } - - CNButton { - text: "b2 (default focus)" - focus: true - } - - CNButton { - id: defaultButton - text: "b3 (escape target)" - } - - CNButton { - text: "b4" - } - - } - - } - - Rectangle { - - width: 250 - height: 200 - - border.width: 2 - border.color: "gray" - - FocusScope { - CursorNavigation.acceptsCursor: true - anchors.fill: parent - CursorNavigation.escapeTarget: defaultButton - - //redefine the controls for this scope - //(default arrow keys will still work as well, unless reassigned here) - Keys.onDigit5Pressed: CursorNavigation.moveUp() - Keys.onDigit2Pressed: CursorNavigation.moveDown() - Keys.onDigit3Pressed: CursorNavigation.moveRight() - Keys.onDigit1Pressed: CursorNavigation.moveLeft() - - Grid { - spacing: 5 - columns: 2 - rows: 2 - - CNButton { - text: "sb1" - } - - CNButton { - text: "sb2" - } - - CNButton { - text: "sb3" - } - - CNButton { - text: "sb4 (default focus)" - focus: true - } - - } - } - - } - } - } -} diff --git a/DemoApplication/controls/CNButton.qml b/DemoApplication/controls/CNButton.qml new file mode 100644 index 0000000..33299d1 --- /dev/null +++ b/DemoApplication/controls/CNButton.qml @@ -0,0 +1,38 @@ +import QtQuick 2.0 +import QtQuick.Controls 2.2 +import CursorNavigation 1.0 + +Button { + id: root + implicitWidth: (textLabel.contentWidth + 40) + implicitHeight: 40 + + CursorNavigation.acceptsCursor: true + property bool hasCursor: CursorNavigation.hasCursor + + background: Rectangle { + anchors.fill: parent + radius: 40 + opacity: root.pressed ? 0.6 : 0.4 + color: "grey" + } + + contentItem: Item { + anchors.fill: parent + Label { + id: textLabel + anchors.centerIn: parent + font.pixelSize: 14 + color: "blue" + text: root.text + } + + Rectangle { + border.width: 2 + border.color: "red" + anchors.fill: parent + visible: root.hasCursor + color: "transparent" + } + } +} diff --git a/DemoApplication/main.cpp b/DemoApplication/main.cpp deleted file mode 100644 index 0635536..0000000 --- a/DemoApplication/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication::addLibraryPath(QLatin1String("./plugin")); - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - - QGuiApplication app(argc, argv); - - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; - - return app.exec(); -} diff --git a/DemoApplication/main.qml b/DemoApplication/main.qml index b408923..b0e54cb 100644 --- a/DemoApplication/main.qml +++ b/DemoApplication/main.qml @@ -1,74 +1,39 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + import CursorNavigation 1.0 +import "pages" ApplicationWindow { id: window - visible: true width: 800 height: 600 - title: qsTr("Stack") - - header: ToolBar { - contentHeight: toolButton.implicitHeight - - ToolButton { - id: toolButton - text: stackView.depth > 1 ? "\u25C0" : "\u2630" - font.pixelSize: Qt.application.font.pixelSize * 1.6 - onClicked: { - if (stackView.depth > 1) { - stackView.pop() - } else { - drawer.open() - } - } + visible: true + title: qsTr("Cursor Navigation Demo Application") + + header: TabBar { + id: tabBar + width: parent.width + TabButton { + CursorNavigation.acceptsCursor: true + text: qsTr("Page 1") } - - Label { - text: stackView.currentItem.title - anchors.centerIn: parent + TabButton { + CursorNavigation.acceptsCursor: true + text: qsTr("Page 2") } - } - - Drawer { - id: drawer - width: window.width * 0.66 - height: window.height - - Column { - anchors.fill: parent - - ItemDelegate { - text: qsTr("Page 1") - width: parent.width - onClicked: { - stackView.push("Page1Form.qml") - drawer.close() - } - } - ItemDelegate { - text: qsTr("Page 2") - width: parent.width - onClicked: { - stackView.push("Page2Form.qml") - drawer.close() - } - } - ItemDelegate { - text: qsTr("Page 3") - width: parent.width - onClicked: { - stackView.push("Page3Form.qml") - drawer.close() - } - } + TabButton { + CursorNavigation.acceptsCursor: true + text: qsTr("Page 3") } } - StackView { - id: stackView - initialItem: "HomeForm.qml" + contentData: StackLayout { anchors.fill: parent + currentIndex: tabBar.currentIndex + Page1 { } + Page2 { } + Page3 { } } } diff --git a/DemoApplication/pages/Page1.qml b/DemoApplication/pages/Page1.qml new file mode 100644 index 0000000..b73be48 --- /dev/null +++ b/DemoApplication/pages/Page1.qml @@ -0,0 +1,78 @@ +import QtQuick 2.9 + +import CursorNavigation 1.0 +import "../controls" + +Item { + width: parent.width + height: parent.height + + FocusScope { + anchors.fill: parent + + Item { + width: 500 + height: 400 + anchors.centerIn: parent + + CNButton { + id: button + x: 52 + y: 50 + text: qsTr("Button") + } + + CNButton { + id: button1 + x: 110 + y: 138 + text: qsTr("Button") + } + + CNButton { + id: button2 + x: 160 + y: 241 + text: qsTr("Button with default focus") + focus: true + } + + CNButton { + id: button3 + x: 383 + y: 241 + text: qsTr("Button") + } + + CNButton { + id: button4 + x: 383 + y: 322 + text: qsTr("Button") + } + + CNButton { + id: button5 + x: 383 + y: 138 + text: qsTr("Button") + } + + CNButton { + id: button6 + x: 383 + y: 50 + text: qsTr("Button") + } + + CNButton { + id: button7 + x: 62 + y: 241 + text: qsTr("Button") + } + } + //this seems to be the way to force focus on a newly opened dialog? + Component.onCompleted: { forceActiveFocus(); } + } +} diff --git a/DemoApplication/pages/Page2.qml b/DemoApplication/pages/Page2.qml new file mode 100644 index 0000000..c655170 --- /dev/null +++ b/DemoApplication/pages/Page2.qml @@ -0,0 +1,122 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.4 + +import CursorNavigation 1.0 +import "../controls" + +Item { + width: parent.width + height: parent.height + + Item { + width: 580 + height: 450 + anchors.centerIn: parent + FocusScope { + id: focusScope + width: 198 + height: 359 + anchors.right: parent.right + anchors.top: parent.top + anchors.topMargin: 20 + + CursorNavigation.acceptsCursor: true + ListView { + id: listView + anchors.fill: parent + spacing: 4 + focus: true + + Rectangle { + anchors.fill: parent + visible: listView.activeFocus + border.width: 2 + border.color: "red" + color: "transparent" + } + + highlight: Rectangle { + width: listView.width + height: 40 + color: "lightgrey" + opacity: 0.3 + } + + delegate: ItemDelegate { + width: listView.width + height: 40 + + contentItem: Row { + width: (parent.width - x) + height: 35 + x: 5 + anchors.verticalCenter: parent.verticalCenter + spacing: 10 + Rectangle { + width: parent.height + height: parent.height + radius: width/2 + color: colorCode + } + Text { + height: parent.height + font.bold: true + verticalAlignment: Text.AlignVCenter + text: name + } + } + onClicked: { + listView.currentIndex = index; + } + } + + model: ListModel { + ListElement { + name: "Grey" + colorCode: "grey" + } + + ListElement { + name: "Red" + colorCode: "red" + } + + ListElement { + name: "Blue" + colorCode: "blue" + } + + ListElement { + name: "Green" + colorCode: "green" + } + } + } + } + CNButton { + id: button3 + anchors.top: focusScope.bottom + anchors.topMargin: 20 + anchors.right: parent.right + anchors.rightMargin: 60 + text: qsTr("Button") + } + Column { + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 50 + spacing: 30 + CNButton { + text: qsTr("Button") + } + + CNButton { + text: qsTr("Button") + } + + CNButton { + text: qsTr("Button") + } + } + } +} diff --git a/DemoApplication/pages/Page3.qml b/DemoApplication/pages/Page3.qml new file mode 100644 index 0000000..ece6975 --- /dev/null +++ b/DemoApplication/pages/Page3.qml @@ -0,0 +1,93 @@ +import QtQuick 2.0 + +import CursorNavigation 1.0 +import "../controls" + +Item { + width: parent.width + height: parent.height + + FocusScope { + id: rootScope + anchors.fill: parent + Row { + anchors.centerIn: parent + spacing: 10 + CNButton { + width: 100 + height: 100 + text: "alone!" + } + + Grid { + columns: 2 + rows: 2 + spacing: 5 + + CNButton { + text: "b1" + } + + CNButton { + text: "b2 (default focus)" + focus: true + } + + CNButton { + id: defaultButton + text: "b3 (escape target)" + } + + CNButton { + text: "b4" + } + } + + Rectangle { + width: 250 + height: 200 + + border.width: 2 + border.color: "grey" + + FocusScope { + anchors.fill: parent + CursorNavigation.acceptsCursor: true + CursorNavigation.escapeTarget: defaultButton + + //redefine the controls for this scope + //(default arrow keys will still work as well, unless reassigned here) + Keys.onDigit5Pressed: CursorNavigation.moveUp() + Keys.onDigit2Pressed: CursorNavigation.moveDown() + Keys.onDigit3Pressed: CursorNavigation.moveRight() + Keys.onDigit1Pressed: CursorNavigation.moveLeft() + + Grid { + spacing: 5 + columns: 2 + rows: 2 + + CNButton { + text: "sb1" + } + + CNButton { + text: "sb2" + } + + CNButton { + text: "sb3" + } + + CNButton { + text: "sb4 (default focus)" + focus: true + } + } + } + } + } + //this seems to be the way to force focus on a newly opened dialog? + Component.onCompleted: { forceActiveFocus(); } + } +} diff --git a/DemoApplication/qml.qrc b/DemoApplication/qml.qrc deleted file mode 100644 index 058589b..0000000 --- a/DemoApplication/qml.qrc +++ /dev/null @@ -1,11 +0,0 @@ - - - main.qml - HomeForm.qml - Page1Form.qml - Page2Form.qml - qtquickcontrols2.conf - CNButton.qml - Page3Form.qml - - diff --git a/DemoApplication/qtquickcontrols2.conf b/DemoApplication/qtquickcontrols2.conf deleted file mode 100644 index 75b2cb8..0000000 --- a/DemoApplication/qtquickcontrols2.conf +++ /dev/null @@ -1,6 +0,0 @@ -; This file can be edited to change the style of the application -; Read "Qt Quick Controls 2 Configuration File" for details: -; http://doc.qt.io/qt-5/qtquickcontrols2-configuration.html - -[Controls] -Style=Default diff --git a/DemoApplication/src/main.cpp b/DemoApplication/src/main.cpp new file mode 100644 index 0000000..b8b24cb --- /dev/null +++ b/DemoApplication/src/main.cpp @@ -0,0 +1,17 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::addLibraryPath(QLatin1String("./plugin")); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} -- cgit v1.2.3