Warning, /maui/mauikit-imagetools/src/controls.5/image2text/OCRPage.qml is written in an unsupported language. File is not indexed.

0001 // Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
0002 // Copyright 2018-2020 Nitrux Latinoamericana S.C.
0003 //
0004 // SPDX-License-Identifier: GPL-3.0-or-later
0005 
0006 import QtQuick 2.13
0007 
0008 import QtQuick.Controls 2.13
0009 import QtQuick.Layouts 1.3
0010 import QtQuick.Window 2.13
0011 
0012 import org.mauikit.controls 1.3 as Maui
0013 import org.mauikit.imagetools 1.3 as IT
0014 import org.kde.kquickimageeditor 1.0 as KQuickImageEditor
0015 
0016 
0017 Maui.Page
0018 {
0019     id: control
0020 
0021     property alias url : _ocr.filePath
0022 
0023     IT.OCR
0024     {
0025         id: _ocr
0026     }
0027 
0028     headBar.rightContent: Maui.ToolButtonMenu
0029     {
0030         icon.name: "format-text-bold"
0031 
0032 
0033         MenuItem
0034         {
0035             text: i18n("Read Area")
0036             icon.name: "transform-crop"
0037             onTriggered:
0038             {
0039 
0040                 control.push(_ocrComponent)
0041 
0042             }
0043         }
0044 
0045         MenuItem
0046         {
0047             text: i18n("Read All")
0048             icon.name: "viewimage"
0049             onTriggered:
0050             {
0051                 console.log(_ocr.getText())
0052             }
0053         }
0054 
0055         MenuSeparator{}
0056 
0057         MenuItem
0058         {
0059             text: i18n("Configure")
0060         }
0061     }
0062 
0063     Maui.SplitView
0064     {
0065         anchors.fill: parent
0066 
0067         KQuickImageEditor.ImageItem
0068         {
0069             id: editImage
0070             readonly property real ratioX: editImage.paintedWidth / editImage.nativeWidth;
0071             readonly property real ratioY: editImage.paintedHeight / editImage.nativeHeight;
0072 
0073             fillMode: KQuickImageEditor.ImageItem.PreserveAspectFit
0074             image: imageDoc.image
0075 
0076             SplitView.fillHeight: true
0077             SplitView.fillWidth: true
0078 
0079 
0080             KQuickImageEditor.ImageDocument
0081             {
0082                 id: imageDoc
0083                 path: control.url
0084             }
0085 
0086             KQuickImageEditor.SelectionTool
0087             {
0088                 id: selectionTool
0089                 visible: true
0090                 width: editImage.paintedWidth
0091                 height: editImage.paintedHeight
0092                 x: editImage.horizontalPadding
0093                 y: editImage.verticalPadding
0094 
0095                 KQuickImageEditor.CropBackground
0096                 {
0097                     anchors.fill: parent
0098                     z: -1
0099                     insideX: selectionTool.selectionX
0100                     insideY: selectionTool.selectionY
0101                     insideWidth: selectionTool.selectionWidth
0102                     insideHeight: selectionTool.selectionHeight
0103                 }
0104                 Connections {
0105                     target: selectionTool.selectionArea
0106                     function onDoubleClicked() {
0107                         _ocr.area = Qt.rect(selectionTool.selectionX / editImage.ratioX,
0108                                             selectionTool.selectionY / editImage.ratioY,
0109                                             selectionTool.selectionWidth / editImage.ratioX,
0110                                             selectionTool.selectionHeight / editImage.ratioY)
0111 
0112 
0113                         _listModel.append({'text': _ocr.getText()})
0114                     }
0115                 }
0116             }
0117 
0118             onImageChanged:
0119             {
0120                 selectionTool.selectionX = 0
0121                 selectionTool.selectionY = 0
0122                 selectionTool.selectionWidth = Qt.binding(() => selectionTool.width)
0123                 selectionTool.selectionHeight = Qt.binding(() => selectionTool.height)
0124             }
0125         }
0126 
0127         Maui.Page
0128         {
0129             visible: _textArea.text
0130             SplitView.fillWidth: true
0131             SplitView.fillHeight: true
0132             SplitView.maximumWidth: 400
0133             SplitView.maximumHeight: 400
0134             SplitView.preferredWidth: 400
0135             SplitView.preferredHeight: 400
0136 
0137             Maui.Theme.colorSet: Maui.Theme.Window
0138 
0139             ListModel { id: _listModel}
0140 
0141             Maui.ListBrowser
0142             {
0143                 id: _textArea
0144                 anchors.fill: parent
0145 
0146                 model: _listModel
0147 
0148                 delegate: ItemDelegate
0149                 {
0150                     id: _delegate
0151                     text: model.text
0152                     width: ListView.view.width
0153                     onClicked: Maui.Handy.copyTextToClipboard(model.text)
0154 
0155                     background: Rectangle
0156                     {
0157                         radius: Maui.Style.radiusV
0158                         color: Maui.Theme.alternateBackgroundColor
0159                     }
0160 
0161                     contentItem: TextArea
0162                     {
0163                         text: _delegate.text
0164                     }
0165                 }
0166             }
0167         }
0168 
0169     }
0170 
0171 }