SingleCameraOperationWnd.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #include "SingleCameraOperationWnd.h"
  2. #include "ui_SingleCameraOperationWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QDebug>
  7. #include <QTimer>
  8. #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
  9. SingleCameraOperationWnd::SingleCameraOperationWnd(QWidget *parent)
  10. : JOriginalMainWnd(parent)
  11. , ui(new Ui::SingleCameraOperationWnd), scaleFactor(1.0)
  12. {
  13. ui->setupUi(this);
  14. ui->viewwidgetgroup->resizeSingleUI(true);
  15. ui->lightJoystickSwitchPage->resizeSingleUI();
  16. isShow = true;
  17. liveClick = true;
  18. initFrom();
  19. }
  20. SingleCameraOperationWnd::~SingleCameraOperationWnd()
  21. {
  22. delete ui;
  23. }
  24. void SingleCameraOperationWnd::initFrom() {
  25. // 设置右上部分
  26. QWidget *viewport = ui->scrollArea->viewport();
  27. QWidget *container = new QWidget(viewport);
  28. QVBoxLayout *layout = new QVBoxLayout(container);
  29. layout->setSpacing(16); // 设置Group之间的间隔距离
  30. layout->setMargin(0);
  31. QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
  32. QList<Group*> widgets;
  33. for (int i = 0; i < numbers.size(); ++i) {
  34. int num = numbers[i];
  35. CameraImageHandler* manager = new CameraImageHandler(num);
  36. Group* widget = manager->getGroup();
  37. //connect(widget,&Group::send_button_Signal,this,&SingleCameraOperationWnd::showAndHideButton);
  38. //connect(widget,&Group::send_ComboBox_singal,this,&SingleCameraOperationWnd::handleComBoxChange);
  39. if (widget != nullptr) {
  40. connect(widget, &Group::sendUpdateGroupState,
  41. this, &SingleCameraOperationWnd::checkSettings);
  42. layout->addWidget(widget);
  43. widgets.append(widget);
  44. groupMap[num] = widget;
  45. }
  46. if(manager->getWafer()) {
  47. waferMap.insert(num, manager->getWafer());
  48. }
  49. if(manager->getWafer()) {
  50. waffleMap.insert(num, manager->getWaffle());
  51. }
  52. if(manager->getMaterialBox()){
  53. materialBoxMap.insert(num,manager->getMaterialBox());
  54. }
  55. delete manager;
  56. }
  57. // 设置控件的最小高度和最大宽度
  58. int minHeight = 162;
  59. int maxWidth = 244;
  60. for (Group* w : widgets) {
  61. w->setMinimumHeight(minHeight);
  62. w->setMaximumWidth(maxWidth);
  63. }
  64. container->setLayout(layout);
  65. ui->scrollArea->setWidget(container);
  66. ui->scrollArea->resize(261, 700);
  67. checkSettings();
  68. }
  69. void SingleCameraOperationWnd::closeEvent(QCloseEvent *event) {
  70. // 保存滑块状态
  71. // saveSliderStates();
  72. // 确保调用基类的 closeEvent 处理其他关闭逻辑
  73. QMainWindow::closeEvent(event);
  74. }
  75. void SingleCameraOperationWnd::checkSettings() {
  76. QSettings settings("YourCompany", "YourApplication_");
  77. int groupId = settings.value("GroupId", 0).toInt();
  78. int index = settings.value("Index", 0).toInt();
  79. if (groupId != lastGroupId || index != lastIndex) {
  80. lastGroupId = groupId;
  81. lastIndex = index;
  82. loadSettings();
  83. }
  84. }
  85. void SingleCameraOperationWnd::loadSettings()
  86. {
  87. QSettings settings("YourCompany", "YourApplication_");
  88. int groupId = settings.value("GroupId", 0).toInt();
  89. int index = settings.value("Index", 0).toInt();
  90. loadGroupSettings(groupId, index);
  91. }
  92. void SingleCameraOperationWnd::loadGroupSettings(int Id, int Index) {
  93. QSettings settings("YourOrganization", "YourApplication");
  94. settings.beginGroup(QString::number(Id));
  95. QString imagePath = settings.value("ImagePath1").toString();
  96. int materialWndType = settings.value("MaterialWndType").toInt();
  97. QStringList textList = settings.value("TextList").toStringList();
  98. settings.endGroup();
  99. QPixmap newPixmap;
  100. // 判断是实时图片还是物料窗口
  101. if (Index == 1) {
  102. newPixmap = QPixmap(imagePath);
  103. QStringList test = { "1","2" };
  104. ui->viewwidgetgroup->updateOperateWidget(newPixmap);
  105. ui->viewwidgetgroup->setEnableControls(true);
  106. }else if (Index == 2) {
  107. updateMaterialWidget(materialWndType, Id);
  108. ui->viewwidgetgroup->setEnableControls(false);
  109. }
  110. }
  111. void SingleCameraOperationWnd::updateMaterialWidget( int materialWndType, int groupId){
  112. switch (materialWndType) {
  113. case 1: ui->viewwidgetgroup->setWafer(waferMap.value(lastGroupId)); break;
  114. case 2: ui->viewwidgetgroup->setWaffle(waffleMap.value(lastGroupId)); break;
  115. case 3: ui->viewwidgetgroup->setMaterialBox(materialBoxMap.value(lastGroupId)); break;
  116. }
  117. }
  118. void SingleCameraOperationWnd::InitMainCameraBind(CameraBind* pCameraBind)
  119. {
  120. }
  121. void SingleCameraOperationWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  122. {
  123. }
  124. void SingleCameraOperationWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  125. {
  126. }
  127. void SingleCameraOperationWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  128. {
  129. }
  130. void SingleCameraOperationWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  131. {
  132. }
  133. void SingleCameraOperationWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  134. {
  135. }
  136. void SingleCameraOperationWnd::wheelEvent(QWheelEvent *event)
  137. {
  138. mousePos = ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos());
  139. if (ui->viewwidgetgroup->getOperatewidget()->rect().contains(ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  140. if (event->angleDelta().y() > 0) {
  141. ui->viewwidgetgroup->updateScale(scaleFactor * 1.1); // 放大
  142. } else {
  143. ui->viewwidgetgroup->updateScale(scaleFactor * 0.9); // 缩小
  144. }
  145. }
  146. if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  147. // 获取 QScrollArea 的横向滚动条
  148. QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  149. // 根据滚轮滚动方向改变滚动条的值
  150. if (event->angleDelta().y() > 0) {
  151. scrollBar->setValue(scrollBar->value() - 50);
  152. } else {
  153. scrollBar->setValue(scrollBar->value() + 50);
  154. }
  155. }
  156. QMainWindow::wheelEvent(event);
  157. }
  158. //void SingleCameraOperationWnd::onComboBoxIndexChanged(int index) {
  159. // // 根据index获取图片路径
  160. // QString imagePath = getImagePathFromIndex(index);
  161. // if (!imagePath.isEmpty()) {
  162. // QPixmap newPixmap(imagePath);
  163. // QPixmap scaledPixmap = newPixmap.scaled(ui->viewwidgetgroup->getOperatewidget()->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  164. // ui->viewwidgetgroup->getOperatewidget()->setPixmap(scaledPixmap);
  165. // // 更新当前图片的成员变量
  166. // currentPixmap = scaledPixmap;
  167. // scaleFactor = 1.0;
  168. // ui->viewwidgetgroup->label_Percentage->setText("100%");
  169. // }
  170. //}
  171. QString SingleCameraOperationWnd::getImagePathFromIndex(int index) {
  172. QStringList imagePaths = {
  173. ":/images/test_image/image.png",
  174. ":/images/test_image/image_2.png",
  175. };
  176. if (index >= 0 && index < imagePaths.size()) {
  177. return imagePaths[index];
  178. }
  179. return ":/images/test_image/image.png";
  180. }
  181. void SingleCameraOperationWnd::showEvent(QShowEvent *event) {
  182. QMainWindow::showEvent(event);
  183. loadSettings();
  184. }
  185. void SingleCameraOperationWnd::hideEvent(QHideEvent *event) {
  186. QMainWindow::hideEvent(event);
  187. }
  188. void SingleCameraOperationWnd::startCamera(int cameraId) {
  189. m_grabber = new ImageGrabber(cameraId);
  190. connect(m_grabber, &ImageGrabber::imageGrabbed,
  191. this, &SingleCameraOperationWnd::updateImage);
  192. m_grabber->start();
  193. }
  194. void SingleCameraOperationWnd::stopCamera(int cameraId){
  195. m_grabber->stop();
  196. }
  197. void SingleCameraOperationWnd::on_DatacomboBox_currentIndexChanged(int index){
  198. QSettings settings("YourCompany", "YourApplication_");
  199. int groupId = settings.value("GroupId", 0).toInt();
  200. if (groupMap.contains(groupId)) {
  201. Group* group = groupMap[groupId];
  202. // 修改属性
  203. group->setDatacomboBox(index);
  204. } else {
  205. qDebug() << "Group with id" << groupId << "not found.";
  206. }
  207. }
  208. //void SingleCameraOperationWnd::handleComBoxChange(int groupId,int index){
  209. // QSettings settings("YourCompany", "YourApplication_");
  210. // int currentGroupId = settings.value("GroupId", 0).toInt();
  211. // if(currentGroupId == groupId){
  212. // ui->viewwidgetgroup->DataSources->setCurrentIndex(index);
  213. // }
  214. //}
  215. void SingleCameraOperationWnd::updateImage(const QImage&image){
  216. QPixmap pixmap = QPixmap::fromImage(image);
  217. QSize size = ui->viewwidgetgroup->getOperatewidget()->size();
  218. // QPixmap scaledPixmap = pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  219. QPixmap scaledPixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  220. ui->viewwidgetgroup->getOperatewidget()->setPixmap(scaledPixmap);
  221. }
  222. void SingleCameraOperationWnd::loadLiveVedio(){
  223. if(liveClick == true){
  224. startCamera(0);
  225. liveClick = false;
  226. }else{
  227. stopCamera(0);
  228. liveClick = true;
  229. }
  230. }