From d6101a83cad797e80ade602662878378ee0f2306 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 30 Jan 2017 15:37:30 +0100 Subject: Added UrlLineEdit class Address bar should highlight the host name WebView widget should now be focused on startup instead of the address bar Added names to the toolbars to make their context menu useful Tabs now have a set width of 200 --- src/widgets/urllineedit.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/widgets/urllineedit.cpp (limited to 'src/widgets/urllineedit.cpp') diff --git a/src/widgets/urllineedit.cpp b/src/widgets/urllineedit.cpp new file mode 100644 index 0000000..25bf157 --- /dev/null +++ b/src/widgets/urllineedit.cpp @@ -0,0 +1,43 @@ +#include "urllineedit.h" +#include + +UrlLineEdit::UrlLineEdit(QWidget *parent) : + QLineEdit(parent) +{ + //setStyleSheet("color: #808080"); +} + +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; + + clear(); + clearTextFormat(); + setTextFormat(fr_tracker); + setText(urlText); +} + +void UrlLineEdit::setTextFormat(const QTextLayout::FormatRange &format) +{ + QList attributes; + attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, format.start, format.length, format.format)); + QInputMethodEvent ev(QString(), attributes); + event(&ev); + +} + +void UrlLineEdit::clearTextFormat() +{ + setTextFormat(QTextLayout::FormatRange()); +} -- cgit v1.2.1