1 #include <QMediaPlayer>
3 #include <QApplication>
7 #include <QInputDialog>
15 #include "mainwindow.h"
16 #include "ui_mainwindow.h"
19 #include "formations.h"
21 #include "video_widget.h"
25 string format_timestamp(uint64_t pos)
35 snprintf(buf, sizeof(buf), "%d:%02d:%02d.%03d", hour, min, sec, ms);
39 string get_video_filename(sqlite3 *db, int match_id)
43 int ret = sqlite3_prepare_v2(db, "SELECT video_filename FROM match WHERE match=?", -1, &stmt, 0);
44 if (ret != SQLITE_OK) {
45 fprintf(stderr, "SELECT prepare: %s\n", sqlite3_errmsg(db));
49 sqlite3_bind_int64(stmt, 1, match_id);
51 ret = sqlite3_step(stmt);
52 if (ret != SQLITE_ROW) {
53 fprintf(stderr, "SELECT step: %s\n", sqlite3_errmsg(db));
57 if (sqlite3_column_type(stmt, 0) != SQLITE_TEXT) {
60 string filename = (const char *)sqlite3_column_text(stmt, 0);
62 ret = sqlite3_finalize(stmt);
63 if (ret != SQLITE_OK) {
64 fprintf(stderr, "SELECT finalize: %s\n", sqlite3_errmsg(db));
70 bool get_match_property(sqlite3 *db, int match_id, const string &prop_name)
74 int ret = sqlite3_prepare_v2(db, ("SELECT " + prop_name + " FROM match WHERE match=?").c_str(), -1, &stmt, 0);
75 if (ret != SQLITE_OK) {
76 fprintf(stderr, "SELECT prepare: %s\n", sqlite3_errmsg(db));
80 sqlite3_bind_int64(stmt, 1, match_id);
82 ret = sqlite3_step(stmt);
83 if (ret != SQLITE_ROW) {
84 fprintf(stderr, "SELECT step: %s\n", sqlite3_errmsg(db));
88 if (sqlite3_column_type(stmt, 0) != SQLITE_INTEGER) {
91 bool value = sqlite3_column_int(stmt, 0);
93 ret = sqlite3_finalize(stmt);
94 if (ret != SQLITE_OK) {
95 fprintf(stderr, "SELECT finalize: %s\n", sqlite3_errmsg(db));
101 void save_video_filename(sqlite3 *db, int match_id, const string &filename)
105 int ret = sqlite3_prepare_v2(db, "UPDATE match SET video_filename=? WHERE match=?", -1, &stmt, 0);
106 if (ret != SQLITE_OK) {
107 fprintf(stderr, "SELECT prepare: %s\n", sqlite3_errmsg(db));
111 sqlite3_bind_text(stmt, 1, filename.data(), filename.size(), SQLITE_STATIC);
112 sqlite3_bind_int64(stmt, 2, match_id);
114 ret = sqlite3_step(stmt);
115 if (ret == SQLITE_ROW) {
116 fprintf(stderr, "UPDATE step: %s\n", sqlite3_errmsg(db));
120 ret = sqlite3_finalize(stmt);
121 if (ret != SQLITE_OK) {
122 fprintf(stderr, "SELECT finalize: %s\n", sqlite3_errmsg(db));
127 void save_match_property(sqlite3 *db, int match_id, const string &prop_name, bool value)
131 int ret = sqlite3_prepare_v2(db, ("UPDATE match SET " + prop_name + "=? WHERE match=?").c_str(), -1, &stmt, 0);
132 if (ret != SQLITE_OK) {
133 fprintf(stderr, "SELECT prepare: %s\n", sqlite3_errmsg(db));
137 sqlite3_bind_int64(stmt, 1, value);
138 sqlite3_bind_int64(stmt, 2, match_id);
140 ret = sqlite3_step(stmt);
141 if (ret == SQLITE_ROW) {
142 fprintf(stderr, "UPDATE step: %s\n", sqlite3_errmsg(db));
146 ret = sqlite3_finalize(stmt);
147 if (ret != SQLITE_OK) {
148 fprintf(stderr, "SELECT finalize: %s\n", sqlite3_errmsg(db));
153 MainWindow::MainWindow(EventsModel *events, PlayersModel *players,
154 FormationsModel *offensive_formations, FormationsModel *defensive_formations,
155 sqlite3 *db, int match_id)
156 : events(events), players(players), offensive_formations(offensive_formations), defensive_formations(defensive_formations), db(db), match_id(match_id)
158 ui = new Ui::MainWindow;
161 string filename = get_video_filename(db, match_id);
162 bool need_save_filename = false;
164 if (!filename.empty() && ui->video->open(filename.c_str())) {
168 // TODO: Probably relativize this path, so that we can move the .db
169 // more easily with the videos.
170 filename = QFileDialog::getOpenFileName(this, "Open video").toUtf8();
171 need_save_filename = true;
173 if (need_save_filename) {
174 save_video_filename(db, match_id, filename);
178 ui->event_view->setModel(events);
179 ui->event_view->setColumnWidth(1, 150);
180 ui->event_view->setColumnWidth(2, 150);
181 connect(ui->event_view->selectionModel(), &QItemSelectionModel::currentRowChanged,
182 [this, events](const QModelIndex ¤t, const QModelIndex &previous) {
183 uint64_t t = events->get_time(current.row());
184 if (t != ui->video->get_position()) {
185 ui->video->seek_absolute(events->get_time(current.row()));
187 // Selection could have changed, so we still need to update.
188 // (Just calling setPosition() would not give us the signal
190 update_ui_from_time(t);
194 ui->player_view->setModel(players);
195 ui->player_view->setColumnWidth(0, 30);
196 ui->player_view->setColumnWidth(1, 20);
197 ui->player_view->horizontalHeader()->setStretchLastSection(true);
199 auto formation_changed = [this](const QModelIndex ¤t, const QModelIndex &previous) {
200 QTimer::singleShot(1, [=]{ // The selection is wrong until the callback actually returns.
201 update_action_buttons(ui->video->get_position());
204 ui->offensive_formation_view->setModel(offensive_formations);
205 ui->defensive_formation_view->setModel(defensive_formations);
206 connect(ui->offensive_formation_view->selectionModel(), &QItemSelectionModel::currentRowChanged, formation_changed);
207 connect(ui->defensive_formation_view->selectionModel(), &QItemSelectionModel::currentRowChanged, formation_changed);
208 connect(ui->offensive_formation_view, &QListView::doubleClicked, [this](const QModelIndex &index) {
209 formation_double_clicked(true, index.row());
211 connect(ui->defensive_formation_view, &QListView::doubleClicked, [this](const QModelIndex &index) {
212 formation_double_clicked(false, index.row());
215 connect(ui->video, &VideoWidget::position_changed, [this](uint64_t pos) {
216 position_changed(pos);
219 // It's not really clear whether PgUp should be forwards or backwards,
220 // but mpv does at least up = forwards, so that's probably standard.
221 QShortcut *pgdown = new QShortcut(QKeySequence(Qt::Key_PageDown), this);
222 connect(pgdown, &QShortcut::activated, [this]() { ui->video->seek(-120000); });
223 QShortcut *pgup = new QShortcut(QKeySequence(Qt::Key_PageUp), this);
224 connect(pgup, &QShortcut::activated, [this]() { ui->video->seek(120000); });
226 connect(ui->minus10s, &QPushButton::clicked, [this]() { ui->video->seek(-10000); });
227 connect(ui->plus10s, &QPushButton::clicked, [this]() { ui->video->seek(10000); });
229 connect(ui->minus2s, &QPushButton::clicked, [this]() { ui->video->seek(-2000); });
230 connect(ui->plus2s, &QPushButton::clicked, [this]() { ui->video->seek(2000); });
231 connect(ui->video, &VideoWidget::mouse_back_clicked, [this]() { ui->video->seek(-2000); });
232 connect(ui->video, &VideoWidget::mouse_forward_clicked, [this]() { ui->video->seek(2000); });
234 connect(ui->minus1f, &QPushButton::clicked, [this]() { ui->video->seek_frames(-1); });
235 connect(ui->plus1f, &QPushButton::clicked, [this]() { ui->video->seek_frames(1); });
237 connect(ui->play_pause, &QPushButton::clicked, [this]() {
240 ui->play_pause->setText("Play (space)");
243 ui->play_pause->setText("Pause (space)");
247 // Needs to be set anew when we modify setText(), evidently.
248 ui->play_pause->setShortcut(QCoreApplication::translate("MainWindow", "Space", nullptr));
251 connect(ui->player_1, &QPushButton::clicked, [this]() { insert_player_event(0); });
252 connect(ui->player_2, &QPushButton::clicked, [this]() { insert_player_event(1); });
253 connect(ui->player_3, &QPushButton::clicked, [this]() { insert_player_event(2); });
254 connect(ui->player_4, &QPushButton::clicked, [this]() { insert_player_event(3); });
255 connect(ui->player_5, &QPushButton::clicked, [this]() { insert_player_event(4); });
256 connect(ui->player_6, &QPushButton::clicked, [this]() { insert_player_event(5); });
257 connect(ui->player_7, &QPushButton::clicked, [this]() { insert_player_event(6); });
260 connect(ui->offense_label, &ClickableLabel::clicked, [this]() { insert_noplayer_event("set_offense"); });
261 connect(ui->catch_, &QPushButton::clicked, [this]() { set_current_event_type("catch"); });
262 connect(ui->throwaway, &QPushButton::clicked, [this, events]() {
263 EventsModel::Status s = events->get_status_at(ui->video->get_position());
264 if (s.attack_state == EventsModel::Status::DEFENSE && s.pull_state == EventsModel::Status::PULL_IN_AIR) {
265 insert_noplayer_event("pull_oob");
267 set_current_event_type("throwaway");
270 connect(ui->drop, &QPushButton::clicked, [this]() { set_current_event_type("drop"); });
271 connect(ui->goal, &QPushButton::clicked, [this]() { set_current_event_type("goal"); });
272 connect(ui->stallout, &QPushButton::clicked, [this]() { set_current_event_type("stallout"); });
273 connect(ui->soft_plus, &QPushButton::clicked, [this, events]() {
274 EventsModel::Status s = events->get_status_at(ui->video->get_position());
275 if (s.attack_state == EventsModel::Status::OFFENSE) {
276 set_current_event_type("offensive_soft_plus");
277 } else if (s.attack_state == EventsModel::Status::DEFENSE) {
278 set_current_event_type("defensive_soft_plus");
281 connect(ui->soft_minus, &QPushButton::clicked, [this, events]() {
282 EventsModel::Status s = events->get_status_at(ui->video->get_position());
283 if (s.attack_state == EventsModel::Status::OFFENSE) {
284 set_current_event_type("offensive_soft_minus");
285 } else if (s.attack_state == EventsModel::Status::DEFENSE) {
286 set_current_event_type("defensive_soft_minus");
289 connect(ui->pull_or_was_d, &QPushButton::clicked, [this, events]() {
290 EventsModel::Status s = events->get_status_at(ui->video->get_position());
291 if (s.pull_state == EventsModel::Status::SHOULD_PULL ||
292 events->get_status_at(ui->video->get_position() - 1).pull_state == EventsModel::Status::SHOULD_PULL) {
293 set_current_event_type("pull");
294 } else if (s.pull_state == EventsModel::Status::PULL_IN_AIR) {
295 insert_noplayer_event("pull_landed");
296 } else if (s.pull_state == EventsModel::Status::NOT_PULLING) {
297 set_current_event_type("was_d");
301 // Defensive events (TODO add more)
302 connect(ui->interception, &QPushButton::clicked, [this]() { set_current_event_type("interception"); });
303 connect(ui->defense_label, &ClickableLabel::clicked, [this]() { insert_noplayer_event("set_defense"); });
304 connect(ui->their_throwaway, &QPushButton::clicked, [this]() { insert_noplayer_event("their_throwaway"); });
305 connect(ui->their_goal, &QPushButton::clicked, [this]() { insert_noplayer_event("their_goal"); });
306 connect(ui->their_pull, &QPushButton::clicked, [this, events]() {
307 EventsModel::Status s = events->get_status_at(ui->video->get_position());
308 if (s.pull_state == EventsModel::Status::SHOULD_PULL) {
309 insert_noplayer_event("their_pull");
312 connect(ui->our_defense, &QPushButton::clicked, [this]() { set_current_event_type("defense"); });
314 connect(ui->offensive_formation, &QPushButton::clicked, [this]() { insert_or_change_formation(/*offense=*/true); });
315 connect(ui->defensive_formation, &QPushButton::clicked, [this]() { insert_or_change_formation(/*offense=*/false); });
318 connect(ui->substitution, &QPushButton::clicked, [this]() { make_substitution(); });
319 connect(ui->stoppage, &QPushButton::clicked, [this, events]() {
320 EventsModel::Status s = events->get_status_at(ui->video->get_position());
322 insert_noplayer_event("restart");
324 insert_noplayer_event("stoppage");
327 connect(ui->unknown, &QPushButton::clicked, [this]() { insert_noplayer_event("unknown"); });
329 QShortcut *key_delete = new QShortcut(QKeySequence(Qt::Key_Delete), this);
330 connect(key_delete, &QShortcut::activated, [this]() { ui->delete_->animateClick(); });
331 connect(ui->delete_, &QPushButton::clicked, [this]() { delete_current_event(); });
334 connect(ui->action_exit, &QAction::triggered, [this] { close(); });
335 connect(ui->action_export_json, &QAction::triggered, [db] { export_to_json(db, "ultimate.json"); });
337 ui->action_gender_rule_a->setChecked(get_match_property(db, match_id, "gender_rule_a"));
338 ui->action_gender_pull_rule->setChecked(get_match_property(db, match_id, "gender_pull_rule"));
339 connect(ui->action_gender_rule_a, &QAction::toggled, [this, db, match_id] {
340 save_match_property(db, match_id, "gender_rule_a", ui->action_gender_rule_a->isChecked());
342 connect(ui->action_gender_pull_rule, &QAction::toggled, [this, db, match_id] {
343 save_match_property(db, match_id, "gender_pull_rule", ui->action_gender_pull_rule->isChecked());
347 void MainWindow::position_changed(uint64_t pos)
349 ui->timestamp->setText(QString::fromUtf8(format_timestamp(pos)));
351 ui->video->pause(); // We only played to get a picture.
354 QModelIndex row = events->get_last_event_qt(ui->video->get_position());
355 ui->event_view->scrollTo(row, QAbstractItemView::PositionAtCenter);
357 update_ui_from_time(pos);
360 void MainWindow::insert_player_event(int button_id)
362 uint64_t t = ui->video->get_position();
363 vector<int> team = events->sort_team(events->get_team_at(t));
364 if (unsigned(button_id) >= team.size()) {
367 int player_id = team[button_id];
369 EventsModel::Status s = events->get_status_at(t);
371 ui->event_view->selectionModel()->blockSignals(true);
372 if (s.attack_state == EventsModel::Status::OFFENSE) {
373 // TODO: Perhaps not if that player already did the last catch?
374 ui->event_view->selectRow(events->insert_event(t, player_id, nullopt, "catch"));
376 ui->event_view->selectRow(events->insert_event(t, player_id, nullopt));
378 ui->event_view->selectionModel()->blockSignals(false);
380 update_ui_from_time(t);
383 void MainWindow::insert_noplayer_event(const string &type)
385 uint64_t t = ui->video->get_position();
387 ui->event_view->selectionModel()->blockSignals(true);
388 ui->event_view->selectRow(events->insert_event(t, nullopt, nullopt, type));
389 ui->event_view->selectionModel()->blockSignals(false);
391 update_ui_from_time(t);
394 void MainWindow::set_current_event_type(const string &type)
396 QItemSelectionModel *select = ui->event_view->selectionModel();
397 if (!select->hasSelection()) {
400 int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
401 events->set_event_type(row, type);
402 update_ui_from_time(ui->video->get_position());
405 // Formation buttons either modify the existing formation (if we've selected
406 // a formation change event), or insert a new one (if not).
407 void MainWindow::insert_or_change_formation(bool offense)
409 FormationsModel *formations = offense ? offensive_formations : defensive_formations;
410 QListView *formation_view = offense ? ui->offensive_formation_view : ui->defensive_formation_view;
411 if (!formation_view->selectionModel()->hasSelection()) {
412 // This shouldn't happen; the button should not have been enabled.
415 int formation_row = formation_view->selectionModel()->selectedRows().front().row(); // Should only be one, due to our selection behavior.
416 int formation_id = formations->get_formation_id(formation_row);
417 if (formation_id == -1) {
418 // This also shouldn't happen (“Add new…” selected).
422 QItemSelectionModel *select = ui->event_view->selectionModel();
423 if (select->hasSelection()) {
424 int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
425 EventType expected_type = offense ? EventType::FORMATION_OFFENSE : EventType::FORMATION_DEFENSE;
426 if (events->get_event_type(row) == expected_type) {
427 events->set_event_formation(row, formation_id);
428 update_ui_from_time(ui->video->get_position());
433 // Insert a new formation event instead (same as double-click on the selected one).
434 events->set_formation_at(ui->video->get_position(), offense, formation_id);
435 update_ui_from_time(ui->video->get_position());
438 void MainWindow::delete_current_event()
440 QItemSelectionModel *select = ui->event_view->selectionModel();
441 if (!select->hasSelection()) {
444 int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
445 ui->event_view->selectionModel()->blockSignals(true);
446 events->delete_event(row);
447 ui->event_view->selectionModel()->blockSignals(false);
448 update_ui_from_time(ui->video->get_position());
451 void MainWindow::make_substitution()
453 QItemSelectionModel *select = ui->player_view->selectionModel();
455 for (QModelIndex row : select->selectedRows()) {
456 new_team.insert(players->get_player_id(row.row()));
458 events->set_team_at(ui->video->get_position(), new_team);
459 update_player_buttons(ui->video->get_position());
462 void MainWindow::update_ui_from_time(uint64_t t)
465 update_player_buttons(t);
466 update_action_buttons(t);
469 void MainWindow::update_status(uint64_t t)
471 EventsModel::Status s = events->get_status_at(t);
473 std::string formation = "Not started";
474 if (s.attack_state == EventsModel::Status::OFFENSE) {
475 if (s.offensive_formation != 0) {
476 formation = offensive_formations->get_formation_name_by_id(s.offensive_formation);
478 formation = "Offense";
480 } else if (s.attack_state == EventsModel::Status::DEFENSE) {
481 if (s.defensive_formation != 0) {
482 formation = defensive_formations->get_formation_name_by_id(s.defensive_formation);
484 formation = "Defense";
488 snprintf(buf, sizeof(buf), "%d–%d | %s | %d passes, %d sec possession",
489 s.our_score, s.their_score, formation.c_str(), s.num_passes, s.possession_sec);
490 if (s.stoppage_sec > 0) {
492 snprintf(buf2, sizeof(buf2), "%s (plus %d sec stoppage)", buf, s.stoppage_sec);
493 ui->status->setText(buf2);
495 ui->status->setText(buf);
499 void MainWindow::update_player_buttons(uint64_t t)
501 QPushButton *buttons[] = {
510 const char shortcuts[] = "qweasdf";
512 for (int player_id : events->sort_team(events->get_team_at(t))) {
513 QPushButton *btn = buttons[num_players];
514 string label = players->get_player_name_by_id(player_id) + " (&" + shortcuts[num_players] + ")";
515 char shortcut[2] = "";
516 shortcut[0] = toupper(shortcuts[num_players]);
517 btn->setText(QString::fromUtf8(label));
518 btn->setShortcut(QCoreApplication::translate("MainWindow", shortcut, nullptr));
519 btn->setEnabled(true);
520 if (++num_players == 7) {
524 for (int i = num_players; i < 7; ++i) {
525 QPushButton *btn = buttons[i];
526 btn->setText("No player");
527 btn->setEnabled(false);
531 void MainWindow::update_action_buttons(uint64_t t)
534 QItemSelectionModel *select = ui->offensive_formation_view->selectionModel();
535 if (select->hasSelection()) {
536 int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
537 ui->offensive_formation->setEnabled(offensive_formations->get_formation_id(row) != -1);
539 ui->offensive_formation->setEnabled(false);
543 QItemSelectionModel *select = ui->defensive_formation_view->selectionModel();
544 if (select->hasSelection()) {
545 int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
546 ui->defensive_formation->setEnabled(defensive_formations->get_formation_id(row) != -1);
548 ui->defensive_formation->setEnabled(false);
552 EventsModel::Status s = events->get_status_at(t);
554 bool has_selection = false;
555 bool has_selection_with_player = false;
557 QItemSelectionModel *select = ui->event_view->selectionModel();
558 if (select->hasSelection()) {
559 has_selection = true;
560 int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
561 has_selection_with_player = events->get_player_id(row).has_value();
563 ui->delete_->setEnabled(has_selection);
566 ui->stoppage->setText("Restart (&v)");
567 ui->stoppage->setShortcut(QCoreApplication::translate("MainWindow", "V", nullptr));
568 ui->catch_->setEnabled(false);
569 ui->throwaway->setEnabled(false);
570 ui->drop->setEnabled(false);
571 ui->goal->setEnabled(false);
572 ui->stallout->setEnabled(false);
573 ui->soft_plus->setEnabled(false);
574 ui->soft_minus->setEnabled(false);
575 ui->pull_or_was_d->setEnabled(false);
576 ui->interception->setEnabled(false);
577 ui->their_throwaway->setEnabled(false);
578 ui->our_defense->setEnabled(false);
579 ui->their_goal->setEnabled(false);
580 ui->their_pull->setEnabled(false);
583 ui->stoppage->setText("Stoppage (&v)");
584 ui->stoppage->setShortcut(QCoreApplication::translate("MainWindow", "V", nullptr));
587 // Defaults for pull-related buttons.
588 ui->pull_or_was_d->setText("Pull (&p)");
589 ui->their_pull->setText("Their pull (&p)");
590 ui->pull_or_was_d->setShortcut(QCoreApplication::translate("MainWindow", "P", nullptr));
591 ui->their_pull->setShortcut(QCoreApplication::translate("MainWindow", "P", nullptr));
592 ui->throwaway->setText("Throwaway (&t)");
593 ui->throwaway->setShortcut(QCoreApplication::translate("MainWindow", "T", nullptr));
595 if (s.pull_state == EventsModel::Status::SHOULD_PULL ||
596 (has_selection_with_player && events->get_status_at(ui->video->get_position() - 1).pull_state == EventsModel::Status::SHOULD_PULL)) { // Can change this event to pull.
597 ui->pull_or_was_d->setEnabled(s.attack_state == EventsModel::Status::DEFENSE && has_selection_with_player);
598 ui->their_pull->setEnabled(s.attack_state == EventsModel::Status::OFFENSE);
600 ui->catch_->setEnabled(false);
601 ui->throwaway->setEnabled(false);
602 ui->drop->setEnabled(false);
603 ui->goal->setEnabled(false);
604 ui->stallout->setEnabled(false);
605 ui->soft_plus->setEnabled(false);
606 ui->soft_minus->setEnabled(false);
607 ui->interception->setEnabled(false);
608 ui->their_throwaway->setEnabled(false);
609 ui->our_defense->setEnabled(false);
610 ui->their_goal->setEnabled(false);
613 if (s.pull_state == EventsModel::Status::PULL_IN_AIR) {
614 if (s.attack_state == EventsModel::Status::DEFENSE) {
615 ui->pull_or_was_d->setText("Pull landed (&p)");
616 ui->pull_or_was_d->setShortcut(QCoreApplication::translate("MainWindow", "P", nullptr));
617 ui->pull_or_was_d->setEnabled(true);
619 ui->throwaway->setText("Pull OOB (&t)");
620 ui->throwaway->setShortcut(QCoreApplication::translate("MainWindow", "T", nullptr));
621 ui->throwaway->setEnabled(true);
623 ui->pull_or_was_d->setEnabled(false);
624 ui->throwaway->setEnabled(false);
626 ui->their_pull->setEnabled(false); // We don't track their pull landings; only by means of catch etc.
628 ui->catch_->setEnabled(false);
629 ui->drop->setEnabled(false);
630 ui->goal->setEnabled(false);
631 ui->stallout->setEnabled(false);
632 ui->soft_plus->setEnabled(false);
633 ui->soft_minus->setEnabled(false);
634 ui->interception->setEnabled(false);
635 ui->their_throwaway->setEnabled(false);
636 ui->our_defense->setEnabled(false);
637 ui->their_goal->setEnabled(false);
641 // Not pulling, so reuse the pull button for got d-ed.
642 ui->pull_or_was_d->setText("Was d-ed (&z)");
643 ui->pull_or_was_d->setShortcut(QCoreApplication::translate("MainWindow", "Z", nullptr));
644 ui->pull_or_was_d->setEnabled(true);
646 ui->catch_->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
647 ui->throwaway->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
648 ui->drop->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
649 ui->goal->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
650 ui->stallout->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
651 ui->soft_plus->setEnabled(s.attack_state != EventsModel::Status::NOT_STARTED && has_selection_with_player);
652 ui->soft_minus->setEnabled(s.attack_state != EventsModel::Status::NOT_STARTED && has_selection_with_player);
653 ui->pull_or_was_d->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player); // Was d-ed.
655 ui->interception->setEnabled(s.attack_state == EventsModel::Status::DEFENSE && has_selection_with_player);
656 ui->their_throwaway->setEnabled(s.attack_state == EventsModel::Status::DEFENSE);
657 ui->our_defense->setEnabled(s.attack_state == EventsModel::Status::DEFENSE && has_selection_with_player);
658 ui->their_goal->setEnabled(s.attack_state == EventsModel::Status::DEFENSE);
659 ui->their_pull->setEnabled(false);
662 void MainWindow::formation_double_clicked(bool offense, unsigned row)
664 FormationsModel *formations = offense ? offensive_formations : defensive_formations;
665 int id = formations->get_formation_id(row);
666 if (id == -1) { // “Add new” clicked.
668 QString new_formation_str = QInputDialog::getText(this, "New formation", "Choose name for new formation:", QLineEdit::Normal, "", &ok);
669 if (!ok || new_formation_str.isEmpty()) {
673 id = formations->insert_new(new_formation_str.toStdString());
674 QListView *view = offense ? ui->offensive_formation_view : ui->defensive_formation_view;
675 view->selectionModel()->select(formations->index(formations->get_row_from_id(id), 0), QItemSelectionModel::ClearAndSelect);
676 events->inserted_new_formation(id, new_formation_str.toStdString());
678 events->set_formation_at(ui->video->get_position(), offense, id);
680 update_ui_from_time(ui->video->get_position());