From 8e6c4ad35d73e9f099d9795ecb7b83ea72bdcec0 Mon Sep 17 00:00:00 2001
From: Klaus Basan
Date: Sat, 5 Mar 2016 02:59:41 +0100
Subject: [PATCH] refs #485, finetuning the HTML cmd line help Turn Qt message
into HTML table
---
src/blackgui/guiapplication.cpp | 61 +++++++++++++++++++++++++++++++--
src/blackgui/guiapplication.h | 4 +++
2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/src/blackgui/guiapplication.cpp b/src/blackgui/guiapplication.cpp
index 413e46333..ef6da0bbb 100644
--- a/src/blackgui/guiapplication.cpp
+++ b/src/blackgui/guiapplication.cpp
@@ -34,7 +34,7 @@ namespace BlackGui
const BlackMisc::CLogCategoryList &CGuiApplication::getLogCategories()
{
- static const CLogCategoryList l(CApplication::getLogCategories().join( { CLogCategory::guiComponent() }));
+ static const CLogCategoryList l(CApplication::getLogCategories().join({ CLogCategory::guiComponent() }));
return l;
}
@@ -121,13 +121,70 @@ namespace BlackGui
CApplication::exit(retcode);
}
+ void CGuiApplication::ps_startupCompleted()
+ {
+ CApplication::ps_startupCompleted();
+ if (this->m_splashScreen)
+ {
+ this->m_splashScreen->close();
+ this->m_splashScreen.reset();
+ }
+ }
+
+ QString CGuiApplication::beautifyHelpMessage(const QString &helpText)
+ {
+ // just formatting Qt help message into HTML table
+ if (helpText.isEmpty()) { return ""; }
+ const QStringList lines(helpText.split('\n'));
+ QString html;
+ bool tableMode = false;
+ bool pendingTr = false;
+ for (const QString &l : lines)
+ {
+ QString lt(l.trimmed());
+ if (!tableMode && lt.startsWith("-"))
+ {
+ tableMode = true;
+ html += "\n";
+ }
+ if (!tableMode)
+ {
+ html += l;
+ html += "
";
+ }
+ else
+ {
+ // in table mode
+ if (lt.startsWith("-"))
+ {
+ if (pendingTr)
+ {
+ html += "\n";
+ }
+ html += "| ";
+ static const QRegExp reg("[ ]{2,}");
+ html += lt.replace(reg, " | ");
+ pendingTr = true;
+ }
+ else
+ {
+ html += " ";
+ html += l.simplified();
+ }
+ }
+ }
+ html += " |
\n";
+ return html;
+ }
+
void CGuiApplication::cmdLineErrorMessage(const QString &errorMessage) const
{
if (CProject::isRunningOnWindowsNtPlatform())
{
+ const QString helpText(beautifyHelpMessageImpl(this->m_parser.helpText()));
QMessageBox::warning(nullptr,
QGuiApplication::applicationDisplayName(),
- "
" + errorMessage + "
" + this->m_parser.helpText() + "
");
+ "" + errorMessage + "
" + helpText + "");
}
else
{
diff --git a/src/blackgui/guiapplication.h b/src/blackgui/guiapplication.h
index ce5a10233..d457de2cf 100644
--- a/src/blackgui/guiapplication.h
+++ b/src/blackgui/guiapplication.h
@@ -29,6 +29,7 @@ namespace BlackGui
*
* - style sheet handling
* - standard menus
+ * - splash screen support
*
* Simple example
* \snippet swiftlauncher/main.cpp CSwiftGuiStdApplication
@@ -137,6 +138,9 @@ namespace BlackGui
QPixmap m_windowIcon;
QCommandLineOption m_cmdWindowStateMinimized { "empty" }; //!< window state (minimized)
QCommandLineOption m_cmdWindowMode { "empty" }; //!< window mode (flags: frameless ...)
+
+ //! Qt help message to formatted HTML
+ static QString beautifyHelpMessage(const QString &helpText);
};
} // ns