comparison 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
comparison
equal deleted inserted replaced
113:907f2ddf6801 114:a5c8741b8662
12 #include <QMainWindow> 12 #include <QMainWindow>
13 #include <QShortcut> 13 #include <QShortcut>
14 #include <QDialog> 14 #include <QDialog>
15 #include <QtSql> 15 #include <QtSql>
16 #include <QSqlQueryModel> 16 #include <QSqlQueryModel>
17 #include <QPainter>
18 #include <QPrinter>
17 19
18 20
19 // 21 //
20 // Global application defines 22 // Global application defines
21 // 23 //
103 { 105 {
104 class SyntilistaMainWindow; 106 class SyntilistaMainWindow;
105 class EditPerson; 107 class EditPerson;
106 class AboutWindow; 108 class AboutWindow;
107 } 109 }
110
111 typedef struct
112 {
113 int nlinesPerPage;
114 int npages;
115 } SLPageInfo;
116
108 117
109 class SyntilistaMainWindow : public QMainWindow 118 class SyntilistaMainWindow : public QMainWindow
110 { 119 {
111 Q_OBJECT 120 Q_OBJECT
112 121
121 void setActivePerson(qint64 id); 130 void setActivePerson(qint64 id);
122 int addTransaction(qint64 id, double value, PersonInfo &info); 131 int addTransaction(qint64 id, double value, PersonInfo &info);
123 int addTransactionGUI(qint64 id, bool debt, double value); 132 int addTransactionGUI(qint64 id, bool debt, double value);
124 void updatePersonList(); 133 void updatePersonList();
125 134
135 bool printDocumentPage(SLPageInfo &pinfo, const bool getPageInfo, const int page, QPainter *pt, QPrinter *printer);
136
126 PersonSQLModel *model_People; 137 PersonSQLModel *model_People;
127 138
128 public slots: 139 public slots:
129 void focusDebtEdit(); 140 void focusDebtEdit();
130 141
136 void on_edit_PersonFilter_textChanged(const QString &arg1); 147 void on_edit_PersonFilter_textChanged(const QString &arg1);
137 void on_button_ClearFilter_clicked(); 148 void on_button_ClearFilter_clicked();
138 149
139 void on_button_Quit_clicked(); 150 void on_button_Quit_clicked();
140 void on_button_About_clicked(); 151 void on_button_About_clicked();
152 void on_button_Print_clicked();
141 153
142 void on_button_AddDebt_clicked(); 154 void on_button_AddDebt_clicked();
143 void on_button_PayDebt_clicked(); 155 void on_button_PayDebt_clicked();
144 void on_button_PayFullDebt_clicked(); 156 void on_button_PayFullDebt_clicked();
145 157
154 void changeUIZoomOut(); 166 void changeUIZoomOut();
155 void changeUIZoomReset(); 167 void changeUIZoomReset();
156 168
157 void updateSortOrder(int index, Qt::SortOrder order); 169 void updateSortOrder(int index, Qt::SortOrder order);
158 170
171 void printDocument(QPrinter *printer);
172
159 173
160 private: 174 private:
161 Ui::SyntilistaMainWindow *ui; 175 Ui::SyntilistaMainWindow *ui;
162 176
163 TransactionSQLModel *model_Latest; 177 TransactionSQLModel *model_Latest;
220 private: 234 private:
221 Ui::AboutWindow *ui; 235 Ui::AboutWindow *ui;
222 }; 236 };
223 237
224 238
239 //
240 // Custom painter drawing helper class
241 //
242 class SLDrawContext : public QObject
243 {
244 Q_OBJECT
245
246 public:
247 QPointF m_pos;
248 QString m_str;
249 qreal m_lf_add;
250
251 explicit SLDrawContext(QPainter *pt)
252 {
253 painter = pt;
254 metrics = NULL;
255 m_str = "ABC";
256 setPos(0, 0);
257 m_lf_add = 0;
258 }
259
260 ~SLDrawContext()
261 {
262 if (metrics)
263 delete metrics;
264 }
265
266 void setFont(const QFont &ft)
267 {
268 if (metrics)
269 delete metrics;
270
271 font = QFont(ft, painter->device());
272 painter->setFont(font);
273 metrics = new QFontMetricsF(font);
274 }
275
276 void setLFAdd(const qreal lf_add)
277 {
278 m_lf_add = lf_add;
279 }
280
281 void drawText(const QPointF &pos, const QString &str)
282 {
283 m_str = str;
284 painter->drawText(m_pos + pos, str);
285 }
286
287 void drawText(const QString &str)
288 {
289 drawText(QPointF(0, 0), str);
290 }
291
292 void drawText(const qreal xc, const qreal width, const QString &str, const int flags = 0)
293 {
294 m_str = str;
295 painter->drawText(
296 m_pos.x() + xc, m_pos.y(),
297 width, boundRect().height(),
298 flags,
299 str);
300 }
301
302 const QRectF boundRect(const QString str)
303 {
304 return metrics->boundingRect(str);
305 }
306
307 const QRectF boundRect()
308 {
309 return metrics->boundingRect(m_str);
310 }
311
312 void lf(qreal yadd)
313 {
314 m_pos.setY(m_pos.y() + boundRect().height() + yadd);
315 }
316
317 void lf()
318 {
319 lf(m_lf_add);
320 }
321
322 void setPos(const QPointF &pos)
323 {
324 m_pos = pos;
325 }
326
327 void setPos(const qreal x, const qreal y)
328 {
329 setPos(QPointF(x, y));
330 }
331
332 void move(const QPointF &pos)
333 {
334 m_pos += pos;
335 }
336
337 void move(const qreal x, const qreal y)
338 {
339 move(QPointF(x, y));
340 }
341
342 private:
343 QPainter *painter;
344 QFont font;
345 QFontMetricsF *metrics;
346 };
347
348
225 #endif // SYNTILISTA_H 349 #endif // SYNTILISTA_H