2020-06-01 03:39:08 +00:00
|
|
|
#include <QtWidgets>
|
|
|
|
#include <QObject>
|
|
|
|
|
2020-05-30 04:37:06 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
2020-06-01 03:39:08 +00:00
|
|
|
#include "timer.h"
|
|
|
|
|
2020-06-02 02:08:21 +00:00
|
|
|
/*
|
|
|
|
General Qt implementation notes:
|
|
|
|
|
|
|
|
* it seems like Qt doesn't offer a way to constrain the aspect ratio of a view by constraining
|
|
|
|
the size of the window (i.e. you can use a custom layout to constrain a view, but that won't
|
|
|
|
affect the window, so isn't useful for this project). Therefore the emulation window
|
|
|
|
*/
|
|
|
|
|
2020-05-30 04:37:06 +00:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2020-06-01 03:39:08 +00:00
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
2020-05-30 04:37:06 +00:00
|
|
|
{
|
2020-06-01 03:39:08 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
createActions();
|
|
|
|
|
2020-06-01 03:58:19 +00:00
|
|
|
// Set up the emulation timer. Bluffer's guide: the QTimer will post an
|
|
|
|
// event to an event loop. QThread is a thread with an event loop.
|
|
|
|
// My class, Timer, will be wired up to receive the QTimer's events.
|
|
|
|
qTimer = std::make_unique<QTimer>(this);
|
|
|
|
qTimer->setInterval(1);
|
|
|
|
|
|
|
|
timerThread = std::make_unique<QThread>(this);
|
|
|
|
|
|
|
|
timer = std::make_unique<Timer>();
|
|
|
|
timer->moveToThread(timerThread.get());
|
|
|
|
|
|
|
|
connect(qTimer.get(), SIGNAL(timeout()), timer.get(), SLOT(tick()));
|
|
|
|
|
|
|
|
// Start the thread and timer.
|
|
|
|
// TODO: not until there's actually something to display.
|
|
|
|
timerThread->start();
|
|
|
|
qTimer->start();
|
2020-05-30 04:37:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 03:39:08 +00:00
|
|
|
void MainWindow::createActions() {
|
|
|
|
// Create a file menu.
|
|
|
|
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
|
|
|
|
|
|
|
// QAction *newAct = new QAction(tr("&New"), this);
|
|
|
|
// newAct->setShortcuts(QKeySequence::New);
|
|
|
|
// newAct->setStatusTip(tr("Create a new file"));
|
|
|
|
// connect(newAct, &QAction::triggered, this, &MainWindow::newFile);
|
|
|
|
// fileMenu->addAction(newAct);
|
|
|
|
|
|
|
|
// Add file option: 'Open..."
|
|
|
|
QAction *openAct = new QAction(tr("&Open..."), this);
|
|
|
|
openAct->setShortcuts(QKeySequence::Open);
|
|
|
|
openAct->setStatusTip(tr("Open an existing file"));
|
|
|
|
connect(openAct, &QAction::triggered, this, &MainWindow::open);
|
|
|
|
fileMenu->addAction(openAct);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::open() {
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this);
|
2020-06-01 03:58:19 +00:00
|
|
|
if(!fileName.isEmpty()) {
|
|
|
|
qDebug() << "Should open" << fileName;
|
|
|
|
}
|
2020-06-01 03:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
2020-06-01 03:58:19 +00:00
|
|
|
// Stop the timer by asking its QThread to exit and
|
|
|
|
// waiting for it to do so.
|
|
|
|
timerThread->exit();
|
|
|
|
while(timerThread->isRunning());
|
2020-05-30 04:37:06 +00:00
|
|
|
}
|
|
|
|
|