Fixed build breaks that result after disabling "contextmenu" feature

Change-Id: I261f927ee720e0c65abd18417e1ac48dbee820df
Reviewed-by: Jake Petroules <jake.petroules@theqtcompany.com>
This commit is contained in:
Shrikant Dhumal 2015-09-03 20:07:27 -07:00
parent 933e3e886f
commit 924d4aefd5
20 changed files with 59 additions and 12 deletions

View File

@ -468,11 +468,13 @@ void ColorSwatch::tabInto(QAction *action)
mainWindow->tabifyDockWidget(target, this); mainWindow->tabifyDockWidget(target, this);
} }
#ifndef QT_NO_CONTEXTMENU
void ColorSwatch::contextMenuEvent(QContextMenuEvent *event) void ColorSwatch::contextMenuEvent(QContextMenuEvent *event)
{ {
event->accept(); event->accept();
menu->exec(event->globalPos()); menu->exec(event->globalPos());
} }
#endif // QT_NO_CONTEXTMENU
void ColorSwatch::resizeEvent(QResizeEvent *e) void ColorSwatch::resizeEvent(QResizeEvent *e)
{ {

View File

@ -51,7 +51,9 @@ public:
QMenu *colorSwatchMenu() const { return menu; } QMenu *colorSwatchMenu() const { return menu; }
protected: protected:
#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
#endif // QT_NO_CONTEXTMENU
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
private slots: private slots:

View File

@ -83,6 +83,7 @@ MainWindow::MainWindow()
//! [2] //! [2]
//! [3] //! [3]
#ifndef QT_NO_CONTEXTMENU
void MainWindow::contextMenuEvent(QContextMenuEvent *event) void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{ {
QMenu menu(this); QMenu menu(this);
@ -91,6 +92,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
menu.addAction(pasteAct); menu.addAction(pasteAct);
menu.exec(event->globalPos()); menu.exec(event->globalPos());
} }
#endif // QT_NO_CONTEXTMENU
//! [3] //! [3]
void MainWindow::newFile() void MainWindow::newFile()

View File

@ -59,7 +59,9 @@ public:
MainWindow(); MainWindow();
protected: protected:
#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
#endif // QT_NO_CONTEXTMENU
//! [0] //! [0]
//! [1] //! [1]

View File

@ -3940,9 +3940,11 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
QtDebugUtils::formatQEnum(dbg, static_cast<const QApplicationStateChangeEvent *>(e)->applicationState()); QtDebugUtils::formatQEnum(dbg, static_cast<const QApplicationStateChangeEvent *>(e)->applicationState());
dbg << ')'; dbg << ')';
break; break;
# ifndef QT_NO_CONTEXTMENU
case QEvent::ContextMenu: case QEvent::ContextMenu:
dbg << "QContextMenuEvent(" << static_cast<const QContextMenuEvent *>(e)->pos() << ')'; dbg << "QContextMenuEvent(" << static_cast<const QContextMenuEvent *>(e)->pos() << ')';
break; break;
# endif // !QT_NO_CONTEXTMENU
# ifndef QT_NO_TABLETEVENT # ifndef QT_NO_TABLETEVENT
case QEvent::TabletEnterProximity: case QEvent::TabletEnterProximity:
case QEvent::TabletLeaveProximity: case QEvent::TabletLeaveProximity:

View File

@ -366,6 +366,7 @@ void QIBusPlatformInputContext::filterEventFinished(QDBusPendingCallWatcher *cal
bool retval = reply.value(); bool retval = reply.value();
qCDebug(qtQpaInputMethods) << "filterEventFinished return" << code << sym << state << retval; qCDebug(qtQpaInputMethods) << "filterEventFinished return" << code << sym << state << retval;
if (!retval) { if (!retval) {
#ifndef QT_NO_CONTEXTMENU
QWindow *window = dynamic_cast<QWindow *>(input); QWindow *window = dynamic_cast<QWindow *>(input);
if (type == QEvent::KeyPress && qtcode == Qt::Key_Menu if (type == QEvent::KeyPress && qtcode == Qt::Key_Menu
&& window != NULL) { && window != NULL) {
@ -374,6 +375,7 @@ void QIBusPlatformInputContext::filterEventFinished(QDBusPendingCallWatcher *cal
QWindowSystemInterface::handleContextMenuEvent(window, false, pos, QWindowSystemInterface::handleContextMenuEvent(window, false, pos,
globalPos, modifiers); globalPos, modifiers);
} }
#endif // QT_NO_CONTEXTMENU
QKeyEvent event(type, qtcode, modifiers, code, sym, QKeyEvent event(type, qtcode, modifiers, code, sym,
state, string, isAutoRepeat, count); state, string, isAutoRepeat, count);
event.setTimestamp(time); event.setTimestamp(time);

View File

@ -1511,11 +1511,13 @@ void QXcbKeyboard::handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type,
QWindow *window = targetWindow->window(); QWindow *window = targetWindow->window();
if (!filtered) { if (!filtered) {
#ifndef QT_NO_CONTEXTMENU
if (type == QEvent::KeyPress && qtcode == Qt::Key_Menu) { if (type == QEvent::KeyPress && qtcode == Qt::Key_Menu) {
const QPoint globalPos = window->screen()->handle()->cursor()->pos(); const QPoint globalPos = window->screen()->handle()->cursor()->pos();
const QPoint pos = window->mapFromGlobal(globalPos); const QPoint pos = window->mapFromGlobal(globalPos);
QWindowSystemInterface::handleContextMenuEvent(window, false, pos, globalPos, modifiers); QWindowSystemInterface::handleContextMenuEvent(window, false, pos, globalPos, modifiers);
} }
#endif // QT_NO_CONTEXTMENU
QWindowSystemInterface::handleExtendedKeyEvent(window, time, type, qtcode, modifiers, QWindowSystemInterface::handleExtendedKeyEvent(window, time, type, qtcode, modifiers,
code, sym, state, string, isAutoRepeat); code, sym, state, string, isAutoRepeat);
} }

View File

@ -89,16 +89,14 @@ public:
{ {
public: public:
TextEdit(QWidget *parent=0) : QTextEdit(parent) { } TextEdit(QWidget *parent=0) : QTextEdit(parent) { }
#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(QContextMenuEvent * e) Q_DECL_OVERRIDE void contextMenuEvent(QContextMenuEvent * e) Q_DECL_OVERRIDE
{ {
#ifndef QT_NO_CONTEXTMENU
QMenu *menu = createStandardContextMenu(); QMenu *menu = createStandardContextMenu();
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->popup(e->globalPos()); menu->popup(e->globalPos());
#else
Q_UNUSED(e);
#endif
} }
#endif // QT_NO_CONTEXTMENU
}; };
QMessageBoxDetailsText(QWidget *parent=0) QMessageBoxDetailsText(QWidget *parent=0)

View File

@ -283,7 +283,7 @@ bool QWidgetWindow::event(QEvent *event)
case QEvent::ContextMenu: case QEvent::ContextMenu:
handleContextMenuEvent(static_cast<QContextMenuEvent *>(event)); handleContextMenuEvent(static_cast<QContextMenuEvent *>(event));
return true; return true;
#endif #endif // QT_NO_CONTEXTMENU
// Handing show events to widgets (see below) here would cause them to be triggered twice // Handing show events to widgets (see below) here would cause them to be triggered twice
case QEvent::Show: case QEvent::Show:
@ -510,8 +510,12 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
popupEvent = popupChild; popupEvent = popupChild;
QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
QApplication::sendSpontaneousEvent(popupEvent, &e); QApplication::sendSpontaneousEvent(popupEvent, &e);
#endif
} }
#else
Q_UNUSED(contextMenuTrigger)
Q_UNUSED(oldOpenPopupCount)
}
#endif
if (releaseAfter) { if (releaseAfter) {
qt_button_down = 0; qt_button_down = 0;

View File

@ -170,7 +170,9 @@ void QSystemTrayIconSys::mousePressEvent(QMouseEvent *ev)
#ifndef QT_NO_CONTEXTMENU #ifndef QT_NO_CONTEXTMENU
if (ev->button() == Qt::RightButton && q->contextMenu()) if (ev->button() == Qt::RightButton && q->contextMenu())
q->contextMenu()->popup(globalPos); q->contextMenu()->popup(globalPos);
#endif #else
Q_UNUSED(globalPos)
#endif // QT_NO_CONTEXTMENU
if (QBalloonTip::isBalloonVisible()) { if (QBalloonTip::isBalloonVisible()) {
emit q->messageClicked(); emit q->messageClicked();

View File

@ -229,7 +229,9 @@ protected:
#ifndef QT_NO_WHEELEVENT #ifndef QT_NO_WHEELEVENT
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
#endif #endif
#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE; void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE;
#endif // QT_NO_CONTEXTMENU
void inputMethodEvent(QInputMethodEvent *) Q_DECL_OVERRIDE; void inputMethodEvent(QInputMethodEvent *) Q_DECL_OVERRIDE;
void initStyleOption(QStyleOptionComboBox *option) const; void initStyleOption(QStyleOptionComboBox *option) const;

View File

@ -882,13 +882,11 @@ void QLabel::mouseReleaseEvent(QMouseEvent *ev)
d->sendControlEvent(ev); d->sendControlEvent(ev);
} }
#ifndef QT_NO_CONTEXTMENU
/*!\reimp /*!\reimp
*/ */
void QLabel::contextMenuEvent(QContextMenuEvent *ev) void QLabel::contextMenuEvent(QContextMenuEvent *ev)
{ {
#ifdef QT_NO_CONTEXTMENU
Q_UNUSED(ev);
#else
Q_D(QLabel); Q_D(QLabel);
if (!d->isTextLabel) { if (!d->isTextLabel) {
ev->ignore(); ev->ignore();
@ -902,8 +900,8 @@ void QLabel::contextMenuEvent(QContextMenuEvent *ev)
ev->accept(); ev->accept();
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->popup(ev->globalPos()); menu->popup(ev->globalPos());
#endif
} }
#endif // QT_NO_CONTEXTMENU
/*! /*!
\reimp \reimp

View File

@ -132,7 +132,9 @@ protected:
void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(QContextMenuEvent *ev) Q_DECL_OVERRIDE; void contextMenuEvent(QContextMenuEvent *ev) Q_DECL_OVERRIDE;
#endif // QT_NO_CONTEXTMENU
void focusInEvent(QFocusEvent *ev) Q_DECL_OVERRIDE; void focusInEvent(QFocusEvent *ev) Q_DECL_OVERRIDE;
void focusOutEvent(QFocusEvent *ev) Q_DECL_OVERRIDE; void focusOutEvent(QFocusEvent *ev) Q_DECL_OVERRIDE;
bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE;

View File

@ -1060,6 +1060,8 @@ bool QTextEdit::event(QEvent *e)
|| e->type() == QEvent::ToolTip) { || e->type() == QEvent::ToolTip) {
d->sendControlEvent(e); d->sendControlEvent(e);
} }
#else
Q_UNUSED(d)
#endif // QT_NO_CONTEXTMENU #endif // QT_NO_CONTEXTMENU
#ifdef QT_KEYPAD_NAVIGATION #ifdef QT_KEYPAD_NAVIGATION
if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) { if (e->type() == QEvent::EnterEditFocus || e->type() == QEvent::LeaveEditFocus) {

View File

@ -385,7 +385,9 @@ private slots:
void itemContainsChildrenInShape2(); void itemContainsChildrenInShape2();
void ancestorFlags(); void ancestorFlags();
void untransformable(); void untransformable();
#ifndef QT_NO_CONTEXTMENU
void contextMenuEventPropagation(); void contextMenuEventPropagation();
#endif // QT_NO_CONTEXTMENU
void itemIsMovable(); void itemIsMovable();
void boundingRegion_data(); void boundingRegion_data();
void boundingRegion(); void boundingRegion();
@ -5193,6 +5195,7 @@ public:
} }
protected: protected:
#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(QGraphicsSceneContextMenuEvent *) void contextMenuEvent(QGraphicsSceneContextMenuEvent *)
{ {
if (harakiri == 3) { if (harakiri == 3) {
@ -5200,6 +5203,7 @@ protected:
delete this; delete this;
} }
} }
#endif // QT_NO_CONTEXTMENU
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{ {
@ -5378,11 +5382,13 @@ void tst_QGraphicsItem::deleteItemInEventHandlers()
if (!item->dead) if (!item->dead)
scene.advance(); scene.advance();
#ifndef QT_NO_CONTEXTMENU
if (!item->dead) { if (!item->dead) {
QContextMenuEvent event(QContextMenuEvent::Other, QContextMenuEvent event(QContextMenuEvent::Other,
view.mapFromScene(item->scenePos())); view.mapFromScene(item->scenePos()));
QCoreApplication::sendEvent(view.viewport(), &event); QCoreApplication::sendEvent(view.viewport(), &event);
} }
#endif // QT_NO_CONTEXTMENU
if (!item->dead) if (!item->dead)
QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos())); QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos()));
if (!item->dead) if (!item->dead)
@ -6276,6 +6282,7 @@ void tst_QGraphicsItem::untransformable()
} }
} }
#ifndef QT_NO_CONTEXTMENU
class ContextMenuItem : public QGraphicsRectItem class ContextMenuItem : public QGraphicsRectItem
{ {
public: public:
@ -6339,6 +6346,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation()
QCOMPARE(bottomItem->gotEvent, false); QCOMPARE(bottomItem->gotEvent, false);
QCOMPARE(topItem->eventWasAccepted, true); QCOMPARE(topItem->eventWasAccepted, true);
} }
#endif // QT_NO_CONTEXTMENU
void tst_QGraphicsItem::itemIsMovable() void tst_QGraphicsItem::itemIsMovable()
{ {

View File

@ -162,7 +162,9 @@ private slots:
void fontPropagation(); void fontPropagation();
void dontCrashWhenDie(); void dontCrashWhenDie();
void createProxyForChildWidget(); void createProxyForChildWidget();
#ifndef QT_NO_CONTEXTMENU
void actionsContextMenu(); void actionsContextMenu();
#endif // QT_NO_CONTEXTMENU
void actionsContextMenu_data(); void actionsContextMenu_data();
void deleteProxyForChildWidget(); void deleteProxyForChildWidget();
void bypassGraphicsProxyWidget_data(); void bypassGraphicsProxyWidget_data();
@ -3071,6 +3073,7 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget()
delete boxProxy; delete boxProxy;
} }
#ifndef QT_NO_CONTEXTMENU
class ContextMenuWidget : public QLabel class ContextMenuWidget : public QLabel
{ {
Q_OBJECT Q_OBJECT
@ -3119,6 +3122,7 @@ private:
bool m_embeddedPopupSet; bool m_embeddedPopupSet;
QTimer *m_timer; QTimer *m_timer;
}; };
#endif // QT_NO_CONTEXTMENU
void tst_QGraphicsProxyWidget::actionsContextMenu_data() void tst_QGraphicsProxyWidget::actionsContextMenu_data()
{ {
@ -3131,6 +3135,7 @@ void tst_QGraphicsProxyWidget::actionsContextMenu_data()
QTest::newRow("with actionsContextMenu without focus") << true << false; QTest::newRow("with actionsContextMenu without focus") << true << false;
} }
#ifndef QT_NO_CONTEXTMENU
void tst_QGraphicsProxyWidget::actionsContextMenu() void tst_QGraphicsProxyWidget::actionsContextMenu()
{ {
QFETCH(bool, hasFocus); QFETCH(bool, hasFocus);
@ -3185,7 +3190,7 @@ void tst_QGraphicsProxyWidget::actionsContextMenu()
} }
} }
#endif // QT_NO_CONTEXTMENU
void tst_QGraphicsProxyWidget::deleteProxyForChildWidget() void tst_QGraphicsProxyWidget::deleteProxyForChildWidget()
{ {

View File

@ -227,8 +227,10 @@ private slots:
void render_data(); void render_data();
void render(); void render();
void renderItemsWithNegativeWidthOrHeight(); void renderItemsWithNegativeWidthOrHeight();
#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(); void contextMenuEvent();
void contextMenuEvent_ItemIgnoresTransformations(); void contextMenuEvent_ItemIgnoresTransformations();
#endif
void update(); void update();
void update2(); void update2();
void views(); void views();
@ -2712,6 +2714,7 @@ void tst_QGraphicsScene::renderItemsWithNegativeWidthOrHeight()
QCOMPARE(actual, expected); QCOMPARE(actual, expected);
} }
#ifndef QT_NO_CONTEXTMENU
void tst_QGraphicsScene::contextMenuEvent() void tst_QGraphicsScene::contextMenuEvent()
{ {
QGraphicsScene scene; QGraphicsScene scene;
@ -2794,6 +2797,7 @@ void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations()
QVERIFY(!event.isAccepted()); QVERIFY(!event.isAccepted());
} }
} }
#endif // QT_NO_CONTEXTMENU
void tst_QGraphicsScene::update() void tst_QGraphicsScene::update()
{ {

View File

@ -469,10 +469,12 @@ void tst_QGraphicsView::interactive()
QCOMPARE(item->events.size(), i * 5 + 5); QCOMPARE(item->events.size(), i * 5 + 5);
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GraphicsSceneMouseRelease); QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GraphicsSceneMouseRelease);
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::UngrabMouse); QCOMPARE(item->events.at(item->events.size() - 1), QEvent::UngrabMouse);
#ifndef QT_NO_CONTEXTMENU
QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint)); QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint));
QApplication::sendEvent(view.viewport(), &contextEvent); QApplication::sendEvent(view.viewport(), &contextEvent);
QCOMPARE(item->events.size(), i * 5 + 6); QCOMPARE(item->events.size(), i * 5 + 6);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu); QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu);
#endif // QT_NO_CONTEXTMENU
} }
view.setInteractive(false); view.setInteractive(false);
@ -484,10 +486,12 @@ void tst_QGraphicsView::interactive()
sendMouseRelease(view.viewport(), itemPoint); sendMouseRelease(view.viewport(), itemPoint);
QCOMPARE(item->events.size(), 501); QCOMPARE(item->events.size(), 501);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu); QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu);
#ifndef QT_NO_CONTEXTMENU
QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint)); QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint));
QApplication::sendEvent(view.viewport(), &contextEvent); QApplication::sendEvent(view.viewport(), &contextEvent);
QCOMPARE(item->events.size(), 501); QCOMPARE(item->events.size(), 501);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu); QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu);
#endif // QT_NO_CONTEXTMENU
} }
} }

View File

@ -1471,12 +1471,14 @@ void tst_QStyleSheetStyle::embeddedFonts()
QCOMPARE(spin.font().pixelSize(), 32); QCOMPARE(spin.font().pixelSize(), 32);
QCOMPARE(embedded->font().pixelSize(), 32); QCOMPARE(embedded->font().pixelSize(), 32);
#ifndef QT_NO_CONTEXTMENU
QMenu *menu = embedded->createStandardContextMenu(); QMenu *menu = embedded->createStandardContextMenu();
menu->show(); menu->show();
QTest::qWait(20); QTest::qWait(20);
QVERIFY(menu); QVERIFY(menu);
QVERIFY(menu->font().pixelSize() != 32); QVERIFY(menu->font().pixelSize() != 32);
QCOMPARE(menu->font().pixelSize(), qApp->font(menu).pixelSize()); QCOMPARE(menu->font().pixelSize(), qApp->font(menu).pixelSize());
#endif // QT_NO_CONTEXTMENU
//task 242556 //task 242556
QComboBox box; QComboBox box;

View File

@ -2243,6 +2243,7 @@ void tst_QLineEdit::deleteSelectedText()
edit.setText(text); edit.setText(text);
edit.selectAll(); edit.selectAll();
#ifndef QT_NO_CONTEXTMENU
QMenu *menu = edit.createStandardContextMenu(); QMenu *menu = edit.createStandardContextMenu();
for (int i = 0; i < menu->actions().count(); ++i) { for (int i = 0; i < menu->actions().count(); ++i) {
QAction *current = menu->actions().at(i); QAction *current = menu->actions().at(i);
@ -2251,6 +2252,7 @@ void tst_QLineEdit::deleteSelectedText()
QVERIFY(edit.text().isEmpty()); QVERIFY(edit.text().isEmpty());
} }
} }
#endif // QT_NO_CONTEXTMENU
} }