Changeset View
Changeset View
Standalone View
Standalone View
src/quick/barcodequickitem.cpp
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | |||||
99 | 99 | | |||
100 | void BarcodeQuickItem::paint(QPainter* painter) | 100 | void BarcodeQuickItem::paint(QPainter* painter) | ||
101 | { | 101 | { | ||
102 | if (!m_barcode) | 102 | if (!m_barcode) | ||
103 | return; | 103 | return; | ||
104 | 104 | | |||
105 | const auto w_max = std::max(implicitWidth(), width()); | 105 | const auto w_max = std::max(implicitWidth(), width()); | ||
106 | const auto h_max = std::max(implicitHeight(), height()); | 106 | const auto h_max = std::max(implicitHeight(), height()); | ||
107 | const auto scale = std::min(w_max / implicitWidth(), h_max / implicitHeight()); | 107 | const auto img = m_barcode->toImage(QSizeF(w_max, h_max)); | ||
108 | const auto w = scale * implicitWidth(); | 108 | const auto x = (w_max - img.width()) / 2; | ||
109 | const auto h = scale * implicitHeight(); | 109 | const auto y = (h_max - img.height()) / 2; | ||
110 | const auto x = (width() - w) / 2; | | |||
111 | const auto y = (height() - h) / 2; | | |||
112 | | ||||
113 | const auto img = m_barcode->toImage(m_barcode->minimumSize()); | | |||
114 | painter->setRenderHint(QPainter::SmoothPixmapTransform, false); | 110 | painter->setRenderHint(QPainter::SmoothPixmapTransform, false); | ||
115 | painter->drawImage(QRectF(x, y, w, h), img, img.rect()); | 111 | painter->drawImage(QRectF(x, y, img.width(), img.height()), img, img.rect()); | ||
116 | } | 112 | } | ||
117 | 113 | | |||
118 | void BarcodeQuickItem::componentComplete() | 114 | void BarcodeQuickItem::componentComplete() | ||
119 | { | 115 | { | ||
120 | QQuickPaintedItem::componentComplete(); | 116 | QQuickPaintedItem::componentComplete(); | ||
121 | updateBarcode(); | 117 | updateBarcode(); | ||
122 | } | 118 | } | ||
123 | 119 | | |||
Show All 24 Lines |