aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-01-30 19:45:09 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-01-30 19:45:09 +0100
commit50f9adad0ffbe7d9176326ed8601148630ad1b61 (patch)
tree2f6c5d1edb2a048c236b948532dc1009e6a838bf /src/widgets
parentAdded UrlLineEdit class (diff)
downloadsmolbote-50f9adad0ffbe7d9176326ed8601148630ad1b61.tar.xz
Cleaned up UrlLineEdit
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/urllineedit.cpp35
-rw-r--r--src/widgets/urllineedit.h7
2 files changed, 32 insertions, 10 deletions
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