]> cloud.milkyroute.net Git - dolphin.git/blob - src/bookmarkselector.h
Ported to KBookmarkManager::closestBookmark - which even solves another TODO about...
[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, KBookmarkManager* bookmarkManager);
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 /** Returns the selected bookmark. */
61 KBookmark selectedBookmark() const;
62
63 /** @see QWidget::sizeHint() */
64 virtual QSize sizeHint() const;
65
66 signals:
67 /**
68 * Is send when a bookmark has been activated by the user.
69 * @param url URL of the selected bookmark.
70 */
71 void bookmarkActivated(const KUrl& url);
72
73 protected:
74 /**
75 * Draws the icon of the selected Url as content of the Url
76 * selector.
77 */
78 virtual void paintEvent(QPaintEvent* event);
79
80 private slots:
81 /**
82 * Updates the selected index and the icon to the bookmark
83 * which is indicated by the triggered action \a action.
84 */
85 void activateBookmark(QAction* action);
86
87 private:
88 QString m_selectedAddress;
89 UrlNavigator* m_urlNavigator;
90 KMenu* m_bookmarksMenu;
91 KBookmarkManager* m_bookmarkManager;
92 };
93
94 #endif