本文整理汇总了C++中QWidget::childAt方法的典型用法代码示例。如果您正苦于以下问题:C++ QWidget::childAt方法的具体用法?C++ QWidget::childAt怎么用?C++ QWidget::childAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWidget
的用法示例。
在下文中一共展示了QWidget::childAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getWidgetAt
QWidget* QGraphicsViewAdapter::getWidgetAt(const QPoint& pos)
{
QWidget* childAt = _graphicsView->childAt(pos);
if(childAt)
{
return childAt;
}
QGraphicsItem* item = _graphicsView->itemAt(pos);
if(item && item->contains(item->mapFromScene(pos)))
{
QGraphicsProxyWidget* p = dynamic_cast<QGraphicsProxyWidget*>(item);
if(p)
{
childAt = p->widget();
QWidget* c;
while( (c = childAt->childAt(childAt->mapFromGlobal(pos)))!=0 )
{
childAt = c;
}
return childAt;
}
}
return NULL;
}
示例2: handleWheelEvent
void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
{
if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
return;
QWidget *rootWidget = m_widget;
QPoint pos = event->pos();
// Use proper popup window for wheel event. Some QPA sends the wheel
// event to the root menu, so redirect it to the proper popup window.
QWidget *activePopupWidget = QApplication::activePopupWidget();
if (activePopupWidget && activePopupWidget != m_widget) {
rootWidget = activePopupWidget;
pos = rootWidget->mapFromGlobal(event->globalPos());
}
// which child should have it?
QWidget *widget = rootWidget->childAt(pos);
if (!widget)
widget = rootWidget;
QPoint mapped = widget->mapFrom(rootWidget, pos);
QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source());
QGuiApplication::sendSpontaneousEvent(widget, &translated);
}
示例3: QMouseEvent
bool
BioWidget::sendMouseEvent( QMouseEvent* event )
{
QWidget* w = m_widgetTextObject->widgetAtPoint( event->pos());
if ( !w )
return false;
QRectF wRect = m_widgetTextObject->widgetRect( w );
QPoint pos = event->pos() - wRect.toRect().topLeft();
QWidget* childWidget = w->childAt( event->pos());
if( !childWidget )
childWidget = w;
else
pos = childWidget->mapTo( w, pos );
QMouseEvent* widgetMouseEvent = new QMouseEvent( event->type(), pos, event->button(), event->buttons(), event->modifiers());
QCoreApplication::postEvent( childWidget, widgetMouseEvent );
event->accept();
return true;
}
示例4: viewport
bool
BioWidget::eventFilter( QObject* o, QEvent* e )
{
QWidget* w = qobject_cast<QWidget*>( o );
if ( viewport() == w )
{
if ( QEvent::MouseMove != e->type() )
return false;
QMouseEvent* event = static_cast<QMouseEvent*>(e);
//respect child widget cursor
QWidget* w = m_widgetTextObject->widgetAtPoint(event->pos() );
if ( w != m_currentHoverWidget )
{
m_currentHoverWidget = w;
if( 0 == w )
viewport()->unsetCursor();
else
{
QWidget* c = w->childAt(event->pos());
c = c ? c : w;
viewport()->setCursor( c->cursor());
}
}
return false;
}
return false;
}
示例5:
QWidget *QWidgetProto::childAt(const QPoint &p) const
{
QWidget *item = qscriptvalue_cast<QWidget*>(thisObject());
if (item)
return item->childAt(p);
return 0;
}
示例6: FindControl
QWidget* QtWidgetsTweakletImpl::FindControl(const QList<Shell::Pointer>& shells, const QPoint& location)
{
for (QList<Shell::Pointer>::const_iterator iter = shells.begin();
iter != shells.end(); ++iter)
{
QWidget* shellWidget = static_cast<QWidget*>((*iter)->GetControl());
QWidget* control = shellWidget->childAt(location.x(), location.y());
if (control) return control;
}
return nullptr;
}
示例7: mousePressEvent
bool WindowManager::mousePressEvent(QObject *object, QEvent *event)
{
// cast event and check buttons/modifiers
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (!(Qt::NoModifier==mouseEvent->modifiers() && Qt::LeftButton==mouseEvent->button())) {
return false;
}
// check lock
if (isLocked()) {
return false;
} else {
setLocked(true);
}
// cast to widget
QWidget *widget = static_cast<QWidget*>(object);
// check if widget can be dragged from current position
if (isBlackListed(widget) || !canDrag(widget)) {
return false;
}
// retrieve widget's child at event position
QPoint position(mouseEvent->pos());
QWidget *child = widget->childAt(position);
if (!canDrag(widget, child, position)) {
return false;
}
// save target and drag point
_target = widget;
_dragPoint = position;
_globalDragPoint = mouseEvent->globalPos();
_dragAboutToStart = true;
// send a move event to the current child with same position
// if received, it is caught to actually start the drag
QPoint localPoint(_dragPoint);
if (child) {
localPoint = child->mapFrom(widget, localPoint);
} else {
child = widget;
}
QMouseEvent localMouseEvent(QEvent::MouseMove, localPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
qApp->sendEvent(child, &localMouseEvent);
// never eat event
return false;
}
示例8: mousePressEvent
void UiManager::mousePressEvent(QMouseEvent *event)
{
QWidget *pressedWidget = NULL;
// get the clicked item through the view (respects view and item transformations)
QGraphicsItem* itemAt = mWidgetView->itemAt(event->pos());
if ((itemAt) && (itemAt->isWidget()))
{
QGraphicsProxyWidget *proxyWidget = qgraphicsitem_cast<QGraphicsProxyWidget *>(itemAt);
if (proxyWidget)
{
QWidget *embeddedWidget = proxyWidget->widget();
// if the widget has children, use them, otherwise use the widget directly
if (embeddedWidget->children().size() > 0)
{
QPoint widgetPoint = proxyWidget->mapFromScene(mWidgetView->mapToScene(event->pos())).toPoint();
pressedWidget = embeddedWidget->childAt(widgetPoint);
}
else
{
pressedWidget = embeddedWidget;
}
}
}
// if there was a focused widget and there is none or a different one now, defocus
if (mFocusedWidget && (!pressedWidget || pressedWidget != mFocusedWidget))
{
QEvent foe(QEvent::FocusOut);
QApplication::sendEvent(mFocusedWidget, &foe);
mFocusedWidget = NULL;
mTopLevelWidget->setFocus();
}
// set the new focus
if (pressedWidget)
{
QEvent fie(QEvent::FocusIn);
QApplication::sendEvent(pressedWidget, &fie);
pressedWidget->setFocus(Qt::MouseFocusReason);
mFocusedWidget = pressedWidget;
}
QApplication::sendEvent(mWidgetView->viewport(), event);
}
示例9: processWheelEvent
void QApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
{
if (!e->widget)
return;
// QPoint localPoint = ev.pos();
QPoint globalPoint = e->globalPos;
// bool trustLocalPoint = !!tlw; //is there something the local point can be local to?
QWidget *mouseWidget;
qt_last_x = globalPoint.x();
qt_last_y = globalPoint.y();
QWidget *mouseWindow = e->widget.data();
// find the tlw if we didn't get it from the plugin
if (!mouseWindow) {
mouseWindow = QApplication::topLevelAt(globalPoint);
}
if (!mouseWindow)
return;
mouseWidget = mouseWindow;
if (app_do_modal && !qt_try_modal(mouseWindow, QEvent::Wheel) ) {
qDebug() << "modal blocked wheel event" << mouseWindow;
return;
}
QPoint p = mouseWindow->mapFromGlobal(globalPoint);
QWidget *w = mouseWindow->childAt(p);
if (w) {
mouseWidget = w;
p = mouseWidget->mapFromGlobal(globalPoint);
}
QWheelEvent ev(p, globalPoint, e->delta, buttons, QApplication::keyboardModifiers(),
e->orient);
QApplication::sendSpontaneousEvent(mouseWidget, &ev);
}
示例10: curr
bool KisTabletSupportX11::nativeEventFilter(const QByteArray &/*eventType*/, void *ev, long * /*unused_on_X11*/)
{
XEvent *event = static_cast<XEvent*>(ev);
// Eat the choked mouse event...
if (kis_tabletChokeMouse &&
(event->type == ButtonRelease ||
event->type == ButtonPress ||
event->type == MotionNotify)) {
kis_tabletChokeMouse = false;
// Mhom-mhom...
return true;
}
if (kis_haveEvdevTablets && event->type == EnterNotify) {
evdevEventsActivationWorkaround((WId)event->xany.window);
}
QTabletDeviceDataList *tablets = qt_tablet_devices();
for (int i = 0; i < tablets->size(); ++i) {
QTabletDeviceData &tab = tablets->operator [](i);
if (event->type == tab.xinput_motion
|| event->type == tab.xinput_button_release
|| event->type == tab.xinput_button_press) {
QWidget *widget = QApplication::activePopupWidget();
if (!widget) {
widget = QApplication::activeModalWidget();
}
if (!widget) {
widget = QWidget::find((WId)event->xany.window);
}
bool retval = widget ? translateXinputEvent(event, &tab, widget) : false;
if (retval) {
/**
* If the tablet event is accepted, no mouse event
* should arrive. Otherwise, the popup widgets (at
* least) will not work correctly
*/
kis_tabletChokeMouse = true;
}
return retval;
} else if (event->type == tab.xinput_proximity_in ||
event->type == tab.xinput_proximity_out) {
const XProximityNotifyEvent *proximity =
reinterpret_cast<const XProximityNotifyEvent*>(event);
XID device_id = proximity->deviceid;
QTabletDeviceDataList *tablet_list = qt_tablet_devices();
for (int i = 0; i < tablet_list->size(); ++i) {
QTabletDeviceData &tab = tablet_list->operator[](i);
if (device_id == static_cast<XDevice *>(tab.device)->device_id &&
tab.isTouchWacomTablet) {
QWidget *widget = QApplication::activePopupWidget();
if (!widget) {
widget = QApplication::activeModalWidget();
}
if (!widget) {
widget = QWidget::find((WId)event->xany.window);
}
if (widget) {
QPoint curr(proximity->x, proximity->y);
QWidget *child = widget->childAt(curr);
if (child) {
widget = child;
}
QEvent::Type type = (QEvent::Type)
(event->type == tab.xinput_proximity_in ?
KisTabletEvent::TouchProximityInEx :
KisTabletEvent::TouchProximityOutEx);
QEvent e(type);
e.ignore();
QApplication::sendEvent(widget, &e);
}
return true;
}
}
}
}
return false;
}
示例11: translateXinputEvent
//.........这里部分代码省略.........
deviceType = QTabletEvent::Stylus;
pointerType = QTabletEvent::Eraser;
} else if (tab.deviceType == QTabletEvent::Stylus) {
pointerType = QTabletEvent::Pen;
}
break;
}
}
/**
* Touch events from Wacom tablets should not be sent as real
* tablet events
*/
if (tablet->isTouchWacomTablet) return false;
fetchWacomToolId(wacomSerialId, wacomDeviceId, tablet);
if (wacomDeviceId && deviceType == QTabletEvent::Stylus) {
deviceType = parseWacomDeviceId(wacomDeviceId);
}
QRect screenArea = qApp->desktop()->rect();
/**
* Some 'nice' tablet drivers (evdev) do not return the value
* of all the axes each time. Instead they tell about the
* recenty changed axes only, so we have to keep the state of
* all the axes internally and update the relevant part only.
*/
bool hasSaneData = false;
if (motion) {
hasSaneData =
tablet->savedAxesData.updateAxesData(motion->first_axis,
motion->axes_count,
motion->axis_data);
} else if (button) {
hasSaneData =
tablet->savedAxesData.updateAxesData(button->first_axis,
button->axes_count,
button->axis_data);
}
if (!hasSaneData) return false;
hiRes = tablet->savedAxesData.position(tablet, screenArea);
pressure = tablet->savedAxesData.pressure();
xTilt = tablet->savedAxesData.xTilt();
yTilt = tablet->savedAxesData.yTilt();
if (deviceType == QTabletEvent::Airbrush) {
tangentialPressure =
std::fmod(qreal(tablet->savedAxesData.rotation() - tablet->minRotation) /
(tablet->maxRotation - tablet->minRotation) , 2.0);
} else {
rotation =
std::fmod(qreal(tablet->savedAxesData.rotation() - tablet->minRotation) /
(tablet->maxRotation - tablet->minRotation) + 0.5, 1.0) * 360.0;
}
#endif
if (tablet->widgetToGetPress) {
w = tablet->widgetToGetPress;
} else {
QWidget *child = w->childAt(curr);
if (child)
w = child;
}
curr = w->mapFromGlobal(global);
if (t == KisTabletEvent::TabletPressEx) {
tablet->widgetToGetPress = w;
} else if (t == KisTabletEvent::TabletReleaseEx && tablet->widgetToGetPress) {
w = tablet->widgetToGetPress;
curr = w->mapFromGlobal(global);
tablet->widgetToGetPress = 0;
}
Qt::MouseButton qtbutton = Qt::NoButton;
Qt::MouseButtons qtbuttons;
if (motion) {
qtbuttons = translateMouseButtons(motion->state);
} else if (button) {
qtbuttons = translateMouseButtons(button->state);
qtbutton = translateMouseButton(button->button);
}
KisTabletEvent e(t, curr, global, hiRes,
deviceType, pointerType,
qreal(pressure / qreal(tablet->maxPressure - tablet->minPressure)),
xTilt, yTilt, tangentialPressure, rotation, z, modifiers, wacomSerialId,
qtbutton, qtbuttons);
e.ignore();
QApplication::sendEvent(w, &e);
return e.isAccepted();
}
示例12: generateTouchEvent
// generateTouchEvent - iterates through existing touches and creates a QTouchEvent.
// For the primary finger, it also creates a mouse event if the location has move
void QPAHiddTpHandler::generateTouchEvent()
{
if (m_touches.empty())
return;
QList<QTouchEvent::TouchPoint> touchPoints;
QList<HiddTouch>::const_iterator it;
QWidget* widget = QWidget::mouseGrabber();
if (!widget) {
QWidget* window = QApplication::topLevelAt(m_lastTouchDown);
if (window)
widget = window->childAt(window->mapFromGlobal(m_lastTouchDown));
}
if (!widget) {
QPoint dummyPt(10, 10);
QWidget* window = QApplication::topLevelAt(dummyPt);
if (window)
widget = window->childAt(window->mapFromGlobal(dummyPt));
}
if(!widget) {
widget = QApplication::activeWindow();
if(QApplication::focusWidget())
{
widget = QApplication::focusWidget();
}
}
Qt::KeyboardModifiers keyboardModifiers = QApplication::keyboardModifiers();
if (widget && m_sendPenCancel) {
//printf("Mouse Up for Pen Cancel: %d, %d\n", m_penCancelPoint.x(), m_penCancelPoint.y());
QMouseEvent ev(QEvent::MouseButtonRelease, m_penCancelPoint, m_penCancelPoint, true,
Qt::LeftButton, Qt::NoButton, keyboardModifiers);
qt_sendSpontaneousEvent((QObject*) widget, &ev);
m_sendPenCancel = false;
m_penCancelPoint = QPoint (0,0);
}
for (it = m_touches.begin(); it != m_touches.end(); ++it) {
QTouchEvent::TouchPoint touchPoint;
touchPoint.setId(it->id);
touchPoint.setPos(QPoint(it->x, it->y));
touchPoint.setScreenPos(touchPoint.pos());
switch (it->state) {
case QPAHiddTpHandler::FingerDown:
touchPoint.setState(Qt::TouchPointPressed);
break;
case QPAHiddTpHandler::FingerUp:
touchPoint.setState(Qt::TouchPointReleased);
break;
case QPAHiddTpHandler::FingerMove:
touchPoint.setState(Qt::TouchPointMoved);
break;
default:
touchPoint.setState(Qt::TouchPointStationary);
break;
}
if (it->isPrimary) {
touchPoint.setState(touchPoint.state() | Qt::TouchPointPrimary);
}
touchPoints.append(touchPoint);
// printf ("%s: adding touch point id %d (hiddId %llu) for pos (%d, %d) primary %d\n",
// __func__, it->id, it->hiddId, it->x, it->y, it->isPrimary);
if (it->isPrimary) {
QPoint mousePos = QPoint(it->x, it->y);
if (widget) {
if (it->state == QPAHiddTpHandler::FingerDown) {
uint32_t currTime = m_touchTimer.elapsed();
int dx = mousePos.x() - m_mousePress.x();
int dy = mousePos.y() - m_mousePress.y();
if (((currTime - m_mousePressTime) < (uint32_t) QApplication::doubleClickInterval()) &&
((dx * dx + dy * dy) <= 144)) {
//printf("Mouse Double Click: %d, %d\n", mousePos.x(), mousePos.y());
QMouseEvent ev(QEvent::MouseButtonDblClick, mousePos, mousePos,
Qt::LeftButton, Qt::LeftButton, keyboardModifiers);
qt_sendSpontaneousEvent((QObject*) widget, &ev);
m_mousePressTime = 0;
}
else {
//printf("Mouse Down: %d, %d\n", mousePos.x(), mousePos.y());
QMouseEvent ev(QEvent::MouseButtonPress, mousePos, mousePos,
Qt::LeftButton, Qt::LeftButton, keyboardModifiers);
qt_sendSpontaneousEvent((QObject*) widget, &ev);
m_mousePress = mousePos;
//.........这里部分代码省略.........
示例13: updateTouchEvents
//.........这里部分代码省略.........
m_screenEdgeFlickGesture->m_edge = ScreenEdgeFlickGesture::EdgeTop;
m_screenEdgeFlickGesture->m_yDistance = (touch.y - yDown);
} else {
printf("Rejected Flick\n");
}
}
else if ((yDown > (m_deviceHeight - borderWidth)) &&
(abs(touch.y - m_deviceHeight) > minimumYLength) &&
(touch.yVelocity < 0) &&
(abs(touch.yVelocity) > abs(touch.xVelocity))) {
printf("flick on bottom border. distance: %d, yDist = %d\n", abs(touch.y - m_deviceHeight), yDown - touch.y);
if((yDown - touch.y) >= minimumYLength) {
m_screenEdgeFlickGesture->m_edge = ScreenEdgeFlickGesture::EdgeBottom;
m_screenEdgeFlickGesture->m_yDistance = (yDown - touch.y);
} else {
printf("Rejected Flick\n");
}
}
}
if (m_screenEdgeFlickGesture->m_edge != ScreenEdgeFlickGesture::EdgeUnknown) {
QList<QGesture *> gestureStartedList;
QList<QGesture *> gestureFinishedList;
m_screenEdgeFlickGesture->setHotSpot(m_lastTouchDown);
m_screenEdgeFlickGesture->setState(Qt::GestureStarted);
gestureStartedList.append(m_screenEdgeFlickGesture);
// determine which widget this event will go to
QWidget* window = QApplication::topLevelAt(m_lastTouchDown);
if (window) {
QWidget* widget = window->childAt(window->mapFromGlobal(m_lastTouchDown));
if (widget) {
QGestureEvent gestureStartedEvent(gestureStartedList);
QApplication::sendEvent((QObject*) widget, &gestureStartedEvent);
m_screenEdgeFlickGesture->setState(Qt::GestureFinished);
gestureFinishedList.append(m_screenEdgeFlickGesture);
QGestureEvent gestureFinishedEvent(gestureFinishedList);
QApplication::sendEvent((QObject*) widget, &gestureFinishedEvent);
}
}
}
}
if (m_screenEdgeFlickGesture->m_edge == ScreenEdgeFlickGesture::EdgeUnknown) {
QList<QGesture *> gestureStartedList;
QList<QGesture *> gestureFinishedList;
flickGesture->m_endPos = QPoint(touch.x, touch.y);
flickGesture->m_velocity = transMap(QPoint(touch.xVelocity, touch.yVelocity));
//flickGesture->m_velocity = HostBase::instance()->map(QPoint(touch.xVelocity, touch.yVelocity));
flickGesture->setHotSpot(m_lastTouchDown);
flickGesture->setState(Qt::GestureStarted);
gestureStartedList.append(flickGesture);
// determine which widget this event will go to
QWidget* window = QApplication::topLevelAt(m_lastTouchDown);
if (window) {
QWidget* widget = window->childAt(window->mapFromGlobal(m_lastTouchDown));
示例14: processMouseEvent
void QApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
{
if (!e->widget)
return;
// qDebug() << "handleMouseEvent" << tlw << ev.pos() << ev.globalPos() << hex << ev.buttons();
static QWeakPointer<QWidget> implicit_mouse_grabber;
QEvent::Type type;
// move first
Qt::MouseButtons stateChange = e->buttons ^ buttons;
if (e->globalPos != QPoint(qt_last_x, qt_last_y) && (stateChange != Qt::NoButton)) {
QWindowSystemInterfacePrivate::MouseEvent * newMouseEvent =
new QWindowSystemInterfacePrivate::MouseEvent(e->widget.data(), e->timestamp, e->localPos, e->globalPos, e->buttons);
QWindowSystemInterfacePrivate::windowSystemEventQueue.prepend(newMouseEvent); // just in case the move triggers a new event loop
stateChange = Qt::NoButton;
}
QWidget * tlw = e->widget.data();
QPoint localPoint = e->localPos;
QPoint globalPoint = e->globalPos;
QWidget *mouseWindow = tlw;
Qt::MouseButton button = Qt::NoButton;
if (qt_last_x != globalPoint.x() || qt_last_y != globalPoint.y()) {
type = QEvent::MouseMove;
qt_last_x = globalPoint.x();
qt_last_y = globalPoint.y();
if (qAbs(globalPoint.x() - mousePressX) > mouse_double_click_distance||
qAbs(globalPoint.y() - mousePressY) > mouse_double_click_distance)
mousePressButton = Qt::NoButton;
}
else { // check to see if a new button has been pressed/released
for (int check = Qt::LeftButton;
check <= Qt::XButton2;
check = check << 1) {
if (check & stateChange) {
button = Qt::MouseButton(check);
break;
}
}
if (button == Qt::NoButton) {
// Ignore mouse events that don't change the current state
return;
}
buttons = e->buttons;
if (button & e->buttons) {
if ((e->timestamp - mousePressTime) < static_cast<ulong>(QApplication::doubleClickInterval()) && button == mousePressButton) {
type = QEvent::MouseButtonDblClick;
mousePressButton = Qt::NoButton;
}
else {
type = QEvent::MouseButtonPress;
mousePressTime = e->timestamp;
mousePressButton = button;
mousePressX = qt_last_x;
mousePressY = qt_last_y;
}
}
else
type = QEvent::MouseButtonRelease;
}
if (self->inPopupMode()) {
//popup mouse handling is magical...
mouseWindow = qApp->activePopupWidget();
implicit_mouse_grabber.clear();
//### how should popup mode and implicit mouse grab interact?
} else if (tlw && app_do_modal && !qt_try_modal(tlw, QEvent::MouseButtonRelease) ) {
//even if we're blocked by modality, we should deliver the mouse release event..
//### this code is not completely correct: multiple buttons can be pressed simultaneously
if (!(implicit_mouse_grabber && buttons == Qt::NoButton)) {
//qDebug() << "modal blocked mouse event to" << tlw;
return;
}
}
// find the tlw if we didn't get it from the plugin
if (!mouseWindow) {
mouseWindow = QApplication::topLevelAt(globalPoint);
}
if (!mouseWindow && !implicit_mouse_grabber)
mouseWindow = QApplication::desktop();
if (mouseWindow && mouseWindow != tlw) {
//we did not get a sensible localPoint from the window system, so let's calculate it
localPoint = mouseWindow->mapFromGlobal(globalPoint);
}
// which child should have it?
QWidget *mouseWidget = mouseWindow;
if (mouseWindow) {
QWidget *w = mouseWindow->childAt(localPoint);
if (w) {
//.........这里部分代码省略.........
示例15: handleMouseEvent
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
if (qApp->d_func()->inPopupMode()) {
QWidget *activePopupWidget = qApp->activePopupWidget();
QWidget *popup = activePopupWidget;
QPoint mapped = event->pos();
if (popup != m_widget)
mapped = popup->mapFromGlobal(event->globalPos());
bool releaseAfter = false;
QWidget *popupChild = popup->childAt(mapped);
if (popup != qt_popup_down) {
qt_button_down = 0;
qt_popup_down = 0;
}
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
qt_button_down = popupChild;
qt_popup_down = popup;
break;
case QEvent::MouseButtonRelease:
releaseAfter = true;
break;
default:
break; // nothing for mouse move
}
int oldOpenPopupCount = openPopupCount;
if (popup->isEnabled()) {
// deliver event
qt_replay_popup_mouse_event = false;
QWidget *receiver = popup;
QPoint widgetPos = mapped;
if (qt_button_down)
receiver = qt_button_down;
else if (popupChild)
receiver = popupChild;
if (receiver != popup)
widgetPos = receiver->mapFromGlobal(event->globalPos());
QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos()));
QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
e.setTimestamp(event->timestamp());
QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver);
} else {
// close disabled popups when a mouse button is pressed or released
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
popup->close();
break;
default:
break;
}
}
if (qApp->activePopupWidget() != activePopupWidget
&& qt_replay_popup_mouse_event) {
if (m_widget->windowType() != Qt::Popup)
qt_button_down = 0;
qt_replay_popup_mouse_event = false;
#ifndef QT_NO_CONTEXTMENU
} else if (event->type() == QEvent::MouseButtonPress
&& event->button() == Qt::RightButton
&& (openPopupCount == oldOpenPopupCount)) {
QWidget *popupEvent = popup;
if (qt_button_down)
popupEvent = qt_button_down;
else if(popupChild)
popupEvent = popupChild;
QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
QApplication::sendSpontaneousEvent(popupEvent, &e);
#endif
}
if (releaseAfter) {
qt_button_down = 0;
qt_popup_down = 0;
}
return;
}
// modal event handling
if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
return;
// which child should have it?
QWidget *widget = m_widget->childAt(event->pos());
QPoint mapped = event->pos();
if (!widget)
widget = m_widget;
if (event->type() == QEvent::MouseButtonPress && !qt_button_down)
qt_button_down = widget;
QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(),
//.........这里部分代码省略.........