1
0
Fork 0

{fatal,modal}MessageBox: Use Qt on Linux when available

(console error messages are invisible when started from an icon)
This commit is contained in:
Rebecca N. Palmer 2015-11-24 07:24:32 +00:00
parent 3e67417bf0
commit 997a431d53
4 changed files with 66 additions and 0 deletions

View file

@ -105,6 +105,8 @@ if (HAVE_QT)
PathsDialog.hxx
LocationWidget.cxx
LocationWidget.hxx
QtMessageBox.cxx
QtMessageBox.hxx
${uic_sources}
${qrc_sources})

View file

@ -31,6 +31,10 @@ cocoaMessageBox(const std::string& msg, const std::string& text);
#endif
#ifdef HAVE_QT
#include "QtMessageBox.hxx"
#endif
using namespace simgear::strutils;
namespace {
@ -122,6 +126,8 @@ MessageBoxResult modalMessageBox(const std::string& caption,
return win32MessageBox(caption, msg, moreText);
#elif defined(SG_MAC)
return cocoaMessageBox(msg, moreText);
#elif defined(HAVE_QT)
return QtMessageBox(caption, msg, moreText, false);
#else
SG_LOG(SG_GENERAL, SG_ALERT, caption << ":" << msg);
if (!moreText.empty()) {
@ -139,6 +145,8 @@ MessageBoxResult fatalMessageBox(const std::string& caption,
return win32MessageBox(caption, msg, moreText);
#elif defined(SG_MAC)
return cocoaFatalMessage(msg, moreText);
#elif defined(HAVE_QT)
return QtMessageBox(caption, msg, moreText, true);
#else
std::cerr << "FATAL:" << msg << "\n";
if (!moreText.empty()) {

51
src/GUI/QtMessageBox.cxx Normal file
View file

@ -0,0 +1,51 @@
// QtMessageBox.cxx - Qt5 implementation of MessageBox
//
// Written by Rebecca Palmer, started November 2015.
//
// Copyright (C) 2015 Rebecca Palmer <rebecca_palmer@zoho.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "MessageBox.hxx"
#include "QtLauncher.hxx"
// Qt
#include <QMessageBox>
#include <QString>
flightgear::MessageBoxResult
QtMessageBox(const std::string& caption,
const std::string& msg,
const std::string& moreText,
bool fatal)
{
int fakeargc = 1;
static char fakeargv0[] = "fgfs";
static char * fakeargv[2] = {fakeargv0, 0};
// This does nothing if it has already been run, so the fake argc/argv
// are only used if an error box is triggered in early startup
flightgear::initApp(fakeargc, fakeargv);
QMessageBox msgBox;
msgBox.setWindowTitle(QString::fromStdString(caption));
msgBox.setText(QString::fromStdString(msg));
msgBox.setInformativeText(QString::fromStdString(moreText));
if (fatal) {
msgBox.setIcon(QMessageBox::Critical);
} else {
msgBox.setIcon(QMessageBox::Warning);
}
msgBox.exec();
return flightgear::MSG_BOX_OK;
}

5
src/GUI/QtMessageBox.hxx Normal file
View file

@ -0,0 +1,5 @@
flightgear::MessageBoxResult
QtMessageBox(const std::string& caption,
const std::string& msg,
const std::string& moreText,
bool fatal);