File indexing completed on 2024-12-29 04:50:01

0001 /*
0002     SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <KItinerary/BarcodeDecoder>
0010 
0011 #include <QDateTime>
0012 #include <QJSValue>
0013 #include <QObject>
0014 
0015 namespace KItinerary {
0016 
0017 class BarcodeDecoder;
0018 
0019 namespace JsApi {
0020 
0021 /** Barcode decoding functions. */
0022 class Barcode : public QObject
0023 {
0024     Q_OBJECT
0025 public:
0026     /** Decode a PDF417 barcode image.
0027      *  @param img An image containing the barcode, e.g. a PdfImage instance.
0028      */
0029     Q_INVOKABLE QString decodePdf417(const QVariant &img) const;
0030     /** Decode a Aztec barcode image.
0031      *  @param img An image containing the barcode, e.g. a PdfImage instance.
0032      */
0033     Q_INVOKABLE QString decodeAztec(const QVariant &img) const;
0034     /** Decode a Aztec barcode image containing binary data.
0035      *  @param img An image containing the barcode, e.g. a PdfImage instance.
0036      *  @return a JS ArrayBuffer
0037      */
0038     Q_INVOKABLE QJSValue decodeAztecBinary(const QVariant &img) const;
0039     /** Decode as QR barcode image.
0040      *  @param img An image containing the barcode, e.g. a PdfImage instance.
0041      */
0042     Q_INVOKABLE QString decodeQR(const QVariant &img) const;
0043     /** Decode a DataMatrix barcode image.
0044      *  @param img An image containing the barcode, e.g. a PdfImage instance.
0045      */
0046     Q_INVOKABLE QString decodeDataMatrix(const QVariant &img) const;
0047     /** Attempts to decode any barcode found in the given image.
0048      *  This is the most expensive of the above option, and should only be
0049      *  used if no other alternative is available.
0050      *  @param img An image containing the barcode, e.g. a PdfImage instance.
0051      */
0052     Q_INVOKABLE QString decodeAnyBarcode(const QVariant &img) const;
0053 
0054     ///@cond internal
0055     void setDecoder(const BarcodeDecoder *decoder);
0056     ///@endcond
0057 
0058 private:
0059     QString decodeBarcode(const QVariant &img, BarcodeDecoder::BarcodeTypes hints) const;
0060 
0061     const BarcodeDecoder *m_decoder = nullptr;
0062 };
0063 
0064 }
0065 }
0066