int handleEvents(){ sf::Event event; while(_window.GetEvent(event)){ switch(event.Type) { case sf::Event::KeyPressed: switch(event.Key.Code){ case sf::Key::Escape: quit(); break; case sf::Key::Up: walk += move_step_increment; walk = std::min(walk, max_move_step); break; case sf::Key::Down: walk -= move_step_increment; walk = std::max(walk, .0); break; case sf::Key::Left: rotation += rotation_step_increment; rotation = std::min(rotation, max_rotation_step); break; case sf::Key::Right: rotation -= rotation_step_increment; rotation = std::max(rotation, -max_rotation_step); break; case sf::Key::Return: rotation = 0; walk = 0; break; case sf::Key::Q: range += 10; range = std::min(range, max_range); updateRangeSpriteScale(); break; case sf::Key::W: range -= 10; range = std::max(range, min_range); updateRangeSpriteScale(); break; default: break; } // end of key switch break; case sf::Event::MouseButtonPressed: if(event.MouseButton.Button == sf::Mouse::Left){ mouseLeftPressed(event.MouseButton.X, event.MouseButton.Y); } break; default: break; } // end of event type switch } // end of while return 0; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); calib_vs_vision = false; sql = new SQLite("../data/main.db", "passwd"); for(int i = 0 ; i < 8 ; i++){ colors.push_back(0); } image = new QCustomLabel(); image->setMouseTracking(true); QObject::connect(image, SIGNAL(Mouse_Pos()), this, SLOT(mouseCurrentPos())); QObject::connect(image, SIGNAL(Mouse_Left_Pressed()), this, SLOT(mouseLeftPressed())); QObject::connect(image, SIGNAL(Mouse_Right_Pressed()), this, SLOT(mouseRightPressed())); ui->layoutH2->addWidget(image); QObject::connect(&calib, SIGNAL(finished()), this, SLOT(quit())); calib.alloc_label_input(image); calib.alloc_calibration(&_calib); QObject::connect(&vi, SIGNAL(finished()), this, SLOT(quit())); vi.alloc_label_input(image); vi.alloc_calibration(&_calib); vi.alloc_state(&state); vi.alloc_colors(&colors); vi.alloc_execution_config(&execConfig); calib.start(); vi.start(); image->show(); coordinate_mouse = new QLabel("M(0, 0)"); mainItem = new QTreeWidgetItem; cmbCameraIds = new QComboBox(); cmbSavedImages = new QComboBox(); cmbSavedVideos = new QComboBox(); checkUseCamera = new QCheckBox(); checkUseImage = new QCheckBox(); checkUseVideo = new QCheckBox(); cmbColors = new QComboBox(); cmbBallColors = new QComboBox(); cmbMainColors_1 = new QComboBox(); cmbMainColors_2 = new QComboBox(); cmbSecColors_1 = new QComboBox(); cmbSecColors_2 = new QComboBox(); cmbSecColors_3 = new QComboBox(); cmbSecColors_4 = new QComboBox(); cmbSecColors_5 = new QComboBox(); cmbSecColors_6 = new QComboBox(); btnDoColorCalib = new QPushButton("Do", this); btnRunVision = new QPushButton("Run", this); blockdevice = QIcon(":icons/blockdevice.png"); ksame = QIcon(":icons/ksame.png"); kdf = QIcon(":icons/kdf.png"); package = QIcon(":icons/package.png"); getAllDevices(); buildTrees(); if(devices.size() < 1){ checkUseCamera->setChecked(false); checkUseImage->setChecked(true); checkUseVideo->setChecked(false); cmbCameraIds->setDisabled(true); }else{ checkUseCamera->setChecked(true); checkUseImage->setChecked(false); checkUseVideo->setChecked(false); } lblH = new QLabel("H (0 - 180)"); lblS = new QLabel("S (0 - 255)"); lblV = new QLabel("V (0 - 255)"); lbl_val = new QLabel("Pos\nVel\nKPos\nKVel"); val_ball = new QLabel("Ball"); val_robot1 = new QLabel("Robot 1"); val_robot2 = new QLabel("Robot 2"); val_robot3 = new QLabel("Robot 3"); val_robot4 = new QLabel("Robot 4"); val_robot5 = new QLabel("Robot 5"); val_robot6 = new QLabel("Robot 6"); h_val_ball = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n"); h_val_robot1 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n"); h_val_robot2 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n"); h_val_robot3 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n"); h_val_robot4 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n"); h_val_robot5 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n"); h_val_robot6 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n"); lbl_val->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;"); h_val_ball->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}"); h_val_robot1->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}"); h_val_robot2->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}"); h_val_robot3->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}"); h_val_robot4->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}"); h_val_robot5->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}"); h_val_robot6->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}"); sliderHmin = new QSlider(Qt::Orientation(VerticalTabs)); sliderHmax = new QSlider(Qt::Orientation(VerticalTabs)); sliderSmin = new QSlider(Qt::Orientation(VerticalTabs)); sliderSmax = new QSlider(Qt::Orientation(VerticalTabs)); sliderVmin = new QSlider(Qt::Orientation(VerticalTabs)); sliderVmax = new QSlider(Qt::Orientation(VerticalTabs)); sliderHmin->setMaximum(179); sliderSmin->setMaximum(254); sliderVmin->setMaximum(254); sliderHmax->setMaximum(180); sliderSmax->setMaximum(255); sliderVmax->setMaximum(255); sliderHmin->setMinimum(0); sliderSmin->setMinimum(0); sliderVmin->setMinimum(0); sliderHmax->setMinimum(1); sliderSmax->setMinimum(1); sliderVmax->setMinimum(1); sliderHmin->setMinimumHeight(140); sliderSmin->setMinimumHeight(140); sliderVmin->setMinimumHeight(140); sliderHmax->setMinimumHeight(140); sliderSmax->setMinimumHeight(140); sliderVmax->setMinimumHeight(140); sliderHmin->setValue(_calib.colors.at(0).min.rgb[h]); sliderSmin->setValue(_calib.colors.at(0).min.rgb[s]); sliderVmin->setValue(_calib.colors.at(0).min.rgb[v]); sliderHmax->setValue(_calib.colors.at(0).max.rgb[h]); sliderSmax->setValue(_calib.colors.at(0).max.rgb[s]); sliderVmax->setValue(_calib.colors.at(0).max.rgb[v]); connect(sliderHmin, SIGNAL(valueChanged(int)), this, SLOT(updateHmin(int))); connect(sliderSmin, SIGNAL(valueChanged(int)), this, SLOT(updateSmin(int))); connect(sliderVmin, SIGNAL(valueChanged(int)), this, SLOT(updateVmin(int))); connect(sliderHmax, SIGNAL(valueChanged(int)), this, SLOT(updateHmax(int))); connect(sliderSmax, SIGNAL(valueChanged(int)), this, SLOT(updateSmax(int))); connect(sliderVmax, SIGNAL(valueChanged(int)), this, SLOT(updateVmax(int))); updateValuesHSV(); update_hsv_s(); lblH->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-weight: bold;}"); lblS->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-weight: bold;}"); lblV->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-weight: bold;}"); sliderHmax->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0 #00f, stop: 0.167 #f0f, stop: 0.334 #f00, stop: 0.501 #ff0, stop: 0.668 #0f0, stop: 0.835 #0ff, stop: 1.0 #00f)}"); sliderHmin->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0 #00f, stop: 0.167 #f0f, stop: 0.334 #f00, stop: 0.501 #ff0, stop: 0.668 #0f0, stop: 0.835 #0ff, stop: 1.0 #00f)}"); sliderSmin->setStyleSheet(hsv_s.c_str()); sliderSmax->setStyleSheet(hsv_s.c_str()); sliderVmin->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #fff, stop: 1 #000)}"); sliderVmax->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #fff, stop: 1 #000)}"); ui->layoutH3->setContentsMargins(2, 0, 2, 0); ui->layoutH4->setContentsMargins(2, 0, 2, 0); ui->layoutH5->setContentsMargins(2, 0, 2, 0); ui->layoutH6->setContentsMargins(2, 0, 2, 0); ui->layoutH7->setContentsMargins(2, 0, 2, 0); ui->layoutH8->setContentsMargins(2, 0, 2, 0); ui->layoutH9->setContentsMargins(2, 0, 2, 0); ui->layoutH10->setContentsMargins(2, 0, 2, 0); }