#pragma once
#ifndef SINGLECAMERAOPERATIONWND_H
#define SINGLECAMERAOPERATIONWND_H

#include <QMainWindow>
#include <QSlider>
#include <QLineEdit>
#include "CameraMaterialGroupWnd/MaterialWindow/Wafer.h"
#include "CameraMaterialGroupWnd/MaterialWindow/Waffle.h"
#include "CameraMaterialGroupWnd/MaterialWindow/MaterialBox.h"
#include "CameraDataHandleAndShow.h"
#include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
namespace Ui {
class SingleCameraOperationWnd;
}

class SingleCameraOperationWnd : public QMainWindow
{
    Q_OBJECT

public:
    explicit SingleCameraOperationWnd(QWidget *parent = nullptr);
    ~SingleCameraOperationWnd();

    void initFrom();
    void connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit);
    void initSliders();
    void initLineEdits();
    void initProgressBar();
    // void saveSliderStates();
    // void loadSliderStates();
    void closeEvent(QCloseEvent *event) override;

    void loadGroupSettings(int Id, int Index);

    void clearLayout(); // 清除大窗口上当前的布局
    void WaferWidget(); // 圆晶
    void WaffleWidget(); // 华夫盒
    void MaterialBoxWidget(); // 料盒
	void startCamera(int cameraId);
    void updateImage(const QImage&image);
public slots: // 确保这里声明了槽函数
    void onComboBoxIndexChanged(int index); // 确保签名匹配
    QString getImagePathFromIndex(int index);
    void handleDoubleClick();
    void showAndHideButton();

    void on_DatacomboBox_currentIndexChanged(int index);
    void handleComBoxChange(int groupId,int index);
    void loadLiveVedio();
protected:
    void wheelEvent(QWheelEvent *event) override;
    void loadSettings();
    void checkSettings();
    void showEvent(QShowEvent *event) override;
    void hideEvent(QHideEvent *event) override;

private slots:
    void on_ZoomUpButton_clicked();

    QPixmap getCurrentPixmap() const {
        return currentPixmap;
    }

    void on_ZoomOutButton_clicked();

private:
    Ui::SingleCameraOperationWnd *ui;

    QPixmap currentPixmap;
    qreal scaleFactor;
    int lastGroupId = -1;
    int lastIndex = -1;

    Wafer *wafer; // 声明Wafer指针
    Waffle *waffle; // 声明Waffle指针
    MaterialBox *materialbox; // 声明materialbox指针
    bool isShow;
    ImageGrabber *m_grabber;
    QMap<int, Group*> groupMap;
    int currentCameraId;
};

#endif // SINGLECAMERAOPERATIONWND_H
