Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
#
# $Id$
# $HeadURL$
# $Author$
#
# Created by Christian Ehrlicher, SLSE, 2017-12-05
#
FIND_PACKAGE(KDReports REQUIRED)
SET(SRCS
printing_base.cpp
printing_base.h
printing.cpp
printing.h
)
NGL_ADD_LIBRARY(WS LtsPrinting SHARED ${SRCS})
NGL_TARGET_INCLUDE_DIRECTORIES(LtsPrinting
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(LtsPrinting
PRIVATE
KDReports::KDReports
LtsSessionData
LtsSession
nglsettings
ngltools
PUBLIC
Qt5::PrintSupport
Qt5::Core
)
NGL_INSTALL_TARGET(LtsPrinting)
+444
View File
@@ -0,0 +1,444 @@
/**
* Printing helper functions
* $Id$
* $HeadURL$
* $Author$
*
* Created by Christian Ehrlicher, SLSE, 2017-12-05
*/
#include "printing.h"
#include "printing_base.h"
#include <LtsSession/lts_session.h>
#include <LtsSession/lts_session_data.h>
#include <LtsWidgets/lts_base_layout_widget.h>
#include <KDReports/KDReportsReport>
#include <QString>
#include <QTableView>
#include <QTreeView>
#include <QListView>
#include <QAbstractItemModel>
#include <QImage>
#include <QTextDocument>
#include <QTextCursor>
#include <QPrinter>
#include <QPainter>
#include <QPrintDialog>
#include <QTableWidget>
#include <QLabel>
#include <QTextTable>
#include <QDebug>
#include <QTextEdit>
namespace LtsPrinting
{
/**
* check if any item has children.
* @param view Address of the view to be checked if any items have children
*/
// -----------------------------------------------------------------------------
bool itemsHaveNoChildren(const QTreeView *view)
{
const QAbstractItemModel *itemModel = view->model();
int rowCount = itemModel->rowCount();
for (int row = 0; row < rowCount; ++row)
{
if (itemModel->hasChildren(itemModel->index(row, 0)))
return false;
}
return true;
}
/**
* Set name of operator and exercise for printing
* @param session Address of session to access exercise data
* @param nglPrinter Printer used for settings
*/
// -----------------------------------------------------------------------------
void setNameOfExerciseAndOperator(LtsSession::LtsSession *session, LtsPrinting::Base &nglPrinter)
{
if ( session->exerciseId() != 0 )
nglPrinter.setCurrentExerciseName(QObject::tr("Exercise: %1 %2").arg(session->exerciseData()->exName,
session->exerciseData()->phName));
else
nglPrinter.setCurrentExerciseName(QObject::tr("Exercise: Administration") );
LtsSessionData::LtsSessionData *sessionData = LtsSessionData::LtsSessionData::getInstance();
nglPrinter.setOperatorName(sessionData->getOperatorName());
}
// -----------------------------------------------------------------------------
void printView(LtsSession::LtsSession *session,
QWidget *dialogParent,
const QAbstractItemView *view,
const QString& headingHtml)
{
const QTableView *tableView = dynamic_cast<const QTableView *>(view);
const QTreeView *treeView = dynamic_cast<const QTreeView *>(view);
QSet<int> hiddenCols;
int switchNum = 0;
if (tableView != nullptr)
{
switchNum = 1;
hiddenCols = LtsPrinting::Base::getHiddenCols(tableView);
}
else if (treeView != nullptr)
{
switchNum = 2;
hiddenCols = LtsPrinting::Base::getHiddenCols(treeView);
if (itemsHaveNoChildren(treeView)) switchNum = 1; // print tree view as table
}
else if (dynamic_cast<const QListView *>(view) != nullptr)
switchNum = 3;
else
{
return; // not print function available for the view
}
QTextDocument doc;
QTextCursor cursor(&doc);
doc.setMetaInformation(QTextDocument::DocumentTitle, dialogParent->windowTitle());
LtsPrinting::Base nglPrinter(doc, dialogParent,
QObject::tr("Print %1").arg(dialogParent->windowTitle()),
dialogParent->windowTitle(), // use title for file name
QPrinter::A4, QPrinter::Landscape);
if (!nglPrinter.printer())
return;
setNameOfExerciseAndOperator(session, nglPrinter);
cursor.movePosition(QTextCursor::End);
QString htmlStr;
switch (switchNum)
{
case 1:
nglPrinter.printTableData(htmlStr, view, QString(), hiddenCols); // QTableView
break;
case 2:
nglPrinter.printTreeData(htmlStr, view, QString(), hiddenCols); // QTreeView
break;
case 3:
nglPrinter.printListData(htmlStr, view, QString()); // QListView
break;
}
cursor.insertHtml(headingHtml);
cursor.insertHtml(htmlStr);
nglPrinter.print(&doc);
}
// -----------------------------------------------------------------------------
void printView(LtsSession::LtsSession *session,
QWidget *dialogParent,
QAbstractItemView *view,
const QString& headingHtml)
{
const QAbstractItemView *itemView = static_cast<const QAbstractItemView *>(view);
printView(session, dialogParent, itemView, headingHtml);
}
// ---------------------------------------------------------------------------
void printImage(LtsSession::LtsSession *session, QWidget *dialogParent,
const QImage &image, const QString &imageTitle, const QString &description,
const QPrinter::PageSize &pageSize, const QPrinter::Orientation &pageOrientation)
{
QTextDocument doc;
QTextCursor cursor(&doc);
QString windowTitle = dialogParent->windowTitle();
doc.setMetaInformation(QTextDocument::DocumentTitle, dialogParent->windowTitle());
LtsPrinting::Base nglPrinter(doc, dialogParent,
QObject::tr("Print %1").arg(windowTitle),
windowTitle, // use title for file name
pageSize, pageOrientation);
if (!nglPrinter.printer())
return;
setNameOfExerciseAndOperator(session, nglPrinter);
cursor.movePosition(QTextCursor::End);
nglPrinter.printDocImage(doc, image, imageTitle, description);
nglPrinter.print(&doc);
}
// ---------------------------------------------------------------------------
void printImages(LtsSession::LtsSession *session, QWidget *dialogParent,
const QString &docName, QVector<QImage> &images,
QVector<QString> &imageTitles, QVector<QString> &descriptions,
const QPrinter::PageSize &pageSize, const QPrinter::Orientation &pageOrientation)
{
QTextDocument doc;
QTextCursor cursor(&doc);
doc.setMetaInformation(QTextDocument::DocumentTitle, docName);
LtsPrinting::Base nglPrinter(doc, dialogParent,
QObject::tr("Print %1").arg(docName),
docName, pageSize, pageOrientation);
if (!nglPrinter.printer())
return;
setNameOfExerciseAndOperator(session, nglPrinter);
cursor.movePosition(QTextCursor::End);
for ( int i = 0; i < images.size(); i++)
{
QString imageTitle, imageDescription;
if (imageTitles.size() > i && imageTitles[i].size() > 0)
imageTitle = imageTitles[i];
if (descriptions.size() > i && descriptions[i].size() > 0)
imageDescription = descriptions[i];
nglPrinter.printDocImage(doc, images[i], imageTitle, imageDescription);
nglPrinter.printSinglePage(&doc);
doc.clear();
if (i != images.size() -1) // don't append empty page if at end
nglPrinter.newPage();
//qCritical() << "FALSE nglPrinter.newPage";
}
nglPrinter.printDone();
}
// ---------------------------------------------------------------------------
void printPDFImages(QWidget *dialogParent, const QString &docName, const QString &printPath, QVector<QImage> &images)
{
QPrinter printer;
printer.setColorMode(QPrinter::ColorMode::Color);
printer.setOrientation(QPrinter::Orientation::Portrait);
printer.setPageSize(QPrinter::PageSize::A4);
QString fn = docName;
fn = fn.remove(QLatin1Char(' '));
fn = fn.remove(QLatin1String(".."));
fn = fn.remove(QLatin1Char('/'));
fn = printPath + fn;
if (!fn.endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive))
fn += QLatin1String(".pdf");
#ifndef WIN32
printer.setOutputFileName(fn);
#endif
printer.setOutputFormat(QPrinter::NativeFormat);
QPrintDialog *dialog = new QPrintDialog(&printer, dialogParent);
dialog->setWindowTitle(QObject::tr("Print %1").arg(docName));
if (dialog->exec() != QDialog::Accepted)
return;
QPainter painter;
painter.begin(&printer);
int lastItem = images.size() - 1;
for (int i = 0; i < images.size(); ++i)
{
QRect rect = painter.viewport();
QSize size = images.at(i).size();
size.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(),
size.width(), size.height());
painter.setWindow(images.at(i).rect());
painter.drawImage(0, 0, images.at(i));
if (i != lastItem)
printer.newPage();
}
painter.end();
}
// not used in Reports anymore, as it fits only text reports. used instead KDReports::PreviewDialog
// still used in Codification table
// ---------------------------------------------------------------------------
void printReport( LtsSession::LtsSession *session, QWidget *dialogParent, KDReports::Report& report )
{
QTextDocument doc;
QTextCursor cursor(&doc);
doc.setMetaInformation(QTextDocument::DocumentTitle, dialogParent->windowTitle());
LtsPrinting::Base nglPrinter(doc, dialogParent,
QObject::tr("Print %1").arg(dialogParent->windowTitle()),
dialogParent->windowTitle(), // use title for file name
QPrinter::A3, QPrinter::Landscape);
if (!nglPrinter.printer())
return;
setNameOfExerciseAndOperator( session, nglPrinter );
cursor.movePosition(QTextCursor::End);
report.setWidthForEndlessPrinter(0);
report.setPageSize(QPrinter::A3);
report.setOrientation(QPrinter::Landscape);
LtsPrinting::Base::printReportData(doc, report);
nglPrinter.print(&doc);
}
// ---------------------------------------------------------------------------
void printWidget(LtsSession::LtsSession *session, QWidget *dialogParent, QWidget *widget, const QString &title)
{
QTextDocument doc;
QTextCursor cursor(&doc);
QImage image(widget->size(), QImage::Format_ARGB32);
widget->render(&image);
QString windowTitle = dialogParent->windowTitle();
doc.setMetaInformation(QTextDocument::DocumentTitle, dialogParent->windowTitle());
LtsPrinting::Base nglPrinter(doc, dialogParent,
QObject::tr("Print %1").arg(windowTitle),
windowTitle, // use title for file name
QPrinter::A3, QPrinter::Landscape);
if (!nglPrinter.printer())
return;
setNameOfExerciseAndOperator(session, nglPrinter);
cursor.movePosition(QTextCursor::End);
nglPrinter.printDocImage(doc, image, title);
nglPrinter.print(&doc);
}
void printMessage(LtsSession::LtsSession *session,
QWidget *dialogParent,
const QString &subject, const QString &subjectContent,
const QString &from, const QString &fromContent,
const QString &to, const QString &toContent,
const QString &msgTextContent,
const QString &time, const QString &timeContent)
{
QTextDocument doc;
QString windowTitle = subject;
doc.setMetaInformation(QTextDocument::DocumentTitle, subject);
LtsPrinting::Base nglPrinter(doc, dialogParent,
QObject::tr("Print %1").arg(windowTitle),
windowTitle, // use title for file name
QPrinter::A4, QPrinter::Portrait);
QString str = QString(QStringLiteral("<H2><strong>%1</strong> %2 </H2>")).arg(subject).arg(subjectContent);
str.append( QString(QStringLiteral("<strong>%1</strong> %2<br>")).arg(time).arg(timeContent));
str.append( QString(QStringLiteral("<strong>%1</strong> %2<br>")).arg(from).arg(fromContent));
str.append( QString(QStringLiteral("<strong>%1</strong> %2<hr>")).arg(to).arg(toContent));
str.append( QString(QStringLiteral("%1")).arg(msgTextContent));
doc.setHtml(str);
if (!nglPrinter.printer())
return;
setNameOfExerciseAndOperator(session, nglPrinter);
nglPrinter.print(&doc);
}
/*!
\brief Method to print the QTableWidget with QLabel of StoryboardDialog in SkriptEditor
\details Iterate through all rows and columns and convert the QTableWidget to a HTML table
\details Each line in QTableWidgetCell get an seperate cell in HTML. Included page breaks after the size of the document is bigger than the contentRect in \class printing_base.cpp
!*/
void printStoryboard(LtsSession::LtsSession *session, QWidget *dialogParent, QAbstractItemView *view, const QString &headingHtml)
{
QTableWidget *tbl = dynamic_cast< QTableWidget *>(view);
QTextDocument doc;
QTextCursor cursor(&doc);
QTextBlockFormat tbfFormat;
tbfFormat.setPageBreakPolicy(QTextFormat::PageBreakFlag::PageBreak_Auto);
QString windowTitle = dialogParent->windowTitle();
doc.setMetaInformation(QTextDocument::DocumentTitle, dialogParent->windowTitle());
LtsPrinting::Base nglPrinter(doc, dialogParent,
QObject::tr("Print %1").arg(windowTitle),
windowTitle,
QPrinter::A4, QPrinter::Portrait);
if (!nglPrinter.printer())
return;
const int rows = tbl->rowCount();
cursor.insertHtml(headingHtml);
double currentHeight = 0;
double previousPagesHeight = 0;
QString htmlStr;
for (int rowCounter = 0; rowCounter < rows; rowCounter++)
{
htmlStr.append(QStringLiteral("<table>"));
QTextEdit *labelForFirstCell = (QTextEdit*)tbl->cellWidget(rowCounter, 0);
QString stringFirstColumn = labelForFirstCell->toHtml();
QTextEdit *labelSecondColumn = (QTextEdit*)tbl->cellWidget(rowCounter, 1);
QString stringSecondColumn = labelSecondColumn->toHtml();
QTextEdit *labelThirdColumn = (QTextEdit*)tbl->cellWidget(rowCounter, 2);
QString stringThirdColumn = labelThirdColumn->toHtml();
for (int rowInCellCounter = 0; rowInCellCounter < stringSecondColumn.split(QStringLiteral("<br>")).size(); ++rowInCellCounter)
{
htmlStr.append(QStringLiteral("<tr>"));
if (rowInCellCounter < stringFirstColumn.split(QStringLiteral("<br>")).size())
{
htmlStr.append(QStringLiteral("<td width = \"25%\">"));
htmlStr.append(stringFirstColumn.split(QStringLiteral("<br>"))[rowInCellCounter]);
htmlStr.append(QStringLiteral("</td>"));
}
else
{
htmlStr.append(QStringLiteral("<td width = \"25%\"> "));
htmlStr.append(QStringLiteral("</td>"));
}
QString currentTextSecond = stringSecondColumn.split(QStringLiteral("<br>"))[rowInCellCounter];
htmlStr.append(QStringLiteral("<td width = \"37%\">"));
htmlStr.append(currentTextSecond);
htmlStr.append(QStringLiteral("</td>"));
QString currentTextThird = stringThirdColumn.split(QStringLiteral("<br>"))[rowInCellCounter];
htmlStr.append(QStringLiteral("<td width = \"37%\">"));
htmlStr.append(currentTextThird);
htmlStr.append(QStringLiteral("</td>"));
htmlStr.append(QStringLiteral("</tr>"));
}
QTextDocument tempDoc; // Hold the size of the next Topic
tempDoc.setPageSize(doc.pageSize());
tempDoc.setHtml(htmlStr);
currentHeight = doc.size().height() - previousPagesHeight;
if (currentHeight + tempDoc.size().height() > nglPrinter.pageSizeInMM().height()) //Compares the current height + the height of the next object with page height
{
tbfFormat.setPageBreakPolicy(QTextFormat::PageBreakFlag::PageBreak_AlwaysBefore);
cursor.insertBlock(tbfFormat); //Force the page break with that
previousPagesHeight = doc.size().height();
currentHeight = doc.size().height() - previousPagesHeight;
}
else
{
tbfFormat.setPageBreakPolicy(QTextFormat::PageBreakFlag::PageBreak_Auto);
currentHeight = doc.size().height() - previousPagesHeight;
}
cursor.insertHtml(htmlStr);
htmlStr.clear();
}
htmlStr.append(QStringLiteral("</table>"));
cursor.insertHtml(htmlStr);
cursor.movePosition(QTextCursor::End);
setNameOfExerciseAndOperator(session, nglPrinter);
nglPrinter.print(&doc);
}
}
+143
View File
@@ -0,0 +1,143 @@
/**
* Printing helper functions
* $Id$
* $HeadURL$
* $Author$
*
* Created by Christian Ehrlicher, SLSE, 2017-12-05
*/
#pragma once
#include <QtPrintSupport/QPrinter>
#ifndef LTSPRINTING_EXPORT
# ifdef BUILD_STATIC_LIBRARIES
# define LTSPRINTING_EXPORT
# else
# if defined(MAKE_LTSPRINTING_LIB)
# define LTSPRINTING_EXPORT Q_DECL_EXPORT
# else
# define LTSPRINTING_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
class QWidget;
class QAbstractItemView;
class QImage;
namespace LtsSession
{
class LtsSession;
}
namespace KDReports
{
class Report;
}
namespace LtsPrinting
{
/**
* print view as table or tree, depending on view type.
* @param session Address of session to access exercise data
* @param dialogParent Address of dialog parent window
* @param view Address of the view to be printed
* @param headingHtml HTML content html content that is inserted as a header in front of the widget content. It is not the header bar, but a header of the content
*/
LTSPRINTING_EXPORT void printView(LtsSession::LtsSession *session,
QWidget *dialogParent,
const QAbstractItemView *view,
const QString &headingHtml = QString());
LTSPRINTING_EXPORT void printView(LtsSession::LtsSession *session,
QWidget *dialogParent,
QAbstractItemView *view,
const QString &headingHtml = QString());
LTSPRINTING_EXPORT void printStoryboard(LtsSession::LtsSession *session,
QWidget *dialogParent,
QAbstractItemView *view,
const QString &headingHtml = QString());
/**
* Print Image.
* @param session Address of session to access exercise data
* @param dialogParent Address of dialog parent window
* @param image Image of the map to be printed
* @param imageTitle Title of image
* @param imageDescription Image description
* @param pageSize Page size
* @param pageOrientation Page orientation
*/
LTSPRINTING_EXPORT void printImage(LtsSession::LtsSession *session,
QWidget *dialogParent,
const QImage &image,
const QString &imageTitle,
const QString &description,
const QPrinter::PageSize &pageSize = QPrinter::A3,
const QPrinter::Orientation &pageOrientation = QPrinter::Landscape);
/**
* Print list of images.
* @param session Address of session to access exercise data
* @param dialogParent Address of dialog parent window
* @param docName Document name
* @param images List of images to be printed
* @param imageTitles List of images titles
* @param descriptions List of images descriptions
* @param pageSize Page size
* @param pageOrientation Page orientation
*/
LTSPRINTING_EXPORT void printImages(LtsSession::LtsSession *session,
QWidget *dialogParent,
const QString &docName,
QVector < QImage> &images,
QVector < QString> &imageTitles,
QVector < QString> &descriptions,
const QPrinter::PageSize &pageSize = QPrinter::A3,
const QPrinter::Orientation &pageOrientation = QPrinter::Landscape);
/**
* Print list of pdf pages as images.
* @param dialogParent Address of dialog parent window
* @param docName Document name
* @param printPath Where to save output file
* @param images List of images to be printed
*/
LTSPRINTING_EXPORT void printPDFImages(QWidget *dialogParent,
const QString &docName,
const QString &printPath,
QVector<QImage> &images);
/**
* print Report.
* @param session Address of session to access exercise data
* @param dialogParent Address of dialog parent window
* @param report Report to be printed
*/
LTSPRINTING_EXPORT void printReport( LtsSession::LtsSession *session, QWidget *dialogParent, KDReports::Report& report );
/**
* print Widget.
* @param session Address of session to access exercise data
* @param dialogParent Address of dialog parent window
* @param widget Widget to be printed
* @param title Image title
*/
LTSPRINTING_EXPORT void printWidget(LtsSession::LtsSession *session, QWidget *dialogParent, QWidget *widget, const QString &title);
/**
* print printMessage.
* @param session Address of session to access exercise data
* @param subject subject of message
* @param from sender
* @param to receiver
* @param msgText text of the message
* @param time time of the message
*/
LTSPRINTING_EXPORT void printMessage(LtsSession::LtsSession *session,
QWidget *dialogParent,
const QString &subject, const QString &subjectContent,
const QString &from, const QString &fromContent,
const QString &to, const QString &toContent,
const QString &msgTextContent,
const QString &time, const QString &timeContent);
}
File diff suppressed because it is too large. Load diff
+364
View File
@@ -0,0 +1,364 @@
/**
* @RDE_HEADER@
* Small QPrinter abstraction class
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <QtCore/QSet>
#include <QtPrintSupport/QPrinter>
namespace NGL
{
class INGLLogger;
class Settings;
}
namespace KDReports
{
class Report;
}
class QPainter;
class QAbstractItemView;
class QAbstractItemModel;
class QModelIndex;
class QTextDocument;
namespace LtsPrinting
{
static constexpr int DECORATION_EXTENT = 50;
static constexpr int DOC_MARGIN = 60;
static constexpr int ProjectIconHeight = 40;
// HeaderText and FooterText :
static const QLatin1String HeaderText(
"<table width=\"100%\">"
" <tr>"
" <td align=\"left\" valign=\"bottom\">&exercise;</td>" // exercise name
" <td align=\"center\" valign=\"bottom\">&title;</td>" // title
" <td align=\"right\" valign=\"top\"><img src=\"&logo;\" height=\"&logoHeight;\" alt=\"Logo\" /></td>" // logo
" </tr>"
"</table>");
static const QLatin1String FooterText(
"<table width=\"100%\">"
" <tr>"
" <td align=\"left\">&date; -- &user;</td>" // date
" <td align=\"center\" valign=\"bottom\">&footertitle;</td>" // footertitle
" <td align=\"right\">&page;</td>" // pagenumber
" </tr>"
"</table>");
//
class Base
{
public:
/**
* constructor Printer with open QPrintDialog
* @param dialogParent parent of QPrintDialog
* @param dialogTitle windowTitle of QPrintDialog
*/
Base(QTextDocument &doc,
QWidget *dialogParent,
const QString &dialogTitle,
const QString &_fn,
QPrinter::PaperSize _ps = QPrinter::A4,
QPrinter::Orientation _or = QPrinter::Portrait,
QPrinter::ColorMode _cm = QPrinter::Color);
/**
* destructor
*/
virtual ~Base();
/**
* get the QPrinter
* @return the QPrinter
*/
QPrinter *printer();
/**
* set the default print destination (printer or file)
* @param printToFile print to file if true
*/
static void setPrintToFile(bool printToFile);
/**
* get the style sheet(html)
* @return the stle sheet
*/
static QString styleSheet();
/// Get page size
QPrinter::PageSize pageSize() const;
/// Set page size
void setPageSize(QPrinter::PageSize size);
/// Get page orientation
QPrinter::Orientation orientation() const;
/// Set page orientation
void setOrientation(QPrinter::Orientation orientation);
bool newPage();
/// Get left margin width
double leftMargin() const;
/// Set left margin width
void setLeftMargin(double margin);
/// Get right margin width
double rightMargin() const;
/// Set right margin width
void setRightMargin(double margin);
/// Get top margin width
double topMargin() const;
/// Set top margin width
void setTopMargin(double margin);
/// Get bottom margin width
double bottomMargin() const;
/// Set bottom margin width
void setBottomMargin(double margin);
/// Set all margins
void setMargins(double margin);
/// Get spacing between content and header and footer
double spacing() const;
/// Set spacing between content and header and footer
void setSpacing(double spacing);
/// Get header size
double headerSize() const;
/// Set header size
void setHeaderSize(double size);
/// Set header rule size
double headerRule() const;
/// Get header rule size
void setHeaderRule(double pointsize);
/// Get header text
const QString &headerText() const;
/// Set header text
void setHeaderText(const QString &text);
/// Get footer size
double footerSize() const;
/// Set footer size
void setFooterSize(double size);
/// Get footer rule size
double footerRule() const;
/// Set footer rule size
void setFooterRule(double pointsize);
/// Get footer text
const QString &footerText() const;
/// Set footer text
void setFooterText(const QString &text);
/// Set the footer title (the text in the center)
void setFooterTitle(const QString &footertitle) { footertitle_ = footertitle; }
/// Set the font size of a list/table/tree item :
/// between 1 (==very small) and 7 (==very large), 3 == normal
void setItemFontSize(int itemFontSize);
/**
* print title data (html) into a QString
* @param htmlStr data (html) will be append to str
* @param title the title of the data
* @param html heading type (h1, h2, h3, h4, h5, h6 - default h3)
* @return nothing
*/
static void printTitleData(QString &htmlStr, const QString &title, const QString &heading = QStringLiteral("h3"));
/**
* print list data (html) into a QString
* @param str data (html) will be append to str
* @param view the model-data of this view will be translate into html
* @param title the title of the data
* @param iconMode if true : icons only will be print
* @param iconExtent the extent (width and height) of an icon
* @return true on sucess
*/
bool printListData(QString &str,
const QAbstractItemView *view,
const QString &title,
bool asIcons = false,
int iconExtent = DECORATION_EXTENT);
/**
* print table data (html) into a QString
* @param str data (html) will be append to str
* @param view the model-data of this view will be translate into html
* @param title the title of the data
* @param suppressCols list of colums to be ignored
* @param iconExtent the extent (width and height) of an icon
* @return true on sucess
*/
bool printTableData(QString &str,
const QAbstractItemView *view,
const QString &title = QString(),
const QSet<int> &suppressCols = QSet<int>(),
int iconExtent = DECORATION_EXTENT);
/**
* append tree data (html) into a QString
* @param str data (html) will be append to str
* @param view the model-data of this view will be translate into html
* @param title the title of the data
* @param suppressCols list of colums to be ignored
* @param iconExtent the extent (width and height) of an icon
* @param tabtexts alternative colum texts (instead of headerData texts)
* @return true on sucess
*/
bool printTreeData(QString &str,
const QAbstractItemView *view,
const QString &title = QString(),
const QSet<int> &suppressCols = QSet<int>(),
int iconExtent = DECORATION_EXTENT,
const QList<QString> &tabtexts = QList<QString>());
/**
* print a text block into a doc
* @param doc destination
* @param text to be inserted
* @param title the title of the text block
* @return true on sucess
*/
static bool printDocTextBlock(QTextDocument &doc,
const QString &text,
const QString &title = QString());
/**
* print an image into a doc
* @param doc destination
* @param image to be inserted
* @param title the title of the image
* @return true on sucess
*/
bool printDocImage(QTextDocument &doc, const QImage &image,
const QString &title = QString(), const QString &description = QString(), const qreal alreadyUsedHeight = 0) const;
/**
* print a report into a doc
* @param doc destination
* @param report to be inserted
* @return true on sucess
*/
static bool printReportData(QTextDocument &doc, KDReports::Report &report);
/**
* prints out (to printer or to a file) the textDocument
* @param doc the doc to be printed
* @param printer the associated printer
*/
virtual void print(QTextDocument *doc);
virtual void printSinglePage(QTextDocument *doc);
virtual void printDone();
/**
* Get all hidden cols for the given view - useful to
* only print the columns which are visible to the user
*/
template<class T>
static QSet<int> getHiddenCols(T *view)
{
QSet<int> hiddenCols;
int colCount = view->model()->columnCount();
for (int i = 0; i < colCount; ++i)
{
if (view->isColumnHidden(i))
hiddenCols += i;
}
return hiddenCols;
}
/**
* Set exercise Name for prints
* @param exerciseName Exercise name to be used for printing
*/
void setCurrentExerciseName( const QString& exerciseName );
/**
* Set operator Name for prints
* @param operatorName Operator name to be used for printing
*/
void setOperatorName( const QString& operatorName );
// paint specific page
void paintPage(QTextDocument *document,
int pagenum);
QSize pageSizeInMM();
protected:
bool printTableItemData(QString &str,
const QAbstractItemModel *model,
const QModelIndex &mi,
int rowSpanSize,
int columnSpanSize,
int iconExtent = DECORATION_EXTENT);
bool printItemData(QString &str,
const QAbstractItemModel *model,
const QModelIndex &mi,
int iconExtent = DECORATION_EXTENT);
void printDecorationData(QString &str,
const QAbstractItemModel *model,
const QModelIndex &mi,
int iconExtent = DECORATION_EXTENT);
void printListPoint(QString &str,
const QAbstractItemView *view,
const QAbstractItemModel *vm,
const QModelIndex &miColumn0,
const QSet<int> &suppressCols = QSet<int>(),
int iconExtent = DECORATION_EXTENT);
static int hierarchyCount(const QModelIndex &child);
QString iconFilename(int nr) const;
QSize printerPageSize() const;
QSize contentPageSize() const;
QString currentExerciseName() const;
QString operatorName() const;
// return paper rect
QRectF paperRect(QPaintDevice *device);
// return printable rects
QRectF contentRect(QPaintDevice *device);
QRectF headerRect(QPaintDevice *device);
QRectF footerRect(QPaintDevice *device);
// common print routine
void printSinglePage();
void print();
private:
QPrinter *m_printer;
QPainter *m_painter;
static bool m_printToFile;
int m_iconFilenameNr;
QTextDocument *m_tempdoc;
double leftmargin_;
double rightmargin_;
double topmargin_;
double bottommargin_;
double spacing_;
double headersize_;
double headerrule_;
QString headertext_;
double footersize_;
double footerrule_;
QString footertext_;
QString footertitle_;
int itemFontSize_;
private:
NGL::Settings *m_settings;
NGL::INGLLogger &m_logger;
QString m_exerciseName;
QString m_operatorName;
int m_currentPage;
};
} // namespace LtsPrinting