addPic.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #include "addPic.h"
  2. #include "ui_addPic.h"
  3. #include "CAppInfo.h"
  4. addPic::addPic(int nOrder, QWidget *parent) :
  5. CBaseWidget(parent),
  6. ui(new Ui::addPic), m_nOrder(nOrder)
  7. {
  8. ui->setupUi(this);
  9. setStyleSheet(g_appInfoPtr->m_sQssStr);
  10. if(m_picList == nullptr)
  11. {
  12. m_picList = std::make_shared<wPictureList>(g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*10, this);
  13. connect(m_picList.get(), &wPictureList::picChange, this, [&](){
  14. QString sFileUrls = m_picList->getFileUrls();
  15. m_sFileUrls = sFileUrls;
  16. QStringList fileList;
  17. if(!sFileUrls.isEmpty())
  18. {
  19. fileList = sFileUrls.split(",");
  20. }
  21. int nPicWidth = 0;
  22. if (fileList.count() > 5)
  23. {
  24. nPicWidth = g_appInfoPtr->m_fRate * (100+10) * 6;
  25. ui->btn_addPic->setVisible(false);
  26. }
  27. else
  28. {
  29. ui->btn_addPic->setVisible(true);
  30. nPicWidth = g_appInfoPtr->m_fRate * (100+10) * fileList.count();
  31. }
  32. int nHeight = m_picList->setUI(0, g_appInfoPtr->m_fRate * 10,
  33. nPicWidth);
  34. m_picList->show();
  35. ui->btn_addPic->setGeometry(m_picList->width(), g_appInfoPtr->m_fRate*10, g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*100);
  36. emit answerChanged(fileList.count()>0);
  37. });
  38. }
  39. }
  40. addPic::~addPic()
  41. {
  42. delete ui;
  43. }
  44. int addPic::setUI(const int nWidth)
  45. {
  46. ui->btn_addPic->setGeometry(0, g_appInfoPtr->m_fRate*10, g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*100);
  47. ui->label_ap_tips->adjustSize();
  48. ui->label_ap_tips->setGeometry(ui->btn_addPic->x(), ui->btn_addPic->y() + ui->btn_addPic->height() + g_appInfoPtr->m_fRate*6,
  49. ui->label_ap_tips->width(), ui->label_ap_tips->height());
  50. setGeometry(0, 0, nWidth, ui->label_ap_tips->y() + ui->label_ap_tips->height() + g_appInfoPtr->m_fRate*10);
  51. return height();
  52. }
  53. int addPic::widgetType()
  54. {
  55. return wt_photoAnswer;
  56. }
  57. void addPic::on_btn_addPic_clicked()
  58. {
  59. if(m_pWxAnswer == nullptr)
  60. {
  61. m_pWxAnswer = std::make_shared<wxAnswer>("MULTIPLE_PICTURES", m_nOrder, g_appInfoPtr->m_pAnsBgWidget);
  62. m_pWxAnswer->setUI(0);
  63. m_pWxAnswer->setPics(m_sFileUrls);
  64. connect(m_pWxAnswer.get(), &wxAnswer::exit, this, [&]() {
  65. m_pWxAnswer.reset();
  66. });
  67. connect(m_pWxAnswer.get(), &wxAnswer::picConfirm, this, [&](QString sFileUrls){
  68. m_sFileUrls = sFileUrls;
  69. m_pWxAnswer.reset();
  70. if(m_picList == nullptr)
  71. {
  72. m_picList = std::make_shared<wPictureList>(g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*10, this);
  73. }
  74. m_picList->clearPic();
  75. QStringList fileList;
  76. if(!m_sFileUrls.isEmpty())
  77. {
  78. fileList = m_sFileUrls.split(",");
  79. for(QString sFile : fileList)
  80. {
  81. m_picList->AddPic(sFile);
  82. }
  83. }
  84. int nPicWidth = 0;
  85. if (fileList.count() > 5)
  86. {
  87. nPicWidth = g_appInfoPtr->m_fRate * (100+10) * 6;
  88. ui->btn_addPic->setVisible(false);
  89. }
  90. else
  91. {
  92. nPicWidth = g_appInfoPtr->m_fRate * (100+10) * fileList.count();
  93. }
  94. int nHeight = m_picList->setUI(0, g_appInfoPtr->m_fRate * 10,
  95. nPicWidth);
  96. m_picList->show();
  97. ui->btn_addPic->setGeometry(m_picList->width(), g_appInfoPtr->m_fRate*10, g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*100);
  98. emit answerChanged(fileList.count()>0);
  99. });
  100. }
  101. m_pWxAnswer->show();
  102. }
  103. QString addPic::getFileUrl()
  104. {
  105. return m_picList->getFileUrls();
  106. }
  107. void addPic::setAnswer(QString sAnswer)
  108. {
  109. m_sFileUrls = sAnswer;
  110. m_picList->clearPic();
  111. QStringList fileList;
  112. if(!m_sFileUrls.isEmpty())
  113. {
  114. fileList = m_sFileUrls.split(",");
  115. for(QString sFile : fileList)
  116. {
  117. m_picList->AddPic(sFile);
  118. }
  119. }
  120. int nPicWidth = 0;
  121. if (fileList.count() > 5)
  122. {
  123. nPicWidth = g_appInfoPtr->m_fRate * (100+10)*6;
  124. ui->btn_addPic->setVisible(false);
  125. }
  126. else
  127. {
  128. nPicWidth = g_appInfoPtr->m_fRate * (100+10) * fileList.count();
  129. }
  130. int nHeight = m_picList->setUI(0, g_appInfoPtr->m_fRate * 10,
  131. nPicWidth);
  132. m_picList->show();
  133. ui->btn_addPic->setGeometry(m_picList->width(), g_appInfoPtr->m_fRate*10, g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*100);
  134. }