From c6e137acee1f707d33afd6bf5bbbe994167d6a2f Mon Sep 17 00:00:00 2001
From: Yoann Laissus <yoann.laissus@gmail.com>
Date: Mon, 29 Mar 2010 18:32:16 +0200
Subject: Add mid click support for the completition widget of the url bar

---
 src/urlbar/completionwidget.cpp | 13 ++++++++-----
 src/urlbar/completionwidget.h   |  5 +++--
 src/urlbar/listitem.cpp         |  3 ++-
 src/urlbar/listitem.h           |  2 +-
 src/urlbar/urlbar.cpp           |  6 +++---
 src/urlbar/urlbar.h             |  2 +-
 6 files changed, 18 insertions(+), 13 deletions(-)

(limited to 'src')

diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index 42abcb73..3ea35a0b 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -72,7 +72,7 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list)
     {
         UrlSearchItem item = list.at(i);
         ListItem *suggestion = new ListItem(item);
-        connect(suggestion, SIGNAL(itemClicked(ListItem *)), this, SLOT(itemChosen(ListItem *)));
+        connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton)));
         suggestion->setObjectName( QString::number(i) );
         layout()->addWidget( suggestion );
     }
@@ -208,7 +208,7 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e )
 
                 case Qt::Key_Return:
                         hide();
-                        emit chosenUrl(currentUrl().url());
+                        emit chosenUrl(currentUrl().url(), Rekonq::CurrentTab);
                         ev->accept();
                         return true;
                     break;
@@ -235,8 +235,11 @@ void CompletionWidget::setVisible( bool visible )
 }
 
 
-void CompletionWidget::itemChosen(ListItem *item)
+void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button)
 {
-    emit chosenUrl(_list.at(layout()->indexOf(item)).url);
+    if(button == Qt::MidButton)
+        emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::NewCurrentTab);
+    else
+        emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::CurrentTab);
     hide();
-}
\ No newline at end of file
+}
diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h
index 7b474bd8..64d33189 100644
--- a/src/urlbar/completionwidget.h
+++ b/src/urlbar/completionwidget.h
@@ -29,6 +29,7 @@
 
 
 // Local Includes
+#include "application.h"
 #include "urlresolver.h"
 #include "listitem.h"
 
@@ -60,10 +61,10 @@ public:
     KUrl currentUrl();
     
 private slots:
-    void itemChosen(ListItem *item);
+    void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton);
 
 signals:
-    void chosenUrl(const QString&);
+    void chosenUrl(const QString&, Rekonq::OpenType);
 
 private:
     void sizeAndPosition();
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index 92951cb7..d9837c7e 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -44,6 +44,7 @@
 #include <QPixmap>
 #include <QStylePainter>
 #include <QFile>
+#include <QMouseEvent>
 
 ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
     : QWidget(parent),
@@ -167,7 +168,7 @@ void ListItem::leaveEvent(QEvent *e)
 
 void ListItem::mousePressEvent(QMouseEvent *e)
 {
-    emit itemClicked(this);
+    emit itemClicked(this, e->button());
     QWidget::mousePressEvent(e);
 }
 
diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h
index 6aa3f1e9..ac476d4b 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -44,7 +44,7 @@ public:
     void deactivate();
 
 signals:
-    void itemClicked(ListItem *item);
+    void itemClicked(ListItem *item, Qt::MouseButton);
 
 protected:
    virtual void paintEvent(QPaintEvent *event);
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index 54a0a02d..57108d29 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -85,7 +85,7 @@ UrlBar::UrlBar(QWidget *parent)
     connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&)));
     
     installEventFilter(m_box);
-    connect(m_box, SIGNAL(chosenUrl(const QString&)), SLOT(activated(const QString&)));
+    connect(m_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType)));
 }
 
 
@@ -171,7 +171,7 @@ void UrlBar::updateUrl()
 }
 
 
-void UrlBar::activated(const QString& urlString)
+void UrlBar::activated(const QString& urlString, Rekonq::OpenType type)
 {
     disconnect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &)));
     
@@ -180,7 +180,7 @@ void UrlBar::activated(const QString& urlString)
 
     clearFocus();
     setUrl(urlString);
-    Application::instance()->loadUrl(m_currentUrl);
+    Application::instance()->loadUrl(m_currentUrl, type);
 }
 
 
diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h
index ef53d63a..552d1ee0 100644
--- a/src/urlbar/urlbar.h
+++ b/src/urlbar/urlbar.h
@@ -69,7 +69,7 @@ public slots:
     void updateUrl();
 
 private slots:
-    void activated(const QString& url);
+    void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab);
     void loadFinished(bool);
     void suggestUrls(const QString &editedText);
 
-- 
cgit v1.2.1