1/***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * Copyright (C) 2007 by Kevin Ottens (ervin@kde.org) *
4 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Lesser General Public *
7 * License as published by the Free Software Foundation; either *
8 * version 2 of the License, or (at your option) any later version. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Lesser General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Lesser General Public *
16 * License along with this library; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21#ifndef KURLNAVIGATORPLACESSELECTOR_P_H
22#define KURLNAVIGATORPLACESSELECTOR_P_H
23
24#include "kurlnavigatorbuttonbase_p.h"
25#include <kurl.h>
26
27#include <QtCore/QPersistentModelIndex>
28
29class KFilePlacesModel;
30class KMenu;
31
32namespace KDEPrivate
33{
34
35/**
36 * @brief Allows to select a bookmark from a popup menu.
37 *
38 * The icon from the current selected bookmark is shown
39 * inside the bookmark selector.
40 *
41 * @see KUrlNavigator
42 * @internal
43 */
44class KUrlNavigatorPlacesSelector : public KUrlNavigatorButtonBase
45{
46 Q_OBJECT
47
48public:
49 /**
50 * @param parent Parent widget where the bookmark selector
51 * is embedded into.
52 */
53 KUrlNavigatorPlacesSelector(QWidget* parent, KFilePlacesModel* placesModel);
54
55 virtual ~KUrlNavigatorPlacesSelector();
56
57 /**
58 * Updates the selection dependent from the given URL \a url. The
59 * URL must not match exactly to one of the available bookmarks:
60 * The bookmark which is equal to the URL or at least is a parent URL
61 * is selected. If there are more than one possible parent URL candidates,
62 * the bookmark which covers the bigger range of the URL is selected.
63 */
64 void updateSelection(const KUrl& url);
65
66 /** Returns the selected bookmark. */
67 KUrl selectedPlaceUrl() const;
68 /** Returns the selected bookmark. */
69 QString selectedPlaceText() const;
70
71 /** @see QWidget::sizeHint() */
72 virtual QSize sizeHint() const;
73
74Q_SIGNALS:
75 /**
76 * Is send when a bookmark has been activated by the user.
77 * @param url URL of the selected place.
78 */
79 void placeActivated(const KUrl& url);
80
81protected:
82 /**
83 * Draws the icon of the selected Url as content of the Url
84 * selector.
85 */
86 virtual void paintEvent(QPaintEvent* event);
87
88 virtual void dragEnterEvent(QDragEnterEvent* event);
89 virtual void dragLeaveEvent(QDragLeaveEvent* event);
90 virtual void dropEvent(QDropEvent* event);
91
92private Q_SLOTS:
93 /**
94 * Updates the selected index and the icon to the bookmark
95 * which is indicated by the triggered action \a action.
96 */
97 void activatePlace(QAction* action);
98
99 void updateMenu();
100 void updateTeardownAction();
101
102 void onStorageSetupDone(const QModelIndex &index, bool success);
103
104private:
105 int m_selectedItem;
106 QPersistentModelIndex m_lastClickedIndex;
107 KMenu* m_placesMenu;
108 KFilePlacesModel* m_placesModel;
109 KUrl m_selectedUrl;
110};
111
112} // namespace KDEPrivate
113
114#endif
115