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
Gui: support dragging of toolbar inside status/menu bar #13973
base: main
Are you sure you want to change the base?
Conversation
} | ||
} | ||
|
||
void ToolBarManager::setToolBarMovable(QToolBar *toolbar) const |
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.
Since you already added custom ToolBar
class, would it be vise to move that logic there? Having it separated can cause a lot of confusion when you don't know that you have to call this function.
I wonder if it would not be better to make this function as handler for movableChanged
signal of QToolBar: https://doc.qt.io/qt-6/qtoolbar.html#movableChanged.
At least it should have more descriptive name because for the whole review process I was sure that it calls setMovable()
in the toolbar while it does not.
@@ -756,6 +893,18 @@ void ToolBarManager::restoreState() const | |||
menuBarLeftArea->restoreState(mbLeftToolBars); | |||
} | |||
|
|||
ToolBarArea *ToolBarManager::getToolBarArea(QToolBar *toolbar) const |
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.
In #13721 I already have such method, but it does more like Qt does it so via enum. This method also covers standard Qt::ToolBarArea's: https://github.com/FreeCAD/FreeCAD/pull/13721/files#diff-dafe6a032a9dc3c2149c60fc7319fbdcda9b32e255a21185f62849cc8ba41902R438. Can you rework your code to be more inline with it so we won't have conflicts?
{ | ||
QSignalBlocker blocker(toolbar); | ||
area->removeWidget(toolbar); | ||
getMainWindow()->addToolBar(toolbar); | ||
toolbar->setWindowFlags(Qt::Tool | ||
| Qt::FramelessWindowHint | ||
| Qt::X11BypassWindowManagerHint); | ||
toolbar->adjustSize(); | ||
pos = toolbar->mapFromGlobal(pos); | ||
toolbar->move(pos.x()-10, pos.y()-10); | ||
toolbar->setVisible(true); | ||
} | ||
toolbar->topLevelChanged(true); |
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.
Since you already have custom ToolBar
class it should be some method of that class, like void float()
.
painter.setPen(Qt::transparent); | ||
painter.setOpacity(0.5); | ||
painter.setBrush(QBrush(Qt::black, Qt::Dense6Pattern)); | ||
QRect rect(this->rect()); | ||
painter.drawRect(rect); |
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.
Why is drawing of this widget different when it is not in the custom toolbar area?
void ToolBarGrip::paintEvent(QPaintEvent*) | ||
{ | ||
QPainter painter(this); | ||
if (auto toolbar = qobject_cast<QToolBar*>(parentWidget())) { |
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.
Why not ToolBar*
? You do static_cast after it anyway so you assume that it in fact is the ToolBar*
.
if (!toolbar) | ||
return; |
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 know that this classes do not have automatic code formatting enabled - but it would be nice to adhere to the formatting requested by the project.
if (sep) { | ||
if (movable) { |
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.
why not if (sep && movable)
?
area->adjustParent(); | ||
} | ||
QString name = QStringLiteral("_fc_toolbar_sep_"); | ||
auto sep = toolbar->findChild<QAction*>(name); |
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.
auto separator
- let's not use such short names, it makes code harder to read and understand.
} | ||
} | ||
else { | ||
new ToolBarGrip(toolbar); |
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.
Creating new object without assigning it to anything is a very strange construction. Probably it is fine as it has properly defined parent so Qt will take care of it but nonetheless it is quite odd - please at least put comment over it that it is intentional and how it is supposed to work.
toolbar->move(pos.x()-10, pos.y()-10); | ||
toolbar->setVisible(true); | ||
} | ||
toolbar->topLevelChanged(true); |
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.
While you don't have to mark signals with explicit Q_EMIT
it is nice at it clearly states the intention of that call. Also a comment why it is outside of the block above (to not block this signal - a bug that you have in the previous PR) would be nice as it once again is hard to quickly understand why every call is in that block and it is outside.
@realthunder thanks ! Is this issue fixed in this PR? |
I have tested the functionality and it works great. Much better than the previous 'unlock toolbar' menu. One small note : I don't know if it is possible, but if toolbars that are in the menubar/statusbar could have no top/bottom margins it would look better. |
Also I think that you may have introduced the issue #13927 when fixing the sketcher toolbar problem in #13571 I have not bisected so I'm not 100% sure but I have a build from before and one after your PR, and it the bug is only in the build after. I would guess that a preference is not initialized correctly? |
@realthunder Can you have a look at the proposed changes? Also, there are some conflicts that have to be resolved. |
Yes it would be really good if this can get in before 1.0 because it's really complementing #13571 making things more natural. |
Not in that state. This is another PR that will require a lot of refactoring after merging it. |
Hence the requested changes. Do you have more? |
Yes and no, depends on how you look at it. I did comment on the stuff that is most important and in my opinion should be changed or clarified before merging so in that way no. But I have at least twice as much questions to the PR that are less important and I decided to simply not flood this PR with comments. |
Ok, we have to wait for Realthunder’s feedback anyway. |
Alternatively, if you already knows what needs to be done (as it appears in the review you made) perhaps we can merge it and you can PR the necessary fixes @kadet1090 ? |
@PaddleStroke As long as the PR is open and non-draft, it should be considered for merging even after the freeze date. |
I am a bit busy these few days. Feel free to change the code as you like. |
I'd rather create another PR to replace this one with fixes included to not risk that it will stay like this and fight with potential conflicts that can happen due to others fixing the same piece of code (which happened with #13571). That said, I also won't have time to do that until next saturday - after that I should have more time for FreeCAD. Let's keep this open for now, like it was said - it will get merged as this is marked as ready for review so it can be merged even after the feature freeze. |
Continuation of PR #13571. @PaddleStroke