300 lines
6.7 KiB
C++
Executable File
300 lines
6.7 KiB
C++
Executable File
|
|
|
|
#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;
|
|
};
|
|
}
|