Revert sliders

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2025-03-24 11:59:29 +00:00
parent e1e0a3d887
commit 4e6bfde723
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
5 changed files with 129 additions and 487 deletions

View file

@ -665,7 +665,6 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
m_settings->registerSetting("AutomaticJavaSwitch", defaultEnableAutoJava); m_settings->registerSetting("AutomaticJavaSwitch", defaultEnableAutoJava);
m_settings->registerSetting("AutomaticJavaDownload", defaultEnableAutoJava); m_settings->registerSetting("AutomaticJavaDownload", defaultEnableAutoJava);
m_settings->registerSetting("UserAskedAboutAutomaticJavaDownload", false); m_settings->registerSetting("UserAskedAboutAutomaticJavaDownload", false);
m_settings->registerSetting("AdvancedJavaMemoryControl", false);
// Legacy settings // Legacy settings
m_settings->registerSetting("OnlineFixes", false); m_settings->registerSetting("OnlineFixes", false);

View file

@ -53,11 +53,6 @@
#include "ui_JavaSettingsWidget.h" #include "ui_JavaSettingsWidget.h"
static QString formatGiBLabel(int value)
{
return QObject::tr("%1 GiB").arg(value / 1024.0, 0, 'f', 1);
}
JavaSettingsWidget::JavaSettingsWidget(InstancePtr instance, QWidget* parent) JavaSettingsWidget::JavaSettingsWidget(InstancePtr instance, QWidget* parent)
: QWidget(parent), m_instance(std::move(instance)), m_ui(new Ui::JavaSettingsWidget) : QWidget(parent), m_instance(std::move(instance)), m_ui(new Ui::JavaSettingsWidget)
{ {
@ -106,50 +101,11 @@ JavaSettingsWidget::JavaSettingsWidget(InstancePtr instance, QWidget* parent)
connect(m_ui->javaDetectBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaAutodetect); connect(m_ui->javaDetectBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaAutodetect);
connect(m_ui->javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaBrowse); connect(m_ui->javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaBrowse);
connect(m_ui->minMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), m_ui->minMemSlider, [this](int value) { connect(m_ui->maxMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::updateThresholds);
m_ui->minMemSlider->blockSignals(true); connect(m_ui->minMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::updateThresholds);
m_ui->minMemSlider->setValue(value);
m_ui->minMemSlider->blockSignals(false);
});
connect(m_ui->maxMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), m_ui->maxMemSlider, [this](int value) {
m_ui->maxMemSlider->blockSignals(true);
m_ui->maxMemSlider->setValue(value);
m_ui->maxMemSlider->blockSignals(false);
});
connect(m_ui->minMemSlider, &QAbstractSlider::valueChanged, m_ui->minMemSpinBox, QOverload<int>::of(&QSpinBox::setValue));
connect(m_ui->maxMemSlider, &QAbstractSlider::valueChanged, m_ui->maxMemSpinBox, QOverload<int>::of(&QSpinBox::setValue));
connect(m_ui->minMemSpinBox, &QAbstractSpinBox::editingFinished, this, &JavaSettingsWidget::finishAdjustingMinMemory);
connect(m_ui->maxMemSpinBox, &QAbstractSpinBox::editingFinished, this, &JavaSettingsWidget::finishAdjustingMaxMemory);
connect(m_ui->minMemSlider, &QAbstractSlider::valueChanged, this, &JavaSettingsWidget::finishAdjustingMinMemory);
connect(m_ui->maxMemSlider, &QAbstractSlider::valueChanged, this, &JavaSettingsWidget::finishAdjustingMaxMemory);
connect(m_ui->maxMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::onMemoryChange);
connect(m_ui->minMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::onMemoryChange);
int maxSystemMemory = (Sys::getSystemRam() / Sys::mebibyte) - 1;
m_ui->minMemSlider->setMaximum(maxSystemMemory - 1);
m_ui->maxMemSlider->setMaximum(maxSystemMemory - 1);
m_ui->minMemMaxValueHint->setText(formatGiBLabel(maxSystemMemory - 1));
m_ui->maxMemMaxValueHint->setText(formatGiBLabel(maxSystemMemory - 1));
SettingsObjectPtr settings = APPLICATION->settings();
enableAdvancedMemoryControl(settings->get("AdvancedJavaMemoryControl").toBool());
connect(m_ui->memorySimpleButton, &QPushButton::clicked, this, [this, settings] () {
enableAdvancedMemoryControl(false);
settings->set("AdvancedJavaMemoryControl", false);
});
connect(m_ui->memoryAdvancedButton, &QPushButton::clicked, this, [this, settings] () {
enableAdvancedMemoryControl(true);
settings->set("AdvancedJavaMemoryControl", true);
});
loadSettings(); loadSettings();
onMemoryChange(); updateThresholds();
} }
JavaSettingsWidget::~JavaSettingsWidget() JavaSettingsWidget::~JavaSettingsWidget()
@ -327,43 +283,23 @@ void JavaSettingsWidget::onJavaAutodetect()
} }
} }
} }
void JavaSettingsWidget::updateThresholds()
void JavaSettingsWidget::onMemoryChange()
{ {
auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; auto sysMiB = Sys::getSystemRam() / Sys::mebibyte;
unsigned int maxMem = m_ui->maxMemSpinBox->value(); unsigned int maxMem = m_ui->maxMemSpinBox->value();
unsigned int minMem = m_ui->minMemSpinBox->value();
const QString warningColour(QStringLiteral("<span style='color:#f5c211'>%1</span>"));
if (maxMem >= sysMiB) { if (maxMem >= sysMiB) {
m_ui->labelMaxMemNotice->setText(QString("<span style='color:red'>%1</span>").arg(tr("Your maximum memory allocation exceeds your system memory capacity."))); m_ui->labelMaxMemNotice->setText(QString("<span style='color:red'>%1</span>").arg(tr("Your maximum memory allocation exceeds your system memory capacity.")));
m_ui->labelMaxMemNotice->show(); m_ui->labelMaxMemNotice->show();
} else if (maxMem > (sysMiB * 0.9)) { } else if (maxMem > (sysMiB * 0.9)) {
// TODO: where is this colour from m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is close to your system memory capacity.")));
m_ui->labelMaxMemNotice->setText(QString("<span style='color:#f5c211'>%1</span>")
.arg(tr("Your maximum memory allocation is close to your system memory capacity.")));
m_ui->labelMaxMemNotice->show(); m_ui->labelMaxMemNotice->show();
} else if (maxMem < minMem) {
m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is below the minimum memory allocation.")))
} else { } else {
m_ui->labelMaxMemNotice->hide(); m_ui->labelMaxMemNotice->hide();
} }
m_ui->minMemGBLabel->setText(formatGiBLabel(m_ui->minMemSlider->value()));
m_ui->maxMemGBLabel->setText(formatGiBLabel(m_ui->maxMemSlider->value()));
}
void JavaSettingsWidget::finishAdjustingMinMemory()
{
if (m_ui->minMemSpinBox->value() > m_ui->maxMemSpinBox->value())
m_ui->maxMemSpinBox->setValue(m_ui->minMemSpinBox->value());
}
void JavaSettingsWidget::finishAdjustingMaxMemory()
{
if (m_ui->maxMemSpinBox->value() < m_ui->minMemSpinBox->value())
m_ui->minMemSpinBox->setValue(m_ui->maxMemSpinBox->value());
}
void JavaSettingsWidget::enableAdvancedMemoryControl(bool enabled) {
m_ui->memorySimpleButton->setChecked(!enabled);
m_ui->memoryAdvancedButton->setChecked(enabled);
m_ui->memorySimple->setVisible(!enabled);
m_ui->memoryAdvanced->setVisible(enabled);
} }

View file

@ -59,10 +59,7 @@ class JavaSettingsWidget : public QWidget {
void onJavaBrowse(); void onJavaBrowse();
void onJavaAutodetect(); void onJavaAutodetect();
void onJavaTest(); void onJavaTest();
void onMemoryChange(); void updateThresholds();
void finishAdjustingMinMemory();
void finishAdjustingMaxMemory();
void enableAdvancedMemoryControl(bool enabled);
private: private:
InstancePtr m_instance; InstancePtr m_instance;

View file

@ -164,235 +164,10 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="memorySimpleButton">
<property name="text">
<string>Simple</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="memoryAdvancedButton">
<property name="text">
<string>Advanced</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<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>
<item>
<widget class="QWidget" name="memorySimple" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
<widget class="QLabel" name="labelMinMem"> <widget class="QLabel" name="labelMinMem">
<property name="text"> <property name="text">
<string>M&amp;inimum Memory Usage</string> <string>M&amp;inimum Memory Usage (-Xms)</string>
</property>
<property name="buddy">
<cstring>minMemSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="minMemGBLabel">
<property name="text">
<string>0 GiB</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="minMemSlider">
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>8192</number>
</property>
<property name="singleStep">
<number>512</number>
</property>
<property name="pageStep">
<number>512</number>
</property>
<property name="tracking">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>1024</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="minMemMinValueHint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>0 GiB</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="minMemMaxValueHint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>8 GiB</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelMaxMem">
<property name="text">
<string>M&amp;aximum Memory Usage</string>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="maxMemGBLabel">
<property name="text">
<string>0 GiB</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="maxMemSlider">
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>8192</number>
</property>
<property name="singleStep">
<number>512</number>
</property>
<property name="pageStep">
<number>512</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>1024</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="maxMemMinValueHint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>0 GiB</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="maxMemMaxValueHint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>8 GiB</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="memoryAdvanced" native="true">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Minimum Memory Allocation</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>-Xm&amp;s=</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>minMemSpinBox</cstring> <cstring>minMemSpinBox</cstring>
@ -411,7 +186,7 @@
<string>The amount of memory Minecraft is started with.</string> <string>The amount of memory Minecraft is started with.</string>
</property> </property>
<property name="suffix"> <property name="suffix">
<string notr="true">M</string> <string notr="true"> MiB</string>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>8</number> <number>8</number>
@ -428,36 +203,9 @@
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_4"> <widget class="QLabel" name="labelMaxMem">
<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>
<item>
<widget class="QLabel" name="label_10">
<property name="text"> <property name="text">
<string>Maximum Memory Allocation</string> <string>Ma&amp;ximum Memory Usage (-Xmx)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>-Xm&amp;x=</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>maxMemSpinBox</cstring> <cstring>maxMemSpinBox</cstring>
@ -476,7 +224,7 @@
<string>The maximum amount of memory Minecraft is allowed to use.</string> <string>The maximum amount of memory Minecraft is allowed to use.</string>
</property> </property>
<property name="suffix"> <property name="suffix">
<string notr="true">M</string> <string notr="true"> MiB</string>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>8</number> <number>8</number>
@ -492,37 +240,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_2">
<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>
<item> <item>
<widget class="QLabel" name="label_11"> <widget class="QLabel" name="label_11">
<property name="text"> <property name="text">
<string>PermGen Size</string> <string>&amp;PermGen Size (-XX:PermSize)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>-XX:&amp;PermSize=</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>permGenSpinBox</cstring> <cstring>permGenSpinBox</cstring>
@ -541,7 +262,7 @@
<string>The amount of memory available to store loaded Java classes.</string> <string>The amount of memory available to store loaded Java classes.</string>
</property> </property>
<property name="suffix"> <property name="suffix">
<string notr="true">M</string> <string notr="true"> MiB</string>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>4</number> <number>4</number>
@ -557,28 +278,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_5">
<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>
</item>
<item> <item>
<widget class="QLabel" name="labelMaxMemNotice"> <widget class="QLabel" name="labelMaxMemNotice">
<property name="text"> <property name="text">
<string>Maximum Memory Notice</string> <string>TextLabel</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -609,11 +312,18 @@
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>javaTestBtn</tabstop>
<tabstop>javaDownloadBtn</tabstop>
<tabstop>javaPathTextBox</tabstop> <tabstop>javaPathTextBox</tabstop>
<tabstop>javaDetectBtn</tabstop>
<tabstop>javaBrowseBtn</tabstop>
<tabstop>skipCompatibilityCheckBox</tabstop> <tabstop>skipCompatibilityCheckBox</tabstop>
<tabstop>skipWizardCheckBox</tabstop> <tabstop>skipWizardCheckBox</tabstop>
<tabstop>autodetectJavaCheckBox</tabstop> <tabstop>autodetectJavaCheckBox</tabstop>
<tabstop>autodownloadJavaCheckBox</tabstop> <tabstop>autodownloadJavaCheckBox</tabstop>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemSpinBox</tabstop>
<tabstop>permGenSpinBox</tabstop>
<tabstop>jvmArgsTextBox</tabstop> <tabstop>jvmArgsTextBox</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>