]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/mainview.cpp
Add a zoom factor setting.
[PrivacyBrowserPC.git] / src / mainview.cpp
1 /*
2  * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
6  * Privacy Browser PC is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser PC is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 // Application headers
21 #include "mainview.h"
22 #include "settings.h"
23
24 // KDE Framework headers.
25 #include <KLineEdit>
26
27 // Qt framework headers.
28 #include <QWebEngineView>
29
30 MainView::MainView(QWidget *parent) : QWidget(parent)
31 {
32     // Instantiate the mainview UI.
33     Ui::MainView mainViewUi;
34
35     // Setup the UI.
36     mainViewUi.setupUi(this);
37
38     // Get handles for the views.
39     urlLineEditPointer = mainViewUi.urlLineEdit;
40     webEngineViewPointer = mainViewUi.webEngineView;
41
42     // Update the webengine view from the URL line edit.
43     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
44
45     // Update the URL line edit form the webengine view.
46     connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateUrlLineEdit()));
47     connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
48     connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
49
50     // Set the zoom factor.
51     webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
52
53     // Load a website.
54     webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
55 }
56
57 void MainView::loadUrl(const QString &urlFromUser)
58 {
59     // Load the URL, adding standard protocol sections if needed.  TODO.  Replace this with logic that prefers HTTPS.
60     webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
61 }
62
63 void MainView::updateUrlLineEdit()
64 {
65     // Update the URL line edit.
66     urlLineEditPointer->setUrl(webEngineViewPointer->url().toString());
67
68     // Reapply the zoom factor.  This is a bug in QWebEngineView that resets the zoom with every load.  Hopefully it will be fixed in Qt6.  <https://bugreports.qt.io/browse/QTBUG-51992>
69     webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
70 }