MenuBarStyle.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 QtQuick 2.2
  40. import QtQuick.Controls 1.2
  41. import QtQuick.Controls.Private 1.0
  42. /*!
  43. \qmltype MenuBarStyle
  44. \inqmlmodule QtQuick.Controls.Styles
  45. \since 5.3
  46. \ingroup controlsstyling
  47. \brief Provides custom styling for MenuBar.
  48. \note Styling menu bars may not be supported on platforms using native menu bars
  49. through their QPA plugin.
  50. */
  51. Style {
  52. id: root
  53. /*!
  54. \qmlmethod string MenuBarStyle::formatMnemonic(string text, bool underline = false)
  55. Returns a formatted string to render mnemonics for a given menu item \a text.
  56. The mnemonic character is prefixed by an ampersand in the original string.
  57. Passing \c true for \e underline will underline the mnemonic character (e.g.,
  58. \c formatMnemonic("&File", true) will return \c "<u>F</u>ile"). Passing \c false
  59. for \a underline will return the plain text form (e.g., \c formatMnemonic("&File", false)
  60. will return \c "File").
  61. \sa Label
  62. */
  63. function formatMnemonic(text, underline) {
  64. return underline ? StyleHelpers.stylizeMnemonics(text) : StyleHelpers.removeMnemonics(text)
  65. }
  66. /*! The background for the full menu bar.
  67. The background will be extended to the full containing window width.
  68. Its height will always fit all of the menu bar items. The final size
  69. will include the paddings.
  70. */
  71. property Component background: Rectangle {
  72. color: "#dcdcdc"
  73. implicitHeight: 20
  74. }
  75. /*! The menu bar item.
  76. \target styleData properties
  77. This item has to be configured using the \b styleData object which is in scope,
  78. and contains the following read-only properties:
  79. \table
  80. \row \li \b {styleData.index} : int \li The index of the menu item in its menu.
  81. \row \li \b {styleData.selected} : bool \li \c true if the menu item is selected.
  82. \row \li \b {styleData.open} : bool \li \c true when the pull down menu is open.
  83. \row \li \b {styleData.text} : string \li The menu bar item's text.
  84. \row \li \b {styleData.underlineMnemonic} : bool \li When \c true, the style should underline the menu item's label mnemonic.
  85. \endtable
  86. */
  87. property Component itemDelegate: Rectangle {
  88. implicitWidth: text.width + 12
  89. implicitHeight: text.height + 4
  90. color: styleData.enabled && styleData.open ? "#49d" : "transparent"
  91. Text {
  92. id: text
  93. font: root.font
  94. text: formatMnemonic(styleData.text, styleData.underlineMnemonic)
  95. anchors.centerIn: parent
  96. renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  97. color: styleData.open ? "white" : SystemPaletteSingleton.windowText(control.enabled && styleData.enabled)
  98. }
  99. }
  100. /*! The style component for the menubar's own menus and their submenus.
  101. \sa {MenuStyle}
  102. */
  103. property Component menuStyle: MenuStyle {
  104. font: root.font
  105. }
  106. /*!
  107. \since QtQuick.Controls.Styles 1.3
  108. The font of the control.
  109. */
  110. property font font
  111. /*! \internal */
  112. property bool __isNative: true
  113. }