Friendiqa/source-android/androidnative.pri/qml/AndroidNative/ImagePicker.qml
2017-11-08 21:15:07 +01:00

54 lines
1.5 KiB
QML

import QtQuick 2.0
import AndroidNative 1.0
Item {
/// Set it to true if multiple images should be picked.
property bool multiple: false
/// If it is true, it will broadcast the taked photo to other application (e.g Let it show in Google Photos)
property bool broadcast: true
/// The URL of the image chosen. If multiple images are picked, it will be equal to the first image.
property string imageUrl: ""
/// A list of images chosen
property var imageUrls: []
/// It is emitted whatever photo(s) are picked/taken.
signal ready();
function pickImage() {
SystemDispatcher.dispatch(m_PICK_IMAGE_MESSAGE,{ multiple: multiple});
}
function takePhoto() {
SystemDispatcher.dispatch(m_TAKE_PHOTO_MESSAGE,{
broadcast: broadcast
})
}
property string m_PICK_IMAGE_MESSAGE: "androidnative.ImagePicker.pickImage";
property string m_TAKE_PHOTO_MESSAGE: "androidnative.ImagePicker.takePhoto";
property string m_CHOSEN_MESSAGE: "androidnative.ImagePicker.chosen";
Connections {
target: SystemDispatcher
onDispatched: {
if (type === m_CHOSEN_MESSAGE) {
imageUrls = message.imageUrls;
imageUrl = imageUrls[0];
ready();
}
}
}
Component.onCompleted: {
SystemDispatcher.loadClass("androidnative.ImagePicker");
}
}