Skip to content

Commit e7f2f88

Browse files
Merge pull request #29538 from mathesoncalum/460_porting_2
Porting more PRs to 4.6.0
2 parents 5893698 + c5e2b10 commit e7f2f88

3 files changed

Lines changed: 49 additions & 17 deletions

File tree

src/framework/dockwindow/internal/docktabbar.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,48 @@ bool DockTabBar::event(QEvent* event)
3737
doubleClicked(mouseEvent->pos());
3838
return true;
3939
}
40-
case QEvent::MouseButtonPress: {
41-
QQuickItem* tabBar = tabBarQmlItem();
42-
if (tabBar) {
43-
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
44-
QPoint localPos = mouseEvent->pos();
40+
case QEvent::MouseButtonPress:
41+
case QEvent::MouseButtonRelease: {
42+
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
43+
onMousePressRelease(mouseEvent);
44+
return true;
45+
}
46+
default:
47+
break;
48+
}
4549

46-
int tabIndex = tabAt(localPos);
47-
if (tabIndex < 0) {
48-
return true;
49-
}
50+
return KDDockWidgets::TabBarQuick::event(event);
51+
}
5052

51-
tabBar->setProperty("currentIndex", tabIndex);
52-
TabBar::onMousePress(localPos);
53-
}
53+
void DockTabBar::onMousePressRelease(const QMouseEvent* mouseEvent)
54+
{
55+
QQuickItem* tabBar = tabBarQmlItem();
56+
if (!mouseEvent || !tabBar) {
57+
return;
58+
}
59+
60+
const QPoint localPos = mouseEvent->pos();
61+
62+
int tabIndex = tabAt(localPos);
63+
if (tabIndex < 0) {
64+
return;
65+
}
5466

67+
switch (mouseEvent->type()) {
68+
case QEvent::MouseButtonPress: {
69+
m_indexOfPressedTab = tabIndex;
70+
TabBar::onMousePress(localPos);
5571
break;
5672
}
57-
default:
73+
case QEvent::MouseButtonRelease: {
74+
if (tabIndex == m_indexOfPressedTab) {
75+
tabBar->setProperty("currentIndex", tabIndex);
76+
}
77+
m_indexOfPressedTab = -1;
5878
break;
5979
}
60-
61-
return KDDockWidgets::TabBarQuick::event(event);
80+
default: UNREACHABLE;
81+
}
6282
}
6383

6484
void DockTabBar::doubleClicked(const QPoint& pos) const

src/framework/dockwindow/internal/docktabbar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ class DockTabBar : public KDDockWidgets::TabBarQuick
4040

4141
private:
4242
bool event(QEvent* event) override;
43+
void onMousePressRelease(const QMouseEvent* mouseEvent);
4344
bool isPositionDraggable(QPoint localPos) const override;
4445

4546
QQuickItem* m_draggableMouseArea = nullptr;
47+
int m_indexOfPressedTab = -1;
4648
};
4749
}
4850

src/framework/dockwindow/qml/Muse/Dock/DockFrame.qml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ Rectangle {
9595

9696
titleBarCpp: root.titleBarCpp
9797

98-
contextMenuModel: prv.tabsModel.data(prv.tabsModel.index(prv.currentIndex, 0), DockTabsModel.ContextMenu)
99-
10098
navigationPanel: navPanel
10199
navigationOrder: 1
102100

@@ -105,6 +103,18 @@ Rectangle {
105103
}
106104

107105
titleBarItem: frameModel.titleBar
106+
107+
function updateContextMenu() {
108+
const idx = prv.tabsModel.index(prv.currentIndex, 0);
109+
const menuModel = prv.tabsModel.data(idx, DockTabsModel.ContextMenu)
110+
titleBar.contextMenuModel = menuModel
111+
}
112+
113+
Connections {
114+
target: prv.tabsModel
115+
function onDataChanged() { titleBar.updateContextMenu() }
116+
function onModelReset() { titleBar.updateContextMenu() }
117+
}
108118
}
109119

110120
DockTabBar {

0 commit comments

Comments
 (0)