checkpoint

This commit is contained in:
2025-12-21 11:47:24 -06:00
parent 52ff5cff2b
commit dcd9886df2
11 changed files with 245 additions and 83 deletions

View File

@@ -1,24 +1,44 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.16) project(metabolus
VERSION 0.1
project(HelloQt LANGUAGES CXX) 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
) )
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
)

15
qml/Main.qml Normal file
View File

@@ -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
}
}

1
qml/qmldir Normal file
View File

@@ -0,0 +1 @@
module MyApp

View File

@@ -0,0 +1,9 @@
import QtQuick
import QtQuick.Controls
import MyApp 1.0
MainScreenUI {
//onIncrementClicked: app.increment()
//onResetClicked: app.reset()
}

View File

@@ -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"
}
]
}

View File

@@ -1,9 +1,11 @@
rm -r build @echo off
rmdir /S /Q build
mkdir build mkdir build
cd build cd build
cmake .. -G "MinGW Makefiles" cmake .. -G "MinGW Makefiles"
cmake --build . 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

29
src/AppController.cpp Normal file
View File

@@ -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();
}

30
src/AppController.h Normal file
View File

@@ -0,0 +1,30 @@
#pragma once
#include <QObject>
// 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_;
};

View File

@@ -1,13 +1,24 @@
#include <QApplication> #include <QGuiApplication>
#include "mainwindow.hpp" #include <QQmlApplicationEngine>
#include <QQmlContext>
#include "AppController.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QGuiApplication app(argc, argv);
MainWindow window; QQmlApplicationEngine engine;
window.show();
AppController controller;
engine.rootContext()->setContextProperty("appController", &controller);
engine.loadFromModule("MyApp", "Main");
if (engine.rootObjects().isEmpty()) {
return -1;
}
return app.exec(); return app.exec();
} }

View File

@@ -1,33 +0,0 @@
#include "mainwindow.hpp"
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
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_));
}

View File

@@ -1,21 +0,0 @@
#pragma once
#include <QMainWindow>
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_;
};