]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/behaviorsettingspage.cpp
[KStandardItemListWidget] Pass icon state to overlay painter
[dolphin.git] / src / settings / general / behaviorsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
3 * and Patrice Tremblay *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "behaviorsettingspage.h"
22
23 #include "global.h"
24 #include "views/viewproperties.h"
25
26 #include <KLocalizedString>
27
28 #include <QButtonGroup>
29 #include <QCheckBox>
30 #include <QFormLayout>
31 #include <QRadioButton>
32 #include <QSpacerItem>
33
34 BehaviorSettingsPage::BehaviorSettingsPage(const QUrl& url, QWidget* parent) :
35 SettingsPageBase(parent),
36 m_url(url),
37 m_localViewProps(nullptr),
38 m_globalViewProps(nullptr),
39 m_showToolTips(nullptr),
40 m_showSelectionToggle(nullptr),
41 m_naturalSorting(nullptr),
42 m_caseSensitiveSorting(nullptr),
43 m_caseInsensitiveSorting(nullptr),
44 m_renameInline(nullptr),
45 m_useTabForSplitViewSwitch(nullptr)
46 {
47 QFormLayout* topLayout = new QFormLayout(this);
48
49
50 // View properties
51 m_localViewProps = new QRadioButton(i18nc("@option:radio", "Remember properties for each folder"));
52 m_globalViewProps = new QRadioButton(i18nc("@option:radio", "Use common properties for all folders"));
53
54 QButtonGroup* viewGroup = new QButtonGroup(this);
55 viewGroup->addButton(m_localViewProps);
56 viewGroup->addButton(m_globalViewProps);
57 topLayout->addRow(i18nc("@title:group", "View: "), m_localViewProps);
58 topLayout->addRow(QString(), m_globalViewProps);
59
60
61 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
62
63
64 // Sorting properties
65 m_naturalSorting = new QRadioButton(i18nc("option:radio", "Natural"));
66 m_caseInsensitiveSorting = new QRadioButton(i18nc("option:radio", "Alphabetical, case insensitive"));
67 m_caseSensitiveSorting = new QRadioButton(i18nc("option:radio", "Alphabetical, case sensitive"));
68
69 QButtonGroup* sortingModeGroup = new QButtonGroup(this);
70 sortingModeGroup->addButton(m_naturalSorting);
71 sortingModeGroup->addButton(m_caseInsensitiveSorting);
72 sortingModeGroup->addButton(m_caseSensitiveSorting);
73 topLayout->addRow(i18nc("@title:group", "Sorting mode: "), m_naturalSorting);
74 topLayout->addRow(QString(), m_caseInsensitiveSorting);
75 topLayout->addRow(QString(), m_caseSensitiveSorting);
76
77
78 topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
79
80
81 // 'Show tooltips'
82 m_showToolTips = new QCheckBox(i18nc("@option:check", "Show tooltips"));
83 topLayout->addRow(i18nc("@title:group", "Miscellaneous: "), m_showToolTips);
84
85 // 'Show selection marker'
86 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection marker"));
87 topLayout->addRow(QString(), m_showSelectionToggle);
88
89 // 'Inline renaming of items'
90 m_renameInline = new QCheckBox(i18nc("option:check", "Rename inline"));
91 topLayout->addRow(QString(), m_renameInline);
92
93 // 'Switch between split views with tab key'
94 m_useTabForSplitViewSwitch = new QCheckBox(i18nc("option:check", "Switch between split views with tab key"));
95 topLayout->addRow(QString(), m_useTabForSplitViewSwitch);
96
97 loadSettings();
98
99 connect(m_localViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
100 connect(m_globalViewProps, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
101 connect(m_showToolTips, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
102 connect(m_showSelectionToggle, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
103 connect(m_naturalSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
104 connect(m_caseInsensitiveSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
105 connect(m_caseSensitiveSorting, &QRadioButton::toggled, this, &BehaviorSettingsPage::changed);
106 connect(m_renameInline, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
107 connect(m_useTabForSplitViewSwitch, &QCheckBox::toggled, this, &BehaviorSettingsPage::changed);
108 }
109
110 BehaviorSettingsPage::~BehaviorSettingsPage()
111 {
112 }
113
114 void BehaviorSettingsPage::applySettings()
115 {
116 GeneralSettings* settings = GeneralSettings::self();
117 ViewProperties props(m_url); // read current view properties
118
119 const bool useGlobalViewProps = m_globalViewProps->isChecked();
120 settings->setGlobalViewProps(useGlobalViewProps);
121 settings->setShowToolTips(m_showToolTips->isChecked());
122 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
123 setSortingChoiceValue(settings);
124 settings->setRenameInline(m_renameInline->isChecked());
125 settings->setUseTabForSwitchingSplitView(m_useTabForSplitViewSwitch->isChecked());
126 settings->save();
127
128 if (useGlobalViewProps) {
129 // Remember the global view properties by applying the current view properties.
130 // It is important that GeneralSettings::globalViewProps() is set before
131 // the class ViewProperties is used, as ViewProperties uses this setting
132 // to find the destination folder for storing the view properties.
133 ViewProperties globalProps(m_url);
134 globalProps.setDirProperties(props);
135 }
136 }
137
138 void BehaviorSettingsPage::restoreDefaults()
139 {
140 GeneralSettings* settings = GeneralSettings::self();
141 settings->useDefaults(true);
142 loadSettings();
143 settings->useDefaults(false);
144 }
145
146 void BehaviorSettingsPage::loadSettings()
147 {
148 const bool useGlobalViewProps = GeneralSettings::globalViewProps();
149 m_localViewProps->setChecked(!useGlobalViewProps);
150 m_globalViewProps->setChecked(useGlobalViewProps);
151
152 m_showToolTips->setChecked(GeneralSettings::showToolTips());
153 m_showSelectionToggle->setChecked(GeneralSettings::showSelectionToggle());
154 m_renameInline->setChecked(GeneralSettings::renameInline());
155 m_useTabForSplitViewSwitch->setChecked(GeneralSettings::useTabForSwitchingSplitView());
156
157 loadSortingChoiceSettings();
158 }
159
160 void BehaviorSettingsPage::setSortingChoiceValue(GeneralSettings *settings)
161 {
162 using Choice = GeneralSettings::EnumSortingChoice;
163 if (m_naturalSorting->isChecked()) {
164 settings->setSortingChoice(Choice::NaturalSorting);
165 } else if (m_caseInsensitiveSorting->isChecked()) {
166 settings->setSortingChoice(Choice::CaseInsensitiveSorting);
167 } else if (m_caseSensitiveSorting->isChecked()) {
168 settings->setSortingChoice(Choice::CaseSensitiveSorting);
169 }
170 }
171
172 void BehaviorSettingsPage::loadSortingChoiceSettings()
173 {
174 using Choice = GeneralSettings::EnumSortingChoice;
175 switch (GeneralSettings::sortingChoice()) {
176 case Choice::NaturalSorting:
177 m_naturalSorting->setChecked(true);
178 break;
179 case Choice::CaseInsensitiveSorting:
180 m_caseInsensitiveSorting->setChecked(true);
181 break;
182 case Choice::CaseSensitiveSorting:
183 m_caseSensitiveSorting->setChecked(true);
184 break;
185 default:
186 Q_UNREACHABLE();
187 }
188 }