#include <QVideoWidget>
#include <QShortcut>
#include <QInputDialog>
+#include <QTimer>
#include <algorithm>
#include <string>
#include <map>
ui->setupUi(this);
ui->event_view->setModel(events);
+ ui->event_view->setColumnWidth(1, 150);
+ ui->event_view->setColumnWidth(2, 150);
connect(ui->event_view->selectionModel(), &QItemSelectionModel::currentRowChanged,
[this, events](const QModelIndex ¤t, const QModelIndex &previous) {
uint64_t t = events->get_time(current.row());
ui->player_view->horizontalHeader()->setStretchLastSection(true);
auto formation_changed = [this](const QModelIndex ¤t, const QModelIndex &previous) {
- update_action_buttons(video->position());
+ QTimer::singleShot(1, [=]{ // The selection is wrong until the callback actually returns.
+ update_action_buttons(video->position());
+ });
};
ui->offensive_formation_view->setModel(offensive_formations);
ui->defensive_formation_view->setModel(defensive_formations);
EventsModel::Status s = events->get_status_at(video->position());
if (s.pull_state == EventsModel::Status::SHOULD_PULL) {
set_current_event_type("pull");
- } else if (EventsModel::Status::PULL_IN_AIR) {
+ } else if (s.pull_state == EventsModel::Status::PULL_IN_AIR) {
insert_noplayer_event("pull_landed");
}
});
connect(ui->defensive_soft_plus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_plus"); });
connect(ui->defensive_soft_minus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_minus"); });
+ connect(ui->offensive_formation, &QPushButton::clicked, [this]() { insert_or_change_formation(/*offense=*/true); });
+ connect(ui->defensive_formation, &QPushButton::clicked, [this]() { insert_or_change_formation(/*offense=*/false); });
+
// Misc. events
connect(ui->substitution, &QPushButton::clicked, [this]() { make_substitution(); });
connect(ui->stoppage, &QPushButton::clicked, [this, events]() {
update_ui_from_time(video->position());
}
+// Formation buttons either modify the existing formation (if we've selected
+// a formation change event), or insert a new one (if not).
+void MainWindow::insert_or_change_formation(bool offense)
+{
+ FormationsModel *formations = offense ? offensive_formations : defensive_formations;
+ QListView *formation_view = offense ? ui->offensive_formation_view : ui->defensive_formation_view;
+ if (!formation_view->selectionModel()->hasSelection()) {
+ // This shouldn't happen; the button should not have been enabled.
+ return;
+ }
+ int formation_row = formation_view->selectionModel()->selectedRows().front().row(); // Should only be one, due to our selection behavior.
+ int formation_id = formations->get_formation_id(formation_row);
+ if (formation_id == -1) {
+ // This also shouldn't happen (“Add new…” selected).
+ return;
+ }
+
+ QItemSelectionModel *select = ui->event_view->selectionModel();
+ if (select->hasSelection()) {
+ int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
+ string expected_type = offense ? "formation_offense" : "formation_defense";
+ if (events->get_event_type(row) == expected_type) {
+ events->set_event_formation(row, formation_id);
+ update_ui_from_time(video->position());
+ return;
+ }
+ }
+
+ // Insert a new formation event instead (same as double-click on the selected one).
+ events->set_formation_at(video->position(), offense, formation_id);
+ update_ui_from_time(video->position());
+}
+
void MainWindow::delete_current_event()
{
QItemSelectionModel *select = ui->event_view->selectionModel();
{
EventsModel::Status s = events->get_status_at(t);
char buf[256];
- const char *offense = "not started";
+ std::string formation = "Not started";
if (s.attack_state == EventsModel::Status::OFFENSE) {
- offense = "offense";
+ if (s.offensive_formation != 0) {
+ formation = offensive_formations->get_formation_name_by_id(s.offensive_formation);
+ } else {
+ formation = "Offense";
+ }
} else if (s.attack_state == EventsModel::Status::DEFENSE) {
- offense = "defense";
+ if (s.defensive_formation != 0) {
+ formation = defensive_formations->get_formation_name_by_id(s.defensive_formation);
+ } else {
+ formation = "Defense";
+ }
}
snprintf(buf, sizeof(buf), "%d–%d | %s | %d passes, %d sec possession",
- s.our_score, s.their_score, offense, s.num_passes, s.possession_sec);
+ s.our_score, s.their_score, formation.c_str(), s.num_passes, s.possession_sec);
if (s.stoppage_sec > 0) {
char buf2[256];
snprintf(buf2, sizeof(buf2), "%s (plus %d sec stoppage)", buf, s.stoppage_sec);
} else {
events->set_formation_at(video->position(), offense, id);
}
+ update_ui_from_time(video->position());
}
sqlite3 *open_db(const char *filename)