qmenubar.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 QtWidgets 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. #ifndef QMENUBAR_H
  40. #define QMENUBAR_H
  41. #include <QtWidgets/qmenu.h>
  42. QT_BEGIN_NAMESPACE
  43. #ifndef QT_NO_MENUBAR
  44. class QMenuBarPrivate;
  45. class QStyleOptionMenuItem;
  46. class QWindowsStyle;
  47. class QPlatformMenuBar;
  48. class Q_WIDGETS_EXPORT QMenuBar : public QWidget
  49. {
  50. Q_OBJECT
  51. Q_PROPERTY(bool defaultUp READ isDefaultUp WRITE setDefaultUp)
  52. Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar)
  53. public:
  54. explicit QMenuBar(QWidget *parent = Q_NULLPTR);
  55. ~QMenuBar();
  56. using QWidget::addAction;
  57. QAction *addAction(const QString &text);
  58. QAction *addAction(const QString &text, const QObject *receiver, const char* member);
  59. QAction *addMenu(QMenu *menu);
  60. QMenu *addMenu(const QString &title);
  61. QMenu *addMenu(const QIcon &icon, const QString &title);
  62. QAction *addSeparator();
  63. QAction *insertSeparator(QAction *before);
  64. QAction *insertMenu(QAction *before, QMenu *menu);
  65. void clear();
  66. QAction *activeAction() const;
  67. void setActiveAction(QAction *action);
  68. void setDefaultUp(bool);
  69. bool isDefaultUp() const;
  70. QSize sizeHint() const;
  71. QSize minimumSizeHint() const;
  72. int heightForWidth(int) const;
  73. QRect actionGeometry(QAction *) const;
  74. QAction *actionAt(const QPoint &) const;
  75. void setCornerWidget(QWidget *w, Qt::Corner corner = Qt::TopRightCorner);
  76. QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
  77. #ifdef Q_OS_WINCE
  78. void setDefaultAction(QAction *);
  79. QAction *defaultAction() const;
  80. static void wceCommands(uint command);
  81. static void wceRefresh();
  82. #endif
  83. #ifdef Q_OS_OSX
  84. NSMenu* toNSMenu();
  85. #endif
  86. bool isNativeMenuBar() const;
  87. void setNativeMenuBar(bool nativeMenuBar);
  88. QPlatformMenuBar *platformMenuBar();
  89. public Q_SLOTS:
  90. virtual void setVisible(bool visible);
  91. Q_SIGNALS:
  92. void triggered(QAction *action);
  93. void hovered(QAction *action);
  94. protected:
  95. void changeEvent(QEvent *);
  96. void keyPressEvent(QKeyEvent *);
  97. void mouseReleaseEvent(QMouseEvent *);
  98. void mousePressEvent(QMouseEvent *);
  99. void mouseMoveEvent(QMouseEvent *);
  100. void leaveEvent(QEvent *);
  101. void paintEvent(QPaintEvent *);
  102. void resizeEvent(QResizeEvent *);
  103. void actionEvent(QActionEvent *);
  104. void focusOutEvent(QFocusEvent *);
  105. void focusInEvent(QFocusEvent *);
  106. void timerEvent(QTimerEvent *);
  107. bool eventFilter(QObject *, QEvent *);
  108. bool event(QEvent *);
  109. void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const;
  110. private:
  111. Q_DECLARE_PRIVATE(QMenuBar)
  112. Q_DISABLE_COPY(QMenuBar)
  113. Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())
  114. Q_PRIVATE_SLOT(d_func(), void _q_actionHovered())
  115. Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int))
  116. Q_PRIVATE_SLOT(d_func(), void _q_updateLayout())
  117. #ifdef Q_OS_WINCE
  118. Q_PRIVATE_SLOT(d_func(), void _q_updateDefaultAction())
  119. #endif
  120. friend class QMenu;
  121. friend class QMenuPrivate;
  122. friend class QWindowsStyle;
  123. };
  124. #endif // QT_NO_MENUBAR
  125. QT_END_NAMESPACE
  126. #endif // QMENUBAR_H