1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Merge pull request #809 from TomHarte/QtActivity

Exposes activity lights in Qt.
This commit is contained in:
Thomas Harte 2020-07-10 23:32:38 -04:00 committed by GitHub
commit 9be56aa4a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 1 deletions

View File

@ -74,6 +74,9 @@ void MainWindow::deleteMachine() {
if(controlsMenu) menuBar()->removeAction(controlsMenu->menuAction());
if(inputMenu) menuBar()->removeAction(inputMenu->menuAction());
displayMenu = enhancementsMenu = controlsMenu = inputMenu = nullptr;
// Remove the status bar, if any.
setStatusBar(nullptr);
}
MainWindow::~MainWindow() {
@ -453,6 +456,9 @@ void MainWindow::launchMachine() {
// Push the help menu after any that were just added.
addHelpMenu();
// Add activity LED UI.
addActivityObserver();
}
void MainWindow::addDisplayMenu(const std::string &machinePrefix, const std::string &compositeColour, const std::string &compositeMono, const std::string &svideo, const std::string &rgb) {
@ -1320,3 +1326,36 @@ void MainWindow::restoreSelections() {
#undef CheckBox
#undef ComboBox
}
// MARK: - Activity observation
void MainWindow::addActivityObserver() {
auto activitySource = machine->activity_source();
if(!activitySource) return;
setStatusBar(new QStatusBar());
activitySource->set_activity_observer(this);
}
void MainWindow::register_led(const std::string &name) {
ledStatuses[name] = false;
updateStatusBarText();
}
void MainWindow::set_led_status(const std::string &name, bool isLit) {
ledStatuses[name] = isLit;
updateStatusBarText(); // Assumption here: Qt's attempt at automatic thread confinement will work here.
}
void MainWindow::updateStatusBarText() {
QString fullText;
bool isFirst = true;
for(const auto &pair: ledStatuses) {
if(!isFirst) fullText += " | ";
fullText += QString::fromStdString(pair.first);
fullText += " ";
fullText += pair.second ? "" : "";
isFirst = false;
}
statusBar()->showMessage(fullText);
}

View File

@ -15,6 +15,8 @@
#include "../../Analyser/Static/StaticAnalyser.hpp"
#include "../../Machines/Utility/MachineForTarget.hpp"
#include "../../Activity/Observer.hpp"
// There are machine-specific controls for the following:
#include "../../Machines/ZX8081/ZX8081.hpp"
#include "../../Machines/Atari/2600/Atari2600.hpp"
@ -23,7 +25,7 @@ QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegate, public ScanTargetWidget::MouseDelegate {
class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegate, public ScanTargetWidget::MouseDelegate, public Activity::Observer {
Q_OBJECT
void createActions();
@ -139,6 +141,12 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
QMenu *inputMenu = nullptr;
std::optional<Inputs::Keyboard::Key> keyForEvent(QKeyEvent *);
void register_led(const std::string &) override;
void set_led_status(const std::string &, bool) override;
std::map<std::string, bool> ledStatuses;
void addActivityObserver();
void updateStatusBarText();
};
#endif // MAINWINDOW_H