]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinurlnavigator.h
Apply 1 suggestion(s) to 1 file(s)
[dolphin.git] / src / dolphinurlnavigator.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2020 Felix Ernst <felixernst@kde.org>
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 ~DolphinUrlNavigator() override;
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 /**
70 * Clears the text in the text field
71 */
72 void clearText() const;
73
74 /**
75 * Displays placeholder text in the URL navigator
76 */
77 void setPlaceholderText(const QString &text);
78
79 /**
80 * Sets the visibility of the read-only badge at the end of the breadcrumb.
81 */
82 void setReadOnlyBadgeVisible(bool visible);
83
84 /**
85 * Returns the visibility of the read-only badge at the end of the breadcrumb.
86 */
87 bool readOnlyBadgeVisible() const;
88
89 public Q_SLOTS:
90 /**
91 * Switches to "breadcrumb" mode if the editable mode is not set to be
92 * preferred in the Dolphin settings.
93 */
94 void slotReturnPressed();
95
96 Q_SIGNALS:
97 /**
98 * Escape was pressed, and the focus should return to the view.
99 */
100 void requestToLoseFocus();
101
102 protected:
103 /**
104 * Return focus back to the view when pressing Escape and this would have no other effect (e.g. deselecting or changing edit mode).
105 */
106 void keyPressEvent(QKeyEvent *keyEvent) override;
107 };
108
109 #endif // DOLPHINURLNAVIGATOR_H