-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow_UI_Keyboard_Mouse.cpp
147 lines (119 loc) · 6.88 KB
/
mainwindow_UI_Keyboard_Mouse.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "mainwindow.h"
#include "ui_mainwindow.h"
void MainWindow::keyPressEvent(QKeyEvent *myKey)
{
if (myKey->key() == Qt::Key_Escape) this->close();
else if (myKey->key() == Qt::Key_L) on_myButton_Update_PATH_clicked();
///////
else if (isSequenceLoaded == false) return;
///////
else if (myKey->key() == Qt::Key_Left && !ctrl_key) on_myButton_Prev_clicked();
else if (myKey->key() == Qt::Key_Right && !ctrl_key) on_myButton_Next_clicked();
else if (myKey->key() == Qt::Key_Right && ctrl_key) move_joint(1);
else if (myKey->key() == Qt::Key_Left && ctrl_key) move_joint(2);
else if (myKey->key() == Qt::Key_Down && ctrl_key) move_joint(3);
else if (myKey->key() == Qt::Key_Up && ctrl_key) move_joint(4);
else if (myKey->key() == Qt::Key_U) on_myButton_UpdateFrameID_clicked();
else if (myKey->key() == Qt::Key_R) { ui->myRadioButton_Image_RGB-> setChecked(true); on_myRadioButton_Image_RGB_clicked(); }
else if (myKey->key() == Qt::Key_T) { ui->myRadioButton_Image_RGBD-> setChecked(true); on_myRadioButton_Image_RGBD_clicked(); }
else if (myKey->key() == Qt::Key_D) { ui->myRadioButton_Image_DepthVIZ-> setChecked(true); on_myRadioButton_Image_DepthVIZ_clicked(); }
//else if (myKey->key() == Qt::Key_F) { ui->myRadioButton_Image_DepthREAL->setChecked(true); on_myRadioButton_Image_DepthREAL_clicked(); }
else if (myKey->key() == Qt::Key_Backspace) on_myButton_ANNO_Clear_LAST_clicked();
else if (myKey->key() == Qt::Key_Delete) on_myButton_ANNO_Clear_ALL_clicked();
else if (myKey->key() == Qt::Key_Return) on_myButton_ANNO_Save_clicked();
else if (myKey->key() == Qt::Key_Control) ctrl_key = true;
else if (myKey->key() == Qt::Key_Shift) shift_key = true;
}
void MainWindow::keyReleaseEvent(QKeyEvent *myKey)
{
if (myKey->key() == Qt::Key_Control) ctrl_key = false;
else if (myKey->key() == Qt::Key_Shift) shift_key = false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MainWindow::wheelEvent(QWheelEvent* event){
if (ctrl_key){
rotate_joints(event->delta());
}
}
void MainWindow::Mouse_Pos()
{
ui->myLabel_Mouse_X->setText( QString::number( ui->myLabel_IMG->mouse_X ) );
ui->myLabel_Mouse_Y->setText( QString::number( ui->myLabel_IMG->mouse_Y ) );
if (ctrl_click || shift_click){
update_CURR_Display();
}
}
void MainWindow::Mouse_Pressed()
{
///////////////////////////////////////
if (isSequenceLoaded == false) return;
///////////////////////////////////////
if (!ctrl_key && !shift_key){
if ( (QApplication::mouseButtons() & Qt::LeftButton ) || (QApplication::mouseButtons() & Qt::RightButton ) )
{
//std::cout << "button" << std::endl;
annotations_ADD( ui->myLabel_IMG->mouse_X,
ui->myLabel_IMG->mouse_Y );
}
else if ( (QApplication::mouseButtons() & Qt::MiddleButton) )
{
//std::cout << "wheel" << std::endl;
annotations_ADD( 0, 0 );
}
} else {
if(ctrl_key)
ctrl_click = true;
if(shift_key)
shift_click = true;
selMouseX = ui->myLabel_IMG->mouse_X;
selMouseY = ui->myLabel_IMG->mouse_Y;
}
}
void MainWindow::Mouse_Release(){
if (ctrl_click || shift_click){
if (annotations.size() == 0)
return;
if (ctrl_click && !shift_key)
ui->fingerList->clearSelection();
if (abs(selMouseX-ui->myLabel_IMG->mouse_X) < 2 && abs(selMouseY-ui->myLabel_IMG->mouse_Y) < 2){
double best_dist = 999999999;
int best_id = -1;
// find the closest point to the clicked position
for(int i = 0; i < (int) annotations.size(); i++){
// calculate distance
double dist = sqrt(pow((double)ui->myLabel_IMG->mouse_X - annotations[i].joint_X,2) + pow((double)ui->myLabel_IMG->mouse_Y - annotations[i].joint_Y,2));
if (dist < best_dist){
best_id = i;
best_dist = dist;
}
}
// select the closest point
ui->fingerList->setCurrentRow(best_id, QItemSelectionModel::Toggle );
} else {
// create the selection box
cv::Rect rect(cv::Point(selMouseX, selMouseY), cv::Point(ui->myLabel_IMG->mouse_X, ui->myLabel_IMG->mouse_Y));
for(int i = 0; i < (int) annotations.size(); i++){
// check if it is inside the box
cv::Point current(roundToInt(annotations[i].joint_X), roundToInt(annotations[i].joint_Y));
if (current.inside(rect) ){
ui->fingerList->setCurrentRow(i, QItemSelectionModel::Select );
}
}
}
}
ctrl_click = false;
shift_click = false;
update_CURR_Display();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MainWindow::Mouse_Left(){} // Leaving the QLabel area !!!