mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +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
2 changed files with 32 additions and 5 deletions
|
@ -10,8 +10,10 @@
|
||||||
#include "History.h"
|
#include "History.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QFontMetrics>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QToolTip>
|
#include <QResizeEvent>
|
||||||
|
|
||||||
extern String s_serenity_resource_root;
|
extern String s_serenity_resource_root;
|
||||||
extern Browser::Settings* s_settings;
|
extern Browser::Settings* s_settings;
|
||||||
|
@ -26,6 +28,10 @@ Tab::Tab(QMainWindow* window)
|
||||||
m_toolbar = new QToolBar;
|
m_toolbar = new QToolBar;
|
||||||
m_location_edit = new QLineEdit;
|
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");
|
auto* focus_location_edit_action = new QAction("Edit Location");
|
||||||
focus_location_edit_action->setShortcut(QKeySequence("Ctrl+L"));
|
focus_location_edit_action->setShortcut(QKeySequence("Ctrl+L"));
|
||||||
addAction(focus_location_edit_action);
|
addAction(focus_location_edit_action);
|
||||||
|
@ -52,11 +58,12 @@ Tab::Tab(QMainWindow* window)
|
||||||
m_toolbar->addWidget(m_location_edit);
|
m_toolbar->addWidget(m_location_edit);
|
||||||
|
|
||||||
QObject::connect(m_view, &WebView::linkHovered, [this](QString const& title) {
|
QObject::connect(m_view, &WebView::linkHovered, [this](QString const& title) {
|
||||||
const QPoint* pos = new QPoint(0, size().height() - 15);
|
m_hover_label->setText(title);
|
||||||
QToolTip::showText(*pos, title, this);
|
update_hover_label();
|
||||||
|
m_hover_label->show();
|
||||||
});
|
});
|
||||||
QObject::connect(m_view, &WebView::linkUnhovered, [] {
|
QObject::connect(m_view, &WebView::linkUnhovered, [this] {
|
||||||
QToolTip::hideText();
|
m_hover_label->hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(m_view, &WebView::loadStarted, [this](const URL& url) {
|
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);
|
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 "History.h"
|
||||||
#include "WebView.h"
|
#include "WebView.h"
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
@ -41,6 +42,10 @@ signals:
|
||||||
void favicon_changed(int id, QIcon);
|
void favicon_changed(int id, QIcon);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void resizeEvent(QResizeEvent*) override;
|
||||||
|
|
||||||
|
void update_hover_label();
|
||||||
|
|
||||||
QBoxLayout* m_layout;
|
QBoxLayout* m_layout;
|
||||||
QToolBar* m_toolbar { nullptr };
|
QToolBar* m_toolbar { nullptr };
|
||||||
QLineEdit* m_location_edit { nullptr };
|
QLineEdit* m_location_edit { nullptr };
|
||||||
|
@ -48,6 +53,7 @@ private:
|
||||||
QMainWindow* m_window { nullptr };
|
QMainWindow* m_window { nullptr };
|
||||||
Browser::History m_history;
|
Browser::History m_history;
|
||||||
QString m_title;
|
QString m_title;
|
||||||
|
QLabel* m_hover_label { nullptr };
|
||||||
|
|
||||||
OwnPtr<QAction> m_back_action;
|
OwnPtr<QAction> m_back_action;
|
||||||
OwnPtr<QAction> m_forward_action;
|
OwnPtr<QAction> m_forward_action;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue