Commit 484e946f authored by loh tar's avatar loh tar
Browse files

Add option "Sync section size with tab positions"

This patch alone is not a final solution, it add only the option
to the Behaviour config page and use the option at some places.

What is missing is the way how to handle the section sizes now.
parent cdc37983
......@@ -151,10 +151,19 @@ void KateConfigDialog::addBehaviorPage()
connect(m_modNotifications, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);
vbox->addWidget(m_modNotifications);
buttonGroup->setLayout(vbox);
// show text for the left and right sidebars?
// only useful for Kate
if (KateApp::isKate()) {
QGroupBox *buttonGroup = new QGroupBox(i18n("&Sidebars"), generalFrame);
layout->addWidget(buttonGroup);
QVBoxLayout *vbox = new QVBoxLayout;
m_syncSectionSizeWithSidebarTabs = new QCheckBox(i18n("Sync section size with tab positions"), buttonGroup);
m_syncSectionSizeWithSidebarTabs->setChecked(cgGeneral.readEntry("Sync section size with tab positions", false));
connect(m_syncSectionSizeWithSidebarTabs, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);
vbox->addWidget(m_syncSectionSizeWithSidebarTabs);
m_showTextForLeftRightSidebars = new QCheckBox(i18n("Show text for left and right sidebar buttons"), buttonGroup);
m_showTextForLeftRightSidebars->setChecked(cgGeneral.readEntry("Show text for left and right sidebar", false));
connect(m_showTextForLeftRightSidebars, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);
......@@ -175,10 +184,9 @@ void KateConfigDialog::addBehaviorPage()
m_leftRightSidebarsIconSize->setEnabled(!v);
l->setEnabled(!v);
});
buttonGroup->setLayout(vbox);
}
buttonGroup->setLayout(vbox);
// tabbar => we allow to configure some limit on number of tabs to show
buttonGroup = new QGroupBox(i18n("&Tabs"), generalFrame);
vbox = new QVBoxLayout;
......@@ -446,6 +454,9 @@ void KateConfigDialog::slotApply()
KConfigGroup cg(config, "General");
// only there for kate
if (m_syncSectionSizeWithSidebarTabs) {
cg.writeEntry("Sync section size with tab positions", m_syncSectionSizeWithSidebarTabs->isChecked());
}
if (m_showTextForLeftRightSidebars) {
cg.writeEntry("Show text for left and right sidebar", m_showTextForLeftRightSidebars->isChecked());
}
......
......@@ -90,6 +90,7 @@ private:
QComboBox *m_mouseBackActions = nullptr;
QComboBox *m_mouseForwardActions = nullptr;
QCheckBox *m_modNotifications;
QCheckBox *m_syncSectionSizeWithSidebarTabs = nullptr;
QCheckBox *m_showTextForLeftRightSidebars = nullptr;
QSpinBox *m_leftRightSidebarsIconSize = nullptr;
QComboBox *m_cmbQuickOpenListMode;
......
......@@ -534,9 +534,15 @@ void Sidebar::readConfig()
{
bool needsUpdate = false;
// shall we show text for the left and right bars?
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup cgGeneral = KConfigGroup(config, "General");
const bool syncWithTabs = cgGeneral.readEntry("Sync section size with tab positions", false);
if (syncWithTabs != m_syncWithTabs) {
m_syncWithTabs = syncWithTabs;
needsUpdate = true;
}
// shall we show text for the left and right bars?
const bool showTextForLeftRight = cgGeneral.readEntry("Show text for left and right sidebar", false);
if (showTextForLeftRight != m_showTextForLeftRight) {
m_showTextForLeftRight = showTextForLeftRight;
......@@ -770,14 +776,19 @@ void Sidebar::handleCollapse(int pos, int index)
void Sidebar::ownSplitMoved(int pos, int index)
{
moveSplitter(pos, index);
if (m_syncWithTabs) {
moveSplitter(pos, index);
}
}
void Sidebar::barSplitMoved(int pos, int index)
{
Q_UNUSED(pos);
Q_UNUSED(index);
adjustSplitterSections();
if (m_syncWithTabs) {
adjustSplitterSections();
}
}
bool Sidebar::tabBarIsEmpty(MultiTabBar *bar)
......@@ -853,6 +864,10 @@ bool Sidebar::adjustSplitterSections()
return false;
}
if (!m_syncWithTabs) {
return true;
}
if (sizeCollector && lastExpandedId > -1) {
wsizes[lastExpandedId] += sizeCollector;
}
......@@ -1104,6 +1119,15 @@ void Sidebar::restoreSession(KConfigGroup &config)
}
}
QList<int> sectSizes = config.readEntry(QStringLiteral("Kate-MDI-Sidebar-%1-SectSizes").arg(position()), QList<int>());
for (int i = 0; i < sectSizes.count(); ++i) {
if (tabBarCount() - 1 < i) {
// Config mismatch!
break;
}
tabBar(i)->setSectionSize(sectSizes.at(i));
}
// Collapse now, and before! we restore m_lastSize, will hide (all) m_stack(s) so that
// expanding will work fine...
collapseSidebar();
......@@ -1125,13 +1149,18 @@ void Sidebar::saveSession(KConfigGroup &config)
config.writeEntry(QStringLiteral("Kate-MDI-ToolView-%1-Show-Button-In-Sidebar").arg(tv->id), tv->tabButtonVisible());
}
QList<int> sectSizes;
for (int i = 0; i < tabBarCount(); ++i) {
sectSizes << tabBar(i)->sectionSize();
QStringList tvList;
for (int j : tabBar(i)->tabList()) {
tvList << m_idToWidget.at(j)->id;
}
config.writeEntry(QStringLiteral("Kate-MDI-Sidebar-%1-Bar-%2-TvList").arg(position()).arg(i), tvList);
}
config.writeEntry(QStringLiteral("Kate-MDI-Sidebar-%1-SectSizes").arg(position()), sectSizes);
}
// END SIDEBAR
......
......@@ -220,6 +220,16 @@ public:
return m_tabList.size();
}
int sectionSize() const
{
return m_sectionSize;
}
void setSectionSize(int size)
{
m_sectionSize = size;
}
Q_SIGNALS:
void lastTabRemoved(MultiTabBar *);
......@@ -232,6 +242,7 @@ private:
KMultiTabBar *m_multiTabBar;
QList<int> m_tabList;
int m_activeTab = 0;
int m_sectionSize = 0;
};
class Sidebar : public QSplitter
......@@ -379,6 +390,7 @@ private:
int m_popupButton = 0;
QPointer<QLabel> m_resizePlaceholder;
bool m_isPreviouslyCollapsed = false;
bool m_syncWithTabs = false;
bool m_showTextForLeftRight = false;
int m_leftRightSidebarIconSize = 32;
......
Supports Markdown
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