1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00
CLK/OSBindings/Qt/mainwindow.h

174 lines
4.6 KiB
C
Raw Normal View History

2024-01-22 02:49:59 +00:00
#pragma once
2023-12-31 04:03:15 +00:00
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QAudioSink>
#else
#include <QAudioOutput>
#endif
#include <QMainWindow>
#include <memory>
#include <mutex>
#include "audiobuffer.h"
#include "timer.h"
#include "ui_mainwindow.h"
#include "functionthread.h"
#include "keyboard.h"
#include "../../Analyser/Static/StaticAnalyser.hpp"
#include "../../Machines/Utility/MachineForTarget.hpp"
#include "../../Activity/Observer.hpp"
2020-06-28 21:57:20 +00:00
// There are machine-specific controls for the following:
2021-06-08 21:54:30 +00:00
#include "../../Machines/Apple/AppleII/AppleII.hpp"
2020-06-28 21:57:20 +00:00
#include "../../Machines/Atari/2600/Atari2600.hpp"
2021-06-08 21:54:30 +00:00
#include "../../Machines/Sinclair/ZX8081/ZX8081.hpp"
2020-06-28 21:57:20 +00:00
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegate, public ScanTargetWidget::MouseDelegate, public Activity::Observer {
Q_OBJECT
void createActions();
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
explicit MainWindow(const QString &fileName);
protected:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
2020-07-04 04:29:37 +00:00
void setMouseIsCaptured(bool) override;
void moveMouse(QPoint) override;
void setButtonPressed(int index, bool isPressed) override;
private:
std::unique_ptr<Ui::MainWindow> ui;
std::unique_ptr<Timer> timer;
// Initial setup stuff.
Analyser::Static::TargetList targets;
enum class UIPhase {
2020-06-29 02:50:24 +00:00
SelectingMachine, RequestingROMs, RunningMachine
} uiPhase = UIPhase::SelectingMachine;
QString openFileName;
2020-06-29 02:50:24 +00:00
void setUIPhase(UIPhase);
void launchMachine();
QString romRequestBaseText;
ROM::Request missingRoms;
// File drag and drop is supported.
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
// Ongoing state.
std::unique_ptr<Machine::DynamicMachine> machine;
2020-06-06 03:06:28 +00:00
std::mutex machineMutex;
2023-12-31 04:03:15 +00:00
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
std::unique_ptr<QAudioSink> audioOutput;
2023-12-31 04:03:15 +00:00
#else
std::unique_ptr<QAudioOutput> audioOutput;
#endif
bool audioIs8bit = false, audioIsStereo = false;
void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector<int16_t> &buffer) override;
AudioBuffer audioBuffer;
FunctionThread audioThread;
2020-06-06 03:06:28 +00:00
bool processEvent(QKeyEvent *);
void changeEvent(QEvent *) override;
private slots:
2020-06-19 03:34:37 +00:00
void startMachine();
void updateStatusBarText();
2020-06-19 03:34:37 +00:00
private:
2021-12-08 16:41:38 +00:00
void start_amiga();
2020-06-19 03:34:37 +00:00
void start_appleII();
void start_appleIIgs();
2020-06-19 03:34:37 +00:00
void start_amstradCPC();
void start_atariST();
void start_electron();
void start_enterprise();
2020-06-19 03:34:37 +00:00
void start_macintosh();
void start_msx();
void start_oric();
2023-12-30 03:55:34 +00:00
void start_pc();
void start_spectrum();
2020-06-19 03:34:37 +00:00
void start_vic20();
void start_zx80();
void start_zx81();
enum class KeyboardInputMode {
Keyboard, Joystick
} keyboardInputMode;
2020-06-26 22:25:56 +00:00
QAction *insertAction = nullptr;
bool insertFile(const QString &fileName);
2020-06-26 22:25:56 +00:00
bool launchFile(const QString &fileName);
2020-06-19 03:34:37 +00:00
void launchTarget(std::unique_ptr<Analyser::Static::Target> &&);
void restoreSelections();
void storeSelections();
void init();
void tile(const QMainWindow *previous);
QString getFilename(const char *title);
void closeEvent(QCloseEvent *event) override;
static inline int mainWindowCount = 0;
void deleteMachine();
QMenu *displayMenu = nullptr;
void addDisplayMenu(const std::string &machinePrefix, const std::string &compositeColour, const std::string &compositeMono, const std::string &svideo, const std::string &rgb);
QMenu *enhancementsMenu = nullptr;
2020-06-28 20:23:35 +00:00
QAction *automaticTapeControlAction = nullptr;
void addEnhancementsMenu(const std::string &machinePrefix, bool offerQuickLoad, bool offerQuickBoot);
void addEnhancementsItems(const std::string &machinePrefix, QMenu *menu, bool offerQuickLoad, bool offerQuickBoot, bool automatic_tape_motor_control);
QMenu *controlsMenu = nullptr;
2020-06-28 20:23:35 +00:00
QAction *stopTapeAction = nullptr;
QAction *startTapeAction = nullptr;
void addZX8081Menu(const std::string &machinePrefix);
2020-06-28 20:23:35 +00:00
void updateTapeControls();
2020-06-28 21:57:20 +00:00
void addAtari2600Menu();
void toggleAtari2600Switch(Atari2600Switch toggleSwitch);
2020-07-04 04:29:37 +00:00
void addAppleIIMenu();
void setAppleIISquarePixels(bool);
2020-07-04 04:29:37 +00:00
void setWindowTitle();
bool mouseIsCaptured = false;
QMenu *helpMenu = nullptr;
void addHelpMenu();
QMenu *inputMenu = nullptr;
KeyboardMapper keyMapper;
void register_led(const std::string &, uint8_t) override;
void set_led_status(const std::string &, bool) override;
std::recursive_mutex ledStatusesLock;
std::map<std::string, bool> ledStatuses;
void addActivityObserver();
};