Commit 2ab70959 authored by Nathan Sprangers's avatar Nathan Sprangers Committed by Tomaz Canabrava
Browse files

Improve maximized split-view behavior

Maximized views must be un-maximized before certain actions:
 - detach view
 - split view
 - move to new tab
 - close

This commit fixes the toggle state getting out of sync after those
actions, adds the un-maximize step for splitting a maximized view,
and reduces code duplication by adding ViewSplitter::clearMaximized(),

For now, clearMaximized() does need to be called manually: we want the
display restored before the removal, but ViewSplitter handles removals
after the fact with QEvent::ChildRemoved.
parent 822c48c2
......@@ -435,6 +435,7 @@ void ViewManager::detachActiveView()
// find the currently active view and remove it from its container
if ((_viewContainer->findChildren<TerminalDisplay *>()).count() > 1) {
auto activeSplitter = _viewContainer->activeViewSplitter();
activeSplitter->clearMaximized();
auto terminal = activeSplitter->activeTerminalDisplay();
auto newSplitter = new ViewSplitter();
newSplitter->addTerminalDisplay(terminal, Qt::Horizontal);
......@@ -530,10 +531,8 @@ void ViewManager::sessionFinished()
if (splitter == nullptr) {
return;
}
splitter->clearMaximized();
auto *toplevelSplitter = splitter->getToplevelSplitter();
toplevelSplitter->handleMinimizeMaximize(false);
view->deleteLater();
connect(view, &QObject::destroyed, this, [this]() {
toggleActionsBasedOnState();
......@@ -550,7 +549,7 @@ void ViewManager::sessionFinished()
if (!_sessionMap.empty()) {
updateTerminalDisplayHistory(view, true);
focusAnotherTerminal(toplevelSplitter);
focusAnotherTerminal(splitter->getToplevelSplitter());
}
}
......
......@@ -337,6 +337,7 @@ void TabbedViewContainer::addView(TerminalDisplay *view)
void TabbedViewContainer::splitView(TerminalDisplay *view, Qt::Orientation orientation)
{
auto viewSplitter = qobject_cast<ViewSplitter *>(currentWidget());
viewSplitter->clearMaximized();
viewSplitter->addTerminalDisplay(view, orientation);
connectTerminalDisplay(view);
}
......@@ -699,6 +700,6 @@ void TabbedViewContainer::setNavigationBehavior(int behavior)
void TabbedViewContainer::moveToNewTab(TerminalDisplay *display)
{
// Ensure that the current terminal is not maximized so that the other views will be shown properly
activeViewSplitter()->handleMinimizeMaximize(false);
activeViewSplitter()->clearMaximized();
addView(display);
}
......@@ -304,6 +304,15 @@ void ViewSplitter::handleMinimizeMaximize(bool maximize)
}
}
void ViewSplitter::clearMaximized()
{
ViewSplitter *top = getToplevelSplitter();
Q_ASSERT(top);
if (top->terminalMaximized()) {
top->toggleMaximizeCurrentTerminal();
}
}
ViewSplitter *ViewSplitter::getToplevelSplitter()
{
ViewSplitter *current = this;
......
......@@ -103,7 +103,14 @@ public:
*/
void toggleMaximizeCurrentTerminal();
void handleMinimizeMaximize(bool maximize);
/**
* Can be called on any ViewSplitter to find the top level splitter and ensure
* the active display isn't maximized. Do nothing if it's not maximized.
*
* Useful for ViewManager and TabbedViewContainer when removing or adding a
* display to the hierarchy so that the layout is reflowed correctly.
*/
void clearMaximized();
/** returns the splitter that has no splitter as a parent. */
ViewSplitter *getToplevelSplitter();
......@@ -157,6 +164,9 @@ private:
*/
bool hideRecurse(TerminalDisplay *currentTerminalDisplay);
/** other classes should use clearmMaximized() */
void handleMinimizeMaximize(bool maximize);
void updateSizes();
bool m_terminalMaximized = false;
bool m_blockPropagatedDeletion = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment