Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdesigner_menu_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of Qt Designer. This header
10// file may change from version to version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QDESIGNER_MENU_H
16#define QDESIGNER_MENU_H
17
19
20#include <QtWidgets/qmenu.h>
21
22#include <QtGui/qaction.h>
23#include <QtGui/qpixmap.h>
24
25#include <QtCore/qhash.h>
26
28
29class QTimer;
30class QLineEdit;
31
32class QDesignerFormWindowInterface;
34class QDesignerMenu;
35class QDesignerMenuBar;
36class QPainter;
37class QMimeData;
38
39namespace qdesigner_internal {
40 class CreateSubmenuCommand;
41 class ActionInsertionCommand;
42}
43
45{
46 Q_OBJECT
47public:
48 QDesignerMenu(QWidget *parent = nullptr);
49 ~QDesignerMenu() override;
50
51 bool eventFilter(QObject *object, QEvent *event) override;
52
53 QDesignerFormWindowInterface *formWindow() const;
54 QDesignerActionProviderExtension *actionProvider();
55
56 QDesignerMenu *parentMenu() const;
57 QDesignerMenuBar *parentMenuBar() const;
58
59 void setVisible(bool visible) override;
60
61 void adjustSpecialActions();
62
63 void createRealMenuAction(QAction *action);
64 void removeRealMenu(QAction *action);
65
66 static void drawSelection(QPainter *p, const QRect &r);
67
68 bool dragging() const;
69
70 void closeMenuChain();
71
72 void moveLeft();
73 void moveRight();
74 void moveUp(bool ctrl);
75 void moveDown(bool ctrl);
76
77 // Helper for MenuTaskMenu extension
78 void deleteAction(QAction *a);
79
80private slots:
81 void slotAddSeparator();
82 void slotRemoveSelectedAction();
83 void slotShowSubMenuNow();
84 void slotDeactivateNow();
85 void slotAdjustSizeNow();
86
87protected:
88 void actionEvent(QActionEvent *event) override;
89 void dragEnterEvent(QDragEnterEvent *event) override;
90 void dragMoveEvent(QDragMoveEvent *event) override;
91 void dragLeaveEvent(QDragLeaveEvent *event) override;
92 void dropEvent(QDropEvent *event) override;
93 void paintEvent(QPaintEvent *event) override;
94 void keyPressEvent(QKeyEvent *event) override;
95 void keyReleaseEvent(QKeyEvent *event) override;
96 void showEvent(QShowEvent *event) override;
97
98 bool handleEvent(QWidget *widget, QEvent *event);
99 bool handleMouseDoubleClickEvent(QWidget *widget, QMouseEvent *event);
100 bool handleMousePressEvent(QWidget *widget, QMouseEvent *event);
101 bool handleMouseReleaseEvent(QWidget *widget, QMouseEvent *event);
102 bool handleMouseMoveEvent(QWidget *widget, QMouseEvent *event);
103 bool handleContextMenuEvent(QWidget *widget, QContextMenuEvent *event);
104 bool handleKeyPressEvent(QWidget *widget, QKeyEvent *event);
105
106 void startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers);
107
108 void adjustIndicator(const QPoint &pos);
109 int findAction(const QPoint &pos) const;
110
111 QAction *currentAction() const;
112 int realActionCount() const;
113 enum ActionDragCheck { NoActionDrag, ActionDragOnSubMenu, AcceptActionDrag };
114 ActionDragCheck checkAction(QAction *action) const;
115
116 void showSubMenu(QAction *action);
117
118 enum LeaveEditMode {
119 Default = 0,
120 ForceAccept
121 };
122
123 void enterEditMode();
124 void leaveEditMode(LeaveEditMode mode);
125 void showLineEdit();
126
127 QAction *createAction(const QString &text, bool separator = false);
128 QDesignerMenu *findOrCreateSubMenu(QAction *action);
129
130 QAction *safeActionAt(int index) const;
131 QAction *safeMenuAction(QDesignerMenu *menu) const;
132 bool swap(int a, int b);
133
134 void hideSubMenu();
135 void deleteAction();
136 void deactivateMenu();
137
138 bool canCreateSubMenu(QAction *action) const;
139 QDesignerMenu *findRootMenu() const;
140 QDesignerMenu *findActivatedMenu() const;
141
142 QRect subMenuPixmapRect(QAction *action) const;
143 bool hasSubMenuPixmap(QAction *action) const;
144
145 void selectCurrentAction();
146
147private:
148 bool hideSubMenuOnCursorKey();
149 bool showSubMenuOnCursorKey();
150 const QPixmap m_subMenuPixmap;
151
152 QPoint m_startPosition;
153 int m_currentIndex = 0;
154 QAction *m_addItem;
155 QAction *m_addSeparator;
156 QHash<QAction*, QDesignerMenu*> m_subMenus;
157 QTimer *m_showSubMenuTimer;
158 QTimer *m_deactivateWindowTimer;
159 QTimer *m_adjustSizeTimer;
160 QLineEdit *m_editor;
161 bool m_dragging = false;
162 int m_lastSubMenuIndex = -1;
163
164 friend class qdesigner_internal::CreateSubmenuCommand;
165 friend class qdesigner_internal::ActionInsertionCommand;
166};
167
168QT_END_NAMESPACE
169
170#endif // QDESIGNER_MENU_H
virtual bool dynamicPropertiesAllowed() const =0
virtual bool isDynamicProperty(int index) const =0
virtual bool isLanguageResource(const QString &path) const =0
friend class QPainter
friend class QWidget
Definition qpainter.h:421
QDesignerFormEditorInterface * core() const override
Returns a pointer to \QD's current QDesignerFormEditorInterface object.
void layoutDefault(int *margin, int *spacing) override
Fills in the default margin and spacing for the form's default layout in the margin and spacing varia...
QWidget * mainContainer() const override
Returns the main container widget for the form window.
void manageWidget(QWidget *w) override
Instructs the form window to manage the specified widget.
int toolCount() const override
Returns the number of tools available.
static void markChangedStretchProperties(QDesignerFormEditorInterface *core, QLayout *lt, const DomLayout *domLayout)
static void stretchAttributesToDom(QDesignerFormEditorInterface *core, QLayout *lt, DomLayout *domLayout)
QVariant toNativeValue(const QVariant &value) const override
bool isResourceType(const QVariant &value) const override
QVariant loadResource(const QDir &workingDirectory, const DomProperty *icon) const override
QDesignerResourceBuilder(QDesignerFormEditorInterface *core, DesignerPixmapCache *pixmapCache, DesignerIconCache *iconCache)
DomProperty * saveResource(const QDir &workingDirectory, const QVariant &value) const override
void setIconCache(DesignerIconCache *iconCache)
void setPixmapCache(DesignerPixmapCache *pixmapCache)
DomActionGroup * createDom(QActionGroup *actionGroup) override
QWidget * load(QIODevice *dev, QWidget *parentWidget) override
Loads an XML representation of a widget from the given device, and constructs a new widget with the s...
bool addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout) override
DomLayoutItem * createDom(QLayoutItem *item, DomLayout *ui_layout, DomWidget *ui_parentWidget) override
DomLayout * createDom(QLayout *layout, DomLayout *ui_layout, DomWidget *ui_parentWidget) override
void applyProperties(QObject *o, const QList< DomProperty * > &properties) override
void createCustomWidgets(DomCustomWidgets *) override
QLayout * create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget) override
void applyTabStops(QWidget *widget, DomTabStops *tabStops) override
DomWidget * saveWidget(QToolBar *toolBar, DomWidget *ui_parentWidget)
DomCustomWidgets * saveCustomWidgets() override
DomWidget * saveWidget(QDesignerDockWidget *dockWidget, DomWidget *ui_parentWidget)
DomUI * copy(const FormBuilderClipboard &selection) override
QAction * create(DomAction *ui_action, QObject *parent) override
QActionGroup * create(DomActionGroup *ui_action_group, QObject *parent) override
DomWidget * saveWidget(QWizardPage *wizardPage, DomWidget *ui_parentWidget)
void saveDom(DomUI *ui, QWidget *widget) override
void createResources(DomResources *) override
void save(QIODevice *dev, QWidget *widget) override
Saves an XML representation of the given widget to the specified device in the standard UI file forma...
QLayoutItem * create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget) override
QWidget * create(DomUI *ui, QWidget *parentWidget) override
QWidget * loadUi(DomUI *ui, QWidget *parentWidget)
void loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) override
DomWidget * createDom(QWidget *widget, DomWidget *ui_parentWidget, bool recursive=true) override
DomWidget * saveWidget(QTabWidget *widget, DomWidget *ui_parentWidget)
DomWidget * saveWidget(QToolBox *widget, DomWidget *ui_parentWidget)
FormBuilderClipboard paste(DomUI *ui, QWidget *widgetParent, QObject *actionParent=nullptr) override
DomWidget * saveWidget(QWidget *widget, QDesignerContainerExtension *container, DomWidget *ui_parentWidget)
bool addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) override
void layoutInfo(DomLayout *layout, QObject *parent, int *margin, int *spacing) override
FormBuilderClipboard paste(QIODevice *dev, QWidget *widgetParent, QObject *actionParent=nullptr) override
QList< DomProperty * > computeProperties(QObject *obj) override
DomWidget * saveWidget(QStackedWidget *widget, DomWidget *ui_parentWidget)
QWidget * create(DomWidget *ui_widget, QWidget *parentWidget) override
bool copy(QIODevice *dev, const FormBuilderClipboard &selection) override
QVariant toNativeValue(const QVariant &value) const override
DomProperty * saveText(const QVariant &value) const override
QVariant loadText(const DomProperty *icon) const override
static bool checkProperty(const QString &propertyName)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QString messageBoxTitle()
static void setIconPixmap(QIcon::Mode m, QIcon::State s, const QDir &workingDirectory, QString path, PropertySheetIconValue &icon, const QDesignerLanguageExtension *lang=nullptr)
static DomProperty * stringToDomProperty(const QString &value, const PropertySheetTranslatableData &translatableData)
QString msgUnmanagedPage(QDesignerFormEditorInterface *core, QWidget *container, int index, QWidget *page)
static DomProperty * stringToDomProperty(const QString &value)
void translationParametersToDom(const PropertySheetTranslatableData &data, DomElement *e)
static bool supportsQualifiedEnums(const QVersionNumber &qtVersion)
static bool hasSetter(QDesignerFormEditorInterface *core, QObject *object, const QString &propertyName)
static bool isDeprecatedQt5Property(const QObject *o, const DomProperty *p)
static bool readDomEnumerationValue(const DomProperty *p, const QDesignerPropertySheetExtension *sheet, int index, QVariant &v)
static bool checkContainerProperty(const QWidget *w, const QString &propertyName)
void translationParametersFromDom(const DomElement *e, PropertySheetTranslatableData *data)
#define OLD_RESOURCE_FORMAT
static constexpr auto clipboardObjectName
static constexpr auto currentUiVersion
#define QDESIGNER_SHARED_EXPORT