Group.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "Group.h"
  2. #include "ui_Group.h"
  3. #include <QDebug>
  4. #include <QMouseEvent>
  5. #include <QSettings>
  6. #include <QVBoxLayout>
  7. #include <QLabel>
  8. Group::Group(int Id, const QString& imagePath1, int MaterialWindowType, const QStringList& textList, QWidget* parent)
  9. : QWidget(parent), ui(new Ui::Group) {
  10. ui->setupUi(this);
  11. QPixmap pixmap1(imagePath1);
  12. ui->Imagewidget_left->setPixmap(pixmap1);
  13. ui->DatacomboBox->addItems(textList);
  14. ui->GroupButton->setStyleSheet( // 设置样式表
  15. "QPushButton:hover {"
  16. " background-color: #45a049;" // 悬停时的背景颜色
  17. "}"
  18. "QPushButton:pressed {"
  19. " background-color: #3e8e41;" // 点击时的背景颜色
  20. "}"
  21. );
  22. ui->Imagewidget_left->setProperty("groupId", Id);
  23. ui->Imagewidget_right->setProperty("groupId", Id);
  24. if (MaterialWindowType == 1) { // 判断物料窗口类型,转到处理函数
  25. wafer = new Wafer(0, ui->Imagewidget_right);
  26. WaferWidget();
  27. } else if (MaterialWindowType == 2) {
  28. WaffleWidget();
  29. } else if (MaterialWindowType == 3) {
  30. MaterialBoxWidget();
  31. }
  32. // 存储参数到 QSettings
  33. saveGroupSettings(Id, imagePath1, MaterialWindowType, textList);
  34. connect(ui->GroupButton,&QPushButton::clicked,this,&Group::onclickbutton);
  35. initForm();
  36. }
  37. Group::~Group() {
  38. delete ui;
  39. }
  40. void Group::initForm() {
  41. ui->Imagewidget_left->installEventFilter(this);
  42. ui->Imagewidget_right->installEventFilter(this);
  43. }
  44. bool Group::eventFilter(QObject *obj, QEvent *event) {
  45. if (event->type() == QEvent::MouseButtonDblClick) {
  46. QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
  47. if (mouseEvent->button() == Qt::LeftButton) {
  48. int groupId = obj->property("groupId").toInt();
  49. QSettings settings("YourCompany", "YourApplication_");
  50. settings.setValue("GroupId", groupId);
  51. if (obj == this->ui->Imagewidget_left) {
  52. settings.setValue("Index", 1);
  53. } else if (obj == this->ui->Imagewidget_right) {
  54. settings.setValue("Index", 2);
  55. }
  56. return true;
  57. }
  58. }
  59. return QWidget::eventFilter(obj, event);
  60. }
  61. void Group::saveGroupSettings(int Id, const QString& imagePath1, int materialWndType, const QStringList& textList) {
  62. QSettings settings("YourOrganization", "YourApplication");
  63. settings.beginGroup(QString::number(Id));
  64. settings.setValue("ImagePath1", imagePath1);
  65. settings.setValue("MaterialWndType", materialWndType);
  66. settings.setValue("TextList", textList);
  67. settings.endGroup();
  68. }
  69. // 圆晶
  70. void Group::WaferWidget() {
  71. QVBoxLayout *layout2 = new QVBoxLayout(ui->Imagewidget_right);
  72. wafer->paintInitFrom(ui->Imagewidget_right);
  73. QLabel* pixmapLabel = new QLabel();
  74. pixmapLabel->setPixmap(wafer->getGlobalPixmap());
  75. ui->Imagewidget_right->setLayout(layout2);
  76. ui->Imagewidget_right->setFixedSize(114, 114);
  77. layout2->setContentsMargins(0, 0, 0, 0);
  78. layout2->addWidget(pixmapLabel);
  79. }
  80. // 华夫盒
  81. void Group::WaffleWidget() {
  82. QVBoxLayout *layout2 = new QVBoxLayout(ui->Imagewidget_right);
  83. waffle = new Waffle(0, ui->Imagewidget_right);
  84. ui->Imagewidget_right->setLayout(layout2);
  85. ui->Imagewidget_right->setFixedSize(114, 114);
  86. layout2->setContentsMargins(0, 0, 0, 0);
  87. layout2->addWidget(waffle);
  88. }
  89. // 料盒
  90. void Group::MaterialBoxWidget() {
  91. QVBoxLayout *layout2 = new QVBoxLayout(ui->Imagewidget_right);
  92. materialbox = new MaterialBox(0, ui->Imagewidget_right);
  93. ui->Imagewidget_right->setLayout(layout2);
  94. ui->Imagewidget_right->setFixedSize(114, 114);
  95. layout2->setContentsMargins(0, 0, 0, 0);
  96. layout2->addWidget(materialbox);
  97. }
  98. void Group::onclickbutton(){
  99. sendSignal();
  100. }