Ejemplo n.º 1
0
void OpenGLWindow::internalMouseButton( int button, int state, int x, int y )
{
    MouseButton stdButton = glutToStdMouseButton(button);
    MouseButtonState stdState = glutToStdMouseButtonState(state);
    mouseButtonState[stdButton] = stdState;
    mouseButton(stdButton, stdState, x, y);
    mouseLastX = x;
    mouseLastY = y;
}
Ejemplo n.º 2
0
void InputSimulator::processInput(const std::string &input) {
    std::vector<std::string> tokens;
    std::stringstream ssin(input);
    while (ssin.good()) {
        std::string value;
        ssin >> value;
        tokens.push_back(value);
    }
    if (tokens.size() >= 3) {
        if (tokens[0] == "Mouse" && tokens.size() == 4) {
            if (tokens[1] == "Move" ) {
                try {
                    int x = std::stoi(tokens[2]);
                    int y = std::stoi(tokens[3]);
                    moveMouse(x, y);
                } catch (std::invalid_argument) {}
            }
            else if (tokens[1] == "Button") {
                bool down = tokens[3] == "Down";
                if (tokens[2] == "Left") {
                    mouseButton(1, down);
                }
                else if (tokens[2] == "Right") {
                    mouseButton(3, down);
                }
            }
        }
        else if (tokens[0] == "KeyPress" && tokens.size() == 3) {
            try {
                bool down = tokens[1] == "Down";
                unsigned int keycode = (unsigned int) std::stoi(tokens[2]);
                key(keycode, down);
            } catch (std::invalid_argument) {}
        }
    }
}
// private
void kpAbstractSelectionTool::beginDrawMove ()
{
    d->startMoveDragFromSelectionTopLeft =
        currentPoint () - document ()->selection ()->topLeft ();

    if (mouseButton () == 0)
    {
        /*virtual*/setSelectionBorderForBeginDrawMove ();
    }
    else
    {
        // Don't hide sel border momentarily if user is just
        // right _clicking_ selection.
        // (single shot timer)
        d->RMBMoveUpdateGUITimer->start (100/*ms*/);
    }

    setUserMessage (cancelUserMessage ());
}
Ejemplo n.º 4
0
void kpTool::mousePressEvent (QMouseEvent *e)
{
#if DEBUG_KP_TOOL && 1
    kdDebug () << "kpTool::mousePressEvent pos=" << e->pos ()
               << " btnStateBefore=" << (int) e->state ()
               << " btnStateAfter=" << (int) e->stateAfter ()
               << " button=" << (int) e->button ()
               << " beganDraw=" << m_beganDraw << endl;
#endif

    // state of all the buttons - not just the one that triggered the event (button())
    Qt::ButtonState buttonState = e->stateAfter ();

    if (m_mainWindow && e->button () == Qt::MidButton)
    {
        const QString text = QApplication::clipboard ()->text (QClipboard::Selection);
    #if DEBUG_KP_TOOL && 1
        kdDebug () << "\tMMB pasteText='" << text << "'" << endl;
    #endif
        if (!text.isEmpty ())
        {
            if (hasBegunShape ())
            {
            #if DEBUG_KP_TOOL && 1
                kdDebug () << "\t\thasBegunShape - end" << endl;
            #endif
                endShapeInternal (m_currentPoint,
                                  QRect (m_startPoint, m_currentPoint).normalize ());
            }

            if (viewUnderCursor ())
            {
                m_mainWindow->pasteTextAt (text,
                    viewUnderCursor ()->transformViewToDoc (e->pos ()),
                    true/*adjust topLeft so that cursor isn't
                          on top of resize handle*/);
            }

            return;
        }
    }

    int mb = mouseButton (buttonState);
#if DEBUG_KP_TOOL && 1
    kdDebug () << "\tmb=" << mb << " m_beganDraw=" << m_beganDraw << endl;
#endif

    if (mb == -1 && !m_beganDraw) return; // ignore

    if (m_beganDraw)
    {
        if (mb == -1 || mb != m_mouseButton)
        {
        #if DEBUG_KP_TOOL && 1
            kdDebug () << "\tCancelling operation as " << mb << " == -1 or != " << m_mouseButton << endl;
        #endif

            kpView *view = viewUnderStartPoint ();
            if (!view)
            {
                kdError () << "kpTool::mousePressEvent() cancel without a view under the start point!" << endl;
            }

            // if we get a mousePressEvent when we're drawing, then the other
            // mouse button must have been pressed
            m_currentPoint = view ? view->transformViewToDoc (e->pos ()) : QPoint (-1, -1);
            m_currentViewPoint = view ? e->pos () : QPoint (-1, -1);
            cancelShapeInternal ();
        }

        return;
    }

    kpView *view = viewUnderCursor ();
    if (!view)
    {
        kdError () << "kpTool::mousePressEvent() without a view under the cursor!" << endl;
    }

#if DEBUG_KP_TOOL && 1
    if (view)
        kdDebug () << "\tview=" << view->name () << endl;
#endif


    // let user know what mouse button is being used for entire draw
    m_mouseButton = mouseButton (buttonState);
    m_shiftPressed = (buttonState & Qt::ShiftButton);
    m_controlPressed = (buttonState & Qt::ControlButton);
    m_altPressed = (buttonState & Qt::AltButton);
    m_startPoint = m_currentPoint = view ? view->transformViewToDoc (e->pos ()) : QPoint (-1, -1);
    m_currentViewPoint = view ? e->pos () : QPoint (-1, -1);
    m_viewUnderStartPoint = view;
    m_lastPoint = QPoint (-1, -1);

#if DEBUG_KP_TOOL && 1
    kdDebug () << "\tBeginning draw @ " << m_currentPoint << endl;
#endif

    beginDrawInternal ();

    draw (m_currentPoint, m_lastPoint, QRect (m_currentPoint, m_currentPoint));
    m_lastPoint = m_currentPoint;
}
Ejemplo n.º 5
0
void GraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
    QPoint p(event->globalPos());
    emit mouseReleased(p);
    emit mouseButton(event->button());
}