X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ad5d3367c7fef4c3c11188a768f21a2ee2b3c025..b19b50fff1a17cca0443a6b09bd9caedca19f403:/src/dolphinurlnavigator.h diff --git a/src/dolphinurlnavigator.h b/src/dolphinurlnavigator.h index 032b81e89..d6da51b47 100644 --- a/src/dolphinurlnavigator.h +++ b/src/dolphinurlnavigator.h @@ -1,40 +1,23 @@ /* - * Copyright 2020 Felix Ernst - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ + This file is part of the KDE project + SPDX-FileCopyrightText: 2020 Felix Ernst + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ #ifndef DOLPHINURLNAVIGATOR_H #define DOLPHINURLNAVIGATOR_H -#include #include -#include - -class KToggleAction; - /** - * @brief Extends KUrlNavigator in a Dolphin-specific way - * - * Makes sure that Dolphin preferences, settings and settings changes are + * @brief Extends KUrlNavigator in a Dolphin-specific way. + * + * Makes sure that Dolphin preferences and settings are * applied to all constructed DolphinUrlNavigators. - * * @see KUrlNavigator + * + * To apply changes to all instances of this class @see DolphinUrlNavigatorsController. */ class DolphinUrlNavigator : public KUrlNavigator { @@ -53,63 +36,74 @@ public: */ DolphinUrlNavigator(const QUrl &url, QWidget *parent = nullptr); - virtual ~DolphinUrlNavigator(); + ~DolphinUrlNavigator() override; + + // TODO: Fix KUrlNavigator::sizeHint() instead. + QSize sizeHint() const override; -public slots: /** - * Refreshes all DolphinUrlNavigators to get synchronized with the - * Dolphin settings if they were changed. + * Wraps the visual state of a DolphinUrlNavigator so it can be passed around. + * This notably doesn't involve the locationUrl or history. */ - static void slotReadSettings(); + struct VisualState { + bool isUrlEditable; + bool hasFocus; + QString text; + int cursorPosition; + int selectionStart; + int selectionLength; + }; + /** + * Retrieve the visual state of this DolphinUrlNavigator. + * If two DolphinUrlNavigators have the same visual state they should look identical. + * + * @return a copy of the visualState of this object. Ownership of this copy is transferred + * to the caller via std::unique_ptr. + */ + std::unique_ptr visualState() const; + /** + * @param visualState A struct describing the new visual state of this object. + */ + void setVisualState(const VisualState &visualState); /** - * Switches to "breadcrumb" mode if the editable mode is not set to be - * preferred in the Dolphin settings. + * Clears the text in the text field */ - void slotReturnPressed(); + void clearText() const; /** - * This method is specifically here so the locationInToolbar - * KToggleAction that is created in DolphinMainWindow can be passed to - * this class and then appear in all context menus. This last part is - * done by eventFilter(). - * For any other use parts of this class need to be rewritten. - * @param action The locationInToolbar-action from DolphinMainWindow + * Displays placeholder text in the URL navigator */ - static void addToContextMenu(QAction *action); + void setPlaceholderText(const QString &text); - static void slotPlacesPanelVisibilityChanged(bool visible); + /** + * Sets the visibility of the read-only badge at the end of the breadcrumb. + */ + void setReadOnlyBadgeVisible(bool visible); -protected: /** - * Constructor-helper function + * Returns the visibility of the read-only badge at the end of the breadcrumb. */ - void init(); + bool readOnlyBadgeVisible() const; +public Q_SLOTS: /** - * This filter adds the s_ActionForContextMenu action to QMenus which - * are spawned by the watched QObject if that QMenu contains at least - * two separators. - * @see addToContextMenu() + * Switches to "breadcrumb" mode if the editable mode is not set to be + * preferred in the Dolphin settings. */ - bool eventFilter(QObject * watched, QEvent * event) override; + void slotReturnPressed(); -protected slots: +Q_SIGNALS: /** - * Sets the completion mode for all DolphinUrlNavigators - * and saves it in settings. + * Escape was pressed, and the focus should return to the view. */ - static void setCompletionMode(const KCompletion::CompletionMode completionMode); + void requestToLoseFocus(); protected: - /** Contains all currently constructed DolphinUrlNavigators */ - static std::forward_list s_instances; - - /** Caches the (negated) places panel visibility */ - static bool s_placesSelectorVisible; - - /** An action that is added to the context menu */ - static QAction *s_ActionForContextMenu; + /** + * Return focus back to the view when pressing Escape and this would have no other effect (e.g. deselecting or changing edit mode). + */ + void keyPressEvent(QKeyEvent *keyEvent) override; }; #endif // DOLPHINURLNAVIGATOR_H