Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Fix Command Bar grip initialization and layout refresh

Rodneyf41cf2782ac3
diff --git a/toonz/sources/toonz/commandbar.cpp b/toonz/sources/toonz/commandbar.cpp
index 31684cb20..ba5476172 100644
--- a/toonz/sources/toonz/commandbar.cpp
+++ b/toonz/sources/toonz/commandbar.cpp
@@ -25,6 +25,8 @@
#include <QMenuBar>
#include <QContextMenuEvent>
#include <QActionGroup>
+#include <QLayout>
+#include <QShowEvent>
//=============================================================================
// Toolbar
@@ -181,6 +183,15 @@ void CommandBar::contextMenuEvent(QContextMenuEvent *event) {
//-----------------------------------------------------------------------------
+void CommandBar::showEvent(QShowEvent *event) {
+ QToolBar::showEvent(event);
+ // The toolbar is constructed before setWidget() attaches it to its panel.
+ // Apply the grip constraints once that parent and its geometry are available.
+ if (!m_isXsheetToolbar) onOrientationChanged(orientation());
+}
+
+//-----------------------------------------------------------------------------
+
void CommandBar::save(QSettings &settings) const {
if (m_isXsheetToolbar) return;
settings.setValue(QStringLiteral("orientation"),
@@ -287,6 +298,16 @@ void CommandBar::onOrientationChanged(Qt::Orientation orientation) {
if (titleBar) titleBar->updateGeometry();
updateGeometry();
panel->updateGeometry();
+ // Orientation changes alter both the toolbar and the panel's title-bar
+ // constraints. Resolve both layouts before the next paint.
+ if (layout()) {
+ layout()->invalidate();
+ layout()->activate();
+ }
+ if (panel->layout()) {
+ panel->layout()->invalidate();
+ panel->layout()->activate();
+ }
}
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/toonz/commandbar.h b/toonz/sources/toonz/commandbar.h
index 255f565e5..c384adce9 100644
--- a/toonz/sources/toonz/commandbar.h
+++ b/toonz/sources/toonz/commandbar.h
@@ -15,6 +15,7 @@
// forward declaration
class QAction;
+class QShowEvent;
//=============================================================================
// CommandBar
@@ -40,6 +41,7 @@ protected:
static void fillToolbar(CommandBar *toolbar, bool isXsheetToolbar = false);
static void buildDefaultToolbar(CommandBar *toolbar);
void contextMenuEvent(QContextMenuEvent *event) override;
+ void showEvent(QShowEvent *event) override;
protected slots:
void doCustomizeCommandBar();