Prison::AbstractBarcode

Search for usage in LXR

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
 
QByteArray byteArrayData () 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 QByteArray &data)
 
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 32 of file abstractbarcode.h.

Member Enumeration Documentation

◆ Dimensions

Dimensions of the barcode.

Since
5.69
Enumerator
NoDimensions 

Null barcode.

OneDimension 

One-dimensional barcode.

TwoDimensions 

2D matrix code.

Definition at line 141 of file abstractbarcode.h.

Constructor & Destructor Documentation

◆ AbstractBarcode()

AbstractBarcode::AbstractBarcode ( )

creates a barcode generator without any data

Deprecated:
since 5.69 Use Prison::createBarcode instead.

Definition at line 64 of file abstractbarcode.cpp.

Member Function Documentation

◆ backgroundColor()

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

Definition at line 176 of file abstractbarcode.cpp.

◆ byteArrayData()

QByteArray AbstractBarcode::byteArrayData ( ) const

Binary data encoded in this barcode.

This returns an empty QByteArray if textual content is set.

See also
data()
Since
5.85

Definition at line 81 of file abstractbarcode.cpp.

◆ data()

QString AbstractBarcode::data ( ) const

Textual content encoded in this barcode.

This returns an empty QString if binary content is set.

See also
byteArrayData()

Definition at line 76 of file abstractbarcode.cpp.

◆ dimensions()

AbstractBarcode::Dimensions AbstractBarcode::dimensions ( ) const

Returns the amount of dimensions of the barcode.

Since
5.69

Definition at line 202 of file abstractbarcode.cpp.

◆ foregroundColor()

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

Definition at line 181 of file abstractbarcode.cpp.

◆ minimumSize()

QSizeF AbstractBarcode::minimumSize ( ) const

The minimal size of this barcode.

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

Definition at line 120 of file abstractbarcode.cpp.

◆ paintImage()

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

Doing the actual painting of the image.

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

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

◆ preferredSize()

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.

Parameters
devicePixelRatioThe device pixel ratio of the screen this is shown on.
See also
trueMinimumSize
Since
5.69

Definition at line 148 of file abstractbarcode.cpp.

◆ setBackgroundColor()

void AbstractBarcode::setBackgroundColor ( const QColor backgroundcolor)

sets the background color

Parameters
backgroundcolor- the new background color

Definition at line 186 of file abstractbarcode.cpp.

◆ setData() [1/2]

void AbstractBarcode::setData ( const QByteArray data)

Sets binary data to be drawn as a barcode.

Prefer the QString overload if your content is purely textual, to reduce the risk of encoding issues for non-ASCII content. Calling this function does not do any repaints of anything, they are your own responsibility.

Parameters
databinary barcode content
Since
5.85

Definition at line 113 of file abstractbarcode.cpp.

◆ setData() [2/2]

void AbstractBarcode::setData ( const QString data)

Sets textual data to be drawn as a barcode.

Only use this function if your content is textual, use the QByteArray overload when your content contains non-textual binary content. Calling this function does not do any repaints of anything, they are your own responsibility.

Parameters
datatextual barcode content

Definition at line 107 of file abstractbarcode.cpp.

◆ setForegroundColor()

void AbstractBarcode::setForegroundColor ( const QColor foregroundcolor)

sets the foreground color

Parameters
foregroundcolor- the new foreground color

Definition at line 194 of file abstractbarcode.cpp.

◆ setMinimumSize()

void AbstractBarcode::setMinimumSize ( const QSizeF minimumSize)
protected

Sets the minimum size for this barcode.

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

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

Definition at line 170 of file abstractbarcode.cpp.

◆ toImage()

QImage AbstractBarcode::toImage ( const QSizeF size)

Creates a image with a barcode on.

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

Definition at line 86 of file abstractbarcode.cpp.

◆ trueMinimumSize()

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
preferredSize
Since
5.69

Definition at line 142 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-2023 The KDE developers.
Generated on Mon May 8 2023 03:58:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.