| 1378 | TransLabelSetting* makeLabel(const QString &value) |
| 1379 | { |
| 1380 | TransLabelSetting* l = new TransLabelSetting(); |
| 1381 | l->setValue(value); |
| 1382 | return l; |
| 1383 | } |
| 1384 | |
| 1385 | PlaybackSpeedsConfigWizard::PlaybackSpeedsConfigWizard(vector<int> &_ff_rew, |
| 1386 | vector<int> &_repos, vector<int> &_slowmo) : |
| 1387 | ff_rew(_ff_rew), repos(_repos), slowmo(_slowmo) |
| 1388 | { |
| 1389 | for (uint i = 0; i < ff_rew.size(); i++) |
| 1390 | { |
| 1391 | TransSpinBoxSetting* spin = new TransSpinBoxSetting(0, 360, 5, true, |
| 1392 | "(" + tr("disabled") + ")"); |
| 1393 | spin->setValue(ff_rew[i]); |
| 1394 | ff_rew_spins.push_back(spin); |
| 1395 | |
| 1396 | spin = new TransSpinBoxSetting(-5, 200, 5, false, |
| 1397 | "(" + tr("default") + ")"); |
| 1398 | spin->setValue(repos[i]); |
| 1399 | spin->setHelpText(tr( |
| 1400 | "When exiting sticky keys fast forward/rewind " |
| 1401 | "mode, reposition this many 1/100th seconds before " |
| 1402 | "resuming normal playback. This " |
| 1403 | "compensates for the reaction time between seeing " |
| 1404 | "where to resume playback and actually exiting seeking.")); |
| 1405 | repos_spins.push_back(spin); |
| 1406 | }; |
| 1407 | for (uint i = 0; i < slowmo.size(); i++) |
| 1408 | { |
| 1409 | slowmo_combos.push_back(slowmoCombo(slowmo[i])); |
| 1410 | }; |
| 1411 | |
| 1412 | VerticalConfigurationGroup *ff_rew_rows = |
| 1413 | new VerticalConfigurationGroup(true, true, false, true); |
| 1414 | ff_rew_rows->setLabel(tr("Fast forward/rewind")); |
| 1415 | |
| 1416 | HorizontalConfigurationGroup *row = |
| 1417 | new HorizontalConfigurationGroup(false, false, true, true); |
| 1418 | row->addChild(makeLabel("")); |
| 1419 | row->addChild(makeLabel(tr("Speed"))); |
| 1420 | row->addChild(makeLabel(tr("Reposition"))); |
| 1421 | ff_rew_rows->addChild(row); |
| 1422 | |
| 1423 | for (uint i = 0; i < ff_rew_spins.size(); i++) |
| 1424 | { |
| 1425 | QString str = (i == ff_rew_spins.size()-1) ? tr("Fastest") : |
| 1426 | (i == 0) ? tr("Slowest") : "" ; |
| 1427 | row = new HorizontalConfigurationGroup(false, false, true, true); |
| 1428 | row->addChild(makeLabel(str)); |
| 1429 | row->addChild(ff_rew_spins[i]); |
| 1430 | row->addChild(repos_spins[i]); |
| 1431 | ff_rew_rows->addChild(row); |
| 1432 | }; |
| 1433 | |
| 1434 | HorizontalConfigurationGroup *slowmo_rows = |
| 1435 | new HorizontalConfigurationGroup(true, true, false, true); |
| 1436 | VerticalConfigurationGroup *column1 = |
| 1437 | new VerticalConfigurationGroup(false, false, true, true); |
| 1438 | VerticalConfigurationGroup *column2 = |
| 1439 | new VerticalConfigurationGroup(false, false, true, true); |
| 1440 | |
| 1441 | slowmo_rows->setLabel(tr("Slow motion")); |
| 1442 | |
| 1443 | column1->addChild(makeLabel("")); |
| 1444 | column2->addChild(makeLabel(tr("Speed"))); |
| 1445 | |
| 1446 | for (uint i = 0; i < slowmo_combos.size(); i++) |
| 1447 | { |
| 1448 | QString str = (i == slowmo_combos.size()-1) ? tr("Slowest") : |
| 1449 | (i == 0) ? tr("Fastest") : "" ; |
| 1450 | column1->addChild(makeLabel(str)); |
| 1451 | column2->addChild(slowmo_combos[i]); |
| 1452 | }; |
| 1453 | |
| 1454 | for (uint i = slowmo_combos.size(); i < ff_rew_spins.size(); i++) |
| 1455 | { |
| 1456 | column1->addChild(makeLabel("")); |
| 1457 | column2->addChild(makeLabel("")); |
| 1458 | }; |
| 1459 | |
| 1460 | slowmo_rows->addChild(column1); |
| 1461 | slowmo_rows->addChild(column2); |
| 1462 | |
| 1463 | HorizontalConfigurationGroup *main = |
| 1464 | new HorizontalConfigurationGroup(false, false, true, true); |
| 1465 | main->setLabel(tr("Playback Speed Configuration")); |
| 1466 | main->addChild(ff_rew_rows); |
| 1467 | main->addChild(slowmo_rows); |
| 1468 | |
| 1469 | addChild(main); |
| 1470 | } |
| 1471 | |
| 1472 | void PlaybackSpeedsConfigWizard::save(void) |
| 1473 | { |
| 1474 | for (uint i = 0; i < ff_rew.size(); i++) |
| 1475 | { |
| 1476 | ff_rew[i] = ff_rew_spins[i]->getValue().toInt(); |
| 1477 | repos[i] = repos_spins[i]->getValue().toInt(); |
| 1478 | }; |
| 1479 | |
| 1480 | for (uint i = 0; i < slowmo.size(); i++) |
| 1481 | { |
| 1482 | slowmo[i] = slowmo_combos[i]->getValue().toInt(); |
| 1483 | }; |
| 1484 | } |
| 1485 | |
| 1486 | TransComboBoxSetting* PlaybackSpeedsConfigWizard::slowmoCombo(uint value) |
| 1487 | { |
| 1488 | TransComboBoxSetting* combo = new TransComboBoxSetting(); |
| 1489 | combo->addSelection("(" + tr("disabled") + ")", "0", (value == 0)); |
| 1490 | for (uint i = 2; i <= 64; i++) |
| 1491 | { |
| 1492 | combo->addSelection(QString("1/%1").arg(i), QString::number(i), |
| 1493 | (i == value)); |
| 1494 | }; |
| 1495 | return combo; |
| 1496 | }; |
| 1497 | |
| 1498 | PlaybackSpeedsConfig::PlaybackSpeedsConfig() : |
| 1499 | VerticalConfigurationGroup(false, false, true, true), |
| 1500 | needs_save(false) |
| 1501 | { |
| 1502 | int def1[8] = {3, 5, 10, 20, 30, 60, 120, 180}; |
| 1503 | for (uint i = 0; i < sizeof(def1)/sizeof(def1[0]); i++) |
| 1504 | { |
| 1505 | int speed = gContext->GetNumSetting(QString("FFRewSpeed%1").arg(i), |
| 1506 | def1[i]); |
| 1507 | ff_rew_speeds.push_back(speed); |
| 1508 | |
| 1509 | int repos = gContext->GetNumSetting(QString("FFRewReposTime%1"). |
| 1510 | arg(i), -5); |
| 1511 | ff_rew_repos.push_back(repos); |
| 1512 | }; |
| 1513 | |
| 1514 | int def2[4] = {3, 8, 16, 0}; |
| 1515 | for (uint i = 0; i < sizeof(def2)/sizeof(def2[0]); i++) |
| 1516 | { |
| 1517 | int speed = gContext->GetNumSetting(QString("SlowMotionSpeed%1"). |
| 1518 | arg(i), def2[i]); |
| 1519 | slowmo_speeds.push_back(speed); |
| 1520 | }; |
| 1521 | |
| 1522 | InitUI(); |
| 1523 | } |
| 1524 | |
| 1525 | void PlaybackSpeedsConfig::InitLabels() |
| 1526 | { |
| 1527 | QString str = tr("Fast forward/rewind") + ":"; |
| 1528 | for (uint i = 0; i < ff_rew_speeds.size(); i++) |
| 1529 | if (ff_rew_speeds[i] > 0 ) |
| 1530 | str += QString(" %1x").arg(ff_rew_speeds[i]); |
| 1531 | |
| 1532 | ff_rew_label->setValue(str); |
| 1533 | |
| 1534 | str = tr("Slow motion") + ":"; |
| 1535 | for (uint i = 0; i < slowmo_speeds.size(); i++) |
| 1536 | if (slowmo_speeds[i] > 0 ) |
| 1537 | str += QString(" 1/%1x").arg(slowmo_speeds[i]); |
| 1538 | |
| 1539 | slowmo_label->setValue(str); |
| 1540 | } |
| 1541 | |
| 1542 | void PlaybackSpeedsConfig::InitUI(void) |
| 1543 | { |
| 1544 | VerticalConfigurationGroup *rows = |
| 1545 | new VerticalConfigurationGroup(true, true, false, true); |
| 1546 | rows->setLabel(tr("Playback Speeds")); |
| 1547 | |
| 1548 | ff_rew_label = new TransLabelSetting(); |
| 1549 | slowmo_label = new TransLabelSetting(); |
| 1550 | InitLabels(); |
| 1551 | rows->addChild(ff_rew_label); |
| 1552 | rows->addChild(slowmo_label); |
| 1553 | |
| 1554 | edit = new TransButtonSetting("edit"); |
| 1555 | edit->setLabel(QObject::tr("Edit Playback Speeds")); |
| 1556 | rows->addChild(edit); |
| 1557 | connect(edit, SIGNAL(pressed(QString)), |
| 1558 | this, SLOT (pressed(QString))); |
| 1559 | |
| 1560 | addChild(rows); |
| 1561 | } |
| 1562 | |
| 1563 | void PlaybackSpeedsConfig::save(void) |
| 1564 | { |
| 1565 | if (!needs_save) |
| 1566 | return; // nothing to do.. |
| 1567 | |
| 1568 | for (uint i = 0; i < ff_rew_speeds.size(); i++) |
| 1569 | { |
| 1570 | gContext->SaveSetting(QString("FFRewSpeed%1").arg(i), |
| 1571 | QString::number(ff_rew_speeds[i])); |
| 1572 | gContext->SaveSetting(QString("FFRewReposTime%1").arg(i), |
| 1573 | QString::number(ff_rew_repos[i])); |
| 1574 | }; |
| 1575 | for (uint i = 0; i < slowmo_speeds.size(); i++) |
| 1576 | { |
| 1577 | gContext->SaveSetting(QString("SlowMotionSpeed%1").arg(i), |
| 1578 | QString::number(slowmo_speeds[i])); |
| 1579 | }; |
| 1580 | } |
| 1581 | |
| 1582 | void PlaybackSpeedsConfig::pressed(QString cmd) |
| 1583 | { |
| 1584 | PlaybackSpeedsConfigWizard cfg(ff_rew_speeds, ff_rew_repos, slowmo_speeds); |
| 1585 | if (cfg.exec() != QDialog::Accepted) |
| 1586 | VERBOSE(VB_IMPORTANT, "playback speeds rejected"); |
| 1587 | |
| 1588 | InitLabels(); |
| 1589 | needs_save = true; |
| 1590 | |
| 1591 | repaint(); |
| 1592 | } |
| 1593 | |