File indexing completed on 2024-04-21 16:30:16

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2020 Felix Ernst <felixernst@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef DOLPHINURLNAVIGATOR_H
0009 #define DOLPHINURLNAVIGATOR_H
0010 
0011 #include <KUrlNavigator>
0012 
0013 /**
0014  * @brief Extends KUrlNavigator in a Dolphin-specific way.
0015  *
0016  * Makes sure that Dolphin preferences and settings are
0017  * applied to all constructed DolphinUrlNavigators.
0018  * @see KUrlNavigator
0019  *
0020  * To apply changes to all instances of this class @see DolphinUrlNavigatorsController.
0021  */
0022 class DolphinUrlNavigator : public KUrlNavigator
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     /**
0028      * Applies all Dolphin-specific settings to a KUrlNavigator
0029      * @see KUrlNavigator::KurlNavigator()
0030      */
0031     DolphinUrlNavigator(QWidget *parent = nullptr);
0032 
0033     /**
0034      * Applies all Dolphin-specific settings to a KUrlNavigator
0035      * @see KUrlNavigator::KurlNavigator()
0036      */
0037     DolphinUrlNavigator(const QUrl &url, QWidget *parent = nullptr);
0038 
0039     ~DolphinUrlNavigator() override;
0040 
0041     // TODO: Fix KUrlNavigator::sizeHint() instead.
0042     QSize sizeHint() const override;
0043 
0044     /**
0045      * Wraps the visual state of a DolphinUrlNavigator so it can be passed around.
0046      * This notably doesn't involve the locationUrl or history.
0047      */
0048     struct VisualState {
0049         bool isUrlEditable;
0050         bool hasFocus;
0051         QString text;
0052         int cursorPosition;
0053         int selectionStart;
0054         int selectionLength;
0055     };
0056     /**
0057      * Retrieve the visual state of this DolphinUrlNavigator.
0058      * If two DolphinUrlNavigators have the same visual state they should look identical.
0059      *
0060      * @return a copy of the visualState of this object. Ownership of this copy is transferred
0061      *         to the caller via std::unique_ptr.
0062      */
0063     std::unique_ptr<VisualState> visualState() const;
0064     /**
0065      * @param visualState A struct describing the new visual state of this object.
0066      */
0067     void setVisualState(const VisualState &visualState);
0068 
0069     /**
0070      * Clears the text in the text field
0071      */
0072     void clearText() const;
0073 
0074     /**
0075      * Displays placeholder text in the URL navigator
0076      */
0077     void setPlaceholderText(const QString &text);
0078 
0079 public Q_SLOTS:
0080     /**
0081      * Switches to "breadcrumb" mode if the editable mode is not set to be
0082      * preferred in the Dolphin settings.
0083      */
0084     void slotReturnPressed();
0085 };
0086 
0087 #endif // DOLPHINURLNAVIGATOR_H