aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/widgets/urllineedit.cpp63
-rw-r--r--src/widgets/urllineedit.h11
2 files changed, 72 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()");
+}
diff --git a/src/widgets/urllineedit.h b/src/widgets/urllineedit.h
index d9d11ae..959461c 100644
--- a/src/widgets/urllineedit.h
+++ b/src/widgets/urllineedit.h
@@ -23,6 +23,7 @@
#include <QLineEdit>
#include <QTextLayout>
+#include <QMenu>
class UrlLineEdit : public QLineEdit
{
@@ -40,11 +41,21 @@ protected:
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
+private slots:
+ void showMenu();
+ void copyUrl();
+ void pasteUrl();
+ void pasteUrlAndGo();
+ void bookmarkUrl();
+
private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
+ QUrl urlFromUserInput(const QString &input);
+
QTextLayout::FormatRange m_hostFormat;
+ QMenu *m_contextMenu;
};
#endif // URLLINEEDIT_H