mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-20 13:28:13 +03:00
UI/Qt: Don't allow tabs to be dragged past the new tab button
Before this change, if would a tab it will pass the add new tab button (+ button). closes #1124
This commit is contained in:
parent
779de840af
commit
9b79081a06
Notes:
github-actions[bot]
2024-09-18 16:54:07 +00:00
Author: https://github.com/PiyushXCoder 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/9b79081a060 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1418 Reviewed-by: https://github.com/tcl3 ✅
@ -45,6 +45,39 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event)
|
||||
tab->context_menu()->exec(event->globalPos());
|
||||
}
|
||||
|
||||
void TabBar::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
event->ignore();
|
||||
|
||||
auto rect_of_current_tab = tabRect(tabAt(event->pos()));
|
||||
m_x_position_in_selected_tab_while_dragging = event->pos().x() - rect_of_current_tab.x();
|
||||
|
||||
QTabBar::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void TabBar::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
event->ignore();
|
||||
|
||||
auto rect_of_first_tab = tabRect(0);
|
||||
auto rect_of_last_tab = tabRect(count() - 1);
|
||||
|
||||
auto boundary_limit_for_dragging_tab = QRect(rect_of_first_tab.x() + m_x_position_in_selected_tab_while_dragging, 0,
|
||||
rect_of_last_tab.x() + m_x_position_in_selected_tab_while_dragging, 0);
|
||||
|
||||
if (event->pos().x() >= boundary_limit_for_dragging_tab.x() && event->pos().x() <= boundary_limit_for_dragging_tab.width()) {
|
||||
QTabBar::mouseMoveEvent(event);
|
||||
} else {
|
||||
auto pos = event->pos();
|
||||
if (event->pos().x() > boundary_limit_for_dragging_tab.width())
|
||||
pos.setX(boundary_limit_for_dragging_tab.width());
|
||||
else if (event->pos().x() < boundary_limit_for_dragging_tab.x())
|
||||
pos.setX(boundary_limit_for_dragging_tab.x());
|
||||
QMouseEvent ev(event->type(), pos, event->globalPosition(), event->button(), event->buttons(), event->modifiers());
|
||||
QTabBar::mouseMoveEvent(&ev);
|
||||
}
|
||||
}
|
||||
|
||||
TabWidget::TabWidget(QWidget* parent)
|
||||
: QTabWidget(parent)
|
||||
{
|
||||
|
@ -28,6 +28,12 @@ public:
|
||||
|
||||
virtual QSize tabSizeHint(int index) const override;
|
||||
virtual void contextMenuEvent(QContextMenuEvent* event) override;
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void mouseMoveEvent(QMouseEvent*) override;
|
||||
|
||||
int m_x_position_in_selected_tab_while_dragging;
|
||||
};
|
||||
|
||||
class TabWidget : public QTabWidget {
|
||||
|
Loading…
Reference in New Issue
Block a user