1 /**************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program 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 *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #ifndef UrlNAVIGATOR_H
22 #define UrlNAVIGATOR_H
27 #include <Q3ValueList>
29 #include <Q3PopupMenu>
44 class BookmarkSelector
;
48 * @brief Navigation bar which contains the current shown Url.
50 * The Url navigator offers two modes:
51 * - Editable: Represents the 'classic' mode, where the current Url
52 * is editable inside a line editor.
53 * - Non editable: The Url is represented by a number of buttons, where
54 * clicking on a button results in activating the Url
55 * the button represents. This mode also supports drag
58 * The mode can be changed by a toggle button located on the left side of
61 * The Url navigator also remembers the Url history and allows to go
62 * back and forward within this history.
67 typedef Q3ValueList
<KUrl
> UrlStack
;
69 class UrlNavigator
: public KHBox
75 * @brief Represents the history element of an Url.
77 * A history element contains the Url, the name of the current file
78 * (the 'current file' is the file where the cursor is located) and
79 * the x- and y-position of the content.
84 HistoryElem(const KUrl
& url
);
85 ~HistoryElem(); // non virtual
87 const KUrl
& url() const { return m_url
; }
89 void setCurrentFileName(const QString
& name
) { m_currentFileName
= name
; }
90 const QString
& currentFileName() const { return m_currentFileName
; }
92 void setContentsX(int x
) { m_contentsX
= x
; }
93 int contentsX() const { return m_contentsX
; }
95 void setContentsY(int y
) { m_contentsY
= y
; }
96 int contentsY() const { return m_contentsY
; }
100 QString m_currentFileName
;
105 UrlNavigator(const KUrl
& url
, QWidget
* parent
);
106 virtual ~UrlNavigator();
108 /** Returns the current active Url. */
109 const KUrl
& url() const;
111 /** Returns the portion of the current active Url up to the button at index. */
112 KUrl
url(int index
) const;
115 * Returns the complete Url history. The index 0 indicates the oldest
117 * @param index Output parameter which indicates the current
118 * index of the location.
120 const Q3ValueList
<HistoryElem
>& history(int& index
) const;
123 * Goes back one step in the Url history. The signals
124 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
130 * Goes forward one step in the Url history. The signals
131 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
137 * Goes up one step of the Url path. The signals
138 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
144 * Goes to the home Url. The signals UrlNavigator::urlChanged
145 * and UrlNavigator::historyChanged are submitted.
150 * @return True, if the Url is editable by the user within a line editor.
151 * If false is returned, each part of the Url is presented by a button
152 * for fast navigation.
154 bool isUrlEditable() const;
157 * Switches to the edit mode and assures that the keyboard focus
160 void editUrl(bool editOrBrowse
); //TODO: switch to an enum
163 * Set the URL navigator to the active mode, if \a active
164 * is true. The active mode is default. Using the URL navigator
165 * in the inactive mode is useful when having split views,
166 * where the inactive view is indicated by a an inactive URL
167 * navigator visually.
169 void setActive(bool active
);
172 * Returns true, if the URL navigator is in the active mode.
173 * @see UrlNavigator::setActive()
175 bool isActive() const { return m_active
; }
178 * Handles the dropping of the URLs \a urls to the given
179 * destination \a destination and emits the signal urlsDropped.
181 void dropUrls(const KUrl::List
& urls
,
182 const KUrl
& destination
);
186 * Sets the current active URL.
187 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
190 void setUrl(const KUrl
& url
);
193 * Activates the URL navigator (UrlNavigator::isActive() will return true)
194 * and emits the signal 'activationChanged()'.
196 void requestActivation();
199 * Stores the coordinates of the contents into
200 * the current history element.
202 void storeContentsPosition(int x
, int y
);
206 * Is emitted, if the URL navigator has been activated by
207 * a user interaction.
212 * Is emitted, if the URL has been changed e. g. by
216 void urlChanged(const KUrl
& url
);
219 * Is emitted, if the history has been changed. Usually
220 * the history is changed if a new URL has been selected.
222 void historyChanged();
225 * Is emitted if the URLs \a urls have been dropped
226 * to the destination \a destination.
228 void urlsDropped(const KUrl::List
& urls
,
229 const KUrl
& destination
);
232 /** If the Escape key is pressed, the navigation bar should switch
233 to the browse mode. */
234 virtual void keyReleaseEvent(QKeyEvent
* event
);
237 void slotReturnPressed(const QString
& text
);
238 void slotUrlActivated(const KUrl
& url
);
239 void slotRemoteHostActivated();
240 void slotProtocolChanged(const QString
& protocol
);
241 void slotRedirection(const KUrl
&, const KUrl
&);
244 * Switches the navigation bar between the editable and noneditable
245 * state (see setUrlEditable()) and is connected to the clicked signal
246 * of the navigation bar button.
253 Q3ValueList
<HistoryElem
> m_history
;
254 QCheckBox
* m_toggleButton
;
255 BookmarkSelector
* m_bookmarkSelector
;
256 KUrlComboBox
* m_pathBox
;
257 ProtocolCombo
* m_protocols
;
258 QLabel
* m_protocolSeparator
;
260 Q3ValueList
<QWidget
*> m_navButtons
;
264 * Allows to edit the Url of the navigation bar if \a editable
265 * is true. If \a editable is false, each part of
266 * the Url is presented by a button for a fast navigation.
268 void setUrlEditable(bool editable
);
271 * Updates the history element with the current file item
272 * and the contents position.
274 void updateHistoryElem();
275 void updateContent();