Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 2.43 KB | None | 0 0
  1. import QtQuick 2.5
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Window 2.0
  4.  
  5. Window {
  6.   id: captchaWindow
  7.   title: qsTr("Captcha")
  8.   minimumWidth: 220
  9.   minimumHeight: 160
  10.   maximumWidth: minimumWidth
  11.   maximumHeight: minimumHeight
  12.   flags: Qt.Dialog
  13.   modality: Qt.ApplicationModal
  14.   color: "white"
  15.   property alias captchaUrl: captchaImage.source
  16.   property int paddings: 10
  17.   signal captchaSubmitted(string code)
  18.   signal closed()
  19.  
  20.   Rectangle {
  21.     id: container
  22.     anchors.fill: parent
  23.     anchors.margins: captchaWindow.paddings
  24.     color: "transparent"
  25.  
  26.     Rectangle {
  27.       id: content
  28.       anchors.top: parent.top
  29.       color: "transparent"
  30.       width: parent.width
  31.       height: parent.height - buttonContainer.height
  32.  
  33.       Column {
  34.         anchors.centerIn: parent
  35.         spacing: captchaWindow.paddings
  36.  
  37.         Image {
  38.           id: captchaImage
  39.           cache: false
  40.           width: 130
  41.           height: 50
  42.  
  43.           function reload() {
  44.             var s = source.toString().replace(/&v=.*/, '');
  45.             source = s + "&v=" + Date.now();
  46.             captchaCode.text = "";
  47.             captchaCode.focus = true;
  48.           }
  49.  
  50.           // Контекстное меню самому нужно реализовывать. Код ниже нерабочий:
  51.           // Menu {
  52.           //   MenuItem {
  53.           //     text: qsTr("Reload")
  54.           //     onTriggered: captchaImage.reload()
  55.           //   }
  56.           // }
  57.  
  58.           MouseArea {
  59.             anchors.fill: parent
  60.             onClicked: parent.reload()
  61.           }
  62.         }
  63.  
  64.         TextField {
  65.           id: captchaCode
  66.           horizontalAlignment: TextInput.AlignHCenter
  67.           placeholderText: qsTr("Enter captcha code")
  68.           width: 130
  69.           // Вручную нужно делать
  70.           onAccepted: sendButton.clicked()
  71.         }
  72.       }
  73.     }
  74.  
  75.     Rectangle {
  76.       id: buttonContainer
  77.       anchors.bottom: parent.bottom
  78.       color: "transparent"
  79.       width: parent.width
  80.       height: childrenRect.height
  81.  
  82.       Button {
  83.         id: sendButton
  84.         anchors.right: parent.right
  85.         text: qsTr("Send")
  86.         onClicked: captchaWindow.captchaSubmitted(captchaCode.text)
  87.       }
  88.     }
  89.   }
  90.  
  91.   onCaptchaSubmitted: {
  92.     close()
  93.   }
  94.  
  95.   onVisibleChanged: {
  96.     if (visible == Window.Hidden) {
  97.       closed()
  98.     }
  99.   }
  100.  
  101.   onClosed: {
  102.     captchaCode.text = ""
  103.   }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement