Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve mouse pointer in piano roll editor #3065

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ protected slots:

bool m_mouseDownLeft; //true if left click is being held down
bool m_mouseDownRight; //true if right click is being held down
bool m_mouseInPianoRoll; //true if mouse is the edit area

TimeLineWidget * m_timeLine;
bool m_scrollBack;
Expand All @@ -359,6 +360,7 @@ protected slots:
void drawDetuningInfo( QPainter & _p, const Note * _n, int _x, int _y ) const;
bool mouseOverNote();
Note * noteUnderMouse();
void setMousePointer();

// turn a selection rectangle into selected notes
void computeSelectedNotes( bool shift );
Expand All @@ -381,6 +383,7 @@ protected slots:
QColor m_markedSemitoneColor;
int m_noteOpacity;
bool m_noteBorders;
QPixmap * m_cursor;

signals:
void positionChanged( const MidiTime & );
Expand Down
101 changes: 71 additions & 30 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ PianoRoll::PianoRoll() :
m_editMode( ModeDraw ),
m_mouseDownLeft( false ),
m_mouseDownRight( false ),
m_mouseInPianoRoll( false ),
m_scrollBack( false ),
m_gridColor( 0, 0, 0 ),
m_noteModeColor( 0, 0, 0 ),
Expand All @@ -199,7 +200,8 @@ PianoRoll::PianoRoll() :
m_textShadow( 0, 0, 0 ),
m_markedSemitoneColor( 0, 0, 0 ),
m_noteOpacity( 255 ),
m_noteBorders( true )
m_noteBorders( true ),
m_cursor( NULL )
{
// gui names of edit modes
m_nemStr.push_back( tr( "Note Velocity" ) );
Expand Down Expand Up @@ -1257,6 +1259,9 @@ void PianoRoll::leaveEvent(QEvent * e )
QApplication::restoreOverrideCursor();
}

m_mouseDownRight = false;
m_mouseInPianoRoll = false;
update();
QWidget::leaveEvent( e );
s_textFloat->hide();
}
Expand Down Expand Up @@ -1577,8 +1582,8 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
m_action = ActionMoveNote;

// set move-cursor
QCursor c( Qt::SizeAllCursor );
QApplication::setOverrideCursor( c );
// QCursor c( Qt::SizeAllCursor );
// QApplication::setOverrideCursor( c );

// if they're holding shift, copy all selected notes
if( ! is_new_note && me->modifiers() & Qt::ShiftModifier )
Expand Down Expand Up @@ -1974,29 +1979,42 @@ void PianoRoll::mouseReleaseEvent( QMouseEvent * me )

void PianoRoll::mouseMoveEvent( QMouseEvent * me )
{
if( ! hasValidPattern() )
if( !hasValidPattern() )
{
update();
return;
}

if( me->x() > WHITE_KEY_WIDTH
&& me->x() < width() - PR_RIGHT_MARGIN - 2
&& me->y() < height() - PR_BOTTOM_MARGIN - m_notesEditHeight )
{
m_mouseInPianoRoll = true;
}
else
{
m_mouseInPianoRoll = false;
}

setMousePointer();

if( m_action == ActionNone && me->buttons() == 0 )
{
if( me->y() > keyAreaBottom() && me->y() < noteEditTop() )
{
QApplication::setOverrideCursor(
QCursor( Qt::SizeVerCursor ) );
setCursor( Qt::SizeVerCursor );
return;
}
}
else if( m_action == ActionResizeNoteEditArea )
{
// change m_notesEditHeight and then repaint
setCursor( Qt::SizeVerCursor );
m_notesEditHeight = tLimit<int>(
m_oldNotesEditHeight - ( me->y() - m_moveStartY ),
NOTE_EDIT_MIN_HEIGHT,
height() - PR_TOP_MARGIN - NOTE_EDIT_RESIZE_BAR -
PR_BOTTOM_MARGIN - KEY_AREA_MIN_HEIGHT );
PR_BOTTOM_MARGIN - KEY_AREA_MIN_HEIGHT );
repaint();
return;
}
Expand Down Expand Up @@ -3080,32 +3098,40 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
p.fillRect( QRect( 0, keyAreaBottom(),
width()-PR_RIGHT_MARGIN, NOTE_EDIT_RESIZE_BAR ), horizCol );

const QPixmap * cursor = NULL;
m_cursor = NULL;
// draw current edit-mode-icon below the cursor
switch( m_editMode )
{
case ModeDraw:
if( m_mouseDownRight )
{
cursor = s_toolErase;
}
else if( m_action == ActionMoveNote )
{
cursor = s_toolMove;
}
else
{
cursor = s_toolDraw;
}
break;
case ModeErase: cursor = s_toolErase; break;
case ModeSelect: cursor = s_toolSelect; break;
case ModeEditDetuning: cursor = s_toolOpen; break;
}
if( cursor != NULL )
{
p.drawPixmap( mapFromGlobal( QCursor::pos() ) + QPoint( 8, 8 ),
*cursor );
case ModeDraw:
if( m_mouseDownRight )
{
m_cursor = s_toolErase;
}
else if( m_action == ActionMoveNote )
{
m_cursor = s_toolMove;
}
else
{
m_cursor = s_toolDraw;
}
setMousePointer();
break;
case ModeErase: m_cursor = s_toolErase; break;
case ModeSelect:
m_cursor = NULL;
if( m_mouseInPianoRoll )
{
p.drawPixmap( mapFromGlobal( QCursor::pos() ) + QPoint( 13, 13 ), *s_toolSelect );
}
break;
case ModeEditDetuning:
m_cursor = NULL;
if( m_mouseInPianoRoll )
{
p.drawPixmap( mapFromGlobal( QCursor::pos() ) + QPoint( 13, 13 ), *s_toolOpen );
}
break;
}
}

Expand Down Expand Up @@ -3993,6 +4019,21 @@ Note * PianoRoll::noteUnderMouse()



void PianoRoll::setMousePointer()
{
if( m_cursor && m_mouseInPianoRoll )
{
setCursor( QCursor( *m_cursor, 0, m_cursor->height() ) );
}
else
{
setCursor( Qt::ArrowCursor );
}
}




PianoRollWindow::PianoRollWindow() :
Editor(true),
m_editor(new PianoRoll())
Expand Down