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 Designer of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 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 General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 // 30 // W A R N I N G 31 // ------------- 32 // 33 // This file is not part of the Qt API. It exists for the convenience 34 // of Qt Designer. This header 35 // file may change from version to version without notice, or even be removed. 36 // 37 // We mean it. 38 // 39 40 #ifndef QDESIGNER_MENUBAR_H 41 #define QDESIGNER_MENUBAR_H 42 43 #include "shared_global_p.h" 44 45 #include <QtWidgets/qaction.h> 46 #include <QtWidgets/qmenubar.h> 47 48 #include <QtCore/qpointer.h> 49 #include <QtCore/qmimedata.h> 50 51 QT_BEGIN_NAMESPACE 52 53 class QDesignerFormWindowInterface; 54 class QDesignerActionProviderExtension; 55 56 class QLineEdit; 57 class QMimeData; 58 59 namespace qdesigner_internal { 60 class PromotionTaskMenu; 61 62 class SpecialMenuAction: public QAction 63 { 64 Q_OBJECT 65 public: 66 SpecialMenuAction(QObject *parent = nullptr); 67 ~SpecialMenuAction() override; 68 }; 69 70 } // namespace qdesigner_internal 71 72 class QDESIGNER_SHARED_EXPORT QDesignerMenuBar: public QMenuBar 73 { 74 Q_OBJECT 75 public: 76 QDesignerMenuBar(QWidget *parent = nullptr); 77 ~QDesignerMenuBar() override; 78 79 bool eventFilter(QObject *object, QEvent *event) override; 80 81 QDesignerFormWindowInterface *formWindow() const; 82 QDesignerActionProviderExtension *actionProvider(); 83 84 void adjustSpecialActions(); 85 bool dragging() const; 86 87 void moveLeft(bool ctrl = false); 88 void moveRight(bool ctrl = false); 89 void moveUp(); 90 void moveDown(); 91 92 // Helpers for MenuTaskMenu/MenuBarTaskMenu extensions 93 QList<QAction *> contextMenuActions(); 94 void deleteMenuAction(QAction *action); 95 96 private slots: 97 void deleteMenu(); 98 void slotRemoveMenuBar(); 99 100 protected: 101 void actionEvent(QActionEvent *event) override; 102 void dragEnterEvent(QDragEnterEvent *event) override; 103 void dragMoveEvent(QDragMoveEvent *event) override; 104 void dragLeaveEvent(QDragLeaveEvent *event) override; 105 void dropEvent(QDropEvent *event) override; 106 void paintEvent(QPaintEvent *event) override; 107 void focusOutEvent(QFocusEvent *event) override; 108 void keyPressEvent(QKeyEvent *event) override; 109 void keyReleaseEvent(QKeyEvent *event) override; 110 111 bool handleEvent(QWidget *widget, QEvent *event); 112 bool handleMouseDoubleClickEvent(QWidget *widget, QMouseEvent *event); 113 bool handleMousePressEvent(QWidget *widget, QMouseEvent *event); 114 bool handleMouseReleaseEvent(QWidget *widget, QMouseEvent *event); 115 bool handleMouseMoveEvent(QWidget *widget, QMouseEvent *event); 116 bool handleContextMenuEvent(QWidget *widget, QContextMenuEvent *event); 117 bool handleKeyPressEvent(QWidget *widget, QKeyEvent *event); 118 119 void startDrag(const QPoint &pos); 120 121 enum ActionDragCheck { NoActionDrag, ActionDragOnSubMenu, AcceptActionDrag }; 122 ActionDragCheck checkAction(QAction *action) const; 123 124 void adjustIndicator(const QPoint &pos); 125 int findAction(const QPoint &pos) const; 126 127 QAction *currentAction() const; 128 int realActionCount() const; 129 130 enum LeaveEditMode { 131 Default = 0, 132 ForceAccept 133 }; 134 135 void enterEditMode(); 136 void leaveEditMode(LeaveEditMode mode); 137 void showLineEdit(); 138 139 void showMenu(int index = -1); 140 void hideMenu(int index = -1); 141 142 QAction *safeActionAt(int index) const; 143 144 bool swapActions(int a, int b); 145 146 private: 147 void updateCurrentAction(bool selectAction); 148 void movePrevious(bool ctrl); 149 void moveNext(bool ctrl); 150 151 QAction *m_addMenu; 152 QPointer<QMenu> m_activeMenu; 153 QPoint m_startPosition; 154 int m_currentIndex = 0; 155 QLineEdit *m_editor; 156 bool m_dragging = false; 157 int m_lastMenuActionIndex = -1; 158 QPointer<QWidget> m_lastFocusWidget; 159 qdesigner_internal::PromotionTaskMenu* m_promotionTaskMenu; 160 }; 161 162 QT_END_NAMESPACE 163 164 #endif // QDESIGNER_MENUBAR_H 165