1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Location bar Paste and Go

This commit is contained in:
Mladen Pejaković 2012-01-21 19:26:47 +01:00
parent 408feb0ac1
commit d0c313f5b7
3 changed files with 82 additions and 2 deletions

View File

@ -41,6 +41,9 @@ LocationBar::LocationBar(QupZilla* mainClass)
, p_QupZilla(mainClass)
, m_webView(0)
, m_locationBarSettings(LocationBarSettings::instance())
, m_menu(new QMenu(this))
, m_pasteAndGoAction(0)
, m_clearAction(0)
, m_holdingAlt(false)
{
setObjectName("locationbar");
@ -238,6 +241,77 @@ void LocationBar::setPrivacy(bool state)
style()->polish(this);
}
void LocationBar::pasteAndGo()
{
clear();
paste();
urlEnter();
}
void LocationBar::contextMenuEvent(QContextMenuEvent* event)
{
Q_UNUSED(event)
if (!m_pasteAndGoAction) {
m_pasteAndGoAction = new QAction(QIcon::fromTheme("edit-paste"), tr("Paste And &Go"), this);
m_pasteAndGoAction->setShortcut(QKeySequence("Ctrl+Shift+V"));
connect(m_pasteAndGoAction, SIGNAL(triggered()), this, SLOT(pasteAndGo()));
}
if (!m_clearAction) {
m_clearAction = new QAction(QIcon::fromTheme("edit-clear"), tr("Clear All"), this);
connect(m_clearAction, SIGNAL(triggered()), this, SLOT(clear()));
}
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);
switch (i) {
case 0:
act->setIcon(QIcon::fromTheme("edit-undo"));
break;
case 1:
act->setIcon(QIcon::fromTheme("edit-redo"));
break;
case 3:
act->setIcon(QIcon::fromTheme("edit-cut"));
break;
case 4:
act->setIcon(QIcon::fromTheme("edit-copy"));
break;
case 5:
act->setIcon(QIcon::fromTheme("edit-paste"));
m_menu->addAction(act);
m_menu->addAction(m_pasteAndGoAction);
break;
case 6:
act->setIcon(QIcon::fromTheme("edit-delete"));
m_menu->addAction(act);
m_menu->addAction(m_clearAction);
break;
case 8:
act->setIcon(QIcon::fromTheme("edit-select-all"));
break;
}
++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 LocationBar::dropEvent(QDropEvent* event)
{
if (event->mimeData()->hasUrls()) {

View File

@ -74,10 +74,12 @@ private slots:
void urlEnter();
void clearIcon();
void showRSSIcon(bool state);
void pasteAndGo();
void updatePlaceHolderText();
private:
void contextMenuEvent(QContextMenuEvent* event);
void focusOutEvent(QFocusEvent* e);
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
@ -100,6 +102,10 @@ private:
LocationCompleter* m_locationCompleter;
LocationBarSettings* m_locationBarSettings;
QMenu* m_menu;
QAction* m_pasteAndGoAction;
QAction* m_clearAction;
bool m_rssIconVisible;
bool m_holdingAlt;
};