MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); timer = new QTimer(); ui->glWidget->setMainWindow(this); /// Collision interpretation modes. ui->optionCollisionCombo->clear(); ui->optionCollisionCombo->addItem(tr("All collisions")); ui->optionCollisionCombo->addItem(tr("First collision")); ui->optionCollisionCombo->setCurrentIndex(0); /// Character shapes display options. ui->optionShowPlayerSolidCombo->clear(); ui->optionShowPlayerSolidCombo->addItem(tr("Hide")); ui->optionShowPlayerSolidCombo->addItem(tr("Wireframe")); ui->optionShowPlayerSolidCombo->addItem(tr("Fill")); ui->optionShowPlayerSolidCombo->setCurrentIndex(0); /// Object shapes display options. ui->optionShowObjectSolidCombo->clear(); ui->optionShowObjectSolidCombo->addItem(tr("Wireframe")); ui->optionShowObjectSolidCombo->addItem(tr("Fill")); ui->optionShowObjectSolidCombo->setCurrentIndex(0); /// Character shapes for physical model. ui->optionPlayerShapeCombo->clear(); ui->optionPlayerShapeCombo->addItem(tr("Point")); ui->optionPlayerShapeCombo->addItem(tr("Line segment")); ui->optionPlayerShapeCombo->addItem(tr("Triangle")); ui->optionPlayerShapeCombo->setCurrentIndex(1); /// Application logic criterias. ui->optionCriteriaCombo->clear(); ui->optionCriteriaCombo->addItem(tr("Consider all objects")); ui->optionCriteriaCombo->addItem(tr("Consider other than green objects")); ui->optionCriteriaCombo->addItem(tr("Consider green objects only")); ui->optionCriteriaCombo->setCurrentIndex(0); /// connections - comboboxes connect(ui->optionCollisionCombo,SIGNAL(currentIndexChanged(int)), this, SLOT(collisionModeChanged())); connect(ui->optionCriteriaCombo,SIGNAL(currentIndexChanged(int)), this, SLOT(collisionModeChanged())); connect(ui->optionShowPlayerSolidCombo,SIGNAL(currentIndexChanged(int)), this, SLOT(optionsFromGui())); connect(ui->optionShowObjectSolidCombo,SIGNAL(currentIndexChanged(int)), this, SLOT(optionsFromGui())); connect(ui->optionPlayerShapeCombo,SIGNAL(currentIndexChanged(int)), this, SLOT(collisionMeshChanged())); /// connections - buttons connect(ui->optionVectorCheck,SIGNAL(clicked()), this, SLOT(optionsFromGui())); connect(ui->optionPlaneCheck,SIGNAL(clicked()), this, SLOT(optionsFromGui())); connect(ui->playerPosCenterButton,SIGNAL(clicked()), this, SLOT(centerPlayer())); /// connections - edits connect(ui->playerPosXEdit,SIGNAL(textChanged(QString)), this, SLOT(playerPosFromGui())); connect(ui->playerPosYEdit,SIGNAL(textChanged(QString)), this, SLOT(playerPosFromGui())); connect(ui->playerPosZEdit,SIGNAL(textChanged(QString)), this, SLOT(playerPosFromGui())); connect(ui->playerPosRadEdit,SIGNAL(valueChanged(double)), this, SLOT(playerPosFromGui())); connect(ui->optionVectorLengthEdit,SIGNAL(valueChanged(double)), this, SLOT(playerPosFromGui())); connect(ui->optionVectorBackEdit,SIGNAL(valueChanged(double)), this, SLOT(playerPosFromGui())); /// connections - menu actions connect(ui->actionExit,SIGNAL(triggered()), this, SLOT(close())); connect(ui->actionAbout,SIGNAL(triggered()), this, SLOT(about())); connect(ui->actionAboutQt,SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(ui->actionLoad,SIGNAL(triggered()), this, SLOT(loadSituation())); connect(ui->actionSave,SIGNAL(triggered()), this, SLOT(saveSituation())); connect(ui->actionCaptureSituation,SIGNAL(triggered()), this, SLOT(captureSituation())); connect(ui->actionPlaySequence,SIGNAL(triggered()), this, SLOT(playSequence())); connect(ui->actionToFirstSituation,SIGNAL(triggered()), this, SLOT(toFirstSituation())); connect(ui->actionNextSituation,SIGNAL(triggered()), this, SLOT(nextSituation())); connect(ui->actionPreviousSituation,SIGNAL(triggered()), this, SLOT(previousSituation())); /// connections - timer timeout connect(timer, SIGNAL(timeout()), this, SLOT(sequenceTimeout())); /// connections - from glWidget connect(ui->glWidget, SIGNAL(playerPosChanged()), this, SLOT(playerPosToGui())); connect(ui->glWidget, SIGNAL(glInitialized()), this, SLOT(collisionModeChanged())); ui->collisionTree->header()->resizeSections(QHeaderView::ResizeToContents); optionsFromGui(); }
FieldWidget::FieldWidget(QWidget *parent) : QGraphicsView(parent), m_geometryUpdated(true), m_rotation(0.0f), m_worldStateUpdated(false), m_visualizationsUpdated(false), m_hasTouchInput(false), m_dragType(DragNone), m_dragItem(NULL) { m_touchStatusType = QGestureRecognizer::registerRecognizer(new TouchStatusRecognizer); grabGesture(m_touchStatusType); grabGesture(Qt::PanGesture); grabGesture(Qt::PinchGesture); geometrySetDefault(&m_geometry); // setup context menu m_contextMenu = new QMenu(this); QAction *actionHorizontal = m_contextMenu->addAction("Horizontal"); connect(actionHorizontal, SIGNAL(triggered()), SLOT(setHorizontal())); QAction *actionVertical = m_contextMenu->addAction("Vertical"); connect(actionVertical, SIGNAL(triggered()), SLOT(setVertical())); QAction *actionFlip = m_contextMenu->addAction("Flip"); connect(actionFlip, SIGNAL(triggered()), SLOT(flip())); m_contextMenu->addSeparator(); // add actions to allow hiding visualizations of a team m_actionShowBlueVis = m_contextMenu->addAction("Show blue visualizations"); m_actionShowBlueVis->setCheckable(true); m_actionShowBlueVis->setChecked(true); connect(m_actionShowBlueVis, SIGNAL(triggered()), SLOT(updateVisualizationVisibility())); m_actionShowYellowVis = m_contextMenu->addAction("Show yellow visualizations"); m_actionShowYellowVis->setCheckable(true); m_actionShowYellowVis->setChecked(true); connect(m_actionShowYellowVis, SIGNAL(triggered()), SLOT(updateVisualizationVisibility())); m_actionShowControllerVis = m_contextMenu->addAction("Show controller visualizations"); m_actionShowControllerVis->setCheckable(true); m_actionShowControllerVis->setChecked(true); connect(m_actionShowControllerVis, SIGNAL(triggered()), SLOT(updateVisualizationVisibility())); updateVisualizationVisibility(); // update the visibility map m_contextMenu->addSeparator(); // other actions QAction *actionShowAOI = m_contextMenu->addAction("Enable custom vision area"); actionShowAOI->setCheckable(true); connect(actionShowAOI, SIGNAL(toggled(bool)), SLOT(setAOIVisible(bool))); m_actionAntialiasing = m_contextMenu->addAction("Anti-aliasing"); m_actionAntialiasing->setCheckable(true); connect(m_actionAntialiasing, SIGNAL(toggled(bool)), SLOT(setAntialiasing(bool))); m_actionGL = m_contextMenu->addAction("OpenGL"); m_actionGL->setCheckable(true); connect(m_actionGL, SIGNAL(toggled(bool)), SLOT(setOpenGL(bool))); m_contextMenu->addSeparator(); QAction *actionScreenshot = m_contextMenu->addAction("Take screenshot"); connect(actionScreenshot, SIGNAL(triggered()), SLOT(takeScreenshot())); QAction *actionSaveSituation = m_contextMenu->addAction("Save Situation"); connect(actionSaveSituation, SIGNAL(triggered()), SLOT(saveSituation())); // create graphics scene m_scene = new QGraphicsScene(this); setScene(m_scene); // ball object const float ballRadius = 0.02133f; m_ball = new QGraphicsEllipseItem; m_ball->setPen(Qt::NoPen); m_ball->setBrush(QColor(255, 66, 0)); m_ball->setZValue(100.0f); m_ball->setRect(QRectF(-ballRadius, -ballRadius, ballRadius * 2.0f, ballRadius * 2.0f)); m_ball->hide(); m_scene->addItem(m_ball); // rectangle for area of interest m_aoiItem = new QGraphicsPathItem; m_aoiItem->setPen(Qt::NoPen); m_aoiItem->setBrush(QColor(0, 0, 0, 128)); m_aoiItem->setZValue(10000.0f); m_aoiItem->hide(); m_scene->addItem(m_aoiItem); m_aoi = QRectF(-1, -1, 2, 2); updateAOI(); m_scene->setBackgroundBrush(Qt::black); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); // should improve the performance setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // transforms are centered on the mouse cursor setTransformationAnchor(QGraphicsView::NoAnchor); setOptimizationFlag(QGraphicsView::DontSavePainterState); setCacheMode(QGraphicsView::CacheBackground); setHorizontal(); // view update timer QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), SLOT(updateAll())); timer->start(30); setMouseTracking(true); // create label to show field coordinates m_lblMousePos = new QLabel(this); m_lblMousePos->setAutoFillBackground(true); // solid background // draw frame m_lblMousePos->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); m_lblMousePos->setMargin(2); // some space m_lblMousePos->hide(); // ensure that the label is hidden on startup // load settings QSettings s; s.beginGroup("Field"); m_actionGL->setChecked(s.value("OpenGL").toBool()); m_actionAntialiasing->setChecked(s.value("AntiAliasing").toBool()); s.endGroup(); }