Skip to content

Commit

Permalink
- added "Export to Image" command and "Export to Clipboard Ctrl+C" co…
Browse files Browse the repository at this point in the history
…mmand to the plot widget

- fixed the default showing of existing plot


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@3812 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Jan 23, 2009
1 parent 40a21d9 commit ecb352e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 4 deletions.
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebookQT4/graphcell.cpp
Expand Up @@ -1582,7 +1582,7 @@ namespace IAEX {
guard->unlock();
exceptionInEval(e);
input_->blockSignals(false);
output_->blockSignals(false);
output_->blockSignals(false);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebookQT4/xmlparser.cpp
Expand Up @@ -823,7 +823,7 @@ namespace IAEX
gCell->compoundwidget->gwMain->newRect = r;
gCell->compoundwidget->gwMain->originalArea = r;

if(!gCell->isJavaPlot())
if(!gCell->isQtPlot())
gCell->compoundwidget->hide();

// gCell->compoundwidget->gwMain->graphicsScene->addItem(gCell->compoundwidget->gwMain->graphicsItems);
Expand Down
4 changes: 2 additions & 2 deletions OMNotebook/Pltpkg2/compoundWidget.ui
Expand Up @@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>672</width>
<height>784</height>
<width>500</width>
<height>400</height>
</rect>
</property>
<property name="palette" >
Expand Down
92 changes: 92 additions & 0 deletions OMNotebook/Pltpkg2/graphWidget.cpp
Expand Up @@ -53,6 +53,10 @@
#include <QToolTip>
#include <QGraphicsRectItem>
#include <QInputDialog>
#include <QFileDialog>
#include <QFile>
#include <QClipboard>
#include <QApplication>

//Std headers
#include <fstream>
Expand Down Expand Up @@ -188,6 +192,14 @@ GraphWidget::GraphWidget(QWidget* parent): QGraphicsView(parent)
tmp=contextMenu->addAction("Preferences...");
connect(tmp, SIGNAL(triggered()), this, SLOT(showPreferences()));

contextMenu->addSeparator();

tmp=contextMenu->addAction("Export to Clipboard", this, SLOT(exportToClipboard()), QKeySequence(tr("Ctrl+C")));
connect(tmp, SIGNAL(triggered()), this, SLOT(exportToClipboard()));

tmp=contextMenu->addAction("Export as Image");
connect(tmp, SIGNAL(triggered()), this, SLOT(saveImage()));

tmp = contextMenu->addAction("oZm");
connect(tmp, SIGNAL(triggered()), this, SLOT(originalZoom()));
tmp->setVisible(false);
Expand Down Expand Up @@ -1993,3 +2005,83 @@ delete r;
}
*/

void GraphWidget::saveImage()
{

QString filename = QFileDialog::getSaveFileName(this, "Export image", "untitled", "Portable Network Graphics (*.png);;Windows Bitmap (*.bmp);;Joint Photographic Experts Group (*.jpg)");

if(!filename.size())
return;

QImage i3(compoundwidget->rect().size(), QImage::Format_RGB32);

i3.fill(QColor(Qt::white).rgb());
QPainter p(&i3);
QRectF target = QRectF(compoundwidget->gwMain->rect());
target.moveTo(compoundwidget->gwMain->pos());
compoundwidget->gwMain->render(&p, target);

p.drawRect(target);

target = QRectF(compoundwidget->gvLeft->rect());
target.moveTo(compoundwidget->gvLeft->pos());
compoundwidget->gvLeft->render(&p, target);

target = QRectF(compoundwidget->gvBottom->rect());
target.moveTo(compoundwidget->gvBottom->pos());
compoundwidget->gvBottom->render(&p, target);

compoundwidget->yLabel->render(&p, compoundwidget->yLabel->pos());
compoundwidget->xLabel->render(&p, compoundwidget->xLabel->pos());
compoundwidget->plotTitle->render(&p, compoundwidget->plotTitle->pos());


QList<LegendLabel*> l = compoundwidget->legendFrame->findChildren<LegendLabel*>();
for(int i = 0; i < l.size(); ++i)
l[i]->render(&p, l[i]->pos()+compoundwidget->legendFrame->pos());


if(filename.endsWith("png"))
i3.save(filename, "PNG");
else if(filename.endsWith("bmp"))
i3.save(filename, "BMP");
else if(filename.endsWith("jpg") || filename.endsWith("jpeg"))
i3.save(filename, "JPG");
else
i3.save(filename+".bmp", "BMP");
}


void GraphWidget::exportToClipboard()
{

QImage i3(compoundwidget->rect().size(), QImage::Format_RGB32);

i3.fill(QColor(Qt::white).rgb());
QPainter p(&i3);
QRectF target = QRectF(compoundwidget->gwMain->rect());
target.moveTo(compoundwidget->gwMain->pos());
compoundwidget->gwMain->render(&p, target);

p.drawRect(target);

target = QRectF(compoundwidget->gvLeft->rect());
target.moveTo(compoundwidget->gvLeft->pos());
compoundwidget->gvLeft->render(&p, target);

target = QRectF(compoundwidget->gvBottom->rect());
target.moveTo(compoundwidget->gvBottom->pos());
compoundwidget->gvBottom->render(&p, target);

compoundwidget->yLabel->render(&p, compoundwidget->yLabel->pos());
compoundwidget->xLabel->render(&p, compoundwidget->xLabel->pos());
compoundwidget->plotTitle->render(&p, compoundwidget->plotTitle->pos());


QList<LegendLabel*> l = compoundwidget->legendFrame->findChildren<LegendLabel*>();
for(int i = 0; i < l.size(); ++i)
l[i]->render(&p, l[i]->pos()+compoundwidget->legendFrame->pos());

QClipboard *clipboard = QApplication::clipboard();
clipboard->setImage(i3, QClipboard::Clipboard);
}
2 changes: 2 additions & 0 deletions OMNotebook/Pltpkg2/graphWidget.h
Expand Up @@ -94,6 +94,8 @@ public slots:

void newWindow();
void zoomIn(QRectF);
void saveImage();
void exportToClipboard();

void setExpr(QString);

Expand Down
2 changes: 2 additions & 0 deletions OMNotebook/Pltpkg2/graphWindow.ui
Expand Up @@ -143,6 +143,8 @@
<addaction name="actionPreferences" />
<addaction name="separator" />
<addaction name="actionActive" />
<addaction name="separator" />
<addaction name="actionImage" />
</widget>
<action name="actionHold" >
<property name="checkable" >
Expand Down

0 comments on commit ecb352e

Please sign in to comment.