// Qt headers.
#include <QWebEngineHistory>
+#include <QWebEngineSettings>
#include <QWebEngineView>
MainView::MainView(QWidget *parent) : QWidget(parent)
// Get handles for the views.
backButtonPointer = mainViewUi.backButton;
forwardButtonPointer = mainViewUi.forwardButton;
+ QPushButton *homeButtonPointer = mainViewUi.homeButton;
urlLineEditPointer = mainViewUi.urlLineEdit;
+ javaScriptButtonPointer = mainViewUi.javaScript;
webEngineViewPointer = mainViewUi.webEngineView;
- // Get handles for the webpage and history.
+ // Get handles for the aspects of the WebEngine.
QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
webEngineHistoryPointer = webEnginePagePointer->history();
+ webEngineSettingsPointer = webEngineViewPointer->settings();
// Update the webengine view from the URL line edit.
connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateInterface()));
connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateInterface()));
- // Setup the forward and back buttons.
+ // Setup the URL bar buttons.
connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back()));
connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward()));
+ connect(homeButtonPointer, SIGNAL(clicked()), this, SLOT(goHome()));
+ connect(javaScriptButtonPointer, SIGNAL(clicked()), this, SLOT(toggleJavaScript()));
// Instantiate the mouse event pointer.
MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer);
// Listen for hovered link URLs.
connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString)));
+ // Don't allow JavaScript to open windows.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
+
// Set the zoom factor.
webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
+ // Apply the application settings.
+ applyApplicationSettings();
+
+ // Apply the domain settings.
+ applyDomainSettings();
+
// Set the focus on the WebEngine view.
webEngineViewPointer->setFocus();
+ // Load the homepage.
+ goHome();
+}
+
+void MainView::applyApplicationSettings()
+{
+ // TODO.
+}
+
+void MainView::applyDomainSettings()
+{
+ // Set the JavaScript status.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript());
+
+ // Update the JavaScript button.
+ if (Settings::javaScript())
+ {
+ javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning"));
+ }
+ else
+ {
+ javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode"));
+ }
+
+ // Reload the website.
+ webEngineViewPointer->reload();
+}
+
+void MainView::goHome()
+{
// Load the homepage. TODO. Consider sanitizing the homepage input and adding things like protocols if they are missing.
webEngineViewPointer->setUrl(Settings::homepage());
}
emit linkHovered(linkUrl);
}
+void MainView::toggleJavaScript()
+{
+ // Toggle JavaScript.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
+
+ // Update the JavaScript button.
+ if (webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled))
+ {
+ javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning"));
+ }
+ else
+ {
+ javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode"));
+ }
+
+ // Reload the website.
+ webEngineViewPointer->reload();
+}
+
void MainView::updateInterface()
{
// Update the URL line edit if it does not have focus.