connected to gui

This commit is contained in:
zanostro 2025-11-12 19:05:16 +01:00
parent 42e884aced
commit 8a6e916876
7 changed files with 165 additions and 3 deletions

View file

@ -4,7 +4,7 @@ project(simulator_SIC_XE VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Put all build outputs under target/bin as requested
# Put all build outputs under target/bin
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/target/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR})
@ -28,8 +28,7 @@ if(EXISTS "${PROJECT_SOURCE_DIR}/src/main.cpp")
target_link_libraries(simulator_exec PRIVATE simulator_lib)
endif()
# Convenience target: `cmake --build build --target run`
# This target will build `simulator_exec` (if present) and then execute it.
if(TARGET simulator_exec)
add_custom_target(run
DEPENDS simulator_exec
@ -43,3 +42,7 @@ endif()
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Sources found: ${SOURCES}")
message(STATUS "Output directory: ${OUTPUT_DIR}")
if(EXISTS "${CMAKE_SOURCE_DIR}/gui/qt/CMakeLists.txt")
add_subdirectory(gui/qt)
endif()

View file

@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.16)
project(simulator_qt LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# Prefer Qt6, fall back to Qt5
find_package(Qt6 COMPONENTS Widgets QUIET)
if(NOT Qt6_FOUND)
# Try explicitly the system Qt6 cmake prefix on Debian/Ubuntu
find_package(Qt6 COMPONENTS Widgets QUIET PATHS /usr/lib/x86_64-linux-gnu)
endif()
if(NOT Qt6_FOUND)
# Fallback: try Qt5 if Qt6 is unavailable
find_package(Qt5 COMPONENTS Widgets QUIET)
endif()
if(Qt6_FOUND)
set(QT_LIB Qt6::Widgets)
elseif(Qt5_FOUND)
set(QT_LIB Qt5::Widgets)
else()
message(FATAL_ERROR "Qt6 or Qt5 not found. Install Qt development packages or set CMAKE_PREFIX_PATH to your Qt installation.")
endif()
set(GUI_SRCS
main.cpp
MainWindow.cpp
MachineController.cpp
)
set(GUI_HDRS
MainWindow.h
MachineController.h
)
add_executable(simulator_qt ${GUI_SRCS} ${GUI_HDRS})
# Use top-level include folder (works when added with add_subdirectory)
target_include_directories(simulator_qt PRIVATE ${CMAKE_SOURCE_DIR}/include)
# Link to core library target (must be defined by top-level CMake)
target_link_libraries(simulator_qt PRIVATE simulator_lib ${QT_LIB})
# Place runtime binary under repo/target/bin to match project layout
set_target_properties(simulator_qt PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/target/bin
)

View file

@ -0,0 +1,32 @@
#include "MachineController.h"
#include <chrono>
MachineController::MachineController(QObject *parent)
: QObject(parent)
{
}
MachineController::~MachineController() {
stop();
}
void MachineController::start() {
if (m_running.exchange(true)) return;
m_thread = std::thread([this]{ runLoop(); });
}
void MachineController::stop() {
if (!m_running.exchange(false)) return;
if (m_thread.joinable()) m_thread.join();
}
void MachineController::step() {
emit tick();
}
void MachineController::runLoop() {
while (m_running.load()) {
emit tick();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}

View file

@ -0,0 +1,27 @@
#ifndef MACHINECONTROLLER_H
#define MACHINECONTROLLER_H
#include <QObject>
#include <atomic>
#include <thread>
class MachineController : public QObject {
Q_OBJECT
public:
explicit MachineController(QObject *parent = nullptr);
~MachineController() override;
void start();
void stop();
void step();
signals:
void tick();
private:
void runLoop();
std::atomic<bool> m_running{false};
std::thread m_thread;
};
#endif // MACHINECONTROLLER_H

View file

@ -0,0 +1,20 @@
#include "MainWindow.h"
#include "MachineController.h"
#include <QLabel>
#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QWidget *central = new QWidget(this);
auto *layout = new QVBoxLayout(central);
auto *label = new QLabel("SIC/XE Simulator — GUI stub", central);
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
setCentralWidget(central);
m_controller = new MachineController(this);
setWindowTitle("SIC/XE Simulator");
}
MainWindow::~MainWindow() = default;

View file

@ -0,0 +1,18 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MachineController;
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
private:
MachineController *m_controller = nullptr;
};
#endif // MAINWINDOW_H

View file

@ -0,0 +1,9 @@
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char **argv) {
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}