OptionInput.qml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  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 string type: "int"
  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 (type == "int" || type == "double") {
  36. if (textField.text != Number(value).toLocaleString()) {
  37. textField.text = Number(value).toLocaleString();
  38. }
  39. }
  40. else if (type == "string") {
  41. if (textField.text != value) {
  42. textField.text = value;
  43. }
  44. }
  45. }
  46. Rectangle {
  47. id: rect
  48. anchors.fill: parent
  49. border.width: 1
  50. radius: 2
  51. border.color: enabled ? palette.text : disabledPalette.text
  52. TextInput {
  53. id: textField
  54. anchors.fill: parent
  55. anchors.leftMargin: margin
  56. horizontalAlignment: TextEdit.AlignLeft
  57. verticalAlignment: TextEdit.AlignVCenter
  58. renderType: Text.NativeRendering
  59. selectByMouse: true
  60. color: enabled ? palette.text : disabledPalette.text
  61. MouseArea {
  62. anchors.fill: parent
  63. cursorShape: Qt.IBeamCursor
  64. acceptedButtons: Qt.NoButton
  65. }
  66. }
  67. SystemPalette {
  68. id: palette
  69. }
  70. SystemPalette {
  71. id: disabledPalette
  72. colorGroup: SystemPalette.Disabled
  73. }
  74. }
  75. }