]> vaikene.ee Git - evaf/blob - src/main/GUI/fatalerr.cpp
Warning fixes and copyright update.
[evaf] / src / main / GUI / fatalerr.cpp
1 /**
2 * @file main/GUI/fatalerr.cpp
3 * @brief Fatal error message dialog box
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011-2019 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #include "fatalerr.h"
21
22 #include <QtWidgets>
23
24 using namespace eVaf::GUI::Internal;
25
26
27 //-------------------------------------------------------------------
28
29 FatalErr::FatalErr(QString const & title, QString const & text, QWidget * parent)
30 : QDialog(parent, Qt::WindowTitleHint)
31 , mTimer(Timer)
32 {
33 setWindowTitle(title);
34
35 QVBoxLayout * layout = new QVBoxLayout;
36 layout->setSpacing(10);
37 setLayout(layout);
38
39 QHBoxLayout * messageBox = new QHBoxLayout;
40 messageBox->setSpacing(20);
41 layout->addLayout(messageBox);
42
43 // Icon
44 QLabel * l = new QLabel;
45 l->setPixmap(QMessageBox::standardIcon(QMessageBox::Critical));
46 l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
47 messageBox->addWidget(l);
48
49 // Error message text
50 l = new QLabel(text);
51 l->setWordWrap(true);
52 l->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
53 messageBox->addWidget(l);
54
55 // Warning about the Ignore button
56 l = new QLabel;
57 l->setTextFormat(Qt::RichText);
58 l->setText(tr(
59 "<p><small><i>Clicking on the 'Abort' button aborts the application.<br>"
60 "Clicking on the 'Ignore' button keeps the application running for diagnostics.</i></small></p>"
61 "<p><small><font color=\"red\">The application might be unstable if fatal errors are ignored!</font></small></p>"
62 ));
63 layout->addWidget(l);
64
65 // Buttons
66 QHBoxLayout * buttonBox = new QHBoxLayout;
67 layout->addLayout(buttonBox);
68
69 buttonBox->addStretch();
70
71 wAbort = new QPushButton(tr("%Abort (%1 sec)").arg(mTimer));
72 connect(wAbort, SIGNAL(clicked()), this, SLOT(abortClicked()));
73 buttonBox->addWidget(wAbort);
74 setFocusProxy(wAbort);
75
76 QPushButton * b = new QPushButton(tr("&Ignore"));
77 connect(b, SIGNAL(clicked()), this, SLOT(ignoreClicked()));
78 buttonBox->addWidget(b);
79
80 setResult(Abort);
81
82 // Start the count-down timer
83 startTimer(1000);
84 }
85
86 void FatalErr::timerEvent(QTimerEvent *)
87 {
88 --mTimer;
89 wAbort->setText(tr("&Abort (%1 sec)").arg(mTimer));
90
91 if (mTimer <= 0)
92 done(Abort);
93 }
94
95 void FatalErr::abortClicked()
96 {
97 done(Abort);
98 }
99
100 void FatalErr::ignoreClicked()
101 {
102 done(Ignore);
103 }
104
105 int FatalErr::message(QString const & title, QString const & text, QWidget * parent)
106 {
107 FatalErr msg(title, text, parent);
108 return msg.exec();
109 }