diff --git a/cbook.cpp b/cbook.cpp index 0def9b1..d49f3dd 100644 --- a/cbook.cpp +++ b/cbook.cpp @@ -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)); diff --git a/common.cpp b/common.cpp index 0968bb7..4bbd5b5 100644 --- a/common.cpp +++ b/common.cpp @@ -227,29 +227,28 @@ QMap paperList() return(list); } -QString unitName(QPrinter::Unit unit) +QString unitName(QPageLayout::Unit unit) { - QMap list = unitList(); + QMap list = unitList(); return(list.value(unit)); } -QPrinter::Unit unitKey(const QString& szUnit) +QPageLayout::Unit unitKey(const QString& szUnit) { - QMap list = unitList(); + QMap list = unitList(); return(list.key(szUnit)); } -QMap unitList() +QMap unitList() { - QMap list; + QMap 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); } diff --git a/common.h b/common.h index 50d7c64..5ca9da1 100644 --- a/common.h +++ b/common.h @@ -120,21 +120,21 @@ QMap 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 + \return QMap */ -QMap unitList(); +QMap unitList(); #endif // COMMON_H diff --git a/cpropertieswindow.cpp b/cpropertieswindow.cpp index ce7165a..9792440 100644 --- a/cpropertieswindow.cpp +++ b/cpropertieswindow.cpp @@ -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 unitLst = unitList(); - QMap::iterator iUnit; + QMap unitLst = unitList(); + QMap::iterator iUnit; for(iUnit = unitLst.begin();iUnit != unitLst.end();iUnit++) ui->m_lpUnit->addItem(iUnit.value(), QVariant::fromValue((int)iUnit.key())); diff --git a/cpropertieswindow.ui b/cpropertieswindow.ui index 7063dcc..dac8d5f 100644 --- a/cpropertieswindow.ui +++ b/cpropertieswindow.ui @@ -837,21 +837,93 @@ - m_lpTitle - m_lpSubTitle - m_lpAuthor - m_lpStartedAt - m_lpFinishedAt - m_lpTargetDate - m_lpShortDescription + m_lpTitleFont + m_lpTitleFontSize + m_lpTitleBold + m_lpTitleItalic + m_lpTitleUnderline + m_lpTitleLeft + m_lpTitleCenter + m_lpTitleRight + m_lpSubtitleFont + m_lpSubtitleFontSize + m_lpSubtitleBold + m_lpSubtitleItalic + m_lpSubtitleUnderline + m_lpSubtitleLeft + m_lpSubtitleCenter + m_lpSubtitleRight + m_lpAuthorFont + m_lpAuthorFontSize + m_lpAuthorBold + m_lpAuthorItalic + m_lpAuthorUnderline + m_lpAuthorLeft + m_lpAuthorCenter + m_lpAuthorRight + m_lpPartNameFont + m_lpPartNameFontSize + m_lpPartNameBold + m_lpPartNameItalic + m_lpPartNameUnderline + m_lpPartNameLeft + m_lpPartNameCenter + m_lpPartNameRight + m_lpChapterNameFont + m_lpChapterNameFontSize + m_lpChapterNameBold + m_lpChapterNameItalic + m_lpChapterNameUnderline + m_lpChapterNameLeft + m_lpChapterNameCenter + m_lpChapterNameRight + m_lpSceneNameFont + m_lpSceneNameFontSize + m_lpSceneNameBold + m_lpSceneNameItalic + m_lpSceneNameUnderline + m_lpSceneNameLeft + m_lpSceneNameCenter + m_lpSceneNameRight + m_lpPaperSize + m_lpOrientationPortrait + m_lpOrientationLandscape + m_lpUnit + m_lpMarginLeft + m_lpMarginRight + m_lpMarginTop + m_lpMarginBottom m_lpDescription + m_lpPrintPartText + m_lpPrintShortDescription + m_lpPrintPartDescription + m_lpPrintChapterText + m_lpPrintDescription + m_lpPrintAuthor + m_lpPrintSceneDescription + m_lpAuthor + m_lpPrintChapterDescription + m_lpPrintPartName + m_lpStartedAt + m_lpPrintSubtitle + m_lpPrintSceneName + m_lpFinishedAt + scrollArea + m_lpSubTitle + m_lpPrintSceneText + m_lpShortDescription + m_lpTitle + m_lpPrintChapterName + m_lpPrintTitle + m_lpTargetDate + m_lpTab - + diff --git a/cstorybook.cpp b/cstorybook.cpp index ad761df..b2e8585 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -24,6 +24,10 @@ #include +#include +#include +#include + #ifndef QT_NO_PRINTER #include #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 part; // QMap 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() + "
"); + 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("

"); + szHTML.append(szText); + szHTML.append("

"); + + 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; } diff --git a/cstorybook.h b/cstorybook.h index bd429d6..f5c7ff4 100644 --- a/cstorybook.h +++ b/cstorybook.h @@ -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 diff --git a/main.cpp b/main.cpp index 7084722..80b9f8d 100644 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,7 @@ #include "csplashscreen.h" -#define SHOW_SPLASH +//#define SHOW_SPLASH int main(int argc, char *argv[])