#ifndef MAINANDSECONDARYCAMERASWND_H
#define MAINANDSECONDARYCAMERASWND_H

#include <QMainWindow>
#include <QSlider>
#include <QLineEdit>
#include "CameraMaterialGroupWnd/MaterialWindow/Wafer.h"
#include "CameraMaterialGroupWnd/MaterialWindow/Waffle.h"
#include "CameraMaterialGroupWnd/MaterialWindow/MaterialBox.h"

namespace Ui {
class MainAndSecondaryCamerasWnd;
}

class MainAndSecondaryCamerasWnd : public QMainWindow
{
    Q_OBJECT

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

    void initFrom();
    void connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit);
    void initLineEdits();
    void initSliders();
    void initProgressBar();

public slots: // 确保这里声明了槽函数
    void handleDoubleClick();
    void showAndHide();
    void showAndHide_L();
    void CheckIs();

protected:
    void wheelEvent(QWheelEvent *event)override;
    void loadSettings();
    void checkSettings();
    void loadGroupSettings(int Id, int Index);
    void showEvent(QShowEvent *event) override;
    void hideEvent(QHideEvent *event) override;

    void clearLayout(int flag); // 清除大窗口上当前的布局
    void WaferWidget(int flag); // 圆晶
    void WaffleWidget(int flag); // 华夫盒
    void MaterialBoxWidget(int flag); // 料盒

private slots:
    void on_LeftZoomUpButton_clicked();

    void on_RightZoomUpButton_clicked();

    void on_LeftZoomOutButton_clicked();

    void on_RightZoomOutButton_clicked();

    QPixmap getCurrentPixmap() const {
        return Right_currentPixmap;
    }

private:
    Ui::MainAndSecondaryCamerasWnd *ui;

    QPixmap Left_currentPixmap;
    qreal Left_scaleFactor;
    QPixmap Right_currentPixmap;
    qreal Right_scaleFactor;
    int lastGroupId = -1;
    int lastIndex = -1;
    int lastLastGroupId = -1;
    int lastLastIndex = -1;
    QPixmap lastRightPixmap;
    QStringList lasttextList;
    QPixmap lastLastRightPixmap;  // 用于存储上一次的 lastRightPixmap
    QStringList lastLasttextList;
    bool isUpdatingSettings;

    Wafer *wafer; // 声明Wafer指针
    Waffle *waffle; // 声明Waffle指针
    MaterialBox *materialbox; // 声明materialbox指针
    bool isShow;
    bool isShow_L;
    QMap<int, Wafer*> waferMap;
    QMap<int, Waffle*> waffleMap;
    QMap<int, MaterialBox*> materialBoxMap;
    OperateMode Left_currentMode = ModeImage;
    OperateMode Right_currentMode = ModeImage;
    QGraphicsView *Left_currentView = nullptr;
    QGraphicsView *Right_currentView = nullptr;
    QPoint mousePos;
    double Left_previousScaleFactor;
    double Right_previousScaleFactor;

    void updateScale(double newScaleFactor, int flag); // 更新缩放比例
    void applyScale(int flag); // 应用缩放
};

#endif // MAINANDSECONDARYCAMERASWND_H