mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 09:21:57 -05: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 (cherry picked from commit 9b79081a0601ef6649592acc1025b12c52e63d5c)
This commit is contained in:
parent
8d56f0ed15
commit
2b84c92566
2 changed files with 39 additions and 0 deletions
|
@ -41,6 +41,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 a new issue