[utilities/konsole] /: Be able to resize the splits to the same size.

Tomaz Canabrava null at kde.org
Mon May 23 15:54:40 BST 2022


Git commit 8663b4be86fbdd45583dcbc373c4b989bd8e819d by Tomaz  Canabrava, on behalf of Kamay Xutax.
Committed on 23/05/2022 at 14:50.
Pushed by tcanabrava into branch 'master'.

Be able to resize the splits to the same size.

Here how it looks like: https://imgur.com/a/uaMQvT6

Before, it was impossible to resize the splits
with the same size in case they were manually resized.

I have added a new button menu for doing so:
in View -> Split View -> Equal size to all views.

First I wanted to make this as a plugin,
but since I thought it could make splits a bit more useful,
I decided to merge it not as a plugin but internally.

GUI: Menu -> View -> Split View -> Equal size to all views
CHANGELOG: Added equal size to all split views.

M  +1    -0    desktop/konsoleui.rc
M  +8    -0    doc/manual/index.docbook
M  +38   -0    src/ViewManager.cpp
M  +1    -0    src/ViewManager.h

https://invent.kde.org/utilities/konsole/commit/8663b4be86fbdd45583dcbc373c4b989bd8e819d

diff --git a/desktop/konsoleui.rc b/desktop/konsoleui.rc
index 02aa1d833..7b70d9449 100644
--- a/desktop/konsoleui.rc
+++ b/desktop/konsoleui.rc
@@ -25,6 +25,7 @@
                 <Action name="expand-active-view"/>
                 <Action name="shrink-active-view"/>
                 <Action name="toggle-maximize-current-view"/>
+                <Action name="equal-size-view"/>
             </Menu>
             <Separator/>
             <Action name="detach-tab" />
diff --git a/doc/manual/index.docbook b/doc/manual/index.docbook
index 0eeeae96d..08d91096c 100644
--- a/doc/manual/index.docbook
+++ b/doc/manual/index.docbook
@@ -695,6 +695,14 @@ Any output on one view is duplicated in the other view.
 </para></listitem>
 </varlistentry>
 
+<varlistentry>
+<term><menuchoice>
+<shortcut><keycombo action="simul">&Ctrl;&Shift;<keycap>\</keycap></keycombo></shortcut>
+<guimenu>View</guimenu><guisubmenu>Split View</guisubmenu><guimenuitem>Equal size to all views</guimenuitem></menuchoice>
+</term>
+<listitem><para><action>Sets the same size for all views</action>
+</para></listitem>
+</varlistentry>
 
 <varlistentry>
 <term><menuchoice>
diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp
index 9e3675a2e..ac7fe98a6 100644
--- a/src/ViewManager.cpp
+++ b/src/ViewManager.cpp
@@ -274,6 +274,14 @@ void ViewManager::setupActions()
     _multiTabOnlyActions << action;
     _viewContainer->addAction(action);
 
+    action = new QAction(this);
+    action->setText(i18nc("@action:inmenu", "Equal size to all views"));
+    collection->setDefaultShortcut(action, Konsole::ACCEL | Qt::SHIFT | Qt::Key_Backslash);
+    action->setEnabled(false);
+    collection->addAction(QStringLiteral("equal-size-view"), action);
+    connect(action, &QAction::triggered, this, &ViewManager::equalSizeAllContainers);
+    _multiSplitterOnlyActions << action;
+
     // _viewSplitter->addAction(lastUsedViewReverseAction);
     const int SWITCH_TO_TAB_COUNT = 19;
     for (int i = 0; i < SWITCH_TO_TAB_COUNT; ++i) {
@@ -632,6 +640,36 @@ void ViewManager::shrinkActiveContainer()
     _viewContainer->activeViewSplitter()->adjustActiveTerminalDisplaySize(-10);
 }
 
+void ViewManager::equalSizeAllContainers()
+{
+    std::function<void(ViewSplitter *)> processChildren = [&processChildren](ViewSplitter *viewSplitter) -> void {
+        // divide the size of the parent widget by the amount of children splits
+        auto hintSize = viewSplitter->size();
+        auto sizes = viewSplitter->sizes();
+        auto sharedSize = hintSize / sizes.size();
+        if (viewSplitter->orientation() == Qt::Horizontal) {
+            for (auto &&size : sizes) {
+                size = sharedSize.width();
+            }
+        } else {
+            for (auto &&size : sizes) {
+                size = sharedSize.height();
+            }
+        }
+        // set new sizes
+        viewSplitter->setSizes(sizes);
+
+        // set equal sizes for each splitter children
+        for (auto &&child : viewSplitter->children()) {
+            auto childViewSplitter = qobject_cast<ViewSplitter *>(child);
+            if (childViewSplitter) {
+                processChildren(childViewSplitter);
+            }
+        }
+    };
+    processChildren(_viewContainer->activeViewSplitter()->getToplevelSplitter());
+}
+
 SessionController *ViewManager::createController(Session *session, TerminalDisplay *view)
 {
     // create a new controller for the session, and ensure that this view manager
diff --git a/src/ViewManager.h b/src/ViewManager.h
index 7b243936a..6d7c455f1 100644
--- a/src/ViewManager.h
+++ b/src/ViewManager.h
@@ -318,6 +318,7 @@ private Q_SLOTS:
     void splitTopBottom();
     void expandActiveContainer();
     void shrinkActiveContainer();
+    void equalSizeAllContainers();
 
     // called when the "Detach View" menu item is selected
     void detachActiveView();


More information about the kde-doc-english mailing list