From c5bf7a98f5f85eb3af53630b424c6a5d42868621 Mon Sep 17 00:00:00 2001 From: Keshav Date: Sun, 20 Mar 2022 13:40:33 +0530 Subject: feat: start application minimized. closes #19 - there is a setting to enable this feature --- src/main.cpp | 10 +- src/mainwindow.cpp | 60 +-- src/mainwindow.h | 2 +- src/settingswidget.cpp | 52 +- src/settingswidget.h | 6 + src/settingswidget.ui | 1319 ++++++++++++++++++++++++------------------------ 6 files changed, 750 insertions(+), 699 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 6aaa42a..68fbe3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,14 +68,18 @@ int main(int argc, char *argv[]) { MainWindow window; QStringList argsList = app.arguments(); - qWarning() << "Launching with argument" << argsList; foreach (QString argStr, argsList) { if (argStr.contains("whatsapp://")) { - qWarning() << "Link passed as argument" << argStr; window.loadAppWithArgument(argStr); } } - window.show(); + QSettings settings; + if (QSystemTrayIcon::isSystemTrayAvailable() && + settings.value("startMinimized", false).toBool()) { + window.runMinimized(); + }else{ + window.show(); + } return app.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a0da733..f8b29d1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -73,10 +73,9 @@ MainWindow::MainWindow(QWidget *parent) }); } -MainWindow::~MainWindow() -{ - webEngine->deleteLater(); -} +void MainWindow::runMinimized() { this->minimizeAction->trigger(); } + +MainWindow::~MainWindow() { webEngine->deleteLater(); } void MainWindow::loadAppWithArgument(const QString &arg) { // https://faq.whatsapp.com/iphone/how-to-link-to-whatsapp-from-a-different-app/?lang=en @@ -261,9 +260,6 @@ void MainWindow::init_settingWidget() { // spell checker settingsWidget->loadDictionaries(m_dictionaries); - - settingsWidget->resize(settingsWidget->sizeHint().width(), - settingsWidget->minimumSizeHint().height()); } } @@ -307,7 +303,7 @@ void MainWindow::showSettings() { if (!settingsWidget->isVisible()) { this->updateSettingsUserAgentWidget(); settingsWidget->refresh(); - settingsWidget->showNormal(); + settingsWidget->show(); } } @@ -747,30 +743,30 @@ void MainWindow::checkLoadedCorrectly() { if (webEngine && webEngine->page()) { // test 1 based on the class name of body of the page webEngine->page()->runJavaScript( - "document.querySelector('body').className", - [this](const QVariant &result) { - if (result.toString().contains("page-version", Qt::CaseInsensitive)) { - qWarning() << "Test 1 found" << result.toString(); - webEngine->page()->runJavaScript( - "document.getElementsByTagName('body')[0].innerText = ''"); - loadingQuirk("test1"); - } else if (webEngine->title().contains("Error", - Qt::CaseInsensitive)) { - utils::delete_cache(webEngine->page()->profile()->cachePath()); - utils::delete_cache( - webEngine->page()->profile()->persistentStoragePath()); - settings.setValue("useragent", defaultUserAgentStr); - utils *util = new utils(this); - util->DisplayExceptionErrorDialog( - "test1 handleWebViewTitleChanged(title) title: Error, " - "Resetting UA, Quiting!\nUA: " + - settings.value("useragent", "DefaultUA").toString()); - - quitAction->trigger(); - } else { - qWarning() << "Test 1 Loaded correctly value:" << result.toString(); - } - }); + "document.querySelector('body').className", + [this](const QVariant &result) { + if (result.toString().contains("page-version", Qt::CaseInsensitive)) { + qWarning() << "Test 1 found" << result.toString(); + webEngine->page()->runJavaScript( + "document.getElementsByTagName('body')[0].innerText = ''"); + loadingQuirk("test1"); + } else if (webEngine->title().contains("Error", + Qt::CaseInsensitive)) { + utils::delete_cache(webEngine->page()->profile()->cachePath()); + utils::delete_cache( + webEngine->page()->profile()->persistentStoragePath()); + settings.setValue("useragent", defaultUserAgentStr); + utils *util = new utils(this); + util->DisplayExceptionErrorDialog( + "test1 handleWebViewTitleChanged(title) title: Error, " + "Resetting UA, Quiting!\nUA: " + + settings.value("useragent", "DefaultUA").toString()); + + quitAction->trigger(); + } else { + qWarning() << "Test 1 Loaded correctly value:" << result.toString(); + } + }); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 7676cb0..5ffe9b1 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -49,7 +49,7 @@ public slots: void handleLoadFinished(bool loaded); void handleDownloadRequested(QWebEngineDownloadItem *download); void loadAppWithArgument(const QString &arg); - + void runMinimized(); protected slots: void closeEvent(QCloseEvent *event) override; void resizeEvent(QResizeEvent *event) override; diff --git a/src/settingswidget.cpp b/src/settingswidget.cpp index ba42372..b07340c 100644 --- a/src/settingswidget.cpp +++ b/src/settingswidget.cpp @@ -19,7 +19,6 @@ SettingsWidget::SettingsWidget(QWidget *parent, QString engineCachePath, ui->zoomFactorSpinBox->setRange(0.25, 5.0); ui->zoomFactorSpinBox->setValue(settings.value("zoomFactor", 1.0).toDouble()); - // emit zoomChanged(); ui->closeButtonActionComboBox->setCurrentIndex( settings.value("closeButtonActionCombo", 0).toInt()); @@ -40,6 +39,8 @@ SettingsWidget::SettingsWidget(QWidget *parent, QString engineCachePath, settings.value("notificationCombo", 1).toInt()); ui->useNativeFileDialog->setChecked( settings.value("useNativeFileDialog", false).toBool()); + ui->startMinimized->setChecked( + settings.value("startMinimized", false).toBool()); ui->automaticThemeCheckBox->blockSignals(true); bool automaticThemeSwitching = @@ -66,6 +67,51 @@ SettingsWidget::SettingsWidget(QWidget *parent, QString engineCachePath, applyThemeQuirks(); ui->setUserAgent->setEnabled(false); + + // event filter to prevent wheel event on certain widgets + foreach (QSlider *slider, this->findChildren()) { + slider->installEventFilter(this); + } + foreach (QComboBox *box, this->findChildren()) { + box->installEventFilter(this); + } + foreach (QSpinBox *spinBox, this->findChildren()) { + spinBox->installEventFilter(this); + } + + ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + this->setMinimumHeight(580); + + ui->scrollArea->setMinimumWidth( + ui->groupBox_8->sizeHint().width() + ui->scrollArea->sizeHint().width() + + ui->scrollAreaWidgetContents->layout()->spacing()); + if (settings.value("settingsGeo").isValid()) { + this->restoreGeometry(settings.value("settingsGeo").toByteArray()); + } +} + +bool SettingsWidget::eventFilter(QObject *obj, QEvent *event) { + + if (isChildOf(this, obj)) { + if (event->type() == QEvent::Wheel) { + return true; + } + } + return QWidget::eventFilter(obj, event); +} + +void SettingsWidget::closeEvent(QCloseEvent *event) { + settings.setValue("settingsGeo", this->saveGeometry()); + QWidget::closeEvent(event); +} + +bool SettingsWidget::isChildOf(QObject *Of, QObject *self) { + bool ischild = false; + if (Of->findChild(self->objectName())) { + ischild = true; + } + return ischild; } inline bool inRange(unsigned low, unsigned high, unsigned x) { @@ -441,3 +487,7 @@ void SettingsWidget::on_zoomReset_clicked() { settings.setValue("zoomFactor", ui->zoomFactorSpinBox->value()); emit zoomChanged(); } + +void SettingsWidget::on_startMinimized_toggled(bool checked) { + settings.setValue("startMinimized", checked); +} diff --git a/src/settingswidget.h b/src/settingswidget.h index 6f0fa4a..d7353ec 100644 --- a/src/settingswidget.h +++ b/src/settingswidget.h @@ -41,6 +41,9 @@ public slots: void appLockSetChecked(bool checked); void setCurrentPasswordText(QString str); void loadDictionaries(QStringList dictionaries); +protected slots: + bool eventFilter(QObject *obj, QEvent *event); + void closeEvent(QCloseEvent *event); private slots: QString cachePath(); QString persistentStoragePath(); @@ -94,6 +97,9 @@ private slots: void on_zoomReset_clicked(); + bool isChildOf(QObject *Of, QObject *self); + void on_startMinimized_toggled(bool checked); + private: Ui::SettingsWidget *ui; QString engineCachePath,enginePersistentStoragePath; diff --git a/src/settingswidget.ui b/src/settingswidget.ui index 55f55a1..09e5639 100644 --- a/src/settingswidget.ui +++ b/src/settingswidget.ui @@ -6,8 +6,8 @@ 0 0 - 512 - 644 + 537 + 580 @@ -88,698 +88,693 @@ background:transparent; - - - - - 9 - - - 9 - - - 9 - - - 9 + + + + true + + + + + 0 + 0 + 521 + 592 + - - - - General settings - - - - - - - - Close button action - - - - - - - - Minimize to tray + + + + + General settings + + + + + + + + Close button action + + + + + + + + Minimize to tray + + + + :/icons/window-2-line.png:/icons/window-2-line.png + + + + + Quit Application + + + + :/icons/shut-down-line.png:/icons/shut-down-line.png + + + + + + + + + + 0 + + + + + <html><head/><body><p>Enable application lock screen.</p></body></html> + + + Enable App Lock on Start + + + + + + + Current Password: + + + + + + + + + + + + 1 + 0 + + + + + 1 + 16777215 + + + + background-color: rgba(63, 129, 216, 48); + + + Qt::Vertical + + + + + + + Disable Notifications PopUp + + + + + + + Disable Auto Playback of Media + + + + + + + Mute Audio from Page + + + + + + + + + PopUp timeout + + + + + + + Secs + + + 2 + + + 20 + + + + + + + + + + + + 0 + 1 + + + + + 16777215 + 1 + + + + background-color: rgba(63, 129, 216, 48); + + + QFrame::Raised + + + Qt::Horizontal + + + + + + + + + Start minimized + + + + + + + Use Native File Dialog + + + + + + + + + + + Enable Spell Checker + + + + + + + + 1 + 0 + + + + + 1 + 16777215 + + + + background-color: rgba(63, 129, 216, 48); + + + QFrame::Raised + + + Qt::Vertical + + + + + + + SpellChecker Language + + + + + + + + + + + + 0 + + + + + App permissions + + + + + + + Show permissions + + + + :/icons/categories/security.png:/icons/categories/security.png + + + + + + + + + + + Global App shortcuts + + + + + + + Show shortcuts + + + + :/icons/share-forward-line.png:/icons/share-forward-line.png + + + + + + + + + + + Notification type + + + + + + + + Native notification + + + + :/icons/categories/featured.png:/icons/categories/featured.png + + + + + Customized notification + + + + :/icons/categories/devices-and-iot.png:/icons/categories/devices-and-iot.png + + + + + + + + + 0 + 0 + + + + Try + + + + :/icons/categories/science.png:/icons/categories/science.png + + + + + + + + + + 0 + 1 + + + + + 16777215 + 1 + + + + background-color: rgba(63, 129, 216, 48); + + + QFrame::Raised + + + Qt::Horizontal + + + + + + + + + User Agent + + + + + + + + + + Set - :/icons/window-2-line.png:/icons/window-2-line.png + :/icons/categories/utilities.png:/icons/categories/utilities.png - - + + + + - Quit Application + Default - :/icons/shut-down-line.png:/icons/shut-down-line.png - - - - - - - - - - 0 - - - - - <html><head/><body><p>Enable application lock screen.</p></body></html> - - - Enable App Lock on Start - - - - - - - Current Password: - - - - - - - - - - - - 1 - 0 - - - - - 1 - 16777215 - - - - background-color: rgba(63, 129, 216, 48); - - - Qt::Vertical - - - - - - - Disable Notifications PopUp - - - - - - - Disable Auto Playback of Media - - - - - - - Mute Audio from Page - - - - - - - + :/icons/refresh-line.png:/icons/refresh-line.png + + + + + + + + + + + Theme + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Based on your system timezone and location.</p></body></html> + + + Automatic + + + + + + - PopUp timeout + Dark - - - - - - Secs + + + :/icons/moon-line.png:/icons/moon-line.png - - 2 + + + + Light - - 20 + + + :/icons/lightbulb-line.png:/icons/lightbulb-line.png - - - - - - - - - - - 0 - 1 - - - - - 16777215 - 1 - - - - background-color: rgba(63, 129, 216, 48); - - - QFrame::Raised - - - Qt::Horizontal - - - - - - - - - Use Native File Dialog - - - - - - - - - - - Enable Spell Checker - - - - - - - - 1 - 0 - - - - - 1 - 16777215 - - - - background-color: rgba(63, 129, 216, 48); - - - QFrame::Raised - - - Qt::Vertical - - - - - - - SpellChecker Language - - - - - - - - - - - - 0 - - - - - App permissions - - - - - - - Show permissions - - - - :/icons/categories/security.png:/icons/categories/security.png - - - - - - - - - - - Global App shortcuts - - - - - - - Show shortcuts - - - - :/icons/share-forward-line.png:/icons/share-forward-line.png - - - - - - - - - - - Notification type - - - - - - - - Native notification + + + + + + + + + 0 + + + + + Zoom factor + + + + + + + + 0 + 0 + + + + Zoom Out + + + - :/icons/categories/featured.png:/icons/categories/featured.png + :/icons/minus.png:/icons/minus.png + + + + + + + + 0 + 0 + + + + Qt::AlignCenter + + + true + + + QAbstractSpinBox::NoButtons + + + + + + + + 0 + 0 + + + + Zoom In - - - Customized notification + - :/icons/categories/devices-and-iot.png:/icons/categories/devices-and-iot.png - - - - - - - - - 0 - 0 - - - - Try - - - - :/icons/categories/science.png:/icons/categories/science.png - - - - - - - - - - 0 - 1 - - - - - 16777215 - 1 - - - - background-color: rgba(63, 129, 216, 48); - - - QFrame::Raised - - - Qt::Horizontal - - - - - - - - - User Agent - - - - - - - - - - Set - - - - :/icons/categories/utilities.png:/icons/categories/utilities.png - - - - - - - Default - - - - :/icons/refresh-line.png:/icons/refresh-line.png - - - - - - - - - - - Theme - - - - - - - - 0 - 0 - - - - <html><head/><body><p>Based on your system timezone and location.</p></body></html> - - - Automatic - - - - - - - - Dark + :/icons/plus.png:/icons/plus.png + + + + + + + + 1 + 0 + + + + + 1 + 16777215 + + + + background-color: rgba(63, 129, 216, 48); + + + QFrame::Raised + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + reset + + + - :/icons/moon-line.png:/icons/moon-line.png + :/icons/arrow-go-back-line.png:/icons/arrow-go-back-line.png - - + + + + + + + + + + + Application Storage and Other Settings + + + + + + - Light + Clear - :/icons/lightbulb-line.png:/icons/lightbulb-line.png - - - - - - - - - - 0 - - - - - Zoom factor - - - - - - - - 0 - 0 - - - - Zoom Out - - - - - - - :/icons/minus.png:/icons/minus.png - - - - - - - - 0 - 0 - - - - Qt::AlignCenter - - - true - - - QAbstractSpinBox::NoButtons - - - - - - - - 0 - 0 - - - - Zoom In - - - - - - - :/icons/plus.png:/icons/plus.png - - - - - - - - 1 - 0 - - - - - 1 - 16777215 - - - - background-color: rgba(63, 129, 216, 48); - - - QFrame::Raised - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - reset - - - - - - - :/icons/arrow-go-back-line.png:/icons/arrow-go-back-line.png - - - - - - - - - - - - Application Storage and Other Settings - - - - - - - - Clear - - - - :/icons/delete-bin-3-line.png:/icons/delete-bin-3-line.png - - - - - - - Application Cache - - - - - - - - - - - Qt::AlignCenter - - - - - - - - 10 - false - - - - Property - - - - - - - - 10 - false - - - - Option - - - Qt::AlignCenter - - - - - - - - 10 - false - - - - Size - - - Qt::AlignCenter - - - - - - - <html><head/><body><p>Persistent data includes persistent cookies, HTML5 local storage, and visited links.</p></body></html> - - - Persistent data - - - - - - - - - - - Qt::AlignCenter - - - - - - - Clear - - - - :/icons/delete-bin-3-line.png:/icons/delete-bin-3-line.png - - - - - - - - - + :/icons/delete-bin-3-line.png:/icons/delete-bin-3-line.png + + + + + + + Application Cache + + + + + + + - + + + Qt::AlignCenter + + + + + + + + 10 + false + + + + Property + + + + + + + + 10 + false + + + + Option + + + Qt::AlignCenter + + + + + + + + 10 + false + + + + Size + + + Qt::AlignCenter + + + + + + + <html><head/><body><p>Persistent data includes persistent cookies, HTML5 local storage, and visited links.</p></body></html> + + + Persistent data + + + + + + + - + + + Qt::AlignCenter + + + + + + + Clear + + + + :/icons/delete-bin-3-line.png:/icons/delete-bin-3-line.png + + + + + + + + + + - - - - Qt::Vertical - - - - 20 - 40 - - - - -- cgit v1.2.3