]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinurlnavigator.h
Merge branch 'release/20.12'
[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 * @see KUrlNavigator
19 *
20 * To apply changes to all instances of this class @see DolphinUrlNavigatorsController.
21 */
22 class DolphinUrlNavigator : public KUrlNavigator
23 {
24 Q_OBJECT
25
26 public:
27 /**
28 * Applies all Dolphin-specific settings to a KUrlNavigator
29 * @see KUrlNavigator::KurlNavigator()
30 */
31 DolphinUrlNavigator(QWidget *parent = nullptr);
32
33 /**
34 * Applies all Dolphin-specific settings to a KUrlNavigator
35 * @see KUrlNavigator::KurlNavigator()
36 */
37 DolphinUrlNavigator(const QUrl &url, QWidget *parent = nullptr);
38
39 virtual ~DolphinUrlNavigator();
40
41 // TODO: Fix KUrlNavigator::sizeHint() instead.
42 QSize sizeHint() const override;
43
44 /**
45 * Wraps the visual state of a DolphinUrlNavigator so it can be passed around.
46 * This notably doesn't involve the locationUrl or history.
47 */
48 struct VisualState {
49 bool isUrlEditable;
50 bool hasFocus;
51 QString text;
52 int cursorPosition;
53 int selectionStart;
54 int selectionLength;
55 };
56 /**
57 * Retrieve the visual state of this DolphinUrlNavigator.
58 * If two DolphinUrlNavigators have the same visual state they should look identical.
59 *
60 * @return a copy of the visualState of this object. Ownership of this copy is transferred
61 * to the caller via std::unique_ptr.
62 */
63 std::unique_ptr<VisualState> visualState() const;
64 /**
65 * @param visualState A struct describing the new visual state of this object.
66 */
67 void setVisualState(const VisualState &visualState);
68
69 public slots:
70 /**
71 * Switches to "breadcrumb" mode if the editable mode is not set to be
72 * preferred in the Dolphin settings.
73 */
74 void slotReturnPressed();
75 };
76
77 #endif // DOLPHINURLNAVIGATOR_H