aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--src/webengine/widgets/pagemenu.cpp69
-rw-r--r--src/webengine/widgets/pagetoolsmenu.cpp2
6 files changed, 76 insertions, 80 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"))
diff --git a/src/webengine/widgets/pagemenu.cpp b/src/webengine/widgets/pagemenu.cpp
index b66c787..dc104e6 100644
--- a/src/webengine/widgets/pagemenu.cpp
+++ b/src/webengine/widgets/pagemenu.cpp
@@ -9,8 +9,6 @@
#include "pagemenu.h"
#include "../webview.h"
#include "webengine/webprofile.h"
-#include <QApplication>
-#include <QClipboard>
#include <QFileDialog>
#include <QLabel>
#include <QPrintDialog>
@@ -22,35 +20,37 @@
#include <QWidgetAction>
PageMenu::PageMenu(WebView *parent)
- : QMenu(parent)
+ : QMenu(tr("Page"), parent)
{
setMinimumWidth(240);
- auto *copyUrlAction = addAction(tr("Copy page URL"));
- connect(copyUrlAction, &QAction::triggered, parent, [parent]() {
- qApp->clipboard()->setText(parent->url().toString());
- parent->setFocus();
- });
-
- auto *loadUrlAction = addAction(tr("Load URL"));
- connect(loadUrlAction, &QAction::triggered, parent, [=]() {
- parent->load(QUrl::fromUserInput(qApp->clipboard()->text()));
- parent->setFocus();
+ auto *bookmarkAction = addAction(tr("Bookmark page"));
+ connect(bookmarkAction, &QAction::triggered, parent, [parent]() {
+ parent->profile()->addBookmark(parent->title(), parent->url().toString());
});
- auto *searchAction = addAction(tr("Search"));
- connect(searchAction, &QAction::triggered, parent, [=]() {
- parent->search(qApp->clipboard()->text());
+ auto *savePageAction = addAction(tr("Save Page"));
+ connect(savePageAction, &QAction::triggered, parent, [parent]() {
+ parent->triggerPageAction(QWebEnginePage::SavePage);
});
- connect(this, &PageMenu::aboutToShow, this, [=]() {
- loadUrlAction->setText(tr("Load URL: '%1'").arg(qApp->clipboard()->text()));
- searchAction->setText(tr("Search: '%1'").arg(qApp->clipboard()->text()));
+ auto *printAction = addAction(tr("Print Page"));
+ connect(printAction, &QAction::triggered, parent, [parent]() {
+ auto *printer = new QPrinter(QPrinterInfo::defaultPrinter());
+ auto *dlg = new QPrintDialog(printer, nullptr);
+ if(dlg->exec() == QDialog::Accepted) {
+ parent->page()->print(printer, [printer](bool success) {
+ qDebug("print %s", success ? "ok" : "failed");
+ delete printer;
+ });
+ }
+ delete dlg;
});
- auto *bookmarkAction = addAction(tr("Bookmark page"));
- connect(bookmarkAction, &QAction::triggered, parent, [parent]() {
- parent->profile()->addBookmark(parent->title(), parent->url().toString());
+ auto *printPdfAction = addAction(tr("Print to PDF"));
+ connect(printPdfAction, &QAction::triggered, parent, [parent]() {
+ const QString path = QFileDialog::getSaveFileName(parent, tr("Print to PDF"), QDir::homePath(), tr("PDF files (*.pdf)"));
+ parent->page()->printToPdf(path);
});
addSeparator();
@@ -89,29 +89,4 @@ PageMenu::PageMenu(WebView *parent)
}
addAction(zoomWidgetAction);
- addSeparator();
-
- auto *savePageAction = addAction(tr("Save Page"));
- connect(savePageAction, &QAction::triggered, parent, [parent]() {
- parent->triggerPageAction(QWebEnginePage::SavePage);
- });
-
- auto *printAction = addAction(tr("Print Page"));
- connect(printAction, &QAction::triggered, parent, [parent]() {
- auto *printer = new QPrinter(QPrinterInfo::defaultPrinter());
- auto *dlg = new QPrintDialog(printer, nullptr);
- if(dlg->exec() == QDialog::Accepted) {
- parent->page()->print(printer, [printer](bool success) {
- qDebug("print %s", success ? "ok" : "failed");
- delete printer;
- });
- }
- delete dlg;
- });
-
- auto *printPdfAction = addAction(tr("Print to PDF"));
- connect(printPdfAction, &QAction::triggered, parent, [parent]() {
- const QString path = QFileDialog::getSaveFileName(parent, tr("Print to PDF"), QDir::homePath(), tr("PDF files (*.pdf)"));
- parent->page()->printToPdf(path);
- });
}
diff --git a/src/webengine/widgets/pagetoolsmenu.cpp b/src/webengine/widgets/pagetoolsmenu.cpp
index 2a227ea..6e48798 100644
--- a/src/webengine/widgets/pagetoolsmenu.cpp
+++ b/src/webengine/widgets/pagetoolsmenu.cpp
@@ -16,7 +16,7 @@
#include <QWebEngineView>
PageToolsMenu::PageToolsMenu(WebView *parent)
- : QMenu(parent)
+ : QMenu(tr("Tools"), parent)
{
Q_CHECK_PTR(parent);
parentView = parent;