mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01: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
|
|
@ -45,6 +45,39 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event)
|
||||||
tab->context_menu()->exec(event->globalPos());
|
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)
|
TabWidget::TabWidget(QWidget* parent)
|
||||||
: QTabWidget(parent)
|
: QTabWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ public:
|
||||||
|
|
||||||
virtual QSize tabSizeHint(int index) const override;
|
virtual QSize tabSizeHint(int index) const override;
|
||||||
virtual void contextMenuEvent(QContextMenuEvent* event) 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 {
|
class TabWidget : public QTabWidget {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user