]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinurlnavigatorwidgetaction.cpp
Add an option to use an UrlNavigator in the toolbar instead
[dolphin.git] / src / views / dolphinurlnavigatorwidgetaction.cpp
1 /*
2 * Copyright 2020 Felix Ernst <fe.a.ernst@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) version 3, or any
8 * later version accepted by the membership of KDE e.V. (or its
9 * successor approved by the membership of KDE e.V.), which shall
10 * act as a proxy defined in Section 6 of version 3 of the license.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 #include "dolphinurlnavigatorwidgetaction.h"
22
23 #include "dolphin_generalsettings.h"
24 #include "dolphinviewcontainer.h"
25
26 #include <KLocalizedString>
27
28 DolphinUrlNavigatorWidgetAction::DolphinUrlNavigatorWidgetAction(QWidget *parent) :
29 QWidgetAction(parent)
30 {
31 setText(i18nc("@action:inmenu", "Url navigator"));
32
33 m_stackedWidget = new QStackedWidget(parent);
34
35 auto expandingSpacer = new QWidget(m_stackedWidget);
36 expandingSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
37 m_stackedWidget->addWidget(expandingSpacer); // index 0 of QStackedWidget
38
39 auto urlNavigator = new DolphinUrlNavigator(m_stackedWidget);
40 m_stackedWidget->addWidget(urlNavigator); // index 1 of QStackedWidget
41
42 setDefaultWidget(m_stackedWidget);
43 setUrlNavigatorVisible(GeneralSettings::locationInToolbar());
44 }
45
46 DolphinUrlNavigator* DolphinUrlNavigatorWidgetAction::urlNavigator() const
47 {
48 return static_cast<DolphinUrlNavigator *>(m_stackedWidget->widget(1));
49 }
50
51 void DolphinUrlNavigatorWidgetAction::setUrlNavigatorVisible(bool visible)
52 {
53 if (!visible) {
54 m_stackedWidget->setCurrentIndex(0); // expandingSpacer
55 } else {
56 m_stackedWidget->setCurrentIndex(1); // urlNavigator
57 }
58 }