QTfrontend/util/MessageDialog.cpp
branchhedgeroid
changeset 15515 7030706266df
parent 14841 b9437746bffb
equal deleted inserted replaced
7861:bc7b6aa5d67a 15515:7030706266df
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    17  */
       
    18 
       
    19 #include "MessageDialog.h"
       
    20 #include "HWApplication.h"
       
    21 
       
    22 
       
    23 
       
    24 int MessageDialog::ShowFatalMessage(const QString & msg, QWidget * parent)
       
    25 {
       
    26     return ShowMessage(QMessageBox::tr("Hedgewars - Error"),
       
    27                        msg,
       
    28                        QMessageBox::Critical,
       
    29                        parent);
       
    30 }
       
    31 
       
    32 int MessageDialog::ShowErrorMessage(const QString & msg, QWidget * parent)
       
    33 {
       
    34     return ShowMessage(QMessageBox::tr("Hedgewars - Warning"),
       
    35                        msg,
       
    36                        QMessageBox::Warning,
       
    37                        parent);
       
    38 }
       
    39 
       
    40 int MessageDialog::ShowInfoMessage(const QString & msg, QWidget * parent)
       
    41 {
       
    42     return ShowMessage(QMessageBox::tr("Hedgewars - Information"),
       
    43                        msg,
       
    44                        QMessageBox::Information,
       
    45                        parent);
       
    46 }
       
    47 
       
    48 int MessageDialog::ShowMessage(const QString & title, const QString & msg, QMessageBox::Icon icon, QWidget * parent)
       
    49 {
       
    50     // if no parent try to use active window
       
    51     parent = parent ? parent : HWApplication::activeWindow();
       
    52 
       
    53     // didn't work? make child of hwform (e.g. for style and because modal)
       
    54     if (!parent)
       
    55     {
       
    56         try
       
    57         {
       
    58             HWApplication * app = dynamic_cast<HWApplication*>(HWApplication::instance());
       
    59             if (app->form)
       
    60                 parent = app->form;
       
    61         }
       
    62         catch (...) { /* nothing */ }
       
    63     }
       
    64 
       
    65     QMessageBox msgMsg(parent);
       
    66     msgMsg.setWindowTitle(title != NULL ? title : "Hedgewars");
       
    67     msgMsg.setText(msg);
       
    68     msgMsg.setIcon(icon);
       
    69     msgMsg.setTextFormat(Qt::PlainText);
       
    70     msgMsg.setWindowModality(Qt::WindowModal);
       
    71 
       
    72     return msgMsg.exec();
       
    73 }