2
0

FanHeader.qml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (C) 2019 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.6
  20. import QtQuick.Controls 2.1
  21. import QtQuick.Layouts 1.2
  22. import org.kde.kirigami 2.3 as Kirigami
  23. RowLayout {
  24. property QtObject fan
  25. property bool editable: true
  26. Loader {
  27. active: !!fan
  28. sourceComponent: editable ? editableNameComponent : nameComponent
  29. Layout.alignment: Qt.AlignLeft
  30. Layout.leftMargin: Kirigami.Units.smallSpacing
  31. }
  32. Item {
  33. Layout.fillWidth: true
  34. }
  35. Label {
  36. Layout.alignment: Qt.AlignRight
  37. Layout.rightMargin: Kirigami.Units.smallSpacing
  38. text: !!fan ? fan.id : ""
  39. horizontalAlignment: Text.AlignRight
  40. }
  41. Component {
  42. id: nameComponent
  43. Label {
  44. text: !!fan ? fan.name : ""
  45. horizontalAlignment: TextEdit.AlignLeft
  46. wrapMode: TextEdit.Wrap
  47. font.bold: true
  48. font.pointSize: Kirigami.Theme.defaultFont.pointSize + 2
  49. }
  50. }
  51. Component {
  52. id: editableNameComponent
  53. TextEdit {
  54. id: nameField
  55. text: !!fan ? fan.name : ""
  56. color: Kirigami.Theme.textColor
  57. horizontalAlignment: TextEdit.AlignLeft
  58. wrapMode: TextEdit.Wrap
  59. font.bold: true
  60. font.pointSize: Kirigami.Theme.defaultFont.pointSize + 2
  61. selectByMouse: true
  62. onTextChanged: if (!!fan && fan.name != text) fan.name = text
  63. Connections {
  64. target: !!fan ? fan : null
  65. onNameChanged: if (fan.name != nameField.text) nameField.text = fan.name
  66. }
  67. MouseArea {
  68. anchors.fill: parent
  69. cursorShape: Qt.IBeamCursor
  70. acceptedButtons: Qt.NoButton
  71. }
  72. }
  73. }
  74. }