diff --git a/app/qml/CMakeLists.txt b/app/qml/CMakeLists.txt index ca0fff811..34b45127f 100644 --- a/app/qml/CMakeLists.txt +++ b/app/qml/CMakeLists.txt @@ -112,7 +112,6 @@ set(MM_QML NumberSpin.qml PanelItem.qml PanelTabButton.qml - PhotoPanel.qml ProjectIssuesPanel.qml ProjectLimitDialog.qml ProjectListPage.qml diff --git a/app/qml/ExternalResourceBundle.qml b/app/qml/ExternalResourceBundle.qml index 533ed8291..acb813885 100644 --- a/app/qml/ExternalResourceBundle.qml +++ b/app/qml/ExternalResourceBundle.qml @@ -10,7 +10,6 @@ import QtQuick import QtQuick.Controls import QtQuick.Dialogs - import "." // import InputStyle singleton Item { @@ -23,6 +22,9 @@ Item { // Has to be set for actions with callbacks property var itemWidget + // Whether we have camera available on this platform + property var hasCameraCapability:__androidUtils.isAndroid || __iosUtils.isIos + /** * Called when clicked on the camera icon to capture an image. * \param itemWidget editorWidget for modified field to send valueChanged signal. @@ -41,7 +43,8 @@ Item { } else if (__iosUtils.isIos) { __iosUtils.callCamera(itemWidget.targetDir) } else { - itemWidget.showDefaultPanel() + // This should never happen + console.log("Camera not implemented on this platform.") } } @@ -63,7 +66,7 @@ Item { } else if (__iosUtils.isIos) { __iosUtils.callImagePicker(itemWidget.targetDir) } else { - fileDialog.open() + desktopGalleryPicker.open() } } @@ -228,15 +231,16 @@ Item { } } + // Gallery picker FileDialog { - id: fileDialog + id: desktopGalleryPicker title: qsTr( "Open Image" ) visible: false nameFilters: [ qsTr( "Image files (*.gif *.png *.jpg)" ) ] - //width: window.width - //height: window.height currentFolder: __inputUtils.imageGalleryLocation() - onAccepted: externalResourceHandler.imageSelected(fileDialog.fileUrl) + onAccepted: { + externalResourceHandler.imageSelected(selectedFile) + } } MessageDialog { diff --git a/app/qml/PhotoPanel.qml b/app/qml/PhotoPanel.qml deleted file mode 100644 index 5fcf61b53..000000000 --- a/app/qml/PhotoPanel.qml +++ /dev/null @@ -1,260 +0,0 @@ -/*************************************************************************** - photopanel.qml - -------------------------------------- - Date : Dec 2017 - Copyright : (C) 2017 by Viktor Sklencar - Email : vsklencar at gmail dot com - *************************************************************************** - * * - * 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.Layouts -import QtQuick.Controls -import QtQml -import QtMultimedia -import Qt5Compat.GraphicalEffects - -Drawer { - // Capture path - property var targetDir - // Along with lastPhotoName creates an absolute path to a photo. Its either project path or defaultRoot. - property var prefixToRelativePath - property var lastPhotoName - property int iconSize: photoPanel.width/20 - property var fieldItem - - property color bgColor: "black" - property real bgOpacity: 1 - property color borderColor: "black" - - // icons: - property var captureButtonIcon: __inputUtils.getThemeIcon("ic_camera_alt_border") - property var confirmButtonIcon: __inputUtils.getThemeIcon("ic_check_black") - property var cancelButtonIcon: __inputUtils.getThemeIcon("ic_clear_black") - property var backButtonSource: __inputUtils.getThemeIcon("ic_back") - property real imageButtonSize: 45 * __dp - property real buttonSize: imageButtonSize * 1.2 - property var buttonsPosition - - signal confirmButtonClicked(string path, string filename) - - function discardCapturedImage() { - captureItem.saveImage = false - photoPreview.visible = false - if (camera.imageCapture.capturedImagePath != "") { - __inputUtils.removeFile(camera.imageCapture.capturedImagePath) - } - } - - id: photoPanel - visible: false - modal: true - interactive: true - dragMargin: 0 // prevents opening the drawer by dragging. - - background: Rectangle { - color: photoPanel.bgColor - opacity: photoPanel.bgOpacity - } - - onVisibleChanged: { - if (visible) { - camera.setCameraState(Camera.ActiveState) - camera.start() - } else { - camera.stop() - photoPreview.visible = false - } - } - - // PhotoCapture item - Item { - - property bool saveImage: false - - id: captureItem - width: window.width - height: window.height - - Component.onDestruction: { - if (!captureItem && camera.imageCapture.capturedImagePath !== ""){ - captureItem.saveImage = false - Utils.removeFile(camera.imageCapture.capturedImagePath) - } - captureItem.saveImage = false - } - - Camera { - id: camera - cameraState: Camera.UnloadedState - focusMode: Camera.FocusContinuous - - imageCapture { - onImageCaptured: { - // Show the preview in an Image - photoPreview.source = preview - } - } - } - - VideoOutput { - id: videoOutput - source: camera - visible: !photoPreview.visible - focus : visible // to receive focus and capture key events when visible - anchors.fill: parent - autoOrientation: true - - Item { - id: captureButton - width: buttonSize - height: buttonSize - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - antialiasing: true - - MouseArea { - id: mouseArea - anchors.fill: parent - onClicked: { - if (targetDir !== "") { - camera.imageCapture.captureToLocation(photoPanel.targetDir); - } else { - // saved to default location - TODO handle this case - camera.imageCapture.capture(); - } - photoPreview.visible = true; - } - } - - Image { - id: captureButtonImage - fillMode: Image.PreserveAspectFit - anchors.centerIn: parent - sourceSize.height: imageButtonSize - sourceSize.width: imageButtonSize - height: imageButtonSize - source: photoPanel.captureButtonIcon - } - - } - } - - Image { - id: photoPreview - width: parent.width - height: parent.height - fillMode: Image.PreserveAspectFit - visible: false - onVisibleChanged: if (!photoPreview.visible) photoPreview.source = "" - - // Cancel button - Rectangle { - id: cancelButton - visible: camera.imageCapture.capturedImagePath != "" - - property int borderWidth: 5 * __dp - width: buttonSize - height: buttonSize - color: "white" - border.color: photoPanel.borderColor - anchors.right: parent.right - anchors.top: confirmButton.bottom - border.width: borderWidth - radius: width*0.5 - antialiasing: true - - MouseArea { - anchors.fill: parent - onClicked:photoPanel.discardCapturedImage() - } - - Image { - fillMode: Image.PreserveAspectFit - anchors.centerIn: parent - sourceSize.height: imageButtonSize - sourceSize.width: imageButtonSize - height: imageButtonSize - source: photoPanel.cancelButtonIcon - } - } - - // Confirm button - Rectangle { - id: confirmButton - visible: camera.imageCapture.capturedImagePath != "" - - property int borderWidth: 5 * __dp - width: buttonSize - height: buttonSize - color: "white" - border.color: photoPanel.borderColor - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - border.width: borderWidth - radius: width*0.5 - antialiasing: true - - MouseArea { - anchors.fill: parent - onClicked: { - captureItem.saveImage = true - photoPanel.visible = false - confirmButtonClicked(photoPanel.prefixToRelativePath, camera.imageCapture.capturedImagePath) - } - } - - Image { - fillMode: Image.PreserveAspectFit - anchors.centerIn: parent - sourceSize.height: imageButtonSize - sourceSize.width: imageButtonSize - height: imageButtonSize - width: imageButtonSize - source: photoPanel.confirmButtonIcon - } - } - } - - Item { - id: backButton - - property int borderWidth: 50 * __dp - width: imageButtonSize * 1.5 - height: width - antialiasing: true - - MouseArea { - anchors.fill: parent - onClicked: { - cancelButton.visible ? photoPanel.discardCapturedImage() : photoPanel.close() - } - } - - Image { - id: backBtnIcon - fillMode: Image.PreserveAspectFit - anchors.centerIn: parent - height: imageButtonSize / 2 - sourceSize.height: height - sourceSize.width: height - source: photoPanel.backButtonSource - } - - ColorOverlay { - anchors.fill: backBtnIcon - anchors.centerIn: parent - source: backBtnIcon - color: "white" - smooth: true - } - } - } -} - diff --git a/app/qml/editor/inputexternalresource.qml b/app/qml/editor/inputexternalresource.qml index dcd3ec1f6..db7bbe4da 100644 --- a/app/qml/editor/inputexternalresource.qml +++ b/app/qml/editor/inputexternalresource.qml @@ -90,22 +90,6 @@ Item { externalResourceHandler.onFormCanceled(fieldItem) } - function showDefaultPanel() { - if (!photoCapturePanelLoader.item) { - // Load the photo capture panel if not loaded yet - photoCapturePanelLoader.setSource("qrc:/PhotoPanel.qml") - photoCapturePanelLoader.item.height = window.height - photoCapturePanelLoader.item.width = window.width - photoCapturePanelLoader.item.edge = Qt.RightEdge - photoCapturePanelLoader.item.imageButtonSize = fieldItem.iconSize - photoCapturePanelLoader.item.backButtonSource = fieldItem.backIcon - } - photoCapturePanelLoader.item.visible = true - photoCapturePanelLoader.item.targetDir = targetDir - photoCapturePanelLoader.item.prefixToRelativePath = prefixToRelativePath - photoCapturePanelLoader.item.fieldItem = fieldItem - } - id: fieldItem enabled: true // its interactive widget height: customStyle.fields.height * 3 @@ -126,17 +110,6 @@ Item { } ] - Loader { - id: photoCapturePanelLoader - } - - Connections { - target: photoCapturePanelLoader.item - function onConfirmButtonClicked( path, filename ) { - externalResourceHandler.confirmImage(fieldItem, path, filename) - } - } - Rectangle { id: imageContainer width: parent.width @@ -234,7 +207,7 @@ Item { iconSource: fieldItem.cameraIcon iconSize: buttonsContainer.itemHeight labelText: qsTr("Take a photo") - visible: !readOnly && fieldItem.state !== " valid" + visible: !readOnly && fieldItem.state !== " valid" && externalResourceHandler.hasCameraCapability Layout.preferredHeight: parent.height Layout.fillWidth: true @@ -243,18 +216,14 @@ Item { MouseArea { anchors.fill: parent onClicked: { - if (externalResourceHandler.capturePhoto) { - externalResourceHandler.capturePhoto(fieldItem) - } else { - showDefaultPanel() - } + externalResourceHandler.capturePhoto(fieldItem) } } } Item { id: lineContainer - visible: !readOnly && fieldItem.state !== " valid" + visible: photoButton.visible Layout.fillWidth: true Layout.preferredHeight: parent.height Layout.preferredWidth: line.width * 2