-
Notifications
You must be signed in to change notification settings - Fork 41
/
MyTabBar.cpp
51 lines (39 loc) · 1.24 KB
/
MyTabBar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "MyTabBar.h"
#include <QApplication>
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
#include "editortabswidget.h"
extern QString dragFileName;
extern EditorTabsWidget* tabWidget;
MyTabBar::MyTabBar(QWidget* parent) : QTabBar(parent) {
setAttribute(Qt::WA_StyledBackground);
setMovable(true);
setTabsClosable(true);
}
void MyTabBar::mousePressEvent(QMouseEvent* event) {
QTabBar::mousePressEvent(event);
if (event->button() == Qt::LeftButton && currentIndex() >= 0) {
theDragPress = true;
dragFileName = tabWidget->getCurentTab()->getPath();
}
}
void MyTabBar::mouseMoveEvent(QMouseEvent* event) {
QTabBar::mouseMoveEvent(event);
if (theDragPress && event->buttons()) {
//是否脱离了tabbar的范围
if (!theDragOut && !contentsRect().contains(event->pos())) {
theDragOut = true;
emit beginDragOut(this->currentIndex());
QMouseEvent* e = new QMouseEvent(
QEvent::MouseButtonRelease, this->mapFromGlobal(QCursor::pos()),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QApplication::postEvent(this, e);
}
}
}
void MyTabBar::mouseReleaseEvent(QMouseEvent* event) {
QTabBar::mouseReleaseEvent(event);
theDragPress = false;
theDragOut = false;
}