//---------------------------------------------------------------------------
//  CardboxRescheduleDialog
//
//! Constructor.
//
//! @param parent the parent widget
//! @param f widget flags
//---------------------------------------------------------------------------
CardboxRescheduleDialog::CardboxRescheduleDialog(QWidget* parent, Qt::WFlags f)
    : QDialog(parent, f)
{
    QVBoxLayout* mainVlay = new QVBoxLayout(this);
    mainVlay->setMargin(MARGIN);
    mainVlay->setSpacing(SPACING);

    lexiconWidget = new LexiconSelectWidget;
    mainVlay->addWidget(lexiconWidget);

    QHBoxLayout* quizTypeHlay = new QHBoxLayout;
    mainVlay->addLayout(quizTypeHlay);

    QLabel* quizTypeLabel = new QLabel;
    quizTypeLabel->setText("Reschedule words for quiz type:");
    quizTypeHlay->addWidget(quizTypeLabel);

    quizTypeCombo = new QComboBox;
    quizTypeCombo->addItem(Auxil::quizTypeToString(QuizSpec::QuizAnagrams));
    quizTypeCombo->addItem(
        Auxil::quizTypeToString(QuizSpec::QuizAnagramsWithHooks));
    quizTypeCombo->addItem(Auxil::quizTypeToString(QuizSpec::QuizHooks));
    quizTypeHlay->addWidget(quizTypeCombo);

    QButtonGroup* methodGroup = new QButtonGroup(this);

    QHBoxLayout* backlogHlay = new QHBoxLayout;
    mainVlay->addLayout(backlogHlay);

    shiftQuestionsButton = new QRadioButton;
    shiftQuestionsButton->setText("Shift words so this many are ready now:");
    connect(shiftQuestionsButton, SIGNAL(toggled(bool)),
            SLOT(shiftQuestionsButtonToggled(bool)));
    methodGroup->addButton(shiftQuestionsButton);
    backlogHlay->addWidget(shiftQuestionsButton);

    backlogSbox = new QSpinBox;
    backlogSbox->setMinimum(1);
    backlogSbox->setMaximum(999999);
    backlogHlay->addWidget(backlogSbox);

    rescheduleQuestionsButton = new QRadioButton;
    rescheduleQuestionsButton->setText("Reschedule words according to "
                                       "their cardbox");
    methodGroup->addButton(rescheduleQuestionsButton);
    mainVlay->addWidget(rescheduleQuestionsButton);

    QFrame* hline = new QFrame;
    hline->setFrameShape(QFrame::HLine);
    mainVlay->addWidget(hline);

    QButtonGroup* selectGroup = new QButtonGroup(this);

    selectAllButton = new QRadioButton;
    selectAllButton->setText("Reschedule all words");
    selectGroup->addButton(selectAllButton);
    mainVlay->addWidget(selectAllButton);

    selectSearchButton = new QRadioButton;
    connect(selectSearchButton, SIGNAL(toggled(bool)),
            SLOT(useSearchButtonToggled(bool)));
    selectSearchButton->setText("Reschedule only words matching search "
                                "specification");
    selectGroup->addButton(selectSearchButton);
    mainVlay->addWidget(selectSearchButton);

    searchSpecGbox = new QGroupBox("Search Specification");
    mainVlay->addWidget(searchSpecGbox);

    QHBoxLayout* specHlay = new QHBoxLayout(searchSpecGbox);

    searchSpecForm = new SearchSpecForm;
    specHlay->addWidget(searchSpecForm);

    QHBoxLayout* buttonHlay = new QHBoxLayout;
    buttonHlay->setSpacing(SPACING);
    mainVlay->addLayout(buttonHlay);

    ZPushButton* okButton = new ZPushButton("&OK");
    okButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    okButton->setDefault(true);
    connect(okButton, SIGNAL(clicked()), SLOT(accept()));
    buttonHlay->addWidget(okButton);

    ZPushButton* cancelButton = new ZPushButton("Cancel");
    cancelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    connect(cancelButton, SIGNAL(clicked()), SLOT(reject()));
    buttonHlay->addWidget(cancelButton);

    setWindowTitle(DIALOG_CAPTION);
    shiftQuestionsButton->setChecked(true);
    selectAllButton->setChecked(true);
    searchSpecGbox->setEnabled(false);
}