Skip to content

Truly independent web browser

UI/Qt: Keep a pressed look on popover buttons when opened

Timothy Flynna7f2ce98c68e
diff --git a/UI/Qt/Popover.cpp b/UI/Qt/Popover.cpp
index c00ca1de2cf..693c4f8025b 100644
--- a/UI/Qt/Popover.cpp
+++ b/UI/Qt/Popover.cpp
@@ -16,6 +16,7 @@
#include <QLabel>
#include <QPushButton>
#include <QScreen>
+#include <QShowEvent>
#include <QVBoxLayout>
namespace Ladybird {
@@ -49,6 +50,20 @@ Popover::Popover(QWidget* parent)
m_card->setGraphicsEffect(shadow);
}
+void Popover::showEvent(QShowEvent* event)
+{
+ QWidget::showEvent(event);
+ if (on_visibility_change)
+ on_visibility_change(true);
+}
+
+void Popover::hideEvent(QHideEvent* event)
+{
+ QWidget::hideEvent(event);
+ if (on_visibility_change)
+ on_visibility_change(false);
+}
+
// A message that asks whether to act on it. Leaving the popover in any other way than accepting it, such as by clicking
// outside it, dismisses the message.
MessagePopover::MessagePopover(QWidget* parent, int width, QString const& title, QString const& body, QString const& dismiss_text, QString const& accept_text)
diff --git a/UI/Qt/Popover.h b/UI/Qt/Popover.h
index 2b6264aaf30..62bac20b809 100644
--- a/UI/Qt/Popover.h
+++ b/UI/Qt/Popover.h
@@ -13,6 +13,7 @@
class QFrame;
class QHideEvent;
+class QShowEvent;
namespace Ladybird {
@@ -22,9 +23,14 @@ public:
QFrame& card() { return *m_card; }
+ Function<void(bool)> on_visibility_change;
+
protected:
explicit Popover(QWidget* parent);
+ virtual void showEvent(QShowEvent*) override;
+ virtual void hideEvent(QHideEvent*) override;
+
private:
QFrame* m_card { nullptr };
};
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index 8ee71a71da2..14cbbea0413 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -1579,6 +1579,10 @@ void Tab::show_downloads_popover()
if (!m_downloads_popover) {
m_downloads_popover = new DownloadsPopover(this);
+ m_downloads_popover->on_visibility_change = [button = QPointer(m_downloads_button)](bool visible) {
+ if (button)
+ button->setDown(visible);
+ };
m_downloads_popover->on_cancel_download = [this](u64 id) {
auto& file_downloader = WebView::Application::the().file_downloader();
if (auto download = file_downloader.download(id); download.has_value() && WebView::FileDownloader::status_is_active(download->status))
@@ -1683,6 +1687,10 @@ void Tab::show_content_blocking_popover()
if (!m_content_blocking_popover) {
m_content_blocking_popover = new ContentBlockingPopover(this);
+ m_content_blocking_popover->on_visibility_change = [button = QPointer(m_content_blocking_button)](bool visible) {
+ if (button)
+ button->setDown(visible);
+ };
m_content_blocking_popover->on_keyboard_dismiss = [button = QPointer(m_content_blocking_button)] {
if (button && button->isVisible())
button->setFocus(Qt::PopupFocusReason);