diff --git a/Ladybird/Qt/SettingsDialog.cpp b/Ladybird/Qt/SettingsDialog.cpp index be69a92e45..bd98068a22 100644 --- a/Ladybird/Qt/SettingsDialog.cpp +++ b/Ladybird/Qt/SettingsDialog.cpp @@ -9,7 +9,6 @@ #include "Settings.h" #include "StringUtils.h" #include -#include #include #include @@ -19,7 +18,6 @@ SettingsDialog::SettingsDialog(QMainWindow* window) : m_window(window) { m_layout = new QFormLayout(this); - m_ok_button = new QPushButton("&Save", this); m_enable_search = make(this); m_enable_search->setChecked(Settings::the()->enable_search()); @@ -35,6 +33,18 @@ SettingsDialog::SettingsDialog(QMainWindow* window) m_new_tab_page = make(this); m_new_tab_page->setText(Settings::the()->new_tab_page()); + QObject::connect(m_new_tab_page, &QLineEdit::textChanged, this, [this] { + auto url_string = MUST(ak_string_from_qstring(m_new_tab_page->text())); + m_new_tab_page->setStyleSheet(URL(url_string).is_valid() ? "" : "border: 1px solid red;"); + }); + QObject::connect(m_new_tab_page, &QLineEdit::editingFinished, this, [this] { + auto url_string = MUST(ak_string_from_qstring(m_new_tab_page->text())); + if (URL(url_string).is_valid()) + Settings::the()->set_new_tab_page(m_new_tab_page->text()); + }); + QObject::connect(m_new_tab_page, &QLineEdit::returnPressed, this, [this] { + close(); + }); setup_search_engines(); @@ -43,11 +53,6 @@ SettingsDialog::SettingsDialog(QMainWindow* window) m_layout->addRow(new QLabel("Search Engine", this), m_search_engine_dropdown); m_layout->addRow(new QLabel("Enable Autocomplete", this), m_enable_autocomplete); m_layout->addRow(new QLabel("Autocomplete Engine", this), m_autocomplete_engine_dropdown); - m_layout->addRow(m_ok_button); - - QObject::connect(m_ok_button, &QPushButton::released, this, [this] { - close(); - }); setWindowTitle("Settings"); setFixedWidth(300); @@ -114,18 +119,4 @@ void SettingsDialog::setup_search_engines() }); } -void SettingsDialog::closeEvent(QCloseEvent* event) -{ - save(); - event->accept(); -} - -void SettingsDialog::save() -{ - auto url_string = MUST(ak_string_from_qstring(m_new_tab_page->text())); - if (!URL(url_string).is_valid()) - return; - Settings::the()->set_new_tab_page(m_new_tab_page->text()); -} - } diff --git a/Ladybird/Qt/SettingsDialog.h b/Ladybird/Qt/SettingsDialog.h index 80eaa5df76..3df4717d60 100644 --- a/Ladybird/Qt/SettingsDialog.h +++ b/Ladybird/Qt/SettingsDialog.h @@ -23,15 +23,10 @@ class SettingsDialog : public QDialog { public: explicit SettingsDialog(QMainWindow* window); - void save(); - - virtual void closeEvent(QCloseEvent*) override; - private: void setup_search_engines(); QFormLayout* m_layout; - QPushButton* m_ok_button { nullptr }; QMainWindow* m_window { nullptr }; OwnPtr m_new_tab_page; OwnPtr m_enable_search;