]> cloud.milkyroute.net Git - dolphin.git/blob - src/bookmarkselector.h
Converted to the standard mimetype names
[dolphin.git] / src / bookmarkselector.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef BOOKMARKSELECTOR_H
21 #define BOOKMARKSELECTOR_H
22
23 #include <kbookmark.h>
24 #include <urlbutton.h>
25
26 class UrlNavigator;
27 class KMenu;
28 class KUrl;
29
30 /**
31 * @brief Allows to select a bookmark from a popup menu.
32 *
33 * The icon from the current selected bookmark is shown
34 * inside the bookmark selector.
35 *
36 * @see UrlNavigator
37 */
38 class BookmarkSelector : public UrlButton
39 {
40 Q_OBJECT
41
42 public:
43 /**
44 * @param parent Parent widget where the bookmark selector
45 * is embedded into.
46 */
47 BookmarkSelector(UrlNavigator* parent);
48
49 virtual ~BookmarkSelector();
50
51 /**
52 * Updates the selection dependent from the given URL \a url. The
53 * URL must not match exactly to one of the available bookmarks:
54 * The bookmark which is equal to the URL or at least is a parent URL
55 * is selected. If there are more than one possible parent URL candidates,
56 * the bookmark which covers the bigger range of the URL is selected.
57 */
58 void updateSelection(const KUrl& url);
59
60 /**
61 * Returns the index of the selected bookmark. To get
62 * the bookmark, use BookmarkSelector::selectedBookmark().
63 */
64 int selectedIndex() const { return m_selectedIndex; }
65
66 /** Returns the selected bookmark. */
67 KBookmark selectedBookmark() const;
68
69 /** @see QWidget::sizeHint() */
70 virtual QSize sizeHint() const;
71
72 /**
73 * Returns the base bookmark for the URL \a url.
74 * The base bookmark is defined as bookmark which is equal to
75 * the URL or at least is a parent URL. If there are more than
76 * one possible parent URL candidates, the bookmark which covers
77 * the bigger range of the URL is returned.
78 *
79 * Example: the url is '/home/peter/Documents/Music. Available
80 * bookmarks are:
81 * - /home/peter
82 * - /home/peter/Documents
83 *
84 * The base URL will be '/home/peter/Documents'.
85 */
86 static KBookmark baseBookmark(const KUrl& url);
87
88 signals:
89 /**
90 * Is send when a bookmark has been activated by the user.
91 * @param url URL of the selected bookmark.
92 */
93 void bookmarkActivated(const KUrl& url);
94
95 protected:
96 /**
97 * Draws the icon of the selected Url as content of the Url
98 * selector.
99 */
100 virtual void paintEvent(QPaintEvent* event);
101
102 private slots:
103 /**
104 * Updates the selected index and the icon to the bookmark
105 * which is indicated by the triggered action \a action.
106 */
107 void activateBookmark(QAction* action);
108
109 private:
110 static int baseBookmarkIndex(const KUrl& url);
111
112 private:
113 int m_selectedIndex;
114 UrlNavigator* m_urlNavigator;
115 KMenu* m_bookmarksMenu;
116
117 };
118
119 #endif