]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinurlnavigator.h
Add an option to use an UrlNavigator in the toolbar instead
[dolphin.git] / src / dolphinurlnavigator.h
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 #ifndef DOLPHINURLNAVIGATOR_H
22 #define DOLPHINURLNAVIGATOR_H
23
24 #include <KCompletion>
25 #include <KUrlNavigator>
26
27 #include <forward_list>
28
29 class KToggleAction;
30
31 /**
32 * @brief Extends KUrlNavigator in a Dolphin-specific way
33 *
34 * Makes sure that Dolphin preferences, settings and settings changes are
35 * applied to all constructed DolphinUrlNavigators.
36 *
37 * @see KUrlNavigator
38 */
39 class DolphinUrlNavigator : public KUrlNavigator
40 {
41 Q_OBJECT
42
43 public:
44 /**
45 * Applies all Dolphin-specific settings to a KUrlNavigator
46 * @see KUrlNavigator::KurlNavigator()
47 */
48 DolphinUrlNavigator(QWidget *parent = nullptr);
49
50 /**
51 * Applies all Dolphin-specific settings to a KUrlNavigator
52 * @see KUrlNavigator::KurlNavigator()
53 */
54 DolphinUrlNavigator(const QUrl &url, QWidget *parent = nullptr);
55
56 virtual ~DolphinUrlNavigator();
57
58 public slots:
59 /**
60 * Refreshes all DolphinUrlNavigators to get synchronized with the
61 * Dolphin settings if they were changed.
62 */
63 static void slotReadSettings();
64
65 /**
66 * Switches to "breadcrumb" mode if the editable mode is not set to be
67 * preferred in the Dolphin settings.
68 */
69 void slotReturnPressed();
70
71 /**
72 * This method is specifically here so the locationInToolbar
73 * KToggleAction that is created in DolphinMainWindow can be passed to
74 * this class and then appear in all context menus. This last part is
75 * done by eventFilter().
76 * For any other use parts of this class need to be rewritten.
77 * @param action The locationInToolbar-action from DolphinMainWindow
78 */
79 static void addToContextMenu(QAction *action);
80
81 static void slotPlacesPanelVisibilityChanged(bool visible);
82
83 protected:
84 /**
85 * Constructor-helper function
86 */
87 void init();
88
89 /**
90 * This filter adds the s_ActionForContextMenu action to QMenus which
91 * are spawned by the watched QObject if that QMenu contains at least
92 * two separators.
93 * @see addToContextMenu()
94 */
95 bool eventFilter(QObject * watched, QEvent * event) override;
96
97 protected slots:
98 /**
99 * Sets the completion mode for all DolphinUrlNavigators
100 * and saves it in settings.
101 */
102 static void setCompletionMode(const KCompletion::CompletionMode completionMode);
103
104 protected:
105 /** Contains all currently constructed DolphinUrlNavigators */
106 static std::forward_list<DolphinUrlNavigator *> s_instances;
107
108 /** Caches the (negated) places panel visibility */
109 static bool s_placesSelectorVisible;
110
111 /** An action that is added to the context menu */
112 static QAction *s_ActionForContextMenu;
113 };
114
115 #endif // DOLPHINURLNAVIGATOR_H