Prison::AbstractBarcode Class Referenceabstract

#include <abstractbarcode.h>

Inheritance diagram for Prison::AbstractBarcode:

Public Types

enum  Dimensions : uint8_t { NoDimensions, OneDimension, TwoDimensions }

Public Member Functions

 AbstractBarcode ()
const QColorbackgroundColor () const
QString data () const
Dimensions dimensions () const
const QColorforegroundColor () const
QSizeF minimumSize () const
QSizeF preferredSize (qreal devicePixelRatio) const
void setBackgroundColor (const QColor &backgroundcolor)
void setData (const QString &data)
void setForegroundColor (const QColor &foregroundcolor)
QImage toImage (const QSizeF &size)
QSizeF trueMinimumSize () const

Protected Member Functions

virtual QImage paintImage (const QSizeF &size)=0
void setMinimumSize (const QSizeF &minimumSize)

Detailed Description

base class for barcode generators To add your own barcode generator, subclass this class and reimplement toImage(const QSizeF&) to do the actual work of generating the barcode.

The barcode is cached in AbstractBarcode when painting and the size and the data doesn't change. Using the same AbstractBarcode to paint on several surfaces, if they aren't of the exact same size will break the caching

Definition at line 30 of file abstractbarcode.h.

Member Enumeration Documentation

Dimensions of the barcode.


Null barcode.


One-dimensional barcode.


2D matrix code.

Definition at line 118 of file abstractbarcode.h.

Constructor & Destructor Documentation

AbstractBarcode::AbstractBarcode ( )

creates a barcode generator without any data

since 5.69 Use Prison::createBarcode instead.

Definition at line 46 of file abstractbarcode.cpp.

Member Function Documentation

const QColor & AbstractBarcode::backgroundColor ( ) const
the background color (by default white) to be used for the barcode.

Definition at line 138 of file abstractbarcode.cpp.

QString AbstractBarcode::data ( ) const
the QString encoded in this barcode.

Definition at line 57 of file abstractbarcode.cpp.

AbstractBarcode::Dimensions AbstractBarcode::dimensions ( ) const

Returns the amount of dimensions of the barcode.


Definition at line 160 of file abstractbarcode.cpp.

const QColor & AbstractBarcode::foregroundColor ( ) const
the foreground color (by default black) to be used for the barcode.

Definition at line 142 of file abstractbarcode.cpp.

QSizeF AbstractBarcode::minimumSize ( ) const

The minimal size of this barcode.

This isn't the absolute minimum, but closer to the result of preferredSize(1).
the minimal size for this barcode.
Since 5.69, use preferredSize() or trueMinimumSize().

Definition at line 89 of file abstractbarcode.cpp.

virtual QImage Prison::AbstractBarcode::paintImage ( const QSizeF size)
protectedpure virtual

Doing the actual painting of the image.

sizeunused - will be removed in KF6
image with barcode, or null image

Implemented in Prison::DataMatrixBarcode, Prison::Code39Barcode, Prison::QRCodeBarcode, Prison::Code128Barcode, Prison::Code93Barcode, and Prison::AztecBarcode.

QSizeF AbstractBarcode::preferredSize ( qreal  devicePixelRatio) const

The recommended size for this barcode when shown on a screen.

This is typically significantly larger than trueMinimumSize() so that barcode scanners tend to reliably detect the code. As this depends on the physical resolution of the output, you have to pass the device pixel ration of the output screen here.

devicePixelRatioThe device pixel ratio of the screen this is shown on.
See also

Definition at line 117 of file abstractbarcode.cpp.

void AbstractBarcode::setBackgroundColor ( const QColor backgroundcolor)

sets the background color

backgroundcolor- the new background color

Definition at line 146 of file abstractbarcode.cpp.

void AbstractBarcode::setData ( const QString data)

sets the data to be drawn by this function calling this function does not do any repaints of anything, they are your own responsibility.

If you are using the barcodes thru BarcodeWidget or BarcodeItem, you should rather use their setData function, as they handle the relevant updates.

dataQString containing the data

Definition at line 83 of file abstractbarcode.cpp.

void AbstractBarcode::setForegroundColor ( const QColor foregroundcolor)

sets the foreground color

foregroundcolor- the new foreground color

Definition at line 153 of file abstractbarcode.cpp.

void AbstractBarcode::setMinimumSize ( const QSizeF minimumSize)

Sets the minimum size for this barcode.

Some barcodes have minimum sizes for when they are readable and such

minimumSizeQSizeF holding the minimum size for this barcode
since 5.69, function is a no-op, no need to call this anymore.

Definition at line 132 of file abstractbarcode.cpp.

QImage AbstractBarcode::toImage ( const QSizeF size)

Creates a image with a barcode on.

QImage with a barcode on, trying to match the requested
sizeIf one of the dimensions of
sizeis smaller than the matching dimension in minimumSize, a null QImage will be returned

Definition at line 62 of file abstractbarcode.cpp.

QSizeF AbstractBarcode::trueMinimumSize ( ) const

The minimal amount of pixels needed to represent this barcode without loss of information.

That is, the size of the barcode image if each line or dot is just one pixel wide. On normal screens that is not enough for barcode scanners to reliably detect the barcode though.

See also

Definition at line 111 of file abstractbarcode.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Jul 8 2020 22:50:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.