PDF export
This commit is contained in:
@@ -82,13 +82,13 @@ bool cBook::save()
|
||||
QByteArray ba;
|
||||
|
||||
if(description())
|
||||
ba = description()->toHtml().toUtf8();
|
||||
ba = shortDescription()->toHtml().toUtf8();
|
||||
else
|
||||
ba = QString("").toUtf8();
|
||||
query.bindValue(":shortDescription", qCompress(ba));
|
||||
|
||||
if(shortDescription())
|
||||
ba = shortDescription()->toHtml().toUtf8();
|
||||
ba = description()->toHtml().toUtf8();
|
||||
else
|
||||
ba = QString("").toUtf8();
|
||||
query.bindValue(":description", qCompress(ba));
|
||||
|
||||
+12
-13
@@ -227,29 +227,28 @@ QMap<QPagedPaintDevice::PageSize, QString> paperList()
|
||||
return(list);
|
||||
}
|
||||
|
||||
QString unitName(QPrinter::Unit unit)
|
||||
QString unitName(QPageLayout::Unit unit)
|
||||
{
|
||||
QMap<QPrinter::Unit, QString> list = unitList();
|
||||
QMap<QPageLayout::Unit, QString> list = unitList();
|
||||
return(list.value(unit));
|
||||
}
|
||||
|
||||
QPrinter::Unit unitKey(const QString& szUnit)
|
||||
QPageLayout::Unit unitKey(const QString& szUnit)
|
||||
{
|
||||
QMap<QPrinter::Unit, QString> list = unitList();
|
||||
QMap<QPageLayout::Unit, QString> list = unitList();
|
||||
return(list.key(szUnit));
|
||||
}
|
||||
|
||||
QMap<QPrinter::Unit, QString> unitList()
|
||||
QMap<QPageLayout::Unit, QString> unitList()
|
||||
{
|
||||
QMap<QPrinter::Unit, QString> list;
|
||||
QMap<QPageLayout::Unit, QString> list;
|
||||
|
||||
list.insert(QPrinter::Millimeter, QObject::tr("Millimeter"));
|
||||
list.insert(QPrinter::Point, QObject::tr("Point"));
|
||||
list.insert(QPrinter::Inch, QObject::tr("Inch"));
|
||||
list.insert(QPrinter::Pica, QObject::tr("Pica"));
|
||||
list.insert(QPrinter::Didot, QObject::tr("Didot"));
|
||||
list.insert(QPrinter::Cicero, QObject::tr("Cicero"));
|
||||
list.insert(QPrinter::DevicePixel, QObject::tr("DevicePixel"));
|
||||
list.insert(QPageLayout::Millimeter, QObject::tr("Millimeter"));
|
||||
list.insert(QPageLayout::Point, QObject::tr("Point"));
|
||||
list.insert(QPageLayout::Inch, QObject::tr("Inch"));
|
||||
list.insert(QPageLayout::Pica, QObject::tr("Pica"));
|
||||
list.insert(QPageLayout::Didot, QObject::tr("Didot"));
|
||||
list.insert(QPageLayout::Cicero, QObject::tr("Cicero"));
|
||||
|
||||
return(list);
|
||||
}
|
||||
|
||||
@@ -120,21 +120,21 @@ QMap<QPagedPaintDevice::PageSize, QString> paperList();
|
||||
\param unit
|
||||
\return QString
|
||||
*/
|
||||
QString unitName(QPrinter::Unit unit);
|
||||
QString unitName(QPageLayout::Unit unit);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn unitKey
|
||||
\param szUnit
|
||||
\return QPrinter::Unit
|
||||
\return QPageLayout::Unit
|
||||
*/
|
||||
QPrinter::Unit unitKey(const QString& szUnit);
|
||||
QPageLayout::Unit unitKey(const QString& szUnit);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn unitList
|
||||
\return QMap<QPrinter::Unit, QString>
|
||||
\return QMap<QPageLayout::Unit, QString>
|
||||
*/
|
||||
QMap<QPrinter::Unit, QString> unitList();
|
||||
QMap<QPageLayout::Unit, QString> unitList();
|
||||
|
||||
#endif // COMMON_H
|
||||
|
||||
@@ -21,8 +21,8 @@ cPropertiesWindow::cPropertiesWindow(QWidget *parent) :
|
||||
for(i = paperLst.begin();i != paperLst.end();i++)
|
||||
ui->m_lpPaperSize->addItem(i.value(), QVariant::fromValue((int)i.key()));
|
||||
|
||||
QMap<QPrinter::Unit, QString> unitLst = unitList();
|
||||
QMap<QPrinter::Unit, QString>::iterator iUnit;
|
||||
QMap<QPageLayout::Unit, QString> unitLst = unitList();
|
||||
QMap<QPageLayout::Unit, QString>::iterator iUnit;
|
||||
|
||||
for(iUnit = unitLst.begin();iUnit != unitLst.end();iUnit++)
|
||||
ui->m_lpUnit->addItem(iUnit.value(), QVariant::fromValue((int)iUnit.key()));
|
||||
|
||||
+80
-8
@@ -837,21 +837,93 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>m_lpTitle</tabstop>
|
||||
<tabstop>m_lpSubTitle</tabstop>
|
||||
<tabstop>m_lpAuthor</tabstop>
|
||||
<tabstop>m_lpStartedAt</tabstop>
|
||||
<tabstop>m_lpFinishedAt</tabstop>
|
||||
<tabstop>m_lpTargetDate</tabstop>
|
||||
<tabstop>m_lpShortDescription</tabstop>
|
||||
<tabstop>m_lpTitleFont</tabstop>
|
||||
<tabstop>m_lpTitleFontSize</tabstop>
|
||||
<tabstop>m_lpTitleBold</tabstop>
|
||||
<tabstop>m_lpTitleItalic</tabstop>
|
||||
<tabstop>m_lpTitleUnderline</tabstop>
|
||||
<tabstop>m_lpTitleLeft</tabstop>
|
||||
<tabstop>m_lpTitleCenter</tabstop>
|
||||
<tabstop>m_lpTitleRight</tabstop>
|
||||
<tabstop>m_lpSubtitleFont</tabstop>
|
||||
<tabstop>m_lpSubtitleFontSize</tabstop>
|
||||
<tabstop>m_lpSubtitleBold</tabstop>
|
||||
<tabstop>m_lpSubtitleItalic</tabstop>
|
||||
<tabstop>m_lpSubtitleUnderline</tabstop>
|
||||
<tabstop>m_lpSubtitleLeft</tabstop>
|
||||
<tabstop>m_lpSubtitleCenter</tabstop>
|
||||
<tabstop>m_lpSubtitleRight</tabstop>
|
||||
<tabstop>m_lpAuthorFont</tabstop>
|
||||
<tabstop>m_lpAuthorFontSize</tabstop>
|
||||
<tabstop>m_lpAuthorBold</tabstop>
|
||||
<tabstop>m_lpAuthorItalic</tabstop>
|
||||
<tabstop>m_lpAuthorUnderline</tabstop>
|
||||
<tabstop>m_lpAuthorLeft</tabstop>
|
||||
<tabstop>m_lpAuthorCenter</tabstop>
|
||||
<tabstop>m_lpAuthorRight</tabstop>
|
||||
<tabstop>m_lpPartNameFont</tabstop>
|
||||
<tabstop>m_lpPartNameFontSize</tabstop>
|
||||
<tabstop>m_lpPartNameBold</tabstop>
|
||||
<tabstop>m_lpPartNameItalic</tabstop>
|
||||
<tabstop>m_lpPartNameUnderline</tabstop>
|
||||
<tabstop>m_lpPartNameLeft</tabstop>
|
||||
<tabstop>m_lpPartNameCenter</tabstop>
|
||||
<tabstop>m_lpPartNameRight</tabstop>
|
||||
<tabstop>m_lpChapterNameFont</tabstop>
|
||||
<tabstop>m_lpChapterNameFontSize</tabstop>
|
||||
<tabstop>m_lpChapterNameBold</tabstop>
|
||||
<tabstop>m_lpChapterNameItalic</tabstop>
|
||||
<tabstop>m_lpChapterNameUnderline</tabstop>
|
||||
<tabstop>m_lpChapterNameLeft</tabstop>
|
||||
<tabstop>m_lpChapterNameCenter</tabstop>
|
||||
<tabstop>m_lpChapterNameRight</tabstop>
|
||||
<tabstop>m_lpSceneNameFont</tabstop>
|
||||
<tabstop>m_lpSceneNameFontSize</tabstop>
|
||||
<tabstop>m_lpSceneNameBold</tabstop>
|
||||
<tabstop>m_lpSceneNameItalic</tabstop>
|
||||
<tabstop>m_lpSceneNameUnderline</tabstop>
|
||||
<tabstop>m_lpSceneNameLeft</tabstop>
|
||||
<tabstop>m_lpSceneNameCenter</tabstop>
|
||||
<tabstop>m_lpSceneNameRight</tabstop>
|
||||
<tabstop>m_lpPaperSize</tabstop>
|
||||
<tabstop>m_lpOrientationPortrait</tabstop>
|
||||
<tabstop>m_lpOrientationLandscape</tabstop>
|
||||
<tabstop>m_lpUnit</tabstop>
|
||||
<tabstop>m_lpMarginLeft</tabstop>
|
||||
<tabstop>m_lpMarginRight</tabstop>
|
||||
<tabstop>m_lpMarginTop</tabstop>
|
||||
<tabstop>m_lpMarginBottom</tabstop>
|
||||
<tabstop>m_lpDescription</tabstop>
|
||||
<tabstop>m_lpPrintPartText</tabstop>
|
||||
<tabstop>m_lpPrintShortDescription</tabstop>
|
||||
<tabstop>m_lpPrintPartDescription</tabstop>
|
||||
<tabstop>m_lpPrintChapterText</tabstop>
|
||||
<tabstop>m_lpPrintDescription</tabstop>
|
||||
<tabstop>m_lpPrintAuthor</tabstop>
|
||||
<tabstop>m_lpPrintSceneDescription</tabstop>
|
||||
<tabstop>m_lpAuthor</tabstop>
|
||||
<tabstop>m_lpPrintChapterDescription</tabstop>
|
||||
<tabstop>m_lpPrintPartName</tabstop>
|
||||
<tabstop>m_lpStartedAt</tabstop>
|
||||
<tabstop>m_lpPrintSubtitle</tabstop>
|
||||
<tabstop>m_lpPrintSceneName</tabstop>
|
||||
<tabstop>m_lpFinishedAt</tabstop>
|
||||
<tabstop>scrollArea</tabstop>
|
||||
<tabstop>m_lpSubTitle</tabstop>
|
||||
<tabstop>m_lpPrintSceneText</tabstop>
|
||||
<tabstop>m_lpShortDescription</tabstop>
|
||||
<tabstop>m_lpTitle</tabstop>
|
||||
<tabstop>m_lpPrintChapterName</tabstop>
|
||||
<tabstop>m_lpPrintTitle</tabstop>
|
||||
<tabstop>m_lpTargetDate</tabstop>
|
||||
<tabstop>m_lpTab</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="m_lpOrientation"/>
|
||||
<buttongroup name="m_lpTitleAlign"/>
|
||||
<buttongroup name="m_lpSubtitleAlign"/>
|
||||
<buttongroup name="m_lpOrientation"/>
|
||||
<buttongroup name="m_lpAuthorAlign"/>
|
||||
<buttongroup name="m_lpPartAlign"/>
|
||||
<buttongroup name="m_lpSceneAlign"/>
|
||||
|
||||
+109
-9
@@ -24,6 +24,10 @@
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QMarginsF>
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
#include <QPrinter>
|
||||
#endif
|
||||
@@ -89,7 +93,7 @@ cStoryBook::cStoryBook(QObject *parent) :
|
||||
m_dRightMargin(10),
|
||||
m_dTopMargin(10),
|
||||
m_dBottomMargin(10),
|
||||
m_iUnit(QPrinter::Millimeter)
|
||||
m_iUnit(QPageLayout::Millimeter)
|
||||
{
|
||||
m_book.setTitle("untitled");
|
||||
m_bIsOpen = true;
|
||||
@@ -225,9 +229,13 @@ bool cStoryBook::printPdf(const QString& szFileName)
|
||||
QPrinter printer(QPrinter::PrinterResolution);
|
||||
|
||||
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||
printer.setPaperSize(QPrinter::A4);
|
||||
printer.setOutputFileName(szFileName);
|
||||
|
||||
return(printDocument(printer));
|
||||
}
|
||||
|
||||
bool cStoryBook::printDocument(QPrinter& printer)
|
||||
{
|
||||
// QMap<qint32, QStandardItem*> part;
|
||||
// QMap<qint32, QStandardItem*> chapter;
|
||||
// QStandardItemModel* lpModel = (QStandardItemModel*)lpView->model();
|
||||
@@ -282,20 +290,112 @@ bool cStoryBook::printPdf(const QString& szFileName)
|
||||
// }
|
||||
// }
|
||||
|
||||
configPrinter(printer);
|
||||
|
||||
QTextDocument doc;
|
||||
QTextCursor cursor(&doc);
|
||||
bool bNewPage = false;
|
||||
|
||||
if(printTitle())
|
||||
{
|
||||
printBlock(cursor, title(), titleFont(), titleFontSize(), titleAlign(), titleBold(), titleItalic(), titleUnderline());
|
||||
bNewPage = true;
|
||||
}
|
||||
|
||||
if(printSubTitle())
|
||||
{
|
||||
printBlock(cursor, m_book.subTitle(), subtitleFont(), subtitleFontSize(), subtitleAlign(), subtitleBold(), subtitleItalic(), subtitleUnderline());
|
||||
bNewPage = true;
|
||||
}
|
||||
|
||||
if(printShortDescription())
|
||||
{
|
||||
cursor.insertHtml(m_book.shortDescription()->toHtml() + "<br>");
|
||||
bNewPage = true;
|
||||
}
|
||||
|
||||
if(printDescription())
|
||||
{
|
||||
cursor.insertHtml(m_book.description()->toHtml());
|
||||
bNewPage = true;
|
||||
}
|
||||
|
||||
if(bNewPage)
|
||||
{
|
||||
QTextBlockFormat blockFormat;
|
||||
blockFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
|
||||
cursor.insertBlock(blockFormat);
|
||||
}
|
||||
|
||||
for(int x = 0;x < m_sceneList.count();x++)
|
||||
{
|
||||
cScene* lpScene = m_sceneList.at(x);
|
||||
if(x)
|
||||
{
|
||||
QTextBlockFormat blockFormat;
|
||||
blockFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
|
||||
cursor.insertBlock(blockFormat);
|
||||
}
|
||||
|
||||
cScene* lpScene = m_sceneList.at(x);
|
||||
|
||||
if(lpScene->deleted())
|
||||
continue;
|
||||
|
||||
lpScene->text()->setPageSize(printer.pageRect().size());
|
||||
lpScene->text()->print(&printer);
|
||||
cursor.insertHtml(lpScene->text()->toHtml());
|
||||
}
|
||||
|
||||
doc.setPageSize(printer.pageRect().size());
|
||||
doc.print(&printer);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void cStoryBook::configPrinter(QPrinter& printer)
|
||||
{
|
||||
printer.setPaperSize(paperSize());
|
||||
printer.setOrientation(paperOrientation());
|
||||
|
||||
QMarginsF marginsF(leftMargin(), topMargin(), rightMargin(), bottomMargin());
|
||||
printer.setPageMargins(marginsF, unit());
|
||||
}
|
||||
|
||||
void cStoryBook::printBlock(QTextCursor& cursor, const QString& szText, const QString& szFont, const qint16& iFontSize, const ALIGN align, const bool& bold, const bool& italic, const bool& underline)
|
||||
{
|
||||
QString szHTML("");
|
||||
szHTML.append(QString("<p style=\"font-family:'%1'; font-size:%2px").arg(szFont).arg(iFontSize));
|
||||
|
||||
switch(align)
|
||||
{
|
||||
case ALIGN::ALIGN_left:
|
||||
szHTML.append("; text-align: left");
|
||||
break;
|
||||
case ALIGN::ALIGN_right:
|
||||
szHTML.append("; text-align: right");
|
||||
break;
|
||||
case ALIGN::ALIGN_center:
|
||||
szHTML.append("; text-align: center");
|
||||
break;
|
||||
case ALIGN::ALIGN_block:
|
||||
szHTML.append("; text-align: justify");
|
||||
break;
|
||||
}
|
||||
|
||||
if(bold)
|
||||
szHTML.append("; font-weight: bold");
|
||||
|
||||
if(italic)
|
||||
szHTML.append("; font-style:italic");
|
||||
|
||||
if(underline)
|
||||
szHTML.append("; text-decoration: underline");
|
||||
|
||||
szHTML.append("\">");
|
||||
szHTML.append(szText);
|
||||
szHTML.append("<br></p>");
|
||||
|
||||
cursor.insertHtml(szHTML);
|
||||
}
|
||||
|
||||
bool cStoryBook::openDatabase()
|
||||
{
|
||||
m_db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
@@ -472,7 +572,7 @@ bool cStoryBook::createDatabase()
|
||||
query.bindValue(":rightMargin", 10);
|
||||
query.bindValue(":topMargin", 10);
|
||||
query.bindValue(":bottomMargin", 10);
|
||||
query.bindValue(":unit", QPrinter::Millimeter);
|
||||
query.bindValue(":unit", QPageLayout::Millimeter);
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
@@ -741,7 +841,7 @@ bool cStoryBook::loadConfig()
|
||||
m_dRightMargin = query.value("rightMargin").toDouble();
|
||||
m_dTopMargin = query.value("topMargin").toDouble();
|
||||
m_dBottomMargin = query.value("bottomMargin").toDouble();
|
||||
m_iUnit = (QPrinter::Unit)query.value("unit").toInt();
|
||||
m_iUnit = (QPageLayout::Unit)query.value("unit").toInt();
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -1940,12 +2040,12 @@ void cStoryBook::setBottomMargin(const qreal& value)
|
||||
m_dBottomMargin = value;
|
||||
}
|
||||
|
||||
QPrinter::Unit cStoryBook::unit()
|
||||
QPageLayout::Unit cStoryBook::unit()
|
||||
{
|
||||
return(m_iUnit);
|
||||
}
|
||||
|
||||
void cStoryBook::setUnit(const QPrinter::Unit& value)
|
||||
void cStoryBook::setUnit(const QPageLayout::Unit& value)
|
||||
{
|
||||
m_iUnit = value;
|
||||
}
|
||||
|
||||
+28
-4
@@ -1164,16 +1164,16 @@ public:
|
||||
\brief
|
||||
|
||||
\fn unit
|
||||
\return QPrinter::Unit
|
||||
\return QPageLayout::Unit
|
||||
*/
|
||||
QPrinter::Unit unit();
|
||||
QPageLayout::Unit unit();
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn setUnit
|
||||
\param value
|
||||
*/
|
||||
void setUnit(const QPrinter::Unit& value);
|
||||
void setUnit(const QPageLayout::Unit& value);
|
||||
|
||||
private:
|
||||
QString m_szProject; /*!< TODO: describe */
|
||||
@@ -1244,7 +1244,7 @@ private:
|
||||
qreal m_dRightMargin; /*!< TODO: describe */
|
||||
qreal m_dTopMargin; /*!< TODO: describe */
|
||||
qreal m_dBottomMargin; /*!< TODO: describe */
|
||||
QPrinter::Unit m_iUnit; /*!< TODO: describe */
|
||||
QPageLayout::Unit m_iUnit; /*!< TODO: describe */
|
||||
|
||||
/*!
|
||||
\brief
|
||||
@@ -1405,6 +1405,30 @@ private:
|
||||
\return bool
|
||||
*/
|
||||
bool saveImageList();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn printDocument
|
||||
\param printer
|
||||
\return bool
|
||||
*/
|
||||
bool printDocument(QPrinter &printer);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn configPrinter
|
||||
\param printer
|
||||
*/
|
||||
void configPrinter(QPrinter &printer);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn configPrinter
|
||||
\param printer
|
||||
*/
|
||||
void printBlock(QTextCursor& cursor, const QString& szText, const QString& szFont, const qint16& iFontSize, const ALIGN align, const bool& bold, const bool& italic, const bool& underline);
|
||||
};
|
||||
|
||||
#endif // CSTORYBOOK_H
|
||||
|
||||
Reference in New Issue
Block a user