diff --git a/src/navigation/websearchbar.cpp b/src/navigation/websearchbar.cpp index 475cf820a..fc34d9a4f 100644 --- a/src/navigation/websearchbar.cpp +++ b/src/navigation/websearchbar.cpp @@ -30,6 +30,8 @@ WebSearchBar::WebSearchBar(QupZilla* mainClass, QWidget* parent) : LineEdit(parent) , p_QupZilla(mainClass) + , m_menu(new QMenu(this)) + , m_pasteAndGoAction(0) { setObjectName("websearchbar"); m_buttonSearch = new ClickableLabel(this); @@ -181,6 +183,48 @@ void WebSearchBar::addEngineFromAction() } } +void WebSearchBar::pasteAndGo() +{ + clear(); + paste(); + search(); +} + +void WebSearchBar::contextMenuEvent(QContextMenuEvent* event) +{ + Q_UNUSED(event) + + if (!m_pasteAndGoAction) { + m_pasteAndGoAction = new QAction(tr("Paste And &Go"), this); +// m_pasteAndGoAction->setShortcut(QKeySequence("Ctrl+Shift+V")); + connect(m_pasteAndGoAction, SIGNAL(triggered()), this, SLOT(pasteAndGo())); + } + + QMenu* tempMenu = createStandardContextMenu(); + m_menu->clear(); + + int i = 0; + foreach(QAction* act, tempMenu->actions()) { + act->setParent(m_menu); + tempMenu->removeAction(act); + m_menu->addAction(act); + + if (i == 5) { + m_menu->addAction(m_pasteAndGoAction); + } + ++i; + } + + delete tempMenu; + + m_pasteAndGoAction->setEnabled(!QApplication::clipboard()->text().isEmpty()); + + //Prevent choosing first option with double rightclick + QPoint pos = QCursor::pos(); + QPoint p(pos.x(), pos.y() + 1); + m_menu->popup(p); +} + void WebSearchBar::focusOutEvent(QFocusEvent* e) { if (text().isEmpty()) { diff --git a/src/navigation/websearchbar.h b/src/navigation/websearchbar.h index a5e822c75..7920ca04a 100644 --- a/src/navigation/websearchbar.h +++ b/src/navigation/websearchbar.h @@ -59,6 +59,7 @@ private slots: void addSuggestions(const QStringList &list); void addEngineFromAction(); + void pasteAndGo(); private: void focusInEvent(QFocusEvent* e); @@ -67,6 +68,7 @@ private: void keyPressEvent(QKeyEvent* event); void completeMenuWithAvailableEngines(QMenu* menu); + void contextMenuEvent(QContextMenuEvent* event); QCompleter* m_completer; QStringListModel* m_completerModel; @@ -80,6 +82,10 @@ private: ButtonWithMenu* m_boxSearchType; SearchEnginesManager* m_searchManager; QWeakPointer m_searchDialog; + + QAction* m_pasteAndGoAction; + QMenu* m_menu; + }; #endif // WEBSEARCHBAR_H