Implemented custom message boxes.

This commit is contained in:
Martin Rotter 2014-01-22 20:29:05 +01:00
parent 8f2c44bcf3
commit d77436ec37
3 changed files with 29 additions and 35 deletions

@ -15,8 +15,8 @@
#include "gui/feedsview.h"
#include "gui/formmain.h"
#include "gui/webbrowser.h"
#include "gui/messagebox.h"
#include <QMessageBox>
#include <QProcess>
#include <QNetworkProxy>
#include <QColorDialog>
@ -199,21 +199,12 @@ bool FormSettings::doSaveCheck() {
resulting_information.replaceInStrings(QRegExp("^"),
QString::fromUtf8(""));
// TODO: dedit qmessagebox
// MessageBox a tam pretizit setIcon
// a setStandardButtons atp
// Some critical errors occurred, display warnings.
QPointer<QMessageBox> msg_error = new QMessageBox(this);
msg_error.data()->setText(tr("Some critical settings are not set. You must fix these settings in order confirm new settings."));
msg_error.data()->setWindowTitle(tr("Cannot save settings"));
msg_error.data()->setDetailedText(tr("List of errors:\n%1.").arg(resulting_information.join(",\n")));
msg_error.data()->setIcon(QMessageBox::Critical);
msg_error.data()->setStandardButtons(QMessageBox::Ok);
msg_error.data()->setDefaultButton(QMessageBox::Ok);
msg_error.data()->exec();
delete msg_error.data();
MessageBox::show(this,
QMessageBox::Critical,
tr("Cannot save settings"),
tr("Some critical settings are not set. You must fix these settings in order confirm new settings."),
QString(),
tr("List of errors:\n%1.").arg(resulting_information.join(",\n")));
}
return everything_ok;
@ -233,24 +224,21 @@ void FormSettings::promptForRestart() {
changed_data_texts.replaceInStrings(QRegExp("^"),
QString::fromUtf8(""));
QPointer<QMessageBox> msg_question = new QMessageBox(this);
msg_question.data()->setText(tr("Some critical settings were changed and will be applied after the application gets restarted."));
msg_question.data()->setInformativeText(tr("Do you want to restart now?"));
msg_question.data()->setWindowTitle(tr("Critical settings were changed"));
msg_question.data()->setDetailedText(tr("List of changes:\n%1.").arg(changed_data_texts.join(",\n")));
msg_question.data()->setIcon(QMessageBox::Question);
msg_question.data()->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msg_question.data()->setDefaultButton(QMessageBox::Yes);
int question_result = msg_question.data()->exec();
delete msg_question.data();
int question_result = MessageBox::show(this,
QMessageBox::Question,
tr("Critical settings were changed"),
tr("Some critical settings were changed and will be applied after the application gets restarted."),
tr("Do you want to restart now?"),
tr("List of changes:\n%1.").arg(changed_data_texts.join(",\n")),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (question_result == QMessageBox::Yes) {
if (!QProcess::startDetached(qApp->applicationFilePath())) {
QMessageBox::warning(this,
tr("Problem with application restart"),
tr("Application couldn't be restarted. Please, restart it manually for changes to take effect."));
MessageBox::show(this,
QMessageBox::Warning,
tr("Problem with application restart"),
tr("Application couldn't be restarted. Please, restart it manually for changes to take effect."));
}
else {
qApp->quit();

@ -37,6 +37,7 @@ QIcon MessageBox::iconForRole(QDialogButtonBox::StandardButton button) {
return IconThemeFactory::instance()->fromTheme("dialog-ok");
case QMessageBox::Cancel:
case QMessageBox::Close:
return IconThemeFactory::instance()->fromTheme("edit-delete");
case QMessageBox::Yes:
@ -77,22 +78,26 @@ QMessageBox::StandardButton MessageBox::show(QWidget *parent,
const QString &title,
const QString &text,
const QString &informative_text,
const QString &detailed_text,
QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton default_button) {
// Create and find needed components.
MessageBox msg_box(parent);
QDialogButtonBox *button_box = msg_box.findChild<QDialogButtonBox*>();
// Initialize message box properties.
msg_box.setWindowTitle(title);
msg_box.setText(text);
msg_box.setInformativeText(informative_text);
msg_box.setDetailedText(detailed_text);
msg_box.setIcon(icon);
msg_box.setStandardButtons(buttons);
msg_box.setDefaultButton(default_button);
// Setup button box icons.
#if !defined(Q_OS_WIN)
QDialogButtonBox *button_box = msg_box.findChild<QDialogButtonBox*>();
iconify(button_box);
#endif
// Display it.
if (msg_box.exec() == -1) {

@ -16,19 +16,20 @@ class MessageBox : public QMessageBox {
// Custom icon setting.
void setIcon(Icon icon);
// Performs icon replacements for given button box.
static void iconify(QDialogButtonBox *button_box);
// Displays custom message box.
static QMessageBox::StandardButton show(QWidget *parent,
QMessageBox::Icon icon,
const QString &title,
const QString &text,
const QString &informative_text = QString(),
const QString &detailed_text = QString(),
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton default_button = QMessageBox::Ok);
private:
// Performs icon replacements for given button box.
static void iconify(QDialogButtonBox *button_box);
// Returns icons for standard roles/statuses.
static QIcon iconForRole(QDialogButtonBox::StandardButton button);
static QIcon iconForStatus(QMessageBox::Icon status);