OptionInput.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. import org.kde.kirigami 2.4 as Kirigami
  22. FocusScope {
  23. property alias text: textField.text
  24. property alias font: textField.font
  25. property alias inputMethodHints: textField.inputMethodHints
  26. property alias validator: textField.validator
  27. property alias color: textField.color
  28. property real margin: Kirigami.Units.smallSpacing
  29. property var value
  30. property var locale: Qt.locale()
  31. id: root
  32. implicitHeight: textField.implicitHeight + margin * 2
  33. implicitWidth: textField.implicitWidth + margin * 2
  34. onValueChanged: {
  35. if (textField.text != value) {
  36. textField.text = value;
  37. }
  38. }
  39. Rectangle {
  40. id: rect
  41. anchors.fill: parent
  42. border.width: 1
  43. radius: 2
  44. color: enabled ? palette.base : disabledPalette.base
  45. border.color: enabled ? mouseArea.containsMouse || root.activeFocus ? palette.highlight : palette.windowText : disabledPalette.windowText
  46. TextInput {
  47. id: textField
  48. anchors.fill: parent
  49. anchors.leftMargin: margin
  50. horizontalAlignment: TextEdit.AlignLeft
  51. verticalAlignment: TextEdit.AlignVCenter
  52. renderType: Text.NativeRendering
  53. selectByMouse: true
  54. color: enabled ? palette.text : disabledPalette.text
  55. MouseArea {
  56. id: mouseArea
  57. anchors.fill: parent
  58. hoverEnabled: true
  59. cursorShape: Qt.IBeamCursor
  60. acceptedButtons: Qt.NoButton
  61. }
  62. }
  63. SystemPalette {
  64. id: palette
  65. }
  66. SystemPalette {
  67. id: disabledPalette
  68. colorGroup: SystemPalette.Disabled
  69. }
  70. }
  71. }