Commit 23eba06c authored by Victor Yacovlev's avatar Victor Yacovlev

Help viewer: non-empty default start page

parent 9000785e
......@@ -10,6 +10,7 @@ typedef QSharedPointer<class DocBookModel> ModelPtr;
class ContentRenderer
{
public:
virtual bool isEmpty() const = 0;
virtual void reset() = 0;
virtual void renderData(ModelPtr data) = 0;
};
......
......@@ -39,12 +39,17 @@ void ContentView::reset()
clear();
}
bool ContentView::isEmpty() const
{
return toPlainText().trimmed().isEmpty();
}
void ContentView::renderData(ModelPtr data)
{
ModelPtr dataToRender = onePageParentModel(data);
if (dataToRender != loadedModel_) {
loadedModel_ = dataToRender;
const QString html = wrapHTML(render(dataToRender));
const QString html = wrapHTML(renderModel(dataToRender));
setHtml(html);
}
if (dataToRender != data) {
......@@ -112,6 +117,9 @@ QString ContentView::wrapHTML(const QString &body) const
" margin: 30;"
" font-style: italic;"
"}"
".subtitle {"
" font-size: " + MainFontSize + ";"
"}"
"body {"
" font-family: " + MainFontFamily + ";"
" font-size: " + MainFontSize + ";"
......@@ -132,10 +140,12 @@ QString ContentView::wrapHTML(const QString &body) const
"<body>\n" + body +"\n</body></html>";
}
QString ContentView::render(ModelPtr data) const
QString ContentView::renderModel(ModelPtr data) const
{
if (data->modelType() == DocBookModel::Set ||
data->modelType() == DocBookModel::Book)
if (data->modelType() == DocBookModel::Set) {
return renderSet(data);
}
else if (data->modelType() == DocBookModel::Book)
{
return renderTOC(data);
}
......@@ -1301,14 +1311,17 @@ QString ContentView::renderTOC(ModelPtr data) const
else
title = tr("List of algorithms of module \"%1\"").arg(data->title());
}
else if (data == DocBookModel::Book || data == DocBookModel::Article) {
title = data->title();
}
else {
title = sectionNumber(data) + "&nbsp;" + data->title();
}
result += "<h1 class='title' align='center'>" + normalizeText(title) + "</h1>\n";
if (data->subtitle().length() > 0) {
result += "<h1 class='subtitle' align='center'>" +
result += "<p class='subtitle' align='center'>" +
normalizeText(data->subtitle()) +
"</h1>\n";
"</p>\n";
}
result += "<hr/>\n";
foreach (ModelPtr child, data->children()) {
......@@ -1318,6 +1331,26 @@ QString ContentView::renderTOC(ModelPtr data) const
return result;
}
QString ContentView::renderSet(ModelPtr data) const
{
QString result;
const QString & title = data->title();
result += "<h1 class='title' align='center'>" + title + "</h1>\n";
foreach (ModelPtr child, data->children()) {
const quintptr dataPtr = quintptr(child.toWeakRef().data());
QByteArray buffer;
QDataStream ds(&buffer, QIODevice::WriteOnly);
ds << dataPtr;
const QString href = QString::fromAscii("model_ptr:") +
QString::fromAscii(buffer.toHex());
result += "<p align=\"left\"><a href=\"" + href +"\">" +
child->title() + "</a></p>\n";
result += "<p margin='10' align='left'>" + child->subtitle() + "</p>";
}
return result;
}
QString ContentView::renderTOCElement(ModelPtr data, quint8 level, bool enumerate) const
{
const quintptr dataPtr = quintptr(data.toWeakRef().data());
......
......@@ -20,7 +20,7 @@ class ContentView
Q_OBJECT
public:
explicit ContentView(QWidget * parent);
bool isEmpty() const;
void reset();
void renderData(ModelPtr data);
QSize minimumSizeHint() const;
......@@ -33,9 +33,9 @@ private:
void wheelEvent(QWheelEvent *e);
QString wrapHTML(const QString & body) const;
QString render(ModelPtr data) const;
QString renderModel(ModelPtr data) const;
QString renderElement(ModelPtr data) const;
QString renderSet(ModelPtr data) const;
QString renderChapter(ModelPtr data) const;
QString renderArticle(ModelPtr data) const;
QString renderAbstract(ModelPtr data) const;
......
......@@ -240,6 +240,9 @@ Document DocBookViewImpl::addDocument(const QUrl &url, QString *error, int index
DocBookFactory * factory = DocBookFactory::self();
Document doc = factory->parseDocument(url, error);
sidePanel_->addDocument(doc);
if (content_->isEmpty()) {
content_->renderData(doc.root_);
}
return doc;
}
......
......@@ -11,6 +11,16 @@ PrintRenderer::PrintRenderer()
baseFont_ = fontDatabase.font("serif", "regular", 12);
}
bool PrintRenderer::isEmpty() const
{
return pagesCount() == 0;
}
int PrintRenderer::pagesCount() const
{
return pages_.size();
}
PrintRenderer* PrintRenderer::self()
{
static PrintRenderer* instance = new PrintRenderer();
......
......@@ -15,6 +15,7 @@ class PrintRenderer
{
public:
static PrintRenderer* self();
bool isEmpty() const;
void reset();
void renderData(ModelPtr data);
void setBaseFont(QFont font);
......
......@@ -4,6 +4,7 @@
[]>
<book xmlns="http://www.oasis-open.org/docbook/xml/4.5/" xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Язык Кумир</title>
<subtitle>Описание русского алгоритмического языка программирования</subtitle>
<xi:include href="structure.xml"/>
<xi:include href="indentifiers.xml"/>
<xi:include href="simple_commands.xml"/>
......
<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookV4.5/docbookx.dtd" []>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []>
<book>
<title>Руководство пользователя</title>
<subtitle>Описание пользовательского интерфейса системы Кумир</subtitle>
<preface/>
<chapter>
<title>Обзор системы Кумир</title>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment