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