Esempio n. 1
0
void Link::paint(QPainter *painter,
    const QStyleOptionGraphicsItem *style, QWidget *widget) {

    if(m_from.isNull() || m_to.isNull()) return;

    if(m_selected) painter->setPen(QPen(QBrush(Qt::green), 3.0));
    else painter->setPen(QPen(QBrush(Qt::darkGreen), 3.0));

    QLineF line(m_from->pos() + m_from->boundingRect().center(),
        m_to->pos() + m_to->boundingRect().center());
    painter->drawLine(line);

    painter->setPen(QPen(QBrush(Qt::blue), 5.0));
    QPointF line13 = (line.p1()*2+line.p2())/3;
    QPointF line23 = (line.p1()+line.p2()*2)/3;
    auto arrow1 = QLineF::fromPolar(15.0, line.angle() - 135);
    auto arrow2 = QLineF::fromPolar(15.0, line.angle() + 135);
    painter->drawLine(arrow1.translated(line13));
    painter->drawLine(arrow2.translated(line13));
    painter->drawLine(arrow1.translated(line23));
    painter->drawLine(arrow2.translated(line23));

    auto tbr = labelBoundingRect();

    painter->setPen(Qt::lightGray);
    if(m_selected) painter->setBrush(QBrush(Qt::yellow, Qt::SolidPattern));
    else painter->setBrush(QBrush(Qt::lightGray, Qt::SolidPattern));
    painter->drawRect(tbr);

    if(m_rtsLink) painter->setPen(QPen(QBrush(Qt::darkRed), 3.0));
    else painter->setPen(QPen(QBrush(Qt::red), 3.0));
    painter->drawText(tbr.center() - QPointF(tbr.width()/2, -4), m_label);
}
Esempio n. 2
0
void QWidgetWindow::handleDragEnterMoveEvent(QDragMoveEvent *event)
{
     Q_ASSERT(event->type() ==QEvent::DragMove || !m_dragTarget);
    // Find a target widget under mouse that accepts drops (QTBUG-22987).
    QWidget *widget = m_widget->childAt(event->pos());
    if (!widget)
        widget = m_widget;
    for ( ; widget && !widget->isWindow() && !widget->acceptDrops(); widget = widget->parentWidget()) ;
    if (widget && !widget->acceptDrops())
        widget = 0;
    // Target widget unchanged: DragMove
    if (widget && widget == m_dragTarget.data()) {
        Q_ASSERT(event->type() == QEvent::DragMove);
        const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos()));
        QDragMoveEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
        translated.setDropAction(event->dropAction());
        if (event->isAccepted()) { // Handling 'DragEnter' should suffice for the application.
            translated.accept();
            translated.setDropAction(event->dropAction());
        }
        QGuiApplication::sendSpontaneousEvent(widget, &translated);
        if (translated.isAccepted()) {
            event->accept();
        } else {
            event->ignore();
        }
        event->setDropAction(translated.dropAction());
        return;
    }
    // Target widget changed: Send DragLeave to previous, DragEnter to new if there is any
    if (m_dragTarget.data()) {
        QDragLeaveEvent le;
        QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &le);
        m_dragTarget = 0;
    }
    if (!widget) {
         event->ignore();
         return;
    }
    m_dragTarget = widget;
    const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos()));
    QDragEnterEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
    QGuiApplication::sendSpontaneousEvent(widget, &translated);
    if (translated.isAccepted()) {
        event->accept();
    } else {
        event->ignore();
    }
    event->setDropAction(translated.dropAction());
}
Esempio n. 3
0
        bool DesktopWindowManager::HandleMouseEvent(
            view::Widget* widget, const view::MouseEvent& event)
        {
            if(mouse_capture_)
            {
                view::MouseEvent translated(event, widget->GetRootView(),
                    mouse_capture_->GetRootView());
                mouse_capture_->OnMouseEvent(translated);
                return true;
            }

            if(event.type() == ui::ET_MOUSE_PRESSED)
            {
                ActivateWidgetAtLocation(widget, event.location());
            }
            else if(event.type()==ui::ET_MOUSEWHEEL && active_widget_)
            {
                return active_widget_->OnMouseEvent(event);
            }

            if(window_controller_.get())
            {
                if(!window_controller_->OnMouseEvent(event))
                {
                    ReleaseMouseCapture();
                    window_controller_.reset();
                }
                return true;
            }

            return false;
        }
Esempio n. 4
0
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);
}
Esempio n. 5
0
RS_Vector LC_MakerCamSVG::convertToSvg(RS_Vector vector) const
{

    RS_Vector translated((vector.x - min.x), (max.y - vector.y));

    return translated + offset;
}
const AffineTransform AffineTransform::rotated (const float angle,
                                                const float pivotX,
                                                const float pivotY) const throw()
{
    return translated (-pivotX, -pivotY)
            .rotated (angle)
            .translated (pivotX, pivotY);
}
Esempio n. 7
0
void DENORM::LocalNormTransform(const FCOORD& pt, FCOORD* transformed) const {
  FCOORD translated(pt.x() - x_origin_, pt.y() - YOriginAtOrigX(pt.x()));
  translated.set_x(translated.x() * x_scale_);
  translated.set_y(translated.y() * YScaleAtOrigX(pt.x()));
  if (rotation_ != NULL)
    translated.rotate(*rotation_);
  transformed->set_x(translated.x() + final_xshift_);
  transformed->set_y(translated.y() + final_yshift_);
}
Esempio n. 8
0
void QWidgetWindow::handleDropEvent(QDropEvent *event)
{
    const QPoint mapped = m_dragTarget.data()->mapFromGlobal(m_widget->mapToGlobal(event->pos()));
    QDropEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
    QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &translated);
    if (translated.isAccepted())
        event->accept();
    event->setDropAction(translated.dropAction());
    m_dragTarget = 0;
}
void QSpaceNavigatorClient::update()
{
	SpaceNavigatorClient::update();
	if (_unconsumedData)
	{
		_unconsumedData = false;
		double x, y, z, rx, ry, rz;
		getTranslation(x, y, z);
		getRotation(rx, ry, rz);
		//emit updated(x, y, z, rx, ry, rz);
		emit translated(x, y, z);
	}
}
void PageStackComponent::transitionIn(Component *component, Transition transition,
                                      int durationMillis, bool reverse) {
  addAndMakeVisible(component);
  auto bounds = getLocalBounds();
  switch (transition) {
    case kTransitionTranslateHorizontal: {
      float dir = reverse ? -1.0f : 1.0f;
      component->setBounds(bounds.translated(bounds.getWidth() * dir, 0));
      animateTranslation(component, 0, 0, 1.0f, durationMillis);
      break;
    } case kTransitionTranslateHorizontalLeft: {
      float dir = reverse ? 1.0f : -1.0f;
      component->setBounds(bounds.translated(bounds.getWidth() * dir, 0));
      animateTranslation(component, 0, 0, 1.0f, durationMillis);
    } break;
    default: {
      component->setBounds(bounds);
      component->setVisible(true);
    }
  }

  component->setEnabled(true);
}
Esempio n. 11
0
void QWidgetWindow::handleDropEvent(QDropEvent *event)
{
    if (m_dragTarget.isNull()) {
        qWarning() << Q_FUNC_INFO << m_widget << ": No drag target set.";
        event->ignore();
        return;
    }
    const QPoint mapped = m_dragTarget.data()->mapFromGlobal(m_widget->mapToGlobal(event->pos()));
    QDropEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
    QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &translated);
    if (translated.isAccepted())
        event->accept();
    event->setDropAction(translated.dropAction());
    m_dragTarget = 0;
}
Esempio n. 12
0
void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
{
    if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
        return;

    // which child should have it?
    QWidget *widget = m_widget->childAt(event->pos());

    if (!widget)
        widget = m_widget;

    QPoint mapped = widget->mapFrom(m_widget, event->pos());

    QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase());
    QGuiApplication::sendSpontaneousEvent(widget, &translated);
}
Esempio n. 13
0
void DENORM::LocalNormTransform(const FCOORD& pt, FCOORD* transformed) const {
  FCOORD translated(pt.x() - x_origin_, pt.y() - y_origin_);
  if (x_map_ != NULL && y_map_ != NULL) {
    int x = ClipToRange(IntCastRounded(translated.x()), 0, x_map_->size()-1);
    translated.set_x((*x_map_)[x]);
    int y = ClipToRange(IntCastRounded(translated.y()), 0, y_map_->size()-1);
    translated.set_y((*y_map_)[y]);
  } else {
    translated.set_x(translated.x() * x_scale_);
    translated.set_y(translated.y() * y_scale_);
    if (rotation_ != NULL)
      translated.rotate(*rotation_);
  }
  transformed->set_x(translated.x() + final_xshift_);
  transformed->set_y(translated.y() + final_yshift_);
}
Esempio n. 14
0
void MainWindowList::avoidSuperimposedWindows (MainWindow* const mw)
{
    for (int i = windows.size(); --i >= 0;)
    {
        auto* other = windows.getUnchecked(i);

        auto b1 = mw->getBounds();
        auto b2 = other->getBounds();

        if (mw != other
             && std::abs (b1.getX() - b2.getX()) < 3
             && std::abs (b1.getY() - b2.getY()) < 3
             && std::abs (b1.getRight()  - b2.getRight()) < 3
             && std::abs (b1.getBottom() - b2.getBottom()) < 3)
        {
            int dx = 40, dy = 30;

            if (b1.getCentreX() >= mw->getScreenBounds().getCentreX())   dx = -dx;
            if (b1.getCentreY() >= mw->getScreenBounds().getCentreY())   dy = -dy;

            mw->setBounds (b1.translated (dx, dy));
        }
    }
}
Esempio n. 15
0
void Mat4::translate(const Vec4 &dv) {
    *this = translated(dv);
}
Esempio n. 16
0
void EditFrame::mouseMoveEvent(QMouseEvent *event)
{
	if( m_MouseDown )
	{
		bool snap = !event->modifiers().testFlag(Qt::ShiftModifier);
		QWidget *pParent = parentWidget();
		QWidget *pGrandParent = (pParent ? pParent->parentWidget() : 0);
		if( pGrandParent )
		{
			switch( m_GeomMode )
			{
				case GEOM_MODE_TOP:
					{
						int dy = (m_MouseGrabGeometry.y() - m_MouseGrabOffset.y());
						int y = (pGrandParent->mapFromGlobal(event->globalPos()).y() + dy);
						if( snap )
							Utils::Snap(ToyWindowTab::GRID_SPACING, y);
						
						if(y < 0)
						{
							y = 0;
						}
						else
						{
							int maxY = (pParent->geometry().bottom() - pParent->minimumHeight());
							if(y > maxY)
								y = maxY;
						}
						
						int dh = (pParent->y() - y);
						pParent->move(pParent->x(), y);
						pParent->resize(pParent->width(), pParent->height() + dh);
						resize( pParent->size() );
						emit grabbed(this);
					}
					break;
					
				case GEOM_MODE_BOTTOM:
					{
						int dy = (m_MouseGrabGeometry.bottom() - m_MouseGrabOffset.y());
						int y = (pGrandParent->mapFromGlobal(event->globalPos()).y() + dy);
						if( snap )
							Utils::Snap(ToyWindowTab::GRID_SPACING, y);
						
						int newHeight = (y - pParent->y());
						if(newHeight < pParent->minimumHeight())
						{
							newHeight = pParent->minimumHeight();
						}
						else
						{
							int maxHeight = (pGrandParent->height() - pParent->y());
							if(newHeight > maxHeight)
								newHeight = maxHeight;
						}
						
						pParent->resize(pParent->width(), newHeight);
						resize( pParent->size() );
						emit grabbed(this);
					}
					break;
					
				case GEOM_MODE_LEFT:
					{
						int dx = (m_MouseGrabGeometry.x() - m_MouseGrabOffset.x());
						int x = (pGrandParent->mapFromGlobal(event->globalPos()).x() + dx);
						if( snap )
							Utils::Snap(ToyWindowTab::GRID_SPACING, x);
						
						if(x < 0)
						{
							x = 0;
						}
						else
						{
							int maxX = (pParent->geometry().right() - pParent->minimumWidth());
							if(x > maxX)
								x = maxX;
						}
						
						int dw = (pParent->x() - x);
						pParent->move(x, pParent->y());
						pParent->resize(pParent->width() + dw, pParent->height());
						resize( pParent->size() );
						emit grabbed(this);
					}
					break;
					
				case GEOM_MODE_RIGHT:
					{
						int dx = (m_MouseGrabGeometry.right() - m_MouseGrabOffset.x());
						int x = (pGrandParent->mapFromGlobal(event->globalPos()).x() + dx);
						if( snap )
							Utils::Snap(ToyWindowTab::GRID_SPACING, x);
						
						int newWidth = (x - pParent->x());
						if(newWidth < pParent->minimumWidth())
						{
							newWidth = pParent->minimumWidth();
						}
						else
						{
							int maxWidth = (pGrandParent->width() - pParent->x());
							if(newWidth > maxWidth)
								newWidth = maxWidth;
						}
						
						pParent->resize(newWidth, pParent->height());
						resize( pParent->size() );
						emit grabbed(this);
					}
					break;
					
				case GEOM_MODE_SCALE:
					{
						float w = m_MouseGrabGeometry.width();
						if(w != 0)
						{
							float ar = m_MouseGrabGeometry.height()/w;
							if(ar != 0)
							{
								// same behavior as GEOM_MODE_RIGHT
								int dx = (m_MouseGrabGeometry.right() - m_MouseGrabOffset.x());
								int x = (pGrandParent->mapFromGlobal(event->globalPos()).x() + dx);
								if( snap )
									Utils::Snap(ToyWindowTab::GRID_SPACING, x);
								
								int newWidth = (x - pParent->x());
								if(newWidth < pParent->minimumWidth())
								{
									newWidth = pParent->minimumWidth();
								}
								else
								{
									int maxWidth = (pGrandParent->width() - pParent->x());
									if(newWidth > maxWidth)
										newWidth = maxWidth;
								}
								
								// adjust height, preseving aspect ratio
								int newHeight = qRound(newWidth * ar);
								if(newHeight < pParent->minimumHeight())
								{
									newHeight = pParent->minimumHeight();
									newWidth = qRound(newHeight/ar);
								}
								else
								{
									int maxHeight = (pGrandParent->height() - pParent->y());
									if(newHeight > maxHeight)
									{
										newHeight = maxHeight;
										newWidth = qRound(newHeight/ar);
									}
								}
								
								pParent->resize(newWidth, newHeight);
								resize( pParent->size() );
								emit grabbed(this);
							}
						}
					}
					break;
					
				default:
					{
						QPoint newPos(pGrandParent->mapFromGlobal(event->globalPos()) - m_MouseGrabOffset);
						if( snap )
							Utils::Snap(ToyWindowTab::GRID_SPACING, newPos);

						QPoint delta = (newPos - pParent->pos());
						if(delta.x()!=0 || delta.y()!=0)
							emit translated(this, delta);
						
						emit grabbed(this);
					}
					break;
			}
		}
	}
	else
		SetGeomMode( GetGeomModeForPos(event->pos()) );
}
Esempio n. 17
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();
        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();
                    }

                    QWindow *win = w->windowHandle();
                    if (!win)
                        win = w->nativeParentWidget()->windowHandle();
                    if (win) {
                        const QRect globalGeometry = win->isTopLevel()
                            ? win->geometry()
                            : QRect(win->mapToGlobal(QPoint(0, 0)), win->size());
                        if (globalGeometry.contains(event->globalPos())) {
                            // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec()
                            const QPoint localPos = win->mapFromGlobal(event->globalPos());
                            QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(),
                                                             event->button(), event->buttons(), event->modifiers(), event->source());
                            QCoreApplicationPrivate::setEventSpontaneous(e, true);
                            e->setTimestamp(event->timestamp());
                            QCoreApplication::postEvent(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 = activePopupWidget;
            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(), event->source());
        translated.setTimestamp(event->timestamp());
        QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget,
                                            &qt_button_down, qt_last_mouse_receiver);
        event->setAccepted(translated.isAccepted());
    }
#ifndef QT_NO_CONTEXTMENU
    if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton
        && m_widget->rect().contains(event->pos())) {
        QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
        QGuiApplication::sendSpontaneousEvent(receiver, &e);
    }
#endif
}
Esempio n. 18
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
}
Esempio n. 19
0
bool translation::operator<( const translation &that ) const
{
    return translated() < that.translated();
}
Esempio n. 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
}
Esempio n. 21
0
bool translation::operator==( const translation &that ) const
{
    return translated() == that.translated();
}
LayerTriangulation::LayerTriangulation(const std::vector<Point2D> &points)
{

    std::vector<int> indices(points.size(), 0);
    // Set up indices
    for (int index = 0; index < indices.size(); ++index) {
        indices[index] = index;
    }

    int origin_i = selectOrigin(points);
    std::swap(indices[0], indices[origin_i]);

    // Select the origin
    Point2D origin = points[indices[0]];

    // Calculate points in translated coordinate system
    std::vector<Point2D> translated(points.size(), Point2D());
    std::transform(points.begin(), points.end(), translated.begin(), [&origin](const Point2D &point) {
        return point - origin;
    });

    // Sort points counterclockwise
    std::sort(indices.begin() + 1, indices.end(), [&translated](int i1, int i2) {
        double angle0 = atan2(translated[i1].y, translated[i1].x), angle1 = atan2(translated[i2].y, translated[i2].x);
        return angle0 < angle1 || (equal(angle0, angle1) && translated[i1].norm() < translated[i2].norm());
    });

    // Extract layers
    std::vector<int> inner;
    do {
        inner.clear(); // Clear inner indices vector
        // Perform Graham scan

        if (layers.size() == 0)
            grahamScan0(indices, points, inner);
        else
            grahamScan1(indices, points, inner);

        // Debug print
        //print(layers.back(), points);

        indices.resize(inner.size());
        std::copy(inner.begin(), inner.end(), indices.begin());

    } while (indices.size() > 1);

    // Find the lowest point for each layer
    for (int layer_i = 0; layer_i < layers.size(); ++layer_i) {
        findLowestPoints(layer_i, points);
    }

    // Perform triangulation
    for (int layer_i = 1; layer_i < layers.size(); ++layer_i) {
        std::cout << layers[layer_i].size() << std::endl;
        triangulate1(layer_i - 1, layer_i, points);
    }

    // Triangulate the last layer if it is possible
    traingluateLastLayer(points);

}
Esempio n. 23
0
void SectionDrawable::draw(Graphics& graphicsRef, const Vector2f& position) {
	Vector2fPtr translated(&(position + *mPosOffset));
	graphicsRef.renderTexture(mTexture, translated->x, translated->y, width, height, mColor->r, mColor->g, mColor->b, mColor->a);
}
Esempio n. 24
0
//
// void translated(v)
// Last modified: 04Sep2006
//
// Translates the vector display based on the
// parameterized translation vector.
//
// Returns:     <none>
// Parameters:
//      v       in      the translation transformation vector
//
void Vector::translated(const Vector &v)
{
    translated(v.x, v.y, v.z);
}   // translated(const Vector &)
Esempio n. 25
0
void LeakDetectable::EndMallocSampling(std::string &dumps, int cutoff) {
  if (MallocSampling == 0) return;

  // grouping
  std::map<std::string, LeakStats> leaked_stacks;
  {
    // turn off hooks
    Lock lock(sampling_mutex);
#ifdef GOOGLE_HEAP_PROFILER
    MallocHook::SetNewHook(NULL);
    MallocHook::SetDeleteHook(NULL);
#endif

    time_t cutoff_time = time(NULL) - cutoff;
    for (SamplingMap::iterator iter =
           sampling_traces.begin(); iter != sampling_traces.end(); ++iter) {
      if (iter->second.time > cutoff_time) continue; // too new

      StackTrace &st = *iter->second.st;
      string hash = st.hexEncode(4, StackTraceGroupLevel + 4);
      LeakStats &stats = leaked_stacks[hash];
      if (stats.count++ == 0) {
        stats.hash = hash;
        stats.totalSize = 0;
      }
      stats.totalSize += iter->second.size;
      if (stats.examples.size() < 5) {
        stats.examples.push_back(st.hexEncode());
      }
    }
    sampling_traces.clear();
  }

  // sorting
  vector<LeakStats*> stats;
  stats.reserve(leaked_stacks.size());
  for (std::map<std::string, LeakStats>::iterator iter =
         leaked_stacks.begin(); iter != leaked_stacks.end(); ++iter) {
    stats.push_back(&iter->second);
  }
  sort(stats.begin(), stats.end(), SortByCount);

  // reporting
  int totalLeaked = 0;
  int totalGroup = 0;
  for (unsigned int i = 0; i < stats.size(); i++) {
    LeakStats *stat = stats[i];
    string translated("");
    if (RuntimeOption::TranslateLeakStackTrace) {
      translated = translate_stack(stat->hash.c_str());
    }
    if (!SuppressStackTrace(translated)) {
      totalLeaked += stat->count;
      totalGroup++;

      dumps += "---------------------------------------------------------\n";
      dumps += lexical_cast<string>(i + 1) + ". Leaked ";
      dumps += lexical_cast<string>(stat->count) + " objects ";
      dumps += lexical_cast<string>(stat->totalSize) + " bytes, ";
      dumps += stat->hash + ":\n\n";
      for (unsigned int j = 0; j < stat->examples.size(); j++) {
        dumps += "  (";
        dumps += lexical_cast<string>(j + 1) + ") ";
        dumps += stat->examples[j] + "\n";
      }
      dumps += "\n";
      dumps += translated;
    }
  }
  dumps += "---------------------------------------------------------\n";
  dumps += "Total Leaked " + lexical_cast<string>(totalLeaked);
  dumps += " in " + lexical_cast<string>(totalGroup) + " groups.\n";
}
Esempio n. 26
0
//Helper function for making local coordinates global
vector3 LocalToWorld(vector3 vec3, matrix4 mat4World){
	vector4 vec4(vec3.x, vec3.y, vec3.z, 1);
	vector4 vec4Translated = mat4World * vec4;
	vector3 translated(vec4Translated.x, vec4Translated.y, vec4Translated.z);
	return translated;
}