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

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 "mainwindow.hpp"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#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();
}
}

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_;
};