Button.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2021 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Quick Controls module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:COMM$
  9. **
  10. ** Commercial License Usage
  11. ** Licensees holding valid commercial Qt licenses may use this file in
  12. ** accordance with the commercial license agreement provided with the
  13. ** Software or, alternatively, in accordance with the terms contained in
  14. ** a written agreement between you and The Qt Company. For licensing terms
  15. ** and conditions see https://www.qt.io/terms-conditions. For further
  16. ** information use the contact form at https://www.qt.io/contact-us.
  17. **
  18. ** $QT_END_LICENSE$
  19. **
  20. **
  21. **
  22. **
  23. **
  24. **
  25. **
  26. **
  27. **
  28. **
  29. **
  30. **
  31. **
  32. **
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ****************************************************************************/
  39. import QtQml 2.14 as Qml
  40. import QtQuick 2.2
  41. import QtQuick.Controls 1.2
  42. import QtQuick.Controls.Private 1.0
  43. /*!
  44. \qmltype Button
  45. \inqmlmodule QtQuick.Controls
  46. \since 5.1
  47. \ingroup controls
  48. \brief A push button with a text label.
  49. \image button.png
  50. The push button is perhaps the most commonly used widget in any graphical
  51. user interface. Pushing (or clicking) a button commands the computer to
  52. perform some action or answer a question. Common examples of buttons are
  53. OK, Apply, Cancel, Close, Yes, No, and Help buttons.
  54. \qml
  55. Button {
  56. text: "Button"
  57. }
  58. \endqml
  59. Button is similar to the QPushButton widget.
  60. You can create a custom appearance for a Button by
  61. assigning a \l {ButtonStyle}.
  62. */
  63. BasicButton {
  64. id: button
  65. /*! This property holds whether the push button is the default button.
  66. Default buttons decide what happens when the user presses enter in a
  67. dialog without giving a button explicit focus. \note This property only
  68. changes the appearance of the button. The expected behavior needs to be
  69. implemented by the user.
  70. The default value is \c false.
  71. */
  72. property bool isDefault: false
  73. /*! Assign a \l Menu to this property to get a pull-down menu button.
  74. The default value is \c null.
  75. */
  76. property Menu menu: null
  77. __effectivePressed: __behavior.effectivePressed || menu && menu.__popupVisible
  78. activeFocusOnTab: true
  79. Accessible.name: text
  80. style: Settings.styleComponent(Settings.style, "ButtonStyle.qml", button)
  81. Qml.Binding {
  82. target: menu
  83. property: "__minimumWidth"
  84. value: button.__panel.width
  85. restoreMode: Binding.RestoreBinding
  86. }
  87. Qml.Binding {
  88. target: menu
  89. property: "__visualItem"
  90. value: button
  91. restoreMode: Binding.RestoreBinding
  92. }
  93. Connections {
  94. target: __behavior
  95. function onEffectivePressedChanged() {
  96. if (!Settings.hasTouchScreen && __behavior.effectivePressed && menu)
  97. popupMenuTimer.start()
  98. }
  99. function onReleased() {
  100. if (Settings.hasTouchScreen && __behavior.containsMouse && menu)
  101. popupMenuTimer.start()
  102. }
  103. }
  104. Timer {
  105. id: popupMenuTimer
  106. interval: 10
  107. onTriggered: {
  108. __behavior.keyPressed = false
  109. if (Qt.application.layoutDirection === Qt.RightToLeft)
  110. menu.__popup(Qt.rect(button.width, button.height, 0, 0), 0)
  111. else
  112. menu.__popup(Qt.rect(0, button.height, 0, 0), 0)
  113. }
  114. }
  115. }