qt: switch to polling for status bar updating
This commit is contained in:
@@ -39,6 +39,7 @@ extern uint64_t tsc;
|
||||
#include <86box/machine.h>
|
||||
#include <86box/network.h>
|
||||
#include <86box/ui.h>
|
||||
#include <86box/machine_status.h>
|
||||
};
|
||||
|
||||
#include <QIcon>
|
||||
@@ -92,17 +93,21 @@ namespace {
|
||||
|
||||
struct StateActive {
|
||||
std::unique_ptr<QLabel> label;
|
||||
QTimer timer;
|
||||
PixmapSetActive* pixmaps = nullptr;
|
||||
bool active = false;
|
||||
|
||||
void setActive(bool b) {
|
||||
active = b;
|
||||
if (! label) {
|
||||
if (!label || b == active)
|
||||
return;
|
||||
active = b;
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
if (!label)
|
||||
return;
|
||||
}
|
||||
label->setPixmap(active ? pixmaps->active : pixmaps->normal);
|
||||
timer.start(75);
|
||||
}
|
||||
};
|
||||
struct StateEmpty {
|
||||
@@ -111,33 +116,42 @@ namespace {
|
||||
bool empty = false;
|
||||
|
||||
void setEmpty(bool e) {
|
||||
empty = e;
|
||||
if (! label) {
|
||||
if (!label || e == empty)
|
||||
return;
|
||||
empty = e;
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
if (!label)
|
||||
return;
|
||||
}
|
||||
label->setPixmap(empty ? pixmaps->empty : pixmaps->normal);
|
||||
}
|
||||
};
|
||||
struct StateEmptyActive {
|
||||
std::unique_ptr<QLabel> label;
|
||||
QTimer timer;
|
||||
PixmapSetEmptyActive* pixmaps = nullptr;
|
||||
bool empty = false;
|
||||
bool active = false;
|
||||
|
||||
void setActive(bool b) {
|
||||
if (!label || b == active)
|
||||
return;
|
||||
|
||||
active = b;
|
||||
refresh();
|
||||
timer.start(75);
|
||||
}
|
||||
void setEmpty(bool b) {
|
||||
if (!label || b == empty)
|
||||
return;
|
||||
|
||||
empty = b;
|
||||
refresh();
|
||||
}
|
||||
void refresh() {
|
||||
if (! label) {
|
||||
if (!label)
|
||||
return;
|
||||
}
|
||||
if (empty) {
|
||||
label->setPixmap(active ? pixmaps->empty_active : pixmaps->empty);
|
||||
} else {
|
||||
@@ -190,26 +204,20 @@ struct MachineStatus::States {
|
||||
cartridge[0].pixmaps = &pixmaps.cartridge;
|
||||
cartridge[1].pixmaps = &pixmaps.cartridge;
|
||||
cassette.pixmaps = &pixmaps.cassette;
|
||||
QObject::connect(&cassette.timer, &QTimer::timeout, parent, [&]{ cassette.setActive(false); });
|
||||
for (auto& f : fdd) {
|
||||
f.pixmaps = &pixmaps.floppy_disabled;
|
||||
QObject::connect(&f.timer, &QTimer::timeout, parent, [&]{ f.setActive(false); });
|
||||
}
|
||||
for (auto& c : cdrom) {
|
||||
c.pixmaps = &pixmaps.cdrom;
|
||||
QObject::connect(&c.timer, &QTimer::timeout, parent, [&]{ c.setActive(false); });
|
||||
}
|
||||
for (auto& z : zip) {
|
||||
z.pixmaps = &pixmaps.zip;
|
||||
QObject::connect(&z.timer, &QTimer::timeout, parent, [&]{ z.setActive(false); });
|
||||
}
|
||||
for (auto& m : mo) {
|
||||
m.pixmaps = &pixmaps.mo;
|
||||
QObject::connect(&m.timer, &QTimer::timeout, parent, [&]{ m.setActive(false); });
|
||||
}
|
||||
for (auto& h : hdds) {
|
||||
h.pixmaps = &pixmaps.hd;
|
||||
QObject::connect(&h.timer, &QTimer::timeout, parent, [&]{ h.setActive(false); });
|
||||
}
|
||||
net.pixmaps = &pixmaps.net;
|
||||
}
|
||||
@@ -227,9 +235,12 @@ struct MachineStatus::States {
|
||||
};
|
||||
|
||||
MachineStatus::MachineStatus(QObject *parent) :
|
||||
QObject(parent)
|
||||
QObject(parent),
|
||||
refreshTimer(new QTimer(this))
|
||||
{
|
||||
d = std::make_unique<MachineStatus::States>(this);
|
||||
connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons);
|
||||
refreshTimer->start(75);
|
||||
}
|
||||
|
||||
MachineStatus::~MachineStatus() = default;
|
||||
@@ -321,6 +332,38 @@ static int hdd_count(int bus) {
|
||||
return(c);
|
||||
}
|
||||
|
||||
void MachineStatus::refreshIcons() {
|
||||
for (size_t i = 0; i < FDD_NUM; ++i) {
|
||||
d->fdd[i].setActive(machine_status.fdd[i].active);
|
||||
d->fdd[i].setEmpty(machine_status.fdd[i].empty);
|
||||
}
|
||||
for (size_t i = 0; i < CDROM_NUM; ++i) {
|
||||
d->cdrom[i].setActive(machine_status.cdrom[i].active);
|
||||
d->cdrom[i].setEmpty(machine_status.cdrom[i].empty);
|
||||
}
|
||||
for (size_t i = 0; i < ZIP_NUM; i++) {
|
||||
d->zip[i].setActive(machine_status.zip[i].active);
|
||||
d->zip[i].setEmpty(machine_status.zip[i].empty);
|
||||
}
|
||||
for (size_t i = 0; i < MO_NUM; i++) {
|
||||
d->mo[i].setActive(machine_status.mo[i].active);
|
||||
d->mo[i].setEmpty(machine_status.mo[i].empty);
|
||||
}
|
||||
|
||||
d->cassette.setEmpty(machine_status.cassette.empty);
|
||||
|
||||
for (size_t i = 0; i < HDD_BUS_USB; i++) {
|
||||
d->hdds[i].setActive(machine_status.hdd[i].active);
|
||||
}
|
||||
|
||||
d->net.setActive(machine_status.net.active);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
d->cartridge[i].setEmpty(machine_status.cartridge[i].empty);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
bool has_mfm = machine_has_flags(machine, MACHINE_MFM) > 0;
|
||||
bool has_xta = machine_has_flags(machine, MACHINE_XTA) > 0;
|
||||
@@ -358,6 +401,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
if (cassette_enable) {
|
||||
d->cassette.label = std::make_unique<ClickableLabel>();
|
||||
d->cassette.setEmpty(QString(cassette_fname).isEmpty());
|
||||
d->cassette.refresh();
|
||||
connect((ClickableLabel*)d->cassette.label.get(), &ClickableLabel::clicked, [](QPoint pos) {
|
||||
MediaMenu::ptr->cassetteMenu->popup(pos - QPoint(0, MediaMenu::ptr->cassetteMenu->sizeHint().height()));
|
||||
});
|
||||
@@ -373,6 +417,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
d->cartridge[i].label = std::make_unique<ClickableLabel>();
|
||||
d->cartridge[i].setEmpty(QString(cart_fns[i]).isEmpty());
|
||||
d->cartridge[i].refresh();
|
||||
connect((ClickableLabel*)d->cartridge[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
|
||||
MediaMenu::ptr->cartridgeMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cartridgeMenus[i]->sizeHint().height()));
|
||||
});
|
||||
@@ -397,6 +442,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
d->fdd[i].label = std::make_unique<ClickableLabel>();
|
||||
d->fdd[i].setEmpty(QString(floppyfns[i]).isEmpty());
|
||||
d->fdd[i].setActive(false);
|
||||
d->fdd[i].refresh();
|
||||
connect((ClickableLabel*)d->fdd[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
|
||||
MediaMenu::ptr->floppyMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->floppyMenus[i]->sizeHint().height()));
|
||||
});
|
||||
@@ -412,6 +458,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
d->cdrom[i].label = std::make_unique<ClickableLabel>();
|
||||
d->cdrom[i].setEmpty(cdrom[i].host_drive != 200 || QString(cdrom[i].image_path).isEmpty());
|
||||
d->cdrom[i].setActive(false);
|
||||
d->cdrom[i].refresh();
|
||||
connect((ClickableLabel*)d->cdrom[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
|
||||
MediaMenu::ptr->cdromMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cdromMenus[i]->sizeHint().height()));
|
||||
});
|
||||
@@ -427,6 +474,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
d->zip[i].label = std::make_unique<ClickableLabel>();
|
||||
d->zip[i].setEmpty(QString(zip_drives[i].image_path).isEmpty());
|
||||
d->zip[i].setActive(false);
|
||||
d->zip[i].refresh();
|
||||
connect((ClickableLabel*)d->zip[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
|
||||
MediaMenu::ptr->zipMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->zipMenus[i]->sizeHint().height()));
|
||||
});
|
||||
@@ -442,6 +490,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
d->mo[i].label = std::make_unique<ClickableLabel>();
|
||||
d->mo[i].setEmpty(QString(mo_drives[i].image_path).isEmpty());
|
||||
d->mo[i].setActive(false);
|
||||
d->mo[i].refresh();
|
||||
connect((ClickableLabel*)d->mo[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) {
|
||||
MediaMenu::ptr->moMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->moMenus[i]->sizeHint().height()));
|
||||
});
|
||||
@@ -457,24 +506,28 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
if ((has_mfm || hdc_name.left(5) == QStringLiteral("st506")) && c_mfm > 0) {
|
||||
d->hdds[HDD_BUS_MFM].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_MFM].setActive(false);
|
||||
d->hdds[HDD_BUS_MFM].refresh();
|
||||
d->hdds[HDD_BUS_MFM].label->setToolTip(tr("Hard disk (%s)").replace("%s", "MFM/RLL"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_MFM].label.get());
|
||||
}
|
||||
if ((has_esdi || hdc_name.left(4) == QStringLiteral("esdi")) && c_esdi > 0) {
|
||||
d->hdds[HDD_BUS_ESDI].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_ESDI].setActive(false);
|
||||
d->hdds[HDD_BUS_ESDI].refresh();
|
||||
d->hdds[HDD_BUS_ESDI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "ESDI"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_ESDI].label.get());
|
||||
}
|
||||
if ((has_xta || hdc_name.left(3) == QStringLiteral("xta")) && c_xta > 0) {
|
||||
d->hdds[HDD_BUS_XTA].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_XTA].setActive(false);
|
||||
d->hdds[HDD_BUS_XTA].refresh();
|
||||
d->hdds[HDD_BUS_XTA].label->setToolTip(tr("Hard disk (%s)").replace("%s", "XTA"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_XTA].label.get());
|
||||
}
|
||||
if ((hasIDE() || hdc_name.left(5) == QStringLiteral("xtide") || hdc_name.left(3) == QStringLiteral("ide")) && c_ide > 0) {
|
||||
d->hdds[HDD_BUS_IDE].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_IDE].setActive(false);
|
||||
d->hdds[HDD_BUS_IDE].refresh();
|
||||
d->hdds[HDD_BUS_IDE].label->setToolTip(tr("Hard disk (%s)").replace("%s", "IDE"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_IDE].label.get());
|
||||
}
|
||||
@@ -482,6 +535,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
(scsi_card_current[2] != 0) || (scsi_card_current[3] != 0)) && c_scsi > 0) {
|
||||
d->hdds[HDD_BUS_SCSI].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_SCSI].setActive(false);
|
||||
d->hdds[HDD_BUS_SCSI].refresh();
|
||||
d->hdds[HDD_BUS_SCSI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "SCSI"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_SCSI].label.get());
|
||||
}
|
||||
@@ -489,6 +543,7 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
if (do_net) {
|
||||
d->net.label = std::make_unique<QLabel>();
|
||||
d->net.setActive(false);
|
||||
d->net.refresh();
|
||||
d->net.label->setToolTip(tr("Network"));
|
||||
sbar->addWidget(d->net.label.get());
|
||||
}
|
||||
@@ -505,72 +560,6 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
sbar->addWidget(d->text.get());
|
||||
}
|
||||
|
||||
void MachineStatus::setActivity(int tag, bool active) {
|
||||
int category = tag & 0xfffffff0;
|
||||
int item = tag & 0xf;
|
||||
switch (category) {
|
||||
case SB_CASSETTE:
|
||||
break;
|
||||
case SB_CARTRIDGE:
|
||||
break;
|
||||
case SB_FLOPPY:
|
||||
d->fdd[item].setActive(active);
|
||||
break;
|
||||
case SB_CDROM:
|
||||
d->cdrom[item].setActive(active);
|
||||
break;
|
||||
case SB_ZIP:
|
||||
d->zip[item].setActive(active);
|
||||
break;
|
||||
case SB_MO:
|
||||
d->mo[item].setActive(active);
|
||||
break;
|
||||
case SB_HDD:
|
||||
d->hdds[item].setActive(active);
|
||||
break;
|
||||
case SB_NETWORK:
|
||||
d->net.setActive(active);
|
||||
break;
|
||||
case SB_SOUND:
|
||||
break;
|
||||
case SB_TEXT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MachineStatus::setEmpty(int tag, bool empty) {
|
||||
int category = tag & 0xfffffff0;
|
||||
int item = tag & 0xf;
|
||||
switch (category) {
|
||||
case SB_CASSETTE:
|
||||
d->cassette.setEmpty(empty);
|
||||
break;
|
||||
case SB_CARTRIDGE:
|
||||
d->cartridge[item].setEmpty(empty);
|
||||
break;
|
||||
case SB_FLOPPY:
|
||||
d->fdd[item].setEmpty(empty);
|
||||
break;
|
||||
case SB_CDROM:
|
||||
d->cdrom[item].setEmpty(empty);
|
||||
break;
|
||||
case SB_ZIP:
|
||||
d->zip[item].setEmpty(empty);
|
||||
break;
|
||||
case SB_MO:
|
||||
d->mo[item].setEmpty(empty);
|
||||
break;
|
||||
case SB_HDD:
|
||||
break;
|
||||
case SB_NETWORK:
|
||||
break;
|
||||
case SB_SOUND:
|
||||
break;
|
||||
case SB_TEXT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MachineStatus::message(const QString &msg) {
|
||||
d->text->setText(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user