-
Notifications
You must be signed in to change notification settings - Fork 272
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
Undoable Polyline segments #1861
Conversation
I don't think this needs a specific shortcut, using backspace seems fine to me. When that's said, rather than implementing something for this specifically, why not utilize undo/redo instead? |
I think it's best to make it customizable, in case someone wants to change it (isn't that the whole point of customizable shortcuts?).
This way was much simpler to implement and follows the behavior of other software such as Photoshop (i.e. the Poly Lasso tool). Also, the whole Polyline gets applied at once when you press Enter instead of the individual points, so I don't even know if the undo system would work here. I could give it a try but if it doesn't just work I don't think I'd be willing to keep trying. This implementation is fine and works well despite being simple, and since it is such an essential functionally I rather just ship it sooner than trying to make it perfect. |
when there is only one point left, the Polyline is cancelled entirely as if pressing the Escape key.
4fef083
to
4a933f6
Compare
defaults to `Backspace` key
PR updated according to the latest changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, the shortcut does not work without being coupled to some UI element, so for now it might be OK to put it back in the edit menu.
Ideally though I think we could benefit from having a dynamic menu item that can be used to store actions of the current tool, so we don't pollute the other menu items with very specific tool actions.
Wait, what? It works fine on my end, I've honestly never noticed such behaviour.
Maybe buttons could be added to the tool options since that's already specific to the active tool? Or maybe in a section underneath it. |
And you tested it again after you removed the menu item from the Edit menu? |
It has worked before I added it and after I removed it from the menu, but I can test it one more time to be absolutely sure.
That's weird. Are you on a Linux system? Because I'm on Windows. Can you please double-check that the shortcut is set, and try to change it to something else? |
I went and made another test and changed shortcut as you asked, though it still didn't work. The documentation also mention that "Actions are added to widgets using QWidget::addAction() or QGraphicsWidget::addAction(). Note that an action must be added to a widget before it can be used. This is also true when the shortcut should be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext)." It does however work if you add actionRemoveLastPolylineSegment to the MainWindow widget by calling QWidget::addAction(...) |
Well, that's awkward. It has worked this whole time but doesn't anymore, I guess I really forgot to re-test it after removing the menu item and remembered it working before adding it because it used to be hardcoded ( Actually, I did test it again afterwards, but on a personal branch which still has it hardcoded. 😅 My sincere apologies for the confusion.
Does that add it visually as a button/menu item? Also where and how exactly would I call that? |
If it does get added somewhere, I haven't figured out where yet, so I don't think so. |
I'll try that tomorrow. I just don't know which widget to add it to. |
You can simply add it to the main window, which is also a widget, eg. MainWindow2::setupKeyboardShortcuts()
{
...
addAction(ui->removeLastPolylineSegment);
...
} |
apparently actions that are not in a menu still need to be added to some widget in order for their shortcut to work.
Fixed and re-tested, 100% working now! Thanks for the help 🙂 2024-07-25.16-06-38.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't decide whether it's okay to have an emitter meant for a specific tool in Editor, maybe it should go through ToolManager instead, yet the ToolManager feels more like a bridge to the GUI part like the toolbox, which we do not use with the shortcut specified here, so maybe it's fine?
Anyone else who wants to throw in their 2 cents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone else who wants to throw in their 2 cents?
Tbh I don’t think this requires any extra indirection at all. Just connect QAction::triggered to PolylineTool::removeLastSegment directly. MainWindow2 already connects directly to PolylineTool’s isActiveChanged signal, we can just do the same for the segment removing slot.
And unrelated, I think it would be great to add this to the help text in StatusBar::updateToolStatus as well.
Hmm ah good point, I forgot we had that one. It's been addressed now.
Yes that would be nice but it's already quite long and will truncate with the additional information. I'm not sure expanding the bottom to accommodate for that is a good idea but what other alternatives are there? Maybe we could randomize the hints 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could randomize the hints 🤔
I don’t really like that either because then the most relevant entries might be missing. GIMP uses a generic “(try Shift, Ctrl, Alt)” for cases like these, but that of course that is kinda vague. Personally, I still have some space left on my Full HD screen which looks like it’d be enough, maybe it’d be good enough to add a tooltip for smaller screens? I don’t think there’s a perfect solution anyway.
That said, I don’t want to block this PR over that. If you are also happy with the state of the PR, let’s merge.
Ah you ended up static casting to get access to the tool methods directly, I thought about that too but since we didn't do that anywhere else, I made the function virtual and accessed it through BaseTool. If you're okay with accessing it directly, then I'm okay it too. |
Yeah but I think we overuse virtual methods somewhat and it results in a bunch of interface pollution, hence why I changed it. |
This PR adds the
Remove Last Polyline Segment
shortcut, which defaults to theBackspace
key and removes individual Polyline points when pressed:2024-07-20.04-00-22.mp4
Note: if there's only one point left, it is also removed (by cancelling the Polyline as if pressing Escape).