Skip to content

Commit

Permalink
Merge pull request #3379 from turtletooth/floating
Browse files Browse the repository at this point in the history
Don't Set Fixed Width if Docking a Floating Panel
  • Loading branch information
RodneyBaker committed Jul 4, 2020
2 parents 26a2b2f + e07f530 commit 6bc9e75
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
26 changes: 18 additions & 8 deletions toonz/sources/toonzqt/docklayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,15 @@ void DockLayout::applyTransform(const QTransform &transform) {

//------------------------------------------------------
// check if the region will be with fixed width
bool Region::checkWidgetsToBeFixedWidth(std::vector<QWidget *> &widgets) {
bool Region::checkWidgetsToBeFixedWidth(std::vector<QWidget *> &widgets,
bool &fromDocking) {
if (m_item) {
if ( (m_item->objectName() == "FilmStrip" && m_item->getCanFixWidth()) ||
if (m_item->wasFloating()) {
fromDocking = true;
m_item->clearWasFloating();
return false;
}
if ((m_item->objectName() == "FilmStrip" && m_item->getCanFixWidth()) ||
m_item->objectName() == "StyleEditor") {
widgets.push_back(m_item);
return true;
Expand All @@ -436,15 +442,17 @@ bool Region::checkWidgetsToBeFixedWidth(std::vector<QWidget *> &widgets) {
if (m_orientation == horizontal) {
bool ret = true;
for (Region *childRegion : m_childList) {
if (!childRegion->checkWidgetsToBeFixedWidth(widgets)) ret = false;
if (!childRegion->checkWidgetsToBeFixedWidth(widgets, fromDocking))
ret = false;
}
return ret;
}
// for vertical orientation, return true if at least one item is to be fixed
else {
bool ret = false;
for (Region *childRegion : m_childList) {
if (childRegion->checkWidgetsToBeFixedWidth(widgets)) ret = true;
if (childRegion->checkWidgetsToBeFixedWidth(widgets, fromDocking))
ret = true;
}
return ret;
}
Expand All @@ -464,9 +472,10 @@ void DockLayout::redistribute() {
// check recursively from the root region, if the widgets can be fixed.
// it avoids all widgets in horizontal alignment to be fixed, or UI becomes
// glitchy.
bool fromDocking = false;
bool widgetsCanBeFixedWidth =
!m_regions.front()->checkWidgetsToBeFixedWidth(widgets);
if (widgetsCanBeFixedWidth) {
!m_regions.front()->checkWidgetsToBeFixedWidth(widgets, fromDocking);
if (!fromDocking && widgetsCanBeFixedWidth) {
for (QWidget *widget : widgets) widget->setFixedWidth(widget->width());
}

Expand All @@ -487,7 +496,7 @@ void DockLayout::redistribute() {
m_regions.front()->setGeometry(contentsRect());
m_regions.front()->redistribute();

if (widgetsCanBeFixedWidth) {
if (!fromDocking && widgetsCanBeFixedWidth) {
for (QWidget *widget : widgets) {
widget->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
widget->setMinimumSize(0, 0);
Expand Down Expand Up @@ -737,7 +746,8 @@ Region *DockLayout::dockItemPrivate(DockWidget *item, Region *r, int idx) {
item->onDock(true);

item->setDockedAppearance();
item->m_floating = false;
item->m_floating = false;
item->m_wasFloating = true;

if (!r) {
// Insert new root region
Expand Down
8 changes: 6 additions & 2 deletions toonz/sources/toonzqt/docklayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ class DVAPI DockWidget : public QFrame {

protected:
// Private attributes for dragging purposes
bool m_floating; // Whether this window is floating or docked
bool m_floating; // Whether this window is floating or docked
bool m_wasFloating;
bool m_dragging; // Whether this window is being dragged
bool m_undocking; // Still docked, but after a mouse button press on a title
// bar.
Expand Down Expand Up @@ -220,6 +221,8 @@ class DVAPI DockWidget : public QFrame {
DockLayout *parentLayout() const { return m_parentLayout; }

bool isFloating() const { return m_floating; }
bool wasFloating() const { return m_wasFloating; }
void clearWasFloating() { m_wasFloating = false; }
bool isMaximized() const { return m_maximized; }

// Query functions
Expand Down Expand Up @@ -530,7 +533,8 @@ class Region {

unsigned int find(const Region *subRegion) const;

bool checkWidgetsToBeFixedWidth(std::vector<QWidget *> &widgets);
bool checkWidgetsToBeFixedWidth(std::vector<QWidget *> &widgets,
bool &fromDocking);

private:
// Setters - private
Expand Down

0 comments on commit 6bc9e75

Please sign in to comment.