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 Maui.SplitViewItem
68 {
69 autoClose: false
70 SplitView.fillHeight: true
71 SplitView.fillWidth: true
72
73 KQuickImageEditor.ImageItem
74 {
75 id: editImage
76 anchors.fill: parent
77
78 readonly property real ratioX: editImage.paintedWidth / editImage.nativeWidth;
79 readonly property real ratioY: editImage.paintedHeight / editImage.nativeHeight;
80
81 fillMode: KQuickImageEditor.ImageItem.PreserveAspectFit
82 image: imageDoc.image
83
84 KQuickImageEditor.ImageDocument
85 {
86 id: imageDoc
87 path: control.url
88 }
89
90 KQuickImageEditor.SelectionTool
91 {
92 id: selectionTool
93 visible: true
94 width: editImage.paintedWidth
95 height: editImage.paintedHeight
96 x: editImage.horizontalPadding
97 y: editImage.verticalPadding
98
99 KQuickImageEditor.CropBackground
100 {
101 anchors.fill: parent
102 z: -1
103 insideX: selectionTool.selectionX
104 insideY: selectionTool.selectionY
105 insideWidth: selectionTool.selectionWidth
106 insideHeight: selectionTool.selectionHeight
107 }
108 Connections {
109 target: selectionTool.selectionArea
110 function onDoubleClicked() {
111 _ocr.area = Qt.rect(selectionTool.selectionX / editImage.ratioX,
112 selectionTool.selectionY / editImage.ratioY,
113 selectionTool.selectionWidth / editImage.ratioX,
114 selectionTool.selectionHeight / editImage.ratioY)
115
116
117 _listModel.append({'text': _ocr.getText()})
118 }
119 }
120 }
121
122 onImageChanged:
123 {
124 selectionTool.selectionX = 0
125 selectionTool.selectionY = 0
126 selectionTool.selectionWidth = Qt.binding(() => selectionTool.width)
127 selectionTool.selectionHeight = Qt.binding(() => selectionTool.height)
128 }
129 }
130 }
131
132 Maui.SplitViewItem
133 {
134 autoClose: false
135 visible: _textArea.text
136 SplitView.fillWidth: true
137 SplitView.fillHeight: true
138 SplitView.maximumWidth: 400
139 SplitView.maximumHeight: 400
140 SplitView.preferredWidth: 400
141 SplitView.preferredHeight: 400
142
143 Maui.Page
144 {
145 anchors.fill: parent
146 Maui.Theme.colorSet: Maui.Theme.Window
147
148 ListModel { id: _listModel}
149
150 Maui.ListBrowser
151 {
152 id: _textArea
153 anchors.fill: parent
154
155 model: _listModel
156
157 delegate: ItemDelegate
158 {
159 id: _delegate
160 text: model.text
161 width: ListView.view.width
162 onClicked: Maui.Handy.copyTextToClipboard(model.text)
163
164 background: Rectangle
165 {
166 radius: Maui.Style.radiusV
167 color: Maui.Theme.alternateBackgroundColor
168 }
169
170 contentItem: TextArea
171 {
172 text: _delegate.text
173 }
174 }
175 }
176 }
177 }
178
179 }
180
181}
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 Fri Nov 29 2024 11:49:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.