diff --git a/candatagrid.cpp b/candatagrid.cpp index 090c203..e4fff83 100644 --- a/candatagrid.cpp +++ b/candatagrid.cpp @@ -138,6 +138,28 @@ void CANDataGrid::paintEvent(QPaintEvent *event) gridSize.setY(ySector); } +void CANDataGrid::saveImage(QString filename, int width, int height) +{ + //can't quite do the below commented out stuff + //it works but doesn't scale the image into that pixmap. Need to + //figure out how to draw the size of the pixmap + /* + QSize pSize; + + if (width == 0) pSize.setWidth(this->size().width()); + else pSize.setWidth(width); + + if (height == 0) pSize.setHeight(this->size().height()); + else pSize.setHeight(height); + + QPixmap pixmap(pSize); + */ + QPixmap pixmap(this->size()); + + this->render(&pixmap); + pixmap.save(filename); //QT will automatically pick the file format given the extension +} + void CANDataGrid::setReference(unsigned char *newRef, bool bUpdate = true) { memcpy(refData, newRef, 8); diff --git a/candatagrid.h b/candatagrid.h index 4177ab5..126ad5a 100644 --- a/candatagrid.h +++ b/candatagrid.h @@ -17,6 +17,7 @@ public: void paintEvent(QPaintEvent *event); void setReference(unsigned char *, bool); void updateData(unsigned char *, bool); + void saveImage(QString filename, int width, int height); protected: void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; diff --git a/flowviewwindow.cpp b/flowviewwindow.cpp index e01809e..40e14da 100644 --- a/flowviewwindow.cpp +++ b/flowviewwindow.cpp @@ -69,6 +69,11 @@ FlowViewWindow::FlowViewWindow(QVector *frames, QWidget *parent) : connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); + ui->graphView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->graphView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestGraph(QPoint))); + ui->flowView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->flowView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestFlow(QPoint))); + playbackTimer->setInterval(ui->spinPlayback->value()); //set the timer to the default value of the control } @@ -94,6 +99,74 @@ FlowViewWindow::~FlowViewWindow() delete playbackTimer; } +void FlowViewWindow::contextMenuRequestFlow(QPoint pos) +{ + QMenu *menu = new QMenu(this); + menu->setAttribute(Qt::WA_DeleteOnClose); + + menu->addAction(tr("Save image to file"), this, SLOT(saveFileFlow())); + + menu->popup(ui->flowView->mapToGlobal(pos)); +} + +void FlowViewWindow::contextMenuRequestGraph(QPoint pos) +{ + QMenu *menu = new QMenu(this); + menu->setAttribute(Qt::WA_DeleteOnClose); + + menu->addAction(tr("Save image to file"), this, SLOT(saveFileGraph())); + + menu->popup(ui->graphView->mapToGlobal(pos)); +} + +void FlowViewWindow::saveFileGraph() +{ + QString filename; + QFileDialog dialog(this); + + QStringList filters; + filters.append(QString(tr("PDF Files (*.pdf)"))); + filters.append(QString(tr("PNG Files (*.png)"))); + filters.append(QString(tr("JPEG Files (*.jpg)"))); + + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setNameFilters(filters); + dialog.setViewMode(QFileDialog::Detail); + dialog.setAcceptMode(QFileDialog::AcceptSave); + + if (dialog.exec() == QDialog::Accepted) + { + filename = dialog.selectedFiles()[0]; + + if (dialog.selectedNameFilter() == filters[0]) ui->graphView->savePdf(filename, true, 0, 0); + if (dialog.selectedNameFilter() == filters[1]) ui->graphView->savePng(filename, 1024, 768); + if (dialog.selectedNameFilter() == filters[2]) ui->graphView->saveJpg(filename, 1024, 768); + } +} + +void FlowViewWindow::saveFileFlow() +{ + QString filename; + QFileDialog dialog(this); + + QStringList filters; + filters.append(QString(tr("PNG Files (*.png)"))); + filters.append(QString(tr("JPEG Files (*.jpg)"))); + + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setNameFilters(filters); + dialog.setViewMode(QFileDialog::Detail); + dialog.setAcceptMode(QFileDialog::AcceptSave); + + if (dialog.exec() == QDialog::Accepted) + { + filename = dialog.selectedFiles()[0]; + + if (dialog.selectedNameFilter() == filters[0]) ui->flowView->saveImage(filename, 1024, 768); + if (dialog.selectedNameFilter() == filters[1]) ui->flowView->saveImage(filename, 1024, 768); + } +} + void FlowViewWindow::updatedFrames(int numFrames) { if (numFrames == -1) //all frames deleted. Kill the display diff --git a/flowviewwindow.h b/flowviewwindow.h index 20fb280..248a557 100644 --- a/flowviewwindow.h +++ b/flowviewwindow.h @@ -28,7 +28,11 @@ private slots: void changeLooping(bool check); void timerTriggered(); void changeID(QString); - void updatedFrames(int); + void updatedFrames(int); + void contextMenuRequestFlow(QPoint pos); + void contextMenuRequestGraph(QPoint pos); + void saveFileFlow(); + void saveFileGraph(); private: Ui::FlowViewWindow *ui; diff --git a/mainwindow.cpp b/mainwindow.cpp index d715e1b..e50cce2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,13 +21,8 @@ Range state - Find things that range like accelerator pedal inputs, road speed, fuzzy scope - Try to find potential places where a given value might be stored - offer guesses and the program tries to find candidates for you -Things currently broken or in need of attention: -1. Currently no screen supports dynamic updates when new frames come in. -2. Some of the save formats are not actually implemented and silently fail. -3. It would be nice to be able to save the graphing view in the flow view. -4. It would also be nice to be able to save an image of the bitfield grid too. -5. New GVRET firmware has a hard time sending data (6 frames per second!) -6. If you load a file, use detailed view, clear it, load another, it seems to only show new IDs +Things currently broken or in need of attention: (push these over to github issues as soon as you can) +1. If you load a file, use detailed view, clear it, load another, it seems to only show new IDs */ QString MainWindow::loadedFileName = "";