barcodeitem.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /***************************************************************************
  2. * Copyright (C) 2008 by BogDan Vatra *
  3. * bogdan@licentia.eu *
  4. * Copyright (C) 2009-2023 by Robin Stuart <rstuart114@gmail.com> *
  5. * *
  6. * This program is free software: you can redistribute it and/or modify *
  7. * it under the terms of the GNU General Public License as published by *
  8. * the Free Software Foundation, either version 3 of the License, or *
  9. * (at your option) any later version. *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  16. ***************************************************************************/
  17. /* vim: set ts=4 sw=4 et : */
  18. //#include <QDebug>
  19. #include "barcodeitem.h"
  20. BarcodeItem::BarcodeItem()
  21. : QGraphicsItem()
  22. {
  23. w = 693;
  24. h = 378; // Default widget size when created
  25. }
  26. BarcodeItem::~BarcodeItem()
  27. {
  28. }
  29. void BarcodeItem::setSize(int width, int height) {
  30. w = width;
  31. h = height;
  32. }
  33. void BarcodeItem::setColor(const QColor& color) {
  34. m_color = color;
  35. }
  36. QRectF BarcodeItem::boundingRect() const
  37. {
  38. return QRectF(0, 0, w, h);
  39. }
  40. void BarcodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
  41. {
  42. QRectF painterRect = boundingRect();
  43. if (m_color.isValid()) {
  44. painter->fillRect(painterRect, m_color);
  45. }
  46. bc.render(*painter, painterRect);
  47. }