diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1da35f2..0e7da86 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -148,17 +148,12 @@ MainWindow::MainWindow(QWidget *parent) ui->tableWidget->setFocus(); setAcceptDrops(true); - // Build the list of known factors (all combinations). + // Build the list of known factors. ui->knownFactors->addItem("", 100.0); - for (int i = 0; i < FACTORS_LABELS.size(); i++) { - for (int j = 0; j < FACTORS_LABELS.size(); j++) { - if (i == j) { - continue; - } - ui->knownFactors->addItem( - QString("%1 → %2").arg(FACTORS_LABELS[i]).arg(FACTORS_LABELS[j]), - FACTORS_VALUES[j] / FACTORS_VALUES[i] * 100.0); - } + foreach (Factor conv, FACTORS_VALUES) { + ui->knownFactors->addItem( + QString("%1 fps → %2 fps").arg(conv.first).arg(conv.second), + conv.first * 100.0 / conv.second); } // Disable print out by default. @@ -1130,14 +1125,16 @@ void MainWindow::actionShowHelp() { } void MainWindow::speedFactorChanged(double p_factor) { - if (FACTORS_VALUES.indexOf(p_factor) >= 0) { + if (qAbs(p_factor - ui->knownFactors->currentData().toDouble()) > 0.001) { ui->knownFactors->setCurrentIndex(-1); } } -void MainWindow::knownFactorChosen(int) { +void MainWindow::knownFactorChosen(int p_chosen) { // Adjust spinbox to known factor. - ui->speedFactor->setValue(ui->knownFactors->currentData().toDouble()); + if (p_chosen >= 0) { + ui->speedFactor->setValue(ui->knownFactors->itemData(p_chosen).toDouble()); + } } void MainWindow::enableKnownFactors(bool p_state) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 8647b8b..05461c3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -38,9 +39,11 @@ #define MAX_RECENT_FILES 7 -static QList FACTORS_VALUES = {23.976, 24, 25, 29.97, 30}; -static QStringList FACTORS_LABELS = {"23,976 fps", "24 fps", "25 fps", - "29,97 fps", "30 fps"}; +typedef QPair Factor; +static QList FACTORS_VALUES = { + {23.976, 24}, {23.976, 25}, {24, 23.976}, {24, 25}, + {25, 23.976}, {25, 24}, {29.97, 30}, {30, 29.97}, +}; class ConfigEditor; class ShortcutEditor;