#include "SpacedRepetitionWindow.h" #include "CardsStatusBar.h" #include "NumberFrame.h" #include "WarningPanel.h" #include "../dictionary/Dictionary.h" #include "../dictionary/Card.h" #include "../dictionary/CardPack.h" SpacedRepetitionWindow::SpacedRepetitionWindow( SpacedRepetitionModel* aModel, QWidget* aParent ): IStudyWindow( aModel, tr("Spaced repetition"), aParent ), exactAnswerLabel(NULL), exactAnswerEdit(NULL) { usesExactAnswer = m_model->getCardPack()->getUsesExactAnswer(); studyType = AppModel::SpacedRepetition; if(usesExactAnswer) createExactAnswerWidget(); createUI(); // Can't call from parent constructor setWindowIcon( QIcon(":/images/spaced-rep.png") ); dayCardsLimitShown = false; showNextCard(); } SpacedRepetitionWindow::~SpacedRepetitionWindow() { WriteSettings(); } void SpacedRepetitionWindow::createExactAnswerWidget() { exactAnswerEdit = new QLineEdit; exactAnswerLabel = new CardSideView; exactAnswerLabel->setMaximumHeight(40); exactAnswerLabel->setShowMode(CardSideView::AnsMode); exactAnswerLabel->setPack(m_model->getCardPack()); } QVBoxLayout* SpacedRepetitionWindow::createLowerPanel() { warningPanel = new WarningPanel; controlLt = new QVBoxLayout; controlLt->addWidget(warningPanel); controlLt->addLayout(createProgressLayout()); controlLt->addLayout(new QVBoxLayout); // Grades layout createGradeButtons(); return controlLt; } QBoxLayout* SpacedRepetitionWindow::createProgressLayout() { QVBoxLayout* lt = new QVBoxLayout; lt->setSpacing(3); lt->addLayout(createStatsLayout()); lt->addLayout(createProgressBarLayout()); return lt; } QBoxLayout* SpacedRepetitionWindow::createStatsLayout() { todayNewLabel = new NumberFrame; todayNewLabel->setToolTip(tr("Today learned new cards")); todayNewLabel->setColor("#c0d6ff"); learningCardsLabel = new NumberFrame; learningCardsLabel->setToolTip(tr("Scheduled learning reviews:\n" "new cards must be repeated today to learn")); learningCardsLabel->setColor(CardsStatusBar::Colors[1]); timeToNextLearningLabel = new QLabel; timeToNextLearningLabel->setToolTip(tr("Time left to the next learning review")); scheduledCardsLabel = new NumberFrame; scheduledCardsLabel->setToolTip(tr("Scheduled cards for today")); scheduledCardsLabel->setColor(CardsStatusBar::Colors[2]); scheduledNewLabel = new NumberFrame; scheduledNewLabel->setToolTip(tr("New scheduled cards for today:\n" "new cards that will be shown between the scheduled ones")); scheduledNewLabel->setColor("#bd8d71"); QHBoxLayout* lt = new QHBoxLayout; lt->setSpacing(5); lt->addWidget(todayNewLabel); lt->addStretch(); lt->addWidget(learningCardsLabel); lt->addWidget(timeToNextLearningLabel); lt->addWidget(scheduledCardsLabel); lt->addWidget(scheduledNewLabel); return lt; } QBoxLayout* SpacedRepetitionWindow::createProgressBarLayout() { progressLabel = new QLabel; progressLabel->setToolTip(getProgressBarTooltip()); coloredProgressBar = new CardsStatusBar; coloredProgressBar->setToolTip(progressLabel->toolTip()); QHBoxLayout* lt = new QHBoxLayout; lt->setSpacing(5); lt->addWidget(progressLabel); lt->addWidget(coloredProgressBar); return lt; } QString SpacedRepetitionWindow::getProgressBarTooltip() { QString boxSpace; for(int i = 0; i < 6; i++) boxSpace += " "; QString colorBoxPattern = "
" + boxSpace + " "; QString pEnd = "
"; QStringList legendLines = { tr("Reviewed cards"), tr("Learning reviews"), tr("Scheduled cards"), tr("New cards for today")}; QString legend; for(int i = 0; i < 4; i++) legend += colorBoxPattern.arg(CardsStatusBar::Colors[i]) + legendLines[i] + pEnd; return tr("Progress of reviews scheduled for today:") + legend; } void SpacedRepetitionWindow::createGradeButtons() { cardGradedSM = new QSignalMapper(this); connect( cardGradedSM, SIGNAL(mapped(int)), qobject_cast" + toolTip);
btn->setShortcut( QString::number(i + 1) );
btn->setMinimumWidth(GradeButtonMinWidth);
#if defined(Q_OS_WIN)
QFont font = btn->font();
font.setPointSize(12);
font.setFamily("Calibri");
btn->setFont(font);
#endif
cardGradedSM->setMapping(btn, i + 1);
connect(btn, SIGNAL(clicked()), cardGradedSM, SLOT(map()));
return btn;
}
void SpacedRepetitionWindow::processState()
{
setEnabledGradeButtons();
switch(state)
{
case StateAnswerHidden:
displayQuestion();
break;
case StateAnswerVisible:
displayAnswer();
break;
case StateNoCards:
updateCardsProgress();
displayNoRemainedCards();
break;
}
}
void SpacedRepetitionWindow::setEnabledGradeButtons()
{
for(int i = 0; i < StudyRecord::GradesNum; i++)
gradeBtns[i]->setEnabled(state == StateAnswerVisible);
}
void SpacedRepetitionWindow::displayQuestion()
{
questionLabel->setQuestion( m_model->getCurCard()->getQuestion() );
answerStackedLt->setCurrentIndex( AnsButtonPage );
updateCardsProgress();
layoutGradeButtons();
focusAnswerWidget();
m_answerTime.start();
processIsNewCard();
}
void SpacedRepetitionWindow::layoutGradeButtons()
{
QHBoxLayout* higherLt = new QHBoxLayout;
higherLt->addStretch();
putGradeButtonsIntoLayouts(higherLt);
higherLt->addStretch();
replaceGradesLayout(higherLt);
setGoodButtonText();
}
void SpacedRepetitionWindow::putGradeButtonsIntoLayouts(QBoxLayout* higherLt)
{
QList " +
tr("You can go to the next pack or dictionary, or open the Word drill.") +
"