0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the Qt Designer of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
//
|
|
43 |
// W A R N I N G
|
|
44 |
// -------------
|
|
45 |
//
|
|
46 |
// This file is not part of the Qt API. It exists for the convenience
|
|
47 |
// of Qt Designer. This header
|
|
48 |
// file may change from version to version without notice, or even be removed.
|
|
49 |
//
|
|
50 |
// We mean it.
|
|
51 |
//
|
|
52 |
|
|
53 |
#ifndef QDESIGNER_MENU_H
|
|
54 |
#define QDESIGNER_MENU_H
|
|
55 |
|
|
56 |
#include "shared_global_p.h"
|
|
57 |
|
|
58 |
#include <QtGui/QAction>
|
|
59 |
#include <QtGui/QMenu>
|
|
60 |
#include <QtCore/QHash>
|
|
61 |
|
|
62 |
QT_BEGIN_NAMESPACE
|
|
63 |
|
|
64 |
class QTimer;
|
|
65 |
class QLineEdit;
|
|
66 |
|
|
67 |
class QDesignerFormWindowInterface;
|
|
68 |
class QDesignerActionProviderExtension;
|
|
69 |
class QDesignerMenu;
|
|
70 |
class QDesignerMenuBar;
|
|
71 |
class QPainter;
|
|
72 |
class QMimeData;
|
|
73 |
|
|
74 |
namespace qdesigner_internal {
|
|
75 |
class CreateSubmenuCommand;
|
|
76 |
class ActionInsertionCommand;
|
|
77 |
}
|
|
78 |
|
|
79 |
class QDESIGNER_SHARED_EXPORT QDesignerMenu: public QMenu
|
|
80 |
{
|
|
81 |
Q_OBJECT
|
|
82 |
public:
|
|
83 |
QDesignerMenu(QWidget *parent = 0);
|
|
84 |
virtual ~QDesignerMenu();
|
|
85 |
|
|
86 |
bool eventFilter(QObject *object, QEvent *event);
|
|
87 |
|
|
88 |
QDesignerFormWindowInterface *formWindow() const;
|
|
89 |
QDesignerActionProviderExtension *actionProvider();
|
|
90 |
|
|
91 |
QDesignerMenu *parentMenu() const;
|
|
92 |
QDesignerMenuBar *parentMenuBar() const;
|
|
93 |
|
|
94 |
virtual void setVisible(bool visible);
|
|
95 |
|
|
96 |
void adjustSpecialActions();
|
|
97 |
|
|
98 |
bool interactive(bool i);
|
|
99 |
void createRealMenuAction(QAction *action);
|
|
100 |
void removeRealMenu(QAction *action);
|
|
101 |
|
|
102 |
static void drawSelection(QPainter *p, const QRect &r);
|
|
103 |
|
|
104 |
bool dragging() const;
|
|
105 |
|
|
106 |
void closeMenuChain();
|
|
107 |
|
|
108 |
void moveLeft();
|
|
109 |
void moveRight();
|
|
110 |
void moveUp(bool ctrl);
|
|
111 |
void moveDown(bool ctrl);
|
|
112 |
|
|
113 |
// Helper for MenuTaskMenu extension
|
|
114 |
void deleteAction(QAction *a);
|
|
115 |
|
|
116 |
private slots:
|
|
117 |
void slotAddSeparator();
|
|
118 |
void slotRemoveSelectedAction();
|
|
119 |
void slotShowSubMenuNow();
|
|
120 |
void slotDeactivateNow();
|
|
121 |
void slotAdjustSizeNow();
|
|
122 |
|
|
123 |
protected:
|
|
124 |
virtual void actionEvent(QActionEvent *event);
|
|
125 |
virtual void dragEnterEvent(QDragEnterEvent *event);
|
|
126 |
virtual void dragMoveEvent(QDragMoveEvent *event);
|
|
127 |
virtual void dragLeaveEvent(QDragLeaveEvent *event);
|
|
128 |
virtual void dropEvent(QDropEvent *event);
|
|
129 |
virtual void paintEvent(QPaintEvent *event);
|
|
130 |
virtual void keyPressEvent(QKeyEvent *event);
|
|
131 |
virtual void keyReleaseEvent(QKeyEvent *event);
|
|
132 |
virtual void showEvent(QShowEvent *event);
|
|
133 |
|
|
134 |
bool handleEvent(QWidget *widget, QEvent *event);
|
|
135 |
bool handleMouseDoubleClickEvent(QWidget *widget, QMouseEvent *event);
|
|
136 |
bool handleMousePressEvent(QWidget *widget, QMouseEvent *event);
|
|
137 |
bool handleMouseReleaseEvent(QWidget *widget, QMouseEvent *event);
|
|
138 |
bool handleMouseMoveEvent(QWidget *widget, QMouseEvent *event);
|
|
139 |
bool handleContextMenuEvent(QWidget *widget, QContextMenuEvent *event);
|
|
140 |
bool handleKeyPressEvent(QWidget *widget, QKeyEvent *event);
|
|
141 |
|
|
142 |
void startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers);
|
|
143 |
|
|
144 |
void adjustIndicator(const QPoint &pos);
|
|
145 |
int findAction(const QPoint &pos) const;
|
|
146 |
|
|
147 |
QAction *currentAction() const;
|
|
148 |
int realActionCount() const;
|
|
149 |
enum ActionDragCheck { NoActionDrag, ActionDragOnSubMenu, AcceptActionDrag };
|
|
150 |
ActionDragCheck checkAction(QAction *action) const;
|
|
151 |
|
|
152 |
void showSubMenu(QAction *action);
|
|
153 |
|
|
154 |
enum LeaveEditMode {
|
|
155 |
Default = 0,
|
|
156 |
ForceAccept
|
|
157 |
};
|
|
158 |
|
|
159 |
void enterEditMode();
|
|
160 |
void leaveEditMode(LeaveEditMode mode);
|
|
161 |
void showLineEdit();
|
|
162 |
|
|
163 |
QAction *createAction(const QString &text, bool separator = false);
|
|
164 |
QDesignerMenu *findOrCreateSubMenu(QAction *action);
|
|
165 |
|
|
166 |
QAction *safeActionAt(int index) const;
|
|
167 |
QAction *safeMenuAction(QDesignerMenu *menu) const;
|
|
168 |
bool swap(int a, int b);
|
|
169 |
|
|
170 |
void hideSubMenu();
|
|
171 |
void deleteAction();
|
|
172 |
void deactivateMenu();
|
|
173 |
|
|
174 |
bool canCreateSubMenu(QAction *action) const;
|
|
175 |
QDesignerMenu *findRootMenu() const;
|
|
176 |
QDesignerMenu *findActivatedMenu() const;
|
|
177 |
|
|
178 |
QRect subMenuPixmapRect(QAction *action) const;
|
|
179 |
bool hasSubMenuPixmap(QAction *action) const;
|
|
180 |
|
|
181 |
void selectCurrentAction();
|
|
182 |
|
|
183 |
private:
|
|
184 |
bool hideSubMenuOnCursorKey();
|
|
185 |
bool showSubMenuOnCursorKey();
|
|
186 |
|
|
187 |
QPoint m_startPosition;
|
|
188 |
int m_currentIndex;
|
|
189 |
QAction *m_addItem;
|
|
190 |
QAction *m_addSeparator;
|
|
191 |
QHash<QAction*, QDesignerMenu*> m_subMenus;
|
|
192 |
QTimer *m_showSubMenuTimer;
|
|
193 |
QTimer *m_deactivateWindowTimer;
|
|
194 |
QTimer *m_adjustSizeTimer;
|
|
195 |
bool m_interactive;
|
|
196 |
QLineEdit *m_editor;
|
|
197 |
bool m_dragging;
|
|
198 |
int m_lastSubMenuIndex;
|
|
199 |
|
|
200 |
friend class qdesigner_internal::CreateSubmenuCommand;
|
|
201 |
friend class qdesigner_internal::ActionInsertionCommand;
|
|
202 |
};
|
|
203 |
|
|
204 |
QT_END_NAMESPACE
|
|
205 |
|
|
206 |
#endif // QDESIGNER_MENU_H
|