summaryrefslogtreecommitdiff
path: root/src/study/IStudyWindow.h
blob: 1f0bd0d73ba51e59fc8b27a7bf77c4fd738663e2 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef ISTUDYWINDOW_H
#define ISTUDYWINDOW_H

#include <QtCore>
#include <QtWidgets>

#include "../main-view/AppModel.h"

class IStudyModel;
class Card;
class Dictionary;
class QProgressBar;
class CardSideView;
class DictTableView;
class CardEditDialog;

class IStudyWindow: public QWidget
{
    Q_OBJECT

protected:
    enum
        {
        StateAnswerHidden,
        StateAnswerVisible,
        StateNoCards,
        StatesNum
        };

public:
    IStudyWindow(IStudyModel* aModel, QString aStudyName, QWidget* aParent);
    virtual ~IStudyWindow();

    AppModel::StudyType getStudyType() const { return studyType; }
    IStudyModel* studyModel() const { return m_model; }
    const DictTableView* cardEditView() const;

protected:
    void createUI();
    virtual QVBoxLayout* createLowerPanel() = 0;
    virtual void setStateForNextCard();
    virtual void processState() = 0;
    virtual void ReadSettings() = 0;
    virtual QWidget* getAnswerEdit() { return NULL; }
    virtual QWidget* getUserAnswerLabel() { return NULL; }
    QString ShortcutToStr( QAbstractButton* aButton );
    bool bigScreen() { return QApplication::desktop()->screenGeometry().height()> 250; }

private:
    QVBoxLayout* createMessageLayout();
    QLabel* createMessageLabel();
    QWidget* createWrapper(QBoxLayout* layout);
    QPushButton* createClosePackButton();
    QHBoxLayout* createUpperPanel();
    QToolButton* createEditCardButton();
    QToolButton* createDeleteCardButton();
    QVBoxLayout* createCardView();    
    QBoxLayout* createAnswerButtonLayout();
    QPushButton* createAnswerButton();
    QBoxLayout* createAnswerLayout();

protected slots:
    void OnDictionaryRemoved();
    void showNextCard();    ///< Entry point for showing a new card
    void showAnswer();      ///< Entry point for showing the answer
    void updateCurCard();   ///< Update the card after pack re-generation
    void invalidateCurCard() { curCard = NULL; }
    void openCardEditDialog();
    void deleteCard();
    void updateToolBarVisibility(int index);
    
protected:
    static const int AnsButtonPage;
    static const int AnsLabelPage;
    static const int CardPage;
    static const int MessagePage;

    AppModel::StudyType studyType;
    IStudyModel* m_model;
    const Card* curCard;
    int state;

    QString m_studyName;
    QToolButton* editCardBtn;
    QToolButton* deleteCardBtn;

    QStackedLayout* centralStackedLt;
    QLabel* messageLabel;

    QStackedLayout* answerStackedLt;
    QPushButton* answerBtn;
    CardSideView* questionLabel;
    CardSideView* answerLabel;

private:
    static const int MinWidth = 500;
    static const int MaxWidth = 800;
    static const int ToolBarButtonSize = 24;
    static const int ToolBarIconSize = 16;
    static const int BigButtonWidth = 160;
    static const int BigButtonHeight = 50;

    QWidget* m_parentWidget;
    CardEditDialog* m_cardEditDialog;
};

#endif