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

Gui: support dragging of toolbar inside status/menu bar #13973

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

realthunder
Copy link
Collaborator

Continuation of PR #13571. @PaddleStroke

@github-actions github-actions bot added the Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD label May 12, 2024
}
}

void ToolBarManager::setToolBarMovable(QToolBar *toolbar) const
Copy link
Contributor

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
Copy link
Contributor

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?

Comment on lines +380 to +392
{
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);
Copy link
Contributor

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().

Comment on lines +355 to +359
painter.setPen(Qt::transparent);
painter.setOpacity(0.5);
painter.setBrush(QBrush(Qt::black, Qt::Dense6Pattern));
QRect rect(this->rect());
painter.drawRect(rect);
Copy link
Contributor

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())) {
Copy link
Contributor

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*.

Comment on lines +1212 to +1213
if (!toolbar)
return;
Copy link
Contributor

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.

Comment on lines +1231 to +1232
if (sep) {
if (movable) {
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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.

@PaddleStroke
Copy link
Contributor

PaddleStroke commented May 13, 2024

@realthunder thanks !
Btw have you seen the bug report by Syres in the previous PR? : https://forum.freecad.org/viewtopic.php?p=758767#p758767

Is this issue fixed in this PR?

@PaddleStroke
Copy link
Contributor

I have tested the functionality and it works great. Much better than the previous 'unlock toolbar' menu.

One small note :
Before with the 'Corner widget' option, the tabbar was added 'Raw' as the corner widget. Resulting in no margin on top/bottom.
Since #13571, the tabbar is now inside a toolbar, and it's the toolbar that is put as corner widget, resulting in some margins :
image

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.

@PaddleStroke
Copy link
Contributor

PaddleStroke commented May 13, 2024

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?

@FEA-eng
Copy link
Contributor

FEA-eng commented May 20, 2024

@realthunder Can you have a look at the proposed changes? Also, there are some conflicts that have to be resolved.

@PaddleStroke
Copy link
Contributor

Yes it would be really good if this can get in before 1.0 because it's really complementing #13571 making things more natural.

@kadet1090
Copy link
Contributor

Not in that state. This is another PR that will require a lot of refactoring after merging it.

@FEA-eng
Copy link
Contributor

FEA-eng commented May 20, 2024

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?

@kadet1090
Copy link
Contributor

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.

@FEA-eng
Copy link
Contributor

FEA-eng commented May 20, 2024

Ok, we have to wait for Realthunder’s feedback anyway.

@PaddleStroke
Copy link
Contributor

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 ?

@FEA-eng
Copy link
Contributor

FEA-eng commented May 20, 2024

@PaddleStroke As long as the PR is open and non-draft, it should be considered for merging even after the freeze date.

@realthunder
Copy link
Collaborator Author

I am a bit busy these few days. Feel free to change the code as you like.

@kadet1090
Copy link
Contributor

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 ?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants