本文整理汇总了C++中QWindow::mapFromGlobal方法的典型用法代码示例。如果您正苦于以下问题:C++ QWindow::mapFromGlobal方法的具体用法?C++ QWindow::mapFromGlobal怎么用?C++ QWindow::mapFromGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWindow
的用法示例。
在下文中一共展示了QWindow::mapFromGlobal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mapFromGlobal
QPoint QWidget::mapFromGlobal(const QPoint &pos) const
{
int x = pos.x(), y = pos.y();
const QWidget *w = this;
while (w) {
QWindow *window = w->windowHandle();
if (window && window->handle())
return window->mapFromGlobal(QPoint(x, y));
x -= w->data->crect.x();
y -= w->data->crect.y();
w = w->isWindow() ? 0 : w->parentWidget();
}
return QPoint(x, y);
}
示例2: handleMouseEvent
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
static const QEvent::Type contextMenuTrigger =
QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
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());
QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
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;
if (event->type() == QEvent::MouseButtonPress) {
// the popup disappeared, replay the mouse press event
QWidget *w = QApplication::widgetAt(event->globalPos());
if (w && !QApplicationPrivate::isBlockedByModal(w)) {
// activate window of the widget under mouse pointer
if (!w->isActiveWindow()) {
w->activateWindow();
w->raise();
}
QWindow *win = w->windowHandle();
if (!win)
win = w->nativeParentWidget()->windowHandle();
if (win && win->geometry().contains(event->globalPos())) {
const QPoint localPos = win->mapFromGlobal(event->globalPos());
QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
e.setTimestamp(event->timestamp());
QApplication::sendSpontaneousEvent(win, &e);
}
}
}
qt_replay_popup_mouse_event = false;
#ifndef QT_NO_CONTEXTMENU
} else if (event->type() == contextMenuTrigger
&& 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());
//.........这里部分代码省略.........
示例3: translateMouseEvent
bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
QtWindows::WindowsEventType et,
MSG msg, LRESULT *result)
{
if (et == QtWindows::MouseWheelEvent)
return translateMouseWheelEvent(window, hwnd, msg, result);
const QPoint winEventPosition(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam));
if (et & QtWindows::NonClientEventFlag) {
const QPoint globalPosition = winEventPosition;
const QPoint clientPosition = QWindowsGeometryHint::mapFromGlobal(hwnd, globalPosition);
const Qt::MouseButtons buttons = QWindowsMouseHandler::queryMouseButtons();
QWindowSystemInterface::handleFrameStrutMouseEvent(window, clientPosition,
globalPosition, buttons,
QWindowsKeyMapper::queryKeyboardModifiers());
return false; // Allow further event processing (dragging of windows).
}
*result = 0;
if (msg.message == WM_MOUSELEAVE) {
if (QWindowsContext::verboseEvents)
qDebug() << "WM_MOUSELEAVE for " << window << " previous window under mouse = " << m_windowUnderMouse << " tracked window =" << m_trackedWindow;
// When moving out of a window, WM_MOUSEMOVE within the moved-to window is received first,
// so if m_trackedWindow is not the window here, it means the cursor has left the
// application.
if (window == m_trackedWindow) {
QWindow *leaveTarget = m_windowUnderMouse ? m_windowUnderMouse : m_trackedWindow;
if (QWindowsContext::verboseEvents)
qDebug() << "Generating leave event for " << leaveTarget;
QWindowSystemInterface::handleLeaveEvent(leaveTarget);
m_trackedWindow = 0;
m_windowUnderMouse = 0;
}
return true;
}
QWindowsWindow *platformWindow = static_cast<QWindowsWindow *>(window->handle());
const Qt::MouseButtons buttons = keyStateToMouseButtons((int)msg.wParam);
// If the window was recently resized via mouse doubleclick on the frame or title bar,
// we don't get WM_LBUTTONDOWN or WM_LBUTTONDBLCLK for the second click,
// but we will get at least one WM_MOUSEMOVE with left button down and the WM_LBUTTONUP,
// which will result undesired mouse press and release events.
// To avoid those, we ignore any events with left button down if we didn't
// get the original WM_LBUTTONDOWN/WM_LBUTTONDBLCLK.
if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONDBLCLK) {
m_leftButtonDown = true;
} else {
const bool actualLeftDown = buttons & Qt::LeftButton;
if (!m_leftButtonDown && actualLeftDown) {
// Autocapture the mouse for current window to and ignore further events until release.
// Capture is necessary so we don't get WM_MOUSELEAVEs to confuse matters.
// This autocapture is released normally when button is released.
if (!platformWindow->hasMouseCapture()) {
QWindowsWindow::baseWindowOf(window)->applyCursor();
platformWindow->setMouseGrabEnabled(true);
platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
if (QWindowsContext::verboseEvents)
qDebug() << "Automatic mouse capture for missing buttondown event" << window;
}
m_previousCaptureWindow = window;
return true;
} else if (m_leftButtonDown && !actualLeftDown) {
m_leftButtonDown = false;
}
}
const QPoint globalPosition = QWindowsGeometryHint::mapToGlobal(hwnd, winEventPosition);
QWindow *currentWindowUnderMouse = platformWindow->hasMouseCapture() ?
QWindowsScreen::windowAt(globalPosition) : window;
compressMouseMove(&msg);
// Qt expects the platform plugin to capture the mouse on
// any button press until release.
if (!platformWindow->hasMouseCapture()
&& (msg.message == WM_LBUTTONDOWN || msg.message == WM_MBUTTONDOWN
|| msg.message == WM_RBUTTONDOWN || msg.message == WM_XBUTTONDOWN
|| msg.message == WM_LBUTTONDBLCLK || msg.message == WM_MBUTTONDBLCLK
|| msg.message == WM_RBUTTONDBLCLK || msg.message == WM_XBUTTONDBLCLK)) {
platformWindow->setMouseGrabEnabled(true);
platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
if (QWindowsContext::verboseEvents)
qDebug() << "Automatic mouse capture " << window;
} else if (platformWindow->hasMouseCapture()
&& platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)
&& (msg.message == WM_LBUTTONUP || msg.message == WM_MBUTTONUP
|| msg.message == WM_RBUTTONUP || msg.message == WM_XBUTTONUP)
&& !buttons) {
platformWindow->setMouseGrabEnabled(false);
if (QWindowsContext::verboseEvents)
qDebug() << "Releasing automatic mouse capture " << window;
}
const bool hasCapture = platformWindow->hasMouseCapture();
const bool currentNotCapturing = hasCapture && currentWindowUnderMouse != window;
#ifndef Q_OS_WINCE
// Enter new window: track to generate leave event.
// If there is an active capture, only track if the current window is capturing,
// so we don't get extra leave when cursor leaves the application.
//.........这里部分代码省略.........
示例4: handleMouseEvent
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
static const QEvent::Type contextMenuTrigger =
QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
if (qApp->d_func()->inPopupMode()) {
QWidget *activePopupWidget = qApp->activePopupWidget();
QPoint mapped = event->pos();
if (activePopupWidget != m_widget)
mapped = activePopupWidget->mapFromGlobal(event->globalPos());
bool releaseAfter = false;
QWidget *popupChild = activePopupWidget->childAt(mapped);
if (activePopupWidget != 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 = activePopupWidget;
break;
case QEvent::MouseButtonRelease:
releaseAfter = true;
break;
default:
break; // nothing for mouse move
}
int oldOpenPopupCount = openPopupCount;
if (activePopupWidget->isEnabled()) {
// deliver event
qt_replay_popup_mouse_event = false;
QWidget *receiver = activePopupWidget;
QPoint widgetPos = mapped;
if (qt_button_down)
receiver = qt_button_down;
else if (popupChild)
receiver = popupChild;
if (receiver != activePopupWidget)
widgetPos = receiver->mapFromGlobal(event->globalPos());
QWidget *alien = receiver;
#if !defined(Q_OS_OSX) && !defined(Q_OS_IOS) // Cocoa tracks popups
const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped);
const bool underMouse = activePopupWidget->underMouse();
if (activePopupWidget != m_widget || (!underMouse && qt_button_down)) {
// If active popup menu is not the first-level popup menu then we must emulate enter/leave events,
// because first-level popup menu grabs the mouse and enter/leave events are delivered only to it
// by QPA. Make an exception for first-level popup menu when the mouse button is pressed on widget.
if (underMouse != reallyUnderMouse) {
if (reallyUnderMouse) {
QApplicationPrivate::dispatchEnterLeave(receiver, Q_NULLPTR, event->screenPos());
qt_last_mouse_receiver = receiver;
} else {
QApplicationPrivate::dispatchEnterLeave(Q_NULLPTR, qt_last_mouse_receiver, event->screenPos());
qt_last_mouse_receiver = receiver;
receiver = activePopupWidget;
}
}
} else if (!reallyUnderMouse) {
alien = Q_NULLPTR;
}
#endif
QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(),
event->button(), event->buttons(), event->modifiers(), event->source());
e.setTimestamp(event->timestamp());
QApplicationPrivate::sendMouseEvent(receiver, &e, alien, receiver->window(), &qt_button_down, qt_last_mouse_receiver);
qt_last_mouse_receiver = 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:
activePopupWidget->close();
break;
default:
break;
}
}
if (qApp->activePopupWidget() != activePopupWidget
&& qt_replay_popup_mouse_event
&& QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ReplayMousePressOutsidePopup).toBool()) {
if (m_widget->windowType() != Qt::Popup)
qt_button_down = 0;
if (event->type() == QEvent::MouseButtonPress) {
// the popup disappeared, replay the mouse press event
QWidget *w = QApplication::widgetAt(event->globalPos());
if (w && !QApplicationPrivate::isBlockedByModal(w)) {
// activate window of the widget under mouse pointer
if (!w->isActiveWindow()) {
w->activateWindow();
w->raise();
}
//.........这里部分代码省略.........