1
0
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:
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 \
\
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

View File

@ -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)
{
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?
}

View File

@ -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
{
class MainWindow : public QMainWindow {
Q_OBJECT
void createActions();
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
std::unique_ptr<Ui::MainWindow> ui;
std::unique_ptr<QTimer> timer;
private slots:
void open();
};
#endif // MAINWINDOW_H

View File

@ -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
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