1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-17 10:06:21 +00:00

Merge pull request #1293 from TomHarte/Qt6

Update to Qt 6.
This commit is contained in:
Thomas Harte 2023-12-29 23:05:43 -05:00 committed by GitHub
commit 7cb40f5d45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 135 additions and 49 deletions

View File

@ -1,4 +1,4 @@
QT += core gui multimedia widgets
QT += core gui multimedia widgets openglwidgets
# Be specific about C++17 but also try the vaguer C++1z for older
# versions of Qt.
@ -24,10 +24,10 @@ DEFINES += TARGET_QT
DEFINES += IGNORE_APPLE
QMAKE_CXXFLAGS_RELEASE += -DNDEBUG
# Generate warnings for any use of APIs deprecated prior to Qt 6.0.0.
# Development was performed against Qt 5.14.
# Generate warnings for any use of APIs deprecated prior to Qt 7.0.0.
# Development was performed against Qt 6.6.1.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x070000
SRC = $$PWD/../..

View File

@ -5,6 +5,9 @@
#include <QObject>
#include <QStandardPaths>
#include <QAudioDevice>
#include <QMediaDevices>
#include <QtWidgets>
#include <QtGlobal>
@ -314,24 +317,24 @@ void MainWindow::launchMachine() {
static constexpr size_t samplesPerBuffer = 256; // TODO: select this dynamically.
const auto speaker = audio_producer->get_speaker();
if(speaker) {
const QAudioDeviceInfo &defaultDeviceInfo = QAudioDeviceInfo::defaultOutputDevice();
if(!defaultDeviceInfo.isNull()) {
QAudioFormat idealFormat = defaultDeviceInfo.preferredFormat();
QAudioDevice device(QMediaDevices::defaultAudioOutput());
if(true) { // TODO: how to check that audio output is available in Qt6?
QAudioFormat idealFormat = device.preferredFormat();
// Use the ideal format's sample rate, provide stereo as long as at least two channels
// are available, and — at least for now — assume a good buffer size.
audioIsStereo = (idealFormat.channelCount() > 1) && speaker->get_is_stereo();
audioIs8bit = idealFormat.sampleSize() < 16;
audioIs8bit = idealFormat.sampleFormat() == QAudioFormat::UInt8;
idealFormat.setChannelCount(1 + int(audioIsStereo));
idealFormat.setSampleSize(audioIs8bit ? 8 : 16);
idealFormat.setSampleFormat(audioIs8bit ? QAudioFormat::UInt8 : QAudioFormat::Int16);
speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo);
speaker->set_delegate(this);
audioThread.start();
audioThread.performAsync([this, idealFormat] {
audioThread.performAsync([&] {
// Create an audio output.
audioOutput = std::make_unique<QAudioOutput>(idealFormat);
audioOutput = std::make_unique<QAudioSink>(device, idealFormat);
// Start the output. The additional `audioBuffer` is meant to minimise latency,
// believe it or not, given Qt's semantics.
@ -373,13 +376,13 @@ void MainWindow::launchMachine() {
QAction *const asKeyboardAction = new QAction(tr("Use Keyboard as Keyboard"), this);
asKeyboardAction->setCheckable(true);
asKeyboardAction->setChecked(true);
asKeyboardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
// asKeyboardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
inputMenu->addAction(asKeyboardAction);
QAction *const asJoystickAction = new QAction(tr("Use Keyboard as Joystick"), this);
asJoystickAction->setCheckable(true);
asJoystickAction->setChecked(false);
asJoystickAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
// asJoystickAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
inputMenu->addAction(asJoystickAction);
connect(asKeyboardAction, &QAction::triggered, this, [=] {
@ -755,12 +758,13 @@ void MainWindow::dropEvent(QDropEvent* event) {
QString unusedRoms;
for(const auto &url: event->mimeData()->urls()) {
const char *const name = url.toLocalFile().toUtf8();
FILE *const file = fopen(name, "rb");
const std::string name = url.toLocalFile().toStdString();
FILE *const file = fopen(name.c_str(), "rb");
if(!file) continue;
const auto contents = fileContentsAndClose(file);
if(!contents) continue;
CRC::CRC32 generator;
const uint32_t crc = generator.compute_crc(*contents);
@ -962,6 +966,7 @@ void MainWindow::setButtonPressed(int index, bool isPressed) {
#include "../../Analyser/Static/Macintosh/Target.hpp"
#include "../../Analyser/Static/MSX/Target.hpp"
#include "../../Analyser/Static/Oric/Target.hpp"
#include "../../Analyser/Static/PCCompatible/Target.hpp"
#include "../../Analyser/Static/ZX8081/Target.hpp"
#include "../../Analyser/Static/ZXSpectrum/Target.hpp"
@ -984,6 +989,7 @@ void MainWindow::startMachine() {
TEST(macintosh);
TEST(msx);
TEST(oric);
TEST(pc);
TEST(spectrum);
TEST(vic20);
TEST(zx80);
@ -1182,6 +1188,23 @@ void MainWindow::start_oric() {
launchTarget(std::move(target));
}
void MainWindow::start_pc() {
using Target = Analyser::Static::PCCompatible::Target;
auto target = std::make_unique<Target>();
switch(ui->pcSpeedComboBox->currentIndex()) {
default: target->speed = Target::Speed::ApproximatelyOriginal; break;
case 1: target->speed = Target::Speed::Fast; break;
}
switch(ui->pcVideoAdaptorComboBox->currentIndex()) {
default: target->adaptor = Target::VideoAdaptor::MDA; break;
case 1: target->adaptor = Target::VideoAdaptor::CGA; break;
}
launchTarget(std::move(target));
}
void MainWindow::start_spectrum() {
using Target = Analyser::Static::ZXSpectrum::Target;
auto target = std::make_unique<Target>();

View File

@ -1,12 +1,11 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QAudioOutput>
#include <QAudioSink>
#include <QMainWindow>
#include <memory>
#include <mutex>
#include <optional>
#include "audiobuffer.h"
#include "timer.h"
@ -71,7 +70,7 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
std::unique_ptr<Machine::DynamicMachine> machine;
std::mutex machineMutex;
std::unique_ptr<QAudioOutput> audioOutput;
std::unique_ptr<QAudioSink> audioOutput;
bool audioIs8bit = false, audioIsStereo = false;
void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector<int16_t> &buffer) override;
AudioBuffer audioBuffer;
@ -96,6 +95,7 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
void start_macintosh();
void start_msx();
void start_oric();
void start_pc();
void start_spectrum();
void start_vic20();
void start_zx80();

View File

@ -39,7 +39,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Chip RAM:</string>
</property>
@ -65,7 +65,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Fast RAM:</string>
</property>
@ -129,7 +129,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model:</string>
</property>
@ -160,7 +160,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Disk Controller:</string>
</property>
@ -214,7 +214,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model:</string>
</property>
@ -240,7 +240,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Memory Size:</string>
</property>
@ -294,7 +294,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model:</string>
</property>
@ -348,7 +348,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>RAM:</string>
</property>
@ -437,7 +437,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model:</string>
</property>
@ -463,7 +463,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Speed:</string>
</property>
@ -484,7 +484,7 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>EXOS:</string>
</property>
@ -510,7 +510,7 @@
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>BASIC:</string>
</property>
@ -541,7 +541,7 @@
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>DOS:</string>
</property>
@ -590,7 +590,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model:</string>
</property>
@ -649,7 +649,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model</string>
</property>
@ -691,7 +691,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Region</string>
</property>
@ -772,7 +772,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model:</string>
</property>
@ -798,7 +798,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Disk Interface:</string>
</property>
@ -852,6 +852,76 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="pcTab">
<attribute name="title">
<string>PC Compatible</string>
</attribute>
<layout class="QVBoxLayout">
<item>
<layout class="QHBoxLayout">
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Video Adaptor:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="pcVideoAdaptorComboBox">
<item>
<property name="text">
<string>MDA</string>
</property>
</item>
<item>
<property name="text">
<string>CGA</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Speed:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="pcSpeedComboBox">
<item>
<property name="text">
<string>Similar to Original</string>
</property>
</item>
<item>
<property name="text">
<string>Turbo</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="vic20Tab">
<attribute name="title">
<string>Vic-20</string>
@ -862,7 +932,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Region:</string>
</property>
@ -898,7 +968,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Memory Size:</string>
</property>
@ -972,7 +1042,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Memory Size:</string>
</property>
@ -1041,7 +1111,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Memory Size:</string>
</property>
@ -1090,7 +1160,7 @@
<item>
<layout class="QFormLayout">
<item row="0" column="0">
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Model:</string>
</property>
@ -1170,9 +1240,6 @@
</item>
<item>
<widget class="QPlainTextEdit" name="missingROMsBox">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>

View File

@ -3,7 +3,6 @@
#include <QApplication>
#include <QCursor>
#include <QDebug>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QKeyEvent>
#include <QMouseEvent>
@ -30,10 +29,7 @@ void ScanTargetWidget::paintGL() {
requestedRedrawTime = 0;
}
// TODO: if Qt 5.14 can be guaranteed, just use window()->screen().
const auto screenNumber = QApplication::desktop()->screenNumber(this);
QScreen *const screen = QGuiApplication::screens()[screenNumber];
QScreen *const screen = window()->screen();
const float newOutputScale = float(screen->devicePixelRatio());
if(outputScale != newOutputScale) {
outputScale = newOutputScale;