2 * SPDX-FileCopyrightText: 2023 Dimosthenis Krallis <dimosthenis.krallis@outlook.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "statusandlocationbarssettingspage.h"
8 #include "dolphinmainwindow.h"
9 #include "dolphinviewcontainer.h"
10 #include "settings/interface/folderstabssettingspage.h"
12 #include <KLocalizedString>
15 #include <QFormLayout>
17 #include <QButtonGroup>
18 #include <QRadioButton>
19 #include <QSpacerItem>
21 #include <QStyleOption>
23 StatusAndLocationBarsSettingsPage::StatusAndLocationBarsSettingsPage(QWidget
*parent
, FoldersTabsSettingsPage
*foldersPage
)
24 : SettingsPageBase(parent
)
25 , m_editableUrl(nullptr)
26 , m_showFullPath(nullptr)
27 , m_statusBarButtonGroup(nullptr)
28 , m_showStatusBarSmall(nullptr)
29 , m_showStatusBarFullWidth(nullptr)
30 , m_showZoomSlider(nullptr)
31 , m_disableStatusBar(nullptr)
33 // We need to update some urls at the Folders & Tabs tab. We get that from foldersPage and set it on a private attribute
34 // foldersTabsPage. That way, we can modify the necessary stuff from here. Specifically, any changes on locationUpdateInitialViewOptions()
35 // which is a copy of updateInitialViewOptions() on Folders & Tabs.
36 foldersTabsPage
= foldersPage
;
38 QFormLayout
*topLayout
= new QFormLayout(this);
41 m_statusBarButtonGroup
= new QButtonGroup(this);
42 m_showStatusBarSmall
= new QRadioButton(i18nc("@option:radio", "Small"), this);
43 m_showStatusBarFullWidth
= new QRadioButton(i18nc("@option:radio", "Full width"), this);
44 m_showZoomSlider
= new QCheckBox(i18nc("@option:check", "Show zoom slider"), this);
45 m_disableStatusBar
= new QRadioButton(i18nc("@option:check", "Disabled"), this);
47 m_statusBarButtonGroup
->addButton(m_showStatusBarSmall
, GeneralSettings::EnumShowStatusBar::Small
);
48 m_statusBarButtonGroup
->addButton(m_showStatusBarFullWidth
, GeneralSettings::EnumShowStatusBar::FullWidth
);
49 m_statusBarButtonGroup
->addButton(m_disableStatusBar
, GeneralSettings::EnumShowStatusBar::Disabled
);
51 topLayout
->addRow(i18nc("@title:group", "Status Bar:"), m_showStatusBarSmall
);
52 topLayout
->addRow(QString(), m_showStatusBarFullWidth
);
54 // Indent the m_showZoomSlider checkbox under m_showStatusBarFullWidth.
55 QHBoxLayout
*zoomSliderLayout
= new QHBoxLayout
;
58 zoomSliderLayout
->addItem(
59 new QSpacerItem(style()->pixelMetric(QStyle::PM_IndicatorWidth
, &opt
, this), Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
60 zoomSliderLayout
->addWidget(m_showZoomSlider
);
62 topLayout
->addRow(QString(), zoomSliderLayout
);
64 topLayout
->addRow(QString(), m_disableStatusBar
);
65 topLayout
->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT
, QSizePolicy::Fixed
, QSizePolicy::Fixed
));
68 m_editableUrl
= new QCheckBox(i18nc("@option:check Startup Settings", "Make location bar editable"));
69 topLayout
->addRow(i18n("Location bar:"), m_editableUrl
);
71 m_showFullPath
= new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"));
72 topLayout
->addRow(QString(), m_showFullPath
);
76 locationUpdateInitialViewOptions();
78 connect(m_editableUrl
, &QCheckBox::toggled
, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged
);
79 connect(m_showFullPath
, &QCheckBox::toggled
, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged
);
81 connect(m_statusBarButtonGroup
, &QButtonGroup::idClicked
, this, &StatusAndLocationBarsSettingsPage::changed
);
82 connect(m_statusBarButtonGroup
, &QButtonGroup::idClicked
, this, &StatusAndLocationBarsSettingsPage::onShowStatusBarToggled
);
83 connect(m_showZoomSlider
, &QCheckBox::toggled
, this, &StatusAndLocationBarsSettingsPage::changed
);
86 StatusAndLocationBarsSettingsPage::~StatusAndLocationBarsSettingsPage()
90 void StatusAndLocationBarsSettingsPage::applySettings()
92 GeneralSettings
*settings
= GeneralSettings::self();
94 settings
->setEditableUrl(m_editableUrl
->isChecked());
95 settings
->setShowFullPath(m_showFullPath
->isChecked());
97 settings
->setShowStatusBar(m_statusBarButtonGroup
->checkedId());
98 settings
->setShowZoomSlider(m_showZoomSlider
->isChecked());
103 void StatusAndLocationBarsSettingsPage::onShowStatusBarToggled()
105 const bool checked
= (m_statusBarButtonGroup
->checkedId() == GeneralSettings::EnumShowStatusBar::FullWidth
);
106 m_showZoomSlider
->setEnabled(checked
);
109 void StatusAndLocationBarsSettingsPage::restoreDefaults()
111 GeneralSettings
*settings
= GeneralSettings::self();
112 settings
->useDefaults(true);
114 settings
->useDefaults(false);
117 void StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged()
119 // Provide a hint that the startup settings have been changed. This allows the views
120 // to apply the startup settings only if they have been explicitly changed by the user
121 // (see bug #254947).
122 GeneralSettings::setModifiedStartupSettings(true);
124 // Enable and disable home URL controls appropriately
125 locationUpdateInitialViewOptions();
129 void StatusAndLocationBarsSettingsPage::locationUpdateInitialViewOptions()
131 foldersTabsPage
->m_homeUrlBoxLayoutContainer
->setEnabled(foldersTabsPage
->m_homeUrlRadioButton
->isChecked());
132 foldersTabsPage
->m_buttonBoxLayoutContainer
->setEnabled(foldersTabsPage
->m_homeUrlRadioButton
->isChecked());
135 void StatusAndLocationBarsSettingsPage::loadSettings()
137 m_editableUrl
->setChecked(GeneralSettings::editableUrl());
138 m_showFullPath
->setChecked(GeneralSettings::showFullPath());
139 m_statusBarButtonGroup
->button(GeneralSettings::showStatusBar())->setChecked(true);
140 m_showZoomSlider
->setChecked(GeneralSettings::showZoomSlider());
142 onShowStatusBarToggled();
145 #include "moc_statusandlocationbarssettingspage.cpp"