1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Adds a Qt timer class. Precision seems to be 'acceptable'.

This commit is contained in:
Thomas Harte 2020-05-31 23:39:08 -04:00
parent 73131735fa
commit d64b4fbc26
8 changed files with 124 additions and 23 deletions

View File

@ -122,7 +122,8 @@ SOURCES += \
../../Storage/Tape/Parsers/*.cpp \ ../../Storage/Tape/Parsers/*.cpp \
\ \
main.cpp \ main.cpp \
mainwindow.cpp mainwindow.cpp \
timer.cpp
HEADERS += \ HEADERS += \
../../Activity/*.hpp \ ../../Activity/*.hpp \
@ -245,7 +246,8 @@ HEADERS += \
../../Storage/Tape/Formats/*.hpp \ ../../Storage/Tape/Formats/*.hpp \
../../Storage/Tape/Parsers/*.hpp \ ../../Storage/Tape/Parsers/*.hpp \
\ \
mainwindow.h mainwindow.h \
timer.h
FORMS += \ FORMS += \
mainwindow.ui mainwindow.ui

View File

@ -1,15 +1,57 @@
#include <QtWidgets>
#include <QObject>
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "timer.h"
Timer *t;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , 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() void MainWindow::createActions() {
{ // Create a file menu.
delete ui; 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?
} }

View File

@ -2,20 +2,27 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <memory>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
QT_END_NAMESPACE QT_END_NAMESPACE
class MainWindow : public QMainWindow class MainWindow : public QMainWindow {
{
Q_OBJECT Q_OBJECT
void createActions();
public: public:
MainWindow(QWidget *parent = nullptr); MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
private: private:
Ui::MainWindow *ui; std::unique_ptr<Ui::MainWindow> ui;
std::unique_ptr<QTimer> timer;
private slots:
void open();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -10,11 +10,30 @@
<height>600</height> <height>600</height>
</rect> </rect>
</property> </property>
<property name="minimumSize">
<size>
<width>400</width>
<height>300</height>
</size>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<widget class="QWidget" name="centralwidget"/> <widget class="QOpenGLWidget" name="openGLWidget">
<widget class="QMenuBar" name="menubar"/> </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 class="QStatusBar" name="statusbar"/>
</widget> </widget>
<resources/> <resources/>

14
OSBindings/Qt/timer.cpp Normal file
View 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
View 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