File indexing completed on 2024-04-14 03:40:29

0001 /***************************************************************************
0002  *   Copyright (C) 2004-2005 by Albert Astals Cid                          *
0003  *   aacid@kde.org                                                         *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "answersdialog.h"
0012 
0013 #include <KLocalizedString>
0014 
0015 #include <QLabel>
0016 #include <QLayout>
0017 #include <QScrollArea>
0018 #include <QDialogButtonBox>
0019 
0020 #include "answer.h"
0021 
0022 answersDialog::answersDialog(QWidget *parent, const QVector<userAnswer> &userAnswers, const QString &question, int correctAnswers)
0023     : QDialog(parent)
0024 {
0025     setWindowTitle(i18n("Your Answers Were"));
0026 
0027     QVBoxLayout *mainLayout = new QVBoxLayout;
0028 
0029     p_scrollArea = new QScrollArea(this);
0030     mainLayout->addWidget(p_scrollArea);
0031 
0032     p_container = new QWidget(this);
0033     p_scrollArea -> setWidget(p_container);
0034     p_scrollArea -> setWidgetResizable(true);
0035 
0036     uint totalAnswers = userAnswers.count();
0037     
0038     QGridLayout *gridLayout = new QGridLayout(p_container);
0039     int spacing = gridLayout -> spacing();
0040     gridLayout -> setSpacing(0);
0041     gridLayout -> setColumnStretch(0, 1);
0042     gridLayout -> setColumnStretch(4, 1);
0043     gridLayout -> setRowStretch(totalAnswers + 4, 1);
0044     
0045     p_container->setLayout(gridLayout);
0046 
0047     QFont titleFont = p_container -> font();
0048     titleFont.setPointSize(24);
0049 
0050     QLabel *titleLabel = new QLabel(question);
0051     titleLabel -> setFont(titleFont);
0052     gridLayout -> addWidget(titleLabel, 0, 0, 1, 5, Qt::AlignHCenter);
0053 
0054     QLabel *correctAnswersInfoLabel = new QLabel(i18n("You answered correctly %1 out of %2 questions.", correctAnswers, totalAnswers));
0055     correctAnswersInfoLabel -> setAlignment(Qt::AlignCenter);
0056     gridLayout -> addWidget(correctAnswersInfoLabel, 1, 0, 1, 5);
0057 
0058     QFont headerFont = p_container -> font();
0059     headerFont.setBold(true);
0060     
0061     QLabel *questionHeaderLabel = new QLabel(i18n("Question"));
0062     questionHeaderLabel -> setFont(headerFont);
0063     questionHeaderLabel -> setContentsMargins(spacing, spacing, spacing, spacing);
0064     gridLayout->addWidget(questionHeaderLabel, 2, 1);
0065 
0066     QLabel *userAnswerHeaderLabel = new QLabel(i18n("Your Answer"));
0067     userAnswerHeaderLabel -> setFont(headerFont);
0068     userAnswerHeaderLabel -> setContentsMargins(spacing, spacing, spacing, spacing);
0069     gridLayout->addWidget(userAnswerHeaderLabel, 2, 2);
0070 
0071     QLabel *correctAnswerHeaderLabel = new QLabel(i18n("Correct Answer"));
0072     correctAnswerHeaderLabel -> setFont(headerFont);
0073     correctAnswerHeaderLabel     -> setContentsMargins(spacing, spacing, spacing, spacing);
0074     gridLayout->addWidget(correctAnswerHeaderLabel, 2, 3);
0075 
0076     for(uint i = 0; i < totalAnswers; i++)
0077     {
0078         userAnswers[i].putWidgets(p_container, gridLayout, i + 3, spacing);
0079     }
0080 
0081     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
0082     connect(buttonBox, &QDialogButtonBox::accepted, this, &answersDialog::accept);
0083     mainLayout->addWidget(buttonBox);
0084 
0085     setLayout(mainLayout);
0086 
0087     resize(500, 500);
0088 }
0089