Mercurial > hg > syntilista
diff src/main.h @ 114:a5c8741b8662
Initial prototype support for printing list of users + print preview dialog.
Has some issues currently.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 05 Jul 2017 12:48:55 +0300 |
parents | 907f2ddf6801 |
children | 404d567edaab |
line wrap: on
line diff
--- a/src/main.h Wed Jul 05 09:52:10 2017 +0300 +++ b/src/main.h Wed Jul 05 12:48:55 2017 +0300 @@ -14,6 +14,8 @@ #include <QDialog> #include <QtSql> #include <QSqlQueryModel> +#include <QPainter> +#include <QPrinter> // @@ -106,6 +108,13 @@ class AboutWindow; } +typedef struct +{ + int nlinesPerPage; + int npages; +} SLPageInfo; + + class SyntilistaMainWindow : public QMainWindow { Q_OBJECT @@ -123,6 +132,8 @@ int addTransactionGUI(qint64 id, bool debt, double value); void updatePersonList(); + bool printDocumentPage(SLPageInfo &pinfo, const bool getPageInfo, const int page, QPainter *pt, QPrinter *printer); + PersonSQLModel *model_People; public slots: @@ -138,6 +149,7 @@ void on_button_Quit_clicked(); void on_button_About_clicked(); + void on_button_Print_clicked(); void on_button_AddDebt_clicked(); void on_button_PayDebt_clicked(); @@ -156,6 +168,8 @@ void updateSortOrder(int index, Qt::SortOrder order); + void printDocument(QPrinter *printer); + private: Ui::SyntilistaMainWindow *ui; @@ -222,4 +236,114 @@ }; +// +// Custom painter drawing helper class +// +class SLDrawContext : public QObject +{ + Q_OBJECT + +public: + QPointF m_pos; + QString m_str; + qreal m_lf_add; + + explicit SLDrawContext(QPainter *pt) + { + painter = pt; + metrics = NULL; + m_str = "ABC"; + setPos(0, 0); + m_lf_add = 0; + } + + ~SLDrawContext() + { + if (metrics) + delete metrics; + } + + void setFont(const QFont &ft) + { + if (metrics) + delete metrics; + + font = QFont(ft, painter->device()); + painter->setFont(font); + metrics = new QFontMetricsF(font); + } + + void setLFAdd(const qreal lf_add) + { + m_lf_add = lf_add; + } + + void drawText(const QPointF &pos, const QString &str) + { + m_str = str; + painter->drawText(m_pos + pos, str); + } + + void drawText(const QString &str) + { + drawText(QPointF(0, 0), str); + } + + void drawText(const qreal xc, const qreal width, const QString &str, const int flags = 0) + { + m_str = str; + painter->drawText( + m_pos.x() + xc, m_pos.y(), + width, boundRect().height(), + flags, + str); + } + + const QRectF boundRect(const QString str) + { + return metrics->boundingRect(str); + } + + const QRectF boundRect() + { + return metrics->boundingRect(m_str); + } + + void lf(qreal yadd) + { + m_pos.setY(m_pos.y() + boundRect().height() + yadd); + } + + void lf() + { + lf(m_lf_add); + } + + void setPos(const QPointF &pos) + { + m_pos = pos; + } + + void setPos(const qreal x, const qreal y) + { + setPos(QPointF(x, y)); + } + + void move(const QPointF &pos) + { + m_pos += pos; + } + + void move(const qreal x, const qreal y) + { + move(QPointF(x, y)); + } + +private: + QPainter *painter; + QFont font; + QFontMetricsF *metrics; +}; + + #endif // SYNTILISTA_H