MauiKit Image Tools

ocs.h
1#pragma once
2
3#include <QObject>
4#include <QUrl>
5#include <QRect>
6#include <QVariantMap>
7#include "image2text_export.h"
8#include <QQmlParserStatus>
9
10namespace tesseract
11{
12class TessBaseAPI;
13}
14
15class OCRLanguageModel;
16
17typedef QVector<QVariantMap> TextBoxes;
18class IMAGE2TEXT_EXPORT OCS : public QObject, public QQmlParserStatus
19{
20 Q_OBJECT
21 Q_INTERFACES(QQmlParserStatus)
22 Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged)
23 Q_PROPERTY(QRect area READ area WRITE setArea NOTIFY areaChanged)
24
25 /** Immediately scan the image after a file url has been provided
26 */
27 Q_PROPERTY(bool autoRead READ autoRead WRITE setAutoRead NOTIFY autoReadChanged)
28
29 Q_PROPERTY(TextBoxes wordBoxes READ wordBoxes NOTIFY wordBoxesChanged)
30 Q_PROPERTY(TextBoxes paragraphBoxes READ paragraphBoxes NOTIFY paragraphBoxesChanged)
31 Q_PROPERTY(TextBoxes lineBoxes READ lineBoxes NOTIFY lineBoxesChanged)
32
33 Q_PROPERTY(BoxesType boxesType READ boxesType WRITE setBoxesType NOTIFY boxesTypeChanged)
34
35public:
36
37 enum BoxType
38 {
39 Nothing = 0x0,
40 Word = 0x1,
41 Paragraph = 0x2,
42 Line = 0x4
43 };
44 Q_DECLARE_FLAGS(BoxesType, BoxType)
45 Q_FLAG(BoxesType)
46 Q_ENUM(BoxType)
47
48 explicit OCS(QObject *parent = nullptr);
49 ~OCS();
50
51 QString filePath() const;
52 QRect area() const;
53 bool autoRead() const;
54 TextBoxes wordBoxes() const;
55 TextBoxes paragraphBoxes() const;
56 TextBoxes lineBoxes() const;
57 OCS::BoxesType boxesType();
58
59 /**
60 * @brief See the Qt documentation on the QQmlParserStatus.
61 */
62 void classBegin() override;
63
64 /**
65 * @brief See the Qt documentation on the QQmlParserStatus.
66 */
67 void componentComplete() override;
68
69public Q_SLOTS:
70 QString getText();
71 void getTextAsync();
72
73 void setFilePath(QString filePath);
74 void setArea(QRect area);
75 void setAutoRead(bool value);
76 void setBoxesType(OCS::BoxesType types);
77
78private:
79 tesseract::TessBaseAPI *m_tesseract;
80 OCRLanguageModel *m_languages;
81
82 QString m_filePath;
83 QRect m_area;
84 bool m_autoRead = false;
85
86 TextBoxes m_wordBoxes;
87 TextBoxes m_paragraphBoxes;
88 TextBoxes m_lineBoxes;
89
90 BoxesType m_boxesTypes;
91
92Q_SIGNALS:
93 void filePathChanged(QString filePath);
94 void areaChanged(QRect area);
95 void autoReadChanged();
96 void textReady(QString text);
97 void wordBoxesChanged();
98 void lineBoxesChanged();
99 void paragraphBoxesChanged();
100 void boxesTypeChanged();
101};
102Q_DECLARE_OPERATORS_FOR_FLAGS(OCS::BoxesType)
Q_ENUM(...)
Q_FLAG(...)
Q_INTERFACES(...)
Q_PROPERTY(...)
virtual void classBegin()=0
virtual void componentComplete()=0
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 7 2025 11:56:33 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.