File indexing completed on 2024-05-12 04:01:32

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: MIT
0004 */
0005 
0006 #ifndef PRISON_VIDEOSCANNER_H
0007 #define PRISON_VIDEOSCANNER_H
0008 
0009 #include "prisonscanner_export.h"
0010 #include "scanresult.h"
0011 
0012 #include <QObject>
0013 #include <QVideoSink>
0014 
0015 #include <memory>
0016 
0017 namespace Prison
0018 {
0019 
0020 class VideoScannerPrivate;
0021 
0022 /** Scans a live video feed for barcodes.
0023  *
0024  *  In Qt5 this can be added as a video filter to a VideoOutput element.
0025  *  In Qt6 this can be connected to a QVideoSink object.
0026  *
0027  *  @since 5.94
0028  */
0029 class PRISONSCANNER_EXPORT VideoScanner : public QObject
0030 {
0031     Q_OBJECT
0032     Q_PROPERTY(Prison::ScanResult result READ result NOTIFY resultChanged)
0033     Q_PROPERTY(Prison::Format::BarcodeFormats formats READ formats WRITE setFormats NOTIFY formatsChanged)
0034 
0035     Q_PROPERTY(QVideoSink *videoSink READ videoSink WRITE setVideoSink NOTIFY videoSinkChanged)
0036 
0037 public:
0038     explicit VideoScanner(QObject *parent = nullptr);
0039     ~VideoScanner();
0040 
0041     /** The latest result of the barcode scan. */
0042     ScanResult result() const;
0043 
0044     /** The barcode formats the scanner should look for.
0045      *  By default all supported formats are enabled.
0046      */
0047     Format::BarcodeFormats formats() const;
0048     /**
0049      * Sets the barcode formats to detect.
0050      * @param formats can be OR'ed values from Format::BarcodeFormats.
0051      */
0052     void setFormats(Format::BarcodeFormats formats);
0053 
0054     /** The video sink being scanned for barcodes. */
0055     QVideoSink *videoSink() const;
0056     /** Sets the video sink to scan for barcodes. */
0057     void setVideoSink(QVideoSink *sink);
0058 
0059 Q_SIGNALS:
0060     /** Emitted whenever we get a new scan result, as long as any
0061      *  property of the result changes. On a live video feed this can
0062      *  be very frequently due to the changes of the position of the detected
0063      *  barcode. This is therefore useful e.g. for marking the position
0064      *  of the detected barcode.
0065      *  @see resultContentChanged
0066      */
0067     void resultChanged(const Prison::ScanResult &scanResult);
0068 
0069     /** Emitted when a barcode with a new content has been detected, but
0070      *  not when merely the position of a barcode changes in the video stream.
0071      *  This is useful e.g. for continuously scanning multiple codes in one go.
0072      *  @see resultChanged
0073      */
0074     void resultContentChanged(const Prison::ScanResult &scanResult);
0075 
0076     void formatsChanged();
0077     void videoSinkChanged();
0078 
0079 private:
0080     std::unique_ptr<VideoScannerPrivate> d;
0081 };
0082 
0083 }
0084 
0085 #endif // PRISON_VIDEOSCANNER_H