Commit ed56d446 authored by Volker Krause's avatar Volker Krause
Browse files

Improve barcode scan mode discoverability and state tracking

So far this was only available by double-tapping the barcode, now there's
also a corresponding action. The scan mode is now also automatically ended
again when leaving the page it was activated on.
parent 250bd93e
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.15
import org.kde.solidextras 1.0 as Solid
/** Shared logic and state for the barcode scan mode.
* That is, disable screen locking and switch to full brightness.
*/
QtObject {
id: controller
/** Whether or not we are in barcode scan mode. */
property bool enabled: false
/** The page showing the barcode.
* Scan mode will automatically be disabled when the page is left or moves down in the page stack.
*/
property var page
function toggle() {
controller.enabled = !controller.enabled;
}
onEnabledChanged: function() {
console.log("switching barcode scan mode", controller.enabled);
Solid.BrightnessManager.toggleBrightness();
Solid.LockManager.toggleInhibitScreenLock(i18n("In barcode scanning mode"));
}
property var __pageWatcher: Connections {
target: page
function onVisibleChanged() {
controller.enabled = false;
}
}
property var __pageStackWather: Connections {
target: applicationWindow().pageStack
function onCurrentItemChanged() {
if (applicationWindow().pageStack.currentItem != page) {
controller.enabled = false;
}
}
}
Component.onDestruction: controller.enabled = false
}
......@@ -4,7 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.5
import QtQuick 2.15
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.17 as Kirigami
......@@ -20,6 +20,9 @@ Item {
implicitWidth: Math.max(bodyLayout.implicitWidth, 332)
/** Double tap on the barcode to request scan mode. */
signal scanModeToggled()
ColumnLayout {
id: topLayout
spacing: 0
......@@ -188,7 +191,12 @@ Item {
}
// barcode
App.PkPassBarcode { pass: root.pass }
App.PkPassBarcode {
pass: root.pass
TapHandler {
onDoubleTapped: root.scanModeToggled()
}
}
ColumnLayout {
id: backLayout
......
......@@ -24,6 +24,15 @@ App.DetailsPage {
}
}
actions.main: Kirigami.Action {
icon.name: "view-barcode-qr"
text: i18n("Barcode Scan Mode")
onTriggered: scanModeController.toggle()
visible: ticketToken.hasBarcode
checkable: true
checked: scanModeController.enabled
}
Component {
id: alternativeAction
Kirigami.Action {
......@@ -39,6 +48,11 @@ App.DetailsPage {
actions.contextualActions.push(alternativeAction.createObject(root));
}
BarcodeScanModeController {
id: scanModeController
page: root
}
ColumnLayout {
width: parent.width
......@@ -51,12 +65,14 @@ App.DetailsPage {
// ticket barcode
App.TicketTokenDelegate {
id: ticketToken
resIds: ReservationManager.reservationsForBatch(root.batchId)
onCurrentReservationIdChanged: {
if (!currentReservationId)
return;
root.currentReservationId = currentReservationId;
}
onScanModeToggled: scanModeController.toggle()
}
Kirigami.FormLayout {
......
......@@ -144,6 +144,7 @@ if (ANDROID)
notifications
question
settings-configure
view-barcode-qr
view-calendar-day
view-list-symbolic
view-refresh
......
......@@ -21,6 +21,20 @@ App.DetailsPage {
}
}
actions.main: Kirigami.Action {
icon.name: "view-barcode-qr"
text: i18n("Barcode Scan Mode")
onTriggered: scanModeController.toggle()
visible: ticketToken.hasBarcode
checkable: true
checked: scanModeController.enabled
}
BarcodeScanModeController {
id: scanModeController
page: root
}
ColumnLayout {
width: parent.width
......@@ -33,9 +47,10 @@ App.DetailsPage {
}
App.TicketTokenDelegate {
id: ticketToken
resIds: ReservationManager.reservationsForBatch(root.batchId)
onScanModeToggled: scanModeController.toggle()
}
Kirigami.FormLayout {
Layout.fillWidth: true
......
......@@ -4,7 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.5
import QtQuick 2.15
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import QtGraphicalEffects 1.0 as Effects
......@@ -20,6 +20,9 @@ Item {
implicitHeight: bodyBackground.implicitHeight
implicitWidth: 332 //Math.max(topLayout.implicitWidth, 332)
/** Double tap on the barcode to request scan mode. */
signal scanModeToggled()
Rectangle {
id: bodyBackground
color: pass.backgroundColor
......@@ -185,7 +188,12 @@ Item {
}
// barcode
App.PkPassBarcode { pass: root.pass }
App.PkPassBarcode {
pass: root.pass
TapHandler {
onDoubleTapped: scanModeToggled()
}
}
// footer
Image {
......
......@@ -30,6 +30,20 @@ App.DetailsPage {
}
}
actions.main: Kirigami.Action {
icon.name: "view-barcode-qr"
text: i18n("Barcode Scan Mode")
onTriggered: scanModeController.toggle()
visible: ticketToken.hasBarcode
checkable: true
checked: scanModeController.enabled
}
BarcodeScanModeController {
id: scanModeController
page: root
}
ColumnLayout {
width: parent.width
......@@ -42,13 +56,14 @@ App.DetailsPage {
// ticket barcode
App.TicketTokenDelegate {
id: ticketDelegate
id: ticketToken
resIds: ReservationManager.reservationsForBatch(root.batchId)
onCurrentReservationIdChanged: {
if (!currentReservationId)
return;
root.currentReservationId = currentReservationId;
}
onScanModeToggled: scanModeController.toggle()
}
Kirigami.FormLayout {
......@@ -57,7 +72,7 @@ App.DetailsPage {
// sequence number belongs to the selected barcode
QQC2.Label {
Kirigami.FormData.label: i18n("Sequence Number:")
text: ReservationManager.reservation(ticketDelegate.currentReservationId).passengerSequenceNumber
text: ReservationManager.reservation(ticketToken.currentReservationId).passengerSequenceNumber
visible: text
}
......
......@@ -8,7 +8,6 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.17 as Kirigami
import org.kde.prison 1.0 as Prison
import org.kde.solidextras 1.0 as Solid
import org.kde.khealthcertificate 1.0 as KHC
import org.kde.itinerary 1.0
......@@ -33,12 +32,4 @@ Rectangle {
case KHC.HealthCertificate.Invalid: return Kirigami.Theme.negativeTextColor;
default: return "transparent"
}
MouseArea {
anchors.fill: parent
onDoubleClicked: {
Solid.BrightnessManager.toggleBrightness()
Solid.LockManager.toggleInhibitScreenLock(i18n("In barcode scanning mode"))
}
}
}
......@@ -17,6 +17,14 @@ Kirigami.ScrollablePage {
title: i18n("Health Certificates")
actions {
main: Kirigami.Action {
icon.name: "view-barcode-qr"
text: i18n("Barcode Scan Mode")
onTriggered: scanModeController.toggle()
visible: certSelector.currentValue != undefined
checkable: true
checked: scanModeController.enabled
}
contextualActions: [
Kirigami.Action {
iconName: "edit-paste"
......@@ -97,6 +105,7 @@ Kirigami.ScrollablePage {
}
Loader {
id: loader
sourceComponent: {
switch (certSelector.currentValue.type) {
case KHC.HealthCertificate.Vaccination:
......@@ -109,5 +118,17 @@ Kirigami.ScrollablePage {
return helpText;
}
}
BarcodeScanModeController {
id: scanModeController
page: root
}
Connections {
target: loader.item
function onScanModeToggled() {
scanModeController.toggle();
}
}
}
}
......@@ -16,12 +16,19 @@ ColumnLayout {
id: root
width: parent.width
property var certificate
/** Double tap on the barcode to request scan mode. */
signal scanModeToggled()
function daysTo(d1, d2) {
return (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24);
}
App.HealthCertificateBarcode {
certificate: root.certificate
TapHandler {
onDoubleTapped: root.scanModeToggled()
}
}
Kirigami.FormLayout {
......
......@@ -16,12 +16,19 @@ ColumnLayout {
id: root
width: parent.width
property var certificate
/** Double tap on the barcode to request scan mode. */
signal scanModeToggled()
function daysTo(d1, d2) {
return (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24);
}
App.HealthCertificateBarcode {
certificate: root.certificate
TapHandler {
onDoubleTapped: root.scanModeToggled()
}
}
Kirigami.FormLayout {
......
......@@ -16,12 +16,19 @@ ColumnLayout {
id: root
width: parent.width
property var certificate
/** Double tap on the barcode to request scan mode. */
signal scanModeToggled()
function daysTo(d1, d2) {
return (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24);
}
App.HealthCertificateBarcode {
certificate: root.certificate
TapHandler {
onDoubleTapped: root.scanModeToggled()
}
}
Kirigami.FormLayout {
......
......@@ -9,7 +9,6 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.pkpass 1.0 as KPkPass
import org.kde.prison 1.0 as Prison
import org.kde.solidextras 1.0 as Solid
Rectangle {
property var pass
......@@ -20,14 +19,6 @@ Rectangle {
radius: 6
Layout.alignment: Qt.AlignCenter
MouseArea {
anchors.fill: parent
onDoubleClicked: {
Solid.BrightnessManager.toggleBrightness()
Solid.LockManager.toggleInhibitScreenLock(i18n("In barcode scanning mode"))
}
}
ColumnLayout {
id: barcodeLayout
anchors.fill: parent
......
......@@ -20,6 +20,15 @@ Kirigami.ScrollablePage {
}
}
actions.main: Kirigami.Action {
icon.name: "view-barcode-qr"
text: i18n("Barcode Scan Mode")
onTriggered: scanModeController.toggle()
visible: root.pass.barcodes.length > 0
checkable: true
checked: scanModeController.enabled
}
Component {
id: boardingPass
App.BoardingPass {
......@@ -36,6 +45,11 @@ Kirigami.ScrollablePage {
}
}
BarcodeScanModeController {
id: scanModeController
page: root
}
Item {
id: contentItem
width: parent.width
......@@ -51,5 +65,12 @@ Kirigami.ScrollablePage {
}
}
}
Connections {
target: loader.item
function onScanModeToggled() {
scanModeController.toggle();
}
}
}
}
......@@ -10,7 +10,6 @@ import QtQuick.Controls 2.1 as QQC2
import QtQuick.Window 2.10
import org.kde.kirigami 2.17 as Kirigami
import org.kde.prison 1.0 as Prison
import org.kde.solidextras 1.0 as Solid
import org.kde.kitinerary 1.0
import org.kde.itinerary 1.0
import "." as App
......@@ -23,6 +22,11 @@ ColumnLayout {
readonly property var currentTicket: ticketModel.reservationAt(travelerBox.currentIndex) ? ticketModel.reservationAt(travelerBox.currentIndex).reservedTicket : undefined
Layout.fillWidth: true
/** There is a barcode displayed. */
readonly property alias hasBarcode: background.visible
/** Double tap on the barcode to request scan mode. */
signal scanModeToggled()
TicketTokenModel {
id: ticketModel
reservationManager: ReservationManager
......@@ -69,10 +73,7 @@ ColumnLayout {
MouseArea {
anchors.fill: parent
onDoubleClicked: {
Solid.BrightnessManager.toggleBrightness()
Solid.LockManager.toggleInhibitScreenLock(i18n("In barcode scanning mode"))
}
onDoubleClicked: root.scanModeToggled()
}
Prison.Barcode {
......
......@@ -22,6 +22,15 @@ App.DetailsPage {
}
}
actions.main: Kirigami.Action {
icon.name: "view-barcode-qr"
text: i18n("Barcode Scan Mode")
onTriggered: scanModeController.toggle()
visible: ticketToken.hasBarcode
checkable: true
checked: scanModeController.enabled
}
Component {
id: alternativePage
App.JourneyQueryPage {
......@@ -99,6 +108,11 @@ App.DetailsPage {
actions.contextualActions.push(notifyTestAction.createObject(root));
}
BarcodeScanModeController {
id: scanModeController
page: root
}
ColumnLayout {
width: parent.width
......@@ -111,12 +125,14 @@ App.DetailsPage {
// ticket barcode
App.TicketTokenDelegate {
id: ticketToken
resIds: ReservationManager.reservationsForBatch(root.batchId)
onCurrentReservationIdChanged: {
if (!currentReservationId)
return;
root.currentReservationId = currentReservationId;
}
onScanModeToggled: scanModeController.toggle()
}
Kirigami.FormLayout {
......
......@@ -8,6 +8,7 @@
<file>main.qml</file>
<file>AboutPage.qml</file>
<file>BarcodeScanModeController.qml</file>
<file>BoardingPass.qml</file>
<file>BusDelegate.qml</file>
<file>BusPage.qml</file>
......
......@@ -5,6 +5,7 @@
<RCC>
<qresource prefix="/">
<file>pkpassviewer.qml</file>
<file alias="BarcodeScanModeController.qml">../src/app/BarcodeScanModeController.qml</file>
<file alias="BoardingPass.qml">../src/app/BoardingPass.qml</file>
<file alias="EventTicket.qml">../src/app/EventTicket.qml</file>
<file alias="PkPassBarcode.qml">../src/app/PkPassBarcode.qml</file>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment