aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/widgets/urllineedit.cpp35
-rw-r--r--src/widgets/urllineedit.h7
3 files changed, 33 insertions, 11 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0369d17..f3f0860 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -174,7 +174,7 @@ void MainWindow::handleTabChanged(QWebEngineView *view)
void MainWindow::handleUrlChanged()
{
- tabBar->currentView()->load(QUrl::fromUserInput(urlLineEdit->text()));
+ tabBar->currentView()->load(urlLineEdit->url());
}
void MainWindow::handleTitleUpdated(const QString &title)
diff --git a/src/widgets/urllineedit.cpp b/src/widgets/urllineedit.cpp
index 25bf157..10b8356 100644
--- a/src/widgets/urllineedit.cpp
+++ b/src/widgets/urllineedit.cpp
@@ -5,6 +5,10 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
QLineEdit(parent)
{
//setStyleSheet("color: #808080");
+
+ QTextCharFormat hostnameFormat;
+ hostnameFormat.setFontWeight(QFont::Bold);
+ m_hostFormat.format = hostnameFormat;
}
void UrlLineEdit::setUrl(const QUrl &url)
@@ -12,22 +16,33 @@ void UrlLineEdit::setUrl(const QUrl &url)
QString urlText = url.toString();
QString domain = url.host();
- QTextCharFormat f_host;
-
- f_host.setFontWeight(QFont::Bold);
- //f_host.setForeground(QBrush(QColor::fromRgb(255, 255, 255)));
-
- QTextLayout::FormatRange fr_tracker;
- fr_tracker.start = urlText.indexOf(domain);
- fr_tracker.length = domain.length();
- fr_tracker.format = f_host;
+ m_hostFormat.start = urlText.indexOf(domain);
+ m_hostFormat.length = domain.length();
clear();
clearTextFormat();
- setTextFormat(fr_tracker);
+ setTextFormat(m_hostFormat);
setText(urlText);
}
+QUrl UrlLineEdit::url()
+{
+ return QUrl::fromUserInput(text());
+}
+
+void UrlLineEdit::focusInEvent(QFocusEvent *event)
+{
+ clearTextFormat();
+ QLineEdit::focusInEvent(event);
+}
+
+void UrlLineEdit::focusOutEvent(QFocusEvent *event)
+{
+ setUrl(QUrl(text()));
+ QLineEdit::focusOutEvent(event);
+}
+
+// formatting taken from: https://forum.qt.io/topic/60962/setting-qlineedit-text-bold
void UrlLineEdit::setTextFormat(const QTextLayout::FormatRange &format)
{
QList<QInputMethodEvent::Attribute> attributes;
diff --git a/src/widgets/urllineedit.h b/src/widgets/urllineedit.h
index e7dcf36..546ca41 100644
--- a/src/widgets/urllineedit.h
+++ b/src/widgets/urllineedit.h
@@ -14,10 +14,17 @@ signals:
public slots:
void setUrl(const QUrl &url);
+ QUrl url();
+
+protected:
+ void focusInEvent(QFocusEvent *event);
+ void focusOutEvent(QFocusEvent *event);
private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
+
+ QTextLayout::FormatRange m_hostFormat;
};
#endif // URLLINEEDIT_H