From b97f9f580943e7fd06567765883c1655c61f25ae Mon Sep 17 00:00:00 2001 From: Cameron Youell Date: Thu, 19 Jan 2023 01:12:13 +1100 Subject: [PATCH] Ladybird: Make LocationEdit its own class Also make return key behave more like other browsers when editing --- Ladybird/CMakeLists.txt | 1 + Ladybird/LocationEdit.cpp | 16 ++++++++++++++++ Ladybird/LocationEdit.h | 19 +++++++++++++++++++ Ladybird/Tab.cpp | 2 +- Ladybird/Tab.h | 3 ++- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 Ladybird/LocationEdit.cpp create mode 100644 Ladybird/LocationEdit.h diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt index c216275f4b8..275aa369ae6 100644 --- a/Ladybird/CMakeLists.txt +++ b/Ladybird/CMakeLists.txt @@ -83,6 +83,7 @@ set(SOURCES BrowserWindow.cpp ConsoleWidget.cpp InspectorWidget.cpp + LocationEdit.cpp ModelTranslator.cpp Settings.cpp SettingsDialog.cpp diff --git a/Ladybird/LocationEdit.cpp b/Ladybird/LocationEdit.cpp new file mode 100644 index 00000000000..474a3fd0634 --- /dev/null +++ b/Ladybird/LocationEdit.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023, Cameron Youell + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "LocationEdit.h" +#include "Tab.h" + +LocationEdit::LocationEdit(Tab* tab) + : QLineEdit(tab) +{ + connect(this, &QLineEdit::returnPressed, this, [&] { + clearFocus(); + }); +} diff --git a/Ladybird/LocationEdit.h b/Ladybird/LocationEdit.h new file mode 100644 index 00000000000..d8ebda54900 --- /dev/null +++ b/Ladybird/LocationEdit.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023, Cameron Youell + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#define AK_DONT_REPLACE_STD + +#include + +class Tab; + +class LocationEdit final : public QLineEdit { + Q_OBJECT +public: + explicit LocationEdit(Tab*); +}; diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index 53ce3845b66..fe3dc130352 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -30,7 +30,7 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path) m_view = new WebContentView(webdriver_content_ipc_path); m_toolbar = new QToolBar(this); - m_location_edit = new QLineEdit(this); + m_location_edit = new LocationEdit(this); m_hover_label = new QLabel(this); m_hover_label->hide(); diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index da5b70a1efd..22df9c8ab45 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -9,6 +9,7 @@ #define AK_DONT_REPLACE_STD +#include "LocationEdit.h" #include "WebContentView.h" #include #include @@ -55,7 +56,7 @@ private: QBoxLayout* m_layout; QToolBar* m_toolbar { nullptr }; - QLineEdit* m_location_edit { nullptr }; + LocationEdit* m_location_edit { nullptr }; WebContentView* m_view { nullptr }; BrowserWindow* m_window { nullptr }; Browser::History m_history;