mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-13 01:40:36 +00:00
UI/Qt: Don't allow tabs to be dragged past the new tab button
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
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 ✅
2 changed files with 39 additions and 0 deletions
|
@ -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 a new issue