Support Qt Quick Controls 2
parent
fc5250b204
commit
b5f649436c
|
@ -14,6 +14,7 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
|
||||||
)
|
)
|
||||||
find_package(Qt5Widgets ${QT_MIN_VERSION} CONFIG)
|
find_package(Qt5Widgets ${QT_MIN_VERSION} CONFIG)
|
||||||
find_package(Qt5Quick ${QT_MIN_VERSION} CONFIG)
|
find_package(Qt5Quick ${QT_MIN_VERSION} CONFIG)
|
||||||
|
find_package(Qt5QuickControls2 ${QT_MIN_VERSION} CONFIG)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||||
|
|
|
@ -41,6 +41,10 @@ if(Qt5Quick_FOUND)
|
||||||
add_definitions(-DQTQUICK)
|
add_definitions(-DQTQUICK)
|
||||||
set(Qt5Quick_LIBS Qt5::Quick)
|
set(Qt5Quick_LIBS Qt5::Quick)
|
||||||
endif()
|
endif()
|
||||||
|
if(Qt5QuickControls2_FOUND)
|
||||||
|
add_definitions(-DQTQUICKCONTROLS2)
|
||||||
|
set(Qt5QuickControls2_LIBS Qt5::QuickControls2)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(Demo_SRCS src/main.cpp src/Tree.cpp src/Fibonacci.cpp
|
set(Demo_SRCS src/main.cpp src/Tree.cpp src/Fibonacci.cpp
|
||||||
resource_file.qrc)
|
resource_file.qrc)
|
||||||
|
@ -49,8 +53,8 @@ add_executable(Demo ${Demo_SRCS})
|
||||||
add_dependencies(Demo rust_target)
|
add_dependencies(Demo rust_target)
|
||||||
|
|
||||||
target_link_libraries(Demo
|
target_link_libraries(Demo
|
||||||
"${Qt5Quick_LIBS}"
|
|
||||||
Qt5::Widgets
|
Qt5::Widgets
|
||||||
|
"${Qt5Quick_LIBS}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a"
|
"${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,71 +1,60 @@
|
||||||
import QtQuick 2.6
|
import QtQuick 2.6
|
||||||
import QtQml.Models 2.2
|
|
||||||
import QtQuick.Controls 2.0
|
import QtQuick.Controls 2.0
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
import rust 1.0
|
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
width: 500
|
id: application
|
||||||
height: 480
|
x: windowX
|
||||||
|
y: windowY
|
||||||
|
width: windowWidth
|
||||||
|
height: windowHeight
|
||||||
visible: true
|
visible: true
|
||||||
ItemSelectionModel {
|
TabBar {
|
||||||
id: selectionModel
|
id: bar
|
||||||
model: fsModel
|
width: parent.width
|
||||||
|
TabButton { text: "style" }
|
||||||
|
TabButton { text: "object" }
|
||||||
|
TabButton { text: "list" }
|
||||||
|
TabButton { text: "tree" }
|
||||||
}
|
}
|
||||||
FibonacciList {
|
StackLayout {
|
||||||
id: fibonacciList
|
width: parent.width
|
||||||
}
|
anchors.top: bar.bottom
|
||||||
TabView {
|
anchors.bottom: parent.bottom
|
||||||
anchors.fill: parent
|
currentIndex: bar.currentIndex
|
||||||
Tab {
|
ComboBox {
|
||||||
title: "object"
|
currentIndex: qtquickIndex
|
||||||
RowLayout {
|
model: styles
|
||||||
TextField {
|
textRole: "display"
|
||||||
id: fibonacciInput
|
onCurrentIndexChanged: {
|
||||||
placeholderText: "Your number"
|
if (currentText && currentText != "QtQuick Controls 2") {
|
||||||
validator: IntValidator {bottom: 0; top: 100;}
|
widgets.currentText = currentText;
|
||||||
}
|
application.close();
|
||||||
Text {
|
|
||||||
text: "The Fibonacci number: " + fibonacci.result
|
|
||||||
}
|
|
||||||
Fibonacci {
|
|
||||||
id: fibonacci
|
|
||||||
input: parseInt(fibonacciInput.text, 10)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tab {
|
RowLayout {
|
||||||
title: "list"
|
TextField {
|
||||||
TableView {
|
id: fibonacciInput
|
||||||
id: listView
|
placeholderText: "Your number"
|
||||||
model: fibonacciList
|
validator: IntValidator {bottom: 0; top: 100;}
|
||||||
TableViewColumn {
|
Component.onCompleted: { text = fibonacci.input }
|
||||||
role: "display"
|
onTextChanged: { fibonacci.input = parseInt(text, 10) }
|
||||||
title: "Row"
|
}
|
||||||
width: 100
|
Text {
|
||||||
}
|
text: "The Fibonacci number: " + fibonacci.result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tab {
|
ListView {
|
||||||
title: "tree"
|
id: listView
|
||||||
TreeView {
|
model: fibonacciList
|
||||||
id: treeView
|
delegate: Row {
|
||||||
model: sortedFsModel
|
Text { text: result }
|
||||||
selection: selectionModel
|
|
||||||
TableViewColumn {
|
|
||||||
title: "Name"
|
|
||||||
role: "fileName"
|
|
||||||
}
|
|
||||||
TableViewColumn {
|
|
||||||
title: "Size"
|
|
||||||
role: "fileSize"
|
|
||||||
}
|
|
||||||
Component.onCompleted: {
|
|
||||||
var root = treeView.rootIndex;
|
|
||||||
var first = sortedFsModel.index(0, 0, root);
|
|
||||||
treeView.expand(first);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Text {
|
||||||
|
id: treeView
|
||||||
|
text: "No TreeView in QtQuick Controls 2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import QtQuick 2.6
|
||||||
import QtQml.Models 2.2
|
import QtQml.Models 2.2
|
||||||
import QtQuick.Controls 1.5
|
import QtQuick.Controls 1.5
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
import rust 1.0
|
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: application
|
id: application
|
||||||
|
|
|
@ -66,7 +66,7 @@ void copyWindowGeometry(QWidget* w, QQmlContext* c) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void createQtQuick(Models* models, QWidget* widgets) {
|
void createQtQuick(const QString& name, const QString& qml, Models* models, QWidget* widgets) {
|
||||||
QQmlApplicationEngine* engine = new QQmlApplicationEngine();
|
QQmlApplicationEngine* engine = new QQmlApplicationEngine();
|
||||||
QQmlContext* c = engine->rootContext();
|
QQmlContext* c = engine->rootContext();
|
||||||
c->setContextProperty("fsModel", &models->tree);
|
c->setContextProperty("fsModel", &models->tree);
|
||||||
|
@ -76,9 +76,9 @@ void createQtQuick(Models* models, QWidget* widgets) {
|
||||||
c->setContextProperty("styles", &models->styles);
|
c->setContextProperty("styles", &models->styles);
|
||||||
c->setContextProperty("widgets", widgets);
|
c->setContextProperty("widgets", widgets);
|
||||||
c->setContextProperty("qtquickIndex",
|
c->setContextProperty("qtquickIndex",
|
||||||
QVariant(models->styles.stringList().indexOf("QtQuick")));
|
QVariant(models->styles.stringList().indexOf(name)));
|
||||||
copyWindowGeometry(widgets, engine->rootContext());
|
copyWindowGeometry(widgets, engine->rootContext());
|
||||||
engine->load(QUrl(QStringLiteral("qrc:///demo.qml")));
|
engine->load(QUrl(qml));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -96,6 +96,9 @@ QComboBox* createStyleComboBox(Models* models) {
|
||||||
}
|
}
|
||||||
#ifdef QTQUICK
|
#ifdef QTQUICK
|
||||||
box->addItem("QtQuick");
|
box->addItem("QtQuick");
|
||||||
|
#endif
|
||||||
|
#ifdef QTQUICKCONTROLS2
|
||||||
|
box->addItem("QtQuick Controls 2");
|
||||||
#endif
|
#endif
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +127,13 @@ QWidget* createStyleTab(Models* models, QWidget* tabs) {
|
||||||
windowRect.setHeight(window->height());
|
windowRect.setHeight(window->height());
|
||||||
}
|
}
|
||||||
tabs->setVisible(false);
|
tabs->setVisible(false);
|
||||||
createQtQuick(models, box);
|
#ifdef QTQUICKCONTROLS2
|
||||||
|
if (text == "QtQuick Controls 2") {
|
||||||
|
createQtQuick("QtQuick Controls 2", "qrc:///demo-qtquick2.qml",
|
||||||
|
models, box);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
createQtQuick("QtQuick", "qrc:///demo.qml", models, box);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue