2023-07-29 11:01:56 +02:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2023-02-18 14:30:06 +01:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
2023-03-09 10:19:58 +01:00
|
|
|
import QtQuick.Controls.Material
|
2023-02-18 14:30:06 +01:00
|
|
|
import QtQuick.Effects
|
|
|
|
import QtQuick.Particles
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
2023-07-29 11:01:56 +02:00
|
|
|
state: "normal"
|
|
|
|
implicitWidth: defaultWidth
|
|
|
|
implicitHeight: defaultHeight
|
|
|
|
property int defaultWidth: 200
|
|
|
|
property int defaultHeight: 200
|
|
|
|
|
|
|
|
function request(url, callback) {
|
2023-08-20 11:59:02 +02:00
|
|
|
var xhr = new XMLHttpRequest();
|
2023-07-29 11:01:56 +02:00
|
|
|
xhr.onreadystatechange = (function (myxhr) {
|
2023-08-20 11:59:02 +02:00
|
|
|
return function () {
|
|
|
|
if (myxhr.readyState === 4)
|
|
|
|
callback(myxhr);
|
|
|
|
};
|
|
|
|
})(xhr);
|
|
|
|
xhr.open('GET', url);
|
|
|
|
xhr.send('');
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
request("http://xkcd.com/info.0.json", function (o) {
|
2023-08-20 11:59:02 +02:00
|
|
|
if (o.status === 200) {
|
|
|
|
var d = eval('new Object(' + o.responseText + ')');
|
|
|
|
console.log(o.responseText);
|
|
|
|
img.source = d.img;
|
|
|
|
} else {
|
|
|
|
console.log("Some error has occurred");
|
|
|
|
}
|
|
|
|
});
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
2023-02-18 14:30:06 +01:00
|
|
|
|
|
|
|
Image {
|
|
|
|
id: img
|
|
|
|
anchors.fill: parent
|
2023-07-29 11:01:56 +02:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
|
|
|
property size imgSize: Qt.size(root.defaultWidth, defaultHeight)
|
2023-02-18 14:30:06 +01:00
|
|
|
onStatusChanged: {
|
|
|
|
if (img.status !== Image.Ready)
|
2023-08-20 11:59:02 +02:00
|
|
|
return;
|
2023-06-11 10:07:39 +02:00
|
|
|
if (img.sourceSize.width === 0 || img.sourceSize.height === 0)
|
2023-08-20 11:59:02 +02:00
|
|
|
return;
|
|
|
|
root.implicitWidth = img.sourceSize.width;
|
|
|
|
root.implicitHeight = img.sourceSize.height;
|
|
|
|
print(img.status, img.sourceSize.width, img.sourceSize.height);
|
|
|
|
img.imgSize = Qt.size(img.sourceSize.width, img.sourceSize.height);
|
|
|
|
print("img.size", img.imgSize);
|
2023-02-18 14:30:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-29 11:01:56 +02:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
2023-08-20 11:59:02 +02:00
|
|
|
root.state = root.state === "expanded" ? "normal" : "expanded";
|
|
|
|
print(root.state, root.implicitHeight, root.implicitWidth);
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
2023-02-18 14:30:06 +01:00
|
|
|
}
|
|
|
|
|
2023-07-29 11:01:56 +02:00
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
PropertyChanges {
|
|
|
|
name: "normal"
|
|
|
|
root {
|
|
|
|
width: root.defaultWidth
|
|
|
|
height: root.defaultHeight
|
|
|
|
implicitWidth: root.defaultWidth
|
|
|
|
implicitHeight: root.defaultHeight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "expanded"
|
|
|
|
PropertyChanges {
|
|
|
|
root {
|
|
|
|
width: img.imgSize.width
|
|
|
|
height: img.imgSize.height
|
|
|
|
implicitWidth: img.imgSize.width
|
|
|
|
implicitHeight: img.imgSize.height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2023-02-18 14:30:06 +01:00
|
|
|
}
|