-
Notifications
You must be signed in to change notification settings - Fork 0
/
horizontalheaderview.cpp
60 lines (48 loc) · 1.68 KB
/
horizontalheaderview.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
52
53
54
55
56
57
58
59
60
#include "horizontalheaderview.h"
#include "maintablewidget.h"
#include <QDropEvent>
#include <QMouseEvent>
HorizontalHeaderView::HorizontalHeaderView(MainTableWidget* m_pTableWidget, QWidget *parent) :
QHeaderView(Qt::Horizontal, parent)
{
this->m_tableWidget = m_pTableWidget;
this->pressedPoint = QPoint(0,0);
this->setMouseTracking(false);
this->blackedOutCols = 1;
this->pressedLogicalIndex = this->pressedVisualIndex = 0;
}
HorizontalHeaderView::~HorizontalHeaderView()
{
}
void HorizontalHeaderView::mousePressEvent(QMouseEvent *event)
{
this->pressedPoint = event->pos();
this->pressedLogicalIndex = this->logicalIndexAt(event->pos());
this->pressedVisualIndex = this->visualIndex(this->pressedLogicalIndex);
QHeaderView::mousePressEvent(event);
}
void HorizontalHeaderView::mouseReleaseEvent(QMouseEvent *event)
{
QHeaderView::mouseReleaseEvent(event);
if(event->pos() != this->pressedPoint)
{
int toVisualIndex = this->visualIndex(this->pressedLogicalIndex);
if(toVisualIndex < this->blackedOutCols)
{
this->m_tableWidget->horizontalHeader()->moveSection(toVisualIndex, this->blackedOutCols);
toVisualIndex = this->blackedOutCols;
}
if(this->pressedVisualIndex < this->blackedOutCols)
{
this->m_tableWidget->horizontalHeader()->moveSection(toVisualIndex, this->pressedVisualIndex);
return;
}
emit teacherMoved(this->pressedVisualIndex, toVisualIndex);
}
}
void HorizontalHeaderView::mouseMoveEvent(QMouseEvent *event)
{
if(pressedVisualIndex < this->blackedOutCols)
return;
QHeaderView::mouseMoveEvent(event);
}