From 1d468ac35ad88d8c77cc83f25e3704d9bd7df01b Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 2 Aug 2023 18:35:35 +0200 Subject: chore: reformat Signed-off-by: Sefa Eyeoglu --- launcher/ui/widgets/CustomCommands.cpp | 13 +- launcher/ui/widgets/CustomCommands.h | 18 ++- launcher/ui/widgets/DropLabel.cpp | 17 ++- launcher/ui/widgets/DropLabel.h | 19 ++- launcher/ui/widgets/ErrorFrame.cpp | 46 +++---- launcher/ui/widgets/ErrorFrame.h | 22 ++-- launcher/ui/widgets/FocusLineEdit.cpp | 9 +- launcher/ui/widgets/FocusLineEdit.h | 17 ++- launcher/ui/widgets/IconLabel.cpp | 16 +-- launcher/ui/widgets/IconLabel.h | 13 +- launcher/ui/widgets/JavaSettingsWidget.cpp | 145 +++++++++-------------- launcher/ui/widgets/JavaSettingsWidget.h | 75 +++++------- launcher/ui/widgets/LabeledToolButton.cpp | 46 ++++--- launcher/ui/widgets/LabeledToolButton.h | 16 +-- launcher/ui/widgets/LineSeparator.cpp | 14 +-- launcher/ui/widgets/LineSeparator.h | 14 +-- launcher/ui/widgets/LogView.cpp | 49 +++----- launcher/ui/widgets/LogView.h | 33 +++--- launcher/ui/widgets/ModFilterWidget.cpp | 110 ++++++++--------- launcher/ui/widgets/ModFilterWidget.h | 33 +++--- launcher/ui/widgets/ModListView.cpp | 46 ++++--- launcher/ui/widgets/ModListView.h | 11 +- launcher/ui/widgets/PageContainer.cpp | 101 ++++++---------- launcher/ui/widgets/PageContainer.h | 54 ++++----- launcher/ui/widgets/PageContainer_p.h | 77 +++++------- launcher/ui/widgets/ProjectItem.cpp | 5 +- launcher/ui/widgets/ProjectItem.h | 7 +- launcher/ui/widgets/SubTaskProgressBar.cpp | 6 +- launcher/ui/widgets/SubTaskProgressBar.h | 10 +- launcher/ui/widgets/ThemeCustomizationWidget.cpp | 18 +-- launcher/ui/widgets/VersionListView.cpp | 48 +++----- launcher/ui/widgets/VersionListView.h | 31 ++--- launcher/ui/widgets/VersionSelectWidget.cpp | 52 ++++---- launcher/ui/widgets/VersionSelectWidget.h | 49 ++++---- launcher/ui/widgets/WideBar.cpp | 10 +- 35 files changed, 518 insertions(+), 732 deletions(-) (limited to 'launcher/ui/widgets') diff --git a/launcher/ui/widgets/CustomCommands.cpp b/launcher/ui/widgets/CustomCommands.cpp index 5ab90395..98a1b7e8 100644 --- a/launcher/ui/widgets/CustomCommands.cpp +++ b/launcher/ui/widgets/CustomCommands.cpp @@ -41,9 +41,7 @@ CustomCommands::~CustomCommands() delete ui; } -CustomCommands::CustomCommands(QWidget* parent): - QWidget(parent), - ui(new Ui::CustomCommands) +CustomCommands::CustomCommands(QWidget* parent) : QWidget(parent), ui(new Ui::CustomCommands) { ui->setupUi(this); } @@ -51,8 +49,7 @@ CustomCommands::CustomCommands(QWidget* parent): void CustomCommands::initialize(bool checkable, bool checked, const QString& prelaunch, const QString& wrapper, const QString& postexit) { ui->customCommandsGroupBox->setCheckable(checkable); - if(checkable) - { + if (checkable) { ui->customCommandsGroupBox->setChecked(checked); } ui->preLaunchCmdTextBox->setText(prelaunch); @@ -60,14 +57,14 @@ void CustomCommands::initialize(bool checkable, bool checked, const QString& pre ui->postExitCmdTextBox->setText(postexit); } - -void CustomCommands::retranslate() { +void CustomCommands::retranslate() +{ ui->retranslateUi(this); } bool CustomCommands::checked() const { - if(!ui->customCommandsGroupBox->isCheckable()) + if (!ui->customCommandsGroupBox->isCheckable()) return true; return ui->customCommandsGroupBox->isChecked(); } diff --git a/launcher/ui/widgets/CustomCommands.h b/launcher/ui/widgets/CustomCommands.h index ed10ba95..96a3fa62 100644 --- a/launcher/ui/widgets/CustomCommands.h +++ b/launcher/ui/widgets/CustomCommands.h @@ -37,19 +37,17 @@ #include -namespace Ui -{ +namespace Ui { class CustomCommands; } -class CustomCommands : public QWidget -{ +class CustomCommands : public QWidget { Q_OBJECT -public: - explicit CustomCommands(QWidget *parent = 0); + public: + explicit CustomCommands(QWidget* parent = 0); virtual ~CustomCommands(); - void initialize(bool checkable, bool checked, const QString & prelaunch, const QString & wrapper, const QString & postexit); + void initialize(bool checkable, bool checked, const QString& prelaunch, const QString& wrapper, const QString& postexit); void retranslate(); bool checked() const; @@ -57,8 +55,6 @@ public: QString wrapperCommand() const; QString postexitCommand() const; -private: - Ui::CustomCommands *ui; + private: + Ui::CustomCommands* ui; }; - - diff --git a/launcher/ui/widgets/DropLabel.cpp b/launcher/ui/widgets/DropLabel.cpp index a900e57c..b1473b35 100644 --- a/launcher/ui/widgets/DropLabel.cpp +++ b/launcher/ui/widgets/DropLabel.cpp @@ -1,34 +1,33 @@ #include "DropLabel.h" -#include #include +#include -DropLabel::DropLabel(QWidget *parent) : QLabel(parent) +DropLabel::DropLabel(QWidget* parent) : QLabel(parent) { setAcceptDrops(true); } -void DropLabel::dragEnterEvent(QDragEnterEvent *event) +void DropLabel::dragEnterEvent(QDragEnterEvent* event) { event->acceptProposedAction(); } -void DropLabel::dragMoveEvent(QDragMoveEvent *event) +void DropLabel::dragMoveEvent(QDragMoveEvent* event) { event->acceptProposedAction(); } -void DropLabel::dragLeaveEvent(QDragLeaveEvent *event) +void DropLabel::dragLeaveEvent(QDragLeaveEvent* event) { event->accept(); } -void DropLabel::dropEvent(QDropEvent *event) +void DropLabel::dropEvent(QDropEvent* event) { - const QMimeData *mimeData = event->mimeData(); + const QMimeData* mimeData = event->mimeData(); - if (!mimeData) - { + if (!mimeData) { return; } diff --git a/launcher/ui/widgets/DropLabel.h b/launcher/ui/widgets/DropLabel.h index c5ca0bcc..0027f48b 100644 --- a/launcher/ui/widgets/DropLabel.h +++ b/launcher/ui/widgets/DropLabel.h @@ -2,19 +2,18 @@ #include -class DropLabel : public QLabel -{ +class DropLabel : public QLabel { Q_OBJECT -public: - explicit DropLabel(QWidget *parent = nullptr); + public: + explicit DropLabel(QWidget* parent = nullptr); -signals: + signals: void droppedURLs(QList urls); -protected: - void dropEvent(QDropEvent *event) override; - void dragEnterEvent(QDragEnterEvent *event) override; - void dragMoveEvent(QDragMoveEvent *event) override; - void dragLeaveEvent(QDragLeaveEvent *event) override; + protected: + void dropEvent(QDropEvent* event) override; + void dragEnterEvent(QDragEnterEvent* event) override; + void dragMoveEvent(QDragMoveEvent* event) override; + void dragLeaveEvent(QDragLeaveEvent* event) override; }; diff --git a/launcher/ui/widgets/ErrorFrame.cpp b/launcher/ui/widgets/ErrorFrame.cpp index b3e41036..213c26b7 100644 --- a/launcher/ui/widgets/ErrorFrame.cpp +++ b/launcher/ui/widgets/ErrorFrame.cpp @@ -27,9 +27,7 @@ void ErrorFrame::clear() setDescription(QString()); } -ErrorFrame::ErrorFrame(QWidget *parent) : - QFrame(parent), - ui(new Ui::ErrorFrame) +ErrorFrame::ErrorFrame(QWidget* parent) : QFrame(parent), ui(new Ui::ErrorFrame) { ui->setupUi(this); ui->label_Description->setHidden(true); @@ -44,24 +42,18 @@ ErrorFrame::~ErrorFrame() void ErrorFrame::updateHiddenState() { - if(ui->label_Description->isHidden() && ui->label_Title->isHidden()) - { + if (ui->label_Description->isHidden() && ui->label_Title->isHidden()) { setHidden(true); - } - else - { + } else { setHidden(false); } } void ErrorFrame::setTitle(QString text) { - if(text.isEmpty()) - { + if (text.isEmpty()) { ui->label_Title->setHidden(true); - } - else - { + } else { ui->label_Title->setText(text); ui->label_Title->setHidden(false); } @@ -70,14 +62,11 @@ void ErrorFrame::setTitle(QString text) void ErrorFrame::setDescription(QString text) { - if(text.isEmpty()) - { + if (text.isEmpty()) { ui->label_Description->setHidden(true); updateHiddenState(); return; - } - else - { + } else { ui->label_Description->setHidden(false); updateHiddenState(); } @@ -87,9 +76,8 @@ void ErrorFrame::setDescription(QString text) QChar rem('\n'); QString finaltext; finaltext.reserve(intermediatetext.size()); - foreach(const QChar& c, intermediatetext) - { - if(c == rem && prev){ + foreach (const QChar& c, intermediatetext) { + if (c == rem && prev) { continue; } prev = c == rem; @@ -97,33 +85,27 @@ void ErrorFrame::setDescription(QString text) } QString labeltext; labeltext.reserve(300); - if(finaltext.length() > 290) - { + if (finaltext.length() > 290) { ui->label_Description->setOpenExternalLinks(false); ui->label_Description->setTextFormat(Qt::TextFormat::RichText); desc = text; // This allows injecting HTML here. labeltext.append("" + finaltext.left(287) + "..."); QObject::connect(ui->label_Description, &QLabel::linkActivated, this, &ErrorFrame::ellipsisHandler); - } - else - { + } else { ui->label_Description->setTextFormat(Qt::TextFormat::PlainText); labeltext.append(finaltext); } ui->label_Description->setText(labeltext); } -void ErrorFrame::ellipsisHandler(const QString &link) +void ErrorFrame::ellipsisHandler(const QString& link) { - if(!currentBox) - { + if (!currentBox) { currentBox = CustomMessageBox::selectable(this, QString(), desc); connect(currentBox, &QMessageBox::finished, this, &ErrorFrame::boxClosed); currentBox->show(); - } - else - { + } else { currentBox->setText(desc); } } diff --git a/launcher/ui/widgets/ErrorFrame.h b/launcher/ui/widgets/ErrorFrame.h index d5069a14..1aea6a1d 100644 --- a/launcher/ui/widgets/ErrorFrame.h +++ b/launcher/ui/widgets/ErrorFrame.h @@ -17,17 +17,15 @@ #include -namespace Ui -{ +namespace Ui { class ErrorFrame; } -class ErrorFrame : public QFrame -{ +class ErrorFrame : public QFrame { Q_OBJECT -public: - explicit ErrorFrame(QWidget *parent = 0); + public: + explicit ErrorFrame(QWidget* parent = 0); ~ErrorFrame(); void setTitle(QString text); @@ -35,15 +33,15 @@ public: void clear(); -public slots: - void ellipsisHandler(const QString& link ); + public slots: + void ellipsisHandler(const QString& link); void boxClosed(int result); -private: + private: void updateHiddenState(); -private: - Ui::ErrorFrame *ui; + private: + Ui::ErrorFrame* ui; QString desc; - class QMessageBox * currentBox = nullptr; + class QMessageBox* currentBox = nullptr; }; diff --git a/launcher/ui/widgets/FocusLineEdit.cpp b/launcher/ui/widgets/FocusLineEdit.cpp index b272100c..6570227b 100644 --- a/launcher/ui/widgets/FocusLineEdit.cpp +++ b/launcher/ui/widgets/FocusLineEdit.cpp @@ -1,23 +1,22 @@ #include "FocusLineEdit.h" #include -FocusLineEdit::FocusLineEdit(QWidget *parent) : QLineEdit(parent) +FocusLineEdit::FocusLineEdit(QWidget* parent) : QLineEdit(parent) { _selectOnMousePress = false; } -void FocusLineEdit::focusInEvent(QFocusEvent *e) +void FocusLineEdit::focusInEvent(QFocusEvent* e) { QLineEdit::focusInEvent(e); selectAll(); _selectOnMousePress = true; } -void FocusLineEdit::mousePressEvent(QMouseEvent *me) +void FocusLineEdit::mousePressEvent(QMouseEvent* me) { QLineEdit::mousePressEvent(me); - if (_selectOnMousePress) - { + if (_selectOnMousePress) { selectAll(); _selectOnMousePress = false; } diff --git a/launcher/ui/widgets/FocusLineEdit.h b/launcher/ui/widgets/FocusLineEdit.h index 71b4f140..f5ea6602 100644 --- a/launcher/ui/widgets/FocusLineEdit.h +++ b/launcher/ui/widgets/FocusLineEdit.h @@ -1,17 +1,14 @@ #include -class FocusLineEdit : public QLineEdit -{ +class FocusLineEdit : public QLineEdit { Q_OBJECT -public: - FocusLineEdit(QWidget *parent); - virtual ~FocusLineEdit() - { - } + public: + FocusLineEdit(QWidget* parent); + virtual ~FocusLineEdit() {} -protected: - void focusInEvent(QFocusEvent *e); - void mousePressEvent(QMouseEvent *me); + protected: + void focusInEvent(QFocusEvent* e); + void mousePressEvent(QMouseEvent* me); bool _selectOnMousePress; }; diff --git a/launcher/ui/widgets/IconLabel.cpp b/launcher/ui/widgets/IconLabel.cpp index bf1c2358..28776686 100644 --- a/launcher/ui/widgets/IconLabel.cpp +++ b/launcher/ui/widgets/IconLabel.cpp @@ -1,13 +1,12 @@ #include "IconLabel.h" -#include -#include #include #include #include +#include +#include -IconLabel::IconLabel(QWidget *parent, QIcon icon, QSize size) - : QWidget(parent), m_size(size), m_icon(icon) +IconLabel::IconLabel(QWidget* parent, QIcon icon, QSize size) : QWidget(parent), m_size(size), m_icon(icon) { setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); } @@ -23,19 +22,16 @@ void IconLabel::setIcon(QIcon icon) update(); } -void IconLabel::paintEvent(QPaintEvent *) +void IconLabel::paintEvent(QPaintEvent*) { QPainter p(this); QRect rect = contentsRect(); int width = rect.width(); int height = rect.height(); - if(width < height) - { + if (width < height) { rect.setHeight(width); rect.translate(0, (height - width) / 2); - } - else if (width > height) - { + } else if (width > height) { rect.setWidth(height); rect.translate((width - height) / 2, 0); } diff --git a/launcher/ui/widgets/IconLabel.h b/launcher/ui/widgets/IconLabel.h index 6d212c4c..41d97f69 100644 --- a/launcher/ui/widgets/IconLabel.h +++ b/launcher/ui/widgets/IconLabel.h @@ -1,26 +1,25 @@ #pragma once -#include #include +#include class QStyleOption; /** * This is a trivial widget that paints a QIcon of the specified size. */ -class IconLabel : public QWidget -{ +class IconLabel : public QWidget { Q_OBJECT -public: + public: /// Create a line separator. orientation is the orientation of the line. - explicit IconLabel(QWidget *parent, QIcon icon, QSize size); + explicit IconLabel(QWidget* parent, QIcon icon, QSize size); virtual QSize sizeHint() const; - virtual void paintEvent(QPaintEvent *); + virtual void paintEvent(QPaintEvent*); void setIcon(QIcon icon); -private: + private: QSize m_size; QIcon m_icon; }; diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp index c94fdd8d..8c4048ff 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.cpp +++ b/launcher/ui/widgets/JavaSettingsWidget.cpp @@ -1,20 +1,20 @@ #include "JavaSettingsWidget.h" -#include +#include #include -#include #include #include #include +#include #include -#include +#include #include +#include "FileSystem.h" #include "JavaCommon.h" #include "java/JavaInstall.h" #include "java/JavaUtils.h" -#include "FileSystem.h" #include "ui/dialogs/CustomMessageBox.h" #include "ui/widgets/VersionSelectWidget.h" @@ -149,40 +149,30 @@ void JavaSettingsWidget::refresh() JavaSettingsWidget::ValidationStatus JavaSettingsWidget::validate() { - switch(javaStatus) - { + switch (javaStatus) { default: case JavaStatus::NotSet: case JavaStatus::DoesNotExist: case JavaStatus::DoesNotStart: - case JavaStatus::ReturnedInvalidData: - { - int button = CustomMessageBox::selectable( - this, - tr("No Java version selected"), - tr("You didn't select a Java version or selected something that doesn't work.\n" - "%1 will not be able to start Minecraft.\n" - "Do you wish to proceed without any Java?" - "\n\n" - "You can change the Java version in the settings later.\n" - ).arg(BuildConfig.LAUNCHER_DISPLAYNAME), - QMessageBox::Warning, - QMessageBox::Yes | QMessageBox::No, - QMessageBox::NoButton - )->exec(); - if(button == QMessageBox::No) - { + case JavaStatus::ReturnedInvalidData: { + int button = CustomMessageBox::selectable(this, tr("No Java version selected"), + tr("You didn't select a Java version or selected something that doesn't work.\n" + "%1 will not be able to start Minecraft.\n" + "Do you wish to proceed without any Java?" + "\n\n" + "You can change the Java version in the settings later.\n") + .arg(BuildConfig.LAUNCHER_DISPLAYNAME), + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton) + ->exec(); + if (button == QMessageBox::No) { return ValidationStatus::Bad; } return ValidationStatus::JavaBad; - } - break; - case JavaStatus::Pending: - { + } break; + case JavaStatus::Pending: { return ValidationStatus::Bad; } - case JavaStatus::Good: - { + case JavaStatus::Good: { return ValidationStatus::AllOK; } } @@ -219,34 +209,26 @@ void JavaSettingsWidget::memoryValueChanged(int) unsigned int min = m_minMemSpinBox->value(); unsigned int max = m_maxMemSpinBox->value(); unsigned int permgen = m_permGenSpinBox->value(); - QObject *obj = sender(); - if (obj == m_minMemSpinBox && min != observedMinMemory) - { + QObject* obj = sender(); + if (obj == m_minMemSpinBox && min != observedMinMemory) { observedMinMemory = min; actuallyChanged = true; - if (min > max) - { + if (min > max) { observedMaxMemory = min; m_maxMemSpinBox->setValue(min); } - } - else if (obj == m_maxMemSpinBox && max != observedMaxMemory) - { + } else if (obj == m_maxMemSpinBox && max != observedMaxMemory) { observedMaxMemory = max; actuallyChanged = true; - if (min > max) - { + if (min > max) { observedMinMemory = max; m_minMemSpinBox->setValue(max); } - } - else if (obj == m_permGenSpinBox && permgen != observedPermGenMemory) - { + } else if (obj == m_permGenSpinBox && permgen != observedPermGenMemory) { observedPermGenMemory = permgen; actuallyChanged = true; } - if(actuallyChanged) - { + if (actuallyChanged) { checkJavaPathOnEdit(m_javaPathTextBox->text()); updateThresholds(); } @@ -255,8 +237,7 @@ void JavaSettingsWidget::memoryValueChanged(int) void JavaSettingsWidget::javaVersionSelected(BaseVersion::Ptr version) { auto java = std::dynamic_pointer_cast(version); - if(!java) - { + if (!java) { return; } auto visible = java->id.requiresPermGen(); @@ -275,8 +256,7 @@ void JavaSettingsWidget::on_javaBrowseBtn_clicked() filter = "Java (java)"; #endif QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable"), QString(), filter); - if(raw_path.isEmpty()) - { + if (raw_path.isEmpty()) { return; } QString cooked_path = FS::NormalizePath(raw_path); @@ -288,8 +268,7 @@ void JavaSettingsWidget::on_javaStatusBtn_clicked() { QString text; bool failed = false; - switch(javaStatus) - { + switch (javaStatus) { case JavaStatus::NotSet: checkJavaPath(m_javaPathTextBox->text()); return; @@ -297,24 +276,20 @@ void JavaSettingsWidget::on_javaStatusBtn_clicked() text += QObject::tr("The specified file either doesn't exist or is not a proper executable."); failed = true; break; - case JavaStatus::DoesNotStart: - { + case JavaStatus::DoesNotStart: { text += QObject::tr("The specified Java binary didn't start properly.
"); auto htmlError = m_result.errorLog; - if(!htmlError.isEmpty()) - { + if (!htmlError.isEmpty()) { htmlError.replace('\n', "
"); text += QString("%1").arg(htmlError); } failed = true; break; } - case JavaStatus::ReturnedInvalidData: - { + case JavaStatus::ReturnedInvalidData: { text += QObject::tr("The specified Java binary returned unexpected results:
"); auto htmlOut = m_result.outLog; - if(!htmlOut.isEmpty()) - { + if (!htmlOut.isEmpty()) { htmlOut.replace('\n', "
"); text += QString("%1").arg(htmlOut); } @@ -322,26 +297,24 @@ void JavaSettingsWidget::on_javaStatusBtn_clicked() break; } case JavaStatus::Good: - text += QObject::tr("Java test succeeded!
Platform reported: %1
Java version " - "reported: %2
").arg(m_result.realPlatform, m_result.javaVersion.toString()); + text += QObject::tr( + "Java test succeeded!
Platform reported: %1
Java version " + "reported: %2
") + .arg(m_result.realPlatform, m_result.javaVersion.toString()); break; case JavaStatus::Pending: // TODO: abort here? return; } - CustomMessageBox::selectable( - this, - failed ? QObject::tr("Java test failure") : QObject::tr("Java test success"), - text, - failed ? QMessageBox::Critical : QMessageBox::Information - )->show(); + CustomMessageBox::selectable(this, failed ? QObject::tr("Java test failure") : QObject::tr("Java test success"), text, + failed ? QMessageBox::Critical : QMessageBox::Information) + ->show(); } void JavaSettingsWidget::setJavaStatus(JavaSettingsWidget::JavaStatus status) { javaStatus = status; - switch(javaStatus) - { + switch (javaStatus) { case JavaStatus::Good: m_javaStatusBtn->setIcon(goodIcon); break; @@ -364,29 +337,23 @@ void JavaSettingsWidget::checkJavaPathOnEdit(const QString& path) { auto realPath = FS::ResolveExecutable(path); QFileInfo pathInfo(realPath); - if (pathInfo.baseName().toLower().contains("java")) - { + if (pathInfo.baseName().toLower().contains("java")) { checkJavaPath(path); - } - else - { - if(!m_checker) - { + } else { + if (!m_checker) { setJavaStatus(JavaStatus::NotSet); } } } -void JavaSettingsWidget::checkJavaPath(const QString &path) +void JavaSettingsWidget::checkJavaPath(const QString& path) { - if(m_checker) - { + if (m_checker) { queuedCheck = path; return; } auto realPath = FS::ResolveExecutable(path); - if(realPath.isNull()) - { + if (realPath.isNull()) { setJavaStatus(JavaStatus::DoesNotExist); return; } @@ -395,8 +362,7 @@ void JavaSettingsWidget::checkJavaPath(const QString &path) m_checker->m_path = path; m_checker->m_minMem = m_minMemSpinBox->value(); m_checker->m_maxMem = m_maxMemSpinBox->value(); - if(m_permGenSpinBox->isVisible()) - { + if (m_permGenSpinBox->isVisible()) { m_checker->m_permGen = m_permGenSpinBox->value(); } connect(m_checker.get(), &JavaChecker::checkFinished, this, &JavaSettingsWidget::checkFinished); @@ -406,27 +372,22 @@ void JavaSettingsWidget::checkJavaPath(const QString &path) void JavaSettingsWidget::checkFinished(JavaCheckResult result) { m_result = result; - switch(result.validity) - { - case JavaCheckResult::Validity::Valid: - { + switch (result.validity) { + case JavaCheckResult::Validity::Valid: { setJavaStatus(JavaStatus::Good); break; } - case JavaCheckResult::Validity::ReturnedInvalidData: - { + case JavaCheckResult::Validity::ReturnedInvalidData: { setJavaStatus(JavaStatus::ReturnedInvalidData); break; } - case JavaCheckResult::Validity::Errored: - { + case JavaCheckResult::Validity::Errored: { setJavaStatus(JavaStatus::DoesNotStart); break; } } m_checker.reset(); - if(!queuedCheck.isNull()) - { + if (!queuedCheck.isNull()) { checkJavaPath(queuedCheck); queuedCheck.clear(); } diff --git a/launcher/ui/widgets/JavaSettingsWidget.h b/launcher/ui/widgets/JavaSettingsWidget.h index e4b7c712..6ea73da6 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.h +++ b/launcher/ui/widgets/JavaSettingsWidget.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include #include +#include #include class QLineEdit; @@ -20,30 +20,16 @@ class QToolButton; /** * This is a widget for all the Java settings dialogs and pages. */ -class JavaSettingsWidget : public QWidget -{ +class JavaSettingsWidget : public QWidget { Q_OBJECT -public: - explicit JavaSettingsWidget(QWidget *parent); - virtual ~JavaSettingsWidget() {}; + public: + explicit JavaSettingsWidget(QWidget* parent); + virtual ~JavaSettingsWidget(){}; - enum class JavaStatus - { - NotSet, - Pending, - Good, - DoesNotExist, - DoesNotStart, - ReturnedInvalidData - } javaStatus = JavaStatus::NotSet; + enum class JavaStatus { NotSet, Pending, Good, DoesNotExist, DoesNotStart, ReturnedInvalidData } javaStatus = JavaStatus::NotSet; - enum class ValidationStatus - { - Bad, - JavaBad, - AllOK - }; + enum class ValidationStatus { Bad, JavaBad, AllOK }; void refresh(); void initialize(); @@ -58,39 +44,38 @@ public: void updateThresholds(); - -protected slots: + protected slots: void memoryValueChanged(int); - void javaPathEdited(const QString &path); + void javaPathEdited(const QString& path); void javaVersionSelected(BaseVersion::Ptr version); void on_javaBrowseBtn_clicked(); void on_javaStatusBtn_clicked(); void checkFinished(JavaCheckResult result); -protected: /* methods */ - void checkJavaPathOnEdit(const QString &path); - void checkJavaPath(const QString &path); + protected: /* methods */ + void checkJavaPathOnEdit(const QString& path); + void checkJavaPath(const QString& path); void setJavaStatus(JavaStatus status); void setupUi(); -private: /* data */ - VersionSelectWidget *m_versionWidget = nullptr; - QVBoxLayout *m_verticalLayout = nullptr; - - QLineEdit * m_javaPathTextBox = nullptr; - QPushButton * m_javaBrowseBtn = nullptr; - QToolButton * m_javaStatusBtn = nullptr; - QHBoxLayout *m_horizontalLayout = nullptr; - - QGroupBox *m_memoryGroupBox = nullptr; - QGridLayout *m_gridLayout_2 = nullptr; - QSpinBox *m_maxMemSpinBox = nullptr; - QLabel *m_labelMinMem = nullptr; - QLabel *m_labelMaxMem = nullptr; - QLabel *m_labelMaxMemIcon = nullptr; - QSpinBox *m_minMemSpinBox = nullptr; - QLabel *m_labelPermGen = nullptr; - QSpinBox *m_permGenSpinBox = nullptr; + private: /* data */ + VersionSelectWidget* m_versionWidget = nullptr; + QVBoxLayout* m_verticalLayout = nullptr; + + QLineEdit* m_javaPathTextBox = nullptr; + QPushButton* m_javaBrowseBtn = nullptr; + QToolButton* m_javaStatusBtn = nullptr; + QHBoxLayout* m_horizontalLayout = nullptr; + + QGroupBox* m_memoryGroupBox = nullptr; + QGridLayout* m_gridLayout_2 = nullptr; + QSpinBox* m_maxMemSpinBox = nullptr; + QLabel* m_labelMinMem = nullptr; + QLabel* m_labelMaxMem = nullptr; + QLabel* m_labelMaxMemIcon = nullptr; + QSpinBox* m_minMemSpinBox = nullptr; + QLabel* m_labelPermGen = nullptr; + QSpinBox* m_permGenSpinBox = nullptr; QIcon goodIcon; QIcon yellowIcon; QIcon badIcon; diff --git a/launcher/ui/widgets/LabeledToolButton.cpp b/launcher/ui/widgets/LabeledToolButton.cpp index f52e49c9..7af48b0c 100644 --- a/launcher/ui/widgets/LabeledToolButton.cpp +++ b/launcher/ui/widgets/LabeledToolButton.cpp @@ -33,31 +33,29 @@ * limitations under the License. */ -#include -#include -#include -#include #include "LabeledToolButton.h" #include #include +#include +#include +#include +#include /* - * + * * Tool Button with a label on it, instead of the normal text rendering - * + * */ -LabeledToolButton::LabeledToolButton(QWidget * parent) - : QToolButton(parent) - , m_label(new QLabel(this)) +LabeledToolButton::LabeledToolButton(QWidget* parent) : QToolButton(parent), m_label(new QLabel(this)) { - //QToolButton::setText(" "); + // QToolButton::setText(" "); m_label->setWordWrap(true); m_label->setMouseTracking(false); m_label->setAlignment(Qt::AlignCenter); m_label->setTextInteractionFlags(Qt::NoTextInteraction); // somehow, this makes word wrap work in the QLabel. yay. - //m_label->setMinimumWidth(100); + // m_label->setMinimumWidth(100); } QString LabeledToolButton::text() const @@ -65,7 +63,7 @@ QString LabeledToolButton::text() const return m_label->text(); } -void LabeledToolButton::setText(const QString & text) +void LabeledToolButton::setText(const QString& text) { m_label->setText(text); } @@ -76,7 +74,6 @@ void LabeledToolButton::setIcon(QIcon icon) resetIcon(); } - /*! \reimp */ @@ -92,24 +89,21 @@ QSize LabeledToolButton::sizeHint() const int w = 0, h = 0; QStyleOptionToolButton opt; initStyleOption(&opt); - QSize sz =m_label->sizeHint(); + QSize sz = m_label->sizeHint(); w = sz.width(); h = sz.height(); - opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height + opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height if (popupMode() == MenuButtonPopup) w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); - + return style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this); } - - -void LabeledToolButton::resizeEvent(QResizeEvent * event) +void LabeledToolButton::resizeEvent(QResizeEvent* event) { - m_label->setGeometry(QRect(4, 4, width()-8, height()-8)); - if(!m_icon.isNull()) - { + m_label->setGeometry(QRect(4, 4, width() - 8, height() - 8)); + if (!m_icon.isNull()) { resetIcon(); } QWidget::resizeEvent(event); @@ -120,14 +114,14 @@ void LabeledToolButton::resetIcon() auto iconSz = m_icon.actualSize(QSize(160, 80)); float w = iconSz.width(); float h = iconSz.height(); - float ar = w/h; + float ar = w / h; // FIXME: hardcoded max size of 160x80 int newW = 80 * ar; - if(newW > 160) + if (newW > 160) newW = 160; - QSize newSz (newW, 80); + QSize newSz(newW, 80); auto pixmap = m_icon.pixmap(newSz); m_label->setPixmap(pixmap); m_label->setMinimumHeight(80); - m_label->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); + m_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); } diff --git a/launcher/ui/widgets/LabeledToolButton.h b/launcher/ui/widgets/LabeledToolButton.h index 51f99e9b..0bb5e28d 100644 --- a/launcher/ui/widgets/LabeledToolButton.h +++ b/launcher/ui/widgets/LabeledToolButton.h @@ -20,21 +20,21 @@ class QLabel; -class LabeledToolButton : public QToolButton -{ +class LabeledToolButton : public QToolButton { Q_OBJECT - QLabel * m_label; + QLabel* m_label; QIcon m_icon; -public: - LabeledToolButton(QWidget * parent = 0); + public: + LabeledToolButton(QWidget* parent = 0); QString text() const; - void setText(const QString & text); + void setText(const QString& text); void setIcon(QIcon icon); virtual QSize sizeHint() const; -protected: - void resizeEvent(QResizeEvent * event); + + protected: + void resizeEvent(QResizeEvent* event); void resetIcon(); }; diff --git a/launcher/ui/widgets/LineSeparator.cpp b/launcher/ui/widgets/LineSeparator.cpp index d03e6762..2d6239a2 100644 --- a/launcher/ui/widgets/LineSeparator.cpp +++ b/launcher/ui/widgets/LineSeparator.cpp @@ -1,11 +1,11 @@ #include "LineSeparator.h" -#include -#include #include #include +#include +#include -void LineSeparator::initStyleOption(QStyleOption *option) const +void LineSeparator::initStyleOption(QStyleOption* option) const { option->initFrom(this); // in a horizontal layout, the line is vertical (and vice versa) @@ -13,8 +13,7 @@ void LineSeparator::initStyleOption(QStyleOption *option) const option->state |= QStyle::State_Horizontal; } -LineSeparator::LineSeparator(QWidget *parent, Qt::Orientation orientation) - : QWidget(parent), m_orientation(orientation) +LineSeparator::LineSeparator(QWidget* parent, Qt::Orientation orientation) : QWidget(parent), m_orientation(orientation) { setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); } @@ -23,12 +22,11 @@ QSize LineSeparator::sizeHint() const { QStyleOption opt; initStyleOption(&opt); - const int extent = - style()->pixelMetric(QStyle::PM_ToolBarSeparatorExtent, &opt, parentWidget()); + const int extent = style()->pixelMetric(QStyle::PM_ToolBarSeparatorExtent, &opt, parentWidget()); return QSize(extent, extent); } -void LineSeparator::paintEvent(QPaintEvent *) +void LineSeparator::paintEvent(QPaintEvent*) { QPainter p(this); QStyleOption opt; diff --git a/launcher/ui/widgets/LineSeparator.h b/launcher/ui/widgets/LineSeparator.h index 22927b68..719facb9 100644 --- a/launcher/ui/widgets/LineSeparator.h +++ b/launcher/ui/widgets/LineSeparator.h @@ -3,16 +3,16 @@ class QStyleOption; -class LineSeparator : public QWidget -{ +class LineSeparator : public QWidget { Q_OBJECT -public: + public: /// Create a line separator. orientation is the orientation of the line. - explicit LineSeparator(QWidget *parent, Qt::Orientation orientation = Qt::Horizontal); + explicit LineSeparator(QWidget* parent, Qt::Orientation orientation = Qt::Horizontal); QSize sizeHint() const; - void paintEvent(QPaintEvent *); - void initStyleOption(QStyleOption *option) const; -private: + void paintEvent(QPaintEvent*); + void initStyleOption(QStyleOption* option) const; + + private: Qt::Orientation m_orientation = Qt::Horizontal; }; diff --git a/launcher/ui/widgets/LogView.cpp b/launcher/ui/widgets/LogView.cpp index 9c46438d..8c960ebb 100644 --- a/launcher/ui/widgets/LogView.cpp +++ b/launcher/ui/widgets/LogView.cpp @@ -34,8 +34,8 @@ */ #include "LogView.h" -#include #include +#include LogView::LogView(QWidget* parent) : QPlainTextEdit(parent) { @@ -50,13 +50,10 @@ LogView::~LogView() void LogView::setWordWrap(bool wrapping) { - if(wrapping) - { + if (wrapping) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setLineWrapMode(QPlainTextEdit::WidgetWidth); - } - else - { + } else { setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setLineWrapMode(QPlainTextEdit::NoWrap); } @@ -64,16 +61,14 @@ void LogView::setWordWrap(bool wrapping) void LogView::setModel(QAbstractItemModel* model) { - if(m_model) - { + if (m_model) { disconnect(m_model, &QAbstractItemModel::modelReset, this, &LogView::repopulate); disconnect(m_model, &QAbstractItemModel::rowsInserted, this, &LogView::rowsInserted); disconnect(m_model, &QAbstractItemModel::rowsAboutToBeInserted, this, &LogView::rowsAboutToBeInserted); disconnect(m_model, &QAbstractItemModel::rowsRemoved, this, &LogView::rowsRemoved); } m_model = model; - if(m_model) - { + if (m_model) { connect(m_model, &QAbstractItemModel::modelReset, this, &LogView::repopulate); connect(m_model, &QAbstractItemModel::rowsInserted, this, &LogView::rowsInserted); connect(m_model, &QAbstractItemModel::rowsAboutToBeInserted, this, &LogView::rowsAboutToBeInserted); @@ -83,15 +78,14 @@ void LogView::setModel(QAbstractItemModel* model) repopulate(); } -QAbstractItemModel * LogView::model() const +QAbstractItemModel* LogView::model() const { return m_model; } void LogView::modelDestroyed(QObject* model) { - if(m_model == model) - { + if (m_model == model) { setModel(nullptr); } } @@ -100,8 +94,7 @@ void LogView::repopulate() { auto doc = document(); doc->clear(); - if(!m_model) - { + if (!m_model) { return; } rowsInserted(QModelIndex(), 0, m_model->rowCount() - 1); @@ -112,39 +105,32 @@ void LogView::rowsAboutToBeInserted(const QModelIndex& parent, int first, int la Q_UNUSED(parent) Q_UNUSED(first) Q_UNUSED(last) - QScrollBar *bar = verticalScrollBar(); + QScrollBar* bar = verticalScrollBar(); int max_bar = bar->maximum(); int val_bar = bar->value(); - if (m_scroll) - { + if (m_scroll) { m_scroll = (max_bar - val_bar) <= 1; - } - else - { + } else { m_scroll = val_bar == max_bar; } } void LogView::rowsInserted(const QModelIndex& parent, int first, int last) { - for(int i = first; i <= last; i++) - { + for (int i = first; i <= last; i++) { auto idx = m_model->index(i, 0, parent); auto text = m_model->data(idx, Qt::DisplayRole).toString(); QTextCharFormat format(*m_defaultFormat); auto font = m_model->data(idx, Qt::FontRole); - if(font.isValid()) - { + if (font.isValid()) { format.setFont(font.value()); } auto fg = m_model->data(idx, Qt::ForegroundRole); - if(fg.isValid()) - { + if (fg.isValid()) { format.setForeground(fg.value()); } auto bg = m_model->data(idx, Qt::BackgroundRole); - if(bg.isValid()) - { + if (bg.isValid()) { format.setBackground(bg.value()); } auto workCursor = textCursor(); @@ -152,10 +138,9 @@ void LogView::rowsInserted(const QModelIndex& parent, int first, int last) workCursor.insertText(text, format); workCursor.insertBlock(); } - if(m_scroll && !m_scrolling) - { + if (m_scroll && !m_scrolling) { m_scrolling = true; - QMetaObject::invokeMethod( this, "scrollToBottom", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "scrollToBottom", Qt::QueuedConnection); } } diff --git a/launcher/ui/widgets/LogView.h b/launcher/ui/widgets/LogView.h index 3143360a..dde5f8f7 100644 --- a/launcher/ui/widgets/LogView.h +++ b/launcher/ui/widgets/LogView.h @@ -1,36 +1,35 @@ #pragma once -#include #include +#include class QAbstractItemModel; -class LogView: public QPlainTextEdit -{ +class LogView : public QPlainTextEdit { Q_OBJECT -public: - explicit LogView(QWidget *parent = nullptr); + public: + explicit LogView(QWidget* parent = nullptr); virtual ~LogView(); - virtual void setModel(QAbstractItemModel *model); - QAbstractItemModel *model() const; + virtual void setModel(QAbstractItemModel* model); + QAbstractItemModel* model() const; -public slots: + public slots: void setWordWrap(bool wrapping); - void findNext(const QString & what, bool reverse); + void findNext(const QString& what, bool reverse); void scrollToBottom(); -protected slots: + protected slots: void repopulate(); // note: this supports only appending - void rowsInserted(const QModelIndex &parent, int first, int last); - void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last); + void rowsInserted(const QModelIndex& parent, int first, int last); + void rowsAboutToBeInserted(const QModelIndex& parent, int first, int last); // note: this supports only removing from front - void rowsRemoved(const QModelIndex &parent, int first, int last); - void modelDestroyed(QObject * model); + void rowsRemoved(const QModelIndex& parent, int first, int last); + void modelDestroyed(QObject* model); -protected: - QAbstractItemModel *m_model = nullptr; - QTextCharFormat *m_defaultFormat = nullptr; + protected: + QAbstractItemModel* m_model = nullptr; + QTextCharFormat* m_defaultFormat = nullptr; bool m_scroll = false; bool m_scrolling = false; }; diff --git a/launcher/ui/widgets/ModFilterWidget.cpp b/launcher/ui/widgets/ModFilterWidget.cpp index ea052c41..c2c099ee 100644 --- a/launcher/ui/widgets/ModFilterWidget.cpp +++ b/launcher/ui/widgets/ModFilterWidget.cpp @@ -18,9 +18,8 @@ unique_qobject_ptr ModFilterWidget::create(Version default_vers auto task = filter_widget->versionList()->getLoadTask(); - connect(task.get(), &Task::failed, [filter_widget]{ - filter_widget->disableVersionButton(VersionButtonID::Major, tr("failed to get version index")); - }); + connect(task.get(), &Task::failed, + [filter_widget] { filter_widget->disableVersionButton(VersionButtonID::Major, tr("failed to get version index")); }); connect(task.get(), &Task::finished, &load_version_list_loop, &QEventLoop::quit); if (!task->isRunning()) @@ -34,16 +33,15 @@ unique_qobject_ptr ModFilterWidget::create(Version default_vers return unique_qobject_ptr(filter_widget); } -ModFilterWidget::ModFilterWidget(Version def, QWidget* parent) - : QTabWidget(parent), m_filter(new Filter()), ui(new Ui::ModFilterWidget) +ModFilterWidget::ModFilterWidget(Version def, QWidget* parent) : QTabWidget(parent), m_filter(new Filter()), ui(new Ui::ModFilterWidget) { ui->setupUi(this); - m_mcVersion_buttons.addButton(ui->strictVersionButton, VersionButtonID::Strict); + m_mcVersion_buttons.addButton(ui->strictVersionButton, VersionButtonID::Strict); ui->strictVersionButton->click(); - m_mcVersion_buttons.addButton(ui->majorVersionButton, VersionButtonID::Major); - m_mcVersion_buttons.addButton(ui->allVersionsButton, VersionButtonID::All); - //m_mcVersion_buttons.addButton(ui->betweenVersionsButton, VersionButtonID::Between); + m_mcVersion_buttons.addButton(ui->majorVersionButton, VersionButtonID::Major); + m_mcVersion_buttons.addButton(ui->allVersionsButton, VersionButtonID::All); + // m_mcVersion_buttons.addButton(ui->betweenVersionsButton, VersionButtonID::Between); connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int))); @@ -57,25 +55,19 @@ void ModFilterWidget::setInstance(MinecraftInstance* instance) { m_instance = instance; - ui->strictVersionButton->setText( - tr("Strict match (= %1)").arg(mcVersionStr())); + ui->strictVersionButton->setText(tr("Strict match (= %1)").arg(mcVersionStr())); // we can't do this for snapshots sadly - if(mcVersionStr().contains('.')) - { + if (mcVersionStr().contains('.')) { auto mcVersionSplit = mcVersionStr().split("."); - ui->majorVersionButton->setText( - tr("Major version match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); - } - else - { + ui->majorVersionButton->setText(tr("Major version match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); + } else { ui->majorVersionButton->setText(tr("Major version match (unsupported)")); disableVersionButton(Major); } - ui->allVersionsButton->setText( - tr("Any version")); - //ui->betweenVersionsButton->setText( - // tr("Between two versions")); + ui->allVersionsButton->setText(tr("Any version")); + // ui->betweenVersionsButton->setText( + // tr("Between two versions")); } auto ModFilterWidget::getFilter() -> std::shared_ptr @@ -89,19 +81,19 @@ void ModFilterWidget::disableVersionButton(VersionButtonID id, QString reason) { QAbstractButton* btn = nullptr; - switch(id){ - case(VersionButtonID::Strict): - btn = ui->strictVersionButton; - break; - case(VersionButtonID::Major): - btn = ui->majorVersionButton; - break; - case(VersionButtonID::All): - btn = ui->allVersionsButton; - break; - case(VersionButtonID::Between): - default: - break; + switch (id) { + case (VersionButtonID::Strict): + btn = ui->strictVersionButton; + break; + case (VersionButtonID::Major): + btn = ui->majorVersionButton; + break; + case (VersionButtonID::All): + btn = ui->allVersionsButton; + break; + case (VersionButtonID::Between): + default: + break; } if (btn) { @@ -113,12 +105,12 @@ void ModFilterWidget::disableVersionButton(VersionButtonID id, QString reason) void ModFilterWidget::onVersionFilterChanged(int id) { - //ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); - //ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between); + // ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); + // ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between); int index = 1; - auto cast_id = (VersionButtonID) id; + auto cast_id = (VersionButtonID)id; if (cast_id != m_version_id) { m_version_id = cast_id; } else { @@ -127,32 +119,32 @@ void ModFilterWidget::onVersionFilterChanged(int id) m_filter->versions.clear(); - switch(cast_id){ - case(VersionButtonID::Strict): - m_filter->versions.push_front(mcVersion()); - break; - case(VersionButtonID::Major): { - auto versionSplit = mcVersionStr().split("."); + switch (cast_id) { + case (VersionButtonID::Strict): + m_filter->versions.push_front(mcVersion()); + break; + case (VersionButtonID::Major): { + auto versionSplit = mcVersionStr().split("."); - auto major_version = QString("%1.%2").arg(versionSplit[0], versionSplit[1]); - QString version_str = major_version; + auto major_version = QString("%1.%2").arg(versionSplit[0], versionSplit[1]); + QString version_str = major_version; - while (m_version_list->hasVersion(version_str)) { - m_filter->versions.emplace_back(version_str); - version_str = QString("%1.%2").arg(major_version, QString::number(index++)); - } + while (m_version_list->hasVersion(version_str)) { + m_filter->versions.emplace_back(version_str); + version_str = QString("%1.%2").arg(major_version, QString::number(index++)); + } - break; - } - case(VersionButtonID::All): - // Empty list to avoid enumerating all versions :P - break; - case(VersionButtonID::Between): - // TODO - break; + break; + } + case (VersionButtonID::All): + // Empty list to avoid enumerating all versions :P + break; + case (VersionButtonID::Between): + // TODO + break; } - if(changed()) + if (changed()) emit filterChanged(); else emit filterUnchanged(); diff --git a/launcher/ui/widgets/ModFilterWidget.h b/launcher/ui/widgets/ModFilterWidget.h index 706ffd21..ed6cd0ea 100644 --- a/launcher/ui/widgets/ModFilterWidget.h +++ b/launcher/ui/widgets/ModFilterWidget.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include "Version.h" @@ -17,16 +17,10 @@ namespace Ui { class ModFilterWidget; } -class ModFilterWidget : public QTabWidget -{ +class ModFilterWidget : public QTabWidget { Q_OBJECT -public: - enum VersionButtonID { - Strict = 0, - Major = 1, - All = 2, - Between = 3 - }; + public: + enum VersionButtonID { Strict = 0, Major = 1, All = 2, Between = 3 }; struct Filter { std::list versions; @@ -37,7 +31,7 @@ public: std::shared_ptr m_filter; -public: + public: static unique_qobject_ptr create(Version default_version, QWidget* parent = nullptr); ~ModFilterWidget(); @@ -51,26 +45,29 @@ public: Meta::VersionList::Ptr versionList() { return m_version_list; } -private: + private: ModFilterWidget(Version def, QWidget* parent = nullptr); - inline auto mcVersionStr() const -> QString { return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; } + inline auto mcVersionStr() const -> QString + { + return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; + } inline auto mcVersion() const -> Version { return { mcVersionStr() }; } -private slots: + private slots: void onVersionFilterChanged(int id); -public: signals: + public: + signals: void filterChanged(); void filterUnchanged(); -private: + private: Ui::ModFilterWidget* ui; MinecraftInstance* m_instance = nullptr; - -/* Version stuff */ + /* Version stuff */ QButtonGroup m_mcVersion_buttons; Meta::VersionList::Ptr m_version_list; diff --git a/launcher/ui/widgets/ModListView.cpp b/launcher/ui/widgets/ModListView.cpp index 80a918b6..c72d4c52 100644 --- a/launcher/ui/widgets/ModListView.cpp +++ b/launcher/ui/widgets/ModListView.cpp @@ -14,61 +14,55 @@ */ #include "ModListView.h" +#include #include #include #include -#include #include -ModListView::ModListView ( QWidget* parent ) - :QTreeView ( parent ) +ModListView::ModListView(QWidget* parent) : QTreeView(parent) { - setAllColumnsShowFocus ( true ); - setExpandsOnDoubleClick ( false ); - setRootIsDecorated ( false ); - setSortingEnabled ( true ); - setAlternatingRowColors ( true ); - setSelectionMode ( QAbstractItemView::ExtendedSelection ); - setHeaderHidden ( false ); + setAllColumnsShowFocus(true); + setExpandsOnDoubleClick(false); + setRootIsDecorated(false); + setSortingEnabled(true); + setAlternatingRowColors(true); + setSelectionMode(QAbstractItemView::ExtendedSelection); + setHeaderHidden(false); setSelectionBehavior(QAbstractItemView::SelectRows); - setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded ); + setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setDropIndicatorShown(true); setDragEnabled(true); setDragDropMode(QAbstractItemView::DropOnly); viewport()->setAcceptDrops(true); } -void ModListView::setModel ( QAbstractItemModel* model ) +void ModListView::setModel(QAbstractItemModel* model) { - QTreeView::setModel ( model ); + QTreeView::setModel(model); auto head = header(); head->setStretchLastSection(false); // HACK: this is true for the checkbox column of mod lists - auto string = model->headerData(0,head->orientation()).toString(); - if(head->count() < 1) - { + auto string = model->headerData(0, head->orientation()).toString(); + if (head->count() < 1) { return; } - if(!string.size()) - { + if (!string.size()) { head->setSectionResizeMode(0, QHeaderView::ResizeToContents); head->setSectionResizeMode(1, QHeaderView::Stretch); - for(int i = 2; i < head->count(); i++) + for (int i = 2; i < head->count(); i++) head->setSectionResizeMode(i, QHeaderView::ResizeToContents); - } - else - { + } else { head->setSectionResizeMode(0, QHeaderView::Stretch); - for(int i = 1; i < head->count(); i++) + for (int i = 1; i < head->count(); i++) head->setSectionResizeMode(i, QHeaderView::ResizeToContents); } } -void ModListView::setResizeModes(const QList &modes) +void ModListView::setResizeModes(const QList& modes) { auto head = header(); - for(int i = 0; i < modes.count(); i++) { + for (int i = 0; i < modes.count(); i++) { head->setSectionResizeMode(i, modes[i]); } } - diff --git a/launcher/ui/widgets/ModListView.h b/launcher/ui/widgets/ModListView.h index 3f0b3b0e..86316459 100644 --- a/launcher/ui/widgets/ModListView.h +++ b/launcher/ui/widgets/ModListView.h @@ -17,11 +17,10 @@ #include #include -class ModListView: public QTreeView -{ +class ModListView : public QTreeView { Q_OBJECT -public: - explicit ModListView ( QWidget* parent = 0 ); - virtual void setModel ( QAbstractItemModel* model ); - virtual void setResizeModes (const QList& modes); + public: + explicit ModListView(QWidget* parent = 0); + virtual void setModel(QAbstractItemModel* model); + virtual void setResizeModes(const QList& modes); }; diff --git a/launcher/ui/widgets/PageContainer.cpp b/launcher/ui/widgets/PageContainer.cpp index b98c9796..c3b70c44 100644 --- a/launcher/ui/widgets/PageContainer.cpp +++ b/launcher/ui/widgets/PageContainer.cpp @@ -38,36 +38,33 @@ #include "BuildConfig.h" #include "PageContainer_p.h" -#include +#include +#include +#include +#include +#include #include #include -#include +#include #include -#include -#include -#include -#include -#include +#include #include "settings/SettingsObject.h" #include "ui/widgets/IconLabel.h" -#include "DesktopServices.h" #include "Application.h" +#include "DesktopServices.h" -class PageEntryFilterModel : public QSortFilterProxyModel -{ -public: - explicit PageEntryFilterModel(QObject *parent = 0) : QSortFilterProxyModel(parent) - { - } +class PageEntryFilterModel : public QSortFilterProxyModel { + public: + explicit PageEntryFilterModel(QObject* parent = 0) : QSortFilterProxyModel(parent) {} -protected: - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const + protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { const QString pattern = filterRegularExpression().pattern(); - const auto model = static_cast(sourceModel()); + const auto model = static_cast(sourceModel()); const auto page = model->pages().at(sourceRow); if (!page->shouldDisplay()) return false; @@ -76,18 +73,15 @@ protected: } }; -PageContainer::PageContainer(BasePageProvider *pageProvider, QString defaultId, - QWidget *parent) - : QWidget(parent) +PageContainer::PageContainer(BasePageProvider* pageProvider, QString defaultId, QWidget* parent) : QWidget(parent) { createUI(); m_model = new PageModel(this); m_proxyModel = new PageEntryFilterModel(this); int counter = 0; auto pages = pageProvider->getPages(); - for (auto page : pages) - { - auto widget = dynamic_cast(page); + for (auto page : pages) { + auto widget = dynamic_cast(page); widget->setParent(this); page->stackIndex = m_pageStack->addWidget(widget); page->listIndex = counter; @@ -108,8 +102,7 @@ PageContainer::PageContainer(BasePageProvider *pageProvider, QString defaultId, m_pageList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); m_pageList->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); m_pageList->setModel(m_proxyModel); - connect(m_pageList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), - this, SLOT(currentChanged(QModelIndex))); + connect(m_pageList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex))); m_pageStack->setStackingMode(QStackedLayout::StackOne); m_pageList->setFocus(); selectPage(defaultId); @@ -120,16 +113,13 @@ bool PageContainer::selectPage(QString pageId) // now find what we want to have selected... auto page = m_model->findPageEntryById(pageId); QModelIndex index; - if (page) - { + if (page) { index = m_proxyModel->mapFromSource(m_model->index(page->listIndex)); } - if(!index.isValid()) - { + if (!index.isValid()) { index = m_proxyModel->index(0, 0); } - if (index.isValid()) - { + if (index.isValid()) { m_pageList->setCurrentIndex(index); return true; } @@ -149,15 +139,11 @@ const QList PageContainer::getPages() const void PageContainer::refreshContainer() { m_proxyModel->invalidate(); - if(!m_currentPage->shouldDisplay()) - { + if (!m_currentPage->shouldDisplay()) { auto index = m_proxyModel->index(0, 0); - if(index.isValid()) - { + if (index.isValid()) { m_pageList->setCurrentIndex(index); - } - else - { + } else { // FIXME: unhandled corner case: what to do when there's no page to select? } } @@ -177,7 +163,7 @@ void PageContainer::createUI() headerLabelFont.setPointSize(pointSize + 2); m_header->setFont(headerLabelFont); - QHBoxLayout *headerHLayout = new QHBoxLayout; + QHBoxLayout* headerHLayout = new QHBoxLayout; const int leftMargin = APPLICATION->style()->pixelMetric(QStyle::PM_LayoutLeftMargin); headerHLayout->addSpacerItem(new QSpacerItem(leftMargin, 0, QSizePolicy::Fixed, QSizePolicy::Ignored)); headerHLayout->addWidget(m_header); @@ -195,7 +181,7 @@ void PageContainer::createUI() m_layout->addWidget(m_pageList, 0, 0, 2, 1); m_layout->addLayout(m_pageStack, 1, 1, 1, 1); m_layout->setColumnStretch(1, 4); - m_layout->setContentsMargins(0,0,0,6); + m_layout->setContentsMargins(0, 0, 0, 6); setLayout(m_layout); } @@ -208,39 +194,32 @@ void PageContainer::retranslate() page->retranslate(); } -void PageContainer::addButtons(QWidget *buttons) +void PageContainer::addButtons(QWidget* buttons) { m_layout->addWidget(buttons, 2, 0, 1, 2); } -void PageContainer::addButtons(QLayout *buttons) +void PageContainer::addButtons(QLayout* buttons) { m_layout->addLayout(buttons, 2, 0, 1, 2); } void PageContainer::showPage(int row) { - if (m_currentPage) - { + if (m_currentPage) { m_currentPage->closed(); } - if (row != -1) - { + if (row != -1) { m_currentPage = m_model->pages().at(row); - } - else - { + } else { m_currentPage = nullptr; } - if (m_currentPage) - { + if (m_currentPage) { m_pageStack->setCurrentIndex(m_currentPage->stackIndex); m_header->setText(m_currentPage->displayName()); m_iconHeader->setIcon(m_currentPage->icon()); m_currentPage->opened(); - } - else - { + } else { m_pageStack->setCurrentIndex(0); m_header->setText(QString()); m_iconHeader->setIcon(APPLICATION->getThemedIcon("bug")); @@ -249,8 +228,7 @@ void PageContainer::showPage(int row) void PageContainer::help() { - if (m_currentPage) - { + if (m_currentPage) { QString pageId = m_currentPage->helpPage(); if (pageId.isEmpty()) return; @@ -258,7 +236,7 @@ void PageContainer::help() } } -void PageContainer::currentChanged(const QModelIndex ¤t) +void PageContainer::currentChanged(const QModelIndex& current) { int selected_index = current.isValid() ? m_proxyModel->mapToSource(current).row() : -1; @@ -272,12 +250,10 @@ void PageContainer::currentChanged(const QModelIndex ¤t) bool PageContainer::prepareToClose() { - if(!saveAll()) - { + if (!saveAll()) { return false; } - if (m_currentPage) - { + if (m_currentPage) { m_currentPage->closed(); } return true; @@ -285,8 +261,7 @@ bool PageContainer::prepareToClose() bool PageContainer::saveAll() { - for (auto page : m_model->pages()) - { + for (auto page : m_model->pages()) { if (!page->apply()) return false; } diff --git a/launcher/ui/widgets/PageContainer.h b/launcher/ui/widgets/PageContainer.h index ad74d43a..f5978dba 100644 --- a/launcher/ui/widgets/PageContainer.h +++ b/launcher/ui/widgets/PageContainer.h @@ -35,11 +35,11 @@ #pragma once -#include #include +#include -#include "ui/pages/BasePageProvider.h" #include "ui/pages/BasePageContainer.h" +#include "ui/pages/BasePageProvider.h" class QLayout; class IconLabel; @@ -51,16 +51,14 @@ class QLineEdit; class QStackedLayout; class QGridLayout; -class PageContainer : public QWidget, public BasePageContainer -{ +class PageContainer : public QWidget, public BasePageContainer { Q_OBJECT -public: - explicit PageContainer(BasePageProvider *pageProvider, QString defaultId = QString(), - QWidget *parent = 0); + public: + explicit PageContainer(BasePageProvider* pageProvider, QString defaultId = QString(), QWidget* parent = 0); virtual ~PageContainer() {} - void addButtons(QWidget * buttons); - void addButtons(QLayout * buttons); + void addButtons(QWidget* buttons); + void addButtons(QLayout* buttons); /* * Save any unsaved state and prepare to be closed. * @return true if everything can be saved, false if there is something that requires attention @@ -71,8 +69,7 @@ public: /* request close - used by individual pages */ bool requestClose() override { - if(m_container) - { + if (m_container) { return m_container->requestClose(); } return false; @@ -83,36 +80,33 @@ public: const QList getPages() const; void refreshContainer() override; - virtual void setParentContainer(BasePageContainer * container) - { - m_container = container; - }; + virtual void setParentContainer(BasePageContainer* container) { m_container = container; }; void changeEvent(QEvent*) override; -private: + private: void createUI(); void retranslate(); -public slots: + public slots: void help(); -signals: + signals: /** Emitted when the currently selected page is changed */ void selectedPageChanged(BasePage* previous, BasePage* selected); -private slots: - void currentChanged(const QModelIndex ¤t); + private slots: + void currentChanged(const QModelIndex& current); void showPage(int row); -private: - BasePageContainer * m_container = nullptr; - BasePage * m_currentPage = 0; - QSortFilterProx