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) , p_QupZilla(mainClass)
, m_webView(0) , m_webView(0)
, m_locationBarSettings(LocationBarSettings::instance()) , m_locationBarSettings(LocationBarSettings::instance())
, m_menu(new QMenu(this))
, m_pasteAndGoAction(0)
, m_clearAction(0)
, m_holdingAlt(false) , m_holdingAlt(false)
{ {
setObjectName("locationbar"); setObjectName("locationbar");
@ -238,6 +241,77 @@ void LocationBar::setPrivacy(bool state)
style()->polish(this); 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) void LocationBar::dropEvent(QDropEvent* event)
{ {
if (event->mimeData()->hasUrls()) { if (event->mimeData()->hasUrls()) {
@ -335,7 +409,7 @@ void LocationBar::keyReleaseEvent(QKeyEvent* event)
QString localDomain = tr(".co.uk", "Append domain name on ALT + Enter = Should be different for every country"); QString localDomain = tr(".co.uk", "Append domain name on ALT + Enter = Should be different for every country");
if (event->key() == Qt::Key_Alt && m_holdingAlt && m_locationBarSettings->addCountryWithAlt && if (event->key() == Qt::Key_Alt && m_holdingAlt && m_locationBarSettings->addCountryWithAlt &&
!text().endsWith(localDomain) && !text().endsWith("/")) { !text().endsWith(localDomain) && !text().endsWith("/")) {
setText(text().append(localDomain)); setText(text().append(localDomain));
} }

View File

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

View File

@ -216,7 +216,7 @@ void WebSearchBar::keyPressEvent(QKeyEvent* event)
switch (event->key()) { switch (event->key()) {
case Qt::Key_Return: case Qt::Key_Return:
case Qt::Key_Enter: case Qt::Key_Enter:
if (event->modifiers() ==Qt::AltModifier) { if (event->modifiers() == Qt::AltModifier) {
searchInNewTab(); searchInNewTab();
} }
else { else {