#include "mainview.h"
#include "settings.h"
+// KDE Framework headers.
+#include <KLineEdit>
+
// Qt framework headers.
#include <QWebEngineView>
MainView::MainView(QWidget *parent) : QWidget(parent)
{
+ // Instantiate the mainview UI.
+ Ui::MainView mainViewUi;
+
// Setup the UI.
mainViewUi.setupUi(this);
- // Get a handle for the web engine view.
- QWebEngineView *webEngineViewPointer = mainViewUi.webEngineView;
+ // Get handles for the views.
+ urlLineEditPointer = mainViewUi.urlLineEdit;
+ webEngineViewPointer = mainViewUi.webEngineView;
+
+ // Update the webengine view from the URL line edit.
+ connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
+
+ // Update the URL line edit form the webengine view.
+ connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateUrlLineEdit()));
+ connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
+ connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
// Load a website.
webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
}
+
+void MainView::loadUrl(const QString &urlFromUser)
+{
+ // Load the URL, adding standard protocol sections if needed. TODO. Replace this with logic that prefers HTTPS.
+ webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
+}
+
+void MainView::updateUrlLineEdit()
+{
+ // Update the URL line edit.
+ urlLineEditPointer->setText(webEngineViewPointer->url().toString());
+}