mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
Ladybird: Show hovered link URLs in a conditional UI label
The tooltips for hovered links were super awkward when in a tooltip
This commit is contained in:
parent
aa27112d78
commit
d74802e4e2
Notes:
sideshowbarker
2024-07-17 05:19:06 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d74802e4e2 Pull-request: https://github.com/SerenityOS/serenity/pull/16583 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
2 changed files with 32 additions and 5 deletions
|
@ -10,8 +10,10 @@
|
|||
#include "History.h"
|
||||
#include "Settings.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QPoint>
|
||||
#include <QToolTip>
|
||||
#include <QResizeEvent>
|
||||
|
||||
extern String s_serenity_resource_root;
|
||||
extern Browser::Settings* s_settings;
|
||||
|
@ -26,6 +28,10 @@ Tab::Tab(QMainWindow* window)
|
|||
m_toolbar = new QToolBar;
|
||||
m_location_edit = new QLineEdit;
|
||||
|
||||
m_hover_label = new QLabel(this);
|
||||
m_hover_label->setFrameShape(QFrame::Shape::Box);
|
||||
m_hover_label->setAutoFillBackground(true);
|
||||
|
||||
auto* focus_location_edit_action = new QAction("Edit Location");
|
||||
focus_location_edit_action->setShortcut(QKeySequence("Ctrl+L"));
|
||||
addAction(focus_location_edit_action);
|
||||
|
@ -52,11 +58,12 @@ Tab::Tab(QMainWindow* window)
|
|||
m_toolbar->addWidget(m_location_edit);
|
||||
|
||||
QObject::connect(m_view, &WebView::linkHovered, [this](QString const& title) {
|
||||
const QPoint* pos = new QPoint(0, size().height() - 15);
|
||||
QToolTip::showText(*pos, title, this);
|
||||
m_hover_label->setText(title);
|
||||
update_hover_label();
|
||||
m_hover_label->show();
|
||||
});
|
||||
QObject::connect(m_view, &WebView::linkUnhovered, [] {
|
||||
QToolTip::hideText();
|
||||
QObject::connect(m_view, &WebView::linkUnhovered, [this] {
|
||||
m_hover_label->hide();
|
||||
});
|
||||
|
||||
QObject::connect(m_view, &WebView::loadStarted, [this](const URL& url) {
|
||||
|
@ -138,3 +145,17 @@ void Tab::debug_request(String const& request, String const& argument)
|
|||
{
|
||||
m_view->debug_request(request, argument);
|
||||
}
|
||||
|
||||
void Tab::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
if (m_hover_label->isVisible())
|
||||
update_hover_label();
|
||||
}
|
||||
|
||||
void Tab::update_hover_label()
|
||||
{
|
||||
m_hover_label->resize(QFontMetrics(m_hover_label->font()).boundingRect(m_hover_label->text()).adjusted(-4, -2, 4, 2).size());
|
||||
m_hover_label->move(6, height() - m_hover_label->height() - 8);
|
||||
m_hover_label->raise();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "History.h"
|
||||
#include "WebView.h"
|
||||
#include <QBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QToolBar>
|
||||
#include <QWidget>
|
||||
|
@ -41,6 +42,10 @@ signals:
|
|||
void favicon_changed(int id, QIcon);
|
||||
|
||||
private:
|
||||
virtual void resizeEvent(QResizeEvent*) override;
|
||||
|
||||
void update_hover_label();
|
||||
|
||||
QBoxLayout* m_layout;
|
||||
QToolBar* m_toolbar { nullptr };
|
||||
QLineEdit* m_location_edit { nullptr };
|
||||
|
@ -48,6 +53,7 @@ private:
|
|||
QMainWindow* m_window { nullptr };
|
||||
Browser::History m_history;
|
||||
QString m_title;
|
||||
QLabel* m_hover_label { nullptr };
|
||||
|
||||
OwnPtr<QAction> m_back_action;
|
||||
OwnPtr<QAction> m_forward_action;
|
||||
|
|
Loading…
Reference in a new issue