diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f0393d..c9ac06f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,44 @@ +cmake_minimum_required(VERSION 3.22) -cmake_minimum_required(VERSION 3.16) - -project(HelloQt LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Adjust path to your Qt MinGW install -set(CMAKE_PREFIX_PATH "C:/Qt/6.7.2/mingw_64") - -find_package(Qt6 REQUIRED COMPONENTS Widgets) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -add_executable(HelloQt - src/main.cpp - src/mainwindow.hpp - src/mainwindow.cpp +project(metabolus + VERSION 0.1 + LANGUAGES CXX ) -target_link_libraries(HelloQt PRIVATE Qt6::Widgets) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_PREFIX_PATH "C:/Qt/6.10.1/mingw_64") + +find_package(Qt6 6.10 REQUIRED COMPONENTS + Core + Gui + Qml + Quick +) + +qt_standard_project_setup() + +qt_add_executable(metabolus + src/main.cpp + src/AppController.cpp + src/AppController.h +) + +qt_add_qml_module(metabolus + URI MyApp + VERSION 1.0 + + QML_FILES + qml/Main.qml + qml/screens/MainScreen.qml + qml/screens/MainScreenUI.ui.qml +) + +target_link_libraries(metabolus + PRIVATE + Qt6::Core + Qt6::Gui + Qt6::Qml + Qt6::Quick +) diff --git a/qml/Main.qml b/qml/Main.qml new file mode 100644 index 0000000..476eaed --- /dev/null +++ b/qml/Main.qml @@ -0,0 +1,15 @@ +import QtQuick +import QtQuick.Window +import MyApp 1.0 + +Window { + width: 800 + height: 600 + visible: true + title: "metabolus" + color: "black" + + MainScreen { + anchors.fill: parent + } +} \ No newline at end of file diff --git a/qml/qmldir b/qml/qmldir new file mode 100644 index 0000000..d8a85db --- /dev/null +++ b/qml/qmldir @@ -0,0 +1 @@ +module MyApp \ No newline at end of file diff --git a/qml/screens/MainScreen.qml b/qml/screens/MainScreen.qml new file mode 100644 index 0000000..f2cd66a --- /dev/null +++ b/qml/screens/MainScreen.qml @@ -0,0 +1,9 @@ + +import QtQuick +import QtQuick.Controls +import MyApp 1.0 + +MainScreenUI { + //onIncrementClicked: app.increment() + //onResetClicked: app.reset() +} diff --git a/qml/screens/MainScreenUI.ui.qml b/qml/screens/MainScreenUI.ui.qml new file mode 100644 index 0000000..73ed8d4 --- /dev/null +++ b/qml/screens/MainScreenUI.ui.qml @@ -0,0 +1,99 @@ + + +/* +This is a UI file (.ui.qml) that is intended to be edited in Qt Design Studio only. +It is supposed to be strictly declarative and only uses a subset of QML. If you edit +this file manually, you might introduce QML code that is not supported by Qt Design Studio. +Check out https://doc.qt.io/qtcreator/creator-quick-ui-forms.html for details on .ui.qml files. +*/ +import QtQuick +import QtQuick.Controls +import MyApp 1.0 + +Rectangle { + id: rectangle + width: Constants.width + height: Constants.height + color: "#181818" + + Slider { + id: slider + x: 300 + y: 282 + value: 0.5 + rotation: -90 + live: true + } + + TextInput { + id: sliderMax + x: 360 + y: 179 + width: 80 + height: 20 + color: "#b9eaff" + text: qsTr("100") + font.pixelSize: 20 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignBottom + } + + TextInput { + id: sliderMin + x: 360 + y: 401 + width: 80 + height: 20 + color: "#b9eaff" + text: qsTr("100") + font.pixelSize: 20 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignBottom + } + + TextInput { + id: sliderValue + x: 360 + y: 153 + width: 80 + height: 20 + color: "#63b9de" + text: qsTr("100") + font.pixelSize: 30 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignBottom + } + + Button { + id: buttonReset + x: 359 + y: 504 + width: 81 + height: 32 + text: qsTr("Reset") + } + + Button { + id: buttonIncrement + x: 359 + y: 542 + text: qsTr("Increment") + } + + Text { + id: text1 + x: 340 + y: 471 + width: 120 + height: 27 + color: "#e8cece" + text: qsTr("Text") + font.pixelSize: 20 + horizontalAlignment: Text.AlignHCenter + } + states: [ + State { + name: "clicked" + } + ] +} diff --git a/scripts/build.bat b/scripts/build.bat index a2c594b..7d81447 100644 --- a/scripts/build.bat +++ b/scripts/build.bat @@ -1,9 +1,11 @@ -rm -r build +@echo off + +rmdir /S /Q build mkdir build cd build cmake .. -G "MinGW Makefiles" cmake --build . -C:\Qt\6.10.1\mingw_64\bin\windeployqt.exe HelloQt.exe +C:\Qt\6.10.1\mingw_64\bin\windeployqt.exe metabolus.exe diff --git a/src/AppController.cpp b/src/AppController.cpp new file mode 100644 index 0000000..70d840f --- /dev/null +++ b/src/AppController.cpp @@ -0,0 +1,29 @@ + +#include "AppController.h" + +AppController::AppController(QObject *parent) + : QObject(parent) +{ + m_status = "Ready"; +} + +void AppController::setSliderValue(int val) { + + if(sliderValue_ == val) return; + sliderValue_ = val; + emit sliderValueChanged(); +} + +void AppController::setSliderMin(int val) { + + if(sliderMin_ == val) return; + sliderMin_ = val; + emit sliderMinChanged(); +} + +void AppController::setSliderMax(int val) { + + if(sliderMax_ == val) return; + sliderMax_ = val; + emit sliderMaxChanged(); +} diff --git a/src/AppController.h b/src/AppController.h new file mode 100644 index 0000000..cbdbb59 --- /dev/null +++ b/src/AppController.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +// AppController is the bridge from the QML logic to the C++ app +class AppController : public QObject +{ + Q_OBJECT + Q_PROPERTY(int sliderValue READ sliderValue WRITE setSliderValue NOTIFY sliderValueChanged) + Q_PROPERTY(int sliderMin READ sliderMin WRITE setSliderMin NOTIFY sliderMinChanged) + Q_PROPERTY(int sliderMax READ sliderMax WRITE setSliderMax NOTIFY sliderMaxChanged) + +public: + explicit AppController(QObject *parent = nullptr); + + int sliderValue(int val) { return sliderValue_; } + int sliderMin(int val) { return sliderMin_; } + int sliderMax(int val) { return sliderMax_; } + + void setSliderValue(); + void setSliderMin(); + void setSliderMax(); + +private: + + int sliderValue_; + int sliderMin_; + int sliderMax_; + +}; diff --git a/src/main.cpp b/src/main.cpp index a3a39c8..e776d7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,24 @@ -#include -#include "mainwindow.hpp" +#include +#include +#include + +#include "AppController.h" int main(int argc, char *argv[]) { - QApplication app(argc, argv); + QGuiApplication app(argc, argv); - MainWindow window; - window.show(); + QQmlApplicationEngine engine; + AppController controller; + engine.rootContext()->setContextProperty("appController", &controller); + + engine.loadFromModule("MyApp", "Main"); + + if (engine.rootObjects().isEmpty()) { + return -1; + } + return app.exec(); -} +} \ No newline at end of file diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp deleted file mode 100644 index 13b5fc9..0000000 --- a/src/mainwindow.cpp +++ /dev/null @@ -1,33 +0,0 @@ - -#include "mainwindow.hpp" - -#include -#include -#include -#include - -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - - // probably this will be in a qml file - auto *central = new QWidget(this); - auto *layout = new QVBoxLayout(central); - - label_ = new QLabel("cases: 0", this); - label_->setAlignment(Qt::AlignCenter); - - button_ = new QPushButton("many such cases !", this); - - layout->addWidget(label_); - layout->addWidget(button_); - - setCentralWidget(central); - setWindowTitle("moblus !!!"); - resize(400, 200); - - connect(button_, &QPushButton::clicked, this, &MainWindow::incrementCounter); -} - -void MainWindow::incrementCounter() { - counter_++; - label_->setText(QString("cases: %1").arg(counter_)); -} \ No newline at end of file diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp deleted file mode 100644 index dc4a3c2..0000000 --- a/src/mainwindow.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -class QLabel; -class QPushButton; - -class MainWindow : public QMainWindow { - Q_OBJECT - - public: - explicit MainWindow(QWidget *parent = nullptr); - - private slots: - void incrementCounter(); - - private: - int counter_ = 0; - QLabel *label_; - QPushButton *button_; -}; \ No newline at end of file