void Graph::mousePressEvent( QMouseEvent * _me ) { if( _me->button() == Qt::LeftButton ) { if ( !( _me->modifiers() & Qt::ShiftModifier ) ) { // get position int x = _me->x(); int y = _me->y(); changeSampleAt( x, y ); // toggle mouse state m_mouseDown = true; setCursor( Qt::BlankCursor ); m_lastCursorX = x; } else { //when shift-clicking, draw a line from last position to current //position int x = _me->x(); int y = _me->y(); drawLineAt( x, y, m_lastCursorX ); m_mouseDown = true; setCursor( Qt::BlankCursor ); m_lastCursorX = x; } } }
void Graph::mouseMoveEvent ( QMouseEvent * _me ) { // get position int x = _me->x(); int y = _me->y(); /* static bool skip = false; if( skip ) { skip = false; return; } */ // avoid mouse leaps int diff = x - m_lastCursorX; /* if( diff >= 1 ) { x = qMin( width() - 3, m_lastCursorX + 1 ); } else if( diff <= -1 ) { x = qMax( 2, m_lastCursorX - 1 ); }*/ x = qMax( 2, qMin( x, width()-3 ) ); y = qMax( 2, qMin( y, height()-3 ) ); if( qAbs( diff ) > 1 ) { drawLineAt( x, y, m_lastCursorX ); } else { changeSampleAt( x, y ); } // update mouse if( diff != 0 ) { m_lastCursorX = x; QPoint pt = mapToGlobal( QPoint( x, y ) ); QCursor::setPos( pt.x(), pt.y() ); } // skip = true; }
void graph::mousePressEvent( QMouseEvent * _me ) { if( _me->button() == Qt::LeftButton ) { // toggle mouse state m_mouseDown = true; // get position int x = _me->x(); int y = _me->y(); changeSampleAt( x, y ); // toggle mouse state m_mouseDown = true; setCursor( Qt::BlankCursor ); m_lastCursorX = x; } }