Maraiah/tycho/cc/tycho.h

168 lines
3.1 KiB
C
Raw Normal View History

2019-07-02 14:57:10 -07:00
#pragma once
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <optional>
2019-07-02 14:57:10 -07:00
#include <vector>
#include <QApplication>
#include <QCloseEvent>
#include <QDialog>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QIcon>
#include <QMainWindow>
#include <QMdiSubWindow>
#include <QMessageBox>
#include "../ui/ui_about.h"
#include "../ui/ui_license.h"
#include "../ui/ui_mapprops.h"
#include "../ui/ui_menu.h"
#include "../ui/ui_project.h"
#include "bindings.h"
#pragma clang diagnostic warning "-Winconsistent-missing-override"
2019-07-02 14:57:10 -07:00
class Project;
2019-07-02 14:57:10 -07:00
using byte = std::uint8_t;
class MapModel final : public IMapModel
2019-07-02 14:57:10 -07:00
{
2019-07-05 20:21:11 -07:00
Q_OBJECT
2019-07-02 14:57:10 -07:00
public:
2019-07-05 20:21:11 -07:00
explicit MapModel(Project *parent);
~MapModel() override;
2019-07-02 14:57:10 -07:00
2019-07-03 16:26:28 -07:00
public slots:
2019-07-05 20:21:11 -07:00
void deselect() override;
void select(QModelIndex const &index) override;
2019-07-03 16:26:28 -07:00
2019-07-02 14:57:10 -07:00
private:
2019-07-05 20:21:11 -07:00
QVariant data(const QModelIndex &index, int role) const override;
2019-07-02 14:57:10 -07:00
};
class MapView final : public IMapView
{
2019-07-05 20:21:11 -07:00
Q_OBJECT
public:
2019-07-05 20:21:11 -07:00
explicit MapView(Project *parent);
~MapView();
private:
2019-07-05 20:21:11 -07:00
MapModel *const m_mapModel;
};
2019-07-03 17:51:38 -07:00
class MapProps final : public QDialog,
private Ui::MapProps
{
2019-07-05 20:21:11 -07:00
Q_OBJECT
public:
2019-07-05 20:21:11 -07:00
explicit MapProps(Project *parent);
~MapProps();
2019-07-05 20:21:11 -07:00
void accept() override;
private:
2019-07-05 20:21:11 -07:00
MapModel *const m_mapModel;
};
2019-07-03 17:51:38 -07:00
class Menu final : public QMainWindow,
private Ui::Menu
2019-07-02 14:57:10 -07:00
{
2019-07-05 20:21:11 -07:00
Q_OBJECT
2019-07-02 14:57:10 -07:00
public:
2019-07-05 20:21:11 -07:00
explicit Menu(QWidget *parent = nullptr);
~Menu();
2019-07-02 14:57:10 -07:00
public slots:
2019-07-05 20:21:11 -07:00
void mapNew();
void mapOpen();
void openAbout();
void openAboutQt();
void openMapProperties();
void updateActions();
2019-07-02 14:57:10 -07:00
protected:
2019-07-05 20:21:11 -07:00
void closeEvent(QCloseEvent *event) override;
void openLicense(QWidget *parent);
2019-07-02 14:57:10 -07:00
private:
2019-07-05 20:21:11 -07:00
Project *activeProject() const;
QMdiSubWindow *activeSubWindow() const;
2019-07-05 20:21:11 -07:00
void addProject(Project *proj);
2019-07-02 14:57:10 -07:00
};
2019-07-03 17:51:38 -07:00
class Project final : public QMdiSubWindow,
private Ui::Project
{
2019-07-05 20:21:11 -07:00
Q_OBJECT
Q_PROPERTY(Type type READ type CONSTANT)
Q_PROPERTY(IProjectModel *model READ model CONSTANT)
Q_PROPERTY(MapModel *mapModel READ mapModel CONSTANT)
public:
2019-07-05 20:21:11 -07:00
enum Type {Map};
Q_ENUM(Type)
2019-07-05 20:21:11 -07:00
explicit Project(Type type);
~Project();
2019-07-05 20:21:11 -07:00
Type type() const;
IProjectModel *model() const;
MapModel *mapModel() const;
protected:
2019-07-05 20:21:11 -07:00
void closeEvent(QCloseEvent *event) override;
private:
2019-07-05 20:21:11 -07:00
Type const m_type;
IProjectModel *const m_model;
IProjectView *const m_view;
};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
template<typename... VA>
static inline
void dbgPrint([[maybe_unused]] char const *fmt, [[maybe_unused]] VA &&...va)
{
2019-07-05 20:21:11 -07:00
#ifdef TYCHO_DEBUG_ASSERTIONS
qDebug(fmt, std::forward<VA>(va)...);
#endif
}
#pragma clang diagnostic pop
#define dbgPrintFunc() dbgPrint("%s", __func__)
constexpr
std::uint32_t fourCC(byte a, byte b, byte c, byte d)
2019-07-02 14:57:10 -07:00
{
2019-07-05 20:21:11 -07:00
return (static_cast<std::uint32_t>(a) << 24) |
(static_cast<std::uint32_t>(b) << 16) |
(static_cast<std::uint32_t>(c) << 8) |
static_cast<std::uint32_t>(d);
2019-07-02 14:57:10 -07:00
}
QIcon getIcon(QString const &name);
2019-07-02 14:57:10 -07:00
extern "C" {
2019-07-05 20:21:11 -07:00
char const *tychoAuthors();
char const *tychoHomepage();
char const *tychoLicenseText();
char const *tychoRepository();
char const *tychoVersion();
2019-07-02 14:57:10 -07:00
}
// EOF