7#include "barcodequickitem.h"
9#include <QGuiApplication>
15BarcodeQuickItem::BarcodeQuickItem(
QQuickItem *parent)
20BarcodeQuickItem::~BarcodeQuickItem() =
default;
22QVariant BarcodeQuickItem::content()
const
27void BarcodeQuickItem::setContent(
const QVariant &content)
29 if (m_content == content) {
37QJSValue BarcodeQuickItem::barcodeType()
const
40 return static_cast<BarcodeType
>(m_type.value());
45void BarcodeQuickItem::setBarcodeType(
const QJSValue &type)
47 if (!
type.isNumber()) {
56 if (enumType == m_type) {
61 Q_EMIT barcodeTypeChanged();
66QColor BarcodeQuickItem::foregroundColor()
const
71void BarcodeQuickItem::setForegroundColor(
const QColor &color)
73 if (m_fgColor == color) {
77 Q_EMIT foregroundColorChanged();
81QColor BarcodeQuickItem::backgroundColor()
const
86void BarcodeQuickItem::setBackgroundColor(
const QColor &color)
88 if (m_bgColor == color) {
92 Q_EMIT backgroundColorChanged();
96BarcodeQuickItem::Dimensions Prison::BarcodeQuickItem::dimensions()
const
99 return static_cast<BarcodeQuickItem::Dimensions
>(m_barcode->dimensions());
100 return BarcodeQuickItem::Dimensions::NoDimensions;
103void BarcodeQuickItem::paint(QPainter *painter)
109 const auto w_max = std::max(minimumWidth(),
width());
110 const auto h_max = std::max(minimumHeight(),
height());
111 const auto img = m_barcode->toImage(QSizeF(w_max, h_max));
112 const auto x = (w_max - img.width()) / 2;
113 const auto y = (h_max - img.height()) / 2;
115 painter->
drawImage(QRectF(
x,
y, img.width(), img.height()), img, img.rect());
118void BarcodeQuickItem::componentComplete()
124qreal BarcodeQuickItem::minimumHeight()
const
126 return m_barcode ? m_barcode->minimumSize().height() : 0;
129qreal BarcodeQuickItem::minimumWidth()
const
131 return m_barcode ? m_barcode->minimumSize().width() : 0;
134bool BarcodeQuickItem::isEmpty()
const
136 switch (m_content.userType()) {
138 return m_content.toString().isEmpty();
140 return m_content.toByteArray().isEmpty();
147void BarcodeQuickItem::updateBarcode()
153 if (isEmpty() || !m_type) {
156 Q_EMIT dimensionsChanged();
167 m_barcode->setData(m_content.toString());
169 m_barcode->setData(m_content.toByteArray());
171 m_barcode->setForegroundColor(m_fgColor);
172 m_barcode->setBackgroundColor(m_bgColor);
174 setImplicitSize(
size.width(),
size.height());
177 Q_EMIT dimensionsChanged();
180#include "moc_barcodequickitem.cpp"
static std::optional< Prison::Barcode > create(Prison::BarcodeType type)
Create a new barcode generator.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
Provides classes and methods for generating barcodes.
BarcodeType
possible supported barcode types
void drawImage(const QPoint &point, const QImage &image)
void setRenderHint(RenderHint hint, bool on)
virtual void componentComplete() override
bool isComponentComplete() const const
QSizeF size() const const