]> git.sesse.net Git - pkanalytics/blobdiff - main.cpp
Disable irrelevant buttons.
[pkanalytics] / main.cpp
index 3c44f94adbbe8cb034b259747ceaaed215a032cc..9b9f6305ba7db66dc35ccb65da8543346176242f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -89,7 +89,6 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players) : events(even
        connect(ui->player_7, &QPushButton::clicked, [this]() { insert_event(7); });
 
        // Offensive events
-       // TODO: disable if nothing is selected
        connect(ui->catch_, &QPushButton::clicked, [this]() { set_current_event_type("catch"); });
        connect(ui->throwaway, &QPushButton::clicked, [this]() { set_current_event_type("throwaway"); });
        connect(ui->drop, &QPushButton::clicked, [this]() { set_current_event_type("drop"); });
@@ -103,9 +102,9 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players) : events(even
        connect(ui->their_throwaway, &QPushButton::clicked, [this]() { insert_noplayer_event("their_throwaway"); });
        connect(ui->their_goal, &QPushButton::clicked, [this]() { insert_noplayer_event("their_goal"); });
        connect(ui->their_pull, &QPushButton::clicked, [this]() { insert_noplayer_event("their_pull"); });
-       connect(ui->our_defense, &QPushButton::clicked, [this]() { set_current_event_type("defense"); });  // TODO: player-connected
-       connect(ui->defensive_soft_plus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_plus"); });  // TODO: player-connected
-       connect(ui->defensive_soft_minus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_minus"); });  // TODO: player-connected
+       connect(ui->our_defense, &QPushButton::clicked, [this]() { set_current_event_type("defense"); });
+       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"); });
 
        // Misc. events
        connect(ui->substitution, &QPushButton::clicked, [this]() { make_substitution(); });
@@ -230,6 +229,7 @@ void MainWindow::update_ui_from_time(uint64_t t)
 {
        update_status(t);
        update_player_buttons(t);
+       update_action_buttons(t);
 }
 
 void MainWindow::update_status(uint64_t t)
@@ -274,6 +274,42 @@ void MainWindow::update_player_buttons(uint64_t t)
        }
 }
 
+void MainWindow::update_action_buttons(uint64_t t)
+{
+       EventsModel::Status s = events->get_status_at(t);
+       bool has_selection = false;
+       bool has_selection_with_player = false;
+
+       QItemSelectionModel *select = ui->event_view->selectionModel();
+       if (select->hasSelection()) {
+               has_selection = true;
+               int row = select->selectedRows().front().row();  // Should only be one, due to our selection behavior.
+               has_selection_with_player = events->get_player_id(row).has_value();
+       }
+
+       ui->catch_->setEnabled(s.offense && has_selection_with_player);
+       ui->throwaway->setEnabled(s.offense && has_selection_with_player);
+       ui->drop->setEnabled(s.offense && has_selection_with_player);
+       ui->goal->setEnabled(s.offense && has_selection_with_player);
+       ui->offensive_soft_plus->setEnabled(s.offense && has_selection_with_player);
+       ui->offensive_soft_minus->setEnabled(s.offense && has_selection_with_player);
+
+       // TODO: be stricter
+       ui->pull->setEnabled(s.offense && has_selection_with_player);
+       ui->pull_landed->setEnabled(s.offense && has_selection_with_player);
+
+       ui->interception->setEnabled(!s.offense && has_selection_with_player);
+       ui->their_throwaway->setEnabled(!s.offense);
+       ui->our_defense->setEnabled(!s.offense && has_selection_with_player);
+       ui->their_goal->setEnabled(!s.offense);
+       ui->defensive_soft_plus->setEnabled(!s.offense && has_selection_with_player);
+       ui->defensive_soft_minus->setEnabled(!s.offense && has_selection_with_player);
+       ui->their_pull->setEnabled(!s.offense);
+       ui->our_foul->setEnabled(!s.offense && has_selection_with_player);
+
+       ui->delete_->setEnabled(has_selection);
+}
+
 sqlite3 *open_db(const char *filename)
 {
        sqlite3 *db;