| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at> |
| 3 | SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef KURLNAVIGATORPLACESSELECTOR_P_H |
| 9 | #define KURLNAVIGATORPLACESSELECTOR_P_H |
| 10 | |
| 11 | #include "kurlnavigatorbuttonbase_p.h" |
| 12 | #include <QUrl> |
| 13 | |
| 14 | #include <QPersistentModelIndex> |
| 15 | |
| 16 | class KFilePlacesModel; |
| 17 | class ; |
| 18 | |
| 19 | namespace KDEPrivate |
| 20 | { |
| 21 | /*! |
| 22 | * Allows to select a bookmark from a popup menu. |
| 23 | * |
| 24 | * The icon from the current selected bookmark is shown |
| 25 | * inside the bookmark selector. |
| 26 | * |
| 27 | * \sa KUrlNavigator |
| 28 | * \internal |
| 29 | */ |
| 30 | class KUrlNavigatorPlacesSelector : public KUrlNavigatorButtonBase |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | |
| 34 | public: |
| 35 | /*! |
| 36 | * \a parent Parent widget where the bookmark selector |
| 37 | * is embedded into. |
| 38 | */ |
| 39 | KUrlNavigatorPlacesSelector(KUrlNavigator *parent, KFilePlacesModel *placesModel); |
| 40 | |
| 41 | ~KUrlNavigatorPlacesSelector() override; |
| 42 | |
| 43 | using ActivationSignal = void (KUrlNavigatorPlacesSelector::*)(const QUrl &); |
| 44 | |
| 45 | /*! |
| 46 | * Updates the selection dependent from the given URL \a url. The |
| 47 | * URL must not match exactly to one of the available bookmarks: |
| 48 | * The bookmark which is equal to the URL or at least is a parent URL |
| 49 | * is selected. If there are more than one possible parent URL candidates, |
| 50 | * the bookmark which covers the bigger range of the URL is selected. |
| 51 | */ |
| 52 | void updateSelection(const QUrl &url); |
| 53 | |
| 54 | /*! Returns the selected bookmark. */ |
| 55 | QUrl selectedPlaceUrl() const; |
| 56 | /*! Returns the selected bookmark. */ |
| 57 | QString selectedPlaceText() const; |
| 58 | |
| 59 | /*! \sa QWidget::sizeHint() */ |
| 60 | QSize sizeHint() const override; |
| 61 | |
| 62 | Q_SIGNALS: |
| 63 | /*! |
| 64 | * Is send when a bookmark has been activated by the user. |
| 65 | * \a url URL of the selected place. |
| 66 | */ |
| 67 | void placeActivated(const QUrl &url); |
| 68 | |
| 69 | /*! |
| 70 | * Is sent when a bookmark was middle clicked by the user |
| 71 | * and thus should be opened in a new tab. |
| 72 | */ |
| 73 | void tabRequested(const QUrl &url); |
| 74 | |
| 75 | protected: |
| 76 | /*! |
| 77 | * Draws the icon of the selected Url as content of the Url |
| 78 | * selector. |
| 79 | */ |
| 80 | void paintEvent(QPaintEvent *event) override; |
| 81 | |
| 82 | void dragEnterEvent(QDragEnterEvent *event) override; |
| 83 | void dragLeaveEvent(QDragLeaveEvent *event) override; |
| 84 | void dropEvent(QDropEvent *event) override; |
| 85 | void mouseReleaseEvent(QMouseEvent *event) override; |
| 86 | |
| 87 | bool eventFilter(QObject *watched, QEvent *event) override; |
| 88 | |
| 89 | private Q_SLOTS: |
| 90 | /*! |
| 91 | * Updates the selected index and the icon to the bookmark |
| 92 | * which is indicated by the triggered action \a action. |
| 93 | */ |
| 94 | void activatePlace(QAction *action, ActivationSignal activationSignal); |
| 95 | |
| 96 | void (); |
| 97 | |
| 98 | void onStorageSetupDone(const QModelIndex &index, bool success); |
| 99 | |
| 100 | private: |
| 101 | int m_selectedItem; |
| 102 | QPersistentModelIndex m_lastClickedIndex; |
| 103 | ActivationSignal m_lastActivationSignal = nullptr; |
| 104 | QMenu *; |
| 105 | KFilePlacesModel *m_placesModel; |
| 106 | QUrl m_selectedUrl; |
| 107 | }; |
| 108 | |
| 109 | } // namespace KDEPrivate |
| 110 | |
| 111 | #endif |
| 112 | |