mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Adds a Qt timer class. Precision seems to be 'acceptable'.
This commit is contained in:
parent
73131735fa
commit
d64b4fbc26
@ -47,7 +47,7 @@ class i8272 : public Storage::Disk::MFMController {
|
||||
|
||||
private:
|
||||
// The bus handler, for interrupt and DMA-driven usage. [TODO]
|
||||
BusHandler &bus_handler_;
|
||||
BusHandler &bus_handler_;
|
||||
std::unique_ptr<BusHandler> allocated_bus_handler_;
|
||||
|
||||
// Status registers.
|
||||
|
@ -122,7 +122,8 @@ SOURCES += \
|
||||
../../Storage/Tape/Parsers/*.cpp \
|
||||
\
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
mainwindow.cpp \
|
||||
timer.cpp
|
||||
|
||||
HEADERS += \
|
||||
../../Activity/*.hpp \
|
||||
@ -245,7 +246,8 @@ HEADERS += \
|
||||
../../Storage/Tape/Formats/*.hpp \
|
||||
../../Storage/Tape/Parsers/*.hpp \
|
||||
\
|
||||
mainwindow.h
|
||||
mainwindow.h \
|
||||
timer.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -1,15 +1,57 @@
|
||||
#include <QtWidgets>
|
||||
#include <QObject>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "timer.h"
|
||||
|
||||
Timer *t;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->setupUi(this);
|
||||
createActions();
|
||||
|
||||
// Start the emulation timer. TODO: not now.
|
||||
timer = std::make_unique<QTimer>(this);
|
||||
QThread *thread = new QThread(this);
|
||||
timer->setInterval(1);
|
||||
t = new Timer;
|
||||
t->moveToThread(thread);
|
||||
connect(timer.get(), SIGNAL(timeout()), t, SLOT(tick()));
|
||||
connect(thread, SIGNAL(finished()), t, SLOT(deleteLater()));
|
||||
thread->start();
|
||||
timer->start();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
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);
|
||||
// if(!fileName.isEmpty())
|
||||
// loadFile(fileName);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
// TODO: stop thread somehow?
|
||||
}
|
||||
|
||||
|
@ -2,20 +2,27 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
void createActions();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::MainWindow> ui;
|
||||
std::unique_ptr<QTimer> timer;
|
||||
|
||||
private slots:
|
||||
void open();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -10,11 +10,30 @@
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QMenuBar" name="menubar"/>
|
||||
<widget class="QOpenGLWidget" name="openGLWidget">
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
14
OSBindings/Qt/timer.cpp
Normal file
14
OSBindings/Qt/timer.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "timer.h"
|
||||
|
||||
#include "../../ClockReceiver/TimeTypes.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Timer::Timer(QObject *parent) : QObject(parent) {}
|
||||
|
||||
void Timer::tick() {
|
||||
// static int64_t last = 0;
|
||||
// const auto now = Time::nanos_now();
|
||||
// qDebug() << now - last;
|
||||
// last = now;
|
||||
}
|
17
OSBindings/Qt/timer.h
Normal file
17
OSBindings/Qt/timer.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Timer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Timer(QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void tick();
|
||||
};
|
||||
|
||||
#endif // TIMER_H
|
Loading…
Reference in New Issue
Block a user