Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
Executable
+35
@@ -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)
|
||||
Executable
+430
@@ -0,0 +1,430 @@
|
||||
|
||||
|
||||
|
||||
#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
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
else if (dynamic_cast<const QListView *>(view) != nullptr)
|
||||
switchNum = 3;
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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(),
|
||||
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);
|
||||
break;
|
||||
case 2:
|
||||
nglPrinter.printTreeData(htmlStr, view, QString(), hiddenCols);
|
||||
break;
|
||||
case 3:
|
||||
nglPrinter.printListData(htmlStr, view, QString());
|
||||
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,
|
||||
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)
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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(),
|
||||
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,
|
||||
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,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
tempDoc.setPageSize(doc.pageSize());
|
||||
tempDoc.setHtml(htmlStr);
|
||||
currentHeight = doc.size().height() - previousPagesHeight;
|
||||
|
||||
if (currentHeight + tempDoc.size().height() > nglPrinter.pageSizeInMM().height())
|
||||
{
|
||||
tbfFormat.setPageBreakPolicy(QTextFormat::PageBreakFlag::PageBreak_AlwaysBefore);
|
||||
cursor.insertBlock(tbfFormat);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
|
||||
|
||||
|
||||
#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
|
||||
{
|
||||
|
||||
|
||||
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());
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
LTSPRINTING_EXPORT void printPDFImages(QWidget *dialogParent,
|
||||
const QString &docName,
|
||||
const QString &printPath,
|
||||
QVector<QImage> &images);
|
||||
|
||||
|
||||
|
||||
LTSPRINTING_EXPORT void printReport( LtsSession::LtsSession *session, QWidget *dialogParent, KDReports::Report& report );
|
||||
|
||||
|
||||
|
||||
LTSPRINTING_EXPORT void printWidget(LtsSession::LtsSession *session, QWidget *dialogParent, QWidget *widget, const QString &title);
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
Executable
+1305
File diff suppressed because it is too large.
Load diff
Executable
+299
@@ -0,0 +1,299 @@
|
||||
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
static const QLatin1String HeaderText(
|
||||
"<table width=\"100%\">"
|
||||
" <tr>"
|
||||
" <td align=\"left\" valign=\"bottom\">&exercise;</td>"
|
||||
" <td align=\"center\" valign=\"bottom\">&title;</td>"
|
||||
" <td align=\"right\" valign=\"top\"><img src=\"&logo;\" height=\"&logoHeight;\" alt=\"Logo\" /></td>"
|
||||
" </tr>"
|
||||
"</table>");
|
||||
|
||||
static const QLatin1String FooterText(
|
||||
"<table width=\"100%\">"
|
||||
" <tr>"
|
||||
" <td align=\"left\">&date; -- &user;</td>"
|
||||
" <td align=\"center\" valign=\"bottom\">&footertitle;</td>"
|
||||
" <td align=\"right\">&page;</td>"
|
||||
" </tr>"
|
||||
"</table>");
|
||||
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
virtual ~Base();
|
||||
|
||||
|
||||
|
||||
QPrinter *printer();
|
||||
|
||||
|
||||
|
||||
static void setPrintToFile(bool printToFile);
|
||||
|
||||
|
||||
|
||||
static QString styleSheet();
|
||||
|
||||
|
||||
QPrinter::PageSize pageSize() const;
|
||||
|
||||
void setPageSize(QPrinter::PageSize size);
|
||||
|
||||
QPrinter::Orientation orientation() const;
|
||||
|
||||
void setOrientation(QPrinter::Orientation orientation);
|
||||
|
||||
bool newPage();
|
||||
|
||||
|
||||
double leftMargin() const;
|
||||
|
||||
void setLeftMargin(double margin);
|
||||
|
||||
double rightMargin() const;
|
||||
|
||||
void setRightMargin(double margin);
|
||||
|
||||
double topMargin() const;
|
||||
|
||||
void setTopMargin(double margin);
|
||||
|
||||
double bottomMargin() const;
|
||||
|
||||
void setBottomMargin(double margin);
|
||||
|
||||
void setMargins(double margin);
|
||||
|
||||
|
||||
double spacing() const;
|
||||
|
||||
void setSpacing(double spacing);
|
||||
|
||||
|
||||
double headerSize() const;
|
||||
|
||||
void setHeaderSize(double size);
|
||||
|
||||
double headerRule() const;
|
||||
|
||||
void setHeaderRule(double pointsize);
|
||||
|
||||
const QString &headerText() const;
|
||||
|
||||
void setHeaderText(const QString &text);
|
||||
|
||||
|
||||
double footerSize() const;
|
||||
|
||||
void setFooterSize(double size);
|
||||
|
||||
double footerRule() const;
|
||||
|
||||
void setFooterRule(double pointsize);
|
||||
|
||||
const QString &footerText() const;
|
||||
|
||||
void setFooterText(const QString &text);
|
||||
|
||||
void setFooterTitle(const QString &footertitle) { footertitle_ = footertitle; }
|
||||
|
||||
|
||||
void setItemFontSize(int itemFontSize);
|
||||
|
||||
|
||||
|
||||
static void printTitleData(QString &htmlStr, const QString &title, const QString &heading = QStringLiteral("h3"));
|
||||
|
||||
|
||||
|
||||
bool printListData(QString &str,
|
||||
const QAbstractItemView *view,
|
||||
const QString &title,
|
||||
bool asIcons = false,
|
||||
int iconExtent = DECORATION_EXTENT);
|
||||
|
||||
|
||||
bool printTableData(QString &str,
|
||||
const QAbstractItemView *view,
|
||||
const QString &title = QString(),
|
||||
const QSet<int> &suppressCols = QSet<int>(),
|
||||
int iconExtent = DECORATION_EXTENT);
|
||||
|
||||
|
||||
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>());
|
||||
|
||||
|
||||
|
||||
static bool printDocTextBlock(QTextDocument &doc,
|
||||
const QString &text,
|
||||
const QString &title = QString());
|
||||
|
||||
|
||||
|
||||
bool printDocImage(QTextDocument &doc, const QImage &image,
|
||||
const QString &title = QString(), const QString &description = QString(), const qreal alreadyUsedHeight = 0) const;
|
||||
|
||||
|
||||
|
||||
static bool printReportData(QTextDocument &doc, KDReports::Report &report);
|
||||
|
||||
|
||||
|
||||
virtual void print(QTextDocument *doc);
|
||||
|
||||
|
||||
virtual void printSinglePage(QTextDocument *doc);
|
||||
|
||||
|
||||
virtual void printDone();
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setCurrentExerciseName( const QString& exerciseName );
|
||||
|
||||
|
||||
|
||||
void setOperatorName( const QString& operatorName );
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
QRectF paperRect(QPaintDevice *device);
|
||||
|
||||
QRectF contentRect(QPaintDevice *device);
|
||||
QRectF headerRect(QPaintDevice *device);
|
||||
QRectF footerRect(QPaintDevice *device);
|
||||
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user