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
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("AutomaticJavaDownload", defaultEnableAutoJava);
m_settings->registerSetting("UserAskedAboutAutomaticJavaDownload", false);
m_settings->registerSetting("AdvancedJavaMemoryControl", false);
// Legacy settings
m_settings->registerSetting("OnlineFixes", false);

View File

@ -62,7 +62,7 @@
JavaPage::JavaPage(QWidget* parent) : QWidget(parent), ui(new Ui::JavaPage)
{
ui->setupUi(this);
if (BuildConfig.JAVA_DOWNLOADER_ENABLED) {
ui->managedJavaList->initialize(new JavaInstallList(this, true));
ui->managedJavaList->setResizeOn(2);

View File

@ -53,11 +53,6 @@
#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)
: 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->javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaBrowse);
connect(m_ui->minMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), m_ui->minMemSlider, [this](int value) {
m_ui->minMemSlider->blockSignals(true);
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);
});
connect(m_ui->maxMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::updateThresholds);
connect(m_ui->minMemSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::updateThresholds);
loadSettings();
onMemoryChange();
updateThresholds();
}
JavaSettingsWidget::~JavaSettingsWidget()
@ -327,43 +283,23 @@ void JavaSettingsWidget::onJavaAutodetect()
}
}
}
void JavaSettingsWidget::onMemoryChange()
void JavaSettingsWidget::updateThresholds()
{
auto sysMiB = Sys::getSystemRam() / Sys::mebibyte;
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) {
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();
} else if (maxMem > (sysMiB * 0.9)) {
// TODO: where is this colour from
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->setText(warningColour.arg(tr("Your maximum memory allocation is close to your system memory capacity.")));
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 {
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,13 +59,10 @@ class JavaSettingsWidget : public QWidget {
void onJavaBrowse();
void onJavaAutodetect();
void onJavaTest();
void onMemoryChange();
void finishAdjustingMinMemory();
void finishAdjustingMaxMemory();
void enableAdvancedMemoryControl(bool enabled);
void updateThresholds();
private:
InstancePtr m_instance;
Ui::JavaSettingsWidget* m_ui;
unique_qobject_ptr<JavaCommon::TestCheck> m_checker;
};
};

View File

@ -165,420 +165,123 @@
</property>
<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>
<widget class="QLabel" name="labelMinMem">
<property name="text">
<string>M&amp;inimum Memory Usage</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 class="QLabel" name="labelMinMem">
<property name="text">
<string>M&amp;inimum Memory Usage (-Xms)</string>
</property>
<property name="buddy">
<cstring>minMemSpinBox</cstring>
</property>
</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 name="buddy">
<cstring>minMemSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="minMemSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The amount of memory Minecraft is started with.</string>
</property>
<property name="suffix">
<string notr="true">M</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>256</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<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">
<string>Maximum Memory Allocation</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 name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="maxMemSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The maximum amount of memory Minecraft is allowed to use.</string>
</property>
<property name="suffix">
<string notr="true">M</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</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>
<widget class="QLabel" name="label_11">
<property name="text">
<string>PermGen Size</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 name="buddy">
<cstring>permGenSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="permGenSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The amount of memory available to store loaded Java classes.</string>
</property>
<property name="suffix">
<string notr="true">M</string>
</property>
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>8</number>
</property>
<property name="value">
<number>64</number>
</property>
</widget>
</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 class="QSpinBox" name="minMemSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The amount of memory Minecraft is started with.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>256</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelMaxMem">
<property name="text">
<string>Ma&amp;ximum Memory Usage (-Xmx)</string>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="maxMemSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The maximum amount of memory Minecraft is allowed to use.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>&amp;PermGen Size (-XX:PermSize)</string>
</property>
<property name="buddy">
<cstring>permGenSpinBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="permGenSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The amount of memory available to store loaded Java classes.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>8</number>
</property>
<property name="value">
<number>64</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelMaxMemNotice">
<property name="text">
<string>Maximum Memory Notice</string>
<string>TextLabel</string>
</property>
</widget>
</item>
@ -609,11 +312,18 @@
</layout>
</widget>
<tabstops>
<tabstop>javaTestBtn</tabstop>
<tabstop>javaDownloadBtn</tabstop>
<tabstop>javaPathTextBox</tabstop>
<tabstop>javaDetectBtn</tabstop>
<tabstop>javaBrowseBtn</tabstop>
<tabstop>skipCompatibilityCheckBox</tabstop>
<tabstop>skipWizardCheckBox</tabstop>
<tabstop>autodetectJavaCheckBox</tabstop>
<tabstop>autodownloadJavaCheckBox</tabstop>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemSpinBox</tabstop>
<tabstop>permGenSpinBox</tabstop>
<tabstop>jvmArgsTextBox</tabstop>
</tabstops>
<resources/>