frmalbum.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include "frmalbum.h"
  2. #include "ui_frmalbum.h"
  3. #include <QUrl>
  4. int FrmAlbum::m_copyType = 0;
  5. FrmAlbum::FrmAlbum(QWidget *parent) : QWidget(parent)
  6. {
  7. initForm();
  8. }
  9. FrmAlbum::~FrmAlbum()
  10. {
  11. delete ui;
  12. }
  13. // QSet<QString> FrmAlbum::getUrlSet()
  14. // {
  15. // return m_selectedImageSet;
  16. // }
  17. int FrmAlbum::getCopyType()
  18. {
  19. return m_copyType;
  20. }
  21. void FrmAlbum::slot_updateImage()
  22. {
  23. picWidgetList.clear();
  24. panelWidget->clearWidgets();
  25. QList<QUrl> urls = ImageManager::instance()->getImageUrls(FileConfigDecode::getInstance()->getAddress(),
  26. FileConfigDecode::getInstance()->getUserName());
  27. qDebug() <<urls.size();
  28. foreach (const QUrl& u, urls) {
  29. FrmImgShow* widget = new FrmImgShow(this);
  30. connect(widget, &FrmImgShow::signal_imageSelected, [this](const QString& url){
  31. m_selectedImageSet.insert(url);
  32. });
  33. connect(widget, &FrmImgShow::signal_imageUnselected, [this](const QString& url){
  34. m_selectedImageSet.remove(url);
  35. });
  36. connect(widget, &FrmImgShow::signal_imageDelete, this, &FrmAlbum::slot_updateImage);
  37. widget->loadImage(u);
  38. picWidgetList.push_back(widget);
  39. // panelWidget->setWidget(picWidgetList, 3);
  40. }
  41. panelWidget->setWidget(picWidgetList, 4);
  42. panelWidget->setSpace(15);
  43. }
  44. void FrmAlbum::initForm()
  45. {
  46. layout = new QVBoxLayout(this);
  47. setLayout(layout);
  48. panelWidget = new PanelWidget(this);
  49. panelWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  50. panelWidget->setStyleSheet("border:1px solid white;");
  51. panelWidget->setSpace(5);
  52. layout->setContentsMargins(0, 0, 0, 0);
  53. layout->setSpacing(0);
  54. panelWidget->setObjectName("widget");
  55. panelWidget->setStyleSheet("background-color: rgb(63, 60, 55)");
  56. // panelWidget->setStyleSheet("background-color: #FFFFFF");
  57. panelWidget->setAutoHeight(false);
  58. panelWidget->setAutoWidth(false);
  59. panelWidget->setAutoHeight(false);
  60. panelWidget->setAutoWidth(false);
  61. btnCopy = new QPushButton;
  62. btnCopy->setText("复制");
  63. btnCopy->setCursor(Qt::PointingHandCursor);
  64. btnCopy->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  65. btnCopy->setStyleSheet("height:25px;width:70px;background-color:#1B9EF3;color:white;border-style:none;border-radius:8px");
  66. connect(btnCopy, &QPushButton::clicked, [this](){
  67. QString clipStr = "";
  68. foreach (QString s, m_selectedImageSet) {
  69. switch (cbbCopyType->currentIndex()) {
  70. case 0:
  71. {
  72. QString curStr = QString("![](%1)").arg(s);
  73. curStr += "\n";
  74. clipStr += curStr;
  75. break;
  76. }
  77. case 1:
  78. {
  79. QString curStr = QString("%1").arg(s);
  80. curStr += "\n";
  81. clipStr += curStr;
  82. break;
  83. }
  84. case 2:
  85. {
  86. QString curStr = QString("<img src=\"%1\"/>").arg(s);
  87. curStr += "\n";
  88. clipStr += curStr;
  89. break;
  90. }
  91. case 3:
  92. {
  93. QString curStr = QString("[IMG]%1[/IMG]").arg(s);
  94. curStr += "\n";
  95. clipStr += curStr;
  96. break;
  97. }
  98. }
  99. }
  100. QClipboard* clipboard = QApplication::clipboard();
  101. clipboard->setText(clipStr);
  102. });
  103. btnDelete = new QPushButton;
  104. btnDelete->setText("删除");
  105. btnDelete->setCursor(Qt::PointingHandCursor);
  106. btnDelete->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  107. btnDelete->setStyleSheet("height:25px;width:70px;background-color:#F15140;color:white;border-style:none;border-radius:8px");
  108. btnSelectAll = new QPushButton;
  109. btnSelectAll->setText("全选");
  110. btnSelectAll->setCursor(Qt::PointingHandCursor);
  111. btnSelectAll->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  112. btnSelectAll->setStyleSheet("height:25px;width:70px;background-color:#44B363;color:white;border-style:none;border-radius:8px");
  113. cbbCopyType = new QComboBox;
  114. cbbCopyType->setCursor(Qt::PointingHandCursor);
  115. cbbCopyType->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  116. cbbCopyType->setStyleSheet("height:25px;width:300;background-color:white;padding-left:16px;");
  117. QList<QString> copyTypeList{"Markdown", "URL", "HTML", "UBB"};
  118. cbbCopyType->addItems(copyTypeList);
  119. connect(cbbCopyType, &QComboBox::currentIndexChanged, [this](int index){
  120. m_copyType = index;
  121. });
  122. spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Fixed);
  123. menuLayout = new QHBoxLayout();
  124. menuLayout->setContentsMargins(0, 0, 0, 0);
  125. menuLayout->setSpacing(8);
  126. menuLayout->addWidget(cbbCopyType);
  127. menuLayout->addWidget(btnCopy);
  128. menuLayout->addWidget(btnDelete);
  129. menuLayout->addWidget(btnSelectAll);
  130. menuLayout->addSpacerItem(spacerItem);
  131. layout->addLayout(menuLayout);
  132. layout->addWidget(panelWidget);
  133. layout->setSpacing(6);
  134. // qDebug() << ui->widget;
  135. connect(TCHttpService::getInstance(), &TCHttpService::signal_loginSuc, [this](){
  136. // qDebug() <<"login success";
  137. QList<QUrl> urls = ImageManager::instance()->getImageUrls(FileConfigDecode::getInstance()->getAddress(),
  138. FileConfigDecode::getInstance()->getUserName());
  139. foreach (const QUrl& u, urls) {
  140. FrmImgShow* widget = new FrmImgShow(this);
  141. connect(widget, &FrmImgShow::signal_imageSelected, [this](const QString& url){
  142. m_selectedImageSet.insert(url);
  143. });
  144. connect(widget, &FrmImgShow::signal_imageUnselected, [this](const QString& url){
  145. m_selectedImageSet.remove(url);
  146. });
  147. widget->loadImage(u);
  148. picWidgetList.push_front(widget);
  149. // panelWidget->setWidget(picWidgetList, 3);
  150. }
  151. panelWidget->setWidget(picWidgetList, 4);
  152. panelWidget->setSpace(15);
  153. });
  154. }