QRCodeReader for iOS

This commit is contained in:
eugenyorbitsoftcom 2022-07-06 14:02:56 +06:00
parent 6744dce57e
commit 9aabe7c72e
7 changed files with 194 additions and 114 deletions

View file

@ -75,7 +75,8 @@ HEADERS += \
logger.h \ logger.h \
loghandler.h \ loghandler.h \
loglevel.h \ loglevel.h \
constants.h constants.h \
platforms/ios/QRCodeReader.h
SOURCES += \ SOURCES += \
configurators/cloak_configurator.cpp \ configurators/cloak_configurator.cpp \
@ -126,8 +127,8 @@ SOURCES += \
vpnconnection.cpp \ vpnconnection.cpp \
protocols/vpnprotocol.cpp \ protocols/vpnprotocol.cpp \
logger.cpp \ logger.cpp \
loghandler.cpp loghandler.cpp \
platforms/ios/QRCodeReader.cpp
RESOURCES += \ RESOURCES += \
resources.qrc resources.qrc
@ -296,8 +297,10 @@ ios {
platforms/ios/bigint.h \ platforms/ios/bigint.h \
platforms/ios/bigintipv6addr.h \ platforms/ios/bigintipv6addr.h \
platforms/ios/ipaddress.h \ platforms/ios/ipaddress.h \
platforms/ios/ipaddressrange.h \ platforms/ios/ipaddressrange.h
platforms/ios/QRCodeReader.h
SOURCES -= \
platforms/ios/QRCodeReader.cpp
SOURCES += \ SOURCES += \
protocols/ios_vpnprotocol.mm \ protocols/ios_vpnprotocol.mm \

View file

@ -0,0 +1,14 @@
#include "QRCodeReader.h"
QRCodeReader::QRCodeReader()
{
}
QRect QRCodeReader::cameraSize() {
return QRect();
}
void QRCodeReader::startReading() {}
void QRCodeReader::stopReading() {}
void QRCodeReader::setCameraSize(QRect) {};

View file

@ -157,5 +157,6 @@
<file>images/svg/control_point_black_24dp.svg</file> <file>images/svg/control_point_black_24dp.svg</file>
<file>images/svg/settings_suggest_black_24dp.svg</file> <file>images/svg/settings_suggest_black_24dp.svg</file>
<file>ui/qml/Controls/SvgButtonType.qml</file> <file>ui/qml/Controls/SvgButtonType.qml</file>
<file>ui/qml/Pages/PageQrDecoderIos.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -24,7 +24,7 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress, Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
GeneralSettings, AppSettings, NetworkSettings, ServerSettings, GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
ServerContainers, ServersList, ShareConnection, Sites, ServerContainers, ServersList, ShareConnection, Sites,
ProtocolSettings, ProtocolShare, QrDecoder, About}; ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About};
Q_ENUM_NS(Page) Q_ENUM_NS(Page)
static void declareQmlPageEnum() { static void declareQmlPageEnum() {

View file

@ -3,7 +3,6 @@ import QtQuick.Controls 2.12
import PageEnum 1.0 import PageEnum 1.0
import QtMultimedia 5.5 import QtMultimedia 5.5
import QZXing 3.2 import QZXing 3.2
import QRCodeReader 1.0
import "./" import "./"
import "../Controls" import "../Controls"
@ -27,7 +26,7 @@ PageBase {
} }
Connections { Connections {
target: QrDecoderLogic target: Qt.platform.os != "ios" ? QrDecoderLogic : nil
function onStartDecode() { function onStartDecode() {
console.debug("Starting QR decoder") console.debug("Starting QR decoder")
loader.sourceComponent = component loader.sourceComponent = component
@ -53,125 +52,108 @@ PageBase {
Item { Item {
anchors.fill: parent anchors.fill: parent
QRCodeReader { Camera
id: qrCodeReader {
id:camera
onCodeReaded: { focus {
QrDecoderLogic.onDetectedQrCode(code) focusMode: CameraFocus.FocusContinuous
focusPointMode: CameraFocus.FocusPointAuto
}
} }
Component.onCompleted: { VideoOutput
qrCodeReader.setCameraSize(Qt.rect(loader.x, {
loader.y, id: videoOutput
loader.width, source: camera
loader.height)) anchors.top: parent.top
qrCodeReader.startReading() anchors.bottom: parent.bottom
} anchors.left: parent.left
Component.onDestruction: qrCodeReader.stopReading() anchors.right: parent.right
autoOrientation: true
fillMode: VideoOutput.PreserveAspectFit
filters: [ zxingFilter ]
Rectangle {
color: "black"
opacity: 0.5
width: videoOutput.contentRect.width * 0.15
height: videoOutput.contentRect.height
x: (videoOutput.width - videoOutput.contentRect.width)/2
anchors.verticalCenter: videoOutput.verticalCenter
} }
// Camera Rectangle {
// { color: "black"
// id:camera opacity: 0.5
// focus { width: videoOutput.contentRect.width * 0.15
// focusMode: CameraFocus.FocusContinuous height: videoOutput.contentRect.height
// focusPointMode: CameraFocus.FocusPointAuto x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width * 0.15
// } anchors.verticalCenter: videoOutput.verticalCenter
// } }
// VideoOutput Rectangle {
// { color: "black"
// id: videoOutput opacity: 0.5
// source: camera width: videoOutput.contentRect.width * 0.7
// anchors.top: parent.top height: videoOutput.contentRect.height * 0.15
// anchors.bottom: parent.bottom x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
// anchors.left: parent.left y: (videoOutput.height - videoOutput.contentRect.height)/2
// anchors.right: parent.right }
// autoOrientation: true
// fillMode: VideoOutput.PreserveAspectFit
// filters: [ zxingFilter ]
Rectangle {
color: "black"
opacity: 0.5
width: videoOutput.contentRect.width * 0.7
height: videoOutput.contentRect.height * 0.15
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height * 0.15
}
// Rectangle { LabelType {
// color: "black" width: parent.width
// opacity: 0.5 text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
// width: videoOutput.contentRect.width * 0.15 horizontalAlignment: Text.AlignLeft
// height: videoOutput.contentRect.height visible: QrDecoderLogic.totalChunksCount > 0
// x: (videoOutput.width - videoOutput.contentRect.width)/2 anchors.horizontalCenter: videoOutput.horizontalCenter
// anchors.verticalCenter: videoOutput.verticalCenter y: videoOutput.height/2 + videoOutput.contentRect.height/2
// } }
}
// Rectangle { QZXingFilter
// color: "black" {
// opacity: 0.5 id: zxingFilter
// width: videoOutput.contentRect.width * 0.15 orientation: videoOutput.orientation
// height: videoOutput.contentRect.height captureRect: {
// x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width * 0.15 // setup bindings
// anchors.verticalCenter: videoOutput.verticalCenter videoOutput.contentRect;
// } videoOutput.sourceRect;
return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
)));
}
// Rectangle { decoder {
// color: "black" enabledDecoders: QZXing.DecoderFormat_QR_CODE
// opacity: 0.5
// width: videoOutput.contentRect.width * 0.7
// height: videoOutput.contentRect.height * 0.15
// x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
// y: (videoOutput.height - videoOutput.contentRect.height)/2
// }
// Rectangle { onTagFound: {
// color: "black" QrDecoderLogic.onDetectedQrCode(tag)
// opacity: 0.5 }
// width: videoOutput.contentRect.width * 0.7
// height: videoOutput.contentRect.height * 0.15
// x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
// y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height * 0.15
// }
// LabelType { tryHarder: true
// width: parent.width }
// text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
// horizontalAlignment: Text.AlignLeft
// visible: QrDecoderLogic.totalChunksCount > 0
// anchors.horizontalCenter: videoOutput.horizontalCenter
// y: videoOutput.height/2 + videoOutput.contentRect.height/2
// }
// }
// QZXingFilter property int framesDecoded: 0
// { property real timePerFrameDecode: 0
// id: zxingFilter
// orientation: videoOutput.orientation
// captureRect: {
// // setup bindings
// videoOutput.contentRect;
// videoOutput.sourceRect;
// return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
// 0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
// )));
// }
// decoder { onDecodingFinished:
// enabledDecoders: QZXing.DecoderFormat_QR_CODE {
timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
// onTagFound: { framesDecoded++;
// QrDecoderLogic.onDetectedQrCode(tag) if(succeeded)
// } console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
}
// tryHarder: true }
// }
// property int framesDecoded: 0
// property real timePerFrameDecode: 0
// onDecodingFinished:
// {
// timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
// framesDecoded++;
// if(succeeded)
// console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
// }
// }
} }

View file

@ -0,0 +1,76 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import PageEnum 1.0
import QRCodeReader 1.0
import "./"
import "../Controls"
import "../Config"
PageBase {
id: root
page: PageEnum.QrDecoderIos
logic: QrDecoderLogic
onDeactivated: {
console.debug("Stopping QR decoder")
loader.sourceComponent = undefined
}
BackButton {
}
Caption {
id: caption
text: qsTr("Import configuration")
}
Connections {
target: Qt.platform.os == "ios" ? QrDecoderLogic : nil
function onStartDecode() {
console.debug("Starting QR decoder")
loader.sourceComponent = component
}
function onStopDecode() {
console.debug("Stopping QR decoder")
loader.sourceComponent = undefined
}
}
Loader {
id: loader
anchors.top: caption.bottom
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
}
Component {
id: component
Item {
anchors.fill: parent
QRCodeReader {
id: qrCodeReader
onCodeReaded: {
QrDecoderLogic.onDetectedQrCode(code)
}
Component.onCompleted: {
qrCodeReader.setCameraSize(Qt.rect(loader.x,
loader.y,
loader.width,
loader.height))
qrCodeReader.startReading()
}
Component.onDestruction: qrCodeReader.stopReading()
}
}
}
}

View file

@ -135,8 +135,12 @@ PageBase {
text: qsTr("Scan QR code") text: qsTr("Scan QR code")
visible: StartPageLogic.pushButtonConnectVisible visible: StartPageLogic.pushButtonConnectVisible
onClicked: { onClicked: {
if (Qt.platform.os == "ios") {
UiLogic.goToPage(PageEnum.QrDecoderIos)
} else {
UiLogic.goToPage(PageEnum.QrDecoder) UiLogic.goToPage(PageEnum.QrDecoder)
} }
}
enabled: StartPageLogic.pushButtonConnectEnabled enabled: StartPageLogic.pushButtonConnectEnabled
} }