diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-12-19 17:17:01 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-01-08 10:53:59 +0000 |
commit | 98fbaa4110d848451594422441b0e930c3f1ada5 (patch) | |
tree | f425f8eb11096a08d9b608e85e975cde3157f200 | |
parent | e1c176ca0b10008a9a79068ff4ef1575d9a2ba4c (diff) |
Qt Designer: Simplify top level geometry calculation
Pass the available geometry to QDesignerToolWindow::geometryHint()
which allows for removing some functions.
Task-number: QTBUG-120236
Change-Id: Id37ff342fa380b6789312124834180b5f01833ac
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
(cherry picked from commit 6aa71e6259dbf88d8d236f72020d265ddd48adfd)
(cherry picked from commit 6182239e52579cf58299c10a5e9392beaed8a64a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/designer/src/designer/qdesigner_toolwindow.cpp | 44 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_toolwindow.h | 4 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_workbench.cpp | 5 |
3 files changed, 16 insertions, 37 deletions
diff --git a/src/designer/src/designer/qdesigner_toolwindow.cpp b/src/designer/src/designer/qdesigner_toolwindow.cpp index a0368f13d..cbbb7bd33 100644 --- a/src/designer/src/designer/qdesigner_toolwindow.cpp +++ b/src/designer/src/designer/qdesigner_toolwindow.cpp @@ -113,16 +113,6 @@ QDesignerWorkbench *QDesignerToolWindow::workbench() const return m_workbench; } -QRect QDesignerToolWindow::geometryHint() const -{ - return QRect(); -} - -QRect QDesignerToolWindow::availableToolWindowGeometry() const -{ - return m_workbench->availableGeometry(); -} - // ---------------------- PropertyEditorToolWindow static inline QWidget *createPropertyEditor(QDesignerFormEditorInterface *core, QWidget *parent = nullptr) @@ -137,7 +127,7 @@ class PropertyEditorToolWindow : public QDesignerToolWindow public: explicit PropertyEditorToolWindow(QDesignerWorkbench *workbench); - QRect geometryHint() const override; + QRect geometryHint(const QRect &) const override; protected: void showEvent(QShowEvent *event) override; @@ -155,9 +145,8 @@ PropertyEditorToolWindow::PropertyEditorToolWindow(QDesignerWorkbench *workbench } -QRect PropertyEditorToolWindow::geometryHint() const +QRect PropertyEditorToolWindow::geometryHint(const QRect &g) const { - const QRect g = availableToolWindowGeometry(); const int spacing = 40; const QSize sz(g.width() * 1/4, g.height() * 4/6); @@ -193,7 +182,7 @@ class ActionEditorToolWindow: public QDesignerToolWindow public: explicit ActionEditorToolWindow(QDesignerWorkbench *workbench); - QRect geometryHint() const override; + QRect geometryHint(const QRect &g) const override; }; ActionEditorToolWindow::ActionEditorToolWindow(QDesignerWorkbench *workbench) : @@ -206,10 +195,8 @@ ActionEditorToolWindow::ActionEditorToolWindow(QDesignerWorkbench *workbench) : { } -QRect ActionEditorToolWindow::geometryHint() const +QRect ActionEditorToolWindow::geometryHint(const QRect &g) const { - const QRect g = availableToolWindowGeometry(); - const QSize sz(g.width() * 1/4, g.height() * 1/6); const QRect rc = QRect((g.right() + 1 - sz.width() - margin), @@ -234,7 +221,7 @@ class ObjectInspectorToolWindow: public QDesignerToolWindow public: explicit ObjectInspectorToolWindow(QDesignerWorkbench *workbench); - QRect geometryHint() const override; + QRect geometryHint(const QRect &g) const override; }; ObjectInspectorToolWindow::ObjectInspectorToolWindow(QDesignerWorkbench *workbench) : @@ -247,10 +234,8 @@ ObjectInspectorToolWindow::ObjectInspectorToolWindow(QDesignerWorkbench *workben { } -QRect ObjectInspectorToolWindow::geometryHint() const +QRect ObjectInspectorToolWindow::geometryHint(const QRect &g) const { - const QRect g = availableToolWindowGeometry(); - const QSize sz(g.width() * 1/4, g.height() * 1/6); const QRect rc = QRect((g.right() + 1 - sz.width() - margin), @@ -268,7 +253,7 @@ class ResourceEditorToolWindow: public QDesignerToolWindow public: explicit ResourceEditorToolWindow(QDesignerWorkbench *workbench); - QRect geometryHint() const override; + QRect geometryHint(const QRect &g) const override; }; ResourceEditorToolWindow::ResourceEditorToolWindow(QDesignerWorkbench *workbench) : @@ -281,10 +266,8 @@ ResourceEditorToolWindow::ResourceEditorToolWindow(QDesignerWorkbench *workbench { } -QRect ResourceEditorToolWindow::geometryHint() const +QRect ResourceEditorToolWindow::geometryHint(const QRect &g) const { - const QRect g = availableToolWindowGeometry(); - const QSize sz(g.width() * 1/3, g.height() * 1/6); QRect r(QPoint(0, 0), sz); r.moveCenter(g.center()); @@ -301,7 +284,7 @@ class SignalSlotEditorToolWindow: public QDesignerToolWindow public: explicit SignalSlotEditorToolWindow(QDesignerWorkbench *workbench); - QRect geometryHint() const override; + QRect geometryHint(const QRect &g) const override; }; SignalSlotEditorToolWindow::SignalSlotEditorToolWindow(QDesignerWorkbench *workbench) : @@ -314,10 +297,8 @@ SignalSlotEditorToolWindow::SignalSlotEditorToolWindow(QDesignerWorkbench *workb { } -QRect SignalSlotEditorToolWindow::geometryHint() const +QRect SignalSlotEditorToolWindow::geometryHint(const QRect &g) const { - const QRect g = availableToolWindowGeometry(); - const QSize sz(g.width() * 1/3, g.height() * 1/6); QRect r(QPoint(0, 0), sz); r.moveCenter(g.center()); @@ -341,7 +322,7 @@ class WidgetBoxToolWindow: public QDesignerToolWindow public: explicit WidgetBoxToolWindow(QDesignerWorkbench *workbench); - QRect geometryHint() const override; + QRect geometryHint(const QRect &g) const override; }; WidgetBoxToolWindow::WidgetBoxToolWindow(QDesignerWorkbench *workbench) : @@ -354,9 +335,8 @@ WidgetBoxToolWindow::WidgetBoxToolWindow(QDesignerWorkbench *workbench) : { } -QRect WidgetBoxToolWindow::geometryHint() const +QRect WidgetBoxToolWindow::geometryHint(const QRect &g) const { - const QRect g = availableToolWindowGeometry(); const QRect rc = QRect(g.left() + margin, g.top() + margin, g.width() * 1/4, g.height() * 5/6); diff --git a/src/designer/src/designer/qdesigner_toolwindow.h b/src/designer/src/designer/qdesigner_toolwindow.h index 07424c544..405ef624c 100644 --- a/src/designer/src/designer/qdesigner_toolwindow.h +++ b/src/designer/src/designer/qdesigner_toolwindow.h @@ -61,7 +61,7 @@ public: QAction *action() const; Qt::DockWidgetArea dockWidgetAreaHint() const { return m_dockAreaHint; } - virtual QRect geometryHint() const; + virtual QRect geometryHint(const QRect &availableGeometry) const = 0; private slots: void showMe(bool); @@ -71,8 +71,6 @@ protected: void hideEvent(QHideEvent *e) override; void changeEvent(QEvent *e) override; - QRect availableToolWindowGeometry() const; - private: const Qt::DockWidgetArea m_dockAreaHint; QDesignerWorkbench *m_workbench; diff --git a/src/designer/src/designer/qdesigner_workbench.cpp b/src/designer/src/designer/qdesigner_workbench.cpp index 4a498ac5f..3de355750 100644 --- a/src/designer/src/designer/qdesigner_workbench.cpp +++ b/src/designer/src/designer/qdesigner_workbench.cpp @@ -452,7 +452,8 @@ void QDesignerWorkbench::switchToTopLevelMode() Q_ASSERT(widgetBoxWrapper); switchToNeutralMode(); - const QPoint desktopOffset = desktopGeometry().topLeft(); + const QRect availableGeometry = desktopGeometry(); + const QPoint desktopOffset = availableGeometry.topLeft(); m_mode = TopLevelMode; // The widget box is special, it gets the menubar and gets to be the main widget. @@ -491,7 +492,7 @@ void QDesignerWorkbench::switchToTopLevelMode() bool found_visible_window = false; for (QDesignerToolWindow *tw : std::as_const(m_toolWindows)) { tw->setParent(magicalParent(tw), magicalWindowFlags(tw)); - settings.restoreGeometry(tw, tw->geometryHint()); + settings.restoreGeometry(tw, tw->geometryHint(availableGeometry)); tw->action()->setChecked(tw->isVisible()); found_visible_window |= tw->isVisible(); } |