Last active
August 5, 2017 18:23
-
-
Save ratmandu/9bf9c779c93591b7085095625a95e0df to your computer and use it in GitHub Desktop.
SEMOW QML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now supports numbers in the input without duplication