void QGraphicsScale::setXScale(qreal scale)
{
    Q_D(QGraphicsScale);
    if (d->xScale == scale)
        return;
    d->xScale = scale;
    update();
    emit xScaleChanged();
    emit scaleChanged();
}
Ejemplo n.º 2
0
//using namespace cv;
Spectro::Spectro(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Spectro)
{
    ui->setupUi(this);

    divData = false;
    calibration = false;

    colors.append(Qt::black);
    colors.append(Qt::red);
    colors.append(Qt::darkGreen);
    colors.append(Qt::darkRed);
    colors.append(Qt::blue);
    colors.append(Qt::darkCyan);
    colors.append(Qt::darkMagenta);
    colors.append(Qt::darkYellow);
    colors.append(Qt::darkBlue);
    currentColor = 0;

    ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWidgetScale));
    ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWidgetMaths));
    ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWidgetCalib));
    ui->tabWidget->hide();

    spectro = new Spectrometer(1);


    QSettings settings;
    setCalibEnabled(true);

   /*
    if(!settings.value("calibration/focal").isNull()){
        double focal = settings.value("calibration/focal").toDouble();
        double sin_i = settings.value("calibration/sin_i").toDouble();
        double pas = settings.value("calibration/pas").toDouble();
        spectro->setParameters(focal,sin_i,pas);
        ui->tabWidgetCalib->setEnabled(false);
        if(spectro->isWlCalib())
            setCalibEnabled(false);
    }
    */

    readCalibrationList();
    if(!settings.value("calibration_num",0).isNull()){
        int num = settings.value("calibration_num").toInt();
        qDebug()<<"num : "<<num;
        if((num>=0) && (num <calibrationList.size())){
            qDebug()<<"calibrating";
            Calibration cal = calibrationList[num];
            spectro->setParameters(cal.focal,cal.sin_i,1e3);
            ui->tabWidgetCalib->setEnabled(false);
            if(spectro->isWlCalib())
                setCalibEnabled(false);
        }
    }


    lastDir = settings.value("application/fileDir",QApplication::applicationDirPath()).toString();

    if(!settings.value("spectro/x1").isNull()){
        double x1 = settings.value("spectro/x1").toInt();
        double y1 = settings.value("spectro/y1").toInt();
        double x2 = settings.value("spectro/x2").toInt();
        double y2 = settings.value("spectro/y2").toInt();
        setSpectrumRect(QRect(QPoint(x1,y1),QPoint(x2,y2)).normalized());
    }

    if(!spectro->isOk())
        close();
    //connect(&video,SIGNAL(rectSelected(QRect)),spectro,SLOT(setSpectrumRect(QRect)));
    connect(&video,SIGNAL(rectSelected(QRect)),this,SLOT(setSpectrumRect(QRect)));

    connect(spectro,SIGNAL(newSpectrum(Tjcampdx)),this,SLOT(newSpectrum(Tjcampdx)));
    //connect(spectro,SIGNAL(newSpectrum_rgb(Tjcampdx,Tjcampdx,Tjcampdx)),this,SLOT(newSpectrum_rgb(Tjcampdx,Tjcampdx,Tjcampdx)));
    connect(spectro,SIGNAL(saturation()),this,SLOT(spectroSaturation()));
    connect(spectro,SIGNAL(measureFinished(Tjcampdx)),this,SLOT(newMeasure(Tjcampdx)));

    connect(spectro,SIGNAL(measureProgressed(int)),ui->progressMeasure,SLOT(setValue(int)));

    connect(spectro,SIGNAL(newFrame(QImage*)),&video,SLOT(setImage(QImage*)));
    connect(ui->plot->xAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(xScaleChanged(QCPRange)));
    connect(ui->plot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(yScaleChanged(QCPRange)));
    connect(ui->actionShowVideo,SIGNAL(toggled(bool)),&video,SLOT(setVisible(bool)));
    connect(ui->plot,SIGNAL(mousePress(QMouseEvent*)),this,SLOT(plotClicked(QMouseEvent*)));
    connect(qApp,SIGNAL(focusChanged(QWidget*,QWidget*)),this,SLOT(focusChanged(QWidget*,QWidget*)));

    // graph for live spectrum
    liveSpec = ui->plot->addGraph();

    /*
    liveSpecR = ui->plot->addGraph();
    liveSpecR->setPen(QPen(Qt::red));
    liveSpecR->setVisible(false);

    liveSpecG = ui->plot->addGraph();
    liveSpecG->setPen(QPen(Qt::green));
    liveSpecG->setVisible(false);


    liveSpecB = ui->plot->addGraph();
    liveSpecB->setPen(QPen(Qt::blue));
    liveSpecB->setVisible(false);
    */
    bbSpec = ui->plot->addGraph();
    bbSpec->setPen(QPen(Qt::black));
    bbSpec->setVisible(false);


    wlLine = new QCPItemStraightLine(ui->plot);

    ui->plot->addItem(wlLine);
    wlLine->setPen(QPen(Qt::red));


    // add the text label at the top:
    wlLabel = new QCPItemText(ui->plot);
    ui->plot->addItem(wlLabel);
    wlLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignRight);
    wlLabel->setClipToAxisRect(false);
    wlLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    wlLabel->position->setCoords(1, 0); // place position at right/top of axis rect
    wlLabel->setText("\u03BB = ??? nm");

    connect(ui->plot,SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(plotMouseMoved(QMouseEvent*)));


    if(!settings.value("scale/xmin").isNull()){
        double xmin = settings.value("scale/xmin",400).toDouble();
        double xmax = settings.value("scale/xmax",1000).toDouble();
        double ymin = settings.value("scale/ymin",0).toDouble();
        double ymax = settings.value("scale/ymax",700).toDouble();
        changeScale(xmin,xmax,ymin,ymax);
    }

    ui->spinNMeas->setValue(settings.value("application/nAverage",1).toInt());
    ui->spinRepeat->setValue(settings.value("application/nRepeat",1).toInt());

    ui->sldGain->setValue(settings.value("spectro/gain",0).toInt());
    spectro->setGain(ui->sldGain->value()/100.);

    /*
    QFileInfo gainFile = QFileInfo(QFileInfo(settings.fileName()).absolutePath()+
                                   QString("dark_g%1.dx").arg(ui->sldGain->value()));
    if(gainFile.exists())
    {
        Tjcampdx darkSpec;
        darkSpec.Open(gainFile.absoluteFilePath().toStdString());
        spectro->setDarkSpec(darkSpec);
    }
    */

    spectro->setFrameRate(15);
    video.hide();
}