From 997a431d536c73e9b3c3213799dd0e0d0bd5ba14 Mon Sep 17 00:00:00 2001 From: "Rebecca N. Palmer" Date: Tue, 24 Nov 2015 07:24:32 +0000 Subject: [PATCH] {fatal,modal}MessageBox: Use Qt on Linux when available (console error messages are invisible when started from an icon) --- src/GUI/CMakeLists.txt | 2 ++ src/GUI/MessageBox.cxx | 8 +++++++ src/GUI/QtMessageBox.cxx | 51 ++++++++++++++++++++++++++++++++++++++++ src/GUI/QtMessageBox.hxx | 5 ++++ 4 files changed, 66 insertions(+) create mode 100644 src/GUI/QtMessageBox.cxx create mode 100644 src/GUI/QtMessageBox.hxx diff --git a/src/GUI/CMakeLists.txt b/src/GUI/CMakeLists.txt index bdff1cce5..26516756a 100644 --- a/src/GUI/CMakeLists.txt +++ b/src/GUI/CMakeLists.txt @@ -105,6 +105,8 @@ if (HAVE_QT) PathsDialog.hxx LocationWidget.cxx LocationWidget.hxx + QtMessageBox.cxx + QtMessageBox.hxx ${uic_sources} ${qrc_sources}) diff --git a/src/GUI/MessageBox.cxx b/src/GUI/MessageBox.cxx index fed1eeffe..ca2e890ab 100644 --- a/src/GUI/MessageBox.cxx +++ b/src/GUI/MessageBox.cxx @@ -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()) { diff --git a/src/GUI/QtMessageBox.cxx b/src/GUI/QtMessageBox.cxx new file mode 100644 index 000000000..430bc34d0 --- /dev/null +++ b/src/GUI/QtMessageBox.cxx @@ -0,0 +1,51 @@ +// QtMessageBox.cxx - Qt5 implementation of MessageBox +// +// Written by Rebecca Palmer, started November 2015. +// +// Copyright (C) 2015 Rebecca Palmer +// +// 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 +#include + +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; +} diff --git a/src/GUI/QtMessageBox.hxx b/src/GUI/QtMessageBox.hxx new file mode 100644 index 000000000..e394a72a2 --- /dev/null +++ b/src/GUI/QtMessageBox.hxx @@ -0,0 +1,5 @@ +flightgear::MessageBoxResult +QtMessageBox(const std::string& caption, + const std::string& msg, + const std::string& moreText, + bool fatal); -- 2.39.5