aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/urllineedit.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-01-30 15:37:30 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-01-30 15:37:30 +0100
commitd6101a83cad797e80ade602662878378ee0f2306 (patch)
treee4f1627aea8ac370f0b6608dcb134fd18ca174fd /src/widgets/urllineedit.cpp
parentAdded bug reporting section to Contributing (diff)
downloadsmolbote-d6101a83cad797e80ade602662878378ee0f2306.tar.xz
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
Diffstat (limited to 'src/widgets/urllineedit.cpp')
-rw-r--r--src/widgets/urllineedit.cpp43
1 files changed, 43 insertions, 0 deletions
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 <QUrl>
+
+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<QInputMethodEvent::Attribute> 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());
+}