1 /**************************************************************************
2 *   Copyright (C) 2015-2020 by Mihai Moldovan <ionic@ionic.de>            *
3 *                                                                         *
4 *   This program is free software; you can redistribute it and/or modify  *
5 *   it under the terms of the GNU General Public License as published by  *
6 *   the Free Software Foundation; either version 2 of the License, or     *
7 *   (at your option) any later version.                                   *
8 *   This program is distributed in the hope that it will be useful,       *
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
11 *   GNU General Public License for more details.                          *
12 *                                                                         *
13 *   You should have received a copy of the GNU General Public License     *
14 *   along with this program.  If not, see <https://www.gnu.org/licenses/>. *
15 ***************************************************************************/
16 
17 #include <QGridLayout>
18 #include <QSpacerItem>
19 
20 #include "non_modal_messagebox.h"
21 #include "x2goutils.h"
22 
23 // Please look up the documentation in the header file!
critical(QWidget * parent,const QString & title,const QString & text,const QString & informative_text,bool rich_text,QMessageBox::StandardButtons buttons,QMessageBox::StandardButton defaultButton)24 void Non_Modal_MessageBox::critical (QWidget *parent, const QString &title,
25                                      const QString &text, const QString &informative_text,
26                                      bool rich_text,
27                                      QMessageBox::StandardButtons buttons,
28                                      QMessageBox::StandardButton defaultButton) {
29   QMessageBox *msg_box = new QMessageBox (QMessageBox::Critical, title, text, buttons, parent);
30 
31   msg_box->setAttribute (Qt::WA_DeleteOnClose);
32   msg_box->setDefaultButton (defaultButton);
33 
34   if (rich_text) {
35     msg_box->setTextFormat (Qt::RichText);
36     msg_box->setInformativeText (convert_to_rich_text (informative_text, true));
37   }
38 
39   // Set to minimum width of 500px.
40   QSpacerItem *horizontal_spacer = new QSpacerItem (500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
41   QGridLayout *grid_layout = (QGridLayout*) (msg_box->layout ());
42   grid_layout->addItem (horizontal_spacer, grid_layout->rowCount (), 0, 1, grid_layout->columnCount ());
43 
44   // Here's the real magic.
45   msg_box->setModal (false);
46 
47   msg_box->show ();
48   msg_box->raise ();
49   msg_box->activateWindow ();
50 }
51 
critical(QWidget * parent,const QString & title,const QString & text,const QString & informative_text,QMessageBox::StandardButtons buttons,QMessageBox::StandardButton defaultButton)52 void Non_Modal_MessageBox::critical (QWidget *parent, const QString &title,
53                                      const QString &text, const QString &informative_text,
54                                      QMessageBox::StandardButtons buttons,
55                                      QMessageBox::StandardButton defaultButton) {
56   Non_Modal_MessageBox::critical (parent, title, text, informative_text, false, buttons, defaultButton);
57 }
58 
critical(QWidget * parent,const QString & title,const QString & text,QMessageBox::StandardButtons buttons,QMessageBox::StandardButton defaultButton)59 void Non_Modal_MessageBox::critical (QWidget *parent, const QString &title,
60                                      const QString &text,
61                                      QMessageBox::StandardButtons buttons,
62                                      QMessageBox::StandardButton defaultButton) {
63   Non_Modal_MessageBox::critical (parent, title, text, QString (), buttons, defaultButton);
64 }
65 
66