void ControllerAnnotations::mousePressEvent(QMouseEvent *event, const QPoint &pos) { // left-click: add annotation in pos or try start dragging annotation if (event->button() == Qt::LeftButton) { auto model = static_cast<Annotations*>(getModel()); bool handled = true; switch (actionQueued) { case ActionQueued::CreateArrow: model->startArrow(pos, model->getCurrentFrame()); break; case ActionQueued::CreateLabel: model->startLabel(pos, model->getCurrentFrame()); break; case ActionQueued::CreateRect: model->startRect(pos, model->getCurrentFrame()); break; case ActionQueued::CreateEllipse: model->startEllipse(pos, model->getCurrentFrame()); break; default: if (model->tryStartDragging(pos)) { updateView(); } else { handled = false; } updateView(); break; } if (handled) event->accept(); actionQueued = ActionQueued::None; } // right-click: set text for annotation in pos else if (event->button() == Qt::RightButton) { auto model = static_cast<Annotations*>(getModel()); bool handled = true; if (model->trySetText(pos)) { updateView(); } else { handled = false; } if (handled) { event->accept(); } } }
QvisRotationTransition::QvisRotationTransition(const QPixmap &pix, QWidget *parent) : QGroupBox(parent) { QVBoxLayout *innerLayout = new QVBoxLayout(this); innerLayout->setMargin(10); innerLayout->addSpacing(15); // Add the pixmap here. QLabel *pixLabel = new QLabel(this); pixLabel->setPixmap(pix); innerLayout->addWidget(pixLabel); innerLayout->addSpacing(15); QHBoxLayout *hLayout = new QHBoxLayout(0); innerLayout->addLayout(hLayout); QGridLayout *gLayout = new QGridLayout(0); hLayout->addLayout(gLayout); gLayout->setSpacing(10); hLayout->addStretch(10); // Angle controls. startAngle = new QSpinBox(this); startAngle->setMinimum(-360 * 100); startAngle->setMaximum(360 * 100); startAngle->setValue(0); QString deg; deg.sprintf("%c", 176); QString startLabel(tr("Start angle") + deg); gLayout->addWidget( new QLabel(startLabel, this), 0, 0); gLayout->addWidget(startAngle, 0, 1); endAngle = new QSpinBox(this); endAngle->setMinimum(-360 * 100); endAngle->setMaximum(360 * 100); endAngle->setValue(360); QString endLabel(tr("End angle") +deg); gLayout->addWidget( new QLabel(endLabel, this), 1, 0); gLayout->addWidget(endAngle, 1, 1); // Number of steps controls. nSteps = new QSpinBox(this); nSteps->setMinimum(1); nSteps->setValue(30); gLayout->addWidget( new QLabel(tr("Number of steps"), this), 2, 0); gLayout->addWidget(nSteps, 2, 1); innerLayout->addStretch(10); }
int autograderGraphicalMain(int argc, char** argv) { GWindow gui(500, 300, /* visible */ false); gui.setTitle(STATIC_VARIABLE(FLAGS).assignmentName + " Autograder"); gui.setCanvasSize(0, 0); gui.setExitOnClose(true); GLabel startLabel(""); if (!STATIC_VARIABLE(FLAGS).startMessage.empty()) { std::string startMessage = STATIC_VARIABLE(FLAGS).startMessage; if (!stringContains(startMessage, "<html>")) { startMessage = stringReplace(startMessage, "Note:", "<b>Note:</b>"); startMessage = stringReplace(startMessage, "NOTE:", "<b>NOTE:</b>"); startMessage = "<html><body style='width: 500px; max-width: 500px;'>" + startMessage + "</body></html>"; } startLabel.setLabel(startMessage); gui.addToRegion(&startLabel, "NORTH"); } std::string autogradeText = addAutograderButton(gui, "Automated\ntests", "check.gif"); std::string manualText = addAutograderButton(gui, "Run\nmanually", "play.gif"); std::string styleCheckText = addAutograderButton(gui, "Style\nchecker", "magnifier.gif"); for (int i = 0; i < STATIC_VARIABLE(FLAGS).callbackButtons.size(); i++) { STATIC_VARIABLE(FLAGS).callbackButtons[i].text = addAutograderButton(gui, STATIC_VARIABLE(FLAGS).callbackButtons[i].text, STATIC_VARIABLE(FLAGS).callbackButtons[i].icon); } std::string lateDayText = addAutograderButton(gui, "Late days\ninfo", "calendar.gif"); std::string aboutText = addAutograderButton(gui, "About\nGrader", "help.gif"); std::string exitText = addAutograderButton(gui, "Exit\nGrader", "stop.gif"); gui.pack(); gui.setVisible(true); int result = 0; while (true) { GEvent event = waitForEvent(ACTION_EVENT); if (event.getEventClass() == ACTION_EVENT) { GActionEvent actionEvent(event); std::string cmd = actionEvent.getActionCommand(); if (cmd == autogradeText) { if (STATIC_VARIABLE(FLAGS).callbackStart) { STATIC_VARIABLE(FLAGS).callbackStart(); } // stanfordcpplib::getPlatform()->autograderunittest_clearTests(); stanfordcpplib::getPlatform()->autograderunittest_clearTestResults(); stanfordcpplib::getPlatform()->autograderunittest_setTestingCompleted(false); stanfordcpplib::getPlatform()->autograderunittest_setVisible(true); result = mainRunAutograderTestCases(argc, argv); stanfordcpplib::getPlatform()->autograderunittest_setTestingCompleted(true); // if style checker is merged, also run it now if (stylecheck::isStyleCheckMergedWithUnitTests()) { mainRunStyleChecker(); } if (STATIC_VARIABLE(FLAGS).callbackEnd) { STATIC_VARIABLE(FLAGS).callbackEnd(); } } else if (cmd == manualText) { // set up buttons to automatically enter user input if (STATIC_VARIABLE(FLAGS).showInputPanel) { inputpanel::load(STATIC_VARIABLE(FLAGS).inputPanelFilename); } // actually run the student's program // (While program is running, if we close console, exit entire // autograder program because we might be blocked on console I/O. // But after it's done running, set behavior to just hide the // console, since the grader will probably try to close it and then // proceed with more grading and tests afterward. // A little wonky, but it avoids most of the surprise cases of // "I closed the student's console and it killed the autograder". stanfordcpplib::getPlatform()->jbeconsole_clear(); stanfordcpplib::getPlatform()->jbeconsole_setVisible(true); stanfordcpplib::getPlatform()->jbeconsole_toFront(); // setConsoleCloseOperation(ConsoleCloseOperation::CONSOLE_EXIT_ON_CLOSE); autograder::setExitEnabled(false); // block exit() call setConsoleCloseOperation(ConsoleCloseOperation::CONSOLE_HIDE_ON_CLOSE); studentMain(); // gwindowSetExitGraphicsEnabled(true); } else if (cmd == styleCheckText) { mainRunStyleChecker(); } else if (cmd == lateDayText) { showLateDays(); } else if (cmd == aboutText) { GOptionPane::showMessageDialog(STATIC_VARIABLE(FLAGS).aboutText, "About Autograder", GOptionPane::MessageType::INFORMATION); } else if (cmd == exitText) { autograder::setExitEnabled(true); // don't block exit() call // free up memory used by graphical interactors for (GButton* button : STATIC_VARIABLE(AUTOGRADER_BUTTONS)) { delete button; } STATIC_VARIABLE(AUTOGRADER_BUTTONS).clear(); gui.close(); // exits program; will not return break; } else { for (CallbackButtonInfo buttonInfo : STATIC_VARIABLE(FLAGS).callbackButtons) { if (cmd == buttonInfo.text) { buttonInfo.func(); break; } } } } } // free up memory used by graphical interactors for (GButton* button : STATIC_VARIABLE(AUTOGRADER_BUTTONS)) { delete button; } STATIC_VARIABLE(AUTOGRADER_BUTTONS).clear(); return result; }