#ifndef CHARTSANDCAMERASWND_H
#define CHARTSANDCAMERASWND_H

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

enum OperateMode {
    ModeImage,  // 显示图片
    ModeView    // 显示 view
};

namespace Ui {
class ChartsAndCamerasWnd;
}


// struct SeriesInfo {
//     QString seriesName;
//     QColor lineColor;
//     QPixmap markerIcon;
//     QList<QPointF> data;
// };

class ChartsAndCamerasWnd : public QMainWindow
{
    Q_OBJECT

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

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

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(); // 清除大窗口上当前的布局
    void WaferWidget(int Id); // 圆晶
    void WaffleWidget(); // 华夫盒
    void MaterialBoxWidget(); // 料盒
public slots: // 确保这里声明了槽函数
    void handleDoubleClick();
private slots:
    void on_ZoomUpButton_clicked();

    QPixmap getCurrentPixmap() const {
        return currentPixmap;
    }

    // 通用槽函数
    void on_CheckBox_clicked();

    void on_ZoomOutButton_clicked();

    // void on_GreenDiamondcheckBox_clicked();

    // void on_YellowDiamondcheckBox_clicked();

    // void on_BlackDiamondcheckBox_clicked();

    // void on_BlueDiamondcheckBox_clicked();

    // void on_BlueHorizontalLinecheckBox_clicked();

    // void on_BlueVerticalBarcheckBox_clicked();

    // void on_GreenVerticalBarcheckBox_clicked();

    // void on_PurpleVerticalBarcheckBox_clicked();

    // void on_RedDiamondcheckBox_clicked();

    // void on_RedHorizontalLinecheckBox_clicked();

    // void on_WhiteVerticalBarcheckBox_clicked();

private:
    Ui::ChartsAndCamerasWnd *ui;

    // // 三个 ChartLine 实例
    // ChartLine *chartLine;
    // ChartLine *chartLine1;
    // ChartLine *chartLine2;


    // ChartLine 实例
    ChartLine *chartLine;
    ChartLine *chartLine1;
    ChartLine *chartLine2;
    // 存储所有系列信息
    QMap<QString, DataSeries> m_seriesMap;

    // 初始化系列信息
    void initializeSeriesInfo();

    QPixmap currentPixmap;
    qreal scaleFactor;
    double previousScaleFactor;

    int lastGroupId = -1;
    int lastIndex = -1;

    Wafer *wafer; // 声明Wafer指针
    Waffle *waffle; // 声明Waffle指针
    MaterialBox *materialbox; // 声明materialbox指针
    bool isShow;

    QMap<int, Wafer*> waferMap;
    OperateMode currentMode = ModeImage;
    QGraphicsView *currentView = nullptr;
    QPoint mousePos;

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

#endif // CHARTSANDCAMERASWND_H
