aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/urllineedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/urllineedit.cpp')
-rw-r--r--src/widgets/urllineedit.cpp63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/widgets/urllineedit.cpp b/src/widgets/urllineedit.cpp
index 5063191..b038da9 100644
--- a/src/widgets/urllineedit.cpp
+++ b/src/widgets/urllineedit.cpp
@@ -22,14 +22,31 @@
#include <QUrl>
#include <QTimer>
+#include <QAction>
+#include <QStyle>
+#include "browser.h"
+
UrlLineEdit::UrlLineEdit(QWidget *parent) :
QLineEdit(parent)
{
//setStyleSheet("color: #808080");
+ setPlaceholderText(tr("Enter address"));
+ setContextMenuPolicy(Qt::NoContextMenu);
QTextCharFormat hostnameFormat;
hostnameFormat.setFontWeight(QFont::Bold);
m_hostFormat.format = hostnameFormat;
+
+ m_contextMenu = new QMenu(this);
+ m_contextMenu->addAction("Copy URL", this, SLOT(copyUrl()));
+ m_contextMenu->addAction("Paste URL", this, SLOT(pasteUrl()));
+ m_contextMenu->addAction("Paste URL and go", this, SLOT(pasteUrlAndGo()));
+ m_contextMenu->addSeparator();
+ m_contextMenu->addAction("Bookmark this page", this, SLOT(bookmarkUrl()))->setEnabled(false);
+
+ QAction *contextAction = addAction(style()->standardIcon(QStyle::SP_TitleBarMinButton), ActionPosition::TrailingPosition);
+ contextAction->setShortcut(QKeySequence::fromString("F3"));
+ connect(contextAction, SIGNAL(triggered()), this, SLOT(showMenu()));
}
void UrlLineEdit::setUrl(const QUrl &url)
@@ -48,7 +65,7 @@ void UrlLineEdit::setUrl(const QUrl &url)
QUrl UrlLineEdit::url()
{
- return QUrl::fromUserInput(text());
+ return urlFromUserInput(text());
}
void UrlLineEdit::focusInEvent(QFocusEvent *event)
@@ -64,7 +81,7 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
void UrlLineEdit::focusOutEvent(QFocusEvent *event)
{
- setUrl(QUrl(text()));
+ setUrl(urlFromUserInput(text()));
QLineEdit::focusOutEvent(event);
}
@@ -82,3 +99,45 @@ void UrlLineEdit::clearTextFormat()
{
setTextFormat(QTextLayout::FormatRange());
}
+
+QUrl UrlLineEdit::urlFromUserInput(const QString &input)
+{
+ if(input.startsWith('#')) {
+ return QUrl::fromUserInput(qApp->settings()->value("general.search").toString().replace("$term", input.mid(1)));
+ }
+ return QUrl::fromUserInput(input);
+}
+
+// Menu
+
+void UrlLineEdit::showMenu()
+{
+ m_contextMenu->exec(mapToGlobal(QPoint(width() - m_contextMenu->width(), height())));
+}
+
+void UrlLineEdit::copyUrl()
+{
+ selectAll();
+ copy();
+ deselect();
+}
+
+void UrlLineEdit::pasteUrl()
+{
+ clear();
+ paste();
+ setUrl(urlFromUserInput(text()));
+}
+
+void UrlLineEdit::pasteUrlAndGo()
+{
+ clear();
+ paste();
+ setUrl(urlFromUserInput(text()));
+ emit returnPressed();
+}
+
+void UrlLineEdit::bookmarkUrl()
+{
+ qDebug("TODO: bookmarkUrl()");
+}