PageRenderTime 60ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/POSClient/ReceiptCreator.cpp

https://bitbucket.org/fbreiten/point-of-sale-system
C++ | 62 lines | 53 code | 9 blank | 0 comment | 2 complexity | 341b97b9731f339961b29f97e89b3d19 MD5 | raw file
  1. #include "receiptcreator.h"
  2. #include <QtCore>
  3. #include <QPainter>
  4. #include <QDesktopServices>
  5. #include <QUrl>
  6. void ReceiptCreator::setData(int listSize, QString sum)
  7. {
  8. m_sum = sum;
  9. m_position = 20;
  10. m_pPixmap = new QPixmap(320, listSize*20+120); //size in pixels
  11. m_pPainter = new QPainter(m_pPixmap);
  12. QColor white(255,255,255);
  13. m_pPixmap->fill(white);
  14. QFont font("", 10); //default font
  15. m_pPainter->setFont(font);
  16. addHeader();
  17. }
  18. void ReceiptCreator::printReceipt()
  19. {
  20. if (m_sum != NULL)
  21. {
  22. m_pPainter->drawText(QPointF(10, m_position + 20), "Total:");
  23. m_pPainter->drawText(QPointF(260, m_position + 20), m_sum);
  24. m_position += 30;
  25. addFooter();
  26. m_pPixmap->save("receipt.jpg");
  27. QDesktopServices::openUrl(QUrl("receipt.jpg"));
  28. qDebug() << "Printed receipt";
  29. }
  30. }
  31. void ReceiptCreator::addRecord(ListProduct *product)
  32. {
  33. m_pPainter->drawText(QPointF(10, m_position), product->name());
  34. float discount = product->discount();
  35. QString price = QString::number(product->price() * product->quantity() * (1-discount/100), 'f', 2);
  36. m_pPainter->drawText(260, m_position, price);
  37. m_position += 20;
  38. }
  39. void ReceiptCreator::addFooter()
  40. {
  41. m_pPainter->setFont(QFont("",10));
  42. m_pPainter->drawText(QPointF(10, m_position + 10), "tel: +358 40 1234560");
  43. m_pPainter->drawText(QPointF(10, m_position + 22), "Have an awesome day!");
  44. m_pPainter->setFont(QFont("",10));
  45. m_position += 20;
  46. }
  47. void ReceiptCreator::addHeader()
  48. {
  49. m_pPainter->setFont(QFont("",16));
  50. m_pPainter->drawText(QPointF(100, 30), "Omnistore");
  51. m_pPainter->setFont(QFont("",10));
  52. m_position += 30;
  53. }