From b0ef429786bef64799d43f1ac502c139bbde8dc5 Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 29 Oct 2013 12:40:09 +0000 Subject: Add selectable message box helper, use it, make login GUI error label selectable --- gui/CustomMessageBox.cpp | 19 ++++++++++++++++++ gui/CustomMessageBox.h | 11 +++++++++++ gui/LabeledToolButton.cpp | 4 ++-- gui/MCModInfoFrame.cpp | 5 ++--- gui/ModEditDialogCommon.cpp | 7 ++++--- gui/OneSixModEditDialog.cpp | 11 ++++++----- gui/consolewindow.cpp | 13 +++++------- gui/logindialog.ui | 3 +++ gui/mainwindow.cpp | 48 +++++++++++++++++++++++++++------------------ gui/settingsdialog.cpp | 9 +++++---- 10 files changed, 86 insertions(+), 44 deletions(-) create mode 100644 gui/CustomMessageBox.cpp create mode 100644 gui/CustomMessageBox.h (limited to 'gui') diff --git a/gui/CustomMessageBox.cpp b/gui/CustomMessageBox.cpp new file mode 100644 index 00000000..e55ebbbb --- /dev/null +++ b/gui/CustomMessageBox.cpp @@ -0,0 +1,19 @@ +#include "CustomMessageBox.h" + +namespace CustomMessageBox +{ + QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text, + QMessageBox::Icon icon, QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) + { + QMessageBox *messageBox = new QMessageBox(parent); + messageBox->setWindowTitle(title); + messageBox->setText(text); + messageBox->setStandardButtons(buttons); + messageBox->setDefaultButton(defaultButton); + messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); + messageBox->setIcon(icon); + + return messageBox; + } +} diff --git a/gui/CustomMessageBox.h b/gui/CustomMessageBox.h new file mode 100644 index 00000000..145651ec --- /dev/null +++ b/gui/CustomMessageBox.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace CustomMessageBox +{ + QMessageBox *selectable(QWidget *parent, const QString &title, const QString &text, + QMessageBox::Icon icon = QMessageBox::NoIcon, + QMessageBox::StandardButtons buttons = QMessageBox::Ok, + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); +} diff --git a/gui/LabeledToolButton.cpp b/gui/LabeledToolButton.cpp index f1e54696..677476b9 100644 --- a/gui/LabeledToolButton.cpp +++ b/gui/LabeledToolButton.cpp @@ -20,7 +20,7 @@ LabeledToolButton::LabeledToolButton(QWidget * parent) m_label->setWordWrap(true); m_label->setMouseTracking(false); m_label->setAlignment(Qt::AlignCenter); - m_label->setTextInteractionFlags(Qt::NoTextInteraction); + m_label->setTextInteractionFlags(Qt::TextSelectableByMouse); // somehow, this makes word wrap work in the QLabel. yay. m_label->setMinimumWidth(100); } @@ -69,4 +69,4 @@ void LabeledToolButton::resizeEvent(QResizeEvent * event) { m_label->setGeometry(QRect(4, 4, width()-8, height()-8)); QWidget::resizeEvent(event); -} \ No newline at end of file +} diff --git a/gui/MCModInfoFrame.cpp b/gui/MCModInfoFrame.cpp index b3f4ca5b..55ef13f1 100644 --- a/gui/MCModInfoFrame.cpp +++ b/gui/MCModInfoFrame.cpp @@ -15,6 +15,7 @@ #include "MCModInfoFrame.h" #include "ui_MCModInfoFrame.h" +#include "CustomMessageBox.h" #include #include void MCModInfoFrame::updateWithMod(Mod &m) @@ -104,7 +105,5 @@ void MCModInfoFrame::setModDescription(QString text) } void MCModInfoFrame::modDescEllipsisHandler(const QString &link) { - QMessageBox msgbox; - msgbox.setText(desc); - msgbox.exec(); + CustomMessageBox::selectable(this, tr(""), desc)->show(); } diff --git a/gui/ModEditDialogCommon.cpp b/gui/ModEditDialogCommon.cpp index 692ac0c4..873cd8ea 100644 --- a/gui/ModEditDialogCommon.cpp +++ b/gui/ModEditDialogCommon.cpp @@ -1,4 +1,5 @@ #include "ModEditDialogCommon.h" +#include "CustomMessageBox.h" #include #include #include @@ -33,8 +34,8 @@ void showWebsiteForMod(QWidget *parentDlg, Mod &m) } else { - QMessageBox::warning( - parentDlg, parentDlg->tr("How sad!"), - parentDlg->tr("The mod author didn't provide a website link for this mod.")); + CustomMessageBox::selectable(parentDlg, parentDlg->tr("How sad!"), + parentDlg->tr("The mod author didn't provide a website link for this mod."), + QMessageBox::Warning); } } diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index 54f7289d..42bcfeb0 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -23,6 +23,7 @@ #include "logic/ForgeInstaller.h" #include "gui/versionselectdialog.h" #include "gui/platform.h" +#include "gui/CustomMessageBox.h" #include "ProgressDialog.h" #include @@ -110,11 +111,11 @@ void OneSixModEditDialog::on_customizeBtn_clicked() void OneSixModEditDialog::on_revertBtn_clicked() { - auto reply = QMessageBox::question( - this, tr("Revert?"), tr("Do you want to revert the " - "version of this instance to its original configuration?"), - QMessageBox::Yes | QMessageBox::No); - if (reply == QMessageBox::Yes) + auto response = CustomMessageBox::selectable(this, tr("Revert?"), + tr("Do you want to revert the " + "version of this instance to its original configuration?"), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); + if (response == QMessageBox::Yes) { if (m_inst->revertCustomVersion()) { diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp index 6ed4a0ec..78ef958e 100644 --- a/gui/consolewindow.cpp +++ b/gui/consolewindow.cpp @@ -5,6 +5,7 @@ #include #include +#include ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) : QDialog(parent), @@ -96,17 +97,13 @@ void ConsoleWindow::closeEvent(QCloseEvent * event) void ConsoleWindow::on_btnKillMinecraft_clicked() { ui->btnKillMinecraft->setEnabled(false); - QMessageBox r_u_sure; - //: Main question of the kill confirmation dialog - r_u_sure.setText(tr("Kill Minecraft?")); - r_u_sure.setInformativeText(tr("This can cause the instance to get corrupted and should only be used if Minecraft is frozen for some reason")); - r_u_sure.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - r_u_sure.setDefaultButton(QMessageBox::Yes); - if (r_u_sure.exec() == QMessageBox::Yes) + auto response = CustomMessageBox::selectable(this, tr("Kill Minecraft?"), + tr("This can cause the instance to get corrupted and should only be used if Minecraft is frozen for some reason"), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)->exec(); + if (response == QMessageBox::Yes) proc->killMinecraft(); else ui->btnKillMinecraft->setEnabled(true); - r_u_sure.close(); } void ConsoleWindow::onEnded(BaseInstance *instance) diff --git a/gui/logindialog.ui b/gui/logindialog.ui index 46965425..52f35b0c 100644 --- a/gui/logindialog.ui +++ b/gui/logindialog.ui @@ -19,6 +19,9 @@ <span style=" color:#ff0000;">Error</span> + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5d3c52b5..b2fdbe16 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -50,6 +50,7 @@ #include "gui/consolewindow.h" #include "gui/instancesettings.h" #include "gui/platform.h" +#include "gui/CustomMessageBox.h" #include "logic/lists/InstanceList.h" #include "logic/lists/MinecraftVersionList.h" @@ -281,20 +282,26 @@ void MainWindow::on_actionAddInstance_triggered() return; case InstanceFactory::InstExists: + { errorMsg += "An instance with the given directory name already exists."; - QMessageBox::warning(this, "Error", errorMsg); + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; + } case InstanceFactory::CantCreateDir: + { errorMsg += "Failed to create the instance directory."; - QMessageBox::warning(this, "Error", errorMsg); + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; + } default: + { errorMsg += QString("Unknown instance loader error %1").arg(error); - QMessageBox::warning(this, "Error", errorMsg); + CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; } + } } void MainWindow::on_actionChangeInstIcon_triggered() @@ -387,9 +394,10 @@ void MainWindow::on_actionDeleteInstance_triggered() { if (m_selectedInstance) { - int response = QMessageBox::question( - this, "CAREFUL", QString("This is permanent! Are you sure?\nAbout to delete: ") + - m_selectedInstance->name()); + auto response = CustomMessageBox::selectable(this, tr("CAREFUL"), + tr("This is permanent! Are you sure?\nAbout to delete: ") + + m_selectedInstance->name(), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); if (response == QMessageBox::Yes) { m_selectedInstance->nuke(); @@ -626,7 +634,7 @@ void MainWindow::onGameUpdateComplete() void MainWindow::onGameUpdateError(QString error) { - QMessageBox::warning(this, "Error updating instance", error); + CustomMessageBox::selectable(this, tr("Error updating instance"), error, QMessageBox::Warning)->show(); } void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) @@ -695,9 +703,9 @@ void MainWindow::on_actionMakeDesktopShortcut_triggered() QStringList() << "-dl" << QDir::currentPath() << "test", name, "application-x-octet-stream"); - QMessageBox::warning( - this, tr("Not useful"), - tr("A Dummy Shortcut was created. it will not do anything productive")); + CustomMessageBox::selectable(this, tr("Not useful"), + tr("A Dummy Shortcut was created. it will not do anything productive"), + QMessageBox::Warning)->show(); } // BrowserDialog @@ -718,11 +726,11 @@ void MainWindow::on_actionChangeInstMCVersion_triggered() { if (m_selectedInstance->versionIsCustom()) { - auto result = QMessageBox::warning( - this, tr("Are you sure?"), - tr("This will remove any library/version customization you did previously. " - "This includes things like Forge install and similar."), - QMessageBox::Ok, QMessageBox::Abort); + auto result = CustomMessageBox::selectable(this, tr("Are you sure?"), + tr("This will remove any library/version customization you did previously. " + "This includes things like Forge install and similar."), + QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Abort)->exec(); + if (result != QMessageBox::Ok) return; } @@ -853,10 +861,12 @@ void MainWindow::checkSetDefaultJava() java = std::dynamic_pointer_cast(vselect.selectedVersion()); else { - QMessageBox::warning(this, tr("Invalid version selected"), - tr("You didn't select a valid Java version, so MultiMC will " - "select the default. " - "You can change this in the settings dialog.")); + CustomMessageBox::selectable(this, tr("Invalid version selected"), + tr("You didn't select a valid Java version, so MultiMC will " + "select the default. " + "You can change this in the settings dialog."), + QMessageBox::Warning)->show(); + JavaUtils ju; java = ju.GetDefaultJava(); } diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index fb204d10..2619a47f 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -19,6 +19,7 @@ #include "logic/JavaUtils.h" #include "gui/versionselectdialog.h" #include "gui/platform.h" +#include "gui/CustomMessageBox.h" #include "logic/lists/JavaVersionList.h" #include @@ -113,10 +114,10 @@ void SettingsDialog::applySettings(SettingsObject *s) } else if (!s->get("UseDevBuilds").toBool()) { - int response = QMessageBox::question( - this, tr("Development builds"), - tr("Development builds contain experimental features " - "and may be unstable. Are you sure you want to enable them?")); + auto response = CustomMessageBox::selectable(this, tr("Development builds"), + tr("Development builds contain experimental features " + "and may be unstable. Are you sure you want to enable them?"), + QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); if (response == QMessageBox::Yes) { s->set("UseDevBuilds", true); -- cgit v1.2.3 From ac4af46aed54dd7c7bd47dfe9fed869d1a61f62f Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 29 Oct 2013 12:47:14 +0000 Subject: Don't make LabeledToolButton selectable --- gui/LabeledToolButton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui') diff --git a/gui/LabeledToolButton.cpp b/gui/LabeledToolButton.cpp index 677476b9..be84d1b7 100644 --- a/gui/LabeledToolButton.cpp +++ b/gui/LabeledToolButton.cpp @@ -20,7 +20,7 @@ LabeledToolButton::LabeledToolButton(QWidget * parent) m_label->setWordWrap(true); m_label->setMouseTracking(false); m_label->setAlignment(Qt::AlignCenter); - m_label->setTextInteractionFlags(Qt::TextSelectableByMouse); + m_label->setTextInteractionFlags(Qt::NoTextInteraction); // somehow, this makes word wrap work in the QLabel. yay. m_label->setMinimumWidth(100); } -- cgit v1.2.3 From aab5478ae7367dd30695353f626379cb698495f3 Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 29 Oct 2013 16:49:41 +0000 Subject: Move "Forget" button to a sane place --- gui/logindialog.ui | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'gui') diff --git a/gui/logindialog.ui b/gui/logindialog.ui index 52f35b0c..94900d72 100644 --- a/gui/logindialog.ui +++ b/gui/logindialog.ui @@ -88,19 +88,6 @@ - - - - - 0 - 0 - - - - Forget - - - @@ -131,6 +118,19 @@ + + + + + 0 + 0 + + + + Forget + + + -- cgit v1.2.3 From 511417c4f7a9429619492092201253124ee9fed9 Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 29 Oct 2013 18:38:11 +0000 Subject: Make ConsoleWindow have Qt::Window flag (adds minimise/maximise buttons to titlebar) --- gui/consolewindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gui') diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp index 78ef958e..49e12339 100644 --- a/gui/consolewindow.cpp +++ b/gui/consolewindow.cpp @@ -13,8 +13,9 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) : m_mayclose(true), proc(mcproc) { - MultiMCPlatform::fixWM_CLASS(this); + MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); + this->setWindowFlags(Qt::Window); connect(mcproc, SIGNAL(ended(BaseInstance*)), this, SLOT(onEnded(BaseInstance*))); } -- cgit v1.2.3