From dd67d5a78960990690d3cf725e598be168436919 Mon Sep 17 00:00:00 2001 From: Rodney Date: Jan 27 2023 00:13:26 +0000 Subject: Merge pull request #4718 from justburner/PanelFixWidthMode Panel FixWidth mode + Level Palette option to not auto adjust width --- diff --git a/toonz/sources/include/toonzqt/paletteviewer.h b/toonz/sources/include/toonzqt/paletteviewer.h index 2610109..69507c9 100644 --- a/toonz/sources/include/toonzqt/paletteviewer.h +++ b/toonz/sources/include/toonzqt/paletteviewer.h @@ -140,6 +140,9 @@ protected: QAction *m_visibleGizmoAction; QAction *m_visibleNameAction; + bool m_variableWidth; + QAction *m_variableWidthAct; + protected: void createTabBar(); @@ -208,6 +211,8 @@ protected slots: void toggleNewStylePageVisibility(bool); void togglePaletteGizmoVisibility(bool); void toggleNameEditorVisibility(bool); + + void toggleVariableWidth(bool); }; #endif // PALETTEVIEWER_H diff --git a/toonz/sources/toonz/filmstrip.cpp b/toonz/sources/toonz/filmstrip.cpp index 6dbaf89..a6675b8 100644 --- a/toonz/sources/toonz/filmstrip.cpp +++ b/toonz/sources/toonz/filmstrip.cpp @@ -1920,7 +1920,8 @@ void Filmstrip::setOrientation(bool isVertical) { m_frameArea->horizontalScrollBar()->setObjectName("LevelStripScrollBar"); } m_frames->setOrientation(m_isVertical); - dynamic_cast(parentWidget())->setCanFixWidth(m_isVertical); + dynamic_cast(parentWidget()) + ->setFixWidthMode(m_isVertical ? TPanel::sizeable : TPanel::variable); } // SaveLoadQSettings diff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cpp index f3e677b..00889eb 100644 --- a/toonz/sources/toonz/tpanels.cpp +++ b/toonz/sources/toonz/tpanels.cpp @@ -659,6 +659,7 @@ public: TPanel *createPanel(QWidget *parent) override { PaletteViewerPanel *panel = new PaletteViewerPanel(parent); + panel->setFixWidthMode(TPanel::sizeable); panel->setObjectName(getPanelType()); panel->setWindowTitle(QObject::tr(("Level Palette"))); @@ -942,6 +943,7 @@ public: TPanel *createPanel(QWidget *parent) override { StyleEditorPanel *panel = new StyleEditorPanel(parent); + panel->setFixWidthMode(TPanel::sizeable); panel->setObjectName(getPanelType()); panel->setWindowTitle(QObject::tr("Style Editor")); return panel; @@ -961,6 +963,7 @@ public: ToolbarFactory() : TPanelFactory("ToolBar") {} void initialize(TPanel *panel) override { Toolbar *toolbar = new Toolbar(panel); + panel->setFixWidthMode(TPanel::fixed); panel->setWidget(toolbar); panel->setIsMaximizable(false); // panel->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea); diff --git a/toonz/sources/toonzqt/docklayout.cpp b/toonz/sources/toonzqt/docklayout.cpp index b2d2c93..11781bf 100644 --- a/toonz/sources/toonzqt/docklayout.cpp +++ b/toonz/sources/toonzqt/docklayout.cpp @@ -430,6 +430,7 @@ bool Region::checkWidgetsToBeFixedWidth(std::vector &widgets, m_item->clearWasFloating(); return false; } + /* if ((m_item->objectName() == "FilmStrip" && m_item->getCanFixWidth()) || m_item->objectName() == "StyleEditor") { widgets.push_back(m_item); @@ -438,6 +439,16 @@ bool Region::checkWidgetsToBeFixedWidth(std::vector &widgets, return true; } else return false; + */ + switch (m_item->getFixWidthMode()) { + case 2: + widgets.push_back(m_item); + // fallthrough + case 1: + return true; + default: + return false; + } } if (m_childList.empty()) return false; // for horizontal orientation, return true if all items are to be fixed @@ -465,6 +476,8 @@ bool Region::checkWidgetsToBeFixedWidth(std::vector &widgets, void DockLayout::redistribute() { if (!m_regions.empty()) { std::vector widgets; + std::vector minSizes; + std::vector maxSizes; // Recompute extremal region sizes // NOTA: Sarebbe da fare solo se un certo flag lo richiede; altrimenti tipo @@ -478,7 +491,11 @@ void DockLayout::redistribute() { bool widgetsCanBeFixedWidth = !m_regions.front()->checkWidgetsToBeFixedWidth(widgets, fromDocking); if (!fromDocking && widgetsCanBeFixedWidth) { - for (QWidget *widget : widgets) widget->setFixedWidth(widget->width()); + for (QWidget *widget : widgets) { + minSizes.push_back(widget->minimumSize()); + maxSizes.push_back(widget->maximumSize()); + widget->setFixedWidth(widget->width()); + } } m_regions.front()->calculateExtremalSizes(); @@ -499,10 +516,16 @@ void DockLayout::redistribute() { m_regions.front()->redistribute(); if (!fromDocking && widgetsCanBeFixedWidth) { + /* for (QWidget *widget : widgets) { widget->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); widget->setMinimumSize(0, 0); } + */ + for (int i = 0; i < widgets.size(); ++i) { + widgets[i]->setMinimumSize(minSizes[i]); + widgets[i]->setMaximumSize(maxSizes[i]); + } } } diff --git a/toonz/sources/toonzqt/docklayout.h b/toonz/sources/toonzqt/docklayout.h index c279874..f168851 100644 --- a/toonz/sources/toonzqt/docklayout.h +++ b/toonz/sources/toonzqt/docklayout.h @@ -171,8 +171,13 @@ class DVAPI DockWidget : public QFrame { public: void maximizeDock(); - bool getCanFixWidth() { return m_canFixWidth; } - void setCanFixWidth(bool fixed) { m_canFixWidth = fixed; } + enum { + variable = 0, // default, docked panel may auto resize with window + fixed = 1, // to be used with setFixedWidth() + sizeable = 2 // allow panel to be sizeable but doesn't auto resize + }; + int getFixWidthMode() { return m_modeFixWidth; } + void setFixWidthMode(int fixedmode) { m_modeFixWidth = fixedmode; } protected: // Private attributes for dragging purposes @@ -194,7 +199,9 @@ protected: // window resize to minimize user frustration // This variable is only used by Level Strip right now. // This is only true if the level strip is vertical. - bool m_canFixWidth = false; + // + // Edit: Implementation changed to avoid hardcoded checks with panels names + int m_modeFixWidth = 0; private: QPoint m_dragInitialPos; diff --git a/toonz/sources/toonzqt/dockwidget.cpp b/toonz/sources/toonzqt/dockwidget.cpp index e70040d..1f20b4e 100644 --- a/toonz/sources/toonzqt/dockwidget.cpp +++ b/toonz/sources/toonzqt/dockwidget.cpp @@ -113,6 +113,7 @@ DockWidget::DockWidget(QWidget *parent, Qt::WindowFlags flags) , m_undocking(false) , m_parentLayout(0) , m_selectedPlace(0) + , m_modeFixWidth(0) , m_maximized(0) { // Don't let this widget inherit the parent's background color // setAutoFillBackground(true); diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cpp index 9f711c3..83c0ed4 100644 --- a/toonz/sources/toonzqt/paletteviewer.cpp +++ b/toonz/sources/toonzqt/paletteviewer.cpp @@ -12,6 +12,7 @@ #include "toonzqt/styleselection.h" #include "toonzqt/stylenameeditor.h" #include "palettedata.h" +#include "docklayout.h" // TnzLib includes #include "toonz/palettecmd.h" @@ -123,6 +124,7 @@ PaletteViewer::PaletteViewer(QWidget *parent, PaletteViewType viewType, , m_showToolbarOnTopAct(nullptr) , m_toolbarContainer(0) , m_styleNameEditor(nullptr) + , m_variableWidth(true) , m_hLayout(0) { setObjectName("OnePixelMarginFrame"); setFrameStyle(QFrame::StyledPanel); @@ -259,6 +261,18 @@ void PaletteViewer::toggleNameEditorVisibility(bool checked) { //----------------------------------------------------------------------------- +void PaletteViewer::toggleVariableWidth(bool checked) { + m_variableWidth = checked; + + DockWidget *dock = dynamic_cast(parentWidget()); + if (dock) { + dock->setFixWidthMode(checked ? DockWidget::variable + : DockWidget::sizeable); + } +} + +//----------------------------------------------------------------------------- + void PaletteViewer::save(QSettings &settings) const { int toolbarOnTop = m_toolbarOnTop ? 1 : 0; settings.setValue("toolbarOnTop", toolbarOnTop); @@ -268,6 +282,8 @@ void PaletteViewer::save(QSettings &settings) const { if (m_visibleGizmoAction->isChecked()) visibleParts |= 0x04; if (m_visibleNameAction->isChecked()) visibleParts |= 0x08; settings.setValue("toolbarVisibleMsk", visibleParts); + int variableWidth = m_variableWidth ? 1 : 0; + settings.setValue("variableWidth", variableWidth); } void PaletteViewer::load(QSettings &settings) { @@ -293,6 +309,9 @@ void PaletteViewer::load(QSettings &settings) { applyToolbarPartVisibility(TBVisNewStylePage, visibleParts & 0x02); applyToolbarPartVisibility(TBVisPaletteGizmo, visibleParts & 0x04); applyToolbarPartVisibility(TBVisNameEditor, visibleParts & 0x08); + + bool variableWidth = settings.value("variableWidth", m_variableWidth).toInt() != 0; + toggleVariableWidth(variableWidth); } //----------------------------------------------------------------------------- @@ -507,6 +526,16 @@ void PaletteViewer::createPaletteToolBar() { viewMode->addSeparator(); + // Docked panels will automatically adjust width based of the window size + m_variableWidthAct = new QAction(tr("Auto Adjust Panel Width")); + m_variableWidthAct->setCheckable(true); + m_variableWidthAct->setChecked(m_variableWidth); + viewMode->addAction(m_variableWidthAct); + connect(m_variableWidthAct, SIGNAL(toggled(bool)), this, + SLOT(toggleVariableWidth(bool))); + + viewMode->addSeparator(); + // Add ability to show or hide buttons QMenu *visibleButtons = new QMenu(tr("Visible Toolbar Buttons")); @@ -834,6 +863,7 @@ void PaletteViewer::mousePressEvent(QMouseEvent *event) { void PaletteViewer::showEvent(QShowEvent *) { onPaletteSwitched(); changeWindowTitle(); + toggleVariableWidth(m_variableWidth); if (!m_paletteHandle) return;