Prison::Barcode

Search for usage in LXR

#include <barcode.h>

Public Types

enum  Dimensions : uint8_t { NoDimensions , OneDimension , TwoDimensions }
 

Public Member Functions

 Barcode (Barcode &&)
 
QColor backgroundColor () const
 
QByteArray byteArrayData () const
 
QString data () const
 
Dimensions dimensions () const
 
QColor foregroundColor () const
 
Prison::BarcodeType format () const
 
QSizeF minimumSize () const
 
Barcodeoperator= (Barcode &&)
 
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)
 

Static Public Member Functions

static std::optional< Prison::Barcodecreate (Prison::BarcodeType type)
 

Detailed Description

A barcode generator for a fixed barcode format.

Note
This replaces Prison::createBarcode and AbstractBarcode* from KF5. You can create Barcode instances directly now and specify the format in its constructor. Rather than checking for createBarcode returning a nullptr, check whether the format is not Prison::Null.
Since
6.0

Definition at line 39 of file barcode.h.

Member Enumeration Documentation

◆ Dimensions

Dimensions of the barcode.

Enumerator
NoDimensions 

Null barcode.

OneDimension 

One-dimensional barcode.

TwoDimensions 

2D matrix code.

Definition at line 131 of file barcode.h.

Member Function Documentation

◆ backgroundColor()

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

Definition at line 143 of file barcode.cpp.

◆ byteArrayData()

QByteArray Barcode::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 91 of file barcode.cpp.

◆ create()

std::optional< Barcode > Barcode::create ( Prison::BarcodeType type)
static

Create a new barcode generator.

If a format is requested that is not supported by the current build due to missing/disabled optional dependencies, Barcode::format() will return Prison::Null.

Definition at line 29 of file barcode.cpp.

◆ data()

QString Barcode::data ( ) const

Textual content encoded in this barcode.

This returns an empty QString if binary content is set.

See also
byteArrayData()

Definition at line 86 of file barcode.cpp.

◆ dimensions()

Barcode::Dimensions Barcode::dimensions ( ) const

Returns the amount of dimensions of the barcode.

Definition at line 169 of file barcode.cpp.

◆ foregroundColor()

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

Definition at line 148 of file barcode.cpp.

◆ format()

Prison::BarcodeType Barcode::format ( ) const

Barcode format of this barcode generator.

Definition at line 81 of file barcode.cpp.

◆ minimumSize()

QSizeF Barcode::minimumSize ( ) 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

Definition at line 131 of file barcode.cpp.

◆ preferredSize()

QSizeF Barcode::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 137 of file barcode.cpp.

◆ setBackgroundColor()

void Barcode::setBackgroundColor ( const QColor & backgroundcolor)

sets the background color

Parameters
backgroundcolor- the new background color

Definition at line 153 of file barcode.cpp.

◆ setData() [1/2]

void Barcode::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 125 of file barcode.cpp.

◆ setData() [2/2]

void Barcode::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 117 of file barcode.cpp.

◆ setForegroundColor()

void Barcode::setForegroundColor ( const QColor & foregroundcolor)

sets the foreground color

Parameters
foregroundcolor- the new foreground color

Definition at line 161 of file barcode.cpp.

◆ toImage()

QImage Barcode::toImage ( const QSizeF & size)

Creates a image with a barcode on.

Returns
QImage with a barcode on, trying to match the requested
Parameters
size

If one of the dimensions of

Parameters
sizeis smaller than the matching dimension in minimumSize, a null QImage will be returned

Definition at line 96 of file barcode.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:12:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.