Example #1
0
QPointF QuasiGame::mouse()
{
#if QT_VERSION >= 0x050000
    return canvas()->mapFromGlobal(QCursor::pos());
#else
    m_mousePos = QCursor::pos();
    QWidget *widget = QApplication::widgetAt(m_mousePos);

    if (widget)
        return widget->mapFromGlobal(m_mousePos);
    else
        return m_mousePos;
#endif
}
Example #2
0
void tst_MacNativeEvents::testMouseLeftDoubleClick()
{
    // Check that a native double click makes
    // the test widget receive a press-release-click-release:
    QWidget w;
    w.show();
    QPoint p = w.geometry().center();

    NativeEventList native;
    native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 1, Qt::NoModifier));
    native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier));
    native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 2, Qt::NoModifier));
    native.append(new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier));

    ExpectedEventList expected(&w);
    expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
    expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::NoButton, Qt::NoModifier));
    expected.append(new QMouseEvent(QEvent::MouseButtonDblClick, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
    expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(p), p, Qt::LeftButton, Qt::NoButton, Qt::NoModifier));

    native.play();
    QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!");
}
Example #3
0
void ProxyConfig::paintEvent(QPaintEvent*)
{
    for (QWidget *p = parentWidget(); p; p = p->parentWidget()){
        const QPixmap *bg = p->backgroundPixmap();
        if (bg){
            QPoint pos = mapToGlobal(QPoint(0, 0));
            pos = p->mapFromGlobal(pos);
            QPainter pp(this);
            pp.drawTiledPixmap(0, 0, width(), height(), *bg, pos.x(), pos.y());
            return;
        }
    }
    QPainter pp(this);
    pp.eraseRect(0, 0, width(), height());
}
void OpenPagesWidget::handleActivated(const QModelIndex &index)
{
    if (index.column() == 0) {
        emit setCurrentPage(index);
    } else if (index.column() == 1) { // the funky close button
        if (model()->rowCount() > 1)
            emit closePage(index);

        // work around a bug in itemviews where the delegate wouldn't get the QStyle::State_MouseOver
        QWidget *vp = viewport();
        const QPoint &cursorPos = QCursor::pos();
        QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos, Qt::NoButton, 0, 0);
        QCoreApplication::sendEvent(vp, &e);
    }
}
Example #5
0
void tst_MacNativeEvents::testMouseMoveLocation()
{
    QWidget w;
    w.setMouseTracking(true);
    w.show();
    QPoint p = w.geometry().center();

    NativeEventList native;
    native.append(new QNativeMouseMoveEvent(p, Qt::NoModifier));

    ExpectedEventList expected(&w);
    expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(p), p, Qt::NoButton, Qt::NoButton, Qt::NoModifier));

    native.play();
    QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!");
}
Example #6
0
void QChildWidget::paintEvent(QPaintEvent*)
{
    for (QWidget *p = parentWidget(); p; p = p->parentWidget()){
        const QPixmap bg = p->palette().brush(p->backgroundRole()).texture();
        if (!bg.isNull()){
            QPoint pos = mapToGlobal(QPoint(0, 0));
            pos = p->mapFromGlobal(pos);
            QPainter pp(this);
            pp.drawTiledPixmap(0, 0, width(), height(), bg, pos.x(), pos.y());
            return;
        }
        if (p == topLevelWidget())
            break;
    }
    QPainter pp(this);
    pp.eraseRect(0, 0, width(), height());
}
void WidgetHandle::mousePressEvent(QMouseEvent *e)
{
    e->accept();

    if (!m_formWindow->hasFeature(FormWindow::EditFeature))
        return;

    if (!(m_widget && e->button() == Qt::LeftButton))
        return;

    if (!(m_active))
        return;

    QWidget *container = m_widget->parentWidget();

    m_origPressPos = container->mapFromGlobal(e->globalPos());
    m_geom = m_origGeom = m_widget->geometry();
}
Example #8
0
void FrameLoaderClientQt::postProgressFinishedNotification()
{
    // send a mousemove event to
    // (1) update the cursor to change according to whatever is underneath the mouse cursor right now
    // (2) display the tool tip if the mouse hovers a node which has a tool tip
    if (m_frame && m_frame->eventHandler() && m_webFrame->page()) {
        QWidget* view = m_webFrame->page()->view();
        if (view && view->hasFocus()) {
            QPoint localPos = view->mapFromGlobal(QCursor::pos());
            if (view->rect().contains(localPos)) {
                QMouseEvent event(QEvent::MouseMove, localPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
                m_frame->eventHandler()->mouseMoved(PlatformMouseEvent(&event, 0));
            }
        }
    }

    if (m_webFrame && m_frame->page())
        emit loadFinished(m_loadError.isNull());
}
void ViewItemButtonMechanism::paint(QPainter *painter,
                                    const QStyleOptionViewItem &option,
                                    const QModelIndex &index)
{
  bool mouseIsOver = false;
  if (painter != 0) {
    QWidget* w = dynamic_cast<QWidget*>(painter->device());
    if (w != 0) {
      QPoint mousePos = QCursor::pos();
      QPoint wMousePos = w->mapFromGlobal(mousePos);
      mouseIsOver = option.rect.contains(wMousePos);
    }
  }

  //  QStyledItemDelegate::paint(painter, option, index);

  if (this->itemView()->isEnabled()) {
    QStyleOptionViewItemV4 optionForBtn(option);
    optionForBtn.rect = this->itemView()->visualRect(d->modelIndexForButtonDisplay(index));
    const int btnIndex = this->buttonAtModelIndex(index);
    ViewItemButtonMechanismPrivate::ButtonInfo* btnInfo = d->mutableButtonInfo(btnIndex);
    const int dispMode = btnInfo != 0 ? btnInfo->itemDisplayMode : -1;
    switch (dispMode) {
    case DisplayPermanent: {
      d->paintButton(btnInfo, painter, optionForBtn);
      break;
    }
    case DisplayOnDetection: {
      if (mouseIsOver)
        d->paintButton(btnInfo, painter, optionForBtn);
      else
        painter->fillRect(optionForBtn.rect, optionForBtn.backgroundBrush);
      break;
    }
    default:
      break;
    }
  }
  else {
    d->resetButtonUnderMouseState();
    //    d->setAllIsOverButtonState(false);
  }
}
Example #10
0
void QObjectProxy::interpretMouseEvent( QEvent *e, QList<QVariant> &args )
{
  if( e->type() == QEvent::Enter ) {
    QPoint pos = QCursor::pos();

    QWidget *w = qobject_cast<QWidget*>( qObject );
    if( w ) pos = w->mapFromGlobal( pos );

    args << pos.x();
    args << pos.y();
    return;
  }

  QMouseEvent *mouse = static_cast<QMouseEvent*>( e );
  args << mouse->x();
  args << mouse->y();

  args << (int) mouse->modifiers();

  if( e->type() == QEvent::MouseMove ) return;

  int button;
  switch( mouse->button() ) {
    case Qt::LeftButton:
      button = 0; break;
    case Qt::RightButton:
      button = 1; break;
    case Qt::MidButton:
      button = 2; break;
    default:
      button = -1;
  }

  args << button;

  switch( e->type() ) {
    case QEvent::MouseButtonPress:
      args << 1; break;
    case QEvent::MouseButtonDblClick:
      args << 2; break;
    default: ;
  }
}
void IndicatorsManager::checkMousePosition()
{
    // Called by m_mouseTrackerTimer to implement mouse scrubbing
    // (Assuming item A menu is opened, move mouse over item B => item B menu opens)
    // Also, delivers motion events to Qt, which will generate correct
    // enter/leave events for IndicatorEntry widgets.
    QPoint pos = QCursor::pos();

    // Don't send the event unless the mouse has moved
    // https://bugs.launchpad.net/bugs/834065
    if (!m_lastMousePosition.isNull() && (m_lastMousePosition == pos)) {
        return;
    }
    m_lastMousePosition = pos;

    QWidget* widget = QApplication::widgetAt(pos);
    Display* display = QX11Info::display();

    QPoint relPos = widget != 0 ? widget->mapFromGlobal(pos) : pos;
    XMotionEvent event = {
        MotionNotify,
        0,
        False,
        display,
        widget != 0 ? widget->effectiveWinId() : 0,
        widget != 0 ? RootWindow(display, widget->x11Info().screen()) : 0,
        0,
        CurrentTime,
        pos.x(), pos.y(),
        relPos.x(), relPos.y(),
        0,
        False,
        True
    };
    qApp->x11ProcessEvent(reinterpret_cast<XEvent*>(&event));

    IndicatorEntryWidget* entryWidget = qobject_cast<IndicatorEntryWidget*>(widget);
    if (!entryWidget) {
        return;
    }
    entryWidget->showMenu(Qt::NoButton);
}
Example #12
0
/*!
  Resizes the top-level widget containing this widget.
*/
void QSizeGrip::mouseMoveEvent( QMouseEvent * e )
{
    if ( e->state() != LeftButton )
	return;

    QWidget* tlw = qt_sizegrip_topLevelWidget(this);
    if ( tlw->testWState(WState_ConfigPending) )
	return;

    QPoint np( e->globalPos() );

    QWidget* ws = qt_sizegrip_workspace( this );
    if ( ws ) {
	QPoint tmp( ws->mapFromGlobal( np ) );
	if ( tmp.x() > ws->width() )
	    tmp.setX( ws->width() );
	if ( tmp.y() > ws->height() )
	    tmp.setY( ws->height() );
	np = ws->mapToGlobal( tmp );
    }

    int w = np.x() - p.x() + s.width();
    int h = np.y() - p.y() + s.height();
    if ( w < 1 )
	w = 1;
    if ( h < 1 )
	h = 1;
    QSize ms( tlw->minimumSizeHint() );
    ms = ms.expandedTo( minimumSize() );
    if ( w < ms.width() )
	w = ms.width();
    if ( h < ms.height() )
	h = ms.height();
    tlw->resize( w, h );
#ifdef _WS_WIN_
    MSG msg;
    while( PeekMessage( &msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE ) )
      ;
#endif
    QApplication::syncX();
}
Example #13
0
/*!
  Open a selection setting the state to active

  \sa isActive, end(), append(), move()
*/
void QwtPicker::begin()
{
    if ( d_data->isActive )
        return;

    d_data->selection.resize(0);
    d_data->isActive = true;

    if ( trackerMode() != AlwaysOff )
    {
        if ( d_data->labelPosition.x() < 0 || d_data->labelPosition.y() < 0 ) 
        {
            QWidget *w = parentWidget();
            if ( w )
                d_data->labelPosition = w->mapFromGlobal(QCursor::pos());
        }
    }

    updateDisplay();
    setMouseTracking(true);
}
Example #14
0
void tst_MacNativeEvents::testMouseEnter()
{
    // When a mouse enters a widget, both a mouse enter events and a
    // mouse move event should be sendt. Lets test this:
    QWidget w;
    w.setMouseTracking(true);
    w.show();
    QPoint outside = w.geometry().topLeft() - QPoint(50, 0);
    QPoint inside = w.geometry().center();

    NativeEventList native;
    native.append(new QNativeMouseMoveEvent(outside, Qt::NoModifier));
    native.append(new QNativeMouseMoveEvent(inside, Qt::NoModifier));

    ExpectedEventList expected(&w);
    expected.append(new QEvent(QEvent::Enter));
    expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(inside), inside, Qt::NoButton, Qt::NoButton, Qt::NoModifier));

    native.play();
    QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!");
}
Example #15
0
void MuseScore::showContextHelp()
      {
      QString s;
      QWidget* w = qApp->widgetAt(globalX, globalY);
      while (w) {
            if (!w->statusTip().isEmpty()) {
                  s = w->statusTip();
                  break;
                  }
            w = w->parentWidget();
            }
      if (w && s == "scoreview") {
            ScoreView* canvas = static_cast<ScoreView*>(w);
            QPoint pt = w->mapFromGlobal(QPoint(globalX, globalY));
            QPointF p = canvas->toLogical(pt);
            Element* e = canvas->elementNear(p);
            if (e)
                  s = QString("element:%1").arg(e->name());
            }
      showHelp(s);
      }
Example #16
0
STDMETHODIMP QOleDropTarget::DragOver( DWORD grfKeyState,
                                       POINTL pt,
                                       LPDWORD pdwEffect )
{
#ifdef DEBUG_QDND_TGT
    qDebug( "QOleDropTarget::DragOver( %d, %d/%d, %d )",
            grfKeyState, pt.x, pt.y, *pdwEffect );
    qDebug( "widget: %p, winID: %08x", widget, widget ? widget->winId() : 0 );
#endif

    if ( !qt_tryModalHelper( widget ) ) {
        *pdwEffect = DROPEFFECT_NONE;
        return NOERROR;
    }

    QPoint tmpPoint = widget->mapFromGlobal( QPoint( pt.x, pt.y ) );
    // see if we should compress this event
    if ( ( tmpPoint == lastPoint || answerRect.contains( tmpPoint ) ) && lastKeyState == grfKeyState ) {
        *pdwEffect = choosenEffect;
        return NOERROR;
    }

    lastPoint = tmpPoint;
    lastKeyState = grfKeyState;

    QDragMoveEvent e( lastPoint );
    e.setAction( translateKeyStateToQDropAction( grfKeyState, *pdwEffect ) );
    e.accept();
    QApplication::sendEvent( widget, &e );

    answerRect = e.answerRect();
    if ( e.isAccepted() )
        choosenEffect = translateToWinDragEffects( e.action() );
    else
        choosenEffect = DROPEFFECT_NONE;
    *pdwEffect = choosenEffect;

    return NOERROR;
}
Example #17
0
STDMETHODIMP QOleDropTarget::DragEnter( LPDATAOBJECT pIDataSource,
                                        DWORD grfKeyState,
                                        POINTL pt,
                                        LPDWORD pdwEffect )
{
#ifdef DEBUG_QDND_TGT
    qDebug( "QOleDropTarget::DragEnter( %p, %d, %d/%d, %d )",
            pIDataSource, grfKeyState, pt.x, pt.y, *pdwEffect );
    qDebug( "widget: %p, winID: %08x", widget, widget ? widget->winId() : 0 );
#endif

    if ( !qt_tryModalHelper( widget ) ) {
        *pdwEffect = DROPEFFECT_NONE;
        return NOERROR;
    }

    pIDataObject = pIDataSource;
    pIDataObject->AddRef();

    lastPoint = widget->mapFromGlobal( QPoint( pt.x, pt.y ) );
    lastKeyState = grfKeyState;

    QDragEnterEvent e( lastPoint );
    e.setAction( translateKeyStateToQDropAction( grfKeyState, *pdwEffect ) );
    e.accept();
    QApplication::sendEvent( widget, &e );

    QDragResponseEvent re ( e.isAccepted() );
    QApplication::sendEvent( widget, &re );

    answerRect = e.answerRect();
    if ( e.isAccepted() )
        choosenEffect = translateToWinDragEffects( e.action() );
    else
        choosenEffect = DROPEFFECT_NONE;
    *pdwEffect = choosenEffect;

    return NOERROR;
}
void Box2DMouseJointItem::synchronize()
{
    if (!m_joint || !m_target)
        return;

    Box2DBaseItem::synchronize();

    QPoint mousePos;

#if QT_VERSION >= 0x050000
    mousePos = canvas()->mapFromGlobal(QCursor::pos());
#else
    m_mousePos = QCursor::pos();
    QWidget *widget = QApplication::widgetAt(m_mousePos);

    if (widget)
        mousePos = widget->mapFromGlobal(m_mousePos);
    else
        mousePos = m_mousePos;
    m_mousePos = mousePos;
#endif

    m_joint->SetTarget(b2Vec2(mousePos.x() / m_scaleRatio, -mousePos.y() / m_scaleRatio));
}
bool translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet, QWidget *defaultWidget)
{
    Q_ASSERT(defaultWidget);

#if defined (Q_OS_IRIX)
#endif

    Q_ASSERT(tablet != 0);

    QWidget *w = defaultWidget;
    QPoint global,
        curr;
    QPointF hiRes;
    qreal pressure = 0;
    int xTilt = 0,
        yTilt = 0,
        z = 0;
    qreal tangentialPressure = 0;
    qreal rotation = 0;
    int deviceType = QTabletEvent::NoDevice;
    int pointerType = QTabletEvent::UnknownPointer;
    const XDeviceMotionEvent *motion = 0;
    XDeviceButtonEvent *button = 0;
    KisTabletEvent::ExtraEventType t = KisTabletEvent::TabletMoveEx;
    Qt::KeyboardModifiers modifiers = 0;

    modifiers = QApplication::queryKeyboardModifiers();

#if !defined (Q_OS_IRIX)
    XID device_id = 0;
#endif

    if (ev->type == tablet->xinput_motion) {
        motion = reinterpret_cast<const XDeviceMotionEvent*>(ev);
        t = KisTabletEvent::TabletMoveEx;
        global = QPoint(motion->x_root, motion->y_root);
        curr = QPoint(motion->x, motion->y);
#if !defined (Q_OS_IRIX)
        device_id = motion->deviceid;
#endif
    } else if (ev->type == tablet->xinput_button_press || ev->type == tablet->xinput_button_release) {
        if (ev->type == tablet->xinput_button_press) {
            t = KisTabletEvent::TabletPressEx;
        } else {
            t = KisTabletEvent::TabletReleaseEx;
        }
        button = (XDeviceButtonEvent*)ev;
        global = QPoint(button->x_root, button->y_root);
        curr = QPoint(button->x, button->y);
#if !defined (Q_OS_IRIX)
        device_id = button->deviceid;
#endif
    } else {
        qFatal("Unknown event type! Probably, 'proximity', "
               "but we don't handle it here, so this is a bug");
    }

    qint64 wacomSerialId = 0;
    qint64 wacomDeviceId = 0;
#if defined (Q_OS_IRIX)
#else
    // We've been passed in data for a tablet device that handles this type
    // of event, but it isn't necessarily the tablet device that originated
    // the event.  Use the device id to find the originating device if we
    // have it.
    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) {
            // Replace the tablet passed in with this one.
            tablet = &tab;
            deviceType = tab.deviceType;
            if (tab.deviceType == QTabletEvent::XFreeEraser) {
                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();
}
Example #20
0
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(),
                                                               qt_button_down, widget);

    if (!receiver) {
        if (event->type() == QEvent::MouseButtonRelease)
            QApplicationPrivate::mouse_buttons &= ~event->button();
        return;
    }

    QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
    translated.setTimestamp(event->timestamp());
    QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, &qt_button_down,
                                        qt_last_mouse_receiver);

#ifndef QT_NO_CONTEXTMENU
    if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::RightButton) {
        QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
        QGuiApplication::sendSpontaneousEvent(receiver, &e);
    }
#endif
}
bool QGraphicsViewAdapter::handlePointerEvent(int x, int y, int buttonMask)
{
    OSG_INFO<<"dispatchPointerEvent("<<x<<", "<<y<<", "<<buttonMask<<")"<<std::endl;

    y = _graphicsView->size().height()-y;

    bool leftButtonPressed = (buttonMask & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)!=0;
    bool middleButtonPressed = (buttonMask & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)!=0;
    bool rightButtonPressed = (buttonMask & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)!=0;

    bool prev_leftButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)!=0;
    bool prev_middleButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)!=0;
    bool prev_rightButtonPressed = (_previousButtonMask & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)!=0;

    OSG_INFO<<"leftButtonPressed "<<leftButtonPressed<<std::endl;
    OSG_INFO<<"middleButtonPressed "<<middleButtonPressed<<std::endl;
    OSG_INFO<<"rightButtonPressed "<<rightButtonPressed<<std::endl;

    Qt::MouseButtons qtMouseButtons =
        (leftButtonPressed ? Qt::LeftButton : Qt::NoButton) |
        (middleButtonPressed ? Qt::MidButton : Qt::NoButton) |
        (rightButtonPressed ? Qt::RightButton : Qt::NoButton);

    const QRect viewportGeometry = _graphicsView->viewport()->geometry();
    const QPoint globalPos(x, y);
     

      
    if (buttonMask != _previousButtonMask)
    {
        Qt::MouseButton qtButton = Qt::NoButton;
        QEvent::Type eventType = QEvent::None;
        if (leftButtonPressed != prev_leftButtonPressed)
        {
            qtButton = Qt::LeftButton;
            eventType = leftButtonPressed ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease ;
        }
        else if (middleButtonPressed != prev_middleButtonPressed)
        {
            qtButton = Qt::MidButton;
            eventType = middleButtonPressed ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease ;
        }
        else if (rightButtonPressed != prev_rightButtonPressed)
        {
            qtButton = Qt::RightButton;
            eventType = rightButtonPressed ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease ;
            if(!rightButtonPressed)
            {
               QWidget* targetWidget = getWidgetAt(globalPos);
               if(targetWidget) 
               {
                  QPoint localPos = targetWidget->mapFromGlobal(globalPos);
                  QContextMenuEvent* cme = new QContextMenuEvent(QContextMenuEvent::Mouse, localPos, globalPos);
                  QCoreApplication::postEvent(targetWidget, cme);
               }               
            }
        }
      
        if (eventType==QEvent::MouseButtonPress)
        {
            _image->sendFocusHint(true);
        }

        QMouseEvent event(eventType, globalPos, qtButton, qtMouseButtons, 0);
        QCoreApplication::sendEvent(_graphicsView->viewport(), &event );

        _previousButtonMask = buttonMask;
    }
    else if (x != _previousMouseX || y != _previousMouseY)
    {
        QMouseEvent event(QEvent::MouseMove, globalPos, Qt::NoButton, qtMouseButtons, 0);
        QCoreApplication::sendEvent(_graphicsView->viewport(), &event);

        _previousMouseX = x;
        _previousMouseY = y;
    }

    return true;
}
void WidgetHandle::mouseMoveEvent(QMouseEvent *e)
{
    if (!(m_widget && m_active && e->buttons() & Qt::LeftButton))
        return;

    e->accept();

    QWidget *container = m_widget->parentWidget();

    const QPoint rp = container->mapFromGlobal(e->globalPos());
    const QPoint d = rp - m_origPressPos;

    const QRect pr = container->rect();

    qdesigner_internal::Grid grid;
    if (const qdesigner_internal::FormWindowBase *fwb = qobject_cast<const qdesigner_internal::FormWindowBase*>(m_formWindow))
        grid = fwb->designerGrid();

    switch (m_type) {

    case LeftTop: {
        if (rp.x() > pr.width() - 2 * width() || rp.y() > pr.height() - 2 * height())
            return;

        int w = m_origGeom.width() - d.x();
        m_geom.setWidth(w);
        w = grid.widgetHandleAdjustX(w);

        int h = m_origGeom.height() - d.y();
        m_geom.setHeight(h);
        h = grid.widgetHandleAdjustY(h);

        const int dx = m_widget->width() - w;
        const int dy = m_widget->height() - h;

        trySetGeometry(m_widget, m_widget->x() + dx, m_widget->y() + dy, w, h);
    } break;

    case Top: {
        if (rp.y() > pr.height() - 2 * height())
            return;

        int h = m_origGeom.height() - d.y();
        m_geom.setHeight(h);
        h = grid.widgetHandleAdjustY(h);

        const int dy = m_widget->height() - h;
        trySetGeometry(m_widget, m_widget->x(), m_widget->y() + dy, m_widget->width(), h);
    } break;

    case RightTop: {
        if (rp.x() < 2 * width() || rp.y() > pr.height() - 2 * height())
            return;

        int h = m_origGeom.height() - d.y();
        m_geom.setHeight(h);
        h = grid.widgetHandleAdjustY(h);

        const int dy = m_widget->height() - h;

        int w = m_origGeom.width() + d.x();
        m_geom.setWidth(w);
        w = grid.widgetHandleAdjustX(w);

        trySetGeometry(m_widget, m_widget->x(), m_widget->y() + dy, w, h);
    } break;

    case Right: {
        if (rp.x() < 2 * width())
            return;

        int w = m_origGeom.width() + d.x();
        m_geom.setWidth(w);
        w = grid.widgetHandleAdjustX(w);

        tryResize(m_widget, w, m_widget->height());
    } break;

    case RightBottom: {
        if (rp.x() < 2 * width() || rp.y() < 2 * height())
            return;

        int w = m_origGeom.width() + d.x();
        m_geom.setWidth(w);
        w = grid.widgetHandleAdjustX(w);

        int h = m_origGeom.height() + d.y();
        m_geom.setHeight(h);
        h = grid.widgetHandleAdjustY(h);

        tryResize(m_widget, w, h);
    } break;

    case Bottom: {
        if (rp.y() < 2 * height())
            return;

        int h = m_origGeom.height() + d.y();
        m_geom.setHeight(h);
        h = grid.widgetHandleAdjustY(h);

        tryResize(m_widget, m_widget->width(), h);
    } break;

    case LeftBottom: {
        if (rp.x() > pr.width() - 2 * width() || rp.y() < 2 * height())
            return;

        int w = m_origGeom.width() - d.x();
        m_geom.setWidth(w);
        w = grid.widgetHandleAdjustX(w);

        int h = m_origGeom.height() + d.y();
        m_geom.setHeight(h);
        h = grid.widgetHandleAdjustY(h);

        int dx = m_widget->width() - w;

        trySetGeometry(m_widget, m_widget->x() + dx, m_widget->y(), w, h);
    } break;

    case Left: {
        if (rp.x() > pr.width() - 2 * width())
            return;

        int w = m_origGeom.width() - d.x();
        m_geom.setWidth(w);
        w = grid.widgetHandleAdjustX(w);

        const int dx = m_widget->width() - w;

        trySetGeometry(m_widget, m_widget->x() + dx, m_widget->y(), w, m_widget->height());
    } break;

    default: break;

    } // end switch

    m_sel->updateGeometry();

    if (LayoutInfo::layoutType(m_formWindow->core(), m_widget) != LayoutInfo::NoLayout)
        m_formWindow->updateChildSelections(m_widget);
}
bool QDragManager::eventFilter(QObject *o, QEvent *e)
{
 if (beingCancelled) {
        return false;
    }
    if (!o->isWidgetType())
        return false;

    switch(e->type()) {
        case QEvent::MouseButtonPress:
        {
        }
        case QEvent::MouseMove:
        {
            if (!object) { //#### this should not happen
                qWarning("QDragManager::eventFilter: No object");
                return true;
            }
            QDragManager *manager = QDragManager::self();
            QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;
            if (manager->object)
                possible_actions =  manager->dragPrivate()->possible_actions;
            else
                possible_actions = Qt::IgnoreAction;

            QMouseEvent *me = (QMouseEvent *)e;

            if (me->buttons()) {
                Qt::DropAction prevAction = global_accepted_action;
                QWidget *cw = QApplication::widgetAt(me->globalPos());
                // map the Coords relative to the window.
                if (!cw)
                    return true;

                while (cw && !cw->acceptDrops() && !cw->isWindow())
                    cw = cw->parentWidget();

                bool oldWillDrop = willDrop;
                if (object->target() != cw) {
                    if (object->target()) {
                        QDragLeaveEvent dle;
                        QApplication::sendEvent(object->target(), &dle);
                        willDrop = false;
                        global_accepted_action = Qt::IgnoreAction;
                        if (oldWillDrop != willDrop)
                            updateCursor();
                        object->d_func()->target = 0;
                    }
                    if (cw && cw->acceptDrops()) {
                        object->d_func()->target = cw;
                        QDragEnterEvent dee(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
                                            me->buttons(), me->modifiers());
                        QApplication::sendEvent(object->target(), &dee);
                        willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction;
                        global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction;
                        if (oldWillDrop != willDrop)
                            updateCursor();
                    }
                } else if (cw) {
                    QDragMoveEvent dme(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
                                       me->buttons(), me->modifiers());
                    if (global_accepted_action != Qt::IgnoreAction) {
                        dme.setDropAction(global_accepted_action);
                        dme.accept();
                    }
                    QApplication::sendEvent(cw, &dme);
                    willDrop = dme.isAccepted();
                    global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction;
                    if (oldWillDrop != willDrop) {
                        updatePixmap();
                        updateCursor();
                    }
                }
                if (global_accepted_action != prevAction)
                    emitActionChanged(global_accepted_action);
            }
            return true; // Eat all mouse events
        }

        case QEvent::MouseButtonRelease:
        {
            qApp->removeEventFilter(this);
#ifndef QT_NO_CURSOR
            if (restoreCursor) {
                QApplication::restoreOverrideCursor();
                willDrop = false;
                restoreCursor = false;
            }
#endif
            if (object && object->target()) {

                QMouseEvent *me = (QMouseEvent *)e;

                QDragManager *manager = QDragManager::self();
                QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;

                QDropEvent de(object->target()->mapFromGlobal(me->globalPos()), possible_actions, dropData,
                              me->buttons(), me->modifiers());
                QApplication::sendEvent(object->target(), &de);
                if (de.isAccepted())
                    global_accepted_action = de.dropAction();
                else
                    global_accepted_action = Qt::IgnoreAction;

                if (object)
                    object->deleteLater();
                drag_object = object = 0;
            }
            eventLoop->exit();
            return true; // Eat all mouse events
        }

        default:
             break;
    }
    return false;
}
Example #24
0
STDMETHODIMP QOleDropTarget::Drop( LPDATAOBJECT pIDataSource,
                                   DWORD grfKeyState,
                                   POINTL pt,
                                   LPDWORD pdwEffect )
{
#ifdef DEBUG_QDND_TGT
    qDebug( "QOleDropTarget::Drop( %p, %d, %d/%d, %d )",
            pIDataSource, grfKeyState, pt.x, pt.y, *pdwEffect );
    qDebug( "widget: %p, winID: %08x", widget, widget ? widget->winId() : 0 );
#endif

    if ( !qt_tryModalHelper( widget ) ) {
        *pdwEffect = DROPEFFECT_NONE;
        return NOERROR;
    }

    lastPoint = widget->mapFromGlobal( QPoint( pt.x, pt.y ) );
    // grfKeyState does not all ways contain button state in the drop so if
    // it doesn't then use the last known button state;
    if ( ( grfKeyState & KEY_STATE_BUTTON_MASK ) == 0 )
        grfKeyState |= lastKeyState & KEY_STATE_BUTTON_MASK;
    lastKeyState = grfKeyState;

    FORMATETC s_fmtMemory = { 0,
                              NULL,
                              DVASPECT_CONTENT,
                              -1,
                              TYMED_HGLOBAL };

    /* Can we convert the data? */
    bool found = false;
    QPtrList<QWindowsMime> all = QWindowsMime::all();
    for ( QWindowsMime * c = all.first(); c && !found; c = all.next() ) {
        for ( int i = 0; i < c->countCf(); i++ ) {
            int cf = c->cf( i );
            s_fmtMemory.cfFormat = cf;
            if ( pIDataSource->QueryGetData( &s_fmtMemory ) == S_OK ) {
                found = true;
                break;
            }

        }
    }
    if ( !found ) {
        return S_OK;
    }
    /* Just to be sure */
    pIDataObject = pIDataSource;

    pIDataObject->AddRef();
    QDropEvent de( lastPoint );
    de.setAction( translateKeyStateToQDropAction( grfKeyState, *pdwEffect ) );
    if ( global_src )
        global_src->setTarget( widget );
    QApplication::sendEvent( widget, &de );

    pIDataObject->Release();
    pIDataObject = NULL;

    return S_OK;
}
Example #25
0
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());
            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 = widget;

    QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(),
                                                               qt_button_down, widget);

    if (!receiver) {
        if (event->type() == QEvent::MouseButtonRelease)
            QApplicationPrivate::mouse_buttons &= ~event->button();
        return;
    }
    if ((event->type() != QEvent::MouseButtonPress)
        || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) {

        // The preceding statement excludes MouseButtonPress events which caused
        // creation of a MouseButtonDblClick event. QTBUG-25831
        QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(),
                               event->button(), event->buttons(), event->modifiers());
        QGuiApplicationPrivate::setMouseEventSource(&translated, QGuiApplicationPrivate::mouseEventSource(event));
        translated.setTimestamp(event->timestamp());
        QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget,
                                            &qt_button_down, qt_last_mouse_receiver);
    }
#ifndef QT_NO_CONTEXTMENU
    if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton) {
        QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
        QGuiApplication::sendSpontaneousEvent(receiver, &e);
    }
#endif
}
Example #26
0
void Q3TitleBar::mouseMoveEvent(QMouseEvent *e)
{
    Q_D(Q3TitleBar);
    e->accept();
    switch (d->buttonDown) {
    case QStyle::SC_None:
        if(autoRaise())
            repaint();
        break;
    case QStyle::SC_TitleBarSysMenu:
        break;
    case QStyle::SC_TitleBarShadeButton:
    case QStyle::SC_TitleBarUnshadeButton:
    case QStyle::SC_TitleBarNormalButton:
    case QStyle::SC_TitleBarMinButton:
    case QStyle::SC_TitleBarMaxButton:
    case QStyle::SC_TitleBarCloseButton:
        {
            QStyle::SubControl last_ctrl = d->buttonDown;
            QStyleOptionTitleBar opt = d->getStyleOption();
            d->buttonDown = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(), this);
            if (d->buttonDown != last_ctrl)
                d->buttonDown = QStyle::SC_None;
            repaint();
            d->buttonDown = last_ctrl;
        }
        break;

    case QStyle::SC_TitleBarLabel:
        if (d->buttonDown == QStyle::SC_TitleBarLabel && d->movable && d->pressed) {
            if ((d->moveOffset - mapToParent(e->pos())).manhattanLength() >= 4) {
                QPoint p = mapFromGlobal(e->globalPos());

                QWidget *parent = d->window ? d->window->parentWidget() : 0;
                if(parent && parent->inherits("Q3WorkspaceChild")) {
                    QWidget *workspace = parent->parentWidget();
                    p = workspace->mapFromGlobal(e->globalPos());
                    if (!workspace->rect().contains(p)) {
                        if (p.x() < 0)
                            p.rx() = 0;
                        if (p.y() < 0)
                            p.ry() = 0;
                        if (p.x() > workspace->width())
                            p.rx() = workspace->width();
                        if (p.y() > workspace->height())
                            p.ry() = workspace->height();
                    }
                }

                QPoint pp = p - d->moveOffset;
                if (!parentWidget()->isMaximized())
                    parentWidget()->move(pp);
            }
        } else {
            QStyle::SubControl last_ctrl = d->buttonDown;
            d->buttonDown = QStyle::SC_None;
            if(d->buttonDown != last_ctrl)
                repaint();
        }
        break;
    default:
        break;
    }
}
Example #27
0
// 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;

						m_mousePressTime = currTime;
					}

				} else if (it->state == QPAHiddTpHandler::FingerMove) {
					//printf("Mouse Move: %d, %d\n", mousePos.x(), mousePos.y());
					QMouseEvent ev(QEvent::MouseMove, mousePos, mousePos,
								   Qt::LeftButton, Qt::LeftButton, keyboardModifiers);
					qt_sendSpontaneousEvent((QObject*) widget, &ev);							
				}
			}
		}
	}
	
	//printf ("sending touch event\n");
	qt_translateRawTouchEvent(QApplication::activeWindow(), QTouchEvent::TouchScreen, touchPoints);

	for (it = m_touches.begin(); it != m_touches.end(); ++it) {

		if (it->isPrimary) {

			QPoint mousePos = QPoint(it->x, it->y);
			if (widget) {
			
				if (it->state == QPAHiddTpHandler::FingerUp) {
					//printf("Mouse Up: %d, %d\n", mousePos.x(), mousePos.y());
					QMouseEvent ev(QEvent::MouseButtonRelease, mousePos, mousePos,
								   Qt::LeftButton, Qt::NoButton, keyboardModifiers);
					qt_sendSpontaneousEvent((QObject*) widget, &ev);			
				}
			}
		}
	}
}
Example #28
0
bool QPAHiddTpHandler::updateTouchEvents(QList<QPAHiddTpHandler::HiddTouch>& hiddTouches) 
{
	bool triggerTouchEvent = false;

	for (QList<HiddTouch>::iterator it = m_touches.begin(); it != m_touches.end(); ++it) {
		it->seenInScan = false;
	}

	for (int i = 0; i < hiddTouches.size(); ++i) {
		
		//int oldMetaActiveTouches = m_metaActiveTouchesCount;
	    HiddTouch& touch = hiddTouches[i];
	    if (touch.state == FingerDown) {
			addNewTouch(touch);
			triggerTouchEvent = true;
	    } else {
			if (updateOldTouch(touch))
				triggerTouchEvent = true;
	    }
/*
	    if (m_metaActiveTouchesCount && m_metaActiveTouchesCount != oldMetaActiveTouches && !oldMetaActiveTouches) {
			//QWSServer::processKeyEvent(-1, Qt::Key_CoreNavi_Meta, Qt::MetaModifier, true, false);
			HostBase::instance()->setMetaModifier(true);
		} else if (oldMetaActiveTouches && !m_metaActiveTouchesCount) {
			//QWSServer::processKeyEvent(-1, Qt::Key_CoreNavi_Meta, Qt::NoModifier, false, false);
			HostBase::instance()->setMetaModifier(false);
		}
*/

	    if (touch.gestureKey != Qt::Key_unknown) {
			if (touch.gestureKey != Qt::Key_Flick) {
				//printf ("Sending Gesture Event %d\n", touch.gestureKey);
				//QWSServer::processKeyEvent(-1, touch.gestureKey, Qt::NoModifier, true, false);
				//QWSServer::processKeyEvent(-1, touch.gestureKey, Qt::NoModifier, false, false);
			}
			if (touch.gestureKey == Qt::Key_Flick
#if !defined(TARGET_DESKTOP)
		   || touch.gestureKey == Qt::Key_CoreNavi_SwipeDown
#endif
			) {

				m_screenEdgeFlickGesture->m_edge = ScreenEdgeFlickGesture::EdgeUnknown;
				
				if (advancedGestures)/*Preferences::instance()->sysUiEnableNextPrevGestures())*/ {

					const int INVALID_COORD = 0xFFFFFFFF;
					int xDown = INVALID_COORD;
					int yDown = INVALID_COORD;

					// finding the old touch to update
					for (QList<HiddTouch>::iterator it = m_touches.begin(); it != m_touches.end(); ++it) {
						if (it->hiddId == touch.hiddId) {
							xDown = it->xDown;
							yDown = it->yDown;						
							break;
						}
					}

					if (xDown != INVALID_COORD && yDown != INVALID_COORD) {

						const int borderWidth = 25;
						const int minimumYLength = 25;

						if ((xDown < borderWidth) &&
						    (abs(touch.x) > minimumYLength) &&
							(touch.xVelocity > 0) &&
							(abs(touch.xVelocity) > abs(touch.yVelocity))) {
							printf("flick on left border. distance: %d, yDist = %d\n", abs(touch.x), touch.x - xDown);
							if((touch.x - xDown) >= minimumYLength) {
								m_screenEdgeFlickGesture->m_edge = ScreenEdgeFlickGesture::EdgeLeft;
								m_screenEdgeFlickGesture->m_yDistance = (touch.x - xDown);
							} else {
								printf("Rejected Flick\n");
							}
						}
						else if ((xDown > (m_deviceWidth - borderWidth)) &&
     							 (abs(touch.x - m_deviceWidth) > minimumYLength) &&
								 (touch.xVelocity < 0) &&
								 (abs(touch.xVelocity) > abs(touch.yVelocity))) {
							printf("flick on right border. distance: %d, yDist = %d\n", abs(touch.x - m_deviceWidth), xDown - touch.x);
							if((xDown - touch.x) >= minimumYLength){
								m_screenEdgeFlickGesture->m_edge = ScreenEdgeFlickGesture::EdgeRight;
								m_screenEdgeFlickGesture->m_yDistance = (xDown - touch.x) ;
							} else {
								printf("Rejected Flick\n");
							}
						}
						else if ((yDown < borderWidth) &&
    							 (abs(touch.y) > minimumYLength) &&
								 (touch.yVelocity > 0) &&
								 (abs(touch.yVelocity) > abs(touch.xVelocity))) {
							printf("flick on top border. distance: %d, yDist = %d\n", abs(touch.y), touch.y - yDown);
							if((touch.y - yDown) >= minimumYLength) {
								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));
						if (widget) {
							QGestureEvent gestureStartedEvent(gestureStartedList);
							QApplication::sendEvent((QObject*) widget, &gestureStartedEvent);

							flickGesture->setState(Qt::GestureFinished);
							gestureFinishedList.append(flickGesture);

							QGestureEvent gestureFinishedEvent(gestureFinishedList);
							QApplication::sendEvent((QObject*) widget, &gestureFinishedEvent);
						}
					}
				}
			}
	    
	    }

	}

	for (QList<HiddTouch>::iterator it = m_touches.begin(); it != m_touches.end(); ++it) {
		if (!it->seenInScan) {
			g_critical("%s: Finger %lld went missing. lifting it up",
					  __PRETTY_FUNCTION__, it->hiddId);
			// FIXME: this should be FingerCancel
			it->state = FingerUp;
/*
			if (it->isMetaTouch) {
				--m_metaActiveTouchesCount;			
				if (m_metaActiveTouchesCount == 0) {
					//QWSServer::processKeyEvent(-1, Qt::Key_CoreNavi_Meta, Qt::NoModifier, false, false);
					HostBase::instance()->setMetaModifier(false);
				}
			}
*/
			triggerTouchEvent = true;
		}
	}
	
	if (triggerTouchEvent) {
		generateTouchEvent();
		removeReleasedTouches();
		return true;
	}

	return false;
}
Example #29
0
bool AppletHandle::eventFilter(QObject *o, QEvent *e)
{
    if (o == parent())
    {
        switch (e->type())
        {
            case QEvent::Enter:
            {
                m_drawHandle = true;
                resetLayout();

                if (m_handleHoverTimer)
                {
                    m_handleHoverTimer->start(250);
                }
                break;
            }

            case QEvent::Leave:
            {
                if (m_menuButton && m_menuButton->isOn())
                {
                    break;
                }

                QWidget* w = dynamic_cast<QWidget*>(o);

                bool nowDrawIt = false;
                if (w)
                {
                    // a hack for applets that have out-of-process
                    // elements (e.g the systray) so that the handle
                    // doesn't flicker when moving over those elements
                    if (w->rect().contains(w->mapFromGlobal(QCursor::pos())))
                    {
                        nowDrawIt = true;
                    }
                }

                if (nowDrawIt != m_drawHandle)
                {
                    if (m_handleHoverTimer)
                    {
                        m_handleHoverTimer->stop();
                    }

                    m_drawHandle = nowDrawIt;
                    resetLayout();
                }
                break;
            }

            default:
                break;
        }

        return QWidget::eventFilter( o, e );
    }
    else if (o == m_dragBar)
    {
        if (e->type() == QEvent::MouseButtonPress)
        {
            QMouseEvent* ev = static_cast<QMouseEvent*>(e);
            if (ev->button() == LeftButton || ev->button() == MidButton)
            {
                emit moveApplet(m_applet->mapFromGlobal(ev->globalPos()));
            }
        }
    }

    if (m_menuButton && e->type() == QEvent::MouseButtonPress)
    {
        QMouseEvent* ev = static_cast<QMouseEvent*>(e);
        if (ev->button() == RightButton)
        {
            if (!m_menuButton->isDown())
            {
                m_menuButton->setDown(true);
                menuButtonPressed();
            }

            return true;
        }
    }

    return QWidget::eventFilter(o, e);    // standard event processing
}
Example #30
0
bool QDragManager::eventFilter(QObject *o, QEvent *e)
{
    if (beingCancelled) {
        if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
            qApp->removeEventFilter(this);
            Q_ASSERT(object == 0);
            beingCancelled = false;
#ifndef QT_NO_LOCALEVENTLOOP
            eventLoop->exit();
#else
            asyncDragFinished();
#endif
            return true; // block the key release
        }
        return false;
    }



    if (!o->isWidgetType())
        return false;

    switch(e->type()) {
    case QEvent::ShortcutOverride:
        // prevent accelerators from firing while dragging
        e->accept();
        return true;

    case QEvent::KeyPress:
    case QEvent::KeyRelease:
    {
        QKeyEvent *ke = ((QKeyEvent*)e);
        if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) {
            cancel();
            qApp->removeEventFilter(this);
            beingCancelled = false;
#ifndef QT_NO_LOCALEVENTLOOP
            eventLoop->exit();
#else
            asyncDragFinished();
#endif
        } else {
            updateCursor();
        }
        return true; // Eat all key events
    }

    case QEvent::MouseButtonPress:
    case QEvent::MouseMove:
    {
        if (!object) { //#### this should not happen
            qWarning("QDragManager::eventFilter: No object");
            return true;
        }

        QDragManager *manager = QDragManager::self();
        QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;
        if (manager->object)
            possible_actions =  manager->dragPrivate()->possible_actions;
        else
            possible_actions = Qt::IgnoreAction;

        QMouseEvent *me = (QMouseEvent *)e;
        if (me->buttons()) {
            Qt::DropAction prevAction = global_accepted_action;
            QWidget *cw = QApplication::widgetAt(me->globalPos());

            // Fix for when we move mouse on to the deco widget
            if (qt_qws_dnd_deco && cw == qt_qws_dnd_deco)
                cw = object->target();

            while (cw && !cw->acceptDrops() && !cw->isWindow())
                cw = cw->parentWidget();

            if (object->target() != cw) {
                if (object->target()) {
                    QDragLeaveEvent dle;
                    QApplication::sendEvent(object->target(), &dle);
                    willDrop = false;
                    global_accepted_action = Qt::IgnoreAction;
                    updateCursor();
                    restoreCursor = true;
                    object->d_func()->target = 0;
                }
                if (cw && cw->acceptDrops()) {
                    object->d_func()->target = cw;
                    QDragEnterEvent dee(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
                                        me->buttons(), me->modifiers());
                    QApplication::sendEvent(object->target(), &dee);
                    willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction;
                    global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction;
                    updateCursor();
                    restoreCursor = true;
                }
            } else if (cw) {
                QDragMoveEvent dme(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
                                   me->buttons(), me->modifiers());
                if (global_accepted_action != Qt::IgnoreAction) {
                    dme.setDropAction(global_accepted_action);
                    dme.accept();
                }
                QApplication::sendEvent(cw, &dme);
                willDrop = dme.isAccepted();
                global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction;
                updatePixmap();
                updateCursor();
            }
            if (global_accepted_action != prevAction)
                emitActionChanged(global_accepted_action);
        }
        return true; // Eat all mouse events
    }

    case QEvent::MouseButtonRelease:
    {
        qApp->removeEventFilter(this);
        if (restoreCursor) {
            willDrop = false;
#ifndef QT_NO_CURSOR
            QApplication::restoreOverrideCursor();
#endif
            restoreCursor = false;
        }
        if (object && object->target()) {
            QMouseEvent *me = (QMouseEvent *)e;

            QDragManager *manager = QDragManager::self();
            QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;

            QDropEvent de(object->target()->mapFromGlobal(me->globalPos()), possible_actions, dropData,
                          me->buttons(), me->modifiers());
            QApplication::sendEvent(object->target(), &de);
            if (de.isAccepted())
                global_accepted_action = de.dropAction();
            else
                global_accepted_action = Qt::IgnoreAction;

            if (object)
                object->deleteLater();
            drag_object = object = 0;
        }
#ifndef QT_NO_LOCALEVENTLOOP
        eventLoop->exit();
#else
        asyncDragFinished();
#endif
        return true; // Eat all mouse events
    }

    default:
        break;
    }

    return false;
}