diff --git a/.gitignore b/.gitignore index a007fea..367f77e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/* +.vscode/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c9ac06f..5ea247f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,44 +1,21 @@ -cmake_minimum_required(VERSION 3.22) - -project(metabolus - VERSION 0.1 - LANGUAGES CXX -) +cmake_minimum_required(VERSION 3.21) +project(metabolus LANGUAGES CXX) 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 -) +find_package(Qt6 REQUIRED COMPONENTS Widgets) 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 + src/MainWindow.cpp + src/MainWindow.h + src/MainWindow.ui + resources/resources.qrc ) target_link_libraries(metabolus - PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Qml - Qt6::Quick -) + PRIVATE Qt6::Widgets +) \ No newline at end of file diff --git a/qml/Main.qml b/qml/Main.qml deleted file mode 100644 index 476eaed..0000000 --- a/qml/Main.qml +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index d8a85db..0000000 --- a/qml/qmldir +++ /dev/null @@ -1 +0,0 @@ -module MyApp \ No newline at end of file diff --git a/qml/screens/MainScreen.qml b/qml/screens/MainScreen.qml deleted file mode 100644 index f2cd66a..0000000 --- a/qml/screens/MainScreen.qml +++ /dev/null @@ -1,9 +0,0 @@ - -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 deleted file mode 100644 index 73ed8d4..0000000 --- a/qml/screens/MainScreenUI.ui.qml +++ /dev/null @@ -1,99 +0,0 @@ - - -/* -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/resources/resources.qrc b/resources/resources.qrc new file mode 100644 index 0000000..e69de29 diff --git a/scripts/build.bat b/scripts/build.bat deleted file mode 100644 index 7d81447..0000000 --- a/scripts/build.bat +++ /dev/null @@ -1,11 +0,0 @@ - -@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 metabolus.exe diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..ef5744a --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,3 @@ + +cmake -S . -B build -G Ninja +cmake --build build diff --git a/src/AppController.cpp b/src/AppController.cpp deleted file mode 100644 index 70d840f..0000000 --- a/src/AppController.cpp +++ /dev/null @@ -1,29 +0,0 @@ - -#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 deleted file mode 100644 index cbdbb59..0000000 --- a/src/AppController.h +++ /dev/null @@ -1,30 +0,0 @@ -#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/MainWindow.cpp b/src/MainWindow.cpp new file mode 100644 index 0000000..41bdb84 --- /dev/null +++ b/src/MainWindow.cpp @@ -0,0 +1,88 @@ + +#include "MainWindow.h" +#include "ui_MainWindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + // Initialize UI + updateCounterLabel(); + + // Connect buttons to slots + connect(ui->buttonIncrement, &QPushButton::clicked, this, &MainWindow::onIncrementClicked); + connect(ui->buttonReset, &QPushButton::clicked, this, &MainWindow::onResetClicked); + + // slider business + connect(ui->slider, &QSlider::valueChanged, this, &MainWindow::onSliderValueChanged); + connect(ui->inputMin, &QLineEdit::editingFinished, this, &MainWindow::onMinChanged); + connect(ui->inputMax, &QLineEdit::editingFinished, this, &MainWindow::onMaxChanged); + connect(ui->inputStep, &QLineEdit::editingFinished, this, &MainWindow::onStepChanged); + connect(ui->inputValue, &QLineEdit::editingFinished, this, &MainWindow::onValueChanged); + +} + +MainWindow::~MainWindow() { + delete ui; +} + +void MainWindow::onIncrementClicked() { + counter_++; + updateCounterLabel(); +} + +void MainWindow::onResetClicked() { + counter_ = 0; + updateCounterLabel(); +} + +void MainWindow::updateCounterLabel() { + ui->labelCounter->setText(QString::number(counter_)); +} + +// allows only numbers to be set +void MainWindow::onSliderValueChanged(int value) { + QSignalBlocker blocker(ui->inputValue); + ui->inputValue->setText(QString::number(value)); +} + +// allows only values within the min, max to be set by the text field +void MainWindow::onValueChanged() { + bool ok = false; + int value = ui->inputValue->text().toInt(&ok); + if(!ok) return; + + value = qBound(ui->slider->minimum(), value, ui->slider->maximum()); + ui->slider->setValue(value); +} + +void MainWindow::applySliderRange() { + bool minOk, maxOk; + int min = ui->inputMin->text().toInt(&minOk); + int max = ui->inputMax->text().toInt(&maxOk); + if(!minOk || !maxOk || min > max) return; + + ui->slider->setRange(min, max); + + syncValueToUi(ui->slider->value()); +} + +void MainWindow::applySliderStep() { + bool ok; + int step = ui->inputStep->text().toInt(&ok); + if(!ok || step <= 0) return; + + ui->slider->setSingleStep(step); + ui->slider->setPageStep(step); +} + +void MainWindow::syncValueToUi(int value) { + QSignalBlocker block1(ui->slider); + QSignalBlocker block2(ui->inputValue); + + value = qBound(ui->slider->minimum(), value, ui->slider->maximum()); + ui->slider->setValue(value); + ui->inputValue->setText(QString::number(value)); +} diff --git a/src/MainWindow.h b/src/MainWindow.h new file mode 100644 index 0000000..1f63fbf --- /dev/null +++ b/src/MainWindow.h @@ -0,0 +1,41 @@ + +#pragma once + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + void onIncrementClicked(); + void onResetClicked(); + + void onSliderValueChanged(int value); + void onMinChanged() { applySliderRange(); } + void onMaxChanged() { applySliderRange(); } + void onStepChanged() { applySliderStep(); } + void onValueChanged(); + +private: + Ui::MainWindow *ui; + int counter_ = 0; + + int value = 0; + + void updateCounterLabel(); + + void applySliderRange(); + void applySliderStep(); + void syncValueToUi(int value); +}; diff --git a/src/MainWindow.ui b/src/MainWindow.ui new file mode 100644 index 0000000..06bc7ce --- /dev/null +++ b/src/MainWindow.ui @@ -0,0 +1,194 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 50 + 70 + 101 + 31 + + + + + 15 + + + + Increment + + + + + + 50 + 100 + 101 + 31 + + + + + 15 + + + + Reset + + + + + + 30 + 20 + 151 + 41 + + + + + 30 + + + + Counter + + + Qt::AlignmentFlag::AlignCenter + + + + + + 390 + 210 + 16 + 160 + + + + 50 + + + Qt::Orientation::Vertical + + + + + + 370 + 190 + 61 + 21 + + + + + 12 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + 370 + 170 + 61 + 21 + + + + + 12 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + 360 + 140 + 81 + 31 + + + + + 16 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + 370 + 370 + 61 + 21 + + + + + 12 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + + diff --git a/src/main.cpp b/src/main.cpp index e776d7a..6280c3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,24 +1,12 @@ -#include -#include -#include +#include +#include "MainWindow.h" -#include "AppController.h" +int main(int argc, char *argv[]) { + QApplication app(argc, argv); -int main(int argc, char *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/untitled.ui b/untitled.ui new file mode 100644 index 0000000..ffdec41 --- /dev/null +++ b/untitled.ui @@ -0,0 +1,194 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 50 + 70 + 101 + 31 + + + + + 15 + + + + Increment + + + + + + 50 + 100 + 101 + 31 + + + + + 15 + + + + Reset + + + + + + 30 + 20 + 151 + 41 + + + + + 30 + + + + Counter + + + Qt::AlignmentFlag::AlignCenter + + + + + + 390 + 210 + 16 + 160 + + + + 50 + + + Qt::Orientation::Vertical + + + + + + 370 + 190 + 61 + 21 + + + + + 12 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + 370 + 170 + 61 + 21 + + + + + 12 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + 360 + 140 + 81 + 31 + + + + + 16 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + 370 + 370 + 61 + 21 + + + + + 12 + PreferDefault + + + + Qt::LayoutDirection::LeftToRight + + + 100 + + + Qt::AlignmentFlag::AlignCenter + + + + + + +