-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added QR Code Input * QR code logic finished * Added fake classes to use QR camera component in Gallery app * Use ApplicationWindow.window.width instead of window.width * Applied review comments * C++ formatting
- Loading branch information
Showing
11 changed files
with
292 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
import QtQuick | ||
import QtQuick.Controls | ||
import QtMultimedia | ||
import lc 1.0 as InputClass | ||
|
||
Drawer { | ||
id: root | ||
|
||
signal scanFinished( var data ) | ||
|
||
width: ApplicationWindow.window.width | ||
height: ApplicationWindow.window.height + 40 * __dp | ||
edge: Qt.BottomEdge | ||
dim: true | ||
interactive: false | ||
dragMargin: 0 | ||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside | ||
|
||
CaptureSession { | ||
id: captureSession | ||
|
||
camera: Camera { | ||
id: camera | ||
active: true | ||
focusMode: Camera.FocusModeAutoNear | ||
} | ||
videoOutput: videoOutput | ||
} | ||
|
||
VideoOutput { | ||
id: videoOutput | ||
|
||
anchors.fill: parent | ||
fillMode: VideoOutput.PreserveAspectCrop | ||
} | ||
|
||
InputClass.QrCodeDecoder { | ||
id: qrcodeScanner | ||
|
||
videoSink: videoOutput.videoSink | ||
|
||
onCodeScanned: function( codeData ) { | ||
root.unload() | ||
root.scanFinished( codeData ) | ||
} | ||
} | ||
|
||
Canvas { | ||
id: canvas | ||
|
||
anchors.fill: parent | ||
opacity: 0.8 | ||
|
||
onPaint: { | ||
var ctx = getContext("2d"); | ||
let w = parent.width | ||
let h = parent.height | ||
ctx.fillStyle = __style.nightColor | ||
ctx.fillRect(0, 0, parent.width, parent.height); | ||
ctx.fill(); | ||
if(parent.width < parent.height) | ||
ctx.clearRect(w / 4, h / 2 - w / 4, w / 2, w / 2) | ||
else | ||
ctx.clearRect(w / 2 - h / 4, h / 4, h / 2, h / 2) | ||
} | ||
} | ||
|
||
Item { | ||
width: parent.width | ||
height: (parent.width < parent.height) ? parent.height / 2 - parent.width / 4 : parent.height / 4 | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
|
||
Column { | ||
id: textColumn | ||
|
||
width: parent.width - 40 * __dp | ||
anchors.centerIn: parent | ||
spacing: 10 * __dp | ||
|
||
Text { | ||
width: parent.width | ||
text: qsTr("Scan the QR code") | ||
verticalAlignment: Text.AlignVCenter | ||
horizontalAlignment: Text.AlignHCenter | ||
font: __style.t1 | ||
wrapMode: Text.WordWrap | ||
color: __style.whiteColor | ||
} | ||
|
||
Text { | ||
width: parent.width | ||
text: qsTr("Please make sure that the lense is clear.") | ||
verticalAlignment: Text.AlignVCenter | ||
horizontalAlignment: Text.AlignHCenter | ||
font: __style.p5 | ||
wrapMode: Text.WordWrap | ||
color: __style.whiteColor | ||
} | ||
} | ||
} | ||
|
||
Image { | ||
id: closeButton | ||
|
||
anchors.horizontalCenter: parent.horizontalCenter | ||
anchors.bottom: parent.bottom | ||
anchors.bottomMargin: 20 * __dp | ||
source: __style.closeButtonIcon | ||
|
||
MouseArea { | ||
anchors.fill: parent | ||
onClicked: { | ||
unload() | ||
close() | ||
} | ||
} | ||
} | ||
|
||
function unload() { | ||
qrcodeScanner.videoSink = null | ||
camera.active = false | ||
captureSession.videoOutput = null | ||
captureSession.camera = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
import QtQuick | ||
import QtQuick.Controls | ||
import QtQuick.Controls.Basic | ||
import "../components" | ||
|
||
MMAbstractEditor { | ||
id: root | ||
|
||
property var parentValue: parent.value | ||
property bool isReadOnly: parent.readOnly ?? false | ||
|
||
property alias placeholderText: textField.placeholderText | ||
property alias text: textField.text | ||
|
||
signal editorValueChanged( var newValue, bool isNull ) | ||
|
||
hasFocus: textField.activeFocus | ||
enabled: !root.isReadOnly | ||
|
||
content: TextField { | ||
id: textField | ||
|
||
anchors.fill: parent | ||
anchors.verticalCenter: parent.verticalCenter | ||
|
||
text: root.parentValue !== undefined ? root.parentValue : '' | ||
readOnly: !root.enabled | ||
color: root.enabled ? __style.nightColor : __style.mediumGreenColor | ||
placeholderTextColor: __style.nightAlphaColor | ||
font: __style.p5 | ||
hoverEnabled: true | ||
background: Rectangle { | ||
color: __style.transparentColor | ||
} | ||
} | ||
|
||
rightAction: MMIcon { | ||
property bool pressed: false | ||
|
||
height: parent.height | ||
|
||
source: __style.qrCodeIcon | ||
color: root.enabled ? __style.forestColor : __style.mediumGreenColor | ||
} | ||
|
||
onRightActionClicked: { | ||
if ( !root.enabled ) | ||
return | ||
if (!__inputUtils.acquireCameraPermission()) | ||
return | ||
codeScannerLoader.active = true | ||
codeScannerLoader.focus = true | ||
} | ||
|
||
Loader { | ||
id: codeScannerLoader | ||
|
||
asynchronous: true | ||
active: false | ||
sourceComponent: readerComponent | ||
} | ||
|
||
Component { | ||
id: readerComponent | ||
|
||
MMCodeScanner { | ||
focus: true | ||
|
||
Component.onCompleted: open() | ||
onClosed: codeScannerLoader.active = false | ||
onScanFinished: function( captured ) { | ||
root.editorValueChanged( captured, false ) | ||
codeScannerLoader.active = false | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef INPUTUTILS_H | ||
#define INPUTUTILS_H | ||
|
||
#include <QObject> | ||
|
||
class InputUtils: public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit InputUtils( QObject *parent = nullptr ) {}; | ||
|
||
Q_INVOKABLE bool acquireCameraPermission() { return true; } | ||
}; | ||
|
||
#endif // INPUTUTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef QRCODEDECODER_H | ||
#define QRCODEDECODER_H | ||
|
||
#include <QObject> | ||
#include <QPointer> | ||
|
||
class QrCodeDecoder : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY( QObject *videoSink READ videoSink WRITE setVideoSink NOTIFY videoSinkChanged ); | ||
|
||
public: | ||
|
||
explicit QrCodeDecoder( QObject *parent = nullptr ) {}; | ||
|
||
QObject *videoSink() {return nullptr;}; | ||
void setVideoSink( QObject *videoSink ) {}; | ||
|
||
signals: | ||
void codeScanned( const QString &codeData ); | ||
void videoSinkChanged(); | ||
|
||
private: | ||
QPointer<QObject> mVideoSink; | ||
}; | ||
|
||
#endif // QRCODEDECODER_H |
5da384e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS - version 24.01.506011 just submitted!