Ref T213, "about" component to display legal HTML page

This commit is contained in:
Klaus Basan
2018-05-23 23:07:32 +02:00
parent 34252d5e69
commit 0c737b1280
3 changed files with 155 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
/* Copyright (C) 2018
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackgui/guiapplication.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/directoryutils.h"
#include "abouthtmlcomponent.h"
#include "ui_abouthtmlcomponent.h"
#include <QTimer>
#include <QPointer>
using namespace BlackMisc;
namespace BlackGui
{
namespace Components
{
CAboutHtmlComponent::CAboutHtmlComponent(QWidget *parent) :
QFrame(parent),
ui(new Ui::CAboutHtmlComponent)
{
ui->setupUi(this);
const QPointer<CAboutHtmlComponent> myself(this);
QTimer::singleShot(2500, this, [ = ]
{
if (!myself) { return; }
myself->loadAbout();
});
}
CAboutHtmlComponent::~CAboutHtmlComponent()
{ }
void CAboutHtmlComponent::loadAbout()
{
// make links absolute
static const QString htmlFixed = [ = ]
{
// workaround:
// 1) Only reading as HTML gives proper formatting
// 2) Reading the file resource fails (likely because of the style sheet)
const QString html = CFileUtils::readFileToString(CDirectoryUtils::aboutFilePath());
const QString legalDir = sGui->getGlobalSetup().getLegalDirectoryUrl().getFullUrl();
return QString(html).replace(QLatin1String("href=\"./"), "href=\"" + legalDir);
}();
ui->tbr_About->setHtml(htmlFixed);
}
} // ns
} // ns

View File

@@ -0,0 +1,47 @@
/* Copyright (C) 2018
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_ABOUTHTMLCOMPONENT_H
#define BLACKGUI_COMPONENTS_ABOUTHTMLCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CAboutHtmlComponent; }
namespace BlackGui
{
namespace Components
{
/**
* Display the HTML info "about swift"
*/
class BLACKGUI_EXPORT CAboutHtmlComponent : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CAboutHtmlComponent(QWidget *parent = nullptr);
//! Destructor
virtual ~CAboutHtmlComponent();
private:
//! Load credits and legal info
void loadAbout();
QScopedPointer<Ui::CAboutHtmlComponent> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CAboutHtmlComponent</class>
<widget class="QFrame" name="CAboutHtmlComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QVBoxLayout" name="vl_AboutHtmlComponent">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTextBrowser" name="tbr_About">
<property name="documentTitle">
<string>About swift</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;title&gt;About swift&lt;/title&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.1pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8.25pt;&quot;&gt;Credits will go here&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>