aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-08-24 15:38:33 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2017-08-24 15:38:33 +0200
commit06fdf013b318c3d8f5efb3d2f87dedcdb507b8bc (patch)
treef7c970fc030741610e3c93306b79550c8cb2f086 /src/lib
parentAddress bar popup is now navigateable (diff)
downloadsmolbote-06fdf013b318c3d8f5efb3d2f87dedcdb507b8bc.tar.xz
Cleaned up code
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/navigation/addressbar.cpp30
-rw-r--r--src/lib/navigation/addressbar.h25
-rw-r--r--src/lib/navigation/navigation.qbs6
-rw-r--r--src/lib/navigation/urllineedit.cpp32
-rw-r--r--src/lib/navigation/urllineedit.h5
5 files changed, 63 insertions, 35 deletions
diff --git a/src/lib/navigation/addressbar.cpp b/src/lib/navigation/addressbar.cpp
new file mode 100644
index 0000000..dd9991d
--- /dev/null
+++ b/src/lib/navigation/addressbar.cpp
@@ -0,0 +1,30 @@
+#include "addressbar.h"
+#include <QHBoxLayout>
+
+AddressBar::AddressBar(QWidget *parent) : QWidget(parent)
+{
+ QHBoxLayout *_layout = new QHBoxLayout(this);
+ _layout->setMargin(0);
+ _layout->setSpacing(0);
+ setLayout(_layout);
+
+ m_urlLineEdit = new UrlLineEdit(this);
+ setFocusProxy(m_urlLineEdit);
+ _layout->addWidget(m_urlLineEdit);
+
+ connect(m_urlLineEdit, &UrlLineEdit::returnPressed, [&](){
+ if(m_urlLineEdit->text().startsWith('#')) {
+ QString term = m_urlLineEdit->text().mid(1);
+ term.replace(' ', '+');
+ emit searchTermEntered(term);
+ } else {
+ emit addressEntered(QUrl::fromUserInput(m_urlLineEdit->text()));
+ }
+ });
+}
+
+void AddressBar::setWebView(const WebView *view)
+{
+ connect(view, &WebView::urlChanged, m_urlLineEdit, &UrlLineEdit::setUrl);
+ m_urlLineEdit->setUrl(view->url());
+}
diff --git a/src/lib/navigation/addressbar.h b/src/lib/navigation/addressbar.h
new file mode 100644
index 0000000..b5b312a
--- /dev/null
+++ b/src/lib/navigation/addressbar.h
@@ -0,0 +1,25 @@
+#ifndef ADDRESSBAR_H
+#define ADDRESSBAR_H
+
+#include <QWidget>
+#include "urllineedit.h"
+#include <webengine/webview.h>
+
+class AddressBar : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit AddressBar(QWidget *parent = nullptr);
+
+signals:
+ void addressEntered(const QUrl &url);
+ void searchTermEntered(const QString &term);
+
+public slots:
+ void setWebView(const WebView *view);
+
+private:
+ UrlLineEdit *m_urlLineEdit;
+};
+
+#endif // ADDRESSBAR_H
diff --git a/src/lib/navigation/navigation.qbs b/src/lib/navigation/navigation.qbs
index 5f7ba41..7ffb3ee 100644
--- a/src/lib/navigation/navigation.qbs
+++ b/src/lib/navigation/navigation.qbs
@@ -7,13 +7,17 @@ Project {
id: navigation
name: "navigation"
+ cpp.includePaths: ['../..']
+
Depends {
name: "Qt"
versionAtLeast: "5.9.0"
- submodules: ["core", "widgets"]
+ submodules: ["core", "widgets", "webengine", "webenginewidgets"]
}
files: [
+ "addressbar.cpp",
+ "addressbar.h",
"urllineedit.cpp",
"urllineedit.h",
]
diff --git a/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp
index f3fcccd..85bcacc 100644
--- a/src/lib/navigation/urllineedit.cpp
+++ b/src/lib/navigation/urllineedit.cpp
@@ -57,10 +57,10 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
listWidget->addItem("neueland.iserlohn-fortress.net");
connect(listWidget, &QListWidget::itemSelectionChanged, [this](){
- setUrl(urlFromUserInput(listWidget->currentItem()->text()));
+ setText(listWidget->currentItem()->text());
});
connect(listWidget, &QListWidget::itemActivated, [this](QListWidgetItem *item){
- setUrl(urlFromUserInput(item->text()));
+ setText(listWidget->currentItem()->text());;
this->m_menu->hide();
});
@@ -73,11 +73,6 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
// connect signals
connect(this, SIGNAL(textEdited(QString)), this, SLOT(showCompleter(QString)));
connect(this, &QLineEdit::returnPressed, [this](){
- if(text().startsWith('#')) {
- emit searchTermEntered(text());
- } else {
- emit addressEntered(url());
- }
m_menu->hide();
});
@@ -97,11 +92,6 @@ void UrlLineEdit::setUrl(const QUrl &url)
setText(urlText);
}
-QUrl UrlLineEdit::url()
-{
- return urlFromUserInput(text());
-}
-
void UrlLineEdit::focusInEvent(QFocusEvent *event)
{
clearTextFormat();
@@ -112,15 +102,6 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
// http://stackoverflow.com/a/35725950/1054406
// mousePressEvent triggers right after focusInEvent so text selected in focusInEvent unselects by mousePressEvent
QTimer::singleShot(0, this, SLOT(selectAll()));
-
- //QTimer::singleShot(0, this, SLOT(showCompleter()));
-}
-
-void UrlLineEdit::focusOutEvent(QFocusEvent *event)
-{
- wasFocused = false;
- setUrl(urlFromUserInput(text()));
- QLineEdit::focusOutEvent(event);
}
void UrlLineEdit::resizeEvent(QResizeEvent *event)
@@ -170,17 +151,12 @@ void UrlLineEdit::clearTextFormat()
setTextFormat(QTextLayout::FormatRange());
}
-QUrl UrlLineEdit::urlFromUserInput(const QString &input)
-{
- return QUrl::fromUserInput(input);
-}
-
// Completer
void UrlLineEdit::showCompleter(const QString &text)
{
m_menu->move(mapToGlobal(QPoint(0, height())));
- listWidget->setCurrentRow(0, QItemSelectionModel::SelectCurrent);
+ //listWidget->setCurrentRow(0, QItemSelectionModel::SelectCurrent);
m_menu->exec();
}
@@ -202,14 +178,12 @@ void UrlLineEdit::pasteUrl()
{
clear();
paste();
- setUrl(urlFromUserInput(text()));
}
void UrlLineEdit::pasteUrlAndGo()
{
clear();
paste();
- setUrl(urlFromUserInput(text()));
emit returnPressed();
}
diff --git a/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h
index 0865d47..8432f14 100644
--- a/src/lib/navigation/urllineedit.h
+++ b/src/lib/navigation/urllineedit.h
@@ -39,11 +39,9 @@ signals:
public slots:
void setUrl(const QUrl &url);
- QUrl url();
protected:
void focusInEvent(QFocusEvent *event);
- void focusOutEvent(QFocusEvent *event);
void resizeEvent(QResizeEvent *event);
void keyPressEvent(QKeyEvent *event);
@@ -59,12 +57,9 @@ private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
- QUrl urlFromUserInput(const QString &input);
-
QTextLayout::FormatRange m_hostFormat;
QMenu *m_contextMenu;
- bool wasFocused = false;
QMenu *m_menu;
QListWidget *listWidget;
};