MauiKit Image Tools

OCRPage.qml
1// Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
2// Copyright 2018-2020 Nitrux Latinoamericana S.C.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6import QtQuick 2.13
7
8import QtQuick.Controls 2.13
9import QtQuick.Layouts 1.3
10import QtQuick.Window 2.13
11
12import org.mauikit.controls 1.3 as Maui
13import org.mauikit.imagetools 1.3 as IT
14import org.kde.kquickimageeditor 1.0 as KQuickImageEditor
15
16
17Maui.Page
18{
19 id: control
20
21 property alias url : _ocr.filePath
22
23 IT.OCR
24 {
25 id: _ocr
26 }
27
28 headBar.rightContent: Maui.ToolButtonMenu
29 {
30 icon.name: "format-text-bold"
31
32
33 MenuItem
34 {
35 text: i18n("Read Area")
36 icon.name: "transform-crop"
37 onTriggered:
38 {
39
40 control.push(_ocrComponent)
41
42 }
43 }
44
45 MenuItem
46 {
47 text: i18n("Read All")
48 icon.name: "viewimage"
49 onTriggered:
50 {
51 console.log(_ocr.getText())
52 }
53 }
54
55 MenuSeparator{}
56
57 MenuItem
58 {
59 text: i18n("Configure")
60 }
61 }
62
63 Maui.SplitView
64 {
65 anchors.fill: parent
66
67 KQuickImageEditor.ImageItem
68 {
69 id: editImage
70 readonly property real ratioX: editImage.paintedWidth / editImage.nativeWidth;
71 readonly property real ratioY: editImage.paintedHeight / editImage.nativeHeight;
72
73 fillMode: KQuickImageEditor.ImageItem.PreserveAspectFit
74 image: imageDoc.image
75
76 SplitView.fillHeight: true
77 SplitView.fillWidth: true
78
79
80 KQuickImageEditor.ImageDocument
81 {
82 id: imageDoc
83 path: control.url
84 }
85
86 KQuickImageEditor.SelectionTool
87 {
88 id: selectionTool
89 visible: true
90 width: editImage.paintedWidth
91 height: editImage.paintedHeight
92 x: editImage.horizontalPadding
93 y: editImage.verticalPadding
94
95 KQuickImageEditor.CropBackground
96 {
97 anchors.fill: parent
98 z: -1
99 insideX: selectionTool.selectionX
100 insideY: selectionTool.selectionY
101 insideWidth: selectionTool.selectionWidth
102 insideHeight: selectionTool.selectionHeight
103 }
104 Connections {
105 target: selectionTool.selectionArea
106 function onDoubleClicked() {
107 _ocr.area = Qt.rect(selectionTool.selectionX / editImage.ratioX,
108 selectionTool.selectionY / editImage.ratioY,
109 selectionTool.selectionWidth / editImage.ratioX,
110 selectionTool.selectionHeight / editImage.ratioY)
111
112
113 _listModel.append({'text': _ocr.getText()})
114 }
115 }
116 }
117
118 onImageChanged:
119 {
120 selectionTool.selectionX = 0
121 selectionTool.selectionY = 0
122 selectionTool.selectionWidth = Qt.binding(() => selectionTool.width)
123 selectionTool.selectionHeight = Qt.binding(() => selectionTool.height)
124 }
125 }
126
127 Maui.Page
128 {
129 visible: _textArea.text
130 SplitView.fillWidth: true
131 SplitView.fillHeight: true
132 SplitView.maximumWidth: 400
133 SplitView.maximumHeight: 400
134 SplitView.preferredWidth: 400
135 SplitView.preferredHeight: 400
136
137 Maui.Theme.colorSet: Maui.Theme.Window
138
139 ListModel { id: _listModel}
140
141 Maui.ListBrowser
142 {
143 id: _textArea
144 anchors.fill: parent
145
146 model: _listModel
147
148 delegate: ItemDelegate
149 {
150 id: _delegate
151 text: model.text
152 width: ListView.view.width
153 onClicked: Maui.Handy.copyTextToClipboard(model.text)
154
155 background: Rectangle
156 {
157 radius: Maui.Style.radiusV
158 color: Maui.Theme.alternateBackgroundColor
159 }
160
161 contentItem: TextArea
162 {
163 text: _delegate.text
164 }
165 }
166 }
167 }
168
169 }
170
171}
QString i18n(const char *text, const TYPE &arg...)
QString path(const QString &relativePath)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:32:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.