2
0

OptionInput.qml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <malte.veerman@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. import QtQuick 2.4
  20. import QtQuick.Layouts 1.1
  21. FocusScope {
  22. property alias text: textField.text
  23. property alias font: textField.font
  24. property alias inputMethodHints: textField.inputMethodHints
  25. property alias validator: textField.validator
  26. property alias color: textField.color
  27. property real margin: 6
  28. property var value
  29. property var locale: Qt.locale()
  30. id: root
  31. implicitHeight: textField.implicitHeight + margin*2
  32. implicitWidth: textField.implicitWidth + margin*2
  33. onValueChanged: {
  34. if (textField.text != value) {
  35. textField.text = value;
  36. }
  37. }
  38. Rectangle {
  39. id: rect
  40. anchors.fill: parent
  41. border.width: 1
  42. radius: 2
  43. color: enabled ? palette.base : disabledPalette.base
  44. border.color: enabled ? mouseArea.containsMouse || root.activeFocus ? palette.highlight : palette.windowText : disabledPalette.windowText
  45. TextInput {
  46. id: textField
  47. anchors.fill: parent
  48. anchors.leftMargin: margin
  49. horizontalAlignment: TextEdit.AlignLeft
  50. verticalAlignment: TextEdit.AlignVCenter
  51. renderType: Text.NativeRendering
  52. selectByMouse: true
  53. color: enabled ? palette.text : disabledPalette.text
  54. MouseArea {
  55. id: mouseArea
  56. anchors.fill: parent
  57. hoverEnabled: true
  58. cursorShape: Qt.IBeamCursor
  59. acceptedButtons: Qt.NoButton
  60. }
  61. }
  62. SystemPalette {
  63. id: palette
  64. }
  65. SystemPalette {
  66. id: disabledPalette
  67. colorGroup: SystemPalette.Disabled
  68. }
  69. }
  70. }