author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 29 | b72c6db6890b |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module 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 |
#include "qmenu.h" |
|
43 |
||
44 |
#ifndef QT_NO_MENU |
|
45 |
||
46 |
#include "qdebug.h" |
|
47 |
#include "qstyle.h" |
|
48 |
#include "qevent.h" |
|
49 |
#include "qtimer.h" |
|
50 |
#include "qlayout.h" |
|
51 |
#include "qpainter.h" |
|
52 |
#include "qapplication.h" |
|
53 |
#include "qdesktopwidget.h" |
|
54 |
#ifndef QT_NO_ACCESSIBILITY |
|
55 |
# include "qaccessible.h" |
|
56 |
#endif |
|
57 |
#ifndef QT_NO_EFFECTS |
|
58 |
# include <private/qeffects_p.h> |
|
59 |
#endif |
|
60 |
#ifndef QT_NO_WHATSTHIS |
|
61 |
# include <qwhatsthis.h> |
|
62 |
#endif |
|
63 |
||
64 |
#include "qmenu_p.h" |
|
65 |
#include "qmenubar_p.h" |
|
66 |
#include "qwidgetaction.h" |
|
67 |
#include "qtoolbutton.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
#include "qpushbutton.h" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
#include <private/qpushbutton_p.h> |
0 | 70 |
#include <private/qaction_p.h> |
71 |
#include <private/qsoftkeymanager_p.h> |
|
72 |
#ifdef QT3_SUPPORT |
|
73 |
#include <qmenudata.h> |
|
74 |
#endif // QT3_SUPPORT |
|
75 |
||
76 |
#ifdef Q_WS_X11 |
|
77 |
# include <private/qt_x11_p.h> |
|
78 |
#endif |
|
79 |
||
80 |
#if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) |
|
81 |
# include <private/qcore_mac_p.h> |
|
82 |
# include <private/qt_cocoa_helpers_mac_p.h> |
|
83 |
#endif |
|
84 |
||
85 |
||
86 |
QT_BEGIN_NAMESPACE |
|
87 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
88 |
QMenu *QMenuPrivate::mouseDown = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
89 |
int QMenuPrivate::sloppyDelayTimer = 0; |
0 | 90 |
|
91 |
/* QMenu code */ |
|
92 |
// internal class used for the torn off popup |
|
93 |
class QTornOffMenu : public QMenu |
|
94 |
{ |
|
95 |
Q_OBJECT |
|
96 |
class QTornOffMenuPrivate : public QMenuPrivate |
|
97 |
{ |
|
98 |
Q_DECLARE_PUBLIC(QMenu) |
|
99 |
public: |
|
100 |
QTornOffMenuPrivate(QMenu *p) : causedMenu(p) { |
|
101 |
tornoff = 1; |
|
102 |
causedPopup.widget = 0; |
|
103 |
causedPopup.action = ((QTornOffMenu*)p)->d_func()->causedPopup.action; |
|
104 |
causedStack = ((QTornOffMenu*)p)->d_func()->calcCausedStack(); |
|
105 |
} |
|
106 |
QList<QPointer<QWidget> > calcCausedStack() const { return causedStack; } |
|
107 |
QPointer<QMenu> causedMenu; |
|
108 |
QList<QPointer<QWidget> > causedStack; |
|
109 |
}; |
|
110 |
public: |
|
111 |
QTornOffMenu(QMenu *p) : QMenu(*(new QTornOffMenuPrivate(p))) |
|
112 |
{ |
|
113 |
Q_D(QTornOffMenu); |
|
114 |
// make the torn-off menu a sibling of p (instead of a child) |
|
115 |
QWidget *parentWidget = d->causedStack.isEmpty() ? p : d->causedStack.last(); |
|
116 |
if (parentWidget->parentWidget()) |
|
117 |
parentWidget = parentWidget->parentWidget(); |
|
118 |
setParent(parentWidget, Qt::Window | Qt::Tool); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
119 |
setAttribute(Qt::WA_DeleteOnClose, true); |
0 | 120 |
setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true); |
121 |
setWindowTitle(p->windowTitle()); |
|
122 |
setEnabled(p->isEnabled()); |
|
123 |
//QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*))); |
|
124 |
//QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*))); |
|
125 |
QList<QAction*> items = p->actions(); |
|
126 |
for(int i = 0; i < items.count(); i++) |
|
127 |
addAction(items.at(i)); |
|
128 |
} |
|
129 |
void syncWithMenu(QMenu *menu, QActionEvent *act) |
|
130 |
{ |
|
131 |
Q_D(QTornOffMenu); |
|
132 |
if(menu != d->causedMenu) |
|
133 |
return; |
|
134 |
if (act->type() == QEvent::ActionAdded) { |
|
135 |
insertAction(act->before(), act->action()); |
|
136 |
} else if (act->type() == QEvent::ActionRemoved) |
|
137 |
removeAction(act->action()); |
|
138 |
} |
|
139 |
void actionEvent(QActionEvent *e) |
|
140 |
{ |
|
141 |
QMenu::actionEvent(e); |
|
142 |
setFixedSize(sizeHint()); |
|
143 |
} |
|
144 |
public slots: |
|
145 |
void onTrigger(QAction *action) { d_func()->activateAction(action, QAction::Trigger, false); } |
|
146 |
void onHovered(QAction *action) { d_func()->activateAction(action, QAction::Hover, false); } |
|
147 |
private: |
|
148 |
Q_DECLARE_PRIVATE(QTornOffMenu) |
|
149 |
friend class QMenuPrivate; |
|
150 |
}; |
|
151 |
||
152 |
void QMenuPrivate::init() |
|
153 |
{ |
|
154 |
Q_Q(QMenu); |
|
155 |
#ifndef QT_NO_WHATSTHIS |
|
156 |
q->setAttribute(Qt::WA_CustomWhatsThis); |
|
157 |
#endif |
|
158 |
q->setAttribute(Qt::WA_X11NetWmWindowTypePopupMenu); |
|
159 |
defaultMenuAction = menuAction = new QAction(q); |
|
160 |
menuAction->d_func()->menu = q; |
|
161 |
q->setMouseTracking(q->style()->styleHint(QStyle::SH_Menu_MouseTracking, 0, q)); |
|
162 |
if (q->style()->styleHint(QStyle::SH_Menu_Scrollable, 0, q)) { |
|
163 |
scroll = new QMenuPrivate::QMenuScroller; |
|
164 |
scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; |
|
165 |
} |
|
166 |
||
167 |
#ifdef QT_SOFTKEYS_ENABLED |
|
168 |
selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, q); |
|
169 |
cancelAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::CancelSoftKey, Qt::Key_Back, q); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
170 |
selectAction->setPriority(QAction::HighPriority); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
171 |
cancelAction->setPriority(QAction::HighPriority); |
0 | 172 |
q->addAction(selectAction); |
173 |
q->addAction(cancelAction); |
|
174 |
#endif |
|
175 |
} |
|
176 |
||
177 |
int QMenuPrivate::scrollerHeight() const |
|
178 |
{ |
|
179 |
Q_Q(const QMenu); |
|
180 |
return qMax(QApplication::globalStrut().height(), q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q)); |
|
181 |
} |
|
182 |
||
183 |
//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't |
|
184 |
QRect QMenuPrivate::popupGeometry(const QWidget *widget) const |
|
185 |
{ |
|
186 |
#ifdef Q_WS_WIN |
|
187 |
return QApplication::desktop()->screenGeometry(widget); |
|
188 |
#elif defined Q_WS_X11 |
|
189 |
if (X11->desktopEnvironment == DE_KDE) |
|
190 |
return QApplication::desktop()->screenGeometry(widget); |
|
191 |
else |
|
192 |
return QApplication::desktop()->availableGeometry(widget); |
|
193 |
#else |
|
194 |
return QApplication::desktop()->availableGeometry(widget); |
|
195 |
#endif |
|
196 |
} |
|
197 |
||
198 |
//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't |
|
199 |
QRect QMenuPrivate::popupGeometry(int screen) const |
|
200 |
{ |
|
201 |
#ifdef Q_WS_WIN |
|
202 |
return QApplication::desktop()->screenGeometry(screen); |
|
203 |
#elif defined Q_WS_X11 |
|
204 |
if (X11->desktopEnvironment == DE_KDE) |
|
205 |
return QApplication::desktop()->screenGeometry(screen); |
|
206 |
else |
|
207 |
return QApplication::desktop()->availableGeometry(screen); |
|
208 |
#else |
|
209 |
return QApplication::desktop()->availableGeometry(screen); |
|
210 |
#endif |
|
211 |
} |
|
212 |
||
213 |
QList<QPointer<QWidget> > QMenuPrivate::calcCausedStack() const |
|
214 |
{ |
|
215 |
QList<QPointer<QWidget> > ret; |
|
216 |
for(QWidget *widget = causedPopup.widget; widget; ) { |
|
217 |
ret.append(widget); |
|
218 |
if (QTornOffMenu *qtmenu = qobject_cast<QTornOffMenu*>(widget)) |
|
219 |
ret += qtmenu->d_func()->causedStack; |
|
220 |
if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) |
|
221 |
widget = qmenu->d_func()->causedPopup.widget; |
|
222 |
else |
|
223 |
break; |
|
224 |
} |
|
225 |
return ret; |
|
226 |
} |
|
227 |
||
228 |
void QMenuPrivate::updateActionRects() const |
|
229 |
{ |
|
230 |
Q_Q(const QMenu); |
|
231 |
if (!itemsDirty) |
|
232 |
return; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
|
0 | 234 |
q->ensurePolished(); |
235 |
||
236 |
//let's reinitialize the buffer |
|
237 |
actionRects.resize(actions.count()); |
|
238 |
actionRects.fill(QRect()); |
|
239 |
||
240 |
//let's try to get the last visible action |
|
241 |
int lastVisibleAction = actions.count() - 1; |
|
242 |
for(;lastVisibleAction >= 0; --lastVisibleAction) { |
|
243 |
const QAction *action = actions.at(lastVisibleAction); |
|
244 |
if (action->isVisible()) { |
|
245 |
//removing trailing separators |
|
246 |
if (action->isSeparator() && collapsibleSeparators) |
|
247 |
continue; |
|
248 |
break; |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
int max_column_width = 0, |
|
253 |
dh = popupGeometry(q).height(), |
|
254 |
y = 0; |
|
255 |
QStyle *style = q->style(); |
|
256 |
QStyleOption opt; |
|
257 |
opt.init(q); |
|
258 |
const int hmargin = style->pixelMetric(QStyle::PM_MenuHMargin, &opt, q), |
|
259 |
vmargin = style->pixelMetric(QStyle::PM_MenuVMargin, &opt, q), |
|
260 |
icone = style->pixelMetric(QStyle::PM_SmallIconSize, &opt, q); |
|
261 |
const int fw = style->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, q); |
|
262 |
const int deskFw = style->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, &opt, q); |
|
263 |
const int tearoffHeight = tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q) : 0; |
|
264 |
||
265 |
//for compatability now - will have to refactor this away.. |
|
266 |
tabWidth = 0; |
|
267 |
maxIconWidth = 0; |
|
268 |
hasCheckableItems = false; |
|
269 |
ncols = 1; |
|
270 |
sloppyAction = 0; |
|
271 |
||
272 |
for (int i = 0; i < actions.count(); ++i) { |
|
273 |
QAction *action = actions.at(i); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
if (action->isSeparator() || !action->isVisible() || widgetItems.contains(action)) |
0 | 275 |
continue; |
276 |
//..and some members |
|
277 |
hasCheckableItems |= action->isCheckable(); |
|
278 |
QIcon is = action->icon(); |
|
279 |
if (!is.isNull()) { |
|
280 |
maxIconWidth = qMax<uint>(maxIconWidth, icone + 4); |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
//calculate size |
|
285 |
QFontMetrics qfm = q->fontMetrics(); |
|
286 |
bool previousWasSeparator = true; // this is true to allow removing the leading separators |
|
287 |
for(int i = 0; i <= lastVisibleAction; i++) { |
|
288 |
QAction *action = actions.at(i); |
|
289 |
||
290 |
if (!action->isVisible() || |
|
291 |
(collapsibleSeparators && previousWasSeparator && action->isSeparator())) |
|
292 |
continue; // we continue, this action will get an empty QRect |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
|
0 | 294 |
previousWasSeparator = action->isSeparator(); |
295 |
||
296 |
//let the style modify the above size.. |
|
297 |
QStyleOptionMenuItem opt; |
|
298 |
q->initStyleOption(&opt, action); |
|
299 |
const QFontMetrics &fm = opt.fontMetrics; |
|
300 |
||
301 |
QSize sz; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
if (QWidget *w = widgetItems.value(action)) { |
0 | 303 |
sz = w->sizeHint().expandedTo(w->minimumSize()).expandedTo(w->minimumSizeHint()).boundedTo(w->maximumSize()); |
304 |
} else { |
|
305 |
//calc what I think the size is.. |
|
306 |
if (action->isSeparator()) { |
|
307 |
sz = QSize(2, 2); |
|
308 |
} else { |
|
309 |
QString s = action->text(); |
|
310 |
int t = s.indexOf(QLatin1Char('\t')); |
|
311 |
if (t != -1) { |
|
312 |
tabWidth = qMax(int(tabWidth), qfm.width(s.mid(t+1))); |
|
313 |
s = s.left(t); |
|
314 |
#ifndef QT_NO_SHORTCUT |
|
315 |
} else { |
|
316 |
QKeySequence seq = action->shortcut(); |
|
317 |
if (!seq.isEmpty()) |
|
318 |
tabWidth = qMax(int(tabWidth), qfm.width(seq)); |
|
319 |
#endif |
|
320 |
} |
|
321 |
sz.setWidth(fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, s).width()); |
|
322 |
sz.setHeight(qMax(fm.height(), qfm.height())); |
|
323 |
||
324 |
QIcon is = action->icon(); |
|
325 |
if (!is.isNull()) { |
|
326 |
QSize is_sz = QSize(icone, icone); |
|
327 |
if (is_sz.height() > sz.height()) |
|
328 |
sz.setHeight(is_sz.height()); |
|
329 |
} |
|
330 |
} |
|
331 |
sz = style->sizeFromContents(QStyle::CT_MenuItem, &opt, sz, q); |
|
332 |
} |
|
333 |
||
334 |
||
335 |
if (!sz.isEmpty()) { |
|
25
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
336 |
max_column_width = qMax(max_column_width, sz.width()); |
0 | 337 |
//wrapping |
338 |
if (!scroll && |
|
339 |
y+sz.height()+vmargin > dh - (deskFw * 2)) { |
|
340 |
ncols++; |
|
341 |
y = vmargin; |
|
342 |
} |
|
343 |
y += sz.height(); |
|
344 |
//update the item |
|
345 |
actionRects[i] = QRect(0, 0, sz.width(), sz.height()); |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
max_column_width += tabWidth; //finally add in the tab width |
|
25
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
350 |
const int sfcMargin = style->sizeFromContents(QStyle::CT_Menu, &opt, QApplication::globalStrut(), q).width() - QApplication::globalStrut().width(); |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
351 |
const int min_column_width = q->minimumWidth() - (sfcMargin + leftmargin + rightmargin + 2 * (fw + hmargin)); |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
352 |
max_column_width = qMax(min_column_width, max_column_width); |
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
353 |
|
0 | 354 |
|
355 |
//calculate position |
|
356 |
const int base_y = vmargin + fw + topmargin + |
|
357 |
(scroll ? scroll->scrollOffset : 0) + |
|
358 |
tearoffHeight; |
|
359 |
int x = hmargin + fw + leftmargin; |
|
360 |
y = base_y; |
|
361 |
||
362 |
for(int i = 0; i < actions.count(); i++) { |
|
363 |
QRect &rect = actionRects[i]; |
|
364 |
if (rect.isNull()) |
|
365 |
continue; |
|
366 |
if (!scroll && |
|
367 |
y+rect.height() > dh - deskFw * 2) { |
|
368 |
x += max_column_width + hmargin; |
|
369 |
y = base_y; |
|
370 |
} |
|
371 |
rect.translate(x, y); //move |
|
372 |
rect.setWidth(max_column_width); //uniform width |
|
373 |
||
374 |
//we need to update the widgets geometry |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
if (QWidget *widget = widgetItems.value(actions.at(i))) { |
0 | 376 |
widget->setGeometry(rect); |
377 |
widget->setVisible(actions.at(i)->isVisible()); |
|
378 |
} |
|
379 |
||
380 |
y += rect.height(); |
|
381 |
} |
|
382 |
itemsDirty = 0; |
|
383 |
} |
|
384 |
||
385 |
QRect QMenuPrivate::actionRect(QAction *act) const |
|
386 |
{ |
|
387 |
int index = actions.indexOf(act); |
|
388 |
if (index == -1) |
|
389 |
return QRect(); |
|
390 |
||
391 |
updateActionRects(); |
|
392 |
||
393 |
//we found the action |
|
394 |
return actionRects.at(index); |
|
395 |
} |
|
396 |
||
397 |
#if defined(Q_WS_MAC) |
|
398 |
static const qreal MenuFadeTimeInSec = 0.150; |
|
399 |
#endif |
|
400 |
||
401 |
void QMenuPrivate::hideUpToMenuBar() |
|
402 |
{ |
|
403 |
Q_Q(QMenu); |
|
404 |
bool fadeMenus = q->style()->styleHint(QStyle::SH_Menu_FadeOutOnHide); |
|
405 |
if (!tornoff) { |
|
406 |
QWidget *caused = causedPopup.widget; |
|
407 |
hideMenu(q); //hide after getting causedPopup |
|
408 |
while(caused) { |
|
409 |
#ifndef QT_NO_MENUBAR |
|
410 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) { |
|
411 |
mb->d_func()->setCurrentAction(0); |
|
412 |
mb->d_func()->setKeyboardMode(false); |
|
413 |
caused = 0; |
|
414 |
} else |
|
415 |
#endif |
|
416 |
if (QMenu *m = qobject_cast<QMenu*>(caused)) { |
|
417 |
caused = m->d_func()->causedPopup.widget; |
|
418 |
if (!m->d_func()->tornoff) |
|
419 |
hideMenu(m, fadeMenus); |
|
420 |
if (!fadeMenus) // Mac doesn't clear the action until after hidden. |
|
421 |
m->d_func()->setCurrentAction(0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
} else { caused = 0; |
0 | 423 |
} |
424 |
} |
|
425 |
#if defined(Q_WS_MAC) |
|
426 |
if (fadeMenus) { |
|
427 |
QEventLoop eventLoop; |
|
428 |
QTimer::singleShot(int(MenuFadeTimeInSec * 1000), &eventLoop, SLOT(quit())); |
|
429 |
QMacWindowFader::currentFader()->performFade(); |
|
430 |
eventLoop.exec(); |
|
431 |
} |
|
432 |
#endif |
|
433 |
} |
|
434 |
setCurrentAction(0); |
|
435 |
} |
|
436 |
||
437 |
void QMenuPrivate::hideMenu(QMenu *menu, bool justRegister) |
|
438 |
{ |
|
439 |
if (!menu) |
|
440 |
return; |
|
441 |
#if !defined(QT_NO_EFFECTS) |
|
442 |
menu->blockSignals(true); |
|
443 |
aboutToHide = true; |
|
444 |
// Flash item which is about to trigger (if any). |
|
445 |
if (menu->style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem) |
|
446 |
&& currentAction && currentAction == actionAboutToTrigger |
|
447 |
&& menu->actions().contains(currentAction)) { |
|
448 |
QEventLoop eventLoop; |
|
449 |
QAction *activeAction = currentAction; |
|
450 |
||
451 |
menu->setActiveAction(0); |
|
452 |
QTimer::singleShot(60, &eventLoop, SLOT(quit())); |
|
453 |
eventLoop.exec(); |
|
454 |
||
455 |
// Select and wait 20 ms. |
|
456 |
menu->setActiveAction(activeAction); |
|
457 |
QTimer::singleShot(20, &eventLoop, SLOT(quit())); |
|
458 |
eventLoop.exec(); |
|
459 |
} |
|
460 |
||
461 |
// Fade out. |
|
462 |
if (menu->style()->styleHint(QStyle::SH_Menu_FadeOutOnHide)) { |
|
463 |
// ### Qt 4.4: |
|
464 |
// Should be something like: q->transitionWindow(Qt::FadeOutTransition, MenuFadeTimeInSec); |
|
465 |
// Hopefully we'll integrate qt/research/windowtransitions into main before 4.4. |
|
466 |
// Talk to Richard, Trenton or Bjoern. |
|
467 |
#if defined(Q_WS_MAC) |
|
468 |
if (justRegister) { |
|
469 |
QMacWindowFader::currentFader()->setFadeDuration(MenuFadeTimeInSec); |
|
470 |
QMacWindowFader::currentFader()->registerWindowToFade(menu); |
|
471 |
} else { |
|
472 |
macWindowFade(qt_mac_window_for(menu), MenuFadeTimeInSec); |
|
473 |
} |
|
474 |
||
475 |
#endif // Q_WS_MAC |
|
476 |
} |
|
477 |
aboutToHide = false; |
|
478 |
menu->blockSignals(false); |
|
479 |
#endif // QT_NO_EFFECTS |
|
480 |
if (!justRegister) |
|
481 |
menu->hide(); |
|
482 |
} |
|
483 |
||
484 |
void QMenuPrivate::popupAction(QAction *action, int delay, bool activateFirst) |
|
485 |
{ |
|
486 |
Q_Q(QMenu); |
|
487 |
if (action && action->isEnabled()) { |
|
488 |
if (!delay) |
|
489 |
q->internalDelayedPopup(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
490 |
else if (!menuDelayTimer.isActive() && (!action->menu() || !action->menu()->isVisible())) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
491 |
menuDelayTimer.start(delay, q); |
0 | 492 |
if (activateFirst && action->menu()) |
493 |
action->menu()->d_func()->setFirstActionActive(); |
|
494 |
} else if (QMenu *menu = activeMenu) { //hide the current item |
|
495 |
activeMenu = 0; |
|
496 |
hideMenu(menu); |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
void QMenuPrivate::setSyncAction() |
|
501 |
{ |
|
502 |
Q_Q(QMenu); |
|
503 |
QAction *current = currentAction; |
|
504 |
if(current && (!current->isEnabled() || current->menu() || current->isSeparator())) |
|
505 |
current = 0; |
|
506 |
for(QWidget *caused = q; caused;) { |
|
507 |
if (QMenu *m = qobject_cast<QMenu*>(caused)) { |
|
508 |
caused = m->d_func()->causedPopup.widget; |
|
509 |
if (m->d_func()->eventLoop) |
|
510 |
m->d_func()->syncAction = current; // synchronous operation |
|
511 |
} else { |
|
512 |
break; |
|
513 |
} |
|
514 |
} |
|
515 |
} |
|
516 |
||
517 |
||
518 |
void QMenuPrivate::setFirstActionActive() |
|
519 |
{ |
|
520 |
Q_Q(QMenu); |
|
521 |
updateActionRects(); |
|
522 |
for(int i = 0, saccum = 0; i < actions.count(); i++) { |
|
523 |
const QRect &rect = actionRects.at(i); |
|
524 |
if (rect.isNull()) |
|
525 |
continue; |
|
526 |
if (scroll && scroll->scrollFlags & QMenuScroller::ScrollUp) { |
|
527 |
saccum -= rect.height(); |
|
528 |
if (saccum > scroll->scrollOffset - scrollerHeight()) |
|
529 |
continue; |
|
530 |
} |
|
531 |
QAction *act = actions.at(i); |
|
532 |
if (!act->isSeparator() && |
|
533 |
(q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q) |
|
534 |
|| act->isEnabled())) { |
|
535 |
setCurrentAction(act); |
|
536 |
break; |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
540 |
||
541 |
// popup == -1 means do not popup, 0 means immediately, others mean use a timer |
|
542 |
void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason reason, bool activateFirst) |
|
543 |
{ |
|
544 |
Q_Q(QMenu); |
|
545 |
tearoffHighlighted = 0; |
|
546 |
if (currentAction) |
|
547 |
q->update(actionRect(currentAction)); |
|
548 |
||
549 |
sloppyAction = 0; |
|
550 |
if (!sloppyRegion.isEmpty()) |
|
551 |
sloppyRegion = QRegion(); |
|
552 |
QMenu *hideActiveMenu = activeMenu; |
|
553 |
#ifndef QT_NO_STATUSTIP |
|
554 |
QAction *previousAction = currentAction; |
|
555 |
#endif |
|
556 |
#ifdef QT3_SUPPORT |
|
557 |
emitHighlighted = action; |
|
558 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
559 |
|
0 | 560 |
currentAction = action; |
561 |
if (action) { |
|
562 |
if (!action->isSeparator()) { |
|
563 |
activateAction(action, QAction::Hover); |
|
564 |
if (popup != -1) { |
|
565 |
hideActiveMenu = 0; //will be done "later" |
|
566 |
// if the menu is visible then activate the required action, |
|
567 |
// otherwise we just mark the action as currentAction |
|
568 |
// and activate it when the menu will be popuped. |
|
569 |
if (q->isVisible()) |
|
570 |
popupAction(currentAction, popup, activateFirst); |
|
571 |
} |
|
572 |
q->update(actionRect(action)); |
|
573 |
||
574 |
if (reason == SelectedFromKeyboard) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
QWidget *widget = widgetItems.value(action); |
0 | 576 |
if (widget) { |
577 |
if (widget->focusPolicy() != Qt::NoFocus) |
|
578 |
widget->setFocus(Qt::TabFocusReason); |
|
579 |
} else { |
|
580 |
//when the action has no QWidget, the QMenu itself should |
|
581 |
// get the focus |
|
582 |
// Since the menu is a pop-up, it uses the popup reason. |
|
583 |
if (!q->hasFocus()) { |
|
584 |
q->setFocus(Qt::PopupFocusReason); |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
} else { //action is a separator |
|
589 |
if (popup != -1) |
|
590 |
hideActiveMenu = 0; //will be done "later" |
|
591 |
} |
|
592 |
#ifndef QT_NO_STATUSTIP |
|
593 |
} else if (previousAction) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
594 |
previousAction->d_func()->showStatusText(topCausedWidget(), QString()); |
0 | 595 |
#endif |
596 |
} |
|
597 |
if (hideActiveMenu) { |
|
598 |
activeMenu = 0; |
|
599 |
#ifndef QT_NO_EFFECTS |
|
600 |
// kill any running effect |
|
601 |
qFadeEffect(0); |
|
602 |
qScrollEffect(0); |
|
603 |
#endif |
|
604 |
hideMenu(hideActiveMenu); |
|
605 |
} |
|
606 |
} |
|
607 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
608 |
//return the top causedPopup.widget that is not a QMenu |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
QWidget *QMenuPrivate::topCausedWidget() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
610 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
611 |
QWidget* top = causedPopup.widget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
612 |
while (QMenu* m = qobject_cast<QMenu *>(top)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
613 |
top = m->d_func()->causedPopup.widget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
614 |
return top; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
615 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
616 |
|
0 | 617 |
QAction *QMenuPrivate::actionAt(QPoint p) const |
618 |
{ |
|
619 |
if (!q_func()->rect().contains(p)) //sanity check |
|
620 |
return 0; |
|
621 |
||
622 |
for(int i = 0; i < actionRects.count(); i++) { |
|
623 |
if (actionRects.at(i).contains(p)) |
|
624 |
return actions.at(i); |
|
625 |
} |
|
626 |
return 0; |
|
627 |
} |
|
628 |
||
629 |
void QMenuPrivate::setOverrideMenuAction(QAction *a) |
|
630 |
{ |
|
631 |
Q_Q(QMenu); |
|
632 |
QObject::disconnect(menuAction, SIGNAL(destroyed()), q, SLOT(_q_overrideMenuActionDestroyed())); |
|
633 |
if (a) { |
|
634 |
menuAction = a; |
|
635 |
QObject::connect(a, SIGNAL(destroyed()), q, SLOT(_q_overrideMenuActionDestroyed())); |
|
636 |
} else { //we revert back to the default action created by the QMenu itself |
|
637 |
menuAction = defaultMenuAction; |
|
638 |
} |
|
639 |
} |
|
640 |
||
641 |
void QMenuPrivate::_q_overrideMenuActionDestroyed() |
|
642 |
{ |
|
643 |
menuAction=defaultMenuAction; |
|
644 |
} |
|
645 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
646 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
647 |
void QMenuPrivate::updateLayoutDirection() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
Q_Q(QMenu); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
650 |
//we need to mimic the cause of the popup's layout direction |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
651 |
//to allow setting it on a mainwindow for example |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
652 |
//we call setLayoutDirection_helper to not overwrite a user-defined value |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
653 |
if (!q->testAttribute(Qt::WA_SetLayoutDirection)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
654 |
if (QWidget *w = causedPopup.widget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
655 |
setLayoutDirection_helper(w->layoutDirection()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
656 |
else if (QWidget *w = q->parentWidget()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
657 |
setLayoutDirection_helper(w->layoutDirection()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
658 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
659 |
setLayoutDirection_helper(QApplication::layoutDirection()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
660 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
662 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
663 |
|
0 | 664 |
/*! |
665 |
Returns the action associated with this menu. |
|
666 |
*/ |
|
667 |
QAction *QMenu::menuAction() const |
|
668 |
{ |
|
669 |
return d_func()->menuAction; |
|
670 |
} |
|
671 |
||
672 |
/*! |
|
673 |
\property QMenu::title |
|
674 |
\brief The title of the menu |
|
675 |
||
676 |
This is equivalent to the QAction::text property of the menuAction(). |
|
677 |
||
678 |
By default, this property contains an empty string. |
|
679 |
*/ |
|
680 |
QString QMenu::title() const |
|
681 |
{ |
|
682 |
return d_func()->menuAction->text(); |
|
683 |
} |
|
684 |
||
685 |
void QMenu::setTitle(const QString &text) |
|
686 |
{ |
|
687 |
d_func()->menuAction->setText(text); |
|
688 |
} |
|
689 |
||
690 |
/*! |
|
691 |
\property QMenu::icon |
|
692 |
||
693 |
\brief The icon of the menu |
|
694 |
||
695 |
This is equivalent to the QAction::icon property of the menuAction(). |
|
696 |
||
697 |
By default, if no icon is explicitly set, this property contains a null icon. |
|
698 |
*/ |
|
699 |
QIcon QMenu::icon() const |
|
700 |
{ |
|
701 |
return d_func()->menuAction->icon(); |
|
702 |
} |
|
703 |
||
704 |
void QMenu::setIcon(const QIcon &icon) |
|
705 |
{ |
|
706 |
d_func()->menuAction->setIcon(icon); |
|
707 |
} |
|
708 |
||
709 |
||
710 |
//actually performs the scrolling |
|
711 |
void QMenuPrivate::scrollMenu(QAction *action, QMenuScroller::ScrollLocation location, bool active) |
|
712 |
{ |
|
713 |
Q_Q(QMenu); |
|
714 |
if (!scroll || !scroll->scrollFlags) |
|
715 |
return; |
|
716 |
updateActionRects(); |
|
717 |
int newOffset = 0; |
|
718 |
const int topScroll = (scroll->scrollFlags & QMenuScroller::ScrollUp) ? scrollerHeight() : 0; |
|
719 |
const int botScroll = (scroll->scrollFlags & QMenuScroller::ScrollDown) ? scrollerHeight() : 0; |
|
720 |
const int vmargin = q->style()->pixelMetric(QStyle::PM_MenuVMargin, 0, q); |
|
721 |
const int fw = q->style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q); |
|
722 |
||
723 |
if (location == QMenuScroller::ScrollTop) { |
|
724 |
for(int i = 0, saccum = 0; i < actions.count(); i++) { |
|
725 |
if (actions.at(i) == action) { |
|
726 |
newOffset = topScroll - saccum; |
|
727 |
break; |
|
728 |
} |
|
729 |
saccum += actionRects.at(i).height(); |
|
730 |
} |
|
731 |
} else { |
|
732 |
for(int i = 0, saccum = 0; i < actions.count(); i++) { |
|
733 |
saccum += actionRects.at(i).height(); |
|
734 |
if (actions.at(i) == action) { |
|
735 |
if (location == QMenuScroller::ScrollCenter) |
|
736 |
newOffset = ((q->height() / 2) - botScroll) - (saccum - topScroll); |
|
737 |
else |
|
738 |
newOffset = (q->height() - botScroll) - saccum; |
|
739 |
break; |
|
740 |
} |
|
741 |
} |
|
742 |
if(newOffset) |
|
743 |
newOffset -= fw * 2; |
|
744 |
} |
|
745 |
||
746 |
//figure out which scroll flags |
|
747 |
uint newScrollFlags = QMenuScroller::ScrollNone; |
|
748 |
if (newOffset < 0) //easy and cheap one |
|
749 |
newScrollFlags |= QMenuScroller::ScrollUp; |
|
750 |
int saccum = newOffset; |
|
751 |
for(int i = 0; i < actionRects.count(); i++) { |
|
752 |
saccum += actionRects.at(i).height(); |
|
753 |
if (saccum > q->height()) { |
|
754 |
newScrollFlags |= QMenuScroller::ScrollDown; |
|
755 |
break; |
|
756 |
} |
|
757 |
} |
|
758 |
||
759 |
if (!(newScrollFlags & QMenuScroller::ScrollDown) && (scroll->scrollFlags & QMenuScroller::ScrollDown)) { |
|
760 |
newOffset = q->height() - (saccum - newOffset) - fw*2 - vmargin; //last item at bottom |
|
761 |
} |
|
762 |
||
763 |
if (!(newScrollFlags & QMenuScroller::ScrollUp) && (scroll->scrollFlags & QMenuScroller::ScrollUp)) { |
|
764 |
newOffset = 0; //first item at top |
|
765 |
} |
|
766 |
||
767 |
if (newScrollFlags & QMenuScroller::ScrollUp) |
|
768 |
newOffset -= vmargin; |
|
769 |
||
770 |
QRect screen = popupGeometry(q); |
|
771 |
const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q); |
|
772 |
if (q->height() < screen.height()-(desktopFrame*2)-1) { |
|
773 |
QRect geom = q->geometry(); |
|
774 |
if (newOffset > scroll->scrollOffset && (scroll->scrollFlags & newScrollFlags & QMenuScroller::ScrollUp)) { //scroll up |
|
775 |
const int newHeight = geom.height()-(newOffset-scroll->scrollOffset); |
|
776 |
if(newHeight > geom.height()) |
|
777 |
geom.setHeight(newHeight); |
|
778 |
} else if(scroll->scrollFlags & newScrollFlags & QMenuScroller::ScrollDown) { |
|
779 |
int newTop = geom.top() + (newOffset-scroll->scrollOffset); |
|
780 |
if (newTop < desktopFrame+screen.top()) |
|
781 |
newTop = desktopFrame+screen.top(); |
|
782 |
if (newTop < geom.top()) { |
|
783 |
geom.setTop(newTop); |
|
784 |
newOffset = 0; |
|
785 |
newScrollFlags &= ~QMenuScroller::ScrollUp; |
|
786 |
} |
|
787 |
} |
|
788 |
if (geom.bottom() > screen.bottom() - desktopFrame) |
|
789 |
geom.setBottom(screen.bottom() - desktopFrame); |
|
790 |
if (geom.top() < desktopFrame+screen.top()) |
|
791 |
geom.setTop(desktopFrame+screen.top()); |
|
792 |
if (geom != q->geometry()) { |
|
793 |
#if 0 |
|
794 |
if (newScrollFlags & QMenuScroller::ScrollDown && |
|
795 |
q->geometry().top() - geom.top() >= -newOffset) |
|
796 |
newScrollFlags &= ~QMenuScroller::ScrollDown; |
|
797 |
#endif |
|
798 |
q->setGeometry(geom); |
|
799 |
} |
|
800 |
} |
|
801 |
||
802 |
//actually update flags |
|
803 |
const int delta = qMin(0, newOffset) - scroll->scrollOffset; //make sure the new offset is always negative |
|
804 |
if (!itemsDirty && delta) { |
|
805 |
//we've scrolled so we need to update the action rects |
|
806 |
for (int i = 0; i < actionRects.count(); ++i) { |
|
807 |
QRect ¤t = actionRects[i]; |
|
808 |
current.moveTop(current.top() + delta); |
|
809 |
||
810 |
//we need to update the widgets geometry |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
811 |
if (QWidget *w = widgetItems.value(actions.at(i))) |
0 | 812 |
w->setGeometry(current); |
813 |
} |
|
814 |
} |
|
815 |
scroll->scrollOffset += delta; |
|
816 |
scroll->scrollFlags = newScrollFlags; |
|
817 |
if (active) |
|
818 |
setCurrentAction(action); |
|
819 |
||
820 |
q->update(); //issue an update so we see all the new state.. |
|
821 |
} |
|
822 |
||
823 |
void QMenuPrivate::scrollMenu(QMenuScroller::ScrollLocation location, bool active) |
|
824 |
{ |
|
825 |
Q_Q(QMenu); |
|
826 |
updateActionRects(); |
|
827 |
if(location == QMenuScroller::ScrollBottom) { |
|
828 |
for(int i = actions.size()-1; i >= 0; --i) { |
|
829 |
QAction *act = actions.at(i); |
|
830 |
if (actionRects.at(i).isNull()) |
|
831 |
continue; |
|
832 |
if (!act->isSeparator() && |
|
833 |
(q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q) |
|
834 |
|| act->isEnabled())) { |
|
835 |
if(scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown) |
|
836 |
scrollMenu(act, QMenuPrivate::QMenuScroller::ScrollBottom, active); |
|
837 |
else if(active) |
|
838 |
setCurrentAction(act, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); |
|
839 |
break; |
|
840 |
} |
|
841 |
} |
|
842 |
} else if(location == QMenuScroller::ScrollTop) { |
|
843 |
for(int i = 0; i < actions.size(); ++i) { |
|
844 |
QAction *act = actions.at(i); |
|
845 |
if (actionRects.at(i).isNull()) |
|
846 |
continue; |
|
847 |
if (!act->isSeparator() && |
|
848 |
(q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q) |
|
849 |
|| act->isEnabled())) { |
|
850 |
if(scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) |
|
851 |
scrollMenu(act, QMenuPrivate::QMenuScroller::ScrollTop, active); |
|
852 |
else if(active) |
|
853 |
setCurrentAction(act, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); |
|
854 |
break; |
|
855 |
} |
|
856 |
} |
|
857 |
} |
|
858 |
} |
|
859 |
||
860 |
//only directional |
|
861 |
void QMenuPrivate::scrollMenu(QMenuScroller::ScrollDirection direction, bool page, bool active) |
|
862 |
{ |
|
863 |
Q_Q(QMenu); |
|
864 |
if (!scroll || !(scroll->scrollFlags & direction)) //not really possible... |
|
865 |
return; |
|
866 |
updateActionRects(); |
|
867 |
const int topScroll = (scroll->scrollFlags & QMenuScroller::ScrollUp) ? scrollerHeight() : 0; |
|
868 |
const int botScroll = (scroll->scrollFlags & QMenuScroller::ScrollDown) ? scrollerHeight() : 0; |
|
869 |
const int vmargin = q->style()->pixelMetric(QStyle::PM_MenuVMargin, 0, q); |
|
870 |
const int fw = q->style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q); |
|
871 |
const int offset = topScroll ? topScroll-vmargin : 0; |
|
872 |
if (direction == QMenuScroller::ScrollUp) { |
|
873 |
for(int i = 0, saccum = 0; i < actions.count(); i++) { |
|
874 |
saccum -= actionRects.at(i).height(); |
|
875 |
if (saccum <= scroll->scrollOffset-offset) { |
|
876 |
scrollMenu(actions.at(i), page ? QMenuScroller::ScrollBottom : QMenuScroller::ScrollTop, active); |
|
877 |
break; |
|
878 |
} |
|
879 |
} |
|
880 |
} else if (direction == QMenuScroller::ScrollDown) { |
|
881 |
bool scrolled = false; |
|
882 |
for(int i = 0, saccum = 0; i < actions.count(); i++) { |
|
883 |
const int iHeight = actionRects.at(i).height(); |
|
884 |
saccum -= iHeight; |
|
885 |
if (saccum <= scroll->scrollOffset-offset) { |
|
886 |
const int scrollerArea = q->height() - botScroll - fw*2; |
|
887 |
int visible = (scroll->scrollOffset-offset) - saccum; |
|
888 |
for(i++ ; i < actions.count(); i++) { |
|
889 |
visible += actionRects.at(i).height(); |
|
890 |
if (visible > scrollerArea - topScroll) { |
|
891 |
scrolled = true; |
|
892 |
scrollMenu(actions.at(i), page ? QMenuScroller::ScrollTop : QMenuScroller::ScrollBottom, active); |
|
893 |
break; |
|
894 |
} |
|
895 |
} |
|
896 |
break; |
|
897 |
} |
|
898 |
} |
|
899 |
if(!scrolled) { |
|
900 |
scroll->scrollFlags &= ~QMenuScroller::ScrollDown; |
|
901 |
q->update(); |
|
902 |
} |
|
903 |
} |
|
904 |
} |
|
905 |
||
906 |
/* This is poor-mans eventfilters. This avoids the use of |
|
907 |
eventFilter (which can be nasty for users of QMenuBar's). */ |
|
908 |
bool QMenuPrivate::mouseEventTaken(QMouseEvent *e) |
|
909 |
{ |
|
910 |
Q_Q(QMenu); |
|
911 |
QPoint pos = q->mapFromGlobal(e->globalPos()); |
|
912 |
if (scroll && !activeMenu) { //let the scroller "steal" the event |
|
913 |
bool isScroll = false; |
|
914 |
if (pos.x() >= 0 && pos.x() < q->width()) { |
|
915 |
for(int dir = QMenuScroller::ScrollUp; dir <= QMenuScroller::ScrollDown; dir = dir << 1) { |
|
916 |
if (scroll->scrollFlags & dir) { |
|
917 |
if (dir == QMenuScroller::ScrollUp) |
|
918 |
isScroll = (pos.y() <= scrollerHeight()); |
|
919 |
else if (dir == QMenuScroller::ScrollDown) |
|
920 |
isScroll = (pos.y() >= q->height() - scrollerHeight()); |
|
921 |
if (isScroll) { |
|
922 |
scroll->scrollDirection = dir; |
|
923 |
break; |
|
924 |
} |
|
925 |
} |
|
926 |
} |
|
927 |
} |
|
928 |
if (isScroll) { |
|
929 |
scroll->scrollTimer.start(50, q); |
|
930 |
return true; |
|
931 |
} else { |
|
932 |
scroll->scrollTimer.stop(); |
|
933 |
} |
|
934 |
} |
|
935 |
||
936 |
if (tearoff) { //let the tear off thingie "steal" the event.. |
|
937 |
QRect tearRect(0, 0, q->width(), q->style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, q)); |
|
938 |
if (scroll && scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) |
|
939 |
tearRect.translate(0, scrollerHeight()); |
|
940 |
q->update(tearRect); |
|
941 |
if (tearRect.contains(pos) && hasMouseMoved(e->globalPos())) { |
|
942 |
setCurrentAction(0); |
|
943 |
tearoffHighlighted = 1; |
|
944 |
if (e->type() == QEvent::MouseButtonRelease) { |
|
945 |
if (!tornPopup) |
|
946 |
tornPopup = new QTornOffMenu(q); |
|
947 |
tornPopup->setGeometry(q->geometry()); |
|
948 |
tornPopup->show(); |
|
949 |
hideUpToMenuBar(); |
|
950 |
} |
|
951 |
return true; |
|
952 |
} |
|
953 |
tearoffHighlighted = 0; |
|
954 |
} |
|
955 |
||
956 |
if (q->frameGeometry().contains(e->globalPos())) //otherwise if the event is in our rect we want it.. |
|
957 |
return false; |
|
958 |
||
959 |
for(QWidget *caused = causedPopup.widget; caused;) { |
|
960 |
bool passOnEvent = false; |
|
961 |
QWidget *next_widget = 0; |
|
962 |
QPoint cpos = caused->mapFromGlobal(e->globalPos()); |
|
963 |
#ifndef QT_NO_MENUBAR |
|
964 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) { |
|
965 |
passOnEvent = mb->rect().contains(cpos); |
|
966 |
} else |
|
967 |
#endif |
|
968 |
if (QMenu *m = qobject_cast<QMenu*>(caused)) { |
|
969 |
passOnEvent = m->rect().contains(cpos); |
|
970 |
next_widget = m->d_func()->causedPopup.widget; |
|
971 |
} |
|
972 |
if (passOnEvent) { |
|
973 |
if(e->type() != QEvent::MouseButtonRelease || mouseDown == caused) { |
|
974 |
QMouseEvent new_e(e->type(), cpos, e->button(), e->buttons(), e->modifiers()); |
|
975 |
QApplication::sendEvent(caused, &new_e); |
|
976 |
return true; |
|
977 |
} |
|
978 |
} |
|
979 |
if (!next_widget) |
|
980 |
break; |
|
981 |
caused = next_widget; |
|
982 |
} |
|
983 |
return false; |
|
984 |
} |
|
985 |
||
986 |
void QMenuPrivate::activateCausedStack(const QList<QPointer<QWidget> > &causedStack, QAction *action, QAction::ActionEvent action_e, bool self) |
|
987 |
{ |
|
29
b72c6db6890b
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
988 |
QBoolBlocker guard(activationRecursionGuard); |
0 | 989 |
#ifdef QT3_SUPPORT |
990 |
const int actionId = q_func()->findIdForAction(action); |
|
991 |
#endif |
|
992 |
if(self) |
|
993 |
action->activate(action_e); |
|
994 |
||
995 |
for(int i = 0; i < causedStack.size(); ++i) { |
|
996 |
QPointer<QWidget> widget = causedStack.at(i); |
|
997 |
if (!widget) |
|
998 |
continue; |
|
999 |
//fire |
|
1000 |
if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { |
|
1001 |
widget = qmenu->d_func()->causedPopup.widget; |
|
1002 |
if (action_e == QAction::Trigger) { |
|
1003 |
emit qmenu->triggered(action); |
|
1004 |
} else if (action_e == QAction::Hover) { |
|
1005 |
emit qmenu->hovered(action); |
|
1006 |
#ifdef QT3_SUPPORT |
|
1007 |
if (emitHighlighted) { |
|
1008 |
emit qmenu->highlighted(actionId); |
|
1009 |
emitHighlighted = false; |
|
1010 |
} |
|
1011 |
#endif |
|
1012 |
} |
|
1013 |
#ifndef QT_NO_MENUBAR |
|
1014 |
} else if (QMenuBar *qmenubar = qobject_cast<QMenuBar*>(widget)) { |
|
1015 |
if (action_e == QAction::Trigger) { |
|
1016 |
emit qmenubar->triggered(action); |
|
1017 |
#ifdef QT3_SUPPORT |
|
1018 |
emit qmenubar->activated(actionId); |
|
1019 |
#endif |
|
1020 |
} else if (action_e == QAction::Hover) { |
|
1021 |
emit qmenubar->hovered(action); |
|
1022 |
#ifdef QT3_SUPPORT |
|
1023 |
if (emitHighlighted) { |
|
1024 |
emit qmenubar->highlighted(actionId); |
|
1025 |
emitHighlighted = false; |
|
1026 |
} |
|
1027 |
#endif |
|
1028 |
} |
|
1029 |
break; //nothing more.. |
|
1030 |
#endif |
|
1031 |
} |
|
1032 |
} |
|
1033 |
} |
|
1034 |
||
1035 |
void QMenuPrivate::activateAction(QAction *action, QAction::ActionEvent action_e, bool self) |
|
1036 |
{ |
|
1037 |
Q_Q(QMenu); |
|
1038 |
#ifndef QT_NO_WHATSTHIS |
|
1039 |
bool inWhatsThisMode = QWhatsThis::inWhatsThisMode(); |
|
1040 |
#endif |
|
1041 |
if (!action || !q->isEnabled() |
|
1042 |
|| (action_e == QAction::Trigger |
|
1043 |
#ifndef QT_NO_WHATSTHIS |
|
1044 |
&& !inWhatsThisMode |
|
1045 |
#endif |
|
1046 |
&& (action->isSeparator() ||!action->isEnabled()))) |
|
1047 |
return; |
|
1048 |
||
1049 |
/* I have to save the caused stack here because it will be undone after popup execution (ie in the hide). |
|
1050 |
Then I iterate over the list to actually send the events. --Sam |
|
1051 |
*/ |
|
1052 |
const QList<QPointer<QWidget> > causedStack = calcCausedStack(); |
|
1053 |
if (action_e == QAction::Trigger) { |
|
1054 |
#ifndef QT_NO_WHATSTHIS |
|
1055 |
if (!inWhatsThisMode) |
|
1056 |
actionAboutToTrigger = action; |
|
1057 |
#endif |
|
1058 |
||
1059 |
if (q->testAttribute(Qt::WA_DontShowOnScreen)) { |
|
1060 |
hideUpToMenuBar(); |
|
1061 |
} else { |
|
1062 |
for(QWidget *widget = QApplication::activePopupWidget(); widget; ) { |
|
1063 |
if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { |
|
1064 |
if(qmenu == q) |
|
1065 |
hideUpToMenuBar(); |
|
1066 |
widget = qmenu->d_func()->causedPopup.widget; |
|
1067 |
} else { |
|
1068 |
break; |
|
1069 |
} |
|
1070 |
} |
|
1071 |
} |
|
1072 |
||
1073 |
#ifndef QT_NO_WHATSTHIS |
|
1074 |
if (inWhatsThisMode) { |
|
1075 |
QString s = action->whatsThis(); |
|
1076 |
if (s.isEmpty()) |
|
1077 |
s = whatsThis; |
|
1078 |
QWhatsThis::showText(q->mapToGlobal(actionRect(action).center()), s, q); |
|
1079 |
return; |
|
1080 |
} |
|
1081 |
#endif |
|
1082 |
} |
|
1083 |
||
1084 |
||
1085 |
activateCausedStack(causedStack, action, action_e, self); |
|
1086 |
||
1087 |
||
1088 |
if (action_e == QAction::Hover) { |
|
1089 |
#ifndef QT_NO_ACCESSIBILITY |
|
1090 |
if (QAccessible::isActive()) { |
|
1091 |
int actionIndex = indexOf(action) + 1; |
|
1092 |
QAccessible::updateAccessibility(q, actionIndex, QAccessible::Focus); |
|
1093 |
QAccessible::updateAccessibility(q, actionIndex, QAccessible::Selection); |
|
1094 |
} |
|
1095 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1096 |
action->showStatusText(topCausedWidget()); |
0 | 1097 |
} else { |
1098 |
actionAboutToTrigger = 0; |
|
1099 |
} |
|
1100 |
} |
|
1101 |
||
1102 |
void QMenuPrivate::_q_actionTriggered() |
|
1103 |
{ |
|
1104 |
Q_Q(QMenu); |
|
1105 |
if (QAction *action = qobject_cast<QAction *>(q->sender())) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1106 |
QWeakPointer<QAction> actionGuard = action; |
0 | 1107 |
#ifdef QT3_SUPPORT |
1108 |
//we store it here because the action might be deleted/changed by connected slots |
|
1109 |
const int id = q->findIdForAction(action); |
|
1110 |
#endif |
|
1111 |
emit q->triggered(action); |
|
1112 |
#ifdef QT3_SUPPORT |
|
1113 |
emit q->activated(id); |
|
1114 |
#endif |
|
1115 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1116 |
if (!activationRecursionGuard && actionGuard) { |
0 | 1117 |
//in case the action has not been activated by the mouse |
1118 |
//we check the parent hierarchy |
|
1119 |
QList< QPointer<QWidget> > list; |
|
1120 |
for(QWidget *widget = q->parentWidget(); widget; ) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1121 |
if (qobject_cast<QMenu*>(widget) |
0 | 1122 |
#ifndef QT_NO_MENUBAR |
1123 |
|| qobject_cast<QMenuBar*>(widget) |
|
1124 |
#endif |
|
1125 |
) { |
|
1126 |
list.append(widget); |
|
1127 |
widget = widget->parentWidget(); |
|
1128 |
} else { |
|
1129 |
break; |
|
1130 |
} |
|
1131 |
} |
|
1132 |
activateCausedStack(list, action, QAction::Trigger, false); |
|
1133 |
} |
|
1134 |
} |
|
1135 |
} |
|
1136 |
||
1137 |
void QMenuPrivate::_q_actionHovered() |
|
1138 |
{ |
|
1139 |
Q_Q(QMenu); |
|
1140 |
if (QAction * action = qobject_cast<QAction *>(q->sender())) { |
|
1141 |
#ifdef QT3_SUPPORT |
|
1142 |
//we store it here because the action might be deleted/changed by connected slots |
|
1143 |
const int id = q->findIdForAction(action); |
|
1144 |
#endif |
|
1145 |
emit q->hovered(action); |
|
1146 |
#ifdef QT3_SUPPORT |
|
1147 |
if (emitHighlighted) { |
|
1148 |
emit q->highlighted(id); |
|
1149 |
emitHighlighted = false; |
|
1150 |
} |
|
1151 |
#endif |
|
1152 |
} |
|
1153 |
} |
|
1154 |
||
1155 |
bool QMenuPrivate::hasMouseMoved(const QPoint &globalPos) |
|
1156 |
{ |
|
1157 |
//determines if the mouse has moved (ie its intial position has |
|
1158 |
//changed by more than QApplication::startDragDistance() |
|
1159 |
//or if there were at least 6 mouse motions) |
|
1160 |
return motions > 6 || |
|
1161 |
QApplication::startDragDistance() < (mousePopupPos - globalPos).manhattanLength(); |
|
1162 |
} |
|
1163 |
||
1164 |
||
1165 |
/*! |
|
1166 |
Initialize \a option with the values from this menu and information from \a action. This method |
|
1167 |
is useful for subclasses when they need a QStyleOptionMenuItem, but don't want |
|
1168 |
to fill in all the information themselves. |
|
1169 |
||
1170 |
\sa QStyleOption::initFrom() QMenuBar::initStyleOption() |
|
1171 |
*/ |
|
1172 |
void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const |
|
1173 |
{ |
|
1174 |
if (!option || !action) |
|
1175 |
return; |
|
1176 |
||
1177 |
Q_D(const QMenu); |
|
1178 |
option->initFrom(this); |
|
1179 |
option->palette = palette(); |
|
1180 |
option->state = QStyle::State_None; |
|
1181 |
||
1182 |
if (window()->isActiveWindow()) |
|
1183 |
option->state |= QStyle::State_Active; |
|
1184 |
if (isEnabled() && action->isEnabled() |
|
1185 |
&& (!action->menu() || action->menu()->isEnabled())) |
|
1186 |
option->state |= QStyle::State_Enabled; |
|
1187 |
else |
|
1188 |
option->palette.setCurrentColorGroup(QPalette::Disabled); |
|
1189 |
||
1190 |
option->font = action->font().resolve(font()); |
|
1191 |
option->fontMetrics = QFontMetrics(option->font); |
|
1192 |
||
1193 |
if (d->currentAction && d->currentAction == action && !d->currentAction->isSeparator()) { |
|
1194 |
option->state |= QStyle::State_Selected |
|
1195 |
| (d->mouseDown ? QStyle::State_Sunken : QStyle::State_None); |
|
1196 |
} |
|
1197 |
||
1198 |
option->menuHasCheckableItems = d->hasCheckableItems; |
|
1199 |
if (!action->isCheckable()) { |
|
1200 |
option->checkType = QStyleOptionMenuItem::NotCheckable; |
|
1201 |
} else { |
|
1202 |
option->checkType = (action->actionGroup() && action->actionGroup()->isExclusive()) |
|
1203 |
? QStyleOptionMenuItem::Exclusive : QStyleOptionMenuItem::NonExclusive; |
|
1204 |
option->checked = action->isChecked(); |
|
1205 |
} |
|
1206 |
if (action->menu()) |
|
1207 |
option->menuItemType = QStyleOptionMenuItem::SubMenu; |
|
1208 |
else if (action->isSeparator()) |
|
1209 |
option->menuItemType = QStyleOptionMenuItem::Separator; |
|
1210 |
else if (d->defaultAction == action) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1211 |
option->menuItemType = QStyleOptionMenuItem::DefaultItem; |
0 | 1212 |
else |
1213 |
option->menuItemType = QStyleOptionMenuItem::Normal; |
|
1214 |
if (action->isIconVisibleInMenu()) |
|
1215 |
option->icon = action->icon(); |
|
1216 |
QString textAndAccel = action->text(); |
|
1217 |
#ifndef QT_NO_SHORTCUT |
|
1218 |
if (textAndAccel.indexOf(QLatin1Char('\t')) == -1) { |
|
1219 |
QKeySequence seq = action->shortcut(); |
|
1220 |
if (!seq.isEmpty()) |
|
1221 |
textAndAccel += QLatin1Char('\t') + QString(seq); |
|
1222 |
} |
|
1223 |
#endif |
|
1224 |
option->text = textAndAccel; |
|
1225 |
option->tabWidth = d->tabWidth; |
|
1226 |
option->maxIconWidth = d->maxIconWidth; |
|
1227 |
option->menuRect = rect(); |
|
1228 |
} |
|
1229 |
||
1230 |
/*! |
|
1231 |
\class QMenu |
|
1232 |
\brief The QMenu class provides a menu widget for use in menu |
|
1233 |
bars, context menus, and other popup menus. |
|
1234 |
||
1235 |
\ingroup mainwindow-classes |
|
1236 |
\ingroup basicwidgets |
|
1237 |
||
1238 |
||
1239 |
A menu widget is a selection menu. It can be either a pull-down |
|
1240 |
menu in a menu bar or a standalone context menu. Pull-down menus |
|
1241 |
are shown by the menu bar when the user clicks on the respective |
|
1242 |
item or presses the specified shortcut key. Use |
|
1243 |
QMenuBar::addMenu() to insert a menu into a menu bar. Context |
|
1244 |
menus are usually invoked by some special keyboard key or by |
|
1245 |
right-clicking. They can be executed either asynchronously with |
|
1246 |
popup() or synchronously with exec(). Menus can also be invoked in |
|
1247 |
response to button presses; these are just like context menus |
|
1248 |
except for how they are invoked. |
|
1249 |
||
1250 |
\raw HTML |
|
1251 |
<table align="center" cellpadding="0"> |
|
1252 |
<tr> |
|
1253 |
<td> |
|
1254 |
\endraw |
|
1255 |
\inlineimage plastique-menu.png |
|
1256 |
\raw HTML |
|
1257 |
</td> |
|
1258 |
<td> |
|
1259 |
\endraw |
|
1260 |
\inlineimage windowsxp-menu.png |
|
1261 |
\raw HTML |
|
1262 |
</td> |
|
1263 |
<td> |
|
1264 |
\endraw |
|
1265 |
\inlineimage macintosh-menu.png |
|
1266 |
\raw HTML |
|
1267 |
</td> |
|
1268 |
||
1269 |
</tr> |
|
1270 |
<tr> |
|
1271 |
<td colspan="3"> |
|
1272 |
\endraw |
|
1273 |
A menu shown in \l{Plastique Style Widget Gallery}{Plastique widget style}, |
|
1274 |
\l{Windows XP Style Widget Gallery}{Windows XP widget style}, |
|
1275 |
and \l{Macintosh Style Widget Gallery}{Macintosh widget style}. |
|
1276 |
\raw HTML |
|
1277 |
</td> |
|
1278 |
</tr> |
|
1279 |
</table> |
|
1280 |
\endraw |
|
1281 |
||
1282 |
\section1 Actions |
|
1283 |
||
1284 |
A menu consists of a list of action items. Actions are added with |
|
1285 |
the addAction(), addActions() and insertAction() functions. An action |
|
1286 |
is represented vertically and rendered by QStyle. In addition, actions |
|
1287 |
can have a text label, an optional icon drawn on the very left side, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1288 |
and shortcut key sequence such as "Ctrl+X". |
0 | 1289 |
|
1290 |
The existing actions held by a menu can be found with actions(). |
|
1291 |
||
1292 |
There are four kinds of action items: separators, actions that |
|
1293 |
show a submenu, widgets, and actions that perform an action. |
|
1294 |
Separators are inserted with addSeparator(), submenus with addMenu(), |
|
1295 |
and all other items are considered action items. |
|
1296 |
||
1297 |
When inserting action items you usually specify a receiver and a |
|
1298 |
slot. The receiver will be notifed whenever the item is |
|
1299 |
\l{QAction::triggered()}{triggered()}. In addition, QMenu provides |
|
1300 |
two signals, activated() and highlighted(), which signal the |
|
1301 |
QAction that was triggered from the menu. |
|
1302 |
||
1303 |
You clear a menu with clear() and remove individual action items |
|
1304 |
with removeAction(). |
|
1305 |
||
1306 |
A QMenu can also provide a tear-off menu. A tear-off menu is a |
|
1307 |
top-level window that contains a copy of the menu. This makes it |
|
1308 |
possible for the user to "tear off" frequently used menus and |
|
1309 |
position them in a convenient place on the screen. If you want |
|
1310 |
this functionality for a particular menu, insert a tear-off handle |
|
1311 |
with setTearOffEnabled(). When using tear-off menus, bear in mind |
|
1312 |
that the concept isn't typically used on Microsoft Windows so |
|
1313 |
some users may not be familiar with it. Consider using a QToolBar |
|
1314 |
instead. |
|
1315 |
||
1316 |
Widgets can be inserted into menus with the QWidgetAction class. |
|
1317 |
Instances of this class are used to hold widgets, and are inserted |
|
1318 |
into menus with the addAction() overload that takes a QAction. |
|
1319 |
||
1320 |
Conversely, actions can be added to widgets with the addAction(), |
|
1321 |
addActions() and insertAction() functions. |
|
1322 |
||
1323 |
\section1 QMenu on Qt for Windows CE |
|
1324 |
||
1325 |
If a menu is integrated into the native menubar on Windows Mobile we |
|
1326 |
do not support the signals: aboutToHide (), aboutToShow () and hovered (). |
|
1327 |
It is not possible to display an icon in a native menu on Windows Mobile. |
|
1328 |
||
1329 |
\section1 QMenu on Mac OS X with Qt build against Cocoa |
|
1330 |
||
1331 |
QMenu can be inserted only once in a menu/menubar. Subsequent insertions will |
|
1332 |
have no effect or will result in a disabled menu item. |
|
1333 |
||
1334 |
See the \l{mainwindows/menus}{Menus} example for an example of how |
|
1335 |
to use QMenuBar and QMenu in your application. |
|
1336 |
||
1337 |
\bold{Important inherited functions:} addAction(), removeAction(), clear(), |
|
1338 |
addSeparator(), and addMenu(). |
|
1339 |
||
1340 |
\sa QMenuBar, {fowler}{GUI Design Handbook: Menu, Drop-Down and Pop-Up}, |
|
1341 |
{Application Example}, {Menus Example}, {Recent Files Example} |
|
1342 |
*/ |
|
1343 |
||
1344 |
||
1345 |
/*! |
|
1346 |
Constructs a menu with parent \a parent. |
|
1347 |
||
1348 |
Although a popup menu is always a top-level widget, if a parent is |
|
1349 |
passed the popup menu will be deleted when that parent is |
|
1350 |
destroyed (as with any other QObject). |
|
1351 |
*/ |
|
1352 |
QMenu::QMenu(QWidget *parent) |
|
1353 |
: QWidget(*new QMenuPrivate, parent, Qt::Popup) |
|
1354 |
{ |
|
1355 |
Q_D(QMenu); |
|
1356 |
d->init(); |
|
1357 |
} |
|
1358 |
||
1359 |
/*! |
|
1360 |
Constructs a menu with a \a title and a \a parent. |
|
1361 |
||
1362 |
Although a popup menu is always a top-level widget, if a parent is |
|
1363 |
passed the popup menu will be deleted when that parent is |
|
1364 |
destroyed (as with any other QObject). |
|
1365 |
||
1366 |
\sa title |
|
1367 |
*/ |
|
1368 |
QMenu::QMenu(const QString &title, QWidget *parent) |
|
1369 |
: QWidget(*new QMenuPrivate, parent, Qt::Popup) |
|
1370 |
{ |
|
1371 |
Q_D(QMenu); |
|
1372 |
d->init(); |
|
1373 |
d->menuAction->setText(title); |
|
1374 |
} |
|
1375 |
||
1376 |
/*! \internal |
|
1377 |
*/ |
|
1378 |
QMenu::QMenu(QMenuPrivate &dd, QWidget *parent) |
|
1379 |
: QWidget(dd, parent, Qt::Popup) |
|
1380 |
{ |
|
1381 |
Q_D(QMenu); |
|
1382 |
d->init(); |
|
1383 |
} |
|
1384 |
||
1385 |
/*! |
|
1386 |
Destroys the menu. |
|
1387 |
*/ |
|
1388 |
QMenu::~QMenu() |
|
1389 |
{ |
|
1390 |
Q_D(QMenu); |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1391 |
if (!d->widgetItems.isEmpty()) { // avoid detach on shared null hash |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1392 |
QHash<QAction *, QWidget *>::iterator it = d->widgetItems.begin(); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1393 |
for (; it != d->widgetItems.end(); ++it) { |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1394 |
if (QWidget *widget = it.value()) { |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1395 |
QWidgetAction *action = static_cast<QWidgetAction *>(it.key()); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1396 |
action->releaseWidget(widget); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1397 |
*it = 0; |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1398 |
} |
0 | 1399 |
} |
1400 |
} |
|
1401 |
||
1402 |
if (d->eventLoop) |
|
1403 |
d->eventLoop->exit(); |
|
1404 |
hideTearOffMenu(); |
|
1405 |
} |
|
1406 |
||
1407 |
/*! |
|
1408 |
\overload |
|
1409 |
||
1410 |
This convenience function creates a new action with \a text. |
|
1411 |
The function adds the newly created action to the menu's |
|
1412 |
list of actions, and returns it. |
|
1413 |
||
1414 |
\sa QWidget::addAction() |
|
1415 |
*/ |
|
1416 |
QAction *QMenu::addAction(const QString &text) |
|
1417 |
{ |
|
1418 |
QAction *ret = new QAction(text, this); |
|
1419 |
addAction(ret); |
|
1420 |
return ret; |
|
1421 |
} |
|
1422 |
||
1423 |
/*! |
|
1424 |
\overload |
|
1425 |
||
1426 |
This convenience function creates a new action with an \a icon |
|
1427 |
and some \a text. The function adds the newly created action to |
|
1428 |
the menu's list of actions, and returns it. |
|
1429 |
||
1430 |
\sa QWidget::addAction() |
|
1431 |
*/ |
|
1432 |
QAction *QMenu::addAction(const QIcon &icon, const QString &text) |
|
1433 |
{ |
|
1434 |
QAction *ret = new QAction(icon, text, this); |
|
1435 |
addAction(ret); |
|
1436 |
return ret; |
|
1437 |
} |
|
1438 |
||
1439 |
/*! |
|
1440 |
\overload |
|
1441 |
||
1442 |
This convenience function creates a new action with the text \a |
|
1443 |
text and an optional shortcut \a shortcut. The action's |
|
1444 |
\l{QAction::triggered()}{triggered()} signal is connected to the |
|
1445 |
\a receiver's \a member slot. The function adds the newly created |
|
1446 |
action to the menu's list of actions and returns it. |
|
1447 |
||
1448 |
\sa QWidget::addAction() |
|
1449 |
*/ |
|
1450 |
QAction *QMenu::addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut) |
|
1451 |
{ |
|
1452 |
QAction *action = new QAction(text, this); |
|
1453 |
#ifdef QT_NO_SHORTCUT |
|
1454 |
Q_UNUSED(shortcut); |
|
1455 |
#else |
|
1456 |
action->setShortcut(shortcut); |
|
1457 |
#endif |
|
1458 |
QObject::connect(action, SIGNAL(triggered(bool)), receiver, member); |
|
1459 |
addAction(action); |
|
1460 |
return action; |
|
1461 |
} |
|
1462 |
||
1463 |
/*! |
|
1464 |
\overload |
|
1465 |
||
1466 |
This convenience function creates a new action with an \a icon and |
|
1467 |
some \a text and an optional shortcut \a shortcut. The action's |
|
1468 |
\l{QAction::triggered()}{triggered()} signal is connected to the |
|
1469 |
\a member slot of the \a receiver object. The function adds the |
|
1470 |
newly created action to the menu's list of actions, and returns it. |
|
1471 |
||
1472 |
\sa QWidget::addAction() |
|
1473 |
*/ |
|
1474 |
QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, |
|
1475 |
const char* member, const QKeySequence &shortcut) |
|
1476 |
{ |
|
1477 |
QAction *action = new QAction(icon, text, this); |
|
1478 |
#ifdef QT_NO_SHORTCUT |
|
1479 |
Q_UNUSED(shortcut); |
|
1480 |
#else |
|
1481 |
action->setShortcut(shortcut); |
|
1482 |
#endif |
|
1483 |
QObject::connect(action, SIGNAL(triggered(bool)), receiver, member); |
|
1484 |
addAction(action); |
|
1485 |
return action; |
|
1486 |
} |
|
1487 |
||
1488 |
/*! |
|
1489 |
This convenience function adds \a menu as a submenu to this menu. |
|
1490 |
It returns \a menu's menuAction(). This menu does not take |
|
1491 |
ownership of \a menu. |
|
1492 |
||
1493 |
\sa QWidget::addAction() QMenu::menuAction() |
|
1494 |
*/ |
|
1495 |
QAction *QMenu::addMenu(QMenu *menu) |
|
1496 |
{ |
|
1497 |
QAction *action = menu->menuAction(); |
|
1498 |
addAction(action); |
|
1499 |
return action; |
|
1500 |
} |
|
1501 |
||
1502 |
/*! |
|
1503 |
Appends a new QMenu with \a title to the menu. The menu |
|
1504 |
takes ownership of the menu. Returns the new menu. |
|
1505 |
||
1506 |
\sa QWidget::addAction() QMenu::menuAction() |
|
1507 |
*/ |
|
1508 |
QMenu *QMenu::addMenu(const QString &title) |
|
1509 |
{ |
|
1510 |
QMenu *menu = new QMenu(title, this); |
|
1511 |
addAction(menu->menuAction()); |
|
1512 |
return menu; |
|
1513 |
} |
|
1514 |
||
1515 |
/*! |
|
1516 |
Appends a new QMenu with \a icon and \a title to the menu. The menu |
|
1517 |
takes ownership of the menu. Returns the new menu. |
|
1518 |
||
1519 |
\sa QWidget::addAction() QMenu::menuAction() |
|
1520 |
*/ |
|
1521 |
QMenu *QMenu::addMenu(const QIcon &icon, const QString &title) |
|
1522 |
{ |
|
1523 |
QMenu *menu = new QMenu(title, this); |
|
1524 |
menu->setIcon(icon); |
|
1525 |
addAction(menu->menuAction()); |
|
1526 |
return menu; |
|
1527 |
} |
|
1528 |
||
1529 |
/*! |
|
1530 |
This convenience function creates a new separator action, i.e. an |
|
1531 |
action with QAction::isSeparator() returning true, and adds the new |
|
1532 |
action to this menu's list of actions. It returns the newly |
|
1533 |
created action. |
|
1534 |
||
1535 |
\sa QWidget::addAction() |
|
1536 |
*/ |
|
1537 |
QAction *QMenu::addSeparator() |
|
1538 |
{ |
|
1539 |
QAction *action = new QAction(this); |
|
1540 |
action->setSeparator(true); |
|
1541 |
addAction(action); |
|
1542 |
return action; |
|
1543 |
} |
|
1544 |
||
1545 |
/*! |
|
1546 |
This convenience function inserts \a menu before action \a before |
|
1547 |
and returns the menus menuAction(). |
|
1548 |
||
1549 |
\sa QWidget::insertAction(), addMenu() |
|
1550 |
*/ |
|
1551 |
QAction *QMenu::insertMenu(QAction *before, QMenu *menu) |
|
1552 |
{ |
|
1553 |
QAction *action = menu->menuAction(); |
|
1554 |
insertAction(before, action); |
|
1555 |
return action; |
|
1556 |
} |
|
1557 |
||
1558 |
/*! |
|
1559 |
This convenience function creates a new separator action, i.e. an |
|
1560 |
action with QAction::isSeparator() returning true. The function inserts |
|
1561 |
the newly created action into this menu's list of actions before |
|
1562 |
action \a before and returns it. |
|
1563 |
||
1564 |
\sa QWidget::insertAction(), addSeparator() |
|
1565 |
*/ |
|
1566 |
QAction *QMenu::insertSeparator(QAction *before) |
|
1567 |
{ |
|
1568 |
QAction *action = new QAction(this); |
|
1569 |
action->setSeparator(true); |
|
1570 |
insertAction(before, action); |
|
1571 |
return action; |
|
1572 |
} |
|
1573 |
||
1574 |
/*! |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1575 |
This sets the default action to \a act. The default action may have |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1576 |
a visual cue, depending on the current QStyle. A default action |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1577 |
usually indicates what will happen by default when a drop occurs. |
0 | 1578 |
|
1579 |
\sa defaultAction() |
|
1580 |
*/ |
|
1581 |
void QMenu::setDefaultAction(QAction *act) |
|
1582 |
{ |
|
1583 |
d_func()->defaultAction = act; |
|
1584 |
} |
|
1585 |
||
1586 |
/*! |
|
1587 |
Returns the current default action. |
|
1588 |
||
1589 |
\sa setDefaultAction() |
|
1590 |
*/ |
|
1591 |
QAction *QMenu::defaultAction() const |
|
1592 |
{ |
|
1593 |
return d_func()->defaultAction; |
|
1594 |
} |
|
1595 |
||
1596 |
/*! |
|
1597 |
\property QMenu::tearOffEnabled |
|
1598 |
\brief whether the menu supports being torn off |
|
1599 |
||
1600 |
When true, the menu contains a special tear-off item (often shown as a dashed |
|
1601 |
line at the top of the menu) that creates a copy of the menu when it is |
|
1602 |
triggered. |
|
1603 |
||
1604 |
This "torn-off" copy lives in a separate window. It contains the same menu |
|
1605 |
items as the original menu, with the exception of the tear-off handle. |
|
1606 |
||
1607 |
By default, this property is false. |
|
1608 |
*/ |
|
1609 |
void QMenu::setTearOffEnabled(bool b) |
|
1610 |
{ |
|
1611 |
Q_D(QMenu); |
|
1612 |
if (d->tearoff == b) |
|
1613 |
return; |
|
1614 |
if (!b) |
|
1615 |
hideTearOffMenu(); |
|
1616 |
d->tearoff = b; |
|
1617 |
||
1618 |
d->itemsDirty = true; |
|
1619 |
if (isVisible()) |
|
1620 |
resize(sizeHint()); |
|
1621 |
} |
|
1622 |
||
1623 |
bool QMenu::isTearOffEnabled() const |
|
1624 |
{ |
|
1625 |
return d_func()->tearoff; |
|
1626 |
} |
|
1627 |
||
1628 |
/*! |
|
1629 |
When a menu is torn off a second menu is shown to display the menu |
|
1630 |
contents in a new window. When the menu is in this mode and the menu |
|
1631 |
is visible returns true; otherwise false. |
|
1632 |
||
1633 |
\sa hideTearOffMenu() isTearOffEnabled() |
|
1634 |
*/ |
|
1635 |
bool QMenu::isTearOffMenuVisible() const |
|
1636 |
{ |
|
1637 |
if (d_func()->tornPopup) |
|
1638 |
return d_func()->tornPopup->isVisible(); |
|
1639 |
return false; |
|
1640 |
} |
|
1641 |
||
1642 |
/*! |
|
1643 |
This function will forcibly hide the torn off menu making it |
|
1644 |
disappear from the users desktop. |
|
1645 |
||
1646 |
\sa isTearOffMenuVisible() isTearOffEnabled() |
|
1647 |
*/ |
|
1648 |
void QMenu::hideTearOffMenu() |
|
1649 |
{ |
|
1650 |
if (QWidget *w = d_func()->tornPopup) |
|
1651 |
w->close(); |
|
1652 |
} |
|
1653 |
||
1654 |
||
1655 |
/*! |
|
1656 |
Sets the currently highlighted action to \a act. |
|
1657 |
*/ |
|
1658 |
void QMenu::setActiveAction(QAction *act) |
|
1659 |
{ |
|
1660 |
Q_D(QMenu); |
|
1661 |
d->setCurrentAction(act, 0); |
|
1662 |
if (d->scroll) |
|
1663 |
d->scrollMenu(act, QMenuPrivate::QMenuScroller::ScrollCenter); |
|
1664 |
} |
|
1665 |
||
1666 |
||
1667 |
/*! |
|
1668 |
Returns the currently highlighted action, or 0 if no |
|
1669 |
action is currently highlighted. |
|
1670 |
*/ |
|
1671 |
QAction *QMenu::activeAction() const |
|
1672 |
{ |
|
1673 |
return d_func()->currentAction; |
|
1674 |
} |
|
1675 |
||
1676 |
/*! |
|
1677 |
\since 4.2 |
|
1678 |
||
1679 |
Returns true if there are no visible actions inserted into the menu, false |
|
1680 |
otherwise. |
|
1681 |
||
1682 |
\sa QWidget::actions() |
|
1683 |
*/ |
|
1684 |
||
1685 |
bool QMenu::isEmpty() const |
|
1686 |
{ |
|
1687 |
bool ret = true; |
|
1688 |
for(int i = 0; ret && i < actions().count(); ++i) { |
|
1689 |
const QAction *action = actions().at(i); |
|
1690 |
if (!action->isSeparator() && action->isVisible()) { |
|
1691 |
ret = false; |
|
1692 |
} |
|
1693 |
} |
|
1694 |
return ret; |
|
1695 |
} |
|
1696 |
||
1697 |
/*! |
|
1698 |
Removes all the menu's actions. Actions owned by the menu and not |
|
1699 |
shown in any other widget are deleted. |
|
1700 |
||
1701 |
\sa removeAction() |
|
1702 |
*/ |
|
1703 |
void QMenu::clear() |
|
1704 |
{ |
|
1705 |
QList<QAction*> acts = actions(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1706 |
|
0 | 1707 |
for(int i = 0; i < acts.size(); i++) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1708 |
#ifdef QT_SOFTKEYS_ENABLED |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1709 |
Q_D(QMenu); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1710 |
// Lets not touch to our internal softkey actions |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1711 |
if(acts[i] == d->selectAction || acts[i] == d->cancelAction) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1712 |
continue; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1713 |
#endif |
0 | 1714 |
removeAction(acts[i]); |
1715 |
if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty()) |
|
1716 |
delete acts[i]; |
|
1717 |
} |
|
1718 |
} |
|
1719 |
||
1720 |
/*! |
|
1721 |
If a menu does not fit on the screen it lays itself out so that it |
|
1722 |
does fit. It is style dependent what layout means (for example, on |
|
1723 |
Windows it will use multiple columns). |
|
1724 |
||
1725 |
This functions returns the number of columns necessary. |
|
1726 |
*/ |
|
1727 |
int QMenu::columnCount() const |
|
1728 |
{ |
|
1729 |
return d_func()->ncols; |
|
1730 |
} |
|
1731 |
||
1732 |
/*! |
|
1733 |
Returns the item at \a pt; returns 0 if there is no item there. |
|
1734 |
*/ |
|
1735 |
QAction *QMenu::actionAt(const QPoint &pt) const |
|
1736 |
{ |
|
1737 |
if (QAction *ret = d_func()->actionAt(pt)) |
|
1738 |
return ret; |
|
1739 |
return 0; |
|
1740 |
} |
|
1741 |
||
1742 |
/*! |
|
1743 |
Returns the geometry of action \a act. |
|
1744 |
*/ |
|
1745 |
QRect QMenu::actionGeometry(QAction *act) const |
|
1746 |
{ |
|
1747 |
return d_func()->actionRect(act); |
|
1748 |
} |
|
1749 |
||
1750 |
/*! |
|
1751 |
\reimp |
|
1752 |
*/ |
|
1753 |
QSize QMenu::sizeHint() const |
|
1754 |
{ |
|
1755 |
Q_D(const QMenu); |
|
1756 |
d->updateActionRects(); |
|
1757 |
||
1758 |
QSize s; |
|
1759 |
for (int i = 0; i < d->actionRects.count(); ++i) { |
|
1760 |
const QRect &rect = d->actionRects.at(i); |
|
1761 |
if (rect.isNull()) |
|
1762 |
continue; |
|
1763 |
if (rect.bottom() >= s.height()) |
|
1764 |
s.setHeight(rect.y() + rect.height()); |
|
1765 |
if (rect.right() >= s.width()) |
|
1766 |
s.setWidth(rect.x() + rect.width()); |
|
1767 |
} |
|
1768 |
// Note that the action rects calculated above already include |
|
1769 |
// the top and left margins, so we only need to add margins for |
|
1770 |
// the bottom and right. |
|
1771 |
QStyleOption opt(0); |
|
1772 |
opt.init(this); |
|
1773 |
const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, this); |
|
1774 |
s.rwidth() += style()->pixelMetric(QStyle::PM_MenuHMargin, &opt, this) + fw + d->rightmargin; |
|
1775 |
s.rheight() += style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) + fw + d->bottommargin; |
|
1776 |
||
1777 |
return style()->sizeFromContents(QStyle::CT_Menu, &opt, |
|
1778 |
s.expandedTo(QApplication::globalStrut()), this); |
|
1779 |
} |
|
1780 |
||
1781 |
/*! |
|
1782 |
Displays the menu so that the action \a atAction will be at the |
|
1783 |
specified \e global position \a p. To translate a widget's local |
|
1784 |
coordinates into global coordinates, use QWidget::mapToGlobal(). |
|
1785 |
||
1786 |
When positioning a menu with exec() or popup(), bear in mind that |
|
1787 |
you cannot rely on the menu's current size(). For performance |
|
1788 |
reasons, the menu adapts its size only when necessary, so in many |
|
1789 |
cases, the size before and after the show is different. Instead, |
|
1790 |
use sizeHint() which calculates the proper size depending on the |
|
1791 |
menu's current contents. |
|
1792 |
||
1793 |
\sa QWidget::mapToGlobal(), exec() |
|
1794 |
*/ |
|
1795 |
void QMenu::popup(const QPoint &p, QAction *atAction) |
|
1796 |
{ |
|
1797 |
Q_D(QMenu); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1798 |
if (d->scroll) { // reset scroll state from last popup |
0 | 1799 |
d->scroll->scrollOffset = 0; |
1800 |
d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; |
|
1801 |
} |
|
1802 |
d->tearoffHighlighted = 0; |
|
1803 |
d->motions = 0; |
|
1804 |
d->doChildEffects = true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1805 |
d->updateLayoutDirection(); |
0 | 1806 |
|
1807 |
#ifndef QT_NO_MENUBAR |
|
1808 |
// if this menu is part of a chain attached to a QMenuBar, set the |
|
1809 |
// _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1810 |
setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast<QMenuBar *>(d->topCausedWidget()) != 0); |
0 | 1811 |
#endif |
1812 |
||
1813 |
ensurePolished(); // Get the right font |
|
1814 |
emit aboutToShow(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1815 |
const bool actionListChanged = d->itemsDirty; |
0 | 1816 |
d->updateActionRects(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1817 |
QPoint pos; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1818 |
QPushButton *causedButton = qobject_cast<QPushButton*>(d->causedPopup.widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1819 |
if (actionListChanged && causedButton) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1820 |
pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1821 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1822 |
pos = p; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1823 |
|
0 | 1824 |
QSize size = sizeHint(); |
1825 |
QRect screen; |
|
1826 |
#ifndef QT_NO_GRAPHICSVIEW |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1827 |
bool isEmbedded = !bypassGraphicsProxyWidget(this) && d->nearestGraphicsProxyWidget(this); |
0 | 1828 |
if (isEmbedded) |
1829 |
screen = d->popupGeometry(this); |
|
1830 |
else |
|
1831 |
#endif |
|
1832 |
screen = d->popupGeometry(QApplication::desktop()->screenNumber(p)); |
|
1833 |
||
1834 |
const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, this); |
|
1835 |
bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen); |
|
1836 |
#ifdef QT_KEYPAD_NAVIGATION |
|
1837 |
if (!atAction && QApplication::keypadNavigationEnabled()) { |
|
1838 |
// Try to have one item activated |
|
1839 |
if (d->defaultAction && d->defaultAction->isEnabled()) { |
|
1840 |
atAction = d->defaultAction; |
|
1841 |
// TODO: This works for first level menus, not yet sub menus |
|
1842 |
} else { |
|
1843 |
foreach (QAction *action, d->actions) |
|
1844 |
if (action->isEnabled()) { |
|
1845 |
atAction = action; |
|
1846 |
break; |
|
1847 |
} |
|
1848 |
} |
|
1849 |
d->currentAction = atAction; |
|
1850 |
} |
|
1851 |
#endif |
|
1852 |
if (d->ncols > 1) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1853 |
pos.setY(screen.top() + desktopFrame); |
0 | 1854 |
} else if (atAction) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1855 |
for (int i = 0, above_height = 0; i < d->actions.count(); i++) { |
0 | 1856 |
QAction *action = d->actions.at(i); |
1857 |
if (action == atAction) { |
|
1858 |
int newY = pos.y() - above_height; |
|
1859 |
if (d->scroll && newY < desktopFrame) { |
|
1860 |
d->scroll->scrollFlags = d->scroll->scrollFlags |
|
1861 |
| QMenuPrivate::QMenuScroller::ScrollUp; |
|
1862 |
d->scroll->scrollOffset = newY; |
|
1863 |
newY = desktopFrame; |
|
1864 |
} |
|
1865 |
pos.setY(newY); |
|
1866 |
||
1867 |
if (d->scroll && d->scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone |
|
1868 |
&& !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, 0, this)) { |
|
1869 |
int below_height = above_height + d->scroll->scrollOffset; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1870 |
for (int i2 = i; i2 < d->actionRects.count(); i2++) |
0 | 1871 |
below_height += d->actionRects.at(i2).height(); |
1872 |
size.setHeight(below_height); |
|
1873 |
} |
|
1874 |
break; |
|
1875 |
} else { |
|
1876 |
above_height += d->actionRects.at(i).height(); |
|
1877 |
} |
|
1878 |
} |
|
1879 |
} |
|
1880 |
||
1881 |
QPoint mouse = QCursor::pos(); |
|
1882 |
d->mousePopupPos = mouse; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1883 |
const bool snapToMouse = (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); |
0 | 1884 |
|
1885 |
if (adjustToDesktop) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1886 |
// handle popup falling "off screen" |
0 | 1887 |
if (isRightToLeft()) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1888 |
if (snapToMouse) // position flowing left from the mouse |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1889 |
pos.setX(mouse.x() - size.width()); |
0 | 1890 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1891 |
#ifndef QT_NO_MENUBAR |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1892 |
// if in a menubar, it should be right-aligned |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1893 |
if (qobject_cast<QMenuBar*>(d->causedPopup.widget)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1894 |
pos.rx() -= size.width(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1895 |
#endif //QT_NO_MENUBAR |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1896 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1897 |
if (pos.x() < screen.left() + desktopFrame) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1898 |
pos.setX(qMax(p.x(), screen.left() + desktopFrame)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1899 |
if (pos.x() + size.width() - 1 > screen.right() - desktopFrame) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1900 |
pos.setX(qMax(p.x() - size.width(), screen.right() - desktopFrame - size.width() + 1)); |
0 | 1901 |
} else { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1902 |
if (pos.x() + size.width() - 1 > screen.right() - desktopFrame) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1903 |
pos.setX(screen.right() - desktopFrame - size.width() + 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1904 |
if (pos.x() < screen.left() + desktopFrame) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1905 |
pos.setX(screen.left() + desktopFrame); |
0 | 1906 |
} |
1907 |
if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) { |
|
1908 |
if(snapToMouse) |
|
1909 |
pos.setY(qMin(mouse.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); |
|
1910 |
else |
|
1911 |
pos.setY(qMax(p.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); |
|
1912 |
} else if (pos.y() < screen.top() + desktopFrame) { |
|
1913 |
pos.setY(screen.top() + desktopFrame); |
|
1914 |
} |
|
1915 |
||
1916 |
if (pos.y() < screen.top() + desktopFrame) |
|
1917 |
pos.setY(screen.top() + desktopFrame); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1918 |
if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) { |
0 | 1919 |
if (d->scroll) { |
1920 |
d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); |
|
1921 |
int y = qMax(screen.y(),pos.y()); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1922 |
size.setHeight(screen.bottom() - (desktopFrame * 2) - y); |
0 | 1923 |
} else { |
1924 |
// Too big for screen, bias to see bottom of menu (for some reason) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1925 |
pos.setY(screen.bottom() - size.height() + 1); |
0 | 1926 |
} |
1927 |
} |
|
1928 |
} |
|
1929 |
setGeometry(QRect(pos, size)); |
|
1930 |
#ifndef QT_NO_EFFECTS |
|
1931 |
int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; |
|
1932 |
int vGuess = QEffects::DownScroll; |
|
1933 |
if (isRightToLeft()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1934 |
if ((snapToMouse && (pos.x() + size.width() / 2 > mouse.x())) || |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1935 |
(qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 > d->causedPopup.widget->x())) |
0 | 1936 |
hGuess = QEffects::RightScroll; |
1937 |
} else { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1938 |
if ((snapToMouse && (pos.x() + size.width() / 2 < mouse.x())) || |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1939 |
(qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 < d->causedPopup.widget->x())) |
0 | 1940 |
hGuess = QEffects::LeftScroll; |
1941 |
} |
|
1942 |
||
1943 |
#ifndef QT_NO_MENUBAR |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1944 |
if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) || |
0 | 1945 |
(qobject_cast<QMenuBar*>(d->causedPopup.widget) && |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1946 |
pos.y() + size.width() / 2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y())) |
0 | 1947 |
vGuess = QEffects::UpScroll; |
1948 |
#endif |
|
1949 |
if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) { |
|
1950 |
bool doChildEffects = true; |
|
1951 |
#ifndef QT_NO_MENUBAR |
|
1952 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) { |
|
1953 |
doChildEffects = mb->d_func()->doChildEffects; |
|
1954 |
mb->d_func()->doChildEffects = false; |
|
1955 |
} else |
|
1956 |
#endif |
|
1957 |
if (QMenu *m = qobject_cast<QMenu*>(d->causedPopup.widget)) { |
|
1958 |
doChildEffects = m->d_func()->doChildEffects; |
|
1959 |
m->d_func()->doChildEffects = false; |
|
1960 |
} |
|
1961 |
||
1962 |
if (doChildEffects) { |
|
1963 |
if (QApplication::isEffectEnabled(Qt::UI_FadeMenu)) |
|
1964 |
qFadeEffect(this); |
|
1965 |
else if (d->causedPopup.widget) |
|
1966 |
qScrollEffect(this, qobject_cast<QMenu*>(d->causedPopup.widget) ? hGuess : vGuess); |
|
1967 |
else |
|
1968 |
qScrollEffect(this, hGuess | vGuess); |
|
1969 |
} else { |
|
1970 |
// kill any running effect |
|
1971 |
qFadeEffect(0); |
|
1972 |
qScrollEffect(0); |
|
1973 |
||
1974 |
show(); |
|
1975 |
} |
|
1976 |
} else |
|
1977 |
#endif |
|
1978 |
{ |
|
1979 |
show(); |
|
1980 |
} |
|
1981 |
||
1982 |
#ifndef QT_NO_ACCESSIBILITY |
|
1983 |
QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuStart); |
|
1984 |
#endif |
|
1985 |
} |
|
1986 |
||
1987 |
/*! |
|
1988 |
Executes this menu synchronously. |
|
1989 |
||
1990 |
This is equivalent to \c{exec(pos())}. |
|
1991 |
||
1992 |
This returns the triggered QAction in either the popup menu or one |
|
1993 |
of its submenus, or 0 if no item was triggered (normally because |
|
1994 |
the user pressed Esc). |
|
1995 |
||
1996 |
In most situations you'll want to specify the position yourself, |
|
1997 |
for example, the current mouse position: |
|
1998 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 0 |
|
1999 |
or aligned to a widget: |
|
2000 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 1 |
|
2001 |
or in reaction to a QMouseEvent *e: |
|
2002 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 2 |
|
2003 |
*/ |
|
2004 |
QAction *QMenu::exec() |
|
2005 |
{ |
|
2006 |
return exec(pos()); |
|
2007 |
} |
|
2008 |
||
2009 |
||
2010 |
/*! |
|
2011 |
\overload |
|
2012 |
||
2013 |
Executes this menu synchronously. |
|
2014 |
||
2015 |
Pops up the menu so that the action \a action will be at the |
|
2016 |
specified \e global position \a p. To translate a widget's local |
|
2017 |
coordinates into global coordinates, use QWidget::mapToGlobal(). |
|
2018 |
||
2019 |
This returns the triggered QAction in either the popup menu or one |
|
2020 |
of its submenus, or 0 if no item was triggered (normally because |
|
2021 |
the user pressed Esc). |
|
2022 |
||
2023 |
Note that all signals are emitted as usual. If you connect a |
|
2024 |
QAction to a slot and call the menu's exec(), you get the result |
|
2025 |
both via the signal-slot connection and in the return value of |
|
2026 |
exec(). |
|
2027 |
||
2028 |
Common usage is to position the menu at the current mouse |
|
2029 |
position: |
|
2030 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 3 |
|
2031 |
or aligned to a widget: |
|
2032 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 4 |
|
2033 |
or in reaction to a QMouseEvent *e: |
|
2034 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 5 |
|
2035 |
||
2036 |
When positioning a menu with exec() or popup(), bear in mind that |
|
2037 |
you cannot rely on the menu's current size(). For performance |
|
2038 |
reasons, the menu adapts its size only when necessary. So in many |
|
2039 |
cases, the size before and after the show is different. Instead, |
|
2040 |
use sizeHint() which calculates the proper size depending on the |
|
2041 |
menu's current contents. |
|
2042 |
||
2043 |
\sa popup(), QWidget::mapToGlobal() |
|
2044 |
*/ |
|
2045 |
QAction *QMenu::exec(const QPoint &p, QAction *action) |
|
2046 |
{ |
|
2047 |
Q_D(QMenu); |
|
2048 |
createWinId(); |
|
2049 |
QEventLoop eventLoop; |
|
2050 |
d->eventLoop = &eventLoop; |
|
2051 |
popup(p, action); |
|
2052 |
||
2053 |
QPointer<QObject> guard = this; |
|
2054 |
(void) eventLoop.exec(); |
|
2055 |
if (guard.isNull()) |
|
2056 |
return 0; |
|
2057 |
||
2058 |
action = d->syncAction; |
|
2059 |
d->syncAction = 0; |
|
2060 |
d->eventLoop = 0; |
|
2061 |
return action; |
|
2062 |
} |
|
2063 |
||
2064 |
/*! |
|
2065 |
\overload |
|
2066 |
||
2067 |
Executes a menu synchronously. |
|
2068 |
||
2069 |
The menu's actions are specified by the list of \a actions. The menu will |
|
2070 |
pop up so that the specified action, \a at, appears at global position \a |
|
2071 |
pos. If \a at is not specified then the menu appears at position \a |
|
2072 |
pos. \a parent is the menu's parent widget; specifying the parent will |
|
2073 |
provide context when \a pos alone is not enough to decide where the menu |
|
2074 |
should go (e.g., with multiple desktops or when the parent is embedded in |
|
2075 |
QGraphicsView). |
|
2076 |
||
2077 |
The function returns the triggered QAction in either the popup |
|
2078 |
menu or one of its submenus, or 0 if no item was triggered |
|
2079 |
(normally because the user pressed Esc). |
|
2080 |
||
2081 |
This is equivalent to: |
|
2082 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 6 |
|
2083 |
||
2084 |
\sa popup(), QWidget::mapToGlobal() |
|
2085 |
*/ |
|
2086 |
QAction *QMenu::exec(QList<QAction*> actions, const QPoint &pos, QAction *at, QWidget *parent) |
|
2087 |
{ |
|
2088 |
QMenu menu(parent); |
|
2089 |
menu.addActions(actions); |
|
2090 |
return menu.exec(pos, at); |
|
2091 |
} |
|
2092 |
||
2093 |
/*! |
|
2094 |
\overload |
|
2095 |
||
2096 |
Executes a menu synchronously. |
|
2097 |
||
2098 |
The menu's actions are specified by the list of \a actions. The menu |
|
2099 |
will pop up so that the specified action, \a at, appears at global |
|
2100 |
position \a pos. If \a at is not specified then the menu appears |
|
2101 |
at position \a pos. |
|
2102 |
||
2103 |
The function returns the triggered QAction in either the popup |
|
2104 |
menu or one of its submenus, or 0 if no item was triggered |
|
2105 |
(normally because the user pressed Esc). |
|
2106 |
||
2107 |
This is equivalent to: |
|
2108 |
\snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 6 |
|
2109 |
||
2110 |
\sa popup(), QWidget::mapToGlobal() |
|
2111 |
*/ |
|
2112 |
QAction *QMenu::exec(QList<QAction*> actions, const QPoint &pos, QAction *at) |
|
2113 |
{ |
|
2114 |
// ### Qt 5: merge |
|
2115 |
return exec(actions, pos, at, 0); |
|
2116 |
} |
|
2117 |
||
2118 |
/*! |
|
2119 |
\reimp |
|
2120 |
*/ |
|
2121 |
void QMenu::hideEvent(QHideEvent *) |
|
2122 |
{ |
|
2123 |
Q_D(QMenu); |
|
2124 |
emit aboutToHide(); |
|
2125 |
if (d->eventLoop) |
|
2126 |
d->eventLoop->exit(); |
|
2127 |
d->setCurrentAction(0); |
|
2128 |
#ifndef QT_NO_ACCESSIBILITY |
|
2129 |
QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuEnd); |
|
2130 |
#endif |
|
2131 |
#ifndef QT_NO_MENUBAR |
|
2132 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) |
|
2133 |
mb->d_func()->setCurrentAction(0); |
|
2134 |
#endif |
|
2135 |
d->mouseDown = 0; |
|
2136 |
d->hasHadMouse = false; |
|
2137 |
d->causedPopup.widget = 0; |
|
2138 |
d->causedPopup.action = 0; |
|
2139 |
if (d->scroll) |
|
2140 |
d->scroll->scrollTimer.stop(); //make sure the timer stops |
|
2141 |
} |
|
2142 |
||
2143 |
/*! |
|
2144 |
\reimp |
|
2145 |
*/ |
|
2146 |
void QMenu::paintEvent(QPaintEvent *e) |
|
2147 |
{ |
|
2148 |
Q_D(QMenu); |
|
2149 |
d->updateActionRects(); |
|
2150 |
QPainter p(this); |
|
2151 |
QRegion emptyArea = QRegion(rect()); |
|
2152 |
||
2153 |
QStyleOptionMenuItem menuOpt; |
|
2154 |
menuOpt.initFrom(this); |
|
2155 |
menuOpt.state = QStyle::State_None; |
|
2156 |
menuOpt.checkType = QStyleOptionMenuItem::NotCheckable; |
|
2157 |
menuOpt.maxIconWidth = 0; |
|
2158 |
menuOpt.tabWidth = 0; |
|
2159 |
style()->drawPrimitive(QStyle::PE_PanelMenu, &menuOpt, &p, this); |
|
2160 |
||
2161 |
//draw the items that need updating.. |
|
2162 |
for (int i = 0; i < d->actions.count(); ++i) { |
|
2163 |
QAction *action = d->actions.at(i); |
|
2164 |
QRect adjustedActionRect = d->actionRects.at(i); |
|
2165 |
if (!e->rect().intersects(adjustedActionRect) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2166 |
|| d->widgetItems.value(action)) |
0 | 2167 |
continue; |
2168 |
//set the clip region to be extra safe (and adjust for the scrollers) |
|
2169 |
QRegion adjustedActionReg(adjustedActionRect); |
|
2170 |
emptyArea -= adjustedActionReg; |
|
2171 |
p.setClipRegion(adjustedActionReg); |
|
2172 |
||
2173 |
QStyleOptionMenuItem opt; |
|
2174 |
initStyleOption(&opt, action); |
|
2175 |
opt.rect = adjustedActionRect; |
|
2176 |
style()->drawControl(QStyle::CE_MenuItem, &opt, &p, this); |
|
2177 |
} |
|
2178 |
||
2179 |
const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this); |
|
2180 |
//draw the scroller regions.. |
|
2181 |
if (d->scroll) { |
|
2182 |
menuOpt.menuItemType = QStyleOptionMenuItem::Scroller; |
|
2183 |
menuOpt.state |= QStyle::State_Enabled; |
|
2184 |
if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) { |
|
2185 |
menuOpt.rect.setRect(fw, fw, width() - (fw * 2), d->scrollerHeight()); |
|
2186 |
emptyArea -= QRegion(menuOpt.rect); |
|
2187 |
p.setClipRect(menuOpt.rect); |
|
2188 |
style()->drawControl(QStyle::CE_MenuScroller, &menuOpt, &p, this); |
|
2189 |
} |
|
2190 |
if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown) { |
|
2191 |
menuOpt.rect.setRect(fw, height() - d->scrollerHeight() - fw, width() - (fw * 2), |
|
2192 |
d->scrollerHeight()); |
|
2193 |
emptyArea -= QRegion(menuOpt.rect); |
|
2194 |
menuOpt.state |= QStyle::State_DownArrow; |
|
2195 |
p.setClipRect(menuOpt.rect); |
|
2196 |
style()->drawControl(QStyle::CE_MenuScroller, &menuOpt, &p, this); |
|
2197 |
} |
|
2198 |
} |
|
2199 |
//paint the tear off.. |
|
2200 |
if (d->tearoff) { |
|
2201 |
menuOpt.menuItemType = QStyleOptionMenuItem::TearOff; |
|
2202 |
menuOpt.rect.setRect(fw, fw, width() - (fw * 2), |
|
2203 |
style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this)); |
|
2204 |
if (d->scroll && d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) |
|
2205 |
menuOpt.rect.translate(0, d->scrollerHeight()); |
|
2206 |
emptyArea -= QRegion(menuOpt.rect); |
|
2207 |
p.setClipRect(menuOpt.rect); |
|
2208 |
menuOpt.state = QStyle::State_None; |
|
2209 |
if (d->tearoffHighlighted) |
|
2210 |
menuOpt.state |= QStyle::State_Selected; |
|
2211 |
style()->drawControl(QStyle::CE_MenuTearoff, &menuOpt, &p, this); |
|
2212 |
} |
|
2213 |
//draw border |
|
2214 |
if (fw) { |
|
2215 |
QRegion borderReg; |
|
2216 |
borderReg += QRect(0, 0, fw, height()); //left |
|
2217 |
borderReg += QRect(width()-fw, 0, fw, height()); //right |
|
2218 |
borderReg += QRect(0, 0, width(), fw); //top |
|
2219 |
borderReg += QRect(0, height()-fw, width(), fw); //bottom |
|
2220 |
p.setClipRegion(borderReg); |
|
2221 |
emptyArea -= borderReg; |
|
2222 |
QStyleOptionFrame frame; |
|
2223 |
frame.rect = rect(); |
|
2224 |
frame.palette = palette(); |
|
2225 |
frame.state = QStyle::State_None; |
|
2226 |
frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth); |
|
2227 |
frame.midLineWidth = 0; |
|
2228 |
style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, &p, this); |
|
2229 |
} |
|
2230 |
||
2231 |
//finally the rest of the space |
|
2232 |
p.setClipRegion(emptyArea); |
|
2233 |
menuOpt.state = QStyle::State_None; |
|
2234 |
menuOpt.menuItemType = QStyleOptionMenuItem::EmptyArea; |
|
2235 |
menuOpt.checkType = QStyleOptionMenuItem::NotCheckable; |
|
2236 |
menuOpt.rect = rect(); |
|
2237 |
menuOpt.menuRect = rect(); |
|
2238 |
style()->drawControl(QStyle::CE_MenuEmptyArea, &menuOpt, &p, this); |
|
2239 |
} |
|
2240 |
||
2241 |
#ifndef QT_NO_WHEELEVENT |
|
2242 |
/*! |
|
2243 |
\reimp |
|
2244 |
*/ |
|
2245 |
void QMenu::wheelEvent(QWheelEvent *e) |
|
2246 |
{ |
|
2247 |
Q_D(QMenu); |
|
2248 |
if (d->scroll && rect().contains(e->pos())) |
|
2249 |
d->scrollMenu(e->delta() > 0 ? |
|
2250 |
QMenuPrivate::QMenuScroller::ScrollUp : QMenuPrivate::QMenuScroller::ScrollDown); |
|
2251 |
} |
|
2252 |
#endif |
|
2253 |
||
2254 |
/*! |
|
2255 |
\reimp |
|
2256 |
*/ |
|
2257 |
void QMenu::mousePressEvent(QMouseEvent *e) |
|
2258 |
{ |
|
2259 |
Q_D(QMenu); |
|
2260 |
if (d->aboutToHide || d->mouseEventTaken(e)) |
|
2261 |
return; |
|
2262 |
if (!rect().contains(e->pos())) { |
|
2263 |
if (d->noReplayFor |
|
2264 |
&& QRect(d->noReplayFor->mapToGlobal(QPoint()), d->noReplayFor->size()).contains(e->globalPos())) |
|
2265 |
setAttribute(Qt::WA_NoMouseReplay); |
|
2266 |
if (d->eventLoop) // synchronous operation |
|
2267 |
d->syncAction = 0; |
|
2268 |
d->hideUpToMenuBar(); |
|
2269 |
return; |
|
2270 |
} |
|
2271 |
d->mouseDown = this; |
|
2272 |
||
2273 |
QAction *action = d->actionAt(e->pos()); |
|
2274 |
d->setCurrentAction(action, 20); |
|
2275 |
update(); |
|
2276 |
} |
|
2277 |
||
2278 |
/*! |
|
2279 |
\reimp |
|
2280 |
*/ |
|
2281 |
void QMenu::mouseReleaseEvent(QMouseEvent *e) |
|
2282 |
{ |
|
2283 |
Q_D(QMenu); |
|
2284 |
if (d->aboutToHide || d->mouseEventTaken(e)) |
|
2285 |
return; |
|
2286 |
if(d->mouseDown != this) { |
|
2287 |
d->mouseDown = 0; |
|
2288 |
return; |
|
2289 |
} |
|
2290 |
||
2291 |
d->mouseDown = 0; |
|
2292 |
d->setSyncAction(); |
|
2293 |
QAction *action = d->actionAt(e->pos()); |
|
2294 |
||
2295 |
if (action && action == d->currentAction) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2296 |
if (!action->menu()){ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2297 |
#if defined(Q_WS_WIN) |
0 | 2298 |
//On Windows only context menus can be activated with the right button |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2299 |
if (e->button() == Qt::LeftButton || d->topCausedWidget() == 0) |
0 | 2300 |
#endif |
2301 |
d->activateAction(action, QAction::Trigger); |
|
2302 |
} |
|
2303 |
} else if (d->hasMouseMoved(e->globalPos())) { |
|
2304 |
d->hideUpToMenuBar(); |
|
2305 |
} |
|
2306 |
} |
|
2307 |
||
2308 |
/*! |
|
2309 |
\reimp |
|
2310 |
*/ |
|
2311 |
void QMenu::changeEvent(QEvent *e) |
|
2312 |
{ |
|
2313 |
Q_D(QMenu); |
|
2314 |
if (e->type() == QEvent::StyleChange || e->type() == QEvent::FontChange || |
|
2315 |
e->type() == QEvent::LayoutDirectionChange) { |
|
2316 |
d->itemsDirty = 1; |
|
2317 |
setMouseTracking(style()->styleHint(QStyle::SH_Menu_MouseTracking, 0, this)); |
|
2318 |
if (isVisible()) |
|
2319 |
resize(sizeHint()); |
|
2320 |
if (!style()->styleHint(QStyle::SH_Menu_Scrollable, 0, this)) { |
|
2321 |
delete d->scroll; |
|
2322 |
d->scroll = 0; |
|
2323 |
} else if (!d->scroll) { |
|
2324 |
d->scroll = new QMenuPrivate::QMenuScroller; |
|
2325 |
d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; |
|
2326 |
} |
|
2327 |
} else if (e->type() == QEvent::EnabledChange) { |
|
2328 |
if (d->tornPopup) // torn-off menu |
|
2329 |
d->tornPopup->setEnabled(isEnabled()); |
|
2330 |
d->menuAction->setEnabled(isEnabled()); |
|
2331 |
#ifdef Q_WS_MAC |
|
2332 |
if (d->mac_menu) |
|
2333 |
d->setMacMenuEnabled(isEnabled()); |
|
2334 |
#endif |
|
2335 |
} |
|
2336 |
QWidget::changeEvent(e); |
|
2337 |
} |
|
2338 |
||
2339 |
||
2340 |
/*! |
|
2341 |
\reimp |
|
2342 |
*/ |
|
2343 |
bool |
|
2344 |
QMenu::event(QEvent *e) |
|
2345 |
{ |
|
2346 |
Q_D(QMenu); |
|
2347 |
switch (e->type()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2348 |
case QEvent::Polish: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2349 |
d->updateLayoutDirection(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2350 |
break; |
0 | 2351 |
case QEvent::ShortcutOverride: { |
2352 |
QKeyEvent *kev = static_cast<QKeyEvent*>(e); |
|
2353 |
if (kev->key() == Qt::Key_Up || kev->key() == Qt::Key_Down |
|
2354 |
|| kev->key() == Qt::Key_Left || kev->key() == Qt::Key_Right |
|
2355 |
|| kev->key() == Qt::Key_Enter || kev->key() == Qt::Key_Return |
|
2356 |
|| kev->key() == Qt::Key_Escape) { |
|
2357 |
e->accept(); |
|
2358 |
return true; |
|
2359 |
} |
|
2360 |
} |
|
2361 |
break; |
|
2362 |
case QEvent::KeyPress: { |
|
2363 |
QKeyEvent *ke = (QKeyEvent*)e; |
|
2364 |
if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) { |
|
2365 |
keyPressEvent(ke); |
|
2366 |
return true; |
|
2367 |
} |
|
2368 |
} break; |
|
2369 |
case QEvent::ContextMenu: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2370 |
if(d->menuDelayTimer.isActive()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2371 |
d->menuDelayTimer.stop(); |
0 | 2372 |
internalDelayedPopup(); |
2373 |
} |
|
2374 |
break; |
|
2375 |
case QEvent::Resize: { |
|
2376 |
QStyleHintReturnMask menuMask; |
|
2377 |
QStyleOption option; |
|
2378 |
option.initFrom(this); |
|
2379 |
if (style()->styleHint(QStyle::SH_Menu_Mask, &option, this, &menuMask)) { |
|
2380 |
setMask(menuMask.region); |
|
2381 |
} |
|
2382 |
d->itemsDirty = 1; |
|
2383 |
d->updateActionRects(); |
|
2384 |
break; } |
|
2385 |
case QEvent::Show: |
|
2386 |
d->mouseDown = 0; |
|
2387 |
d->updateActionRects(); |
|
2388 |
if (d->currentAction) |
|
2389 |
d->popupAction(d->currentAction, 0, false); |
|
2390 |
break; |
|
2391 |
#ifndef QT_NO_WHATSTHIS |
|
2392 |
case QEvent::QueryWhatsThis: |
|
2393 |
e->setAccepted(d->whatsThis.size()); |
|
2394 |
if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) { |
|
2395 |
if (action->whatsThis().size() || action->menu()) |
|
2396 |
e->accept(); |
|
2397 |
} |
|
2398 |
return true; |
|
2399 |
#endif |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2400 |
#ifdef QT_SOFTKEYS_ENABLED |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2401 |
case QEvent::LanguageChange: { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2402 |
d->selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2403 |
d->cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2404 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2405 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2406 |
#endif |
0 | 2407 |
default: |
2408 |
break; |
|
2409 |
} |
|
2410 |
return QWidget::event(e); |
|
2411 |
} |
|
2412 |
||
2413 |
/*! |
|
2414 |
\reimp |
|
2415 |
*/ |
|
2416 |
bool QMenu::focusNextPrevChild(bool next) |
|
2417 |
{ |
|
2418 |
setFocus(); |
|
2419 |
QKeyEvent ev(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); |
|
2420 |
keyPressEvent(&ev); |
|
2421 |
return true; |
|
2422 |
} |
|
2423 |
||
2424 |
/*! |
|
2425 |
\reimp |
|
2426 |
*/ |
|
2427 |
void QMenu::keyPressEvent(QKeyEvent *e) |
|
2428 |
{ |
|
2429 |
Q_D(QMenu); |
|
2430 |
d->updateActionRects(); |
|
2431 |
int key = e->key(); |
|
2432 |
if (isRightToLeft()) { // in reverse mode open/close key for submenues are reversed |
|
2433 |
if (key == Qt::Key_Left) |
|
2434 |
key = Qt::Key_Right; |
|
2435 |
else if (key == Qt::Key_Right) |
|
2436 |
key = Qt::Key_Left; |
|
2437 |
} |
|
2438 |
#ifndef Q_WS_MAC |
|
2439 |
if (key == Qt::Key_Tab) //means down |
|
2440 |
key = Qt::Key_Down; |
|
2441 |
if (key == Qt::Key_Backtab) //means up |
|
2442 |
key = Qt::Key_Up; |
|
2443 |
#endif |
|
2444 |
||
2445 |
bool key_consumed = false; |
|
2446 |
switch(key) { |
|
2447 |
case Qt::Key_Home: |
|
2448 |
key_consumed = true; |
|
2449 |
if (d->scroll) |
|
2450 |
d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollTop, true); |
|
2451 |
break; |
|
2452 |
case Qt::Key_End: |
|
2453 |
key_consumed = true; |
|
2454 |
if (d->scroll) |
|
2455 |
d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollBottom, true); |
|
2456 |
break; |
|
2457 |
case Qt::Key_PageUp: |
|
2458 |
key_consumed = true; |
|
2459 |
if (d->currentAction && d->scroll) { |
|
2460 |
if(d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) |
|
2461 |
d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollUp, true, true); |
|
2462 |
else |
|
2463 |
d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollTop, true); |
|
2464 |
} |
|
2465 |
break; |
|
2466 |
case Qt::Key_PageDown: |
|
2467 |
key_consumed = true; |
|
2468 |
if (d->currentAction && d->scroll) { |
|
2469 |
if(d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown) |
|
2470 |
d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollDown, true, true); |
|
2471 |
else |
|
2472 |
d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollBottom, true); |
|
2473 |
} |
|
2474 |
break; |
|
2475 |
case Qt::Key_Up: |
|
2476 |
case Qt::Key_Down: { |
|
2477 |
key_consumed = true; |
|
2478 |
QAction *nextAction = 0; |
|
2479 |
QMenuPrivate::QMenuScroller::ScrollLocation scroll_loc = QMenuPrivate::QMenuScroller::ScrollStay; |
|
2480 |
if (!d->currentAction) { |
|
2481 |
if(key == Qt::Key_Down) { |
|
2482 |
for(int i = 0; i < d->actions.count(); ++i) { |
|
2483 |
QAction *act = d->actions.at(i); |
|
2484 |
if (d->actionRects.at(i).isNull()) |
|
2485 |
continue; |
|
2486 |
if (!act->isSeparator() && |
|
2487 |
(style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) |
|
2488 |
|| act->isEnabled())) { |
|
2489 |
nextAction = act; |
|
2490 |
break; |
|
2491 |
} |
|
2492 |
} |
|
2493 |
} else { |
|
2494 |
for(int i = d->actions.count()-1; i >= 0; --i) { |
|
2495 |
QAction *act = d->actions.at(i); |
|
2496 |
if (d->actionRects.at(i).isNull()) |
|
2497 |
continue; |
|
2498 |
if (!act->isSeparator() && |
|
2499 |
(style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) |
|
2500 |
|| act->isEnabled())) { |
|
2501 |
nextAction = act; |
|
2502 |
break; |
|
2503 |
} |
|
2504 |
} |
|
2505 |
} |
|
2506 |
} else { |
|
2507 |
for(int i = 0, y = 0; !nextAction && i < d->actions.count(); i++) { |
|
2508 |
QAction *act = d->actions.at(i); |
|
2509 |
if (act == d->currentAction) { |
|
2510 |
if (key == Qt::Key_Up) { |
|
2511 |
for(int next_i = i-1; true; next_i--) { |
|
2512 |
if (next_i == -1) { |
|
2513 |
if(!style()->styleHint(QStyle::SH_Menu_SelectionWrap, 0, this)) |
|
2514 |
break; |
|
2515 |
if (d->scroll) |
|
2516 |
scroll_loc = QMenuPrivate::QMenuScroller::ScrollBottom; |
|
2517 |
next_i = d->actionRects.count()-1; |
|
2518 |
} |
|
2519 |
QAction *next = d->actions.at(next_i); |
|
2520 |
if (next == d->currentAction) |
|
2521 |
break; |
|
2522 |
if (d->actionRects.at(next_i).isNull()) |
|
2523 |
continue; |
|
2524 |
if (next->isSeparator() || |
|
2525 |
(!next->isEnabled() && |
|
2526 |
!style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this))) |
|
2527 |
continue; |
|
2528 |
nextAction = next; |
|
2529 |
if (d->scroll && (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp)) { |
|
2530 |
int topVisible = d->scrollerHeight(); |
|
2531 |
if (d->tearoff) |
|
2532 |
topVisible += style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this); |
|
2533 |
if (((y + d->scroll->scrollOffset) - topVisible) <= d->actionRects.at(next_i).height()) |
|
2534 |
scroll_loc = QMenuPrivate::QMenuScroller::ScrollTop; |
|
2535 |
} |
|
2536 |
break; |
|
2537 |
} |
|
2538 |
if (!nextAction && d->tearoff) |
|
2539 |
d->tearoffHighlighted = 1; |
|
2540 |
} else { |
|
2541 |
y += d->actionRects.at(i).height(); |
|
2542 |
for(int next_i = i+1; true; next_i++) { |
|
2543 |
if (next_i == d->actionRects.count()) { |
|
2544 |
if(!style()->styleHint(QStyle::SH_Menu_SelectionWrap, 0, this)) |
|
2545 |
break; |
|
2546 |
if (d->scroll) |
|
2547 |
scroll_loc = QMenuPrivate::QMenuScroller::ScrollTop; |
|
2548 |
next_i = 0; |
|
2549 |
} |
|
2550 |
QAction *next = d->actions.at(next_i); |
|
2551 |
if (next == d->currentAction) |
|
2552 |
break; |
|
2553 |
if (d->actionRects.at(next_i).isNull()) |
|
2554 |
continue; |
|
2555 |
if (next->isSeparator() || |
|
2556 |
(!next->isEnabled() && |
|
2557 |
!style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this))) |
|
2558 |
continue; |
|
2559 |
nextAction = next; |
|
2560 |
if (d->scroll && (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown)) { |
|
2561 |
int bottomVisible = height() - d->scrollerHeight(); |
|
2562 |
if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) |
|
2563 |
bottomVisible -= d->scrollerHeight(); |
|
2564 |
if (d->tearoff) |
|
2565 |
bottomVisible -= style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this); |
|
2566 |
if ((y + d->scroll->scrollOffset + d->actionRects.at(next_i).height()) > bottomVisible) |
|
2567 |
scroll_loc = QMenuPrivate::QMenuScroller::ScrollBottom; |
|
2568 |
} |
|
2569 |
break; |
|
2570 |
} |
|
2571 |
} |
|
2572 |
break; |
|
2573 |
} |
|
2574 |
y += d->actionRects.at(i).height(); |
|
2575 |
} |
|
2576 |
} |
|
2577 |
if (nextAction) { |
|
2578 |
if (d->scroll && scroll_loc != QMenuPrivate::QMenuScroller::ScrollStay) { |
|
2579 |
d->scroll->scrollTimer.stop(); |
|
2580 |
d->scrollMenu(nextAction, scroll_loc); |
|
2581 |
} |
|
2582 |
d->setCurrentAction(nextAction, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); |
|
2583 |
} |
|
2584 |
break; } |
|
2585 |
||
2586 |
case Qt::Key_Right: |
|
2587 |
if (d->currentAction && d->currentAction->isEnabled() && d->currentAction->menu()) { |
|
2588 |
d->popupAction(d->currentAction, 0, true); |
|
2589 |
key_consumed = true; |
|
2590 |
break; |
|
2591 |
} |
|
2592 |
//FALL THROUGH |
|
2593 |
case Qt::Key_Left: { |
|
2594 |
if (d->currentAction && !d->scroll) { |
|
2595 |
QAction *nextAction = 0; |
|
2596 |
if (key == Qt::Key_Left) { |
|
2597 |
QRect actionR = d->actionRect(d->currentAction); |
|
2598 |
for(int x = actionR.left()-1; !nextAction && x >= 0; x--) |
|
2599 |
nextAction = d->actionAt(QPoint(x, actionR.center().y())); |
|
2600 |
} else { |
|
2601 |
QRect actionR = d->actionRect(d->currentAction); |
|
2602 |
for(int x = actionR.right()+1; !nextAction && x < width(); x++) |
|
2603 |
nextAction = d->actionAt(QPoint(x, actionR.center().y())); |
|
2604 |
} |
|
2605 |
if (nextAction) { |
|
2606 |
d->setCurrentAction(nextAction, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); |
|
2607 |
key_consumed = true; |
|
2608 |
} |
|
2609 |
} |
|
2610 |
if (!key_consumed && key == Qt::Key_Left && qobject_cast<QMenu*>(d->causedPopup.widget)) { |
|
2611 |
QPointer<QWidget> caused = d->causedPopup.widget; |
|
2612 |
d->hideMenu(this); |
|
2613 |
if (caused) |
|
2614 |
caused->setFocus(); |
|
2615 |
key_consumed = true; |
|
2616 |
} |
|
2617 |
break; } |
|
2618 |
||
2619 |
case Qt::Key_Alt: |
|
2620 |
if (d->tornoff) |
|
2621 |
break; |
|
2622 |
||
2623 |
key_consumed = true; |
|
2624 |
if (style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this)) |
|
2625 |
{ |
|
2626 |
d->hideMenu(this); |
|
2627 |
#ifndef QT_NO_MENUBAR |
|
2628 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(QApplication::focusWidget())) { |
|
2629 |
mb->d_func()->setKeyboardMode(false); |
|
2630 |
} |
|
2631 |
#endif |
|
2632 |
} |
|
2633 |
break; |
|
2634 |
||
2635 |
case Qt::Key_Escape: |
|
2636 |
#ifdef QT_KEYPAD_NAVIGATION |
|
2637 |
case Qt::Key_Back: |
|
2638 |
#endif |
|
2639 |
key_consumed = true; |
|
2640 |
if (d->tornoff) { |
|
2641 |
close(); |
|
2642 |
return; |
|
2643 |
} |
|
2644 |
{ |
|
2645 |
QPointer<QWidget> caused = d->causedPopup.widget; |
|
2646 |
d->hideMenu(this); // hide after getting causedPopup |
|
2647 |
#ifndef QT_NO_MENUBAR |
|
2648 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) { |
|
2649 |
mb->d_func()->setCurrentAction(d->menuAction); |
|
2650 |
mb->d_func()->setKeyboardMode(true); |
|
2651 |
} |
|
2652 |
#endif |
|
2653 |
} |
|
2654 |
break; |
|
2655 |
||
2656 |
case Qt::Key_Space: |
|
2657 |
if (!style()->styleHint(QStyle::SH_Menu_SpaceActivatesItem, 0, this)) |
|
2658 |
break; |
|
2659 |
// for motif, fall through |
|
2660 |
#ifdef QT_KEYPAD_NAVIGATION |
|
2661 |
case Qt::Key_Select: |
|
2662 |
#endif |
|
2663 |
case Qt::Key_Return: |
|
2664 |
case Qt::Key_Enter: { |
|
2665 |
if (!d->currentAction) { |
|
2666 |
d->setFirstActionActive(); |
|
2667 |
key_consumed = true; |
|
2668 |
break; |
|
2669 |
} |
|
2670 |
||
2671 |
d->setSyncAction(); |
|
2672 |
||
2673 |
if (d->currentAction->menu()) |
|
2674 |
d->popupAction(d->currentAction, 0, true); |
|
2675 |
else |
|
2676 |
d->activateAction(d->currentAction, QAction::Trigger); |
|
2677 |
key_consumed = true; |
|
2678 |
break; } |
|
2679 |
||
2680 |
#ifndef QT_NO_WHATSTHIS |
|
2681 |
case Qt::Key_F1: |
|
2682 |
if (!d->currentAction || d->currentAction->whatsThis().isNull()) |
|
2683 |
break; |
|
2684 |
QWhatsThis::enterWhatsThisMode(); |
|
2685 |
d->activateAction(d->currentAction, QAction::Trigger); |
|
2686 |
return; |
|
2687 |
#endif |
|
2688 |
default: |
|
2689 |
key_consumed = false; |
|
2690 |
} |
|
2691 |
||
2692 |
if (!key_consumed) { // send to menu bar |
|
2693 |
if ((!e->modifiers() || e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ShiftModifier) && |
|
2694 |
e->text().length()==1) { |
|
2695 |
bool activateAction = false; |
|
2696 |
QAction *nextAction = 0; |
|
2697 |
if (style()->styleHint(QStyle::SH_Menu_KeyboardSearch, 0, this) && !e->modifiers()) { |
|
2698 |
int best_match_count = 0; |
|
2699 |
d->searchBufferTimer.start(2000, this); |
|
2700 |
d->searchBuffer += e->text(); |
|
2701 |
for(int i = 0; i < d->actions.size(); ++i) { |
|
2702 |
int match_count = 0; |
|
2703 |
if (d->actionRects.at(i).isNull()) |
|
2704 |
continue; |
|
2705 |
QAction *act = d->actions.at(i); |
|
2706 |
const QString act_text = act->text(); |
|
2707 |
for(int c = 0; c < d->searchBuffer.size(); ++c) { |
|
2708 |
if(act_text.indexOf(d->searchBuffer.at(c), 0, Qt::CaseInsensitive) != -1) |
|
2709 |
++match_count; |
|
2710 |
} |
|
2711 |
if(match_count > best_match_count) { |
|
2712 |
best_match_count = match_count; |
|
2713 |
nextAction = act; |
|
2714 |
} |
|
2715 |
} |
|
2716 |
} |
|
2717 |
#ifndef QT_NO_SHORTCUT |
|
2718 |
else { |
|
2719 |
int clashCount = 0; |
|
2720 |
QAction *first = 0, *currentSelected = 0, *firstAfterCurrent = 0; |
|
2721 |
QChar c = e->text().at(0).toUpper(); |
|
2722 |
for(int i = 0; i < d->actions.size(); ++i) { |
|
2723 |
if (d->actionRects.at(i).isNull()) |
|
2724 |
continue; |
|
2725 |
QAction *act = d->actions.at(i); |
|
2726 |
QKeySequence sequence = QKeySequence::mnemonic(act->text()); |
|
2727 |
int key = sequence[0] & 0xffff; |
|
2728 |
if (key == c.unicode()) { |
|
2729 |
clashCount++; |
|
2730 |
if (!first) |
|
2731 |
first = act; |
|
2732 |
if (act == d->currentAction) |
|
2733 |
currentSelected = act; |
|
2734 |
else if (!firstAfterCurrent && currentSelected) |
|
2735 |
firstAfterCurrent = act; |
|
2736 |
} |
|
2737 |
} |
|
2738 |
if (clashCount == 1) |
|
2739 |
activateAction = true; |
|
2740 |
if (clashCount >= 1) { |
|
2741 |
if (clashCount == 1 || !currentSelected || !firstAfterCurrent) |
|
2742 |
nextAction = first; |
|
2743 |
else |
|
2744 |
nextAction = firstAfterCurrent; |
|
2745 |
} |
|
2746 |
} |
|
2747 |
#endif |
|
2748 |
if (nextAction) { |
|
2749 |
key_consumed = true; |
|
2750 |
if(d->scroll) |
|
2751 |
d->scrollMenu(nextAction, QMenuPrivate::QMenuScroller::ScrollCenter, false); |
|
2752 |
d->setCurrentAction(nextAction, 20, QMenuPrivate::SelectedFromElsewhere, true); |
|
2753 |
if (!nextAction->menu() && activateAction) { |
|
2754 |
d->setSyncAction(); |
|
2755 |
d->activateAction(nextAction, QAction::Trigger); |
|
2756 |
} |
|
2757 |
} |
|
2758 |
} |
|
2759 |
if (!key_consumed) { |
|
2760 |
#ifndef QT_NO_MENUBAR |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2761 |
if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->topCausedWidget())) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2762 |
QAction *oldAct = mb->d_func()->currentAction; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2763 |
QApplication::sendEvent(mb, e); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2764 |
if (mb->d_func()->currentAction != oldAct) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2765 |
key_consumed = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2766 |
} |
0 | 2767 |
#endif |
2768 |
} |
|
2769 |
||
2770 |
#ifdef Q_OS_WIN32 |
|
2771 |
if (key_consumed && (e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift || e->key() == Qt::Key_Meta)) |
|
2772 |
QApplication::beep(); |
|
2773 |
#endif // Q_OS_WIN32 |
|
2774 |
} |
|
2775 |
if (key_consumed) |
|
2776 |
e->accept(); |
|
2777 |
else |
|
2778 |
e->ignore(); |
|
2779 |
} |
|
2780 |
||
2781 |
/*! |
|
2782 |
\reimp |
|
2783 |
*/ |
|
2784 |
void QMenu::mouseMoveEvent(QMouseEvent *e) |
|
2785 |
{ |
|
2786 |
Q_D(QMenu); |
|
2787 |
if (!isVisible() || d->aboutToHide || d->mouseEventTaken(e)) |
|
2788 |
return; |
|
2789 |
d->motions++; |
|
2790 |
if (d->motions == 0) // ignore first mouse move event (see enterEvent()) |
|
2791 |
return; |
|
2792 |
d->hasHadMouse = d->hasHadMouse || rect().contains(e->pos()); |
|
2793 |
||
2794 |
QAction *action = d->actionAt(e->pos()); |
|
2795 |
if (!action) { |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2796 |
if (d->hasHadMouse |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2797 |
&& (!d->currentAction |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2798 |
|| !(d->currentAction->menu() && d->currentAction->menu()->isVisible()))) |
0 | 2799 |
d->setCurrentAction(0); |
2800 |
return; |
|
2801 |
} else if(e->buttons()) { |
|
2802 |
d->mouseDown = this; |
|
2803 |
} |
|
2804 |
if (d->sloppyRegion.contains(e->pos())) { |
|
2805 |
d->sloppyAction = action; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2806 |
QMenuPrivate::sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6); |
0 | 2807 |
} else { |
2808 |
d->setCurrentAction(action, style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)); |
|
2809 |
} |
|
2810 |
} |
|
2811 |
||
2812 |
/*! |
|
2813 |
\reimp |
|
2814 |
*/ |
|
2815 |
void QMenu::enterEvent(QEvent *) |
|
2816 |
{ |
|
2817 |
d_func()->motions = -1; // force us to ignore the generate mouse move in mouseMoveEvent() |
|
2818 |
} |
|
2819 |
||
2820 |
/*! |
|
2821 |
\reimp |
|
2822 |
*/ |
|
2823 |
void QMenu::leaveEvent(QEvent *) |
|
2824 |
{ |
|
2825 |
Q_D(QMenu); |
|
2826 |
d->sloppyAction = 0; |
|
2827 |
if (!d->sloppyRegion.isEmpty()) |
|
2828 |
d->sloppyRegion = QRegion(); |
|
2829 |
if (!d->activeMenu && d->currentAction) |
|
2830 |
setActiveAction(0); |
|
2831 |
} |
|
2832 |
||
2833 |
/*! |
|
2834 |
\reimp |
|
2835 |
*/ |
|
2836 |
void |
|
2837 |
QMenu::timerEvent(QTimerEvent *e) |
|
2838 |
{ |
|
2839 |
Q_D(QMenu); |
|
2840 |
if (d->scroll && d->scroll->scrollTimer.timerId() == e->timerId()) { |
|
2841 |
d->scrollMenu((QMenuPrivate::QMenuScroller::ScrollDirection)d->scroll->scrollDirection); |
|
2842 |
if (d->scroll->scrollFlags == QMenuPrivate::QMenuScroller::ScrollNone) |
|
2843 |
d->scroll->scrollTimer.stop(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2844 |
} else if(d->menuDelayTimer.timerId() == e->timerId()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2845 |
d->menuDelayTimer.stop(); |
0 | 2846 |
internalDelayedPopup(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2847 |
} else if(QMenuPrivate::sloppyDelayTimer == e->timerId()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2848 |
killTimer(QMenuPrivate::sloppyDelayTimer); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
2849 |
QMenuPrivate::sloppyDelayTimer = 0; |
0 | 2850 |
internalSetSloppyAction(); |
2851 |
} else if(d->searchBufferTimer.timerId() == e->timerId()) { |
|
2852 |
d->searchBuffer.clear(); |
|
2853 |
} |
|
2854 |
} |
|
2855 |
||
2856 |
/*! |
|
2857 |
\reimp |
|
2858 |
*/ |
|
2859 |
void QMenu::actionEvent(QActionEvent *e) |
|
2860 |
{ |
|
2861 |
Q_D(QMenu); |
|
2862 |
d->itemsDirty = 1; |
|
2863 |
setAttribute(Qt::WA_Resized, false); |
|
2864 |
if (d->tornPopup) |
|
2865 |
d->tornPopup->syncWithMenu(this, e); |
|
2866 |
if (e->type() == QEvent::ActionAdded) { |
|
2867 |
if(!d->tornoff) { |
|
2868 |
connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); |
|
2869 |
connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered())); |
|
2870 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2871 |
if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2872 |
QWidget *widget = wa->requestWidget(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2873 |
if (widget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2874 |
d->widgetItems.insert(wa, widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2875 |
} |
0 | 2876 |
} else if (e->type() == QEvent::ActionRemoved) { |
2877 |
e->action()->disconnect(this); |
|
2878 |
if (e->action() == d->currentAction) |
|
2879 |
d->currentAction = 0; |
|
2880 |
if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2881 |
if (QWidget *widget = d->widgetItems.value(wa)) |
0 | 2882 |
wa->releaseWidget(widget); |
2883 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2884 |
d->widgetItems.remove(e->action()); |
0 | 2885 |
} |
2886 |
||
2887 |
#ifdef Q_WS_MAC |
|
2888 |
if (d->mac_menu) { |
|
2889 |
if (e->type() == QEvent::ActionAdded) |
|
2890 |
d->mac_menu->addAction(e->action(), d->mac_menu->findAction(e->before()), d); |
|
2891 |
else if (e->type() == QEvent::ActionRemoved) |
|
2892 |
d->mac_menu->removeAction(e->action()); |
|
2893 |
else if (e->type() == QEvent::ActionChanged) |
|
2894 |
d->mac_menu->syncAction(e->action()); |
|
2895 |
} |
|
2896 |
#endif |
|
2897 |
||
2898 |
#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) |
|
2899 |
if (!d->wce_menu) |
|
2900 |
d->wce_menu = new QMenuPrivate::QWceMenuPrivate; |
|
2901 |
if (e->type() == QEvent::ActionAdded) |
|
2902 |
d->wce_menu->addAction(e->action(), d->wce_menu->findAction(e->before())); |
|
2903 |
else if (e->type() == QEvent::ActionRemoved) |
|
2904 |
d->wce_menu->removeAction(e->action()); |
|
2905 |
else if (e->type() == QEvent::ActionChanged) |
|
2906 |
d->wce_menu->syncAction(e->action()); |
|
2907 |
#endif |
|
2908 |
||
2909 |
#ifdef Q_WS_S60 |
|
2910 |
if (!d->symbian_menu) |
|
2911 |
d->symbian_menu = new QMenuPrivate::QSymbianMenuPrivate; |
|
2912 |
if (e->type() == QEvent::ActionAdded) |
|
2913 |
d->symbian_menu->addAction(e->action(), d->symbian_menu->findAction(e->before())); |
|
2914 |
else if (e->type() == QEvent::ActionRemoved) |
|
2915 |
d->symbian_menu->removeAction(e->action()); |
|
2916 |
else if (e->type() == QEvent::ActionChanged) |
|
2917 |
d->symbian_menu->syncAction(e->action()); |
|
2918 |
#endif |
|
2919 |
if (isVisible()) { |
|
2920 |
d->updateActionRects(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2921 |
resize(sizeHint()); |
0 | 2922 |
update(); |
2923 |
} |
|
2924 |
} |
|
2925 |
||
2926 |
/*! |
|
2927 |
\internal |
|
2928 |
*/ |
|
2929 |
void QMenu::internalSetSloppyAction() |
|
2930 |
{ |
|
2931 |
if (d_func()->sloppyAction) |
|
2932 |
d_func()->setCurrentAction(d_func()->sloppyAction, 0); |
|
2933 |
} |
|
2934 |
||
2935 |
/*! |
|
2936 |
\internal |
|
2937 |
*/ |
|
2938 |
void QMenu::internalDelayedPopup() |
|
2939 |
{ |
|
2940 |
Q_D(QMenu); |
|
2941 |
||
2942 |
//hide the current item |
|
2943 |
if (QMenu *menu = d->activeMenu) { |
|
2944 |
d->activeMenu = 0; |
|
2945 |
d->hideMenu(menu); |
|
2946 |
} |
|
2947 |
||
2948 |
if (!d->currentAction || !d->currentAction->isEnabled() || !d->currentAction->menu() || |
|
2949 |
!d->currentAction->menu()->isEnabled() || d->currentAction->menu()->isVisible()) |
|
2950 |
return; |
|
2951 |
||
2952 |
//setup |
|
2953 |
d->activeMenu = d->currentAction->menu(); |
|
2954 |
d->activeMenu->d_func()->causedPopup.widget = this; |
|
2955 |
d->activeMenu->d_func()->causedPopup.action = d->currentAction; |
|
2956 |
||
2957 |
int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, this); |
|
2958 |
const QRect actionRect(d->actionRect(d->currentAction)); |
|
2959 |
const QSize menuSize(d->activeMenu->sizeHint()); |
|
2960 |
const QPoint rightPos(mapToGlobal(QPoint(actionRect.right() + subMenuOffset + 1, actionRect.top()))); |
|
2961 |
const QPoint leftPos(mapToGlobal(QPoint(actionRect.left() - subMenuOffset - menuSize.width(), actionRect.top()))); |
|
2962 |
||
2963 |
QPoint pos(rightPos); |
|
2964 |
QMenu *caused = qobject_cast<QMenu*>(d->activeMenu->d_func()->causedPopup.widget); |
|
2965 |
||
2966 |
const QRect availGeometry(d->popupGeometry(caused)); |
|
2967 |
if (isRightToLeft()) { |
|
2968 |
pos = leftPos; |
|
2969 |
if ((caused && caused->x() < x()) || pos.x() < availGeometry.left()) { |
|
2970 |
if(rightPos.x() + menuSize.width() < availGeometry.right()) |
|
2971 |
pos = rightPos; |
|
2972 |
else |
|
2973 |
pos.rx() = availGeometry.left(); |
|
2974 |
} |
|
2975 |
} else { |
|
2976 |
if ((caused && caused->x() > x()) || pos.x() + menuSize.width() > availGeometry.right()) { |
|
2977 |
if(leftPos.x() < availGeometry.left()) |
|
2978 |
pos.rx() = availGeometry.right() - menuSize.width(); |
|
2979 |
else |
|
2980 |
pos = leftPos; |
|
2981 |
} |
|
2982 |
} |
|
2983 |
||
2984 |
//calc sloppy focus buffer |
|
2985 |
if (style()->styleHint(QStyle::SH_Menu_SloppySubMenus, 0, this)) { |
|
2986 |
QPoint cur = QCursor::pos(); |
|
2987 |
if (actionRect.contains(mapFromGlobal(cur))) { |
|
2988 |
QPoint pts[4]; |
|
2989 |
pts[0] = QPoint(cur.x(), cur.y() - 2); |
|
2990 |
pts[3] = QPoint(cur.x(), cur.y() + 2); |
|
2991 |
if (pos.x() >= cur.x()) { |
|
2992 |
pts[1] = QPoint(geometry().right(), pos.y()); |
|
2993 |
pts[2] = QPoint(geometry().right(), pos.y() + menuSize.height()); |
|
2994 |
} else { |
|
2995 |
pts[1] = QPoint(pos.x() + menuSize.width(), pos.y()); |
|
2996 |
pts[2] = QPoint(pos.x() + menuSize.width(), pos.y() + menuSize.height()); |
|
2997 |
} |
|
2998 |
QPolygon points(4); |
|
2999 |
for(int i = 0; i < 4; i++) |
|
3000 |
points.setPoint(i, mapFromGlobal(pts[i])); |
|
3001 |
d->sloppyRegion = QRegion(points); |
|
3002 |
} |
|
3003 |
} |
|
3004 |
||
3005 |
//do the popup |
|
3006 |
d->activeMenu->popup(pos); |
|
3007 |
} |
|
3008 |
||
3009 |
/*! |
|
3010 |
\fn void QMenu::addAction(QAction *action) |
|
3011 |
\overload |
|
3012 |
||
3013 |
Appends the action \a action to the menu's list of actions. |
|
3014 |
||
3015 |
\sa QMenuBar::addAction(), QWidget::addAction() |
|
3016 |
*/ |
|
3017 |
||
3018 |
/*! |
|
3019 |
\fn void QMenu::aboutToHide() |
|
3020 |
\since 4.2 |
|
3021 |
||
3022 |
This signal is emitted just before the menu is hidden from the user. |
|
3023 |
||
3024 |
\sa aboutToShow(), hide() |
|
3025 |
*/ |
|
3026 |
||
3027 |
/*! |
|
3028 |
\fn void QMenu::aboutToShow() |
|
3029 |
||
3030 |
This signal is emitted just before the menu is shown to the user. |
|
3031 |
||
3032 |
\sa aboutToHide(), show() |
|
3033 |
*/ |
|
3034 |
||
3035 |
/*! |
|
3036 |
\fn void QMenu::triggered(QAction *action) |
|
3037 |
||
3038 |
This signal is emitted when an action in this menu is triggered. |
|
3039 |
||
3040 |
\a action is the action that caused the signal to be emitted. |
|
3041 |
||
3042 |
Normally, you connect each menu action's \l{QAction::}{triggered()} signal |
|
3043 |
to its own custom slot, but sometimes you will want to connect several |
|
3044 |
actions to a single slot, for example, when you have a group of closely |
|
3045 |
related actions, such as "left justify", "center", "right justify". |
|
3046 |
||
3047 |
\note This signal is emitted for the main parent menu in a hierarchy. |
|
3048 |
Hence, only the parent menu needs to be connected to a slot; sub-menus need |
|
3049 |
not be connected. |
|
3050 |
||
3051 |
\sa hovered(), QAction::triggered() |
|
3052 |
*/ |
|
3053 |
||
3054 |
/*! |
|
3055 |
\fn void QMenu::hovered(QAction *action) |
|
3056 |
||
3057 |
This signal is emitted when a menu action is highlighted; \a action |
|
3058 |
is the action that caused the signal to be emitted. |
|
3059 |
||
3060 |
Often this is used to update status information. |
|
3061 |
||
3062 |
\sa triggered(), QAction::hovered() |
|
3063 |
*/ |
|
3064 |
||
3065 |
||
3066 |
/*!\internal |
|
3067 |
*/ |
|
3068 |
void QMenu::setNoReplayFor(QWidget *noReplayFor) |
|
3069 |
{ |
|
3070 |
#ifdef Q_WS_WIN |
|
3071 |
d_func()->noReplayFor = noReplayFor; |
|
3072 |
#else |
|
3073 |
Q_UNUSED(noReplayFor); |
|
3074 |
#endif |
|
3075 |
} |
|
3076 |
||
3077 |
/*! |
|
3078 |
\property QMenu::separatorsCollapsible |
|
3079 |
\since 4.2 |
|
3080 |
||
3081 |
\brief whether consecutive separators should be collapsed |
|
3082 |
||
3083 |
This property specifies whether consecutive separators in the menu |
|
3084 |
should be visually collapsed to a single one. Separators at the |
|
3085 |
beginning or the end of the menu are also hidden. |
|
3086 |
||
3087 |
By default, this property is true. |
|
3088 |
*/ |
|
3089 |
bool QMenu::separatorsCollapsible() const |
|
3090 |
{ |
|
3091 |
Q_D(const QMenu); |
|
3092 |
return d->collapsibleSeparators; |
|
3093 |
} |
|
3094 |
||
3095 |
void QMenu::setSeparatorsCollapsible(bool collapse) |
|
3096 |
{ |
|
3097 |
Q_D(QMenu); |
|
3098 |
if (d->collapsibleSeparators == collapse) |
|
3099 |
return; |
|
3100 |
||
3101 |
d->collapsibleSeparators = collapse; |
|
3102 |
d->itemsDirty = 1; |
|
3103 |
if (isVisible()) { |
|
3104 |
d->updateActionRects(); |
|
3105 |
update(); |
|
3106 |
} |
|
3107 |
#ifdef Q_WS_MAC |
|
3108 |
if (d->mac_menu) |
|
3109 |
d->syncSeparatorsCollapsible(collapse); |
|
3110 |
#endif |
|
3111 |
} |
|
3112 |
||
3113 |
#ifdef QT3_SUPPORT |
|
3114 |
||
3115 |
int QMenu::insertAny(const QIcon *icon, const QString *text, const QObject *receiver, const char *member, |
|
3116 |
const QKeySequence *shortcut, const QMenu *popup, int id, int index) |
|
3117 |
{ |
|
3118 |
QAction *act = popup ? popup->menuAction() : new QAction(this); |
|
3119 |
if (id != -1) |
|
3120 |
static_cast<QMenuItem*>(act)->setId(id); |
|
3121 |
if (icon) |
|
3122 |
act->setIcon(*icon); |
|
3123 |
if (text) |
|
3124 |
act->setText(*text); |
|
3125 |
if (shortcut) |
|
3126 |
act->setShortcut(*shortcut); |
|
3127 |
if (receiver && member) |
|
3128 |
QObject::connect(act, SIGNAL(activated(int)), receiver, member); |
|
3129 |
if (index == -1 || index >= actions().count()) |
|
3130 |
addAction(act); |
|
3131 |
else |
|
3132 |
insertAction(actions().value(index), act); |
|
3133 |
return findIdForAction(act); |
|
3134 |
} |
|
3135 |
||
3136 |
/*! |
|
3137 |
Use insertAction() or one of the addAction() overloads instead. |
|
3138 |
*/ |
|
3139 |
int QMenu::insertItem(QMenuItem *item, int id, int index) |
|
3140 |
{ |
|
3141 |
if (index == -1 || index >= actions().count()) |
|
3142 |
addAction(item); |
|
3143 |
else |
|
3144 |
insertAction(actions().value(index), item); |
|
3145 |
if (id > -1) |
|
3146 |
item->d_func()->id = id; |
|
3147 |
return findIdForAction(item); |
|
3148 |
} |
|
3149 |
||
3150 |
/*! |
|
3151 |
Use the insertSeparator() overload that takes a QAction * |
|
3152 |
parameter instead. |
|
3153 |
*/ |
|
3154 |
int QMenu::insertSeparator(int index) |
|
3155 |
{ |
|
3156 |
QAction *act = new QAction(this); |
|
3157 |
act->setSeparator(true); |
|
3158 |
if (index == -1 || index >= actions().count()) |
|
3159 |
addAction(act); |
|
3160 |
else |
|
3161 |
insertAction(actions().value(index), act); |
|
3162 |
return findIdForAction(act); |
|
3163 |
} |
|
3164 |
||
3165 |
QAction *QMenu::findActionForId(int id) const |
|
3166 |
{ |
|
3167 |
Q_D(const QMenu); |
|
3168 |
for (int i = 0; i < d->actions.size(); ++i) { |
|
3169 |
QAction *act = d->actions.at(i); |
|
3170 |
if (findIdForAction(act)== id) |
|
3171 |
return act; |
|
3172 |
} |
|
3173 |
return 0; |
|
3174 |
} |
|
3175 |
||
3176 |
/*! |
|
3177 |
Use QAction and actions() instead. |
|
3178 |
*/ |
|
3179 |
QMenuItem *QMenu::findPopup( QMenu *popup, int *index ) |
|
3180 |
{ |
|
3181 |
QList<QAction *> list = actions(); |
|
3182 |
for (int i = 0; i < list.size(); ++i) { |
|
3183 |
QAction *act = list.at(i); |
|
3184 |
if (act->menu() == popup) { |
|
3185 |
QMenuItem *item = static_cast<QMenuItem *>(act); |
|
3186 |
if (index) |
|
3187 |
*index = act->d_func()->id; |
|
3188 |
return item; |
|
3189 |
} |
|
3190 |
} |
|
3191 |
return 0; |
|
3192 |
} |
|
3193 |
||
3194 |
||
3195 |
/*! |
|
3196 |
Use QAction::setData() instead. |
|
3197 |
*/ |
|
3198 |
bool QMenu::setItemParameter(int id, int param) |
|
3199 |
{ |
|
3200 |
if (QAction *act = findActionForId(id)) { |
|
3201 |
act->d_func()->param = param; |
|
3202 |
return true; |
|
3203 |
} |
|
3204 |
return false; |
|
3205 |
} |
|
3206 |
||
3207 |
/*! |
|
3208 |
Use QAction::data() instead. |
|
3209 |
*/ |
|
3210 |
int QMenu::itemParameter(int id) const |
|
3211 |
{ |
|
3212 |
if (QAction *act = findActionForId(id)) |
|
3213 |
return act->d_func()->param; |
|
3214 |
return id; |
|
3215 |
} |
|
3216 |
||
3217 |
/*! |
|
3218 |
Use actions instead. |
|
3219 |
*/ |
|
3220 |
void QMenu::setId(int index, int id) |
|
3221 |
{ |
|
3222 |
if(QAction *act = actions().value(index)) |
|
3223 |
act->d_func()->id = id; |
|
3224 |
} |
|
3225 |
||
3226 |
/*! |
|
3227 |
Use style()->pixelMetric(QStyle::PM_MenuPanelWidth, this) instead. |
|
3228 |
*/ |
|
3229 |
int QMenu::frameWidth() const |
|
3230 |
{ |
|
3231 |
return style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this); |
|
3232 |
} |
|
3233 |
||
3234 |
int QMenu::findIdForAction(QAction *act) const |
|
3235 |
{ |
|
3236 |
if (!act) |
|
3237 |
return -1; |
|
3238 |
return act->d_func()->id; |
|
3239 |
} |
|
3240 |
#endif // QT3_SUPPORT |
|
3241 |
||
3242 |
/*! |
|
3243 |
\fn uint QMenu::count() const |
|
3244 |
||
3245 |
Use actions().count() instead. |
|
3246 |
*/ |
|
3247 |
||
3248 |
/*! |
|
3249 |
\fn int QMenu::insertItem(const QString &text, const QObject *receiver, const char* member, const QKeySequence& shortcut, int id, int index) |
|
3250 |
||
3251 |
Use insertAction() or one of the addAction() overloads instead. |
|
3252 |
*/ |
|
3253 |
||
3254 |
/*! |
|
3255 |
\fn int QMenu::insertItem(const QIcon& icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence& shortcut, int id, int index) |
|
3256 |
||
3257 |
Use insertAction() or one of the addAction() overloads instead. |
|
3258 |
*/ |
|
3259 |
||
3260 |
/*! |
|
3261 |
\fn int QMenu::insertItem(const QPixmap &pixmap, const QObject *receiver, const char* member, const QKeySequence& shortcut, int id, int index) |
|
3262 |
||
3263 |
Use insertAction() or one of the addAction() overloads instead. |
|
3264 |
*/ |
|
3265 |
||
3266 |
/*! |
|
3267 |
\fn int QMenu::insertItem(const QString &text, int id, int index) |
|
3268 |
||
3269 |
Use insertAction() or one of the addAction() overloads instead. |
|
3270 |
*/ |
|
3271 |
||
3272 |
/*! |
|
3273 |
\fn int QMenu::insertItem(const QIcon& icon, const QString &text, int id, int index) |
|
3274 |
||
3275 |
Use insertAction() or one of the addAction() overloads instead. |
|
3276 |
*/ |
|
3277 |
||
3278 |
/*! |
|
3279 |
\fn int QMenu::insertItem(const QString &text, QMenu *popup, int id, int index) |
|
3280 |
||
3281 |
Use insertMenu() or one of the addMenu() overloads instead. |
|
3282 |
*/ |
|
3283 |
||
3284 |
/*! |
|
3285 |
\fn int QMenu::insertItem(const QIcon& icon, const QString &text, QMenu *popup, int id, int index) |
|
3286 |
||
3287 |
Use insertMenu() or one of the addMenu() overloads instead. |
|
3288 |
*/ |
|
3289 |
||
3290 |
/*! |
|
3291 |
\fn int QMenu::insertItem(const QPixmap &pixmap, int id, int index) |
|
3292 |
||
3293 |
Use insertAction() or one of the addAction() overloads instead. |
|
3294 |
*/ |
|
3295 |
||
3296 |
/*! |
|
3297 |
\fn int QMenu::insertItem(const QPixmap &pixmap, QMenu *popup, int id, int index) |
|
3298 |
||
3299 |
Use insertMenu() or one of the addMenu() overloads instead. |
|
3300 |
*/ |
|
3301 |
||
3302 |
/*! |
|
3303 |
\fn void QMenu::removeItem(int id) |
|
3304 |
||
3305 |
Use removeAction() instead. |
|
3306 |
*/ |
|
3307 |
||
3308 |
/*! |
|
3309 |
\fn void QMenu::removeItemAt(int index) |
|
3310 |
||
3311 |
Use removeAction() instead. |
|
3312 |
*/ |
|
3313 |
||
3314 |
/*! |
|
3315 |
\fn QKeySequence QMenu::accel(int id) const |
|
3316 |
||
3317 |
Use shortcut() on the relevant QAction instead. |
|
3318 |
*/ |
|
3319 |
||
3320 |
/*! |
|
3321 |
\fn void QMenu::setAccel(const QKeySequence& key, int id) |
|
3322 |
||
3323 |
Use setShortcut() on the relevant QAction instead. |
|
3324 |
*/ |
|
3325 |
||
3326 |
/*! |
|
3327 |
\fn QIcon QMenu::iconSet(int id) const |
|
3328 |
||
3329 |
Use icon() on the relevant QAction instead. |
|
3330 |
*/ |
|
3331 |
||
3332 |
/*! |
|
3333 |
\fn QString QMenu::text(int id) const |
|
3334 |
||
3335 |
Use text() on the relevant QAction instead. |
|
3336 |
*/ |
|
3337 |
||
3338 |
/*! |
|
3339 |
\fn QPixmap QMenu::pixmap(int id) const |
|
3340 |
||
3341 |
Use QPixmap(icon()) on the relevant QAction instead. |
|
3342 |
*/ |
|
3343 |
||
3344 |
/*! |
|
3345 |
\fn void QMenu::setWhatsThis(int id, const QString &w) |
|
3346 |
||
3347 |
Use setWhatsThis() on the relevant QAction instead. |
|
3348 |
*/ |
|
3349 |
||
3350 |
/*! |
|
3351 |
\fn QString QMenu::whatsThis(int id) const |
|
3352 |
||
3353 |
Use whatsThis() on the relevant QAction instead. |
|
3354 |
*/ |
|
3355 |
||
3356 |
/*! |
|
3357 |
\fn void QMenu::changeItem(int id, const QString &text) |
|
3358 |
||
3359 |
Use setText() on the relevant QAction instead. |
|
3360 |
*/ |
|
3361 |
||
3362 |
/*! |
|
3363 |
\fn void QMenu::changeItem(int id, const QPixmap &pixmap) |
|
3364 |
||
3365 |
Use setText() on the relevant QAction instead. |
|
3366 |
*/ |
|
3367 |
||
3368 |
/*! |
|
3369 |
\fn void QMenu::changeItem(int id, const QIcon &icon, const QString &text) |
|
3370 |
||
3371 |
Use setIcon() and setText() on the relevant QAction instead. |
|
3372 |
*/ |
|
3373 |
||
3374 |
/*! |
|
3375 |
\fn bool QMenu::isItemActive(int id) const |
|
3376 |
||
3377 |
Use activeAction() instead. |
|
3378 |
*/ |
|
3379 |
||
3380 |
/*! |
|
3381 |
\fn bool QMenu::isItemEnabled(int id) const |
|
3382 |
||
3383 |
Use isEnabled() on the relevant QAction instead. |
|
3384 |
*/ |
|
3385 |
||
3386 |
/*! |
|
3387 |
\fn void QMenu::setItemEnabled(int id, bool enable) |
|
3388 |
||
3389 |
Use setEnabled() on the relevant QAction instead. |
|
3390 |
*/ |
|
3391 |
||
3392 |
/*! |
|
3393 |
\fn bool QMenu::isItemChecked(int id) const |
|
3394 |
||
3395 |
Use isChecked() on the relevant QAction instead. |
|
3396 |
*/ |
|
3397 |
||
3398 |
/*! |
|
3399 |
\fn void QMenu::setItemChecked(int id, bool check) |
|
3400 |
||
3401 |
Use setChecked() on the relevant QAction instead. |
|
3402 |
*/ |
|
3403 |
||
3404 |
/*! |
|
3405 |
\fn bool QMenu::isItemVisible(int id) const |
|
3406 |
||
3407 |
Use isVisible() on the relevant QAction instead. |
|
3408 |
*/ |
|
3409 |
||
3410 |
/*! |
|
3411 |
\fn void QMenu::setItemVisible(int id, bool visible) |
|
3412 |
||
3413 |
Use setVisible() on the relevant QAction instead. |
|
3414 |
*/ |
|
3415 |
||
3416 |
/*! |
|
3417 |
\fn QRect QMenu::itemGeometry(int index) |
|
3418 |
||
3419 |
Use actionGeometry() on the relevant QAction instead. |
|
3420 |
*/ |
|
3421 |
||
3422 |
/*! |
|
3423 |
\fn QFont QMenu::itemFont(int id) const |
|
3424 |
||
3425 |
Use font() on the relevant QAction instead. |
|
3426 |
*/ |
|
3427 |
||
3428 |
/*! |
|
3429 |
\fn void QMenu::setItemFont(int id, const QFont &font) |
|
3430 |
||
3431 |
Use setFont() on the relevant QAction instead. |
|
3432 |
*/ |
|
3433 |
||
3434 |
/*! |
|
3435 |
\fn int QMenu::indexOf(int id) const |
|
3436 |
||
3437 |
Use actions().indexOf(action) on the relevant QAction instead. |
|
3438 |
*/ |
|
3439 |
||
3440 |
/*! |
|
3441 |
\fn int QMenu::idAt(int index) const |
|
3442 |
||
3443 |
Use actions instead. |
|
3444 |
*/ |
|
3445 |
||
3446 |
/*! |
|
3447 |
\fn void QMenu::activateItemAt(int index) |
|
3448 |
||
3449 |
Use activate() on the relevant QAction instead. |
|
3450 |
*/ |
|
3451 |
||
3452 |
/*! |
|
3453 |
\fn bool QMenu::connectItem(int id, const QObject *receiver, const char* member) |
|
3454 |
||
3455 |
Use connect() on the relevant QAction instead. |
|
3456 |
*/ |
|
3457 |
||
3458 |
/*! |
|
3459 |
\fn bool QMenu::disconnectItem(int id,const QObject *receiver, const char* member) |
|
3460 |
Use disconnect() on the relevant QAction instead. |
|
3461 |
||
3462 |
*/ |
|
3463 |
||
3464 |
/*! |
|
3465 |
\fn QMenuItem *QMenu::findItem(int id) const |
|
3466 |
||
3467 |
Use actions instead. |
|
3468 |
*/ |
|
3469 |
||
3470 |
/*! |
|
3471 |
\fn void QMenu::popup(const QPoint & pos, int indexAtPoint) |
|
3472 |
||
3473 |
Use popup() on the relevant QAction instead. |
|
3474 |
*/ |
|
3475 |
||
3476 |
/*! |
|
3477 |
\fn int QMenu::insertTearOffHandle(int a, int b) |
|
3478 |
||
3479 |
Use setTearOffEnabled() instead. |
|
3480 |
*/ |
|
3481 |
||
3482 |
/*! |
|
3483 |
\fn int QMenu::itemAtPos(const QPoint &p, bool ignoreSeparator) |
|
3484 |
||
3485 |
Use actions instead. |
|
3486 |
*/ |
|
3487 |
||
3488 |
/*! |
|
3489 |
\fn int QMenu::columns() const |
|
3490 |
||
3491 |
Use columnCount() instead. |
|
3492 |
*/ |
|
3493 |
||
3494 |
/*! |
|
3495 |
\fn int QMenu::itemHeight(int index) |
|
3496 |
||
3497 |
Use actionGeometry(actions().value(index)).height() instead. |
|
3498 |
*/ |
|
3499 |
||
3500 |
/*! |
|
3501 |
\fn int QMenu::itemHeight(QMenuItem *mi) |
|
3502 |
||
3503 |
Use actionGeometry() instead. |
|
3504 |
*/ |
|
3505 |
||
3506 |
/*! |
|
3507 |
\fn void QMenu::activated(int itemId); |
|
3508 |
||
3509 |
Use triggered() instead. |
|
3510 |
*/ |
|
3511 |
||
3512 |
/*! |
|
3513 |
\fn void QMenu::highlighted(int itemId); |
|
3514 |
||
3515 |
Use hovered() instead. |
|
3516 |
*/ |
|
3517 |
||
3518 |
/*! |
|
3519 |
\fn void QMenu::setCheckable(bool checkable) |
|
3520 |
||
3521 |
Not necessary anymore. The \a checkable parameter is ignored. |
|
3522 |
*/ |
|
3523 |
||
3524 |
/*! |
|
3525 |
\fn bool QMenu::isCheckable() const |
|
3526 |
||
3527 |
Not necessary anymore. Always returns true. |
|
3528 |
*/ |
|
3529 |
||
3530 |
/*! |
|
3531 |
\fn void QMenu::setActiveItem(int id) |
|
3532 |
||
3533 |
Use setActiveAction() instead. |
|
3534 |
*/ |
|
3535 |
||
3536 |
QT_END_NAMESPACE |
|
3537 |
||
3538 |
// for private slots |
|
3539 |
#include "moc_qmenu.cpp" |
|
3540 |
#include "qmenu.moc" |
|
3541 |
||
3542 |
#endif // QT_NO_MENU |