summaryrefslogtreecommitdiff
path: root/src/main-view/CardPreview.cpp
blob: aa5903103e08799f1876555a6bf3ed70723be3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "CardPreview.h"
#include "../study/CardSideView.h"
#include "../dictionary/Card.h"

CardPreview::CardPreview(QWidget* parent):
	QDockWidget(parent)
{
    setDockProperties();
    createCardSides();
    createInternalWidget();
}

void CardPreview::setDockProperties()
{
    setWindowTitle(tr("Card preview"));
    setObjectName("Card-preview");
    setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
}

void CardPreview::createCardSides()
{
    questionSide = new CardSideView(CardSideView::QstMode);
    answerSide = new CardSideView(CardSideView::AnsMode);
}

void CardPreview::createInternalWidget()
{
    QVBoxLayout* mainLt = new QVBoxLayout;
    mainLt->addWidget(questionSide, 1);
    mainLt->addWidget(answerSide, 1);

    QWidget* internalWidget = new QWidget;
    internalWidget->setLayout(mainLt);
    setWidget(internalWidget);
}

void CardPreview::setPack(const CardPack* pack)
{
    questionSide->setPack(pack);
    answerSide->setPack(pack);
}

void CardPreview::setContent(const CardPack* pack, Card* card)
{
    setPack(pack);
    QString question;
    QStringList answers;
    if(card)
    {
        question = card->getQuestion();
        answers = card->getAnswers();
    }
    questionSide->setQuestion(question);
    answerSide->setQstAnsr(question, answers);
}