aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/addressbar/addressbar.cpp14
-rw-r--r--lib/addressbar/urllineedit.cpp61
-rw-r--r--lib/addressbar/urllineedit.h7
-rw-r--r--lib/configuration/configuration.cpp3
4 files changed, 53 insertions, 32 deletions
diff --git a/lib/addressbar/addressbar.cpp b/lib/addressbar/addressbar.cpp
index e8dcc6a..a923e72 100644
--- a/lib/addressbar/addressbar.cpp
+++ b/lib/addressbar/addressbar.cpp
@@ -21,6 +21,7 @@ AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent)
layout()->setSpacing(0);
urlBar = new UrlLineEdit(this);
+ urlBar->menuAction->setShortcut(QKeySequence(config.value("addressbar.shortcuts.menu")));
layout()->addWidget(urlBar);
auto *focusShortcut = new QShortcut(QKeySequence(config.value("addressbar.shortcuts.focus")), parent);
@@ -29,11 +30,6 @@ AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent)
urlBar->selectAll();
});
- urlBar->pageMenu_action->setShortcut(QKeySequence(config.value("addressbar.shortcuts.pageMenu")));
- urlBar->pageMenu_action->setToolTip(tr("Page Actions (%1)").arg(urlBar->pageMenu_action->shortcut().toString()));
-
- urlBar->toolsMenu_action->setShortcut(QKeySequence(config.value("addressbar.shortcuts.toolsMenu")));
- urlBar->toolsMenu_action->setToolTip(tr("Tools (%1)").arg(urlBar->toolsMenu_action->shortcut().toString()));
connect(urlBar, &UrlLineEdit::textEdited, [=](const QString &text) {
std::function<void(QStringList &)> callback = std::bind(&UrlLineEdit::updateCompleter, urlBar, std::placeholders::_1);
@@ -63,8 +59,8 @@ void AddressBar::setView(QWebEngineView *view)
if(view == nullptr) {
urlBar->clear();
- urlBar->pageMenu_action->setMenu(nullptr);
- urlBar->toolsMenu_action->setMenu(nullptr);
+ urlBar->pageMenu = nullptr;
+ urlBar->toolsMenu = nullptr;
return;
}
@@ -85,10 +81,10 @@ void AddressBar::setView(QWebEngineView *view)
void AddressBar::setPageMenu(QMenu *menu)
{
- urlBar->pageMenu_action->setMenu(menu);
+ urlBar->pageMenu = menu;
}
void AddressBar::setToolsMenu(QMenu *menu)
{
- urlBar->toolsMenu_action->setMenu(menu);
+ urlBar->toolsMenu = menu;
}
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);
}
diff --git a/lib/addressbar/urllineedit.h b/lib/addressbar/urllineedit.h
index f27addc..f28983d 100644
--- a/lib/addressbar/urllineedit.h
+++ b/lib/addressbar/urllineedit.h
@@ -28,10 +28,11 @@ public slots:
void updateCompleter(const QStringList &l);
public:
+ QAction *menuAction = nullptr;
// pageMenu action: zoom, print
- QAction *pageMenu_action = nullptr;
+ QMenu *pageMenu = nullptr;
// devMenu action: scripts, etc
- QAction *toolsMenu_action = nullptr;
+ QMenu *toolsMenu = nullptr;
protected:
void focusInEvent(QFocusEvent *event) override;
@@ -42,6 +43,8 @@ private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
+ QList<QAction *> actions;
+
QTextLayout::FormatRange m_hostFormat;
// completer
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp
index 7032a1d..6351348 100644
--- a/lib/configuration/configuration.cpp
+++ b/lib/configuration/configuration.cpp
@@ -80,8 +80,7 @@ Configuration::Configuration()
// address bar
("addressbar.shortcuts.focus", po::value<std::string>()->default_value("F4"))
- ("addressbar.shortcuts.pageMenu", po::value<std::string>()->default_value("F2"))
- ("addressbar.shortcuts.toolsMenu", po::value<std::string>()->default_value("F12"))
+ ("addressbar.shortcuts.menu", po::value<std::string>()->default_value("F2"))
// window
("window.shortcuts.new", po::value<std::string>()->default_value("Ctrl+T"))