Changeset View
Changeset View
Standalone View
Standalone View
src/settings/startup/startupsettingspage.cpp
Show All 19 Lines | |||||
20 | #include "startupsettingspage.h" | 20 | #include "startupsettingspage.h" | ||
21 | 21 | | |||
22 | #include "dolphin_generalsettings.h" | 22 | #include "dolphin_generalsettings.h" | ||
23 | #include "dolphinmainwindow.h" | 23 | #include "dolphinmainwindow.h" | ||
24 | #include "dolphinviewcontainer.h" | 24 | #include "dolphinviewcontainer.h" | ||
25 | #include "global.h" | 25 | #include "global.h" | ||
26 | 26 | | |||
27 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
28 | #include <KMessageBox> | 28 | #include <KMessageWidget> | ||
29 | 29 | | |||
30 | #include <QCheckBox> | 30 | #include <QCheckBox> | ||
31 | #include <QFileDialog> | 31 | #include <QFileDialog> | ||
32 | #include <QGroupBox> | 32 | #include <QGroupBox> | ||
33 | #include <QLabel> | 33 | #include <QLabel> | ||
34 | #include <QLineEdit> | 34 | #include <QLineEdit> | ||
35 | #include <QPushButton> | 35 | #include <QPushButton> | ||
36 | #include <QFormLayout> | ||||
37 | #include <QHBoxLayout> | ||||
36 | #include <QVBoxLayout> | 38 | #include <QVBoxLayout> | ||
37 | 39 | | |||
38 | StartupSettingsPage::StartupSettingsPage(const QUrl& url, QWidget* parent) : | 40 | StartupSettingsPage::StartupSettingsPage(const QUrl& url, QWidget* parent) : | ||
39 | SettingsPageBase(parent), | 41 | SettingsPageBase(parent), | ||
40 | m_url(url), | 42 | m_url(url), | ||
41 | m_homeUrl(nullptr), | 43 | m_homeUrl(nullptr), | ||
42 | m_splitView(nullptr), | 44 | m_splitView(nullptr), | ||
43 | m_editableUrl(nullptr), | 45 | m_editableUrl(nullptr), | ||
44 | m_showFullPath(nullptr), | 46 | m_showFullPath(nullptr), | ||
45 | m_filterBar(nullptr), | 47 | m_filterBar(nullptr), | ||
46 | m_showFullPathInTitlebar(nullptr) | 48 | m_showFullPathInTitlebar(nullptr), | ||
49 | m_topLayout(nullptr) | ||||
47 | { | 50 | { | ||
48 | QVBoxLayout* topLayout = new QVBoxLayout(this); | 51 | m_topLayout = new QFormLayout(this); | ||
49 | QWidget* vBox = new QWidget(this); | | |||
50 | QVBoxLayout *vBoxLayout = new QVBoxLayout(vBox); | | |||
51 | vBoxLayout->setMargin(0); | | |||
52 | vBoxLayout->setAlignment(Qt::AlignTop); | | |||
53 | 52 | | |||
54 | // create 'Home URL' editor | | |||
55 | QGroupBox* homeBox = new QGroupBox(i18nc("@title:group", "Home Folder"), vBox); | | |||
56 | vBoxLayout->addWidget(homeBox); | | |||
57 | | ||||
58 | QWidget* homeUrlBox = new QWidget(homeBox); | | |||
59 | QHBoxLayout *homeUrlBoxLayout = new QHBoxLayout(homeUrlBox); | | |||
60 | homeUrlBoxLayout->setMargin(0); | | |||
61 | 53 | | |||
elvisangelaccio: Please add a parent to this layout | |||||
My understanding of Qt's layout system is that any item (including a layout) that will be added to a layout doesn't need to be given a parent, since Qt automatically re-parents it to the layout it's added to. ngraham: My understanding of Qt's layout system is that any item (including a layout) that will be added… | |||||
elvisangelaccio: Oh, right! | |||||
62 | QLabel* homeUrlLabel = new QLabel(i18nc("@label:textbox", "Location:"), homeUrlBox); | 54 | // create 'Home URL' editor | ||
63 | homeUrlBoxLayout->addWidget(homeUrlLabel); | 55 | m_homeUrl = new QLineEdit(); | ||
64 | m_homeUrl = new QLineEdit(homeUrlBox); | | |||
65 | homeUrlBoxLayout->addWidget(m_homeUrl); | | |||
66 | m_homeUrl->setClearButtonEnabled(true); | 56 | m_homeUrl->setClearButtonEnabled(true); | ||
67 | 57 | | |||
68 | QPushButton* selectHomeUrlButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString(), homeUrlBox); | 58 | QPushButton* selectHomeUrlButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString()); | ||
69 | homeUrlBoxLayout->addWidget(selectHomeUrlButton); | | |||
70 | | ||||
71 | #ifndef QT_NO_ACCESSIBILITY | 59 | #ifndef QT_NO_ACCESSIBILITY | ||
72 | selectHomeUrlButton->setAccessibleName(i18nc("@action:button", "Select Home Location")); | 60 | selectHomeUrlButton->setAccessibleName(i18nc("@action:button", "Select Home Location")); | ||
73 | #endif | 61 | #endif | ||
74 | 62 | | |||
75 | connect(selectHomeUrlButton, &QPushButton::clicked, | 63 | QHBoxLayout *homeUrlBoxLayout = new QHBoxLayout(); | ||
76 | this, &StartupSettingsPage::selectHomeUrl); | 64 | homeUrlBoxLayout->setMargin(0); | ||
65 | homeUrlBoxLayout->addWidget(m_homeUrl); | ||||
66 | homeUrlBoxLayout->addWidget(selectHomeUrlButton); | ||||
67 | | ||||
68 | | ||||
elvisangelaccio: Please add a parent to this layout | |||||
ngraham: Same ^^ | |||||
69 | QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location")); | ||||
70 | | ||||
71 | QVBoxLayout *locationLayout = new QVBoxLayout(); | ||||
72 | locationLayout->setMargin(0); | ||||
73 | locationLayout->addLayout(homeUrlBoxLayout); | ||||
74 | locationLayout->addWidget(useCurrentButton); | ||||
75 | locationLayout->setStretchFactor(useCurrentButton, 1); | ||||
76 | | ||||
77 | m_topLayout->addRow(i18nc("@label:textbox", "Location:"), locationLayout); | ||||
78 | | ||||
79 | | ||||
80 | m_topLayout->addItem(new QSpacerItem(0,12, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||||
77 | 81 | | |||
78 | QWidget* buttonBox = new QWidget(homeBox); | | |||
79 | QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox); | | |||
80 | buttonBoxLayout->setMargin(0); | | |||
81 | | ||||
82 | QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location"), buttonBox); | | |||
83 | buttonBoxLayout->addWidget(useCurrentButton); | | |||
84 | connect(useCurrentButton, &QPushButton::clicked, | | |||
85 | this, &StartupSettingsPage::useCurrentLocation); | | |||
86 | QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location"), buttonBox); | | |||
87 | buttonBoxLayout->addWidget(useDefaultButton); | | |||
88 | connect(useDefaultButton, &QPushButton::clicked, | | |||
89 | this, &StartupSettingsPage::useDefaultLocation); | | |||
90 | | ||||
91 | QVBoxLayout* homeBoxLayout = new QVBoxLayout(homeBox); | | |||
92 | homeBoxLayout->addWidget(homeUrlBox); | | |||
93 | homeBoxLayout->addWidget(buttonBox); | | |||
94 | 82 | | |||
95 | // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes | 83 | // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes | ||
96 | m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode"), vBox); | 84 | m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode")); | ||
97 | vBoxLayout->addWidget(m_splitView); | 85 | m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar")); | ||
98 | m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar"), vBox); | 86 | m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar")); | ||
99 | vBoxLayout->addWidget(m_editableUrl); | 87 | m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar")); | ||
100 | m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"), vBox); | 88 | m_showFullPathInTitlebar = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path in title bar")); | ||
101 | vBoxLayout->addWidget(m_showFullPath); | 89 | | ||
102 | m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar"), vBox); | 90 | m_topLayout->addRow(i18nc("@label:checkbox", "View options:"), m_splitView); | ||
103 | vBoxLayout->addWidget(m_filterBar); | 91 | m_topLayout->addRow(QString(), m_editableUrl); | ||
104 | m_showFullPathInTitlebar = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path in title bar"), vBox); | 92 | m_topLayout->addRow(QString(), m_showFullPath); | ||
105 | vBoxLayout->addWidget(m_showFullPathInTitlebar); | 93 | m_topLayout->addRow(QString(), m_filterBar); | ||
106 | 94 | m_topLayout->addRow(QString(), m_showFullPathInTitlebar); | |||
107 | // Add a dummy widget with no restriction regarding | | |||
108 | // a vertical resizing. This assures that the dialog layout | | |||
109 | // is not stretched vertically. | | |||
110 | new QWidget(vBox); | | |||
111 | 95 | | |||
112 | topLayout->addWidget(vBox); | | |||
113 | 96 | | |||
114 | loadSettings(); | 97 | loadSettings(); | ||
115 | 98 | | |||
99 | connect(selectHomeUrlButton, &QPushButton::clicked, this, &StartupSettingsPage::selectHomeUrl); | ||||
100 | connect(useCurrentButton, &QPushButton::clicked, this, &StartupSettingsPage::useCurrentLocation); | ||||
116 | connect(m_homeUrl, &QLineEdit::textChanged, this, &StartupSettingsPage::slotSettingsChanged); | 101 | connect(m_homeUrl, &QLineEdit::textChanged, this, &StartupSettingsPage::slotSettingsChanged); | ||
117 | connect(m_splitView, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 102 | connect(m_splitView, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
118 | connect(m_editableUrl, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 103 | connect(m_editableUrl, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
119 | connect(m_showFullPath, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 104 | connect(m_showFullPath, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
120 | connect(m_filterBar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 105 | connect(m_filterBar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
121 | connect(m_showFullPathInTitlebar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 106 | connect(m_showFullPathInTitlebar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
122 | } | 107 | } | ||
123 | 108 | | |||
124 | StartupSettingsPage::~StartupSettingsPage() | 109 | StartupSettingsPage::~StartupSettingsPage() | ||
125 | { | 110 | { | ||
126 | } | 111 | } | ||
127 | 112 | | |||
128 | void StartupSettingsPage::applySettings() | 113 | void StartupSettingsPage::applySettings() | ||
129 | { | 114 | { | ||
130 | GeneralSettings* settings = GeneralSettings::self(); | 115 | GeneralSettings* settings = GeneralSettings::self(); | ||
131 | 116 | | |||
132 | const QUrl url(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile)); | 117 | const QUrl url(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile)); | ||
133 | KFileItem fileItem(url); | 118 | KFileItem fileItem(url); | ||
134 | if ((url.isValid() && fileItem.isDir()) || (url.scheme() == QLatin1String("timeline"))) { | 119 | if ((url.isValid() && fileItem.isDir()) || (url.scheme() == QLatin1String("timeline"))) { | ||
135 | settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile)); | 120 | settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile)); | ||
136 | } else { | 121 | } else { | ||
137 | KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied.")); | 122 | KMessageWidget* warningWidget = new KMessageWidget(); | ||
123 | warningWidget->hide(); | ||||
124 | warningWidget->setText(i18n("Choose a valid location.")); | ||||
125 | warningWidget->setCloseButtonVisible(true); | ||||
126 | warningWidget->setMessageType(KMessageWidget::Warning); | ||||
127 | m_topLayout->insertRow(0, warningWidget); | ||||
128 | warningWidget->animatedShow(); | ||||
138 | } | 129 | } | ||
139 | 130 | | |||
140 | settings->setSplitView(m_splitView->isChecked()); | 131 | settings->setSplitView(m_splitView->isChecked()); | ||
141 | settings->setEditableUrl(m_editableUrl->isChecked()); | 132 | settings->setEditableUrl(m_editableUrl->isChecked()); | ||
142 | settings->setShowFullPath(m_showFullPath->isChecked()); | 133 | settings->setShowFullPath(m_showFullPath->isChecked()); | ||
143 | settings->setFilterBar(m_filterBar->isChecked()); | 134 | settings->setFilterBar(m_filterBar->isChecked()); | ||
144 | settings->setShowFullPathInTitlebar(m_showFullPathInTitlebar->isChecked()); | 135 | settings->setShowFullPathInTitlebar(m_showFullPathInTitlebar->isChecked()); | ||
145 | 136 | | |||
Show All 27 Lines | 158 | { | |||
173 | } | 164 | } | ||
174 | } | 165 | } | ||
175 | 166 | | |||
176 | void StartupSettingsPage::useCurrentLocation() | 167 | void StartupSettingsPage::useCurrentLocation() | ||
177 | { | 168 | { | ||
178 | m_homeUrl->setText(m_url.toDisplayString(QUrl::PreferLocalFile)); | 169 | m_homeUrl->setText(m_url.toDisplayString(QUrl::PreferLocalFile)); | ||
179 | } | 170 | } | ||
180 | 171 | | |||
181 | void StartupSettingsPage::useDefaultLocation() | | |||
182 | { | | |||
183 | m_homeUrl->setText(QDir::homePath()); | | |||
184 | } | | |||
185 | | ||||
186 | void StartupSettingsPage::loadSettings() | 172 | void StartupSettingsPage::loadSettings() | ||
187 | { | 173 | { | ||
188 | const QUrl url(Dolphin::homeUrl()); | 174 | const QUrl url(Dolphin::homeUrl()); | ||
189 | m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); | 175 | m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); | ||
190 | m_splitView->setChecked(GeneralSettings::splitView()); | 176 | m_splitView->setChecked(GeneralSettings::splitView()); | ||
191 | m_editableUrl->setChecked(GeneralSettings::editableUrl()); | 177 | m_editableUrl->setChecked(GeneralSettings::editableUrl()); | ||
192 | m_showFullPath->setChecked(GeneralSettings::showFullPath()); | 178 | m_showFullPath->setChecked(GeneralSettings::showFullPath()); | ||
193 | m_filterBar->setChecked(GeneralSettings::filterBar()); | 179 | m_filterBar->setChecked(GeneralSettings::filterBar()); | ||
194 | m_showFullPathInTitlebar->setChecked(GeneralSettings::showFullPathInTitlebar()); | 180 | m_showFullPathInTitlebar->setChecked(GeneralSettings::showFullPathInTitlebar()); | ||
195 | } | 181 | } |
Please add a parent to this layout