Very nice "side effect": the URL navigator is now completely flicker free when changing URLs because of using the whole available width :-)
TODO: I'm not 100 % sure whether checking the middle mousebutton by 'if (event->button() == Qt::MidButton) { ... }' is the right approach (maybe there is a more generic way to check the 'paste button').
svn path=/trunk/KDE/kdebase/apps/; revision=634595
#include <kurlcombobox.h>
#include <kurlcompletion.h>
#include <kurlcombobox.h>
#include <kurlcompletion.h>
+#include <QApplication>
+#include <QClipboard>
+#include <QDir>
+#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QLabel>
#include <QLineEdit>
UrlNavigator::HistoryElem::HistoryElem() :
m_url(),
UrlNavigator::HistoryElem::HistoryElem() :
m_url(),
UrlNavigator::UrlNavigator(const KUrl& url,
QWidget* parent) :
UrlNavigator::UrlNavigator(const KUrl& url,
QWidget* parent) :
m_active(true),
m_historyIndex(0),
m_active(true),
m_historyIndex(0),
m_protocols(0),
m_protocolSeparator(0),
m_host(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_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()),
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&)));
//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);
+
void UrlNavigator::keyReleaseEvent(QKeyEvent* event)
{
void UrlNavigator::keyReleaseEvent(QKeyEvent* event)
{
- KHBox::keyReleaseEvent(event);
+ QWidget::keyReleaseEvent(event);
if (isUrlEditable() && (event->key() == Qt::Key_Escape)) {
setUrlEditable(false);
}
}
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
void UrlNavigator::slotReturnPressed(const QString& text)
{
// Parts of the following code have been taken
else {
m_toggleButton->setToolTip(i18n("Edit location (%1)", shortcut));
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
m_pathBox->hide();
// get the data from the currently selected bookmark
if (!m_host) {
m_protocolSeparator = new QLabel("://", this);
if (!m_host) {
m_protocolSeparator = new QLabel("://", this);
+ appendWidget(m_protocolSeparator);
m_host = new QLineEdit(hostText, this);
m_host = new QLineEdit(hostText, this);
connect(m_host, SIGNAL(lostFocus()),
this, SLOT(slotRemoteHostActivated()));
connect(m_host, SIGNAL(lostFocus()),
this, SLOT(slotRemoteHostActivated()));
UrlNavigatorButton* button = 0;
if (createButton) {
button = new UrlNavigatorButton(idx, this);
UrlNavigatorButton* button = 0;
if (createButton) {
button = new UrlNavigatorButton(idx, this);
m_navButtons.erase(itBegin, itEnd);
}
m_navButtons.erase(itBegin, itEnd);
}
+void UrlNavigator::appendWidget(QWidget* widget)
+{
+ m_layout->insertWidget(m_layout->count() - 1, widget);
+}
+
#include "urlnavigator.moc"
#include "urlnavigator.moc"
#ifndef URLNAVIGATOR_H
#define URLNAVIGATOR_H
#ifndef URLNAVIGATOR_H
#define URLNAVIGATOR_H
+class QCheckBox;
+class QHBoxLayout;
class QLabel;
class QLineEdit;
class QLabel;
class QLineEdit;
class KUrl;
class KFileItem;
class KUrl;
class KFileItem;
typedef QLinkedList<KUrl> UrlStack;
typedef QLinkedList<KUrl> UrlStack;
-class UrlNavigator : public KHBox
+class UrlNavigator : public QWidget
const KUrl& destination);
protected:
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);
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);
private slots:
void slotReturnPressed(const QString& text);
void slotUrlActivated(const KUrl& url);
+ /**
+ * 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;
private:
bool m_active;
int m_historyIndex;
+
+ QHBoxLayout* m_layout;
+
QLinkedList<HistoryElem> m_history;
QCheckBox* m_toggleButton;
BookmarkSelector* m_bookmarkSelector;
QLinkedList<HistoryElem> m_history;
QCheckBox* m_toggleButton;
BookmarkSelector* m_bookmarkSelector;