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

Replace explicit library home/end key handlers with a moveCursor override #11100

Merged
merged 4 commits into from
Jan 10, 2023

Conversation

robbert-vdh
Copy link
Contributor

By simply overriding the cursor movement function instead of adding an explicit key event the home and end keys in the library table view now interact as expected with other hotkeys and cursor actions. Shift+End now select all items through the end of the list, and Ctrl+Home jumps to the first item without selecting it so it can be toggled on and off with Space.

Tagging @ronso0 since they suggested it in #11090. Sorry that it took so long (since making this actual change only took a minute heh). Had a busy weekend. Once either of these PRs are merged I'll rebase the other one and refactor the moveCursor() function a bit.

@github-actions github-actions bot added the ui label Nov 29, 2022
@robbert-vdh robbert-vdh changed the title Replace library home/end key handlers with cursors Replace explicit library home/end key handlers with a moveCursor override Nov 29, 2022
@ronso0
Copy link
Member

ronso0 commented Dec 6, 2022

Thank you, LGTM

It's just I'd prefer to have all keyhandling methods in one class, probably WTrackTableView.
@robbert-vdh Do you mind moving moveCursor() there, somewhere near keyPressEvent?

@robbert-vdh
Copy link
Contributor Author

Wouldn't it make more sense to merge WLibraryTableView and WTrackTableView if the former is only used as a superclass for the latter? I can still move the function if you prefer that instead of merging the classes. I thought it'd make sense to override the behavior as far down in the inheritance stack as possible but I didn't consider that WLibraryTableView is only ever used as a superclass for WTrackTableView.

Comment on lines 266 to 267
// By default the home and end keys move to the first and last column rather
// than the first and last row
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to read that a few times to figure you describe what is overridden, not the new implementation. Let's rephrase it:

Suggested change
// By default the home and end keys move to the first and last column rather
// than the first and last row
// Make the home and end keys move to the first and last row rather than
// the first and last column (QAbstractItemView default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll change that. Btw, I'm not the only one who does this ha. if you grep for By default you'll get 46 other matches.

@ronso0
Copy link
Member

ronso0 commented Dec 6, 2022

... if you prefer that instead of merging the classes.

I'd prefer merging, but as I wrote in #11090 I'd love to hear an opinion from an 'older' team member on that topic before anyone spends time on this.

robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 6, 2022
@robbert-vdh
Copy link
Contributor Author

Oh and the focus in event handler is also overridden in WLibraryTableView. Should I move just moveCursor()? Or move both (sounds like that would be out of scope for this PR)? Or will you move them after this is merged?

By simply overriding the cursor movement function instead of adding an
explicit key event the home and end keys in the library table view now
interact as expected with other hotkeys and cursor actions. Shift+End
now select all items through the end of the list, and Ctrl+Home jumps to
the first item without selecting it so it can be toggled on and off with
Space.
@robbert-vdh robbert-vdh force-pushed the fix/library-home-end-cursors branch from 3e309ae to 4ba3a4e Compare December 8, 2022 13:02
@robbert-vdh
Copy link
Contributor Author

Rebased on top of the changes from the just merged #11090.

@ronso0 ronso0 self-requested a review December 9, 2022 00:14
@ronso0 ronso0 added the library label Dec 9, 2022
@ronso0 ronso0 added this to the 2.4.0 milestone Dec 9, 2022
Copy link
Member

@ronso0 ronso0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, works as expected. Just some comments.

Comment on lines 297 to 311
// Selecting a hidden column doesn't work, so we'll need to find
// the first non-hidden column here
int column = 0;
while (isColumnHidden(column) && column < pModel->columnCount()) {
column++;
}

// If the cursor does not yet exist (because the view has not
// yet been interacted with) then this selects the first/last
// row
if (cursorAction == QAbstractItemView::MoveDown) {
return pModel->index(0, column);
} else {
return pModel->index(pModel->rowCount() - 1, column);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the second comment is actually more relevant for this else branch, so maybe this is more clear?

Suggested change
// Selecting a hidden column doesn't work, so we'll need to find
// the first non-hidden column here
int column = 0;
while (isColumnHidden(column) && column < pModel->columnCount()) {
column++;
}
// If the cursor does not yet exist (because the view has not
// yet been interacted with) then this selects the first/last
// row
if (cursorAction == QAbstractItemView::MoveDown) {
return pModel->index(0, column);
} else {
return pModel->index(pModel->rowCount() - 1, column);
}
// If the cursor does not yet exist (because the view has not
// yet been interacted with) then this selects the first/last
// row
int row = 0; // MoveDown
if (cursorAction == QAbstractItemView::MoveUp) {
row = pModel->rowCount() - 1;
}
// Selecting a hidden column doesn't work, so we'll need to find
// the first non-hidden column here
int column = 0;
while (isColumnHidden(column) && column < pModel->columnCount()) {
column++;
}
return pModel->index(row, column);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (cursorAction == QAbstractItemView::MoveDown) {
if (row + 1 < pModel->rowCount()) {
return pModel->index(row + 1, column);
if (pModel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early return if !pModel? Probably a matter of taste, but it reduces the indentation below.

Suggested change
if (pModel) {
if (!pModel) {
return QTableView::moveCursor(cursorAction, modifiers);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I didn't want to repeat the base case. Felt this was similar to something like a Win32 window procedure where you fall back to the default behavior if you didn't return early.

// or the user needs to reach for the mouse or keyboard when moving
// between 12/C#m/E and 1/G#m/B. This is very similar to
// `moveSelection()`, except that it doesn't actually modify the
// selection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... only with Ctrl modifier , no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the function never moves the selection. It just returns a new cursor, which is then used by the AbstractItemView class to do something based on which modifiers are pressed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yeah, that's what I mean. Worth noting I'd say

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ronso0
Copy link
Member

ronso0 commented Dec 11, 2022

I merged this into my personal branch and experienced some issues last night with mixed keyboard and controller navigation but couldn't investigate further at that time:

  • scroll around with [Library], MoveVertical
  • select a track
  • hold Shift
  • press Home or End

would not give my the expected selection but less.
I'll try to reproduce again soonish.

robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 11, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 11, 2022
@robbert-vdh
Copy link
Contributor Author

  • scroll around with [Library], MoveVertical
  • select a track
  • hold Shift
  • press Home or End

I just tried this and naively moving the cursor with a my controller and then pressing Shift+Home on my keyboard seems to work as expected. I'll see if I can find a situation where it doesn't.

@ronso0
Copy link
Member

ronso0 commented Dec 11, 2022

I merged this into my personal branch and experienced some issues last night with mixed keyboard and controller navigation but couldn't investigate further at that time:

Oh, sorry, I merged only main with the Up/Down wraparound.
Will test this again.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works and looks good.
Thank you.

I have just noticed the inversion of the selection when crossing the list boundaries.
Not sure if this is worth a fix. At least this is unrelated to this PR.

@ronso0 do you want to do more tests or reviews before merge?

@ronso0
Copy link
Member

ronso0 commented Dec 13, 2022

Yes, I'd like to double-check, though it'll take a few days until I get back to my controller.

robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 13, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 13, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 14, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 14, 2022
Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks good, thank you.

robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 15, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 15, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 18, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 18, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 19, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 19, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 21, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 21, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 25, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 25, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 29, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Dec 29, 2022
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Jan 2, 2023
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Jan 2, 2023
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Jan 4, 2023
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Jan 4, 2023
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Jan 8, 2023
robbert-vdh added a commit to robbert-vdh/mixxx that referenced this pull request Jan 8, 2023
@daschuer daschuer requested a review from ronso0 January 10, 2023 09:19
@daschuer
Copy link
Member

@ronso0 Did you find time for the double check?

@ronso0
Copy link
Member

ronso0 commented Jan 10, 2023

I didn't explicitly check (tbh I forgot..) but seems I had this already merged into my personal branch and I didn't encounter issues last times I used that live.

Thanks @robbert-vdh for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants