QTfrontend/util/MessageDialog.cpp
changeset 10307 e13d3147f15b
parent 10305 17f3ca06e39a
child 11046 47a8c19ecb60
equal deleted inserted replaced
10306:4fca8bcfaff0 10307:e13d3147f15b
    45                        parent);
    45                        parent);
    46 }
    46 }
    47 
    47 
    48 int MessageDialog::ShowMessage(const QString & title, const QString & msg, QMessageBox::Icon icon, QWidget * parent)
    48 int MessageDialog::ShowMessage(const QString & title, const QString & msg, QMessageBox::Icon icon, QWidget * parent)
    49 {
    49 {
    50     QMessageBox msgMsg(parent ? parent : HWApplication::activeWindow());
    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);
    51     msgMsg.setWindowTitle(title != NULL ? title : "Hedgewars");
    66     msgMsg.setWindowTitle(title != NULL ? title : "Hedgewars");
    52     msgMsg.setText(msg);
    67     msgMsg.setText(msg);
    53     msgMsg.setIcon(icon);
    68     msgMsg.setIcon(icon);
    54     msgMsg.setWindowModality(Qt::WindowModal);
    69     msgMsg.setWindowModality(Qt::WindowModal);
    55 
    70 
    56     if (!parent)
       
    57     {
       
    58         try
       
    59         {
       
    60             /* workaround to make sure style is correct
       
    61              * I'd rather assign the stylesheet to qApp directly (in main.cpp),
       
    62              * but the current Stylesheet will ruin the look (e.g. map selection) :(
       
    63              */
       
    64             HWApplication * app = dynamic_cast<HWApplication*>(HWApplication::instance());
       
    65             if (app->form)
       
    66                 msgMsg.setStyleSheet(app->form->styleSheet());
       
    67         }
       
    68         catch (...) { /* nothing */ }
       
    69     }
       
    70 
       
    71     return msgMsg.exec();
    71     return msgMsg.exec();
    72 }
    72 }