Skip to content

Commit 35a1fca

Browse files
committed
add example
1 parent a7e0b85 commit 35a1fca

File tree

8 files changed

+216
-0
lines changed

8 files changed

+216
-0
lines changed

example/Page1Form.qml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import QtQuick 2.9
2+
import QtQuick.Controls 2.2
3+
4+
Page {
5+
width: 600
6+
height: 400
7+
8+
header: Label {
9+
text: qsTr("Page 1")
10+
font.pixelSize: Qt.application.font.pixelSize * 2
11+
padding: 10
12+
}
13+
14+
Label {
15+
text: qsTr("You are on Page 1.")
16+
anchors.centerIn: parent
17+
}
18+
}

example/Page2Form.ui.qml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import QtQuick 2.9
2+
import QtQuick.Controls 2.2
3+
4+
Page {
5+
width: 600
6+
height: 400
7+
8+
header: Label {
9+
text: qsTr("Page 2")
10+
font.pixelSize: Qt.application.font.pixelSize * 2
11+
padding: 10
12+
}
13+
14+
Label {
15+
text: qsTr("You are on Page 2.")
16+
anchors.centerIn: parent
17+
}
18+
}

example/example.pro

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
QT += quick
2+
CONFIG += c++11
3+
4+
# The following define makes your compiler emit warnings if you use
5+
# any Qt feature that has been marked deprecated (the exact warnings
6+
# depend on your compiler). Refer to the documentation for the
7+
# deprecated API to know how to port your code away from it.
8+
DEFINES += QT_DEPRECATED_WARNINGS
9+
10+
# You can also make your code fail to compile if it uses deprecated APIs.
11+
# In order to do so, uncomment the following line.
12+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
13+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
14+
15+
SOURCES += \
16+
main.cpp
17+
18+
RESOURCES += qml.qrc
19+
20+
# Additional import path used to resolve QML modules in Qt Creator's code model
21+
QML_IMPORT_PATH =
22+
23+
# Additional import path used to resolve QML modules just for Qt Quick Designer
24+
QML_DESIGNER_IMPORT_PATH =
25+
26+
# Default rules for deployment.
27+
qnx: target.path = /tmp/$${TARGET}/bin
28+
else: unix:!android: target.path = /opt/$${TARGET}/bin
29+
!isEmpty(target.path): INSTALLS += target

example/live.qml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import QtQuick 2.9
2+
import QtQuick.Controls 2.2
3+
import QtQuick.Layouts 1.3
4+
import QtQuick.Window 2.0
5+
import Qt.labs.settings 1.0
6+
import com.machinekoder.live 1.0
7+
8+
ApplicationWindow {
9+
id: root
10+
visible: true
11+
width: 640
12+
height: 480
13+
title: qsTr("Live Coding Example")
14+
flags: liveCoding.flags
15+
visibility: liveCoding.visibility
16+
17+
Component.onCompleted: {
18+
for (var i = 0; i < Qt.application.screens.length; ++i) {
19+
let screen = Qt.application.screens[i]
20+
if (screen.serialNumber === windowSettings.screen) {
21+
root.screen = screen
22+
return
23+
}
24+
}
25+
}
26+
27+
Component.onDestruction: {
28+
windowSettings.screen = root.screen.serialNumber
29+
}
30+
31+
LiveCoding {
32+
id: liveCoding
33+
anchors.fill: parent
34+
}
35+
36+
Settings {
37+
id: windowSettings
38+
category: "window"
39+
property alias width: root.width
40+
property alias height: root.height
41+
property alias x: root.x
42+
property alias y: root.y
43+
property alias visibility: liveCoding.visibility
44+
property alias flags: liveCoding.flags
45+
property alias hideToolBar: liveCoding.hideToolBar
46+
property string screen: ""
47+
}
48+
}

example/main.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <QCommandLineParser>
2+
#include <QFile>
3+
#include <QGuiApplication>
4+
#include <QQmlApplicationEngine>
5+
6+
int main(int argc, char *argv[])
7+
{
8+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
9+
10+
QGuiApplication app(argc, argv);
11+
app.setOrganizationName("machinekoder.com");
12+
app.setOrganizationDomain("machinekoder.com");
13+
app.setApplicationName("LiveCodingExample");
14+
app.setApplicationDisplayName("Live Coding Example");
15+
16+
QCommandLineParser parser;
17+
parser.setApplicationDescription("Live Coding Example");
18+
parser.addHelpOption();
19+
#ifdef QT_DEBUG
20+
QCommandLineOption forceOption(QStringList() << "l" << "live",
21+
QCoreApplication::translate("live", "Start live coding mode."));
22+
parser.addOption(forceOption);
23+
#endif
24+
parser.process(app);
25+
26+
QString fileName = QStringLiteral("main.qml");
27+
#ifdef QT_DEBUG
28+
if (parser.isSet(forceOption)) {
29+
fileName = QStringLiteral("live.qml");
30+
}
31+
#endif
32+
33+
QQmlApplicationEngine engine;
34+
engine.addImportPath(QStringLiteral("."));
35+
engine.addImportPath(QStringLiteral("qrc:/"));
36+
QFile file(QStringLiteral("./") + fileName);
37+
if (file.exists()) {
38+
engine.load(QStringLiteral("./") + fileName);
39+
}
40+
else {
41+
engine.load(QUrl(QStringLiteral("qrc:/") + fileName));
42+
}
43+
if (engine.rootObjects().isEmpty())
44+
return -1;
45+
46+
return app.exec();
47+
}

example/main.qml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import QtQuick 2.9
2+
import QtQuick.Controls 2.2
3+
4+
ApplicationWindow {
5+
visible: true
6+
width: 640
7+
height: 480
8+
title: qsTr("Tabs")
9+
10+
SwipeView {
11+
id: swipeView
12+
anchors.fill: parent
13+
currentIndex: tabBar.currentIndex
14+
15+
Page1Form {
16+
}
17+
18+
Page2Form {
19+
}
20+
}
21+
22+
footer: TabBar {
23+
id: tabBar
24+
currentIndex: swipeView.currentIndex
25+
26+
TabButton {
27+
text: qsTr("Page 1")
28+
}
29+
TabButton {
30+
text: qsTr("Page 2")
31+
}
32+
}
33+
}

example/qml.qrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>Page1Form.qml</file>
5+
<file>Page2Form.ui.qml</file>
6+
<file>main.qml</file>
7+
<file>qtquickcontrols2.conf</file>
8+
<file>live.qml</file>
9+
</qresource>
10+
</RCC>

example/qtquickcontrols2.conf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; This file can be edited to change the style of the application
2+
; Read "Qt Quick Controls 2 Configuration File" for details:
3+
; http://doc.qt.io/qt-5/qtquickcontrols2-configuration.html
4+
5+
[Controls]
6+
Style=Material
7+
8+
[Material]
9+
Theme=Light
10+
;Accent=BlueGrey
11+
;Primary=BlueGray
12+
;Foreground=Brown
13+
;Background=Grey

0 commit comments

Comments
 (0)