]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinurlnavigator.h
Adress most of the second round of Angelaccio's review comments
[dolphin.git] / src / dolphinurlnavigator.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8 #ifndef DOLPHINURLNAVIGATOR_H
9 #define DOLPHINURLNAVIGATOR_H
10
11 #include <KUrlNavigator>
12
13 /**
14 * @brief Extends KUrlNavigator in a Dolphin-specific way.
15 *
16 * Makes sure that Dolphin preferences and settings are
17 * applied to all constructed DolphinUrlNavigators.
18 *
19 * @see KUrlNavigator
20 */
21 class DolphinUrlNavigator : public KUrlNavigator
22 {
23 Q_OBJECT
24
25 public:
26 /**
27 * Applies all Dolphin-specific settings to a KUrlNavigator
28 * @see KUrlNavigator::KurlNavigator()
29 */
30 DolphinUrlNavigator(QWidget *parent = nullptr);
31
32 /**
33 * Applies all Dolphin-specific settings to a KUrlNavigator
34 * @see KUrlNavigator::KurlNavigator()
35 */
36 DolphinUrlNavigator(const QUrl &url, QWidget *parent = nullptr);
37
38 virtual ~DolphinUrlNavigator();
39
40 // TODO: Fix KUrlNavigator::sizeHint() instead.
41 QSize sizeHint() const override;
42
43 /**
44 * Wraps the visual state of a DolphinUrlNavigator so it can be passed around.
45 * This notably doesn't involve the locationUrl or history.
46 */
47 struct VisualState {
48 bool isUrlEditable;
49 bool hasFocus;
50 QString text;
51 int cursorPosition;
52 int selectionStart;
53 int selectionLength;
54 };
55 /**
56 * Retrieve the visual state of this DolphinUrlNavigator.
57 * If two DolphinUrlNavigators have the same visual state they should look identical.
58 */
59 std::unique_ptr<VisualState> visualState() const;
60 /**
61 * @param visualState A struct describing the new visual state of this object.
62 */
63 void setVisualState(const VisualState &visualState);
64
65 public slots:
66 /**
67 * Switches to "breadcrumb" mode if the editable mode is not set to be
68 * preferred in the Dolphin settings.
69 */
70 void slotReturnPressed();
71 };
72
73 #endif // DOLPHINURLNAVIGATOR_H