1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

Paste and Go action for Search Bar

This commit is contained in:
Mladen Pejaković 2012-01-24 15:39:20 +01:00
parent 5d057f9107
commit a09766a2ee
2 changed files with 50 additions and 0 deletions

View File

@ -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()) {

View File

@ -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<SearchEnginesDialog> m_searchDialog;
QAction* m_pasteAndGoAction;
QMenu* m_menu;
};
#endif // WEBSEARCHBAR_H