diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
commit | d24f813f3f2a05c112e803e4256b53535895fc98 (patch) | |
tree | 601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/settings/StudySettingsDialog.cpp |
Diffstat (limited to 'src/settings/StudySettingsDialog.cpp')
-rw-r--r-- | src/settings/StudySettingsDialog.cpp | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/src/settings/StudySettingsDialog.cpp b/src/settings/StudySettingsDialog.cpp new file mode 100644 index 0000000..b38bf67 --- /dev/null +++ b/src/settings/StudySettingsDialog.cpp @@ -0,0 +1,141 @@ +#include "StudySettingsDialog.h" + +StudySettingsDialog::StudySettingsDialog(QWidget *parent): + QDialog(parent) + { + initData(); + createUi(); + updateControls(); + } + +void StudySettingsDialog::initData() + { + settings = *StudySettings::inst(); + } + +void StudySettingsDialog::createUi() +{ + createControls(); + setLayout(createMainLayout()); + setWindowTitle(tr("Study settings")); +} + +void StudySettingsDialog::createControls() +{ + dayShiftBox = createSpinBox(0, 12); + newCardsShareBox = createSpinBox(1, 99); + randomnessBox = createSpinBox(1, 99); + cardsDayLimitBox = createSpinBox(1, 500); + newCardsDayLimitBox = createSpinBox(0, 200); + limitForAddingNewCardsBox = createSpinBox(20, 500); + showRandomlyCB = new QCheckBox(tr("Add new cards in random order")); + createButtonBox(); +} + +QSpinBox* StudySettingsDialog::createSpinBox(int min, int max) +{ + QSpinBox* spinBox = new QSpinBox; + spinBox->setMinimum(min); + spinBox->setMaximum(max); + return spinBox; +} + +void StudySettingsDialog::createButtonBox() +{ + buttonBox = new QDialogButtonBox( + QDialogButtonBox::Ok | QDialogButtonBox::Cancel | + QDialogButtonBox::RestoreDefaults, Qt::Horizontal); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), + SLOT(dialogButtonClicked(QAbstractButton*))); +} + +QBoxLayout* StudySettingsDialog::createMainLayout() +{ + QHBoxLayout* upperPaddedLt = new QHBoxLayout; + upperPaddedLt->addLayout(createUpperLayout()); + upperPaddedLt->addStretch(); + + QVBoxLayout* mainLt = new QVBoxLayout; + mainLt->addLayout(upperPaddedLt); + mainLt->addWidget(showRandomlyCB); + mainLt->addWidget(createLimitsGroup()); + mainLt->addWidget(buttonBox); + return mainLt; +} + +QGridLayout* StudySettingsDialog::createUpperLayout() +{ + QGridLayout* layout = new QGridLayout; + int row = 0; + addUpperGridLine(layout, row++, tr("Day starts at, o'clock:"), dayShiftBox); + addUpperGridLine(layout, row++, tr("Share of new cards:"), newCardsShareBox, "%"); + addUpperGridLine(layout, row++, tr("Repetition interval randomness:"), randomnessBox, "%"); + return layout; +} + +void StudySettingsDialog::addUpperGridLine(QGridLayout* layout, int row, const QString& label, + QWidget* widget, const QString& unitLabel) +{ + QLabel* labelWidget = new QLabel(label); + layout->addWidget(labelWidget, row, 0); + layout->addWidget(widget, row, 1); + layout->addWidget(new QLabel(unitLabel), row, 2); +} + +QGroupBox* StudySettingsDialog::createLimitsGroup() +{ + QGridLayout* layout = new QGridLayout; + layout->setColumnStretch(0, 1); + int row = 0; + addLimitsGridLine(layout, row++, tr("Day reviews limit:"), cardsDayLimitBox); + addLimitsGridLine(layout, row++, tr("Day limit of new cards:"), newCardsDayLimitBox); + addLimitsGridLine(layout, row++, + tr("Don't add new cards after scheduled cards threshold:"), + limitForAddingNewCardsBox); + QGroupBox* group = new QGroupBox(tr("Limits")); + group->setLayout(layout); + return group; +} + +void StudySettingsDialog::addLimitsGridLine(QGridLayout* layout, int row, const QString& label, + QWidget* widget) +{ + QLabel* labelWidget = new QLabel(label); + labelWidget->setWordWrap(true); + layout->addWidget(labelWidget, row, 0); + layout->addWidget(widget, row, 1); +} + +const StudySettings StudySettingsDialog::getSettings() +{ + settings.showRandomly = showRandomlyCB->isChecked(); + settings.newCardsShare = newCardsShareBox->value() / 100.; + settings.schedRandomness = randomnessBox->value() / 100.; + settings.cardsDayLimit = cardsDayLimitBox->value(); + settings.newCardsDayLimit = newCardsDayLimitBox->value(); + settings.limitForAddingNewCards = limitForAddingNewCardsBox->value(); + settings.dayShift = dayShiftBox->value(); + return settings; +} + +void StudySettingsDialog::updateControls() +{ + showRandomlyCB->setChecked( settings.showRandomly ); + newCardsShareBox->setValue( settings.newCardsShare * 100 ); + randomnessBox->setValue( settings.schedRandomness * 100 ); + cardsDayLimitBox->setValue( settings.cardsDayLimit ); + newCardsDayLimitBox->setValue( settings.newCardsDayLimit ); + limitForAddingNewCardsBox->setValue(settings.limitForAddingNewCards); + dayShiftBox->setValue( settings.dayShift ); +} + +void StudySettingsDialog::dialogButtonClicked( QAbstractButton* aButton ) + { + if(buttonBox->buttonRole(aButton) == QDialogButtonBox::ResetRole) + { + settings = StudySettings(); + updateControls(); + } + } |