AuthenticationDialog.qml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. import QtQuick
  4. import QtQuick.Controls
  5. import QtQuick.Layouts
  6. Dialog {
  7. property alias text: message.text
  8. property bool handled: false
  9. signal credentials(string user, string password)
  10. title: qsTr("Authentication Required")
  11. modal: false
  12. anchors.centerIn: parent
  13. objectName: "authenticationDialog"
  14. function acceptDialog() {
  15. credentials(userField.text, passwordField.text);
  16. accept()
  17. }
  18. ColumnLayout {
  19. id: rootLayout
  20. anchors.fill: parent
  21. anchors.margins: 4
  22. property int minimumWidth: rootLayout.implicitWidth + rootLayout.doubleMargins
  23. property int minimumHeight: rootLayout.implicitHeight + rootLayout.doubleMargins
  24. property int doubleMargins: anchors.margins * 2
  25. SystemPalette { id: palette; colorGroup: SystemPalette.Active }
  26. Label {
  27. id: message
  28. color: palette.windowText
  29. textFormat: Text.PlainText
  30. }
  31. GridLayout {
  32. columns: 2
  33. Label {
  34. text: qsTr("Username:")
  35. color: palette.windowText
  36. }
  37. TextField {
  38. id: userField
  39. focus: true
  40. Layout.fillWidth: true
  41. onAccepted: {
  42. if (userField.text && passwordField.text)
  43. acceptDialog();
  44. }
  45. }
  46. Label {
  47. text: qsTr("Password:")
  48. color: palette.windowText
  49. }
  50. TextField {
  51. id: passwordField
  52. Layout.fillWidth: true
  53. echoMode: TextInput.Password
  54. onAccepted: {
  55. if (userField.text && passwordField.text)
  56. acceptDialog();
  57. }
  58. }
  59. }
  60. Item {
  61. Layout.fillHeight: true
  62. }
  63. RowLayout {
  64. Layout.alignment: Qt.AlignRight
  65. spacing: 8
  66. Button {
  67. id: cancelButton
  68. text: qsTr("Cancel")
  69. onClicked: reject()
  70. }
  71. Button {
  72. text: qsTr("Log In")
  73. onClicked: acceptDialog()
  74. }
  75. }
  76. }
  77. }