#include "editprofile.h" #include "ui_editprofile.h" #include "mainwindow.h" editProfile::editProfile(QWidget *parent) : QDialog(parent), ui(new Ui::editProfile) { ui->setupUi(this); // Get the main widget backgorund palette and use the colors for the plots QPalette palette; palette.setCurrentColorGroup(QPalette::Active); QColor color = palette.color(QPalette::Background); QColor textColor = palette.color(QPalette::Text); QColor graphColor = palette.color(QPalette::Highlight); QPen graphPen; graphPen.setWidth(2); graphPen.setColor(graphColor); QPen tickPen; tickPen.setWidthF(0.5); tickPen.setColor(textColor); // Define the filler line vectors and graphs so they don't need to be recreated every update leftLineX.append(x_lower); leftLineX.append(0); leftLineY.append(0); leftLineY.append(0); rightLineX.append(0); rightLineX.append(x_upper); rightLineY.append(0); rightLineY.append(0); ui->curvePlot->addGraph(); ui->curvePlot->addGraph(); ui->curvePlot->addGraph(); ui->curvePlot->graph(0)->setScatterStyle(QCPScatterStyle::ssCircle); ui->curvePlot->graph(0)->setLineStyle(QCPGraph::lsLine); ui->curvePlot->setBackground(color); ui->curvePlot->xAxis->setLabelColor(textColor); ui->curvePlot->yAxis->setLabelColor(textColor); ui->curvePlot->xAxis->setTickLabelColor(textColor); ui->curvePlot->yAxis->setTickLabelColor(textColor); ui->curvePlot->graph(0)->setPen(graphPen); ui->curvePlot->graph(1)->setPen(graphPen); ui->curvePlot->graph(2)->setPen(graphPen); ui->curvePlot->xAxis->setTickPen(tickPen); ui->curvePlot->yAxis->setTickPen(tickPen); ui->curvePlot->xAxis->setSubTickPen(tickPen); ui->curvePlot->yAxis->setSubTickPen(tickPen); ui->curvePlot->xAxis->setBasePen(tickPen); ui->curvePlot->yAxis->setBasePen(tickPen); ui->curvePlot->xAxis->setLabel("Temperature"); ui->curvePlot->yAxis->setLabel("Fan speed (%)"); ui->curvePlot->xAxis->setRange(x_lower, (x_upper+5)); ui->curvePlot->yAxis->setRange(y_lower, (y_upper+5)); connect(ui->curvePlot, SIGNAL(mouseDoubleClick(QMouseEvent*)), SLOT(clickedGraph(QMouseEvent*))); connect(ui->curvePlot, SIGNAL(plottableClick(QCPAbstractPlottable*,int,QMouseEvent*)), SLOT(clickedPoint(QCPAbstractPlottable*,int,QMouseEvent*))); connect(ui->curvePlot, SIGNAL(mousePress(QMouseEvent*)), SLOT(detectPress(QMouseEvent*))); connect(ui->curvePlot, SIGNAL(mouseMove(QMouseEvent*)), SLOT(detectMove(QMouseEvent*))); connect(ui->curvePlot, SIGNAL(mouseRelease(QMouseEvent*)), SLOT(detectRelease(QMouseEvent*))); connect(ui->curvePlot, SIGNAL(mouseMove(QMouseEvent*)), SLOT(getClosestCoords(QMouseEvent*))); // Load the existing points to the graph MainWindow mw; for (int i=0; icurvePlot->graph(0)->setData(qv_x, qv_y); drawFillerLines(); QCPItemText *text = new QCPItemText(ui->curvePlot); coordText = text; } editProfile::~editProfile() { delete ui; } void editProfile::addPoint(double x, double y) { y = round(y); x = round(x); if (qv_x.length() != 0) { checkForDuplicatePoint(x, y); } if ((x_lower<=x) && (x<=x_upper) && (y_lower<=y) && (y<=y_upper) && !duplicatePoint) { qv_x.append(x); qv_y.append(y); index_y = qv_y.size()-1; index_x = qv_x.size()-1; } } void editProfile::rePlot() { ui->curvePlot->replot(); ui->curvePlot->update(); } void editProfile::clickedGraph(QMouseEvent *event) { QPoint point = event->pos(); addPoint(ui->curvePlot->xAxis->pixelToCoord(point.x()), ui->curvePlot->yAxis->pixelToCoord(point.y())); ui->curvePlot->graph(0)->setData(qv_x, qv_y); drawFillerLines(); } void editProfile::clickedPoint(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event) { checkForNearbyPoints(event); ycoord = round(ycoord); xcoord = round(xcoord); if (isNearbyPoint && qv_x.length() != 0) { for (int i=0; icurvePlot->graph(0)->setData(qv_x, qv_y); rePlot(); drawFillerLines(); } } bool editProfile::checkForNearbyPoints(QMouseEvent *event) { if (qv_x.length() != 0) { QPoint point = event->pos(); double pointerxcoord = ui->curvePlot->xAxis->pixelToCoord(point.x()); double pointerycoord = ui->curvePlot->yAxis->pixelToCoord(point.y()); for (int i=0; i 0) { QPoint cursor = event->pos(); double pointerycoord = ui->curvePlot->yAxis->pixelToCoord(cursor.y()); double pointerxcoord = ui->curvePlot->xAxis->pixelToCoord(cursor.x()); for (int i=0; i 0) { for (int i=0; ipos(); qv_y[index_y] = round(ui->curvePlot->yAxis->pixelToCoord(point.y())); qv_x[index_x] = round(ui->curvePlot->xAxis->pixelToCoord(point.x())); if (qv_x[index_x] > x_upper) { qv_x[index_x] = x_upper; } if (qv_x[index_x] < x_lower) { qv_x[index_x] = x_lower; } if (qv_y[index_y] > y_upper) { qv_y[index_y] = y_upper; } if (qv_y[index_y] < y_lower) { qv_y[index_y] = y_lower; } // Display the coordinates QPalette palette; palette.setCurrentColorGroup(QPalette::Active); QColor textColor = palette.color(QPalette::Text); coordText->position->setType(QCPItemPosition::ptPlotCoords); coordText->position->setCoords(qv_x[index_x], qv_y[index_y] + 4); QString xString = QString::number(qv_x[index_x]); QString yString = QString::number(qv_y[index_y]); coordText->setText(xString + ", " + yString); coordText->setColor(textColor); ui->curvePlot->graph(0)->setData(qv_x, qv_y); drawFillerLines(); } void editProfile::drawFillerLines() { // Draw the filler lines separately so they don't interfere with the main data. graph(1) = leftward line, graph(2) = rightward line leftLineX[1] = ui->curvePlot->graph(0)->dataSortKey(0); leftLineY[0] = ui->curvePlot->graph(0)->dataMainValue(0); leftLineY[1] = ui->curvePlot->graph(0)->dataMainValue(0); ui->curvePlot->graph(1)->setData(leftLineX, leftLineY); rightLineX[0] = ui->curvePlot->graph(0)->dataSortKey(qv_x.length() -1); rightLineY[0] = ui->curvePlot->graph(0)->dataMainValue(qv_x.length() -1); rightLineY[1] = ui->curvePlot->graph(0)->dataMainValue(qv_x.length() -1); ui->curvePlot->graph(2)->setData(rightLineX, rightLineY); rePlot(); } void editProfile::detectRelease(QMouseEvent *event) { mousePressed = false; mouseMoving = false; mouseDragging = false; draggingPoint = false; coordText->setText(""); rePlot(); } void editProfile::on_pushButton_clicked() { qDebug() << draggingPoint; coordText->setText(""); } void editProfile::on_saveButton_clicked() { QString xString; QString yString; for (int i=0; icurvePlot->graph(0)->dataSortKey(i)); QString y = QString::number(ui->curvePlot->graph(0)->dataMainValue(i)); xString.append(x + ", "); yString.append(y + ", "); } MainWindow mw; QVariant xarray = xString; QVariant yarray = yString; qDebug() << xarray.toString() << yarray.toString(); QSettings settings("nvfancurve"); QString xsetting = mw.currentProfile; QString ysetting = mw.currentProfile; ysetting.append("/ypoints"); xsetting.append("/xpoints"); settings.setValue(xsetting, xarray); settings.setValue(ysetting, yarray); } void editProfile::on_clearButton_clicked() { MainWindow mw; qv_x.clear(); qv_y.clear(); qDebug() << mw.currentProfile; ui->curvePlot->graph(0)->setData(qv_x, qv_y); drawFillerLines(); }