refs #485, finetuning the HTML cmd line help

Turn Qt message into HTML table
This commit is contained in:
Klaus Basan
2016-03-05 02:59:41 +01:00
committed by Mathew Sutcliffe
parent 1eb65a873c
commit 8e6c4ad35d
2 changed files with 63 additions and 2 deletions

View File

@@ -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 += "<table>\n";
}
if (!tableMode)
{
html += l;
html += "<br>";
}
else
{
// in table mode
if (lt.startsWith("-"))
{
if (pendingTr)
{
html += "</td></tr>\n";
}
html += "<tr><td>";
static const QRegExp reg("[ ]{2,}");
html += lt.replace(reg, "</td><td>");
pendingTr = true;
}
else
{
html += " ";
html += l.simplified();
}
}
}
html += "</table>\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(),
"<html><head/><body><h2>" + errorMessage + "</h2><pre>" + this->m_parser.helpText() + "</pre></body></html>");
"<html><head/><body><h2>" + errorMessage + "</h2>" + helpText + "</body></html>");
}
else
{

View File

@@ -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