#ifndef QUESTIONANDANSWER_H
#define QUESTIONANDANSWER_H

#include <QWidget>
#include <QTimer>
#include "paperDef.h"
#include "CBaseWidget.h"

#include "CHttpBll.h"

namespace Ui {
class questionAndAnswer;
}

class questionAndAnswer : public CQuestionBaseWidget
{
    Q_OBJECT

public:
    explicit questionAndAnswer(CSubQuestionStruct &sqs, QWidget *parent = nullptr);
    ~questionAndAnswer();

    int setUI(const int nWidth);

    void handinPaper();
    void audioPlayCountChange();
    int widgetType();
signals:
    void markedItem(bool bMarked, int nIndex);
    void questionAnswered(bool bAnswered, int nIndex);
    void uploadAnswer(int nIndex, __int64 timeStamp, QString sAnswer);
private slots:
    void on_btn_mark_clicked();
    void onAnswerChanged(bool bAnswer);    

    void onTimeout();
private:
    void initBody(Json::Value jBody, int nOrderIndex);
    void updateAnswer();
    QString generateAnswer(bool &bAnswered);
    bool eventFilter(QObject *obj, QEvent *ev);
    void setMarkStyle();
    Ui::questionAndAnswer *ui;

    CSubQuestionStruct &m_sqs;
    int m_nListHeight;
    bool b_isPressed;

    QTimer *m_pTimer;
    bool m_bAnswerChange;
    QString m_sAnswer;
    __int64 m_nTimeStap;
};

#endif // QUESTIONANDANSWER_H
