#include <kurlcombobox.h>
#include <kurlcompletion.h>
-#include <QDir>
+#include <QApplication>
+#include <QClipboard>
#include <QCheckBox>
+#include <QDir>
+#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
+#include <QMouseEvent>
UrlNavigator::HistoryElem::HistoryElem() :
m_url(),
UrlNavigator::UrlNavigator(const KUrl& url,
QWidget* parent) :
- KHBox(parent),
+ QWidget(parent),
m_active(true),
m_historyIndex(0),
+ m_layout(0),
m_protocols(0),
m_protocolSeparator(0),
m_host(0)
{
+ m_layout = new QHBoxLayout();
+ m_layout->setSpacing(0);
+ m_layout->setMargin(0);
+
m_history.prepend(HistoryElem(url));
QFontMetrics fontMetrics(font());
setMinimumHeight(fontMetrics.height() + 8);
- m_toggleButton = new QCheckBox(this);
- //m_toggleButton->setFlat(true);
- //m_toggleButton->setToggleButton(true);
+ m_toggleButton = new QCheckBox();
m_toggleButton->setFocusPolicy(Qt::NoFocus);
m_toggleButton->setMinimumHeight(minimumHeight());
connect(m_toggleButton, SIGNAL(clicked()),
//connect(dolphinView, SIGNAL(redirection(const KUrl&, const KUrl&)),
// this, SLOT(slotRedirection(const KUrl&, const KUrl&)));
+
+ // Append a filler widget at the end, which automatically resizes to the
+ // maximum available width. This assures that the URL navigator uses the
+ // whole width, so that the clipboard content can be dropped.
+ QWidget* filler = new QWidget();
+ filler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+
+ m_layout->addWidget(m_toggleButton);
+ m_layout->addWidget(m_bookmarkSelector);
+ m_layout->addWidget(m_pathBox);
+ m_layout->addWidget(filler);
+ setLayout(m_layout);
+
updateContent();
}
void UrlNavigator::keyReleaseEvent(QKeyEvent* event)
{
- KHBox::keyReleaseEvent(event);
+ QWidget::keyReleaseEvent(event);
if (isUrlEditable() && (event->key() == Qt::Key_Escape)) {
setUrlEditable(false);
}
}
+void UrlNavigator::mouseReleaseEvent(QMouseEvent* event)
+{
+ if (event->button() == Qt::MidButton) {
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+ if (mimeData->hasText()) {
+ const QString text = mimeData->text();
+ setUrl(KUrl(text));
+ }
+ }
+ QWidget::mouseReleaseEvent(event);
+}
+
void UrlNavigator::slotReturnPressed(const QString& text)
{
// Parts of the following code have been taken
else {
m_toggleButton->setToolTip(i18n("Edit location (%1)", shortcut));
- setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_pathBox->hide();
// get the data from the currently selected bookmark
if (!m_host) {
m_protocolSeparator = new QLabel("://", this);
+ appendWidget(m_protocolSeparator);
m_host = new QLineEdit(hostText, this);
+ appendWidget(m_host);
connect(m_host, SIGNAL(lostFocus()),
this, SLOT(slotRemoteHostActivated()));
UrlNavigatorButton* button = 0;
if (createButton) {
button = new UrlNavigatorButton(idx, this);
+ appendWidget(button);
}
else {
button = *it;
m_navButtons.erase(itBegin, itEnd);
}
+void UrlNavigator::appendWidget(QWidget* widget)
+{
+ m_layout->insertWidget(m_layout->count() - 1, widget);
+}
+
#include "urlnavigator.moc"
#ifndef URLNAVIGATOR_H
#define URLNAVIGATOR_H
-#include <khbox.h>
#include <kurl.h>
+#include <QWidget>
#include <QLinkedList>
+class QCheckBox;
+class QHBoxLayout;
class QLabel;
class QLineEdit;
-class QCheckBox;
+class QMouseEvent;
class KUrl;
class KFileItem;
typedef QLinkedList<KUrl> UrlStack;
-class UrlNavigator : public KHBox
+class UrlNavigator : public QWidget
{
Q_OBJECT
const KUrl& destination);
protected:
- /** If the Escape key is pressed, the navigation bar should switch
- to the browse mode. */
+ /**
+ * If the Escape key is pressed, the navigation bar should switch
+ * to the browse mode.
+ */
virtual void keyReleaseEvent(QKeyEvent* event);
+ /**
+ * Paste the clipboard content as URL, if the middle mouse
+ * button has been clicked.
+ */
+ virtual void mouseReleaseEvent(QMouseEvent* event);
+
private slots:
void slotReturnPressed(const QString& text);
void slotUrlActivated(const KUrl& url);
*/
void deleteButtons();
+ /**
+ * Appends the widget at the end of the URL navigator. It is assured
+ * that the filler widget remains as last widget to fill the remaining
+ * width.
+ */
+ void appendWidget(QWidget* widget);
+
private:
bool m_active;
int m_historyIndex;
+
+ QHBoxLayout* m_layout;
+
QLinkedList<HistoryElem> m_history;
QCheckBox* m_toggleButton;
BookmarkSelector* m_bookmarkSelector;