privacyWidget.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #include "privacyWidget.h"
  2. #include "ui_privacyWidget.h"
  3. #include <QDesktopWidget>
  4. #include <QScrollBar>
  5. #include "CAppInfo.h"
  6. #include "json/json.h"
  7. #include "awMsgBox.h"
  8. #include "logproc.h"
  9. #include "CSqlite3DBProc.h"
  10. #include "CCommonTools.h"
  11. privacyWidget::privacyWidget(QWidget *parent) :
  12. QWidget(parent),
  13. ui(new Ui::privacyWidget)
  14. {
  15. ui->setupUi(this);
  16. setWindowFlags(Qt::FramelessWindowHint);
  17. setStyleSheet(g_appInfoPtr->m_sQssStr);
  18. qRegisterMetaType<CAgreement>("CAgreement");
  19. connect(g_httpBllPtr.get(), &CHttpBll::sgnAgreement, this, &privacyWidget::onAgreement);
  20. CHttpRequestPackage hrp;
  21. hrp.sUri = QString("https://%1/oe_client/pc/agreement.json").arg(g_appInfoPtr->m_sEscDomain);
  22. hrp.nRequestType = RequestType::rtAgreement;
  23. g_httpBllPtr->getUrl(hrp);
  24. m_pTimer = std::make_shared<QTimer>();
  25. m_pTimer->setInterval(1000);
  26. connect(m_pTimer.get(), &QTimer::timeout, this, [&]() {
  27. --m_nStaySeconds;
  28. if (m_nStaySeconds == 0)
  29. {
  30. m_pTimer->stop();
  31. ui->btn_pw_agree->setText(QString::fromLocal8Bit("同意"));
  32. QString sStyle = QString(R"(QPushButton#btn_pw_agree
  33. {
  34. outline:none;
  35. background:rgba(19,186,140,1);
  36. border-radius:%1px;
  37. font-size:%2px;
  38. font-family:"Microsoft YaHei";
  39. font-weight:400;
  40. color:rgba(255,255,255,1);
  41. })").arg((int)(g_appInfoPtr->m_fRate*6))
  42. .arg((int)(g_appInfoPtr->m_fRate*14));
  43. ui->btn_pw_agree->setStyleSheet(sStyle);
  44. }
  45. else
  46. {
  47. ui->btn_pw_agree->setText(QString::fromLocal8Bit("同意 (%1秒)").arg(m_nStaySeconds));
  48. }
  49. });
  50. initUI();
  51. }
  52. privacyWidget::~privacyWidget()
  53. {
  54. awMsgBox::clear(this);
  55. delete ui;
  56. }
  57. void privacyWidget::initAgreement(QString sContent)
  58. {
  59. ui->txtb_pw_privacy->verticalScrollBar()->setStyleSheet(QString(R"(QScrollBar:vertical
  60. {
  61. border:0px;
  62. background:rgba(255,255,255,1);
  63. width:%1px;
  64. margin:0 %2 0 %3px;
  65. }
  66. QScrollBar::handle:vertical
  67. {
  68. background:rgba(227,228,232,1);
  69. border-radius:%4px;
  70. }
  71. QScrollBar::add-line:vertical
  72. {
  73. border:0px solid rgba(227,228,232,1);
  74. background:rgba(255,255,255,1);
  75. }
  76. QScrollBar::sub-line:vertical
  77. {
  78. border:0px solid rgba(255,255,255,1);
  79. background:rgba(255,255,255,1);
  80. }
  81. QScrollBar::up-arrow:vertical,QScrollBar::down-arrow:vertical
  82. {
  83. border:0px solid rgba(255,255,255,1);
  84. width:0px;
  85. height:0px;
  86. background:rgba(255,255,255,1);
  87. }
  88. QScrollBar::add-page:vertical
  89. {
  90. background:rgba(255,255,255,1);
  91. }
  92. QScrollBar::sub-page:vertical
  93. {
  94. background:rgba(255,255,255,1);
  95. })").arg((int)(g_appInfoPtr->m_fRate * 40))
  96. .arg((int)(g_appInfoPtr->m_fRate * 12))
  97. .arg((int)(g_appInfoPtr->m_fRate * 20))
  98. .arg((int)(g_appInfoPtr->m_fRate * 4)));
  99. Json::Reader reader;
  100. Json::Value jsonRoot = Json::Value::null;
  101. if (!reader.parse(sContent.toStdString(), jsonRoot))
  102. {
  103. ShowMsg(QString::fromLocal8Bit("加载隐私协议出错"), this, MSG_ICON_TYPE::mit_error);
  104. qDebug() << sContent;
  105. }
  106. QTextCursor cursor = ui->txtb_pw_privacy->textCursor();
  107. QTextBlockFormat textStyleFormat = cursor.blockFormat();
  108. // textStyleFormat.setTextIndent(26); //首行缩进
  109. textStyleFormat.setLineHeight(10, QTextBlockFormat::LineDistanceHeight);
  110. cursor.setBlockFormat(textStyleFormat);
  111. int nSize = jsonRoot["sections"].size();
  112. for (int i = 0; i < nSize; i++)
  113. {
  114. Json::Value blocks = jsonRoot["sections"][i];
  115. for (int j = 0; j < (int)blocks["blocks"].size(); j++)
  116. {
  117. if (blocks["blocks"][j]["type"].asString() == "text")
  118. {
  119. QTextCharFormat fmt;
  120. QFont font;
  121. font.setFamily("Microsoft YaHei");
  122. font.setPixelSize(g_appInfoPtr->m_fRate*12);
  123. font.setWeight(QFont::Medium);
  124. if (blocks["blocks"][j].isMember("param"))
  125. {
  126. if (blocks["blocks"][j]["param"].isMember("bold"))
  127. {
  128. font.setBold(blocks["blocks"][j]["param"]["bold"].asBool());
  129. }
  130. if (blocks["blocks"][j]["param"].isMember("italic"))
  131. {
  132. bool bstyle = blocks["blocks"][j]["param"]["italic"].asBool();
  133. font.setItalic(bstyle);
  134. }
  135. if (blocks["blocks"][j]["param"].isMember("underline"))
  136. {
  137. font.setUnderline(blocks["blocks"][j]["param"]["underline"].asBool());
  138. }
  139. if (blocks["blocks"][j]["param"].isMember("strikeOut"))
  140. {
  141. font.setStrikeOut(blocks["blocks"][j]["param"]["strikeOut"].asBool());
  142. }
  143. if (blocks["blocks"][j]["param"].isMember("size"))
  144. {
  145. font.setPixelSize(blocks["blocks"][j]["param"]["size"].asInt());
  146. }
  147. if (blocks["blocks"][j]["param"].isMember("name"))
  148. {
  149. font.setFamily(blocks["blocks"][j]["param"]["name"].asString().c_str());
  150. }
  151. }
  152. fmt.setFont(font);
  153. QString sTextStr = blocks["blocks"][j]["value"].asString().c_str();
  154. cursor.insertText(blocks["blocks"][j]["value"].asString().c_str(), fmt);
  155. }
  156. else if (blocks["blocks"][j]["type"].asString() == "image")
  157. {
  158. QString sImage = blocks["blocks"][j]["value"].asString().c_str();
  159. if(!(sImage.startsWith("http") || sImage.startsWith("data:image")))
  160. {
  161. sImage = QString("temp/paper/attachment/") + sImage;
  162. }
  163. if(sImage.startsWith("data:image"))
  164. {
  165. QImage img;
  166. img = QImage::fromData(QByteArray::fromBase64(CCommonTools::getImageRawBase64Str(sImage).toLatin1()));
  167. if(blocks["blocks"][j]["param"].isMember("width")
  168. && !QString(blocks["blocks"][j]["param"]["width"].asString().c_str()).isEmpty() &&
  169. !QString(blocks["blocks"][j]["param"]["height"].asString().c_str()).isEmpty())
  170. {
  171. img = img.scaled(QString(blocks["blocks"][j]["param"]["width"].asString().c_str()).toInt(),
  172. QString(blocks["blocks"][j]["param"]["height"].asString().c_str()).toInt(),
  173. Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  174. }
  175. cursor.insertImage(img);
  176. }
  177. else
  178. {
  179. QImage img(sImage);
  180. if(blocks["blocks"][j]["param"].isMember("width") && !QString(blocks["blocks"][j]["param"]["width"].asString().c_str()).isEmpty() &&
  181. !QString(blocks["blocks"][j]["param"]["height"].asString().c_str()).isEmpty())
  182. {
  183. img = img.scaled(QString(blocks["blocks"][j]["param"]["width"].asString().c_str()).toInt(),
  184. QString(blocks["blocks"][j]["param"]["height"].asString().c_str()).toInt(),
  185. Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  186. }
  187. cursor.insertImage(img);
  188. }
  189. // QString strHtml = "";
  190. // if (blocks["blocks"][j]["param"].isMember("width"))
  191. // {
  192. // strHtml = QString("<img src=\"%1\" height=\"%2\" width=\"%3\" align=\"bottom\" />")
  193. // .arg(blocks["blocks"][j]["value"].asString().c_str())
  194. // .arg(blocks["blocks"][j]["param"]["height"].asString().c_str())
  195. // .arg(blocks["blocks"][j]["param"]["width"].asString().c_str());
  196. // }
  197. // else
  198. // {
  199. // strHtml = "<img src=\"" + QString::fromLocal8Bit(blocks["blocks"][j]["value"].asString().c_str()) + "\" align=\"bottom\" />";
  200. // }
  201. // cursor.insertHtml(strHtml);
  202. }
  203. }
  204. if (i < nSize - 1)
  205. {
  206. cursor.insertText("\n");
  207. }
  208. }
  209. cursor.movePosition(QTextCursor::Start);
  210. ui->txtb_pw_privacy->setTextCursor(cursor);
  211. }
  212. void privacyWidget::initUI()
  213. {
  214. QDesktopWidget *dekwiget = QApplication::desktop();
  215. setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  216. ui->widget_mask->setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  217. ui->widget_pw_BG->setGeometry((width() - g_appInfoPtr->m_fRate*700)/2, (height() - g_appInfoPtr->m_fRate*591)/2,
  218. g_appInfoPtr->m_fRate*700, g_appInfoPtr->m_fRate*591);
  219. ui->label_pw_title->adjustSize();
  220. ui->label_pw_title->setGeometry(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*16,
  221. ui->label_pw_title->width(), ui->label_pw_title->height());
  222. ui->btn_pw_close->setGeometry(ui->widget_pw_BG->width() - g_appInfoPtr->m_fRate*(20 + 16), g_appInfoPtr->m_fRate*19,
  223. g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*16);
  224. ui->label_HLine_top->setGeometry(0, g_appInfoPtr->m_fRate*54, ui->widget_pw_BG->width(), g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1);
  225. ui->txtb_pw_privacy->setGeometry(0, ui->label_HLine_top->y() + ui->label_HLine_top->height() + g_appInfoPtr->m_fRate*20,
  226. ui->widget_pw_BG->width(), g_appInfoPtr->m_fRate*432);
  227. ui->label_HLine_bottom->setGeometry(0, ui->txtb_pw_privacy->y() + ui->txtb_pw_privacy->height() + g_appInfoPtr->m_fRate*19,
  228. ui->widget_pw_BG->width(), g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1);
  229. ui->btn_pw_agree->setGeometry(g_appInfoPtr->m_fRate*185, ui->label_HLine_bottom->y() + ui->label_HLine_bottom->height() + g_appInfoPtr->m_fRate*12,
  230. g_appInfoPtr->m_fRate*160, g_appInfoPtr->m_fRate*40);
  231. ui->btn_pw_disagree->setGeometry(ui->btn_pw_agree->x() + ui->btn_pw_agree->width() + g_appInfoPtr->m_fRate*10, ui->btn_pw_agree->y(),
  232. ui->btn_pw_agree->width(), ui->btn_pw_agree->height());
  233. }
  234. void privacyWidget::onAgreement(CAgreement agreement)
  235. {
  236. if (agreement.nCode = 200)
  237. {
  238. ui->label_pw_title->setText(agreement.sTitle);
  239. ui->label_pw_title->adjustSize();
  240. ui->label_pw_title->setGeometry(g_appInfoPtr->m_fRate * 20, g_appInfoPtr->m_fRate * 16,
  241. ui->label_pw_title->width(), ui->label_pw_title->height());
  242. m_nStaySeconds = agreement.nStaySeconds;
  243. initAgreement(agreement.sContent);
  244. m_pTimer->start();
  245. }
  246. else
  247. {
  248. }
  249. }
  250. void privacyWidget::on_btn_pw_agree_clicked()
  251. {
  252. if (m_nStaySeconds > 0)
  253. {
  254. return;
  255. }
  256. QString sSql = QString("insert or replace into t_agreement (student_id,agreement) values(%1,1)").arg(g_appInfoPtr->m_nStudentId);
  257. if (!g_sysDBProcPtr->ExcuteSql(sSql.toStdString()))
  258. {
  259. ShowMsg(QString::fromLocal8Bit("保存隐私协议信息失败!"), this, MSG_ICON_TYPE::mit_error);
  260. }
  261. emit agreement();
  262. }
  263. void privacyWidget::on_btn_pw_disagree_clicked()
  264. {
  265. emit disAgreement();
  266. }
  267. void privacyWidget::on_btn_pw_close_clicked()
  268. {
  269. emit disAgreement();
  270. }