initial port for Cevo game in C++ (libs)

This commit is contained in:
Geoffray Levasseur committed 2026-10-22 17:20:45 +02:00
commit 8436242032
375 files changed
+46282

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#pragma once
#include "Cevo/ApplicationInfo.h"
#include "Cevo/FormBase.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class FormAbout;
}
QT_END_NAMESPACE
namespace Cevo {
// Equivalent of FormAbout.pas's TFormAbout.
class FormAbout : public FormBase {
Q_OBJECT
public:
explicit FormAbout(QWidget *parent = nullptr);
~FormAbout() override;
const ApplicationInfo *applicationInfo() const { return m_applicationInfo; }
void setApplicationInfo(const ApplicationInfo *value) { m_applicationInfo = value; }
void updateInterface();
protected:
void showEvent(QShowEvent *event) override;
private slots:
void onHomePageClicked();
private:
Ui::FormAbout *ui;
const ApplicationInfo *m_applicationInfo = nullptr;
};
} // namespace Cevo
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include "Cevo/FormBase.h"
#include "Cevo/Item.h"
#include <QVector>
class QLabel;
class QWidget;
QT_BEGIN_NAMESPACE
namespace Ui {
class FormItem;
}
QT_END_NAMESPACE
namespace Cevo {
// Equivalent of FormItem.pas's TFormItem: builds one label+control pair per
// ItemField on the fly, based on each field's DataType.
class FormItem : public FormBase {
Q_OBJECT
public:
explicit FormItem(QWidget *parent = nullptr);
~FormItem() override;
Item *item() const { return m_item; }
void setItem(Item *value);
void updateInterface();
private slots:
void onOkClicked();
void onControlChanged();
private:
void initControls();
void loadData(Item *item);
void saveData(Item *item);
Ui::FormItem *ui;
Item *m_item = nullptr;
QVector<QWidget *> m_dataControls;
QVector<QLabel *> m_dataLabels;
};
} // namespace Cevo
+163
View File
@@ -0,0 +1,163 @@
#pragma once
#include "Cevo/FormBase.h"
#include <QDateTime>
#include <QElapsedTimer>
#include <QObject>
#include <QString>
#include <QStringList>
#include <functional>
#include <memory>
#include <vector>
class QCloseEvent;
class QTimer;
QT_BEGIN_NAMESPACE
namespace Ui {
class FormJobProgress;
}
QT_END_NAMESPACE
namespace Cevo {
class Job;
class FormJobProgress;
// Equivalent of JobProgressView.pas's TProgress. Safe to update from the
// job's worker thread: setters only touch this object's own data (never
// read back from another thread) and emit `changed()`, which Qt delivers
// as a queued call to FormJobProgress's slot since that object lives on
// the main thread - no mutex needed, unlike the original's TCriticalSection.
// Push-based: unlike the original (where only SetValue invoked OnChange,
// and SetMax/SetText only ever reached the UI via the 100ms poll timer),
// all three setters emit `changed()` here for immediate, lag-free updates.
class JobProgress : public QObject {
Q_OBJECT
public:
using QObject::QObject;
int value() const { return m_value; }
int max() const { return m_max; }
QString text() const { return m_text; }
void setMax(int value);
void setText(const QString &text);
void setValue(int value);
void increment();
void reset();
signals:
void changed();
private:
int m_value = 0;
int m_max = 100;
QString m_text;
};
// Equivalent of JobProgressView.pas's TJob.
class Job {
public:
explicit Job(FormJobProgress *owner);
QString title;
std::function<void(Job &)> method;
bool noThreaded = false;
// Kept for interface fidelity with TJob.WaitFor, which the original
// itself never reads anywhere either (write-only field upstream too).
bool waitFor = false;
bool finished = false;
QString resultString;
QDateTime startTime;
QDateTime endTime;
JobProgress progress;
// Appends to the owning dialog's log, marshalling to the main thread
// if called from the job's worker thread (equivalent of TJob.AddLogItem).
void addLogItem(const QString &text);
bool isTerminateRequested() const { return m_terminateRequested; }
void requestTerminate() { m_terminateRequested = true; }
private:
FormJobProgress *m_owner;
bool m_terminateRequested = false;
};
// Equivalent of JobProgressView.pas's TFormJobProgressView + TJobProgressView
// merged into one dialog (Qt's QDialog already is the "component that owns
// the form" the original split across two classes for Lazarus-IDE-palette
// reasons - RegisterComponents('Common', [TJobProgressView]) has no Qt
// equivalent). NOT ported: the OwnerDraw/OnOwnerDraw hook (lets a caller
// suppress the dialog and draw its own progress UI instead) - grepping the
// whole perso/cevo tree found no actual consumer of TJobProgressView at
// all, so this is dead infrastructure; drop it and simply don't call
// start() if you want fully custom progress UI.
class FormJobProgress : public FormBase {
Q_OBJECT
public:
explicit FormJobProgress(QWidget *parent = nullptr);
~FormJobProgress() override;
bool autoClose() const { return m_autoClose; }
void setAutoClose(bool value) { m_autoClose = value; }
// Delay, in ms, before the dialog actually shows itself once start() is
// running (0 shows immediately). Equivalent of TJobProgressView.ShowDelay.
int showDelay() const { return m_showDelay; }
void setShowDelay(int value) { m_showDelay = value; }
// Equivalent of TJobProgressView.AddJob. Ownership stays with this
// dialog; the returned pointer stays valid until clear() or destruction.
Job *addJob(const QString &title, std::function<void(Job &)> method, bool noThreaded = false,
bool waitFor = false);
void clear();
// Equivalent of TJobProgressView.Start: runs every added job in order,
// blocking the caller until all jobs finish or stop() is called, while
// pumping the Qt event loop (via Threading.h's runInThread()) so the
// dialog stays responsive - matches the original's
// Application.ProcessMessages-pumping wait loop.
void start();
// Equivalent of TJobProgressView.Stop / the Terminate property setter:
// cooperatively asks the current (and all pending) jobs to stop.
void stop();
bool isTerminateRequested() const { return m_terminateRequested; }
signals:
void jobFinished(Job *job);
protected:
void closeEvent(QCloseEvent *event) override;
private slots:
void onTimerUpdate();
private:
void reloadJobList();
void updateProgress();
void updateHeight();
void appendLog(const QString &text);
friend class Job;
Ui::FormJobProgress *ui;
QTimer *m_updateTimer;
std::vector<std::unique_ptr<Job>> m_jobs;
int m_currentJobIndex = -1;
Job *m_currentJob = nullptr;
bool m_finished = false;
bool m_autoClose = true;
int m_showDelay = 0;
bool m_terminateRequested = false;
QDateTime m_totalStartTime;
QElapsedTimer m_partElapsed;
QStringList m_log;
};
} // namespace Cevo
@@ -0,0 +1,47 @@
#pragma once
#include "Cevo/FormBase.h"
#include <QList>
#include <QPointer>
class QObject;
QT_BEGIN_NAMESPACE
namespace Ui {
class FormKeyShortcuts;
}
QT_END_NAMESPACE
namespace Cevo {
// Equivalent of FormKeyShortcuts.pas's TFormKeyShortcuts: lists every
// QAction found (recursively) under a set of source objects, with its
// shortcut, double-click/Enter to trigger it. Column sorting uses
// QTreeWidget's native header-click sorting - no ListViewSort port needed.
class FormKeyShortcuts : public FormBase {
Q_OBJECT
public:
explicit FormKeyShortcuts(QWidget *parent = nullptr);
~FormKeyShortcuts() override;
// Equivalent of LoadFromComponent: objects whose QAction children (found
// recursively) should be listed.
void setSourceObjects(const QList<QObject *> &objects) { m_sourceObjects = objects; }
void setMainWindow(QWidget *window) { m_mainWindow = window; }
protected:
void showEvent(QShowEvent *event) override;
private slots:
void onExecuteSelected();
private:
void reload();
Ui::FormKeyShortcuts *ui;
QList<QObject *> m_sourceObjects;
QPointer<QWidget> m_mainWindow;
};
} // namespace Cevo
+54
View File
@@ -0,0 +1,54 @@
#pragma once
#include "Cevo/FormBase.h"
#include "Cevo/Item.h"
class QAction;
QT_BEGIN_NAMESPACE
namespace Ui {
class FormList;
}
QT_END_NAMESPACE
namespace Cevo {
// Equivalent of FormList.pas's TFormList: add/modify/remove/clone items of
// a BaseItemList, with columns derived from the list's ItemFields.
class FormList : public FormBase {
Q_OBJECT
public:
explicit FormList(QWidget *parent = nullptr);
~FormList() override;
BaseItemList *list() const { return m_list; }
void setList(BaseItemList *value);
int minItemCount = 0;
int maxItemCount = -1; // -1: unlimited
protected:
void showEvent(QShowEvent *event) override;
private slots:
void onAdd();
void onModify();
void onRemove();
void onClone();
void onSelectAll();
void onSelectionChanged();
private:
void updateColumns();
void updateList();
void updateInterface();
Ui::FormList *ui;
BaseItemList *m_list = nullptr;
QAction *m_actionAdd = nullptr;
QAction *m_actionModify = nullptr;
QAction *m_actionRemove = nullptr;
QAction *m_actionClone = nullptr;
};
} // namespace Cevo
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include "Cevo/FormBase.h"
#include "Cevo/TestCase.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class FormTest;
}
QT_END_NAMESPACE
namespace Cevo {
// Equivalent of FormTest.pas's TFormTest.
class FormTest : public FormBase {
Q_OBJECT
public:
explicit FormTest(QWidget *parent = nullptr);
~FormTest() override;
TestCase *testCase() const { return m_testCase; }
void setTestCase(TestCase *value) { m_testCase = value; }
protected:
void showEvent(QShowEvent *event) override;
private slots:
void onRunClicked();
private:
Ui::FormTest *ui;
TestCase *m_testCase = nullptr;
};
} // namespace Cevo
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include "Cevo/FormBase.h"
#include "Cevo/TestCase.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class FormTests;
}
QT_END_NAMESPACE
namespace Cevo {
// Equivalent of FormTests.pas's TFormTests.
class FormTests : public FormBase {
Q_OBJECT
public:
explicit FormTests(QWidget *parent = nullptr);
~FormTests() override;
TestCases *testCases() const { return m_testCases; }
void setTestCases(TestCases *value);
protected:
void showEvent(QShowEvent *event) override;
private slots:
void onRunClicked();
void onRunSelected();
void onShowSelected();
void onSelectionChanged();
private:
void reloadList();
void updateInterface();
Ui::FormTests *ui;
TestCases *m_testCases = nullptr;
};
} // namespace Cevo