Button.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 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:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  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. }