void pTabBar::mousePressEvent( QMouseEvent* event ) { // reset drag position dragStartPosition = QPoint(); // get tab under cursor int i = tabAt( event->pos() ); // if tab if ( i != -1 ) { // emit left button pressed if ( event->button() == Qt::LeftButton ) emit leftButtonPressed( i, event->globalPos() ); // emit mid button pressed if ( event->button() == Qt::MidButton ) emit midButtonPressed( i, event->globalPos() ); // emit right button pressed and drag position if ( event->button() == Qt::RightButton ) { emit rightButtonPressed( i, event->globalPos() ); dragStartPosition = event->pos(); } } // default event QTabBar::mousePressEvent( event ); }
QWidget *CentralWidget::createCmdWidget() { joystick = new JoystickButton; connect(joystick, SIGNAL(upButtonPressed()), this, SLOT(slotCarDirectCmd())); connect(joystick, SIGNAL(upButtonReleased()), this, SLOT(slotCarStopCmd())); connect(joystick, SIGNAL(downButtonPressed()), this, SLOT(slotCarReverseCmd())); connect(joystick, SIGNAL(downButtonReleased()), this, SLOT(slotCarStopCmd())); connect(joystick, SIGNAL(rightButtonPressed()), this, SLOT(slotCarRightCmd())); connect(joystick, SIGNAL(rightButtonReleased()), this, SLOT(slotCarStopCmd())); connect(joystick, SIGNAL(leftButtonPressed()), this, SLOT(slotCarLeftCmd())); connect(joystick, SIGNAL(leftButtonReleased()), this, SLOT(slotCarStopCmd())); connect(joystick, SIGNAL(centerButtonPressed()), this, SLOT(slotCarStopCmd())); return joystick; }
void ClickableImage::mousePressEvent(QMouseEvent *eve ) { if ( eve->button() == Qt::LeftButton ) emit leftButtonPressed(this); else if ( eve->button() == Qt::RightButton ) emit rightButtonPressed(this); else if ( eve->button() == Qt::MidButton ) emit middleButtonPressed(this); }
MyMessageBox::MyMessageBox(QWidget *_widget,QString _title, QString _content): MyMessagePanel(_widget),Title(_title),Content(_content) { QRect rect = _widget->rect(); this->setGeometry(rect.width()/4,rect.height()/4,rect.width()/2,rect.height()/3); titleLabel = new QLabel(Title,this); contentLabel = new QLabel(Content,this); leftButton = new QPushButton("Retry",this); rightButton = new QPushButton("Next",this); Initialize(); connect(leftButton,SIGNAL(clicked(bool)),this,SLOT(leftButtonClicked())); connect(rightButton,SIGNAL(clicked(bool)),this,SLOT(rightButtonClicked())); connect(leftButton,SIGNAL(pressed()),this,SLOT(leftButtonPressed())); connect(rightButton,SIGNAL(pressed()),this,SLOT(rightButtonPressed())); connect(leftButton,SIGNAL(released()),this,SLOT(leftButtonReleased())); connect(rightButton,SIGNAL(released()),this,SLOT(rightButtonReleased())); }
void moveMouse() { // gesture analysis barycBufferX[barycBufferIndex] = barycX; barycBufferY[barycBufferIndex] = barycY; barycBufferZ[barycBufferIndex] = barycZ; barycBufferIndex = (barycBufferIndex + 1) % HAND_POS_BUFFER_SIZE; if (isOpenHand) { int prevBarycBufferIndex = (barycBufferIndex > 0) ? barycBufferIndex-1 : HAND_POS_BUFFER_SIZE-1; int countX = -round((barycBufferX[barycBufferIndex] - barycBufferX[prevBarycBufferIndex]) * 600); int countY = round((barycBufferY[barycBufferIndex] - barycBufferY[prevBarycBufferIndex]) * 600); verticalScroll(countX, countY); printf("Scrolling > countX: %d\n", countX); return; } double meanBarycX = 0; double meanBarycY = 0; double meanBarycZ = 0; int i; for (i=0; i<HAND_POS_BUFFER_SIZE; i++) { meanBarycX += barycBufferX[i] / HAND_POS_BUFFER_SIZE; meanBarycY += barycBufferY[i] / HAND_POS_BUFFER_SIZE; meanBarycZ += barycBufferZ[i] / HAND_POS_BUFFER_SIZE; } mousePosX = round(-meanBarycX * 1280 + 640); mousePosY = round(meanBarycY * 1280 + 400); if (leftButtonState == MOUSE_CLICK_UP && normVecY < -0.45) { leftButtonPressed(mousePosX, mousePosY); leftButtonState = MOUSE_CLICK_DOWN; printf("Mouse click left down\n"); } else if (leftButtonState == MOUSE_CLICK_DOWN && normVecY >= -0.45 ) { leftButtonReleased(mousePosX, mousePosY); leftButtonState = MOUSE_CLICK_UP; printf("Mouse click left up\n"); } else if (rightButtonState == MOUSE_CLICK_UP && normVecX < -0.5) { rightButtonPressed(mousePosX, mousePosY); rightButtonState = MOUSE_CLICK_DOWN; printf("Mouse click right down\n"); } else if (rightButtonState == MOUSE_CLICK_DOWN && normVecX >= -0.5 ) { rightButtonReleased(mousePosX, mousePosY); rightButtonState = MOUSE_CLICK_UP; printf("Mouse click right up\n"); } else { moveCursor(mousePosX, mousePosY); } }