Implemented piano roll drag vertical scroll line shifting logic for Qt GUI.

This commit is contained in:
mjbudd77 2021-12-27 20:11:48 -05:00
parent 58b093e549
commit 7f97f2fd4b
2 changed files with 92 additions and 3 deletions

View File

@ -3786,7 +3786,9 @@ QPianoRoll::QPianoRoll(QWidget *parent)
wheelPixelCounter = 0; wheelPixelCounter = 0;
headerItemUnderMouse = 0; headerItemUnderMouse = 0;
nextHeaderUpdateTime = 0; nextHeaderUpdateTime = 0;
rightButtonDragMode = false;
mouse_x = mouse_y = -1; mouse_x = mouse_y = -1;
scroll_x = scroll_y = 0;
memset( headerColors, 0, sizeof(headerColors) ); memset( headerColors, 0, sizeof(headerColors) );
headerLightsColors[ 0] = QColor( 0x00, 0x00, 0x00 ); headerLightsColors[ 0] = QColor( 0x00, 0x00, 0x00 );
@ -4208,7 +4210,7 @@ void QPianoRoll::updateLinesCount(void)
// update the number of items in the list // update the number of items in the list
int movie_size = currMovieData.getNumRecords(); int movie_size = currMovieData.getNumRecords();
maxLineOffset = movie_size - viewLines + 5; maxLineOffset = movie_size - viewLines + 2;
if ( maxLineOffset < 0 ) if ( maxLineOffset < 0 )
{ {
@ -4258,7 +4260,7 @@ void QPianoRoll::resizeEvent(QResizeEvent *event)
viewLines = (viewHeight / pxLineSpacing) + 1; viewLines = (viewHeight / pxLineSpacing) + 1;
maxLineOffset = currMovieData.records.size() - viewLines + 5; maxLineOffset = currMovieData.records.size() - viewLines + 2;
if ( maxLineOffset < 0 ) if ( maxLineOffset < 0 )
{ {
@ -5426,6 +5428,89 @@ void QPianoRoll::handleColumnSet(int column, bool altPressed)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void QPianoRoll::periodicUpdate(void) void QPianoRoll::periodicUpdate(void)
{ {
// scroll Piano Roll if user is dragging cursor outside
if ( (dragMode != DRAG_MODE_NONE) || rightButtonDragMode)
{
int x, y, line, col, scroll_up_threshold, scroll_down_threshold;
QPoint p, c;
x = mouse_x;
y = mouse_y;
p.setX(x);
p.setY(y);
c = convPixToCursor(p);
if ( c.y() >= 0 )
{
line = lineOffset + c.y();
}
else
{
line = lineOffset;
}
col = calcColumn( c.x() );
rowUnderMouse = realRowUnderMouse = line;
columnUnderMouse = col;
scroll_up_threshold = pxLineSpacing;
scroll_down_threshold = (viewHeight - pxLineSpacing/2);
//if (dragMode != DRAG_MODE_MARKER) // in DRAG_MODE_MARKER user can't scroll Piano Roll horizontally
//{
// if (p.x < DRAG_SCROLLING_BORDER_SIZE)
// scroll_dx = p.x - DRAG_SCROLLING_BORDER_SIZE;
// else if (p.x > (wrect.right - wrect.left - DRAG_SCROLLING_BORDER_SIZE))
// scroll_dx = p.x - (wrect.right - wrect.left - DRAG_SCROLLING_BORDER_SIZE);
//}
if (y < scroll_up_threshold )
{
scroll_y += (scroll_up_threshold - y);
if ( scroll_y > pxLineSpacing )
{
int d, v = vbar->value();
d = scroll_y / pxLineSpacing;
v += d; scroll_y = 0;
if ( v > maxLineOffset )
{
v = maxLineOffset;
}
vbar->setValue(v);
}
}
else if (y > scroll_down_threshold)
{
scroll_y += (scroll_down_threshold - y);
if ( scroll_y < -pxLineSpacing )
{
int d, v = vbar->value();
d = scroll_y / pxLineSpacing;
v += d; scroll_y = 0;
if ( v < 0 )
{
v = 0;
}
vbar->setValue(v);
}
}
}
else
{
scroll_x = scroll_y = 0;
}
updateDrag();
// once per 40 milliseconds update colors alpha in the Header // once per 40 milliseconds update colors alpha in the Header
if (clock() > nextHeaderUpdateTime) if (clock() > nextHeaderUpdateTime)
{ {
@ -5481,6 +5566,7 @@ void QPianoRoll::periodicUpdate(void)
update(); update();
} }
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void QPianoRoll::setLightInHeaderColumn(int column, int level) void QPianoRoll::setLightInHeaderColumn(int column, int level)
@ -5879,7 +5965,7 @@ void QPianoRoll::paintEvent(QPaintEvent *event)
viewLines = nrow; viewLines = nrow;
maxLineOffset = currMovieData.records.size() - nrow + 5; maxLineOffset = currMovieData.records.size() - nrow + 2;
if ( maxLineOffset < 0 ) if ( maxLineOffset < 0 )
{ {

View File

@ -241,12 +241,15 @@ class QPianoRoll : public QWidget
int wheelPixelCounter; int wheelPixelCounter;
int headerItemUnderMouse; int headerItemUnderMouse;
int nextHeaderUpdateTime; int nextHeaderUpdateTime;
int scroll_x;
int scroll_y;
int mouse_x; int mouse_x;
int mouse_y; int mouse_y;
int playbackCursorPos; int playbackCursorPos;
bool useDarkTheme; bool useDarkTheme;
bool rightButtonDragMode;
public slots: public slots:
void hbarChanged(int val); void hbarChanged(int val);