2020
2121#include < QFileDialog>
2222#include < QSettings>
23+ #include < QMenu>
2324#include < functional>
2425#include < algorithm>
2526
@@ -112,6 +113,10 @@ NewTournamentDialog::NewTournamentDialog(EngineManager* engineManager,
112113 connect (ui->m_playersList , SIGNAL (doubleClicked (QModelIndex)),
113114 this , SLOT (configureEngine (QModelIndex)));
114115
116+ ui->m_playersList ->setContextMenuPolicy (Qt::ContextMenuPolicy::CustomContextMenu);
117+ connect (ui->m_playersList , SIGNAL (customContextMenuRequested (const QPoint&)),
118+ this , SLOT (onContextMenuRequest ()));
119+
115120 ui->buttonBox ->button (QDialogButtonBox::Ok)->setEnabled (false );
116121 connect (ui->m_gameSettings , &GameSettingsWidget::statusChanged, [=](bool ok)
117122 {
@@ -136,6 +141,7 @@ void NewTournamentDialog::addEngineOnDblClick(const QModelIndex& index)
136141 const QModelIndex& idx = m_proxyModel->mapToSource (index);
137142
138143 m_addedEnginesManager->addEngine (m_srcEngineManager->engineAt (idx.row ()));
144+ m_timeControls << TimeControl ();
139145 listView->selectionModel ()->select (index, QItemSelectionModel::Deselect);
140146
141147 QPushButton* button = ui->buttonBox ->button (QDialogButtonBox::Ok);
@@ -157,7 +163,10 @@ void NewTournamentDialog::addEngine()
157163
158164 const QModelIndexList list (dlg.selection ().indexes ());
159165 for (const QModelIndex& index : list)
166+ {
160167 m_addedEnginesManager->addEngine (m_srcEngineManager->engineAt (index.row ()));
168+ m_timeControls << TimeControl ();
169+ }
161170
162171 QPushButton* button = ui->buttonBox ->button (QDialogButtonBox::Ok);
163172 button->setEnabled (canStart ());
@@ -176,7 +185,10 @@ void NewTournamentDialog::removeEngine()
176185 });
177186
178187 for (const QModelIndex& index : qAsConst (selected))
188+ {
179189 m_addedEnginesManager->removeEngineAt (index.row ());
190+ m_timeControls.remove (index.row ());
191+ }
180192
181193 QPushButton* button = ui->buttonBox ->button (QDialogButtonBox::Ok);
182194 button->setEnabled (canStart ());
@@ -207,10 +219,14 @@ void NewTournamentDialog::moveEngine(int offset)
207219 int row1 = index.row ();
208220 int row2 = row1 + offset;
209221 EngineConfiguration tmp (m_addedEnginesManager->engineAt (row1));
222+ TimeControl tc = m_timeControls.at (row1);
210223
211224 m_addedEnginesManager->updateEngineAt (row1, m_addedEnginesManager->engineAt (row2));
212225 m_addedEnginesManager->updateEngineAt (row2, tmp);
213226
227+ m_timeControls[row1] = m_timeControls.at (row2);
228+ m_timeControls[row2]= tc;
229+
214230 ui->m_playersList ->setCurrentIndex (index.sibling (row2, 0 ));
215231}
216232
@@ -264,6 +280,37 @@ void NewTournamentDialog::onPlayerSelectionChanged(const QItemSelection& selecte
264280 ui->m_moveEngineDownBtn ->setEnabled (enable && i < m_addedEnginesManager->engineCount () - 1 );
265281}
266282
283+ void NewTournamentDialog::onContextMenuRequest ()
284+ {
285+ QList<QModelIndex> selected = ui->m_playersList ->selectionModel ()->selectedRows ();
286+ if (selected.isEmpty ())
287+ return ;
288+
289+ QMenu menu (ui->m_playersList );
290+
291+ auto editTimeControlAct = menu.addAction (tr (" Edit Time Control" ));
292+ connect (editTimeControlAct, &QAction::triggered, this , [=]()
293+ {
294+ int i = selected.first ().row ();
295+ TimeControl tc {m_timeControls.at (i)};
296+ if (!tc.isValid ())
297+ tc = ui->m_gameSettings ->timeControl ();
298+
299+ auto dlg = new TimeControlDialog (tc);
300+ QString name {m_addedEnginesManager->engines ().at (i).name ()};
301+ if (selected.count () > 1 )
302+ name.append (tr (" - %0 engines" ).arg (selected.count ()));
303+ dlg->setWindowTitle (tr (" Time Control - %0" ).arg (name));
304+
305+ if (dlg->exec () == QDialog::Accepted)
306+ for (QModelIndex index: selected)
307+ m_timeControls[index.row ()] = dlg->timeControlWhite ();
308+ delete dlg;
309+ });
310+
311+ menu.exec (QCursor::pos ());
312+ }
313+
267314Tournament* NewTournamentDialog::createTournament (GameManager* gameManager) const
268315{
269316 Q_ASSERT (gameManager != nullptr );
@@ -301,12 +348,19 @@ Tournament* NewTournamentDialog::createTournament(GameManager* gameManager) cons
301348 t->setReverseSides (ts->reversingSchedule ());
302349 t->setResultFormat (ts->resultFormat ());
303350
351+ bool isHourglass = ui->m_gameSettings ->timeControl ().isHourglass ();
352+
304353 const auto engines = m_addedEnginesManager->engines ();
305- for (EngineConfiguration config : engines)
354+ for (int i = 0 ; i < engines. count (); i++ )
306355 {
356+ EngineConfiguration config = engines.at (i);
307357 ui->m_gameSettings ->applyEngineConfiguration (&config);
358+ TimeControl tc = m_timeControls.at (i);
359+ // Hourglass mode must be the same for all players
360+ tc.setHourglass (isHourglass);
361+
308362 t->addPlayer (new EngineBuilder (config),
309- ui->m_gameSettings ->timeControl (),
363+ tc. isValid () ? tc : ui->m_gameSettings ->timeControl (),
310364 book,
311365 bookDepth);
312366 }
0 commit comments