fix up the power management dialog

This commit is contained in:
Arisotura
2022-03-06 22:07:42 +01:00
parent 08a03bdc59
commit 3ec40c3dc8
3 changed files with 39 additions and 1 deletions

View File

@ -31,14 +31,25 @@ PowerManagementDialog* PowerManagementDialog::currentDlg = nullptr;
PowerManagementDialog::PowerManagementDialog(QWidget* parent) : QDialog(parent), ui(new Ui::PowerManagementDialog) PowerManagementDialog::PowerManagementDialog(QWidget* parent) : QDialog(parent), ui(new Ui::PowerManagementDialog)
{ {
inited = false;
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
if (NDS::ConsoleType) if (NDS::ConsoleType == 1)
{
ui->grpDSBattery->setEnabled(false); ui->grpDSBattery->setEnabled(false);
oldDSiBatteryCharging = DSi_BPTWL::GetBatteryCharging();
oldDSiBatteryLevel = DSi_BPTWL::GetBatteryLevel();
}
else else
{
ui->grpDSiBattery->setEnabled(false); ui->grpDSiBattery->setEnabled(false);
oldDSBatteryLevel = SPI_Powerman::GetBatteryLevelOkay();
}
updateDSBatteryLevelControls(); updateDSBatteryLevelControls();
ui->cbDSiBatteryCharging->setChecked(DSi_BPTWL::GetBatteryCharging()); ui->cbDSiBatteryCharging->setChecked(DSi_BPTWL::GetBatteryCharging());
@ -52,6 +63,8 @@ PowerManagementDialog::PowerManagementDialog(QWidget* parent) : QDialog(parent),
case DSi_BPTWL::batteryLevel_Full: dsiBatterySliderPos = 4; break; case DSi_BPTWL::batteryLevel_Full: dsiBatterySliderPos = 4; break;
} }
ui->sliderDSiBatteryLevel->setValue(dsiBatterySliderPos); ui->sliderDSiBatteryLevel->setValue(dsiBatterySliderPos);
inited = true;
} }
PowerManagementDialog::~PowerManagementDialog() PowerManagementDialog::~PowerManagementDialog()
@ -61,6 +74,19 @@ PowerManagementDialog::~PowerManagementDialog()
void PowerManagementDialog::done(int r) void PowerManagementDialog::done(int r)
{ {
if (r != QDialog::Accepted)
{
if (NDS::ConsoleType == 1)
{
DSi_BPTWL::SetBatteryCharging(oldDSiBatteryCharging);
DSi_BPTWL::SetBatteryLevel(oldDSiBatteryLevel);
}
else
{
SPI_Powerman::SetBatteryLevelOkay(oldDSBatteryLevel);
}
}
QDialog::done(r); QDialog::done(r);
closeDlg(); closeDlg();
@ -91,6 +117,8 @@ void PowerManagementDialog::on_cbDSiBatteryCharging_toggled()
void PowerManagementDialog::on_sliderDSiBatteryLevel_valueChanged(int value) void PowerManagementDialog::on_sliderDSiBatteryLevel_valueChanged(int value)
{ {
if (!inited) return;
u8 newBatteryLevel; u8 newBatteryLevel;
switch (value) switch (value)
{ {

View File

@ -22,6 +22,8 @@
#include <QDialog> #include <QDialog>
#include <QAbstractButton> #include <QAbstractButton>
#include "types.h"
namespace Ui { class PowerManagementDialog; } namespace Ui { class PowerManagementDialog; }
class PowerManagementDialog; class PowerManagementDialog;
@ -63,6 +65,11 @@ private slots:
private: private:
Ui::PowerManagementDialog* ui; Ui::PowerManagementDialog* ui;
bool inited;
bool oldDSBatteryLevel;
bool oldDSiBatteryCharging;
u8 oldDSiBatteryLevel;
void updateDSBatteryLevelControls(); void updateDSBatteryLevelControls();
}; };

View File

@ -20,6 +20,9 @@
<string>Power management - melonDS</string> <string>Power management - melonDS</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QGroupBox" name="grpDSBattery"> <widget class="QGroupBox" name="grpDSBattery">
<property name="title"> <property name="title">