frmalbum.cpp 6.1 KB

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