diff options
Diffstat (limited to 'src/widgets/urllineedit.cpp')
-rw-r--r-- | src/widgets/urllineedit.cpp | 43 |
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()); +} |