fbBlank.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include "fbBlank.h"
  2. #include "ui_fbBlank.h"
  3. #include <QFile>
  4. #include <QTextBlock>
  5. //#include "MsgDlg.h"
  6. #include "CAppInfo.h"
  7. fbBlank::fbBlank(int nOrder, QWidget *parent) :
  8. CBaseWidget(parent),
  9. ui(new Ui::fbBlank)
  10. {
  11. ui->setupUi(this);
  12. setAttribute(Qt::WA_DeleteOnClose);
  13. m_nOrder = nOrder;
  14. // QFile qssFile(":/qss/main.qss");
  15. // qssFile.open(QFile::ReadOnly);
  16. // QString qss;
  17. // qss = qssFile.readAll();
  18. // setStyleSheet(qss);
  19. setStyleSheet(g_appInfoPtr->m_sQssStr);
  20. }
  21. fbBlank::~fbBlank()
  22. {
  23. delete ui;
  24. }
  25. int fbBlank::setUI(const int nWidth)
  26. {
  27. setGeometry(0, 0, nWidth, g_appInfoPtr->m_fRate*60);
  28. QString sText = QChar('A' + m_nOrder -1);
  29. ui->btn_blankName->setText(sText);
  30. ui->btn_blankName->setGeometry(0, g_appInfoPtr->m_fRate*15, g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*30);
  31. ui->tedt_blank->setGeometry(ui->btn_blankName->x() + ui->btn_blankName->width() + g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*10, g_appInfoPtr->m_fRate*640, g_appInfoPtr->m_fRate*40);
  32. return g_appInfoPtr->m_fRate*60;
  33. }
  34. int fbBlank::widgetType()
  35. {
  36. return wt_blank;
  37. }
  38. void fbBlank::on_tedt_blank_textChanged()
  39. {
  40. QApplication::processEvents();
  41. emit answerChanged();
  42. }
  43. QString fbBlank::getAnswer()
  44. {
  45. return ui->tedt_blank->toPlainText();
  46. // Json::Value jBody = Json::Value::null;
  47. // auto bodyDoc = ui->tedt_blank->document();
  48. // if(bodyDoc->isEmpty())
  49. // {
  50. // jBody = Json::ValueType::arrayValue;
  51. // }
  52. // else
  53. // {
  54. // Json::Value sectionJson = Json::Value::null;
  55. // for (QTextBlock it = bodyDoc->begin(); it != bodyDoc->end(); it = it.next())
  56. // {
  57. // Json::Value blocksJson = Json::Value::null;
  58. // for(auto fragit = it.begin(); !fragit.atEnd(); ++fragit)
  59. // {
  60. // if(fragit.fragment().charFormat().isImageFormat())
  61. // {//图片
  62. // const std::string& txt = fragit.fragment().charFormat().toImageFormat().name().toLocal8Bit().toStdString();
  63. // if(0 == txt.find_first_of("data:image/"))
  64. // {
  65. // }
  66. // else
  67. // {
  68. // }
  69. // }
  70. // else
  71. // {//文本
  72. // Json::Value blockItem;
  73. // blockItem["type"] = "text";
  74. // blockItem["value"] = fragit.fragment().text().toStdString();
  75. //// //加粗
  76. //// if(fragit.fragment().charFormat().fontWeight() == QFont::Bold)
  77. //// {
  78. //// blockItem["param"]["font"]["bold"] = true;
  79. //// }
  80. //// //斜体
  81. //// if(fragit.fragment().charFormat().fontItalic())
  82. //// {
  83. //// blockItem["param"]["font"]["italic"] = true;
  84. //// }
  85. //// //下划线
  86. //// if(fragit.fragment().charFormat().fontUnderline())
  87. //// {
  88. //// blockItem["param"]["font"]["underline"] = true;
  89. //// }
  90. // blocksJson.append(blockItem);
  91. // }
  92. // }
  93. // Json::Value sectionItem = Json::Value::null;
  94. // if(blocksJson.size() > 0)
  95. // {
  96. // sectionItem["blocks"] = blocksJson;
  97. // }
  98. // else
  99. // {
  100. // sectionItem["blocks"] = Json::ValueType::arrayValue;
  101. // }
  102. // sectionJson.append(sectionItem);
  103. // }
  104. // if(sectionJson.size() > 0)
  105. // {
  106. // jBody = sectionJson;
  107. // }
  108. // else
  109. // {
  110. // jBody = Json::ValueType::arrayValue;
  111. // }
  112. // }
  113. // return jBody;
  114. }
  115. void fbBlank::setAnswer(QString sAnswer)
  116. {
  117. ui->tedt_blank->setText(sAnswer);
  118. // QTextCursor cursor = ui->tedt_blank->textCursor();
  119. // int nSize = jAnswer.size();
  120. // for(int i = 0; i < nSize; i ++)
  121. // {
  122. // Json::Value blocks = jAnswer[i];
  123. // for(int j = 0; j < (int)blocks["blocks"].size(); j++)
  124. // {
  125. // if(blocks["blocks"][j]["type"].asString() == "text")
  126. // {
  127. // QTextCharFormat fmt;
  128. // QFont font;
  129. // font.setFamily("Microsoft YaHei");
  130. // font.setPixelSize(g_appInfoPtr->m_fRate*14);
  131. // font.setWeight(QFont::Medium);
  132. // fmt.setFont(font);
  133. // cursor.insertText((blocks["blocks"][j]["value"].asString().c_str()), fmt);
  134. // }
  135. // }
  136. // if(i < nSize - 1)
  137. // {
  138. // cursor.insertText("\n");
  139. // }
  140. // }
  141. // ui->tedt_blank->setTextCursor(cursor);
  142. }