mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-28 20:29:03 +00:00
Ladybird/Qt: Add a hover effect to the audio play state button
By default, a flat QPushButton does not have a hover effect. Add a small subclass to provide such an effect to make it clearer it is a button.
This commit is contained in:
parent
22ab12e4a1
commit
1fc995d4aa
Notes:
sideshowbarker
2024-07-16 18:03:21 +09:00
Author: https://github.com/trflynn89
Commit: 1fc995d4aa
Pull-request: https://github.com/SerenityOS/serenity/pull/23811
Reviewed-by: https://github.com/MacDue
5 changed files with 63 additions and 4 deletions
|
@ -124,6 +124,7 @@ if (ENABLE_QT)
|
||||||
Qt/Settings.cpp
|
Qt/Settings.cpp
|
||||||
Qt/SettingsDialog.cpp
|
Qt/SettingsDialog.cpp
|
||||||
Qt/Tab.cpp
|
Qt/Tab.cpp
|
||||||
|
Qt/TabBar.cpp
|
||||||
Qt/TaskManagerWindow.cpp
|
Qt/TaskManagerWindow.cpp
|
||||||
Qt/TVGIconEngine.cpp
|
Qt/TVGIconEngine.cpp
|
||||||
Qt/StringUtils.cpp
|
Qt/StringUtils.cpp
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "TaskManagerWindow.h"
|
#include "TaskManagerWindow.h"
|
||||||
#include "WebContentView.h"
|
#include "WebContentView.h"
|
||||||
#include <AK/TypeCasts.h>
|
#include <AK/TypeCasts.h>
|
||||||
|
#include <Ladybird/Qt/TabBar.h>
|
||||||
#include <Ladybird/Utilities.h>
|
#include <Ladybird/Utilities.h>
|
||||||
#include <LibWeb/CSS/PreferredColorScheme.h>
|
#include <LibWeb/CSS/PreferredColorScheme.h>
|
||||||
#include <LibWeb/Loader/ResourceLoader.h>
|
#include <LibWeb/Loader/ResourceLoader.h>
|
||||||
|
@ -669,11 +670,9 @@ void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlay
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Web::HTML::AudioPlayState::Playing:
|
case Web::HTML::AudioPlayState::Playing:
|
||||||
auto* button = new QPushButton(icon_for_page_mute_state(*tab), {});
|
auto* button = new TabBarButton(icon_for_page_mute_state(*tab));
|
||||||
button->setToolTip(tool_tip_for_page_mute_state(*tab));
|
button->setToolTip(tool_tip_for_page_mute_state(*tab));
|
||||||
button->setObjectName("LadybirdAudioState");
|
button->setObjectName("LadybirdAudioState");
|
||||||
button->setFlat(true);
|
|
||||||
button->resize({ 20, 20 });
|
|
||||||
|
|
||||||
connect(button, &QPushButton::clicked, this, [this, tab, position]() {
|
connect(button, &QPushButton::clicked, this, [this, tab, position]() {
|
||||||
tab->view().toggle_page_mute_state();
|
tab->view().toggle_page_mute_state();
|
||||||
|
@ -685,7 +684,7 @@ void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlay
|
||||||
break;
|
break;
|
||||||
case Web::HTML::AudioPlayState::Playing:
|
case Web::HTML::AudioPlayState::Playing:
|
||||||
auto* button = m_tabs_container->tabBar()->tabButton(index, position);
|
auto* button = m_tabs_container->tabBar()->tabButton(index, position);
|
||||||
verify_cast<QPushButton>(button)->setIcon(icon_for_page_mute_state(*tab));
|
verify_cast<TabBarButton>(button)->setIcon(icon_for_page_mute_state(*tab));
|
||||||
button->setToolTip(tool_tip_for_page_mute_state(*tab));
|
button->setToolTip(tool_tip_for_page_mute_state(*tab));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
30
Ladybird/Qt/TabBar.cpp
Normal file
30
Ladybird/Qt/TabBar.cpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Ladybird/Qt/TabBar.h>
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
namespace Ladybird {
|
||||||
|
|
||||||
|
TabBarButton::TabBarButton(QIcon const& icon, QWidget* parent)
|
||||||
|
: QPushButton(icon, {}, parent)
|
||||||
|
{
|
||||||
|
resize({ 20, 20 });
|
||||||
|
setFlat(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TabBarButton::event(QEvent* event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::Enter)
|
||||||
|
setFlat(false);
|
||||||
|
if (event->type() == QEvent::Leave)
|
||||||
|
setFlat(true);
|
||||||
|
|
||||||
|
return QPushButton::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
Ladybird/Qt/TabBar.h
Normal file
27
Ladybird/Qt/TabBar.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
class QEvent;
|
||||||
|
class QIcon;
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
namespace Ladybird {
|
||||||
|
|
||||||
|
class TabBarButton : public QPushButton {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TabBarButton(QIcon const& icon, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool event(QEvent* event);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ moc_qt_objects("generate_moc") {
|
||||||
"Qt/LocationEdit.h",
|
"Qt/LocationEdit.h",
|
||||||
"Qt/SettingsDialog.h",
|
"Qt/SettingsDialog.h",
|
||||||
"Qt/Tab.h",
|
"Qt/Tab.h",
|
||||||
|
"Qt/TabBar.h",
|
||||||
"Qt/TaskManagerWindow.h",
|
"Qt/TaskManagerWindow.h",
|
||||||
"Qt/WebContentView.h",
|
"Qt/WebContentView.h",
|
||||||
]
|
]
|
||||||
|
@ -96,6 +97,7 @@ executable("ladybird_executable") {
|
||||||
"Qt/StringUtils.cpp",
|
"Qt/StringUtils.cpp",
|
||||||
"Qt/TVGIconEngine.cpp",
|
"Qt/TVGIconEngine.cpp",
|
||||||
"Qt/Tab.cpp",
|
"Qt/Tab.cpp",
|
||||||
|
"Qt/TabBar.cpp",
|
||||||
"Qt/TaskManagerWindow.cpp",
|
"Qt/TaskManagerWindow.cpp",
|
||||||
"Qt/WebContentView.cpp",
|
"Qt/WebContentView.cpp",
|
||||||
"Qt/main.cpp",
|
"Qt/main.cpp",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue