#include "ChartsAndCamerasWnd.h"
#include "ui_ChartsAndCamerasWnd.h"
#include <QSettings>
#include <QCloseEvent>
#include <QVBoxLayout>
#include <QTimer>
#include "chartline.h"
#include <QRandomGenerator>
#include <QScrollBar>
#include <qDebug>
// #include "CInterface.h"
#include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"


ChartsAndCamerasWnd::ChartsAndCamerasWnd(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ChartsAndCamerasWnd),
    chartLine(new ChartLine(this)),
    chartLine1(new ChartLine(this)),
    chartLine2(new ChartLine(this))
{
    ui->setupUi(this);



    // 设置 ChartLine 的位置和大小
    chartLine->setParent(ui->Leftwidget);
    chartLine->setGeometry(0, 0, 560, 280);
    chartLine->setChartLabels("Combined Placement", "Number of Samples", "Device Align");

    // 设置 ChartLine1 的位置和大小
    chartLine1->setParent(ui->Leftwidget);
    chartLine1->setGeometry(0, 245, 560, 280);
    chartLine1->setChartLabels("Y placement", "Number of samples", "Y device align");

    // 设置 ChartLine2 的位置和大小
    chartLine2->setParent(ui->Leftwidget);
    chartLine2->setGeometry(0, 490, 560, 280);
    chartLine2->setChartLabels("Theta placement", "Number of samples", "Theta device align");

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

    // 连接所有复选框的 clicked 信号到通用槽函数
    QList<QCheckBox*> checkBoxes = {
        ui->GreenDiamondcheckBox,
        ui->YellowDiamondcheckBox,
        ui->BlackDiamondcheckBox,
        ui->BlueDiamondcheckBox,
        ui->BlueHorizontalLinecheckBox,
        ui->BlueVerticalBarcheckBox,
        ui->GreenVerticalBarcheckBox,
        ui->PurpleVerticalBarcheckBox,
        ui->RedDiamondcheckBox,
        ui->RedHorizontalLinecheckBox,
        ui->WhiteVerticalBarcheckBox
    };

    for (QCheckBox* cb : checkBoxes) {
        cb->setCheckable(true);

        connect(cb, &QCheckBox::clicked, this, &ChartsAndCamerasWnd::on_CheckBox_clicked);
    }



    initFrom();
    isShow = true;
}

ChartsAndCamerasWnd::~ChartsAndCamerasWnd()
{
    delete ui;
}


void ChartsAndCamerasWnd::initializeSeriesInfo()
{
    // 初始化系列信息，使用 DataSeries 结构体
    m_seriesMap["GreenDiamond"] = DataSeries{
        "GreenDiamond",
        QColor("#00FF00"), // 绿色
        QPixmap(":/images/Participation display/GreenDiamond.png"),
        QList<QPointF>() // 初始为空
    };

    m_seriesMap["YellowDiamond"] = DataSeries{
        "YellowDiamond",
        QColor("#FFFF00"), // 黄色
        QPixmap(":/images/Participation display/YellowDiamond.png"),
        QList<QPointF>()
    };

    m_seriesMap["BlackDiamond"] = DataSeries{
        "BlackDiamond",
        QColor("#000000"), // 黑色
        QPixmap(":/images/Participation display/BlackDiamond.png"),
        QList<QPointF>()
    };

    m_seriesMap["BlueDiamond"] = DataSeries{
        "BlueDiamond",
        QColor("#0000FF"), // 蓝色
        QPixmap(":/images/Participation display/BlueDiamond.png"),
        QList<QPointF>()
    };

    m_seriesMap["BlueHorizontalLine"] = DataSeries{
        "BlueHorizontalLine",
        QColor("#0000FF"),
        QPixmap(":/images/Participation display/Blue_horizontal_line.png"),
        QList<QPointF>()
    };

    m_seriesMap["BlueVerticalBar"] = DataSeries{
        "BlueVerticalBar",
        QColor("#0000FF"),
        QPixmap(":/images/Participation display/Blue_vertical_bar.png"),
        QList<QPointF>()
    };

    m_seriesMap["GreenVerticalBar"] = DataSeries{
        "GreenVerticalBar",
        QColor("#00FF00"),
        QPixmap(":/images/Participation display/Green_vertical_bar.png"),
        QList<QPointF>()
    };

    m_seriesMap["PurpleVerticalBar"] = DataSeries{
        "PurpleVerticalBar",
        QColor("#800080"),
        QPixmap(":/images/Participation display/Purple_vertical_bar.png"),
        QList<QPointF>()
    };

    m_seriesMap["RedDiamond"] = DataSeries{
        "RedDiamond",
        QColor("#FF0000"), // 红色
        QPixmap(":/images/Participation display/RedDiamond.png"),
        QList<QPointF>()
    };

    m_seriesMap["RedHorizontalLine"] = DataSeries{
        "RedHorizontalLine",
        QColor("#FF0000"),
        QPixmap(":/images/Participation display/Red_horizontal_line.png"),
        QList<QPointF>()
    };

    m_seriesMap["WhiteVerticalBar"] = DataSeries{
        "WhiteVerticalBar",
        QColor("#FFFFFF"), // 白色
        QPixmap(":/images/Participation display/White_vertical_bar.png"),
        QList<QPointF>()
    };
}




void ChartsAndCamerasWnd::on_CheckBox_clicked()
{
    // 获取发送信号的复选框
    QCheckBox* checkBox = qobject_cast<QCheckBox*>(sender());
    if (!checkBox)
        return;

    QString checkBoxName = checkBox->objectName();
    QString seriesName = checkBoxName;

    // 移除末尾的 "checkBox"
    if (seriesName.endsWith("checkBox")) {
        seriesName.chop(QString("checkBox").length());
    } else if (seriesName.endsWith("CheckBox")) {
        seriesName.chop(QString("CheckBox").length());
    }

    qDebug() << "Checkbox clicked:" << seriesName << (checkBox->isChecked() ? "Checked" : "Unchecked");

    if (!m_seriesMap.contains(seriesName)) {
        qDebug() << "No series info for:" << seriesName;
        return;
    }

    DataSeries &seriesInfo = m_seriesMap[seriesName];

    if (checkBox->isChecked()) {
        // 生成随机数据
        QList<QPointF> data;
        for (int i = 0; i <= 40; i += 4) {
            data.append(QPointF(i, QRandomGenerator::global()->bounded(-30, 80)));
        }
        seriesInfo.data = data;

        // 添加到 ChartLine 实例
        chartLine->addDataSeries(seriesInfo);
        chartLine1->addDataSeries(seriesInfo);
        chartLine2->addDataSeries(seriesInfo);
        qDebug() << "Added series:" << seriesName;
    }
    else {
        // 从 ChartLine 实例中移除
        chartLine->removeDataSeries(seriesName);
        chartLine1->removeDataSeries(seriesName);
        chartLine2->removeDataSeries(seriesName);
        qDebug() << "Removed series:" << seriesName;
    }
}


void ChartsAndCamerasWnd::initFrom() {
    QTimer *timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &ChartsAndCamerasWnd::checkSettings);
    timer->start(100);

    ui->label_Percentage->setAlignment(Qt::AlignCenter);

    initSliders();
    initLineEdits();
    initProgressBar();
    // 连接 QSlider 的 valueChanged 信号到 QProgressBar 的 setValue 槽
    connect(ui->RedLightverticalSlider, &QSlider::valueChanged, ui->RedLightprogressBar, &QProgressBar::setValue);
    connect(ui->BlueLightverticalSlider, &QSlider::valueChanged, ui->BlueLightprogressBar, &QProgressBar::setValue);
    connect(ui->GreenLightverticalSlider, &QSlider::valueChanged, ui->GreenLightprogressBar, &QProgressBar::setValue);
    connect(ui->DotLightverticalSlider, &QSlider::valueChanged, ui->DotLightprogressBar, &QProgressBar::setValue);
    connectSliderAndLineEdit(ui->RedLightverticalSlider, ui->RedLightlineEdit);
    connectSliderAndLineEdit(ui->GreenLightverticalSlider, ui->GreenLightlineEdit);
    connectSliderAndLineEdit(ui->BlueLightverticalSlider, ui->BlueLightlineEdit);
    connectSliderAndLineEdit(ui->DotLightverticalSlider, ui->DotLightlineEdit);
    connect(ui->Operatewidget,&ImageWidget::sendDoubleClicksignal,this,&ChartsAndCamerasWnd::handleDoubleClick);
    QWidget *viewport = ui->scrollArea->viewport();
    QWidget *container = new QWidget(viewport);
    QHBoxLayout *layout = new QHBoxLayout(container);

    layout->setSpacing(16); // 设置Group之间的间隔距离
    layout->setMargin(0);

    // CInterface interface;
    // ImageInfo image;

    // long result = interface.GrabImage(1, image);

    // if (result == 0) {
    //     qDebug() << "Image width: " << image.width;
    //     qDebug() << "Image height: " << image.height;
    //     qDebug() << "Image width: " << image.format;

    //     QImage img;

    //     // 根据图像格式转换
    //     switch (image.format) {
    //     case GRAY8:
    //         img = QImage(image.data, image.width, image.height, QImage::Format_Grayscale8);
    //         break;
    //     case RGB888:
    //         img = QImage(image.data, image.width, image.height, QImage::Format_RGB888);
    //         break;
    //     case ARGB8888:
    //         img = QImage(image.data, image.width, image.height, QImage::Format_ARGB32);
    //         break;
    //     case RGB32:
    //         img = QImage(image.data, image.width, image.height, QImage::Format_RGB32);
    //         break;
    //     case YUV422:
    //         // YUV422 需要额外的转换逻辑
    //         // 这里假设你有转换函数 convertYUV422ToRGB
    //         // img = convertYUV422ToRGB(image.data, image.width, image.height);
    //         break;
    //     default:
    //         qDebug() << "Unsupported image format";
    //     }

    // } else {
    //     qDebug() << "Failed to grab image, error code: " << result;
    // }

    QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};

    QList<Group*> widgets;

    for (int i = 0; i < numbers.size(); ++i) {
        int num = numbers[i];
        CameraImageHandler* manager = new CameraImageHandler(num);
        Group* widget = manager->getGroup();
        connect(widget,&Group::send_button_Signal,this,&ChartsAndCamerasWnd::showAndHide);
        if (widget != nullptr) {
            layout->addWidget(widget);
            widgets.append(widget);
        }
        if(manager->getWafer()) {
            waferMap.insert(num, manager->getWafer());
        }

        delete manager;
    }

    // 设置控件的最小高度和最大宽度
    int minHeight = 162;
    int maxWidth = 244;
    int num = -16;
    for (Group* w : widgets) {
        w->setMinimumHeight(minHeight);
        w->setMaximumWidth(maxWidth);
        num = num + 260;
    }

    container->setMinimumSize(num, 162);
    container->setLayout(layout);
    ui->scrollArea->setWidget(container);
    ui->scrollArea->resize(508, 177);

    ui->Operatewidget->setMouseTracking(true);
}

void ChartsAndCamerasWnd::initSliders() {
    QList<QSlider*> sliders = {
        ui->RedLightverticalSlider, ui->GreenLightverticalSlider,
        ui->BlueLightverticalSlider, ui->DotLightverticalSlider
    };
    QList<int> initialValues = {22, 11, 0, 0};

    for (int i = 0; i < sliders.size(); ++i) {
        sliders[i]->setMinimum(0);
        sliders[i]->setMaximum(100);
        sliders[i]->setValue(initialValues[i]);
    }
}

void ChartsAndCamerasWnd::initLineEdits() {
    QList<QLineEdit*> lineEdits = {
        ui->RedLightlineEdit, ui->GreenLightlineEdit,
        ui->BlueLightlineEdit, ui->DotLightlineEdit
    };

    for (QLineEdit* lineEdit : lineEdits) {
        lineEdit->setAlignment(Qt::AlignCenter);
    }
}

void ChartsAndCamerasWnd::initProgressBar(){
    QList<int> initialValues = {22, 11, 0, 0};
    QList<QProgressBar*> progressBar = {
        ui->RedLightprogressBar,ui->GreenLightprogressBar,
        ui->BlueLightprogressBar,ui->DotLightprogressBar
    };
    for (int i = 0; i < progressBar.size(); ++i) {
        progressBar[i]->setMinimum(0);
        progressBar[i]->setMaximum(100);
        progressBar[i]->setValue(initialValues[i]);
    }
    // // ui->RedLightprogressBar->setStyleSheet(
    // //     "QProgressBar {"
    // //     "   border: 2px solid grey;"
    // //     "   border-radius: 5px;"
    // //     "   text-align: center;"
    // //     "   color: transparent;" // 隐藏文本
    // //     "}"
    // //     "QProgressBar::chunk {"
    // //     "   background-color: #E4080A;"
    // //     "   width: 10px;"
    // //     "   margin: 1px;"
    // //     "}"
    // //     );
    // // ui->GreenLightprogressBar->setStyleSheet(
    // //     "QProgressBar {"
    // //     "   border: 2px solid grey;"
    // //     "   border-radius: 5px;"
    // //     "   text-align: center;"
    // //     "   color: transparent;" // 隐藏文本
    // //     "}"
    // //     "QProgressBar::chunk {"
    // //     "   background-color: #28B766;"
    // //     "   width: 10px;"
    // //     "   margin: 1px;"
    // //     "}"
    // //     );

    // ui->BlueLightprogressBar->setStyleSheet(
    //     "QProgressBar {"
    //     "   border: 2px solid grey;"
    //     "   border-radius: 10px;"
    //     "   text-align: center;"
    //     "   color: transparent;"
    //     "}"
    //     "QProgressBar::chunk {"
    //     "   background-color: #00BFFF;"
    //     "   width: 10px;"
    //     "   margin: 1px;"
    //     "}"
    //     );








    // // ui->DotLightprogressBar->setStyleSheet(
    // //     "QProgressBar {"
    // //     "   border: 2px solid grey;"
    // //     "   border-radius: 5px;"
    // //     "   text-align: center;"
    // //     "   color: transparent;" // 隐藏文本
    // //     "}"
    // //     "QProgressBar::chunk {"
    // //     "   background-color: #CFCFCF;"
    // //     "   width: 10px;"
    // //     "   margin: 1px;"
    // //     "}"
    //     // );
    // qDebug() << "Progress bar style sheet set:" << ui->DotLightprogressBar->styleSheet();
}

void ChartsAndCamerasWnd::connectSliderAndLineEdit(QSlider* slider, QLineEdit* lineEdit)
{
    QIntValidator* validator = new QIntValidator(slider->minimum(), slider->maximum(), lineEdit);
    lineEdit->setValidator(validator);

    connect(slider, &QSlider::valueChanged, [lineEdit](int value) {
        lineEdit->setText(QString::number(value));
    });

    connect(lineEdit, &QLineEdit::textChanged, [slider](const QString &text) {
        bool ok;
        int value = text.toInt(&ok);
        if (ok && value >= slider->minimum() && value <= slider->maximum()) {
            slider->setValue(value);
        } else if (!text.isEmpty()) {
            int closestValue = qMin(qMax(text.toInt(&ok), slider->minimum()), slider->maximum());
            slider->setValue(closestValue);
        }
    });
}

void ChartsAndCamerasWnd::checkSettings() {
    QSettings settings("YourCompany", "YourApplication_");
    int groupId = settings.value("GroupId", 0).toInt();
    int index = settings.value("Index", 0).toInt();

    if (groupId != lastGroupId || index != lastIndex) {
        lastGroupId = groupId;
        lastIndex = index;
        loadSettings();
    }
}

void ChartsAndCamerasWnd::loadSettings()
{
    QSettings settings("YourCompany", "YourApplication_");
    int groupId = settings.value("GroupId", 0).toInt();
    int index = settings.value("Index", 0).toInt();
    loadGroupSettings(groupId, index);
}

void ChartsAndCamerasWnd::loadGroupSettings(int Id, int Index) {
    QSettings settings("YourOrganization", "YourApplication");
    settings.beginGroup(QString::number(Id));
    QString imagePath1 = settings.value("ImagePath1").toString();
    int materialWndType = settings.value("MaterialWndType").toInt();
    QStringList textList = settings.value("TextList").toStringList();
    settings.endGroup();

    QSize size = ui->Operatewidget->size();

    QPixmap newPixmap;
    // 判断是实时图片还是物料窗口
    if (Index == 1) {
        clearLayout();
        newPixmap = QPixmap(imagePath1);
        QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        currentMode = ModeImage;
        currentPixmap = scaledPixmap;
        scaleFactor = 1.0;
        previousScaleFactor = 1.0;
        ui->Operatewidget->setPixmap(scaledPixmap);
        double percentage = scaleFactor * 100;
        QString percentageStr = QString::number((int)percentage);
        ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
    } else if (Index == 2) {
        if (materialWndType == 1) {
            clearLayout();
            // WaferWidget(Id);
            ui->Operatewidget->clearPixmap();
            QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
            waferMap.value(Id)->initFrom(ui->Operatewidget);

            layout->setContentsMargins(0, 0, 0, 0);
            layout->addWidget(waferMap.value(Id)->view);
            ui->Operatewidget->setLayout(layout);
            currentMode = ModeView;
            currentView = waferMap.value(Id)->view;
            scaleFactor = 1.0;
            applyScale();
        } else if (materialWndType == 2) {
            clearLayout();
            WaffleWidget();
        } else if (materialWndType == 3) {
            clearLayout();
            MaterialBoxWidget();
        }
    }

    // QPixmap scaledPixmap = newPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    // ui->Operatewidget->setPixmap(scaledPixmap);

    // // 更新当前图片的成员变量
    // currentPixmap = scaledPixmap;
    // scaleFactor = 1.0;
    // ui->label_Percentage->setText("100%");

    ui->DatacomboBox->clear();
    ui->DatacomboBox->addItems(textList);
    // connect(ui->DatacomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Demo001_3::onComboBoxIndexChanged(int)));
}

void ChartsAndCamerasWnd::clearLayout() {
    // 获取当前布局
    QLayout* layout = ui->Operatewidget->layout();
    if (layout) {
        QLayoutItem *child;
        while ((child = layout->takeAt(0)) != nullptr) {
            if (child->widget() != nullptr) {
                delete child->widget();  // 删除控件
            }
            delete child;  // 删除布局项
        }
        delete layout;  // 删除布局本身
    }
}

// 圆晶
void ChartsAndCamerasWnd::WaferWidget(int Id) {
    QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
    waferMap.value(Id)->initFrom(ui->Operatewidget);

    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(waferMap.value(Id)->view);
    ui->Operatewidget->setLayout(layout);
    ui->Operatewidget->setFixedSize(480, 480);
}

// 华夫盒
void ChartsAndCamerasWnd::WaffleWidget() {
    QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
    waffle = new Waffle(1, ui->Operatewidget);

    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(waffle);
    ui->Operatewidget->setLayout(layout);
    ui->Operatewidget->setFixedSize(480, 480);
}

// 料盒
void ChartsAndCamerasWnd::MaterialBoxWidget() {
    QVBoxLayout *layout = new QVBoxLayout(ui->Operatewidget);
    materialbox = new MaterialBox(1, ui->Operatewidget);

    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(materialbox);
    ui->Operatewidget->setLayout(layout);
    ui->Operatewidget->setFixedSize(480, 480);
}

void ChartsAndCamerasWnd::handleDoubleClick(){
    if (currentMode == ModeImage) {
        QPixmap scaledImage = currentPixmap.scaled(currentPixmap.width(), currentPixmap.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
        ui->Operatewidget->setPixmap(scaledImage); // 这里传递缩放后的图片
    } else if (currentMode == ModeView && currentView) {
        QTransform transform;
        transform.scale(1, 1);
        currentView->setTransform(transform);
    }
    scaleFactor = 1.0;
    previousScaleFactor = 1.0;
    ui->label_Percentage->setText("100%");
}

// 更新缩放比例
void ChartsAndCamerasWnd::updateScale(double newScaleFactor) {
    if (newScaleFactor >= 1.0) {
        scaleFactor = newScaleFactor;
    } else {
        scaleFactor = 1.0; // 最小缩放比例为 1.0
    }

    applyScale(); // 应用缩放
}

// 应用缩放
void ChartsAndCamerasWnd::applyScale() {
    if (currentMode == ModeImage) {
        // 图片模式：缩放图片
        int newWidth = currentPixmap.width() * scaleFactor;
        int newHeight = currentPixmap.height() * scaleFactor;

        QPixmap scaledImage = currentPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        ui->Operatewidget->setPixmapAndPoint(scaledImage, previousScaleFactor, scaleFactor, mousePos);
        previousScaleFactor = scaleFactor;
    } else if (currentMode == ModeView && currentView) {
        // View 模式：缩放 view
        QTransform transform;
        transform.scale(scaleFactor, scaleFactor);
        currentView->setTransform(transform);
    }

    // 更新百分比显示
    double percentage = scaleFactor * 100;
    QString percentageStr = QString::number((int)percentage);
    ui->label_Percentage->setText(QString("%1%").arg(percentageStr));
}

void ChartsAndCamerasWnd::on_ZoomUpButton_clicked()
{
    mousePos = ui->Operatewidget->geometry().center();
    updateScale(scaleFactor * 1.1);
}

void ChartsAndCamerasWnd::on_ZoomOutButton_clicked()
{
    mousePos = ui->Operatewidget->geometry().center();
    updateScale(scaleFactor * 0.9);
}

void ChartsAndCamerasWnd::wheelEvent(QWheelEvent *event)
{
    mousePos = ui->Operatewidget->mapFromGlobal(event->globalPos());

    if (ui->Operatewidget->rect().contains(ui->Operatewidget->mapFromGlobal(event->globalPos()))) {
        if (event->angleDelta().y() > 0) {
            updateScale(scaleFactor * 1.1); // 放大
        } else {
            updateScale(scaleFactor * 0.9); // 缩小
        }
    }

    QMainWindow::wheelEvent(event);
}

void ChartsAndCamerasWnd::showEvent(QShowEvent *event) {
    QMainWindow::showEvent(event);
    loadSettings();
    // initFrom();
}

void ChartsAndCamerasWnd::hideEvent(QHideEvent *event) {
    QMainWindow::hideEvent(event);
}

void ChartsAndCamerasWnd::showAndHide(){
    if(isShow == true){
        isShow = false;
    }else{
        isShow = true;
    }
    QList<QLineEdit*> lineEdits = {
        ui->RedLightlineEdit, ui->GreenLightlineEdit,
        ui->BlueLightlineEdit, ui->DotLightlineEdit,
    };
    QList<QSlider*> sliders = {
        ui->RedLightverticalSlider, ui->GreenLightverticalSlider,
        ui->BlueLightverticalSlider, ui->DotLightverticalSlider
    };
    QList<QProgressBar*> progressBar = {
        ui->RedLightprogressBar,ui->GreenLightprogressBar,
        ui->BlueLightprogressBar,ui->DotLightprogressBar
    };
    if(isShow == true){
        for (QLineEdit* lineEdit : lineEdits) {
            lineEdit->show();
        }
        for (int i = 0; i < sliders.size(); ++i) {
            sliders[i]->show();
        }
        for (int i = 0; i < progressBar.size(); ++i) {
            progressBar[i]->show();
        }
        ui->BlueLight->show();
        ui->RedLight->show();
        ui->DotLight->show();
        ui->GreenLight->show();
    }else{
        for (QLineEdit* lineEdit : lineEdits) {
            lineEdit->hide();
        }
        for (int i = 0; i < sliders.size(); ++i) {
            sliders[i]->hide();
        }
        for (int i = 0; i < progressBar.size(); ++i) {
            progressBar[i]->hide();
        }
        ui->BlueLight->hide();
        ui->RedLight->hide();
        ui->DotLight->hide();
        ui->GreenLight->hide();

    }
}

