QTfrontend/util/MessageDialog.cpp
author Wuzzy <Wuzzy2@mail.ru>
Sat, 05 Jan 2019 21:52:15 +0100
changeset 14526 8a11548cb1d2
parent 11046 47a8c19ecb60
child 14841 b9437746bffb
permissions -rw-r--r--
TS: Improve configurability by game scheme
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     1
/*
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10307
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     4
 *
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     8
 *
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    12
 * GNU General Public License for more details.
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    13
 *
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    17
 */
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    18
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    19
#include "MessageDialog.h"
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8434
diff changeset
    20
#include "HWApplication.h"
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8434
diff changeset
    21
10305
17f3ca06e39a enforce style on message boxes some more
sheepluva
parents: 10108
diff changeset
    22
17f3ca06e39a enforce style on message boxes some more
sheepluva
parents: 10108
diff changeset
    23
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8434
diff changeset
    24
int MessageDialog::ShowFatalMessage(const QString & msg, QWidget * parent)
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8434
diff changeset
    25
{
8805
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    26
    return ShowMessage(QMessageBox::tr("Hedgewars - Error"),
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    27
                       msg,
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    28
                       QMessageBox::Critical,
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    29
                       parent);
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8434
diff changeset
    30
}
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    31
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    32
int MessageDialog::ShowErrorMessage(const QString & msg, QWidget * parent)
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    33
{
8805
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    34
    return ShowMessage(QMessageBox::tr("Hedgewars - Warning"),
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    35
                       msg,
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    36
                       QMessageBox::Warning,
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    37
                       parent);
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    38
}
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    39
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    40
int MessageDialog::ShowInfoMessage(const QString & msg, QWidget * parent)
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    41
{
8805
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    42
    return ShowMessage(QMessageBox::tr("Hedgewars - Information"),
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    43
                       msg,
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    44
                       QMessageBox::Information,
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    45
                       parent);
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    46
}
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    47
8805
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    48
int MessageDialog::ShowMessage(const QString & title, const QString & msg, QMessageBox::Icon icon, QWidget * parent)
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    49
{
10307
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    50
    // if no parent try to use active window
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    51
    parent = parent ? parent : HWApplication::activeWindow();
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    52
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    53
    // didn't work? make child of hwform (e.g. for style and because modal)
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    54
    if (!parent)
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    55
    {
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    56
        try
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    57
        {
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    58
            HWApplication * app = dynamic_cast<HWApplication*>(HWApplication::instance());
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    59
            if (app->form)
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    60
                parent = app->form;
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    61
        }
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    62
        catch (...) { /* nothing */ }
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    63
    }
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    64
e13d3147f15b do not get stuck on "in game..." page just because of game crash. output a message instead. could still need some tweaking, but a man gotta sleep. and sheep too...
sheepluva
parents: 10305
diff changeset
    65
    QMessageBox msgMsg(parent);
8799
44e520374cfc drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents: 8434
diff changeset
    66
    msgMsg.setWindowTitle(title != NULL ? title : "Hedgewars");
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    67
    msgMsg.setText(msg);
8805
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    68
    msgMsg.setIcon(icon);
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    69
    msgMsg.setWindowModality(Qt::WindowModal);
8805
c0ea47957bdc minor refactor of MessageDialog
koda
parents: 8799
diff changeset
    70
8383
b557c73a7593 GCI2012: Abstract Hedgewars Dialogs
dag10
parents:
diff changeset
    71
    return msgMsg.exec();
8386
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8383
diff changeset
    72
}