]> cloud.milkyroute.net Git - dolphin.git/blob - src/bookmarkselector.h
Dolphin is now a KUniqueApplication. A lot of thanks go to Oscar Blumberg, who submit...
[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 signals:
73 /**
74 * Is send when a bookmark has been activated by the user.
75 * @param url URL of the selected bookmark.
76 */
77 void bookmarkActivated(const KUrl& url);
78
79 protected:
80 /**
81 * Draws the icon of the selected Url as content of the Url
82 * selector.
83 */
84 virtual void paintEvent(QPaintEvent* event);
85
86 private slots:
87 /**
88 * Updates the selected index and the icon to the bookmark
89 * which is indicated by the triggered action \a action.
90 */
91 void activateBookmark(QAction* action);
92
93 private:
94 int m_selectedIndex;
95 UrlNavigator* m_urlNavigator;
96 KMenu* m_bookmarksMenu;
97
98 };
99
100 #endif