mirror of
https://github.com/QuasarApp/QtAndroidTools.git
synced 2025-04-26 21:14:31 +00:00
143 lines
4.2 KiB
QML
143 lines
4.2 KiB
QML
import QtQuick 2.12
|
|
import QtQuick.Controls 2.12
|
|
import QtQuick.Dialogs 1.1
|
|
import QtAndroidTools 1.0
|
|
|
|
Page {
|
|
id: page
|
|
padding: 20
|
|
|
|
Component.onCompleted: {
|
|
if(QtAndroidSharing.action === QtAndroidSharing.ACTION_SEND)
|
|
{
|
|
if(QtAndroidSharing.mimeType === "text/plain")
|
|
{
|
|
receivedSharedText.text = QtAndroidSharing.getSharedText();
|
|
receivedSharedText.open();
|
|
}
|
|
else if(QtAndroidSharing.mimeType.startsWith("image") === true)
|
|
{
|
|
QtAndroidTools.insertImage("SharedImage", QtAndroidSharing.getSharedData());
|
|
sharedImage.source = "image://QtAndroidTools/SharedImage";
|
|
receivedSharedImage.open();
|
|
}
|
|
}
|
|
else if(QtAndroidSharing.action === QtAndroidSharing.ACTION_PICK)
|
|
{
|
|
imageToShareDialog.open();
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: QtAndroidSharing
|
|
onRequestedSharedFileReadyToGet: {
|
|
requestedSharedFile.text = "Name: " + name + "\nSize: " + size + "\nMimeType: " + mimeType;
|
|
requestedSharedFile.open();
|
|
}
|
|
}
|
|
|
|
Column {
|
|
anchors.fill: parent
|
|
spacing: 20
|
|
|
|
Label {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: "Text to share"
|
|
font.bold: true
|
|
}
|
|
TextField {
|
|
id: sharedText
|
|
width: parent.width
|
|
text: "Hello Qt!"
|
|
horizontalAlignment: TextField.AlignHCenter
|
|
}
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: "Share"
|
|
onClicked: QtAndroidSharing.shareText(sharedText.text)
|
|
}
|
|
|
|
Label {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: "Share file"
|
|
font.bold: true
|
|
}
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: "Share"
|
|
onClicked: QtAndroidSharing.shareData("image/jpeg", QtAndroidSystem.dataLocation + "/sharedfiles/logo_falsinsoft.jpg")
|
|
}
|
|
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: "Request shared file"
|
|
onClicked: QtAndroidSharing.requestSharedFile("image/*")
|
|
}
|
|
}
|
|
|
|
MessageDialog {
|
|
id: receivedSharedText
|
|
title: "Received shared text"
|
|
onAccepted: Qt.quit()
|
|
}
|
|
|
|
Dialog {
|
|
id: receivedSharedImage
|
|
title: "Received shared image"
|
|
modal: true
|
|
standardButtons: Dialog.Ok
|
|
contentWidth: sharedImage.width
|
|
contentHeight: sharedImage.height
|
|
anchors.centerIn: parent
|
|
|
|
property bool quitOnClose: true
|
|
|
|
Image {
|
|
id: sharedImage
|
|
width: page.width * 0.5
|
|
height: width
|
|
}
|
|
|
|
onAccepted: if(quitOnClose) Qt.quit()
|
|
}
|
|
|
|
MessageDialog {
|
|
id: requestedSharedFile
|
|
title: "It's ok to get this file?"
|
|
standardButtons: StandardButton.Yes | StandardButton.No
|
|
onNo: QtAndroidSharing.closeSharedFile()
|
|
onYes: {
|
|
QtAndroidTools.insertImage("SharedImage", QtAndroidSharing.getRequestedSharedFile());
|
|
sharedImage.source = "image://QtAndroidTools/SharedImage";
|
|
receivedSharedImage.quitOnClose = false;
|
|
receivedSharedImage.open();
|
|
}
|
|
}
|
|
|
|
Dialog {
|
|
id: imageToShareDialog
|
|
title: "Sorry, I have only this image to share,\ndo you want it?"
|
|
modal: true
|
|
standardButtons: Dialog.Yes | Dialog.No
|
|
contentWidth: imageToShare.width
|
|
contentHeight: imageToShare.height
|
|
anchors.centerIn: parent
|
|
|
|
Image {
|
|
id: imageToShare
|
|
width: page.width * 0.5
|
|
height: width
|
|
source: "file:/" + QtAndroidSystem.dataLocation + "/sharedfiles/logo_falsinsoft.jpg"
|
|
}
|
|
|
|
onRejected: {
|
|
QtAndroidSharing.returnSharedFile(false);
|
|
Qt.quit();
|
|
}
|
|
onAccepted: {
|
|
QtAndroidSharing.returnSharedFile(true, "image/jpeg", QtAndroidSystem.dataLocation + "/sharedfiles/logo_falsinsoft.jpg");
|
|
Qt.quit();
|
|
}
|
|
}
|
|
}
|