Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.5
- import QtQuick.Controls 1.4
- import QtQuick.Window 2.0
- Window {
- id: captchaWindow
- title: qsTr("Captcha")
- minimumWidth: 220
- minimumHeight: 160
- maximumWidth: minimumWidth
- maximumHeight: minimumHeight
- flags: Qt.Dialog
- modality: Qt.ApplicationModal
- color: "white"
- property alias captchaUrl: captchaImage.source
- property int paddings: 10
- signal captchaSubmitted(string code)
- signal closed()
- Rectangle {
- id: container
- anchors.fill: parent
- anchors.margins: captchaWindow.paddings
- color: "transparent"
- Rectangle {
- id: content
- anchors.top: parent.top
- color: "transparent"
- width: parent.width
- height: parent.height - buttonContainer.height
- Column {
- anchors.centerIn: parent
- spacing: captchaWindow.paddings
- Image {
- id: captchaImage
- cache: false
- width: 130
- height: 50
- function reload() {
- var s = source.toString().replace(/&v=.*/, '');
- source = s + "&v=" + Date.now();
- captchaCode.text = "";
- captchaCode.focus = true;
- }
- // Контекстное меню самому нужно реализовывать. Код ниже нерабочий:
- // Menu {
- // MenuItem {
- // text: qsTr("Reload")
- // onTriggered: captchaImage.reload()
- // }
- // }
- MouseArea {
- anchors.fill: parent
- onClicked: parent.reload()
- }
- }
- TextField {
- id: captchaCode
- horizontalAlignment: TextInput.AlignHCenter
- placeholderText: qsTr("Enter captcha code")
- width: 130
- // Вручную нужно делать
- onAccepted: sendButton.clicked()
- }
- }
- }
- Rectangle {
- id: buttonContainer
- anchors.bottom: parent.bottom
- color: "transparent"
- width: parent.width
- height: childrenRect.height
- Button {
- id: sendButton
- anchors.right: parent.right
- text: qsTr("Send")
- onClicked: captchaWindow.captchaSubmitted(captchaCode.text)
- }
- }
- }
- onCaptchaSubmitted: {
- close()
- }
- onVisibleChanged: {
- if (visible == Window.Hidden) {
- closed()
- }
- }
- onClosed: {
- captchaCode.text = ""
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement