Gui: Use our own ToolBar class in all places

This commit is contained in:
Kacper Donat
2024-06-15 15:08:01 +02:00
parent 214322665b
commit e04b28e66d
7 changed files with 33 additions and 12 deletions

View File

@@ -45,6 +45,7 @@
#include "Command.h"
#include "MainWindow.h"
#include "OverlayWidgets.h"
#include "WidgetFactory.h"
using namespace Gui;
@@ -175,8 +176,7 @@ ToolBar::ToolBar()
ToolBar::ToolBar(QWidget* parent)
: QToolBar(parent)
{
connect(this, &QToolBar::topLevelChanged, this, &ToolBar::updateCustomGripVisibility);
connect(this, &QToolBar::movableChanged, this, &ToolBar::updateCustomGripVisibility);
setupConnections();
}
void ToolBar::undock()
@@ -220,6 +220,12 @@ void ToolBar::updateCustomGripVisibility()
}
}
void Gui::ToolBar::setupConnections()
{
connect(this, &QToolBar::topLevelChanged, this, &ToolBar::updateCustomGripVisibility);
connect(this, &QToolBar::movableChanged, this, &ToolBar::updateCustomGripVisibility);
}
// -----------------------------------------------------------
ToolBarGrip::ToolBarGrip(QToolBar * parent)
@@ -401,6 +407,8 @@ ToolBarManager::ToolBarManager()
setupConnection();
setupTimer();
setupMenuBarTimer();
setupWidgetProducers();
}
ToolBarManager::~ToolBarManager() = default;
@@ -516,6 +524,11 @@ void ToolBarManager::setupMenuBarTimer()
});
}
void Gui::ToolBarManager::setupWidgetProducers()
{
new WidgetProducer<Gui::ToolBar>;
}
ToolBarArea ToolBarManager::toolBarArea(QWidget *widget) const
{
if (auto toolBar = qobject_cast<QToolBar*>(widget)) {
@@ -697,7 +710,7 @@ void ToolBarManager::setup(ToolBarItem* toolBarItems)
// Enable automatic handling of visibility via, for example, (contextual) menu
toolbar->toggleViewAction()->setVisible(true);
}
else {
else {
// ToolBarItem::DefaultVisibility::Unavailable
// Prevent that the action to show/hide a toolbar appears on the (contextual) menus.
// This is also managed by the client code for a toolbar with custom policy

View File

@@ -117,18 +117,23 @@ private:
* QToolBar from Qt lacks few abilities like ability to float toolbar from code.
* This class allows us to provide custom behaviors for toolbars if needed.
*/
class ToolBar: public QToolBar
class GuiExport ToolBar: public QToolBar
{
Q_OBJECT
Q_OBJECT
friend class ToolBarGrip;
public:
ToolBar(QWidget* parent);
ToolBar();
explicit ToolBar(QWidget* parent);
virtual ~ToolBar() = default;
void undock();
void updateCustomGripVisibility();
friend class ToolBarGrip;
protected:
void setupConnections();
};
/**
@@ -164,7 +169,7 @@ public:
void setState(const QList<QString>& names, State state);
void setState(const QString& name, State state);
int toolBarIconSize(QWidget *widget = nullptr) const;
void setupToolBarIconSize();
@@ -202,6 +207,8 @@ private:
void setupSizeTimer();
void setupResizeTimer();
void setupMenuBarTimer();
void setupWidgetProducers();
void addToMenu(QLayout* layout, QWidget* area, QMenu* menu);
QLayout* findLayoutOfObject(QObject* source, QWidget* area) const;
ToolBarAreaWidget* findToolBarAreaWidget() const;

View File

@@ -59,6 +59,7 @@
#include "InputField.h"
#include "QuantitySpinBox.h"
#include "PrefWidgets.h"
#include "ToolBarManager.h"
using namespace Gui;
using namespace Gui::Dialog;

View File

@@ -117,7 +117,7 @@ def setStatusIcons(show=True):
if statuswidget:
statuswidget.show()
else:
statuswidget = QtGui.QToolBar()
statuswidget = FreeCADGui.UiLoader().createWidget("Gui::ToolBar")
statuswidget.setObjectName("BIMStatusWidget")
s = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General").GetInt("ToolbarIconSize", 24)
statuswidget.setIconSize(QtCore.QSize(s,s))

View File

@@ -106,7 +106,7 @@ class BIM_IfcExplorer:
self.dialog.setObjectName("IfcExplorer")
self.dialog.setWindowTitle(translate("BIM", "Ifc Explorer"))
self.dialog.resize(720, 540)
toolbar = QtGui.QToolBar()
toolbar = FreeCADGui.UiLoader().createWidget("Gui::ToolBar")
layout = QtGui.QVBoxLayout(self.dialog)
layout.addWidget(toolbar)

View File

@@ -81,7 +81,7 @@ class BIM_Views:
size = FreeCAD.ParamGet(
"User parameter:BaseApp/Preferences/General"
).GetInt("ToolbarIconSize", 24)
toolbar = QtGui.QToolBar()
toolbar = FreeCADGui.UiLoader().createWidget("Gui::ToolBar")
toolbar.setIconSize(QtCore.QSize(size, size))
dialog.horizontalLayout.addWidget(toolbar)
for button in [

View File

@@ -205,7 +205,7 @@ class DraftToolBar:
# add only a dummy widget, since widgets are created on demand
self.baseWidget = DraftBaseWidget()
self.tray = QtWidgets.QToolBar(None)
self.tray = FreeCADGui.UiLoader().createWidget("Gui::ToolBar")
self.tray.setObjectName("Draft tray")
self.tray.setWindowTitle("Draft tray")
self.toptray = self.tray