]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/interface/statusandlocationbarssettingspage.cpp
Clazy fix
[dolphin.git] / src / settings / interface / statusandlocationbarssettingspage.cpp
1 /*
2 * SPDX-FileCopyrightText: 2023 Dimosthenis Krallis <dimosthenis.krallis@outlook.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "statusandlocationbarssettingspage.h"
8 #include "dolphinmainwindow.h"
9 #include "dolphinviewcontainer.h"
10 #include "settings/interface/folderstabssettingspage.h"
11
12 #include <KLocalizedString>
13
14 #include <QCheckBox>
15 #include <QFormLayout>
16
17 #include <QButtonGroup>
18 #include <QRadioButton>
19 #include <QSpacerItem>
20 #include <QStyle>
21 #include <QStyleOption>
22
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)
32 {
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;
37
38 QFormLayout *topLayout = new QFormLayout(this);
39
40 // Status bar
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);
46
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);
50
51 topLayout->addRow(i18nc("@title:group", "Status Bar:"), m_showStatusBarSmall);
52 topLayout->addRow(QString(), m_showStatusBarFullWidth);
53
54 // Indent the m_showZoomSlider checkbox under m_showStatusBarFullWidth.
55 QHBoxLayout *zoomSliderLayout = new QHBoxLayout;
56 QStyleOption opt;
57 opt.initFrom(this);
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);
61
62 topLayout->addRow(QString(), zoomSliderLayout);
63
64 topLayout->addRow(QString(), m_disableStatusBar);
65 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
66
67 // Location bar
68 m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Make location bar editable"));
69 topLayout->addRow(i18n("Location bar:"), m_editableUrl);
70
71 m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"));
72 topLayout->addRow(QString(), m_showFullPath);
73
74 loadSettings();
75
76 locationUpdateInitialViewOptions();
77
78 connect(m_editableUrl, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged);
79 connect(m_showFullPath, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged);
80
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);
84 }
85
86 StatusAndLocationBarsSettingsPage::~StatusAndLocationBarsSettingsPage()
87 {
88 }
89
90 void StatusAndLocationBarsSettingsPage::applySettings()
91 {
92 GeneralSettings *settings = GeneralSettings::self();
93
94 settings->setEditableUrl(m_editableUrl->isChecked());
95 settings->setShowFullPath(m_showFullPath->isChecked());
96
97 settings->setShowStatusBar(m_statusBarButtonGroup->checkedId());
98 settings->setShowZoomSlider(m_showZoomSlider->isChecked());
99
100 settings->save();
101 }
102
103 void StatusAndLocationBarsSettingsPage::onShowStatusBarToggled()
104 {
105 const bool checked = (m_statusBarButtonGroup->checkedId() == GeneralSettings::EnumShowStatusBar::FullWidth);
106 m_showZoomSlider->setEnabled(checked);
107 }
108
109 void StatusAndLocationBarsSettingsPage::restoreDefaults()
110 {
111 GeneralSettings *settings = GeneralSettings::self();
112 settings->useDefaults(true);
113 loadSettings();
114 settings->useDefaults(false);
115 }
116
117 void StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged()
118 {
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);
123
124 // Enable and disable home URL controls appropriately
125 locationUpdateInitialViewOptions();
126 Q_EMIT changed();
127 }
128
129 void StatusAndLocationBarsSettingsPage::locationUpdateInitialViewOptions()
130 {
131 foldersTabsPage->m_homeUrlBoxLayoutContainer->setEnabled(foldersTabsPage->m_homeUrlRadioButton->isChecked());
132 foldersTabsPage->m_buttonBoxLayoutContainer->setEnabled(foldersTabsPage->m_homeUrlRadioButton->isChecked());
133 }
134
135 void StatusAndLocationBarsSettingsPage::loadSettings()
136 {
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());
141
142 onShowStatusBarToggled();
143 }
144
145 #include "moc_statusandlocationbarssettingspage.cpp"