Skip to content

Commit

Permalink
Merge pull request #5290 from opengisch/camera_device_selection
Browse files Browse the repository at this point in the history
Implement a camera device switcher to QField's own camera
  • Loading branch information
nirvn authored Jun 1, 2024
2 parents 4fa8352 + 666b764 commit 8a7747a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
<file>themes/qfield/nodpi/ic_flashlight_green_48dp.svg</file>
<file>themes/qfield/nodpi/ic_gallery_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_microphone_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_camera_switch_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_camera_photo_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_camera_video_black_24dp.svg</file>
<file>themes/qfield/hdpi/ic_camera_white_36dp.png</file>
Expand Down
4 changes: 4 additions & 0 deletions images/themes/qfield/nodpi/ic_camera_switch_black_24dp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 85 additions & 2 deletions src/qml/QFieldCamera.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ Popup {
}
}

Component.onCompleted: {
let cameraPicked = false
if (settings.deviceId != '') {
for(const device of mediaDevices.videoInputs) {
if (device.id == settings.deviceId) {
camera.cameraDevice = device
cameraPicked = true
}
}
}
if (!cameraPicked) {
camera.cameraDevice = mediaDevices.defaultVideoInput
}
}

QfCameraPermission {
id: cameraPermission
}
Expand All @@ -63,6 +78,7 @@ Popup {
id: settings
property bool geoTagging: true
property bool showGrid: false
property string deviceId: ''
}

Page {
Expand All @@ -86,7 +102,6 @@ Popup {
id: camera

active: cameraItem.visible && cameraPermission.status === Qt.PermissionStatus.Granted
cameraDevice: mediaDevices.defaultVideoInput

function zoomIn(increase) {
var zoom = camera.zoomFactor + increase
Expand Down Expand Up @@ -433,11 +448,79 @@ Popup {
}

QfToolButton {
id: geotagButton
id: cameraSelectionButton

anchors.left: parent.left
anchors.leftMargin: 4
anchors.top: backButton.bottom
anchors.topMargin: cameraSelectionMenu.count > 1 ? 4 : 0

width: 48
height: cameraSelectionMenu.count > 1 ? 48 : 0

iconSource: Theme.getThemeVectorIcon("ic_camera_switch_black_24dp")
iconColor: "white"
bgcolor: Theme.darkGraySemiOpaque
round: true

onClicked: {
cameraSelectionMenu.popup(cameraSelectionButton.x, cameraSelectionButton.y)
}
}

Menu {
id: cameraSelectionMenu

width: {
let result = 50;
let padding = 0;
for (let i = 0; i < count; ++i) {
let item = itemAt(i);
result = Math.max(item.contentItem.implicitWidth, result);
padding = Math.max(item.leftPadding + item.rightPadding, padding);
}
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : 0;
}

Repeater {
model: mediaDevices.videoInputs

delegate: MenuItem {
property string deviceId: modelData.id
property bool isDefault: modelData.isDefault

text: modelData.description +
(modelData.position !== CameraDevice.UnspecifiedPosition
? ' (' + (modelData.position === CameraDevice.FrontFace
? qsTr('front') : qsTr('back')) + ')'
: '')
height: 48
leftPadding: Theme.menuItemCheckLeftPadding
font: Theme.defaultFont
enabled: !checked
checkable: true
checked: deviceId == settings.deviceId || (isDefault && settings.deviceId == '')
indicator.height: 20
indicator.width: 20
indicator.implicitHeight: 24
indicator.implicitWidth: 24

onCheckedChanged: {
if (checked && settings.deviceId !== modelData.id) {
settings.deviceId = modelData.id
camera.cameraDevice = modelData
}
}
}
}
}

QfToolButton {
id: geotagButton

anchors.left: parent.left
anchors.leftMargin: 4
anchors.top: cameraSelectionButton.bottom
anchors.topMargin: 4

iconSource: positionSource.active ? Theme.getThemeIcon("ic_geotag_24dp") : Theme.getThemeIcon("ic_geotag_missing_24dp")
Expand Down

1 comment on commit 8a7747a

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.