Git commit 51883380af4c2fef061ceedae95a567b8f1d6f17 by Tomaz Canabrava, on behalf of Tomaz Canabrava. Committed on 02/07/2020 at 08:30. Pushed by tcanabrava into branch 'master'.
Add Split Settings: Toggle Visiblity and Dragger Size The Splitter is a great addition to konsole, but it lacked one thing that always made KDE software proud: Configurability. Some people like to have the header bar, some people don't, some people prefer to have thin lines separating the views, some people prefer to have the lines a bit thicker so it's easy to drag them with the mouse. This patch introduces those two settings in a new Tab on the Settings. FIXED-IN: 20.08 FEATURE: GUI: CHANGELOG: Add Splitter settings for visibility and drag size M +1 -1 src/MainWindow.cpp M +9 -0 src/TerminalDisplay.cpp M +2 -0 src/TerminalDisplay.h M +40 -0 src/TerminalHeaderBar.cpp M +4 -0 src/TerminalHeaderBar.h M +17 -6 src/ViewSplitter.cpp M +136 -21 src/settings/TabBarSettings.ui M +20 -0 src/settings/konsole.kcfg https://invent.kde.org/utilities/konsole/commit/51883380af4c2fef061ceedae95a567b8f1d6f17 diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 5b6e441a..a56803cd 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -764,7 +764,7 @@ void MainWindow::showSettingsDialog(const bool showProfilePage) profilePage->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-profiles"))); confDialog->addPage(profilePage, true); - const QString tabBarPageName = i18nc("@title Preferences page name", "Tab Bar"); + const QString tabBarPageName = i18nc("@title Preferences page name", "Tab Bar / Splitters"); auto tabBarPage = new KPageWidgetItem(new TabBarSettings(confDialog), tabBarPageName); tabBarPage->setIcon(QIcon::fromTheme(QStringLiteral("system-run"))); confDialog->addPage(tabBarPage, true); diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp index 5927a5af..58edde6a 100644 --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -22,6 +22,7 @@ // Own #include "TerminalDisplay.h" +#include "KonsoleSettings.h" // Config #include "config-konsole.h" @@ -570,6 +571,8 @@ TerminalDisplay::TerminalDisplay(QWidget* parent) #ifndef QT_NO_ACCESSIBILITY QAccessible::installFactory(Konsole::accessibleInterfaceFactory); #endif + + connect(KonsoleSettings::self(), &KonsoleSettings::configChanged, this, &TerminalDisplay::setupHeaderVisibility); } TerminalDisplay::~TerminalDisplay() @@ -586,6 +589,12 @@ TerminalDisplay::~TerminalDisplay() _outputSuspendedMessageWidget = nullptr; } +void TerminalDisplay::setupHeaderVisibility() +{ + _headerBar->applyVisibilitySettings(); + calcGeometry(); +} + void TerminalDisplay::hideDragTarget() { _drawOverlay = false; diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h index 7587bd1a..e5c77f06 100644 --- a/src/TerminalDisplay.h +++ b/src/TerminalDisplay.h @@ -693,6 +693,8 @@ private: void paintFilters(QPainter &painter); + void setupHeaderVisibility(); + // returns a region covering all of the areas of the widget which contain // a hotspot QRegion hotSpotRegion() const; diff --git a/src/TerminalHeaderBar.cpp b/src/TerminalHeaderBar.cpp index 96db18ad..d06848fa 100644 --- a/src/TerminalHeaderBar.cpp +++ b/src/TerminalHeaderBar.cpp @@ -24,6 +24,8 @@ #include "TerminalDisplay.h" #include "SessionController.h" #include "ViewProperties.h" +#include "KonsoleSettings.h" +#include "ViewSplitter.h" #include <KLocalizedString> #include <QBoxLayout> @@ -250,4 +252,42 @@ QSize TerminalHeaderBar::minimumSizeHint() const return {height, height}; } +QSplitter *TerminalHeaderBar::getTopLevelSplitter() +{ + QWidget *p = parentWidget(); + // This is expected. + if (qobject_cast<TerminalDisplay*>(p)) { + p = p->parentWidget(); + } + + // this is also expected. + auto *innerSplitter = qobject_cast<ViewSplitter*>(p); + if (!innerSplitter) { + return nullptr; + } + + return innerSplitter->getToplevelSplitter(); +} + +void TerminalHeaderBar::applyVisibilitySettings() +{ + auto *settings = KonsoleSettings::self(); + auto toVisibility = settings->splitViewVisibility(); + switch (toVisibility) + { + case KonsoleSettings::AlwaysShowSplitHeader: + setVisible(true); + break; + case KonsoleSettings::ShowSplitHeaderWhenNeeded: { + const bool visible = !(getTopLevelSplitter()->findChildren<TerminalDisplay*>().count() == 1); + setVisible(visible); + } + break; + case KonsoleSettings::AlwaysHideSplitHeader: + setVisible(false); + default: + break; + } +} + } diff --git a/src/TerminalHeaderBar.h b/src/TerminalHeaderBar.h index 3118786f..4bcb4cbc 100644 --- a/src/TerminalHeaderBar.h +++ b/src/TerminalHeaderBar.h @@ -29,6 +29,8 @@ class QLabel; class QToolButton; class QBoxLayout; +class QSplitter; + namespace Konsole { class TerminalDisplay; class ViewProperties; @@ -40,6 +42,8 @@ public: explicit TerminalHeaderBar(QWidget *parent = nullptr); void finishHeaderSetup(ViewProperties *properties); QSize minimumSizeHint() const override; + void applyVisibilitySettings(); + QSplitter *getTopLevelSplitter(); public Q_SLOTS: void setFocusIndicatorState(bool focused); diff --git a/src/ViewSplitter.cpp b/src/ViewSplitter.cpp index 40bc0c48..9e553219 100644 --- a/src/ViewSplitter.cpp +++ b/src/ViewSplitter.cpp @@ -21,6 +21,7 @@ // Own #include "ViewSplitter.h" +#include "KonsoleSettings.h" // Qt #include <QChildEvent> @@ -39,10 +40,24 @@ using Konsole::TerminalDisplay; //TODO: Connect the TerminalDisplay destroyed signal here. +namespace { + int calculateHandleWidth(int settingsEnum) { + switch (settingsEnum) { + case Konsole::KonsoleSettings::SplitDragHandleLarge: return 10; + case Konsole::KonsoleSettings::SplitDragHandleMedium: return 5; + case Konsole::KonsoleSettings::SplitDragHandleSmall: return 1; + default: return 1; + } + } +} + ViewSplitter::ViewSplitter(QWidget *parent) : QSplitter(parent) { setAcceptDrops(true); + connect(KonsoleSettings::self(), &KonsoleSettings::configChanged, this, [this]{ + setHandleWidth(calculateHandleWidth(KonsoleSettings::self()->splitDragHandleSize())); + }); } /* This function is called on the toplevel splitter, we need to look at the actual ViewSplitter inside it */ @@ -130,12 +145,8 @@ void ViewSplitter::childEvent(QChildEvent *event) } auto terminals = getToplevelSplitter()->findChildren<TerminalDisplay*>(); - if (terminals.size() == 1) { - terminals.at(0)->headerBar()->setVisible(false); - } else { - for(auto terminal : terminals) { - terminal->headerBar()->setVisible(true); - } + for(auto terminal : terminals) { + terminal->headerBar()->applyVisibilitySettings(); } } diff --git a/src/settings/TabBarSettings.ui b/src/settings/TabBarSettings.ui index 3cf2fc18..a199f03d 100644 --- a/src/settings/TabBarSettings.ui +++ b/src/settings/TabBarSettings.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>382</width> - <height>418</height> + <width>507</width> + <height>473</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout"> @@ -29,7 +29,7 @@ <item> <widget class="QTabWidget" name="tabs"> <property name="currentIndex"> - <number>0</number> + <number>2</number> </property> <widget class="QWidget" name="appearanceTab"> <attribute name="title"> @@ -254,10 +254,10 @@ <property name="enabled"> <bool>false</bool> </property> - <property name="filter" stdset="0"> + <property name="filter"> <string>text/css</string> </property> - <property name="placeholderText" stdset="0"> + <property name="placeholderText"> <string comment="@item:intext Optional file path is empty">(none)</string> </property> </widget> @@ -372,6 +372,119 @@ </item> </layout> </widget> + <widget class="QWidget" name="splitTab"> + <attribute name="title"> + <string>Splits</string> + </attribute> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Show Header</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QRadioButton" name="ShowSplitHeaderWhenNeeded"> + <property name="text"> + <string>When needed</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">kcfg_SplitViewVisibility</string> + </attribute> + </widget> + </item> + <item row="2" column="1"> + <widget class="QRadioButton" name="AlwaysHideSplitHeader"> + <property name="text"> + <string>Never</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">kcfg_SplitViewVisibility</string> + </attribute> + </widget> + </item> + <item row="3" column="1"> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Drag Handle Size</string> + </property> + <property name="margin"> + <number>0</number> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QRadioButton" name="SplitDragHandleSmall"> + <property name="text"> + <string>Small</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">kcfg_SplitDragHandleSize</string> + </attribute> + </widget> + </item> + <item row="5" column="1"> + <widget class="QRadioButton" name="SplitDragHandleMedium"> + <property name="text"> + <string>Medium</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">kcfg_SplitDragHandleSize</string> + </attribute> + </widget> + </item> + <item row="6" column="1"> + <widget class="QRadioButton" name="SplitDragHandleLarge"> + <property name="text"> + <string>Large</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">kcfg_SplitDragHandleSize</string> + </attribute> + </widget> + </item> + <item row="7" column="1"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="1"> + <widget class="QRadioButton" name="AlwaysShowSplitHeader"> + <property name="text"> + <string>Always</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">kcfg_SplitViewVisibility</string> + </attribute> + </widget> + </item> + </layout> + </widget> </widget> </item> </layout> @@ -379,7 +492,7 @@ <customwidgets> <customwidget> <class>KUrlRequester</class> - <extends>QFrame</extends> + <extends>QWidget</extends> <header>kurlrequester.h</header> <container>1</container> </customwidget> @@ -405,7 +518,7 @@ <connection> <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>None</receiver> + <receiver>Bottom</receiver> <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> @@ -421,7 +534,7 @@ <connection> <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>showCloseTabButtonLabel</receiver> + <receiver>kcfg_TabBarUseUserStyleSheet</receiver> <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> @@ -437,7 +550,7 @@ <connection> <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>OnTabBar</receiver> + <receiver>miscellaneousAppearanceLabel</receiver> <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> @@ -453,7 +566,7 @@ <connection> <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>Bottom</receiver> + <receiver>kcfg_ExpandTabWidth</receiver> <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> @@ -499,10 +612,10 @@ </hints> </connection> <connection> - <sender>AlwaysHideTabBar</sender> + <sender>kcfg_TabBarUseUserStyleSheet</sender> <signal>toggled(bool)</signal> - <receiver>Top</receiver> - <slot>setDisabled(bool)</slot> + <receiver>kcfg_TabBarUserStyleSheetFile</receiver> + <slot>setEnabled(bool)</slot> <hints> <hint type="sourcelabel"> <x>20</x> @@ -517,7 +630,7 @@ <connection> <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>miscellaneousAppearanceLabel</receiver> + <receiver>Top</receiver> <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> @@ -533,7 +646,7 @@ <connection> <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>kcfg_ExpandTabWidth</receiver> + <receiver>showCloseTabButtonLabel</receiver> <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> @@ -549,7 +662,7 @@ <connection> <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>kcfg_TabBarUseUserStyleSheet</receiver> + <receiver>OnTabBar</receiver> <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> @@ -563,10 +676,10 @@ </hints> </connection> <connection> - <sender>kcfg_TabBarUseUserStyleSheet</sender> + <sender>AlwaysHideTabBar</sender> <signal>toggled(bool)</signal> - <receiver>kcfg_TabBarUserStyleSheetFile</receiver> - <slot>setEnabled(bool)</slot> + <receiver>None</receiver> + <slot>setDisabled(bool)</slot> <hints> <hint type="sourcelabel"> <x>20</x> @@ -612,9 +725,11 @@ </connection> </connections> <buttongroups> + <buttongroup name="kcfg_SplitDragHandleSize"/> <buttongroup name="kcfg_TabBarVisibility"/> - <buttongroup name="kcfg_NewTabBehavior"/> - <buttongroup name="kcfg_CloseTabButton"/> <buttongroup name="kcfg_TabBarPosition"/> + <buttongroup name="kcfg_CloseTabButton"/> + <buttongroup name="kcfg_NewTabBehavior"/> + <buttongroup name="kcfg_SplitViewVisibility"/> </buttongroups> </ui> diff --git a/src/settings/konsole.kcfg b/src/settings/konsole.kcfg index abc31a5d..ac7c9b10 100644 --- a/src/settings/konsole.kcfg +++ b/src/settings/konsole.kcfg @@ -83,6 +83,26 @@ <default>true</default> </entry> </group> + <group name="SplitView"> + <entry name="SplitViewVisibility" type="Enum"> + <label>Control the visibility of the whole tab bar</label> + <choices> + <choice name="AlwaysShowSplitHeader" /> + <choice name="ShowSplitHeaderWhenNeeded" /> + <choice name="AlwaysHideSplitHeader" /> + </choices> + <default>ShowTabBarWhenNeeded</default> + </entry> + <entry name="SplitDragHandleSize" type="Enum"> + <label> Control the size of the handle between panels </label> + <choices> + <choice name="SplitDragHandleSmall"/> + <choice name="SplitDragHandleMedium"/> + <choice name="SplitDragHandleLarge"/> + </choices> + <default>SplitDragHandleSmall</default> + </entry> + </group> <group name="TabBar"> <entry name="TabBarVisibility" type="Enum"> <label>Control the visibility of the whole tab bar</label>
