mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
UI/Qt: Fix hover_label hiding URLs
m_hover_label did not have checks if the mouse is in the same location. This caused clickable URLs to be hidden. Also shortened the label text to not be longer than half of the window.
This commit is contained in:
parent
72f093ba9f
commit
edf29857f8
Notes:
github-actions[bot]
2024-12-04 16:10:49 +00:00
Author: https://github.com/Sidicer Commit: https://github.com/LadybirdBrowser/ladybird/commit/edf29857f8f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1176 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/tcl3
3 changed files with 36 additions and 6 deletions
|
@ -61,11 +61,15 @@ Tab::Tab(BrowserWindow* window, RefPtr<WebView::WebContentClient> parent_client,
|
|||
m_toolbar = new QToolBar(this);
|
||||
m_location_edit = new LocationEdit(this);
|
||||
|
||||
m_hover_label = new QLabel(this);
|
||||
m_hover_label = new HyperlinkLabel(this);
|
||||
m_hover_label->hide();
|
||||
m_hover_label->setFrameShape(QFrame::Shape::Box);
|
||||
m_hover_label->setAutoFillBackground(true);
|
||||
|
||||
QObject::connect(m_hover_label, &HyperlinkLabel::mouse_entered, [this] {
|
||||
update_hover_label();
|
||||
});
|
||||
|
||||
auto* focus_location_editor_action = new QAction("Edit Location", this);
|
||||
focus_location_editor_action->setShortcut(QKeySequence("Ctrl+L"));
|
||||
addAction(focus_location_editor_action);
|
||||
|
@ -852,12 +856,18 @@ void Tab::resizeEvent(QResizeEvent* event)
|
|||
|
||||
void Tab::update_hover_label()
|
||||
{
|
||||
m_hover_label->setText(QFontMetrics(m_hover_label->font()).elidedText(m_hover_label->text(), Qt::ElideRight, width() / 2 - 10));
|
||||
m_hover_label->resize(QFontMetrics(m_hover_label->font()).boundingRect(m_hover_label->text()).adjusted(-4, -2, 4, 2).size());
|
||||
auto hover_label_height = height() - m_hover_label->height() - 8;
|
||||
if (m_find_in_page->isVisible())
|
||||
hover_label_height -= m_find_in_page->height() - 4;
|
||||
|
||||
m_hover_label->move(6, hover_label_height);
|
||||
auto hover_label_height = height() - m_hover_label->height();
|
||||
if (m_find_in_page->isVisible())
|
||||
hover_label_height -= m_find_in_page->height();
|
||||
|
||||
if (m_hover_label->underMouse() && m_hover_label->x() == 0)
|
||||
m_hover_label->move(width() / 2 + (width() / 2 - m_hover_label->width()), hover_label_height);
|
||||
else
|
||||
m_hover_label->move(0, hover_label_height);
|
||||
|
||||
m_hover_label->raise();
|
||||
}
|
||||
|
||||
|
|
21
UI/Qt/Tab.h
21
UI/Qt/Tab.h
|
@ -26,6 +26,25 @@ namespace Ladybird {
|
|||
class BrowserWindow;
|
||||
class InspectorWidget;
|
||||
|
||||
class HyperlinkLabel final : public QLabel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HyperlinkLabel(QWidget* parent = nullptr)
|
||||
: QLabel(parent)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
virtual void enterEvent(QEnterEvent* event) override
|
||||
{
|
||||
emit mouse_entered(event);
|
||||
}
|
||||
|
||||
signals:
|
||||
void mouse_entered(QEnterEvent*);
|
||||
};
|
||||
|
||||
class Tab final : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -117,7 +136,7 @@ private:
|
|||
FindInPageWidget* m_find_in_page { nullptr };
|
||||
BrowserWindow* m_window { nullptr };
|
||||
QString m_title;
|
||||
QLabel* m_hover_label { nullptr };
|
||||
HyperlinkLabel* m_hover_label { nullptr };
|
||||
QIcon m_favicon;
|
||||
|
||||
QMenu* m_context_menu { nullptr };
|
||||
|
|
|
@ -403,6 +403,7 @@ void WebContentView::mouseMoveEvent(QMouseEvent* event)
|
|||
}
|
||||
|
||||
enqueue_native_event(Web::MouseEvent::Type::MouseMove, *event);
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void WebContentView::mousePressEvent(QMouseEvent* event)
|
||||
|
|
Loading…
Add table
Reference in a new issue