aboutsummaryrefslogtreecommitdiff
path: root/lib/addressbar/urllineedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/addressbar/urllineedit.cpp')
-rw-r--r--lib/addressbar/urllineedit.cpp61
1 files changed, 42 insertions, 19 deletions
diff --git a/lib/addressbar/urllineedit.cpp b/lib/addressbar/urllineedit.cpp
index 27acf60..f92518e 100644
--- a/lib/addressbar/urllineedit.cpp
+++ b/lib/addressbar/urllineedit.cpp
@@ -7,11 +7,10 @@
*/
#include "urllineedit.h"
-#include <QLabel>
#include <QMenu>
#include <QShortcut>
-#include <QTimer>
-#include <QWidgetAction>
+#include <QApplication>
+#include <QClipboard>
UrlLineEdit::UrlLineEdit(QWidget *parent)
: QLineEdit(parent)
@@ -21,18 +20,49 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
m_listView->setVisible(false);
- pageMenu_action = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
- connect(pageMenu_action, &QAction::triggered, pageMenu_action, [&]() {
- if(pageMenu_action->menu()) {
- pageMenu_action->menu()->exec(this->mapToGlobal(QPoint(0, height())));
- }
+ auto *copyAction = new QAction(tr("Copy URL"), this);
+ connect(copyAction, &QAction::triggered, this, [this]() {
+ qApp->clipboard()->setText(this->text());
+ });
+ actions.append(copyAction);
+
+ auto *pasteAction = new QAction(tr("Paste URL"), this);
+ connect(pasteAction, &QAction::triggered, this, [this]() {
+ this->setText(qApp->clipboard()->text());
+ this->setFocus();
});
+ actions.append(pasteAction);
- toolsMenu_action = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
- connect(toolsMenu_action, &QAction::triggered, toolsMenu_action, [&]() {
- if(toolsMenu_action->menu()) {
- toolsMenu_action->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
+ auto *loadAction = new QAction(tr("Paste and load"), this);
+ connect(loadAction, &QAction::triggered, this, [this]() {
+ this->setText(qApp->clipboard()->text());
+ emit returnPressed();
+ });
+ actions.append(loadAction);
+
+ auto *searchAction = new QAction(tr("Paste and search"), this);
+ connect(searchAction, &QAction::triggered, this, [this]() {
+ this->setText("#" + qApp->clipboard()->text());
+ emit returnPressed();
+ });
+ actions.append(searchAction);
+
+ menuAction = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
+ connect(menuAction, &QAction::triggered, this, [this]() {
+ auto *menu = new QMenu();
+ menu->setAttribute(Qt::WA_DeleteOnClose, true);
+ menu->setMinimumWidth(240);
+ menu->addActions(actions);
+ menu->addSeparator();
+
+ if(pageMenu) {
+ menu->addMenu(pageMenu);
}
+ if(toolsMenu) {
+ menu->addMenu(toolsMenu);
+ }
+
+ menu->exec(this->mapToGlobal(QPoint(0, height())));
});
QTextCharFormat hostnameFormat;
@@ -70,20 +100,13 @@ void UrlLineEdit::updateCompleter(const QStringList &l)
void UrlLineEdit::focusInEvent(QFocusEvent *event)
{
clearTextFormat();
-
QLineEdit::focusInEvent(event);
-
- // select the contents when receiving focus
- // http://stackoverflow.com/a/35725950/1054406
- // mousePressEvent triggers right after focusInEvent so text selected in focusInEvent unselects by mousePressEvent
- //QTimer::singleShot(0, this, SLOT(selectAll()));
}
void UrlLineEdit::focusOutEvent(QFocusEvent *event)
{
if(!text().startsWith('#'))
setUrl(QUrl::fromUserInput(text()));
-
QLineEdit::focusOutEvent(event);
}