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
;
49 * @brief Navigation bar which contains the current shown Url.
51 * The Url navigator offers two modes:
52 * - Editable: Represents the 'classic' mode, where the current Url
53 * is editable inside a line editor.
54 * - Non editable: The Url is represented by a number of buttons, where
55 * clicking on a button results in activating the Url
56 * the button represents. This mode also supports drag
59 * The mode can be changed by a toggle button located on the left side of
62 * The Url navigator also remembers the Url history and allows to go
63 * back and forward within this history.
68 typedef Q3ValueList
<KUrl
> UrlStack
;
70 class UrlNavigator
: public KHBox
76 * @brief Represents the history element of an Url.
78 * A history element contains the Url, the name of the current file
79 * (the 'current file' is the file where the cursor is located) and
80 * the x- and y-position of the content.
85 HistoryElem(const KUrl
& url
);
86 ~HistoryElem(); // non virtual
88 const KUrl
& url() const { return m_url
; }
90 void setCurrentFileName(const QString
& name
) { m_currentFileName
= name
; }
91 const QString
& currentFileName() const { return m_currentFileName
; }
93 void setContentsX(int x
) { m_contentsX
= x
; }
94 int contentsX() const { return m_contentsX
; }
96 void setContentsY(int y
) { m_contentsY
= y
; }
97 int contentsY() const { return m_contentsY
; }
101 QString m_currentFileName
;
106 UrlNavigator(const KUrl
& url
, DolphinView
* dolphinView
);
107 virtual ~UrlNavigator();
110 * Sets the current active Url.
111 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
114 void setUrl(const KUrl
& url
);
116 /** Returns the current active Url. */
117 const KUrl
& url() const;
119 /** Returns the portion of the current active Url up to the button at index. */
120 KUrl
url(int index
) const;
123 * Returns the complete Url history. The index 0 indicates the oldest
125 * @param index Output parameter which indicates the current
126 * index of the location.
128 const Q3ValueList
<HistoryElem
>& history(int& index
) const;
131 * Goes back one step in the Url history. The signals
132 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
138 * Goes forward one step in the Url history. The signals
139 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
145 * Goes up one step of the Url path. The signals
146 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
152 * Goes to the home Url. The signals UrlNavigator::urlChanged
153 * and UrlNavigator::historyChanged are submitted.
158 * @return True, if the Url is editable by the user within a line editor.
159 * If false is returned, each part of the Url is presented by a button
160 * for fast navigation.
162 bool isUrlEditable() const;
165 * Switches to the edit mode and assures that the keyboard focus
168 void editUrl(bool editOrBrowse
); //TODO: switch to an enum
170 DolphinView
* dolphinView() const;
173 void urlChanged(const KUrl
& url
);
174 void historyChanged();
177 /** If the Escape key is pressed, the navigation bar should switch
178 to the browse mode. */
179 virtual void keyReleaseEvent(QKeyEvent
* event
);
182 void slotReturnPressed(const QString
& text
);
183 void slotUrlActivated(const KUrl
& url
);
184 void slotRemoteHostActivated();
185 void slotProtocolChanged(const QString
& protocol
);
187 void slotRequestActivation();
188 void slotBookmarkActivated(int index
);
190 void slotRedirection(const KUrl
&, const KUrl
&);
193 * Stores the coordinates of the moved content into
194 * the current history element. Is usually triggered
195 * by the signal 'contentsMoved' emitted by DolphinView.
197 void slotContentsMoved(int x
, int y
);
200 * Switches the navigation bar between the editable and noneditable
201 * state (see setUrlEditable()) and is connected to the clicked signal
202 * of the navigation bar button.
208 DolphinView
* m_dolphinView
;
209 Q3ValueList
<HistoryElem
> m_history
;
210 QCheckBox
* m_toggleButton
;
211 BookmarkSelector
* m_bookmarkSelector
;
212 KUrlComboBox
* m_pathBox
;
213 ProtocolCombo
* m_protocols
;
214 QLabel
* m_protocolSeparator
;
216 Q3ValueList
<QWidget
*> m_navButtons
;
220 * Allows to edit the Url of the navigation bar if \a editable
221 * is true. If \a editable is false, each part of
222 * the Url is presented by a button for a fast navigation.
224 void setUrlEditable(bool editable
);
227 * Updates the history element with the current file item
228 * and the contents position.
230 void updateHistoryElem();
231 void updateContent();