From: Soren Stoutner Date: Tue, 29 Mar 2022 23:25:24 +0000 (-0700) Subject: Add zoom factor domain settings. X-Git-Tag: v0.1~46 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=27ddfe8833b1ebaf499755135aa5cbfc72acb802;p=PrivacyBrowserPC.git Add zoom factor domain settings. --- diff --git a/src/DomainSettingsDialog.ui b/src/DomainSettingsDialog.ui index a2abaf7..82d6a0d 100644 --- a/src/DomainSettingsDialog.ui +++ b/src/DomainSettingsDialog.ui @@ -227,6 +227,51 @@ + + + + + + Zoom factor + + + + + + + + + System default + + + + + + Custom + + + + + + + + + Set the zoom factor between 0.25 and 5.00. The default is 1.00. + + + + 0.250000000000000 + + + + 5.000000000000000 + + + + 0.250000000000000 + + + diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index e44af92..e3745b5 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -45,6 +45,8 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent) javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel; userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox; userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel; + zoomFactorComboBoxPointer = domainSettingsDialogUi.zoomFactorComboBox; + customZoomFactorSpinBoxPointer = domainSettingsDialogUi.customZoomFactorSpinBox; QPushButton *addDomainButtonPointer = domainSettingsDialogUi.addDomainButton; deleteDomainButtonPointer = domainSettingsDialogUi.deleteDomainButton; QDialogButtonBox *dialogButtonBoxPointer = domainSettingsDialogUi.dialogButtonBox; @@ -88,6 +90,8 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent) connect(domainNameLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(domainNameChanged(QString))); connect(javaScriptComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(javaScriptChanged(int))); connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(userAgentChanged(QString))); + connect(zoomFactorComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(zoomFactorComboBoxChanged(int))); + connect(customZoomFactorSpinBoxPointer, SIGNAL(valueChanged(double)), this, SLOT(customZoomFactorChanged(double))); // Connect the buttons. connect(addDomainButtonPointer, SIGNAL(released()), this, SLOT(showAddMessageBox())); @@ -135,7 +139,18 @@ void DomainSettingsDialog::cancel() reject(); } -void DomainSettingsDialog::domainNameChanged(QString updatedDomainName) const +void DomainSettingsDialog::customZoomFactorChanged(const double &newValue) const +{ + // Update the domains table model. + domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR)), + newValue); + + // Update the UI. + updateUi(); +} + + +void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) const { // Update the domains table model. domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex(), updatedDomainName); @@ -145,7 +160,7 @@ void DomainSettingsDialog::domainNameChanged(QString updatedDomainName) const } -void DomainSettingsDialog::domainSelected(QModelIndex modelIndex) const +void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const { // Populate the domain name line edit pointer. domainNameLineEditPointer->setText(modelIndex.data().toString()); @@ -165,6 +180,18 @@ void DomainSettingsDialog::domainSelected(QModelIndex modelIndex) const // Set the custom user agent if specified. if (userAgentIndex == -1) userAgentComboBoxPointer->setCurrentText(userAgent); + // Get the zoom factor combo box index. + int zoomFactorComboBoxIndex = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR)).data().toInt(); + + // Populate the zoom factor combo box. + zoomFactorComboBoxPointer->setCurrentIndex(zoomFactorComboBoxIndex); + + // Populate the custom zoom factor spin box. + customZoomFactorSpinBoxPointer->setValue(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR)).data().toDouble()); + + // Set the initial visibility of the custom zoom factor spin box. + customZoomFactorSpinBoxPointer->setVisible(zoomFactorComboBoxIndex); + // Populate the labels. populateJavaScriptLabel(); populateUserAgentLabel(userAgentComboBoxPointer->currentText()); @@ -173,7 +200,7 @@ void DomainSettingsDialog::domainSelected(QModelIndex modelIndex) const updateUi(); } -void DomainSettingsDialog::javaScriptChanged(int newIndex) const +void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const { // Update the domains table model. domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)), @@ -282,14 +309,12 @@ void DomainSettingsDialog::showAddMessageBox() // Create a new domain record. QSqlRecord newDomainRecord = QSqlDatabase::database(DomainsDatabaseHelper::CONNECTION_NAME).record(DomainsDatabaseHelper::DOMAINS_TABLE); - // Add the new domain name. + // Set the values for the new domain. newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME), newDomainName); - - // Set the default value of `0` for JavaScript. - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), 0); - - // Set the default value for the user agent. + newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), DomainsDatabaseHelper::SYSTEM_DEFAULT); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE); + newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR), DomainsDatabaseHelper::SYSTEM_DEFAULT); + newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR), 1.0); // Insert the new domain. `-1` appends it to the end. domainsTableModelPointer->insertRecord(-1, newDomainRecord); @@ -388,7 +413,7 @@ void DomainSettingsDialog::updateUi() const domainSettingsWidgetPointer->setVisible(domainsTableModelPointer->rowCount() > 0); } -void DomainSettingsDialog::userAgentChanged(const QString updatedUserAgent) const +void DomainSettingsDialog::userAgentChanged(const QString &updatedUserAgent) const { // Update the domains table model. domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)), @@ -401,4 +426,15 @@ void DomainSettingsDialog::userAgentChanged(const QString updatedUserAgent) cons updateUi(); } +void DomainSettingsDialog::zoomFactorComboBoxChanged(const int &newIndex) const +{ + // Update the domains table model. + domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR)), + newIndex); + + // Update the visibility of the custom zoom factor spin box. + customZoomFactorSpinBoxPointer->setVisible(newIndex); + // Update the UI. + updateUi(); +} diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index 6acfcb5..0694177 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -25,6 +25,7 @@ // Qt toolkit headers. #include +#include #include #include @@ -44,18 +45,21 @@ private Q_SLOTS: // The private slots. void apply() const; void cancel(); - void domainNameChanged(QString updatedDomainName) const; - void domainSelected(QModelIndex modelIndex) const; - void javaScriptChanged(int newIndex) const; + void customZoomFactorChanged(const double &newValue) const; + void domainNameChanged(const QString &updatedDomainName) const; + void domainSelected(const QModelIndex &modelIndex) const; + void javaScriptChanged(const int &newIndex) const; void ok(); void reset() const; void showAddMessageBox(); void showDeleteMessageBox() const; - void userAgentChanged(const QString updatedUserAgent) const; + void userAgentChanged(const QString &updatedUserAgent) const; + void zoomFactorComboBoxChanged(const int &newIndex) const; private: // The private variables. QPushButton *applyButtonPointer; + QDoubleSpinBox *customZoomFactorSpinBoxPointer; QPushButton *deleteDomainButtonPointer; QListView *domainsListViewPointer; KLineEdit *domainNameLineEditPointer; @@ -66,6 +70,7 @@ private: QPushButton *resetButtonPointer; QComboBox *userAgentComboBoxPointer; QLabel *userAgentLabelPointer; + QComboBox *zoomFactorComboBoxPointer; // The private functions. void populateJavaScriptLabel() const; diff --git a/src/helpers/DomainsDatabaseHelper.cpp b/src/helpers/DomainsDatabaseHelper.cpp index 48b28a3..5b6c4fa 100644 --- a/src/helpers/DomainsDatabaseHelper.cpp +++ b/src/helpers/DomainsDatabaseHelper.cpp @@ -26,13 +26,15 @@ const QString DomainsDatabaseHelper::CONNECTION_NAME = "domains_database"; const QString DomainsDatabaseHelper::DOMAINS_TABLE = "domains"; // Define the private static schema constants. -const int DomainsDatabaseHelper::SCHEMA_VERSION = 2; +const int DomainsDatabaseHelper::SCHEMA_VERSION = 3; // Define the public static database field names. const QString DomainsDatabaseHelper::_ID = "_id"; const QString DomainsDatabaseHelper::DOMAIN_NAME = "domain_name"; const QString DomainsDatabaseHelper::JAVASCRIPT = "javascript"; const QString DomainsDatabaseHelper::USER_AGENT = "user_agent"; +const QString DomainsDatabaseHelper::ZOOM_FACTOR = "zoom_factor"; +const QString DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR = "custom_zoom_factor"; // The default constructor. DomainsDatabaseHelper::DomainsDatabaseHelper() {} @@ -75,6 +77,7 @@ void DomainsDatabaseHelper::addDatabase() // Set the default value. domainsDatabase.exec("UPDATE " + DOMAINS_TABLE + " SET " + JAVASCRIPT + " = 0" ); + // Fallthrough to the next case. [[fallthrough]]; } @@ -83,6 +86,17 @@ void DomainsDatabaseHelper::addDatabase() { // Add the User Agent column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "'"); + + // Fallthrough to the next case. + [[fallthrough]]; + } + + // Upgrade from schema version 2. + case 2: + { + // Add the Zoom Factor columns. + domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ZOOM_FACTOR + " INTEGER DEFAULT 0"); + domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + CUSTOM_ZOOM_FACTOR + " REAL DEFAULT 1.0"); } } @@ -99,8 +113,10 @@ void DomainsDatabaseHelper::addDatabase() createTableQuery.prepare("CREATE TABLE " + DOMAINS_TABLE + "(" + _ID + " INTEGER PRIMARY KEY, " + DOMAIN_NAME + " TEXT, " + - JAVASCRIPT + " INTEGER DEFAULT 0," + - USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "')" + JAVASCRIPT + " INTEGER DEFAULT 0, " + + USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "', " + + ZOOM_FACTOR + " INTEGER DEFAULT 0, " + + CUSTOM_ZOOM_FACTOR + " REAL DEFAULT 1.0)" ); // Execute the query. diff --git a/src/helpers/DomainsDatabaseHelper.h b/src/helpers/DomainsDatabaseHelper.h index 4badf41..b95988d 100644 --- a/src/helpers/DomainsDatabaseHelper.h +++ b/src/helpers/DomainsDatabaseHelper.h @@ -37,14 +37,17 @@ public: static const int SYSTEM_DEFAULT = 0; static const int DISABLED = 1; static const int ENABLED = 2; + static const int CUSTOM = 1; // The public constants. static const QString _ID; static const QString CONNECTION_NAME; + static const QString CUSTOM_ZOOM_FACTOR; static const QString DOMAIN_NAME; static const QString DOMAINS_TABLE; static const QString JAVASCRIPT; static const QString USER_AGENT; + static const QString ZOOM_FACTOR; private: // The private static constants. diff --git a/src/ui.rc/browser_ui.rc b/src/ui.rc/browser_ui.rc index 73bf318..3c46ee0 100644 --- a/src/ui.rc/browser_ui.rc +++ b/src/ui.rc/browser_ui.rc @@ -30,7 +30,7 @@ On-The-Fly Settings - User Agent + User Agent @@ -45,7 +45,7 @@ - Search Engine + Search Engine diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 74b27cf..90539a3 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -104,20 +104,23 @@ void BrowserView::applyApplicationSettings() } // This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument. -void BrowserView::applyDomainSettingsAndReload() const +// Once has been resolved this can be `const`. +void BrowserView::applyDomainSettingsAndReload() { // Apply the domain settings. `true` reloads the website. applyDomainSettings(webEngineViewPointer->url().host(), true); } // This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument. -void BrowserView::applyDomainSettingsWithoutReloading(const QString &hostname) const +// Once has been resolved this can be `const`. +void BrowserView::applyDomainSettingsWithoutReloading(const QString &hostname) { // Apply the domain settings `false` does not reload the website. applyDomainSettings(hostname, false); } -void BrowserView::applyDomainSettings(const QString &hostname, const bool reloadWebsite) const +// Once has been resolved this can be `const`. +void BrowserView::applyDomainSettings(const QString &hostname, const bool reloadWebsite) { // Get the record for the hostname. QSqlQuery domainQuery = DomainsDatabaseHelper::getDomainQuery(hostname); @@ -159,8 +162,20 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString())); + // Check if a custom zoom factor is set. This can be removed once has been resolved. + if (domainRecord.field(DomainsDatabaseHelper::ZOOM_FACTOR).value().toInt()) + { + // Store the current zoom factor. + currentZoomFactor = domainRecord.field(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR).value().toDouble(); + } + else + { + // Reset the current zoom factor. + currentZoomFactor = Settings::zoomFactor(); + } + // Set the zoom factor. - webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); + webEngineViewPointer->setZoomFactor(currentZoomFactor); // Apply the domain settings palette to the URL line edit. emit updateDomainSettingsIndicator(true); @@ -173,8 +188,11 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); + // Store the current zoom factor. + currentZoomFactor = Settings::zoomFactor(); + // Set the zoom factor. - webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); + webEngineViewPointer->setZoomFactor(currentZoomFactor); // Apply the no domain settings palette to the URL line edit. emit updateDomainSettingsIndicator(false); @@ -324,6 +342,6 @@ void BrowserView::updateInterface() const emit updateBackAction(webEngineHistoryPointer->canGoBack()); emit updateForwardAction(webEngineHistoryPointer->canGoForward()); - // Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. Hopefully it will be fixed in Qt6. - webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); + // Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. + webEngineViewPointer->setZoomFactor(currentZoomFactor); } diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index 3ba8bc7..12f0274 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -57,8 +57,8 @@ signals: public Q_SLOTS: // The public slots. void applyApplicationSettings(); - void applyDomainSettingsAndReload() const; - void applyDomainSettingsWithoutReloading(const QString &hostname) const; + void applyDomainSettingsAndReload(); + void applyDomainSettingsWithoutReloading(const QString &hostname); void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer); void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const; void back() const; @@ -75,6 +75,7 @@ private Q_SLOTS: private: // The private variables. + double currentZoomFactor; // This can be removed once has been resolved. QString searchEngineUrl; QWebEngineHistory *webEngineHistoryPointer; QWebEngineProfile *webEngineProfilePointer; @@ -82,6 +83,6 @@ private: QWebEngineView *webEngineViewPointer; // The private functions. - void applyDomainSettings(const QString &hostname, const bool reloadWebsite) const; + void applyDomainSettings(const QString &hostname, const bool reloadWebsite); }; #endif diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 77bb43b..e2dd301 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -130,7 +130,22 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings")); // Set the action icons. - //refreshActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); + userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode")); + userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr"))); + userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium"))); + userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr"))); + userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium"))); + userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties"))); + userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties"))); + userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties"))); + searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search"))); + searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search"))); + searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search"))); + searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google"))); + searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search"))); + searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo"))); + searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search"))); + zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom"))); domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("network-server-symbolic"))); // Update the on-the-fly menus.