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
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;
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
147void BarcodeQuickItem::updateBarcode()
153 if (isEmpty() || !m_type) {
156 Q_EMIT dimensionsChanged();
167 m_barcode->setData(m_content.
toString());
171 m_barcode->setForegroundColor(m_fgColor);
172 m_barcode->setBackgroundColor(m_bgColor);
177 Q_EMIT dimensionsChanged();
180#include "moc_barcodequickitem.cpp"
static std::optional< Prison::Barcode > create(Prison::BarcodeType type)
Create a new barcode generator.
Type type(const QSqlDatabase &db)
Provides classes and methods for generating barcodes.
BarcodeType
possible supported barcode types
bool isEmpty() const const
void drawImage(const QPoint &point, const QImage &image)
void setRenderHint(RenderHint hint, bool on)
virtual void componentComplete()=0
bool isComponentComplete() const const
QSizeF size() const const
qreal height() const const
qreal width() const const
bool isEmpty() const const
QByteArray toByteArray() const const
QString toString() const const
int userType() const const