Skip to content

Instantly share code, notes, and snippets.

@ratmandu
Last active August 5, 2017 18:23
Show Gist options
  • Save ratmandu/9bf9c779c93591b7085095625a95e0df to your computer and use it in GitHub Desktop.
Save ratmandu/9bf9c779c93591b7085095625a95e0df to your computer and use it in GitHub Desktop.
SEMOW QML
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("seMOw")
header: Rectangle {
width: parent.width
height: 50
color: "lightgray"
RowLayout {
anchors.fill: parent
TextInput {
id: wordInput
Layout.fillWidth: true
Layout.fillHeight: true
width: 200
Layout.minimumWidth: 100
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
Button {
id: searchButton
text: "Search"
Layout.fillWidth: true
Layout.fillHeight: true
}
}
}
Connections {
target: searchButton
onClicked: {
permutate(wordInput.text)
wordInput.text = ""
}
}
ListModel {
id: imageModel
}
ListView {
id: imageListView
// spacing: 15
anchors.fill: parent
model: imageModel
cacheBuffer: 104800
delegate: AnimatedImage {
source: model.url
fillMode: Image.PreserveAspectFit
width: parent.width
anchors.topMargin: 15
anchors.bottomMargin: 15
// visible:
onStatusChanged: {
if (this.status == AnimatedImage.Ready) {
if (this.source == "https://i.imgur.com/removed.png") {
this.visible = false
}
}
}
Label {
width: parent.width
text: parent.status == Image.Ready ? model.url : "Loading"
anchors.bottom: parent.top
horizontalAlignment: Qt.AlignHCenter
}
}
}
function permutate(word) {
imageModel.clear()
var urls = [];
var s = word;
var sp = s.split("");
for (var i = 0, l = 1 << s.length; i < l; i++) {
for (var j = i, k = 0; j; j >>= 1, k++) {
sp[k] = (j & 1) ? sp[k].toUpperCase() : sp[k].toLowerCase();
}
var st = "https://i.imgur.com/"+sp.join("")+".jpg";
urls.push(st);
// imageModel.append({"url":st});
}
var uniqueURLS = [];
urls.forEach(function(el){
if(uniqueURLS.indexOf(el) == -1) {
imageModel.append({"url":el});
uniqueURLS.push(el);
console.log(el);
}
});
imageListView.update()
}
}
@ratmandu
Copy link
Author

ratmandu commented Aug 5, 2017

Now supports numbers in the input without duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment