Skip to content

Commit

Permalink
ticket:3712
Browse files Browse the repository at this point in the history
Print the OMNotebook plots.
  • Loading branch information
adeas31 committed Oct 28, 2016
1 parent f6b146d commit cb438f2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
1 change: 0 additions & 1 deletion OMNotebook/OMNotebookGUI/notebookcommands.h
Expand Up @@ -313,7 +313,6 @@ namespace IAEX

PrinterVisitor visitor( printDocument, printer_ );
doc_->runVisitor( visitor );
printDocument->setTextWidth(700);

printDocument->print( printer_ );

Expand Down
90 changes: 57 additions & 33 deletions OMNotebook/OMNotebookGUI/printervisitor.cpp
Expand Up @@ -51,6 +51,7 @@
#include <QtGui/QTextTableFormat>
#include <QPrinter>
#endif
#include "qwt_plot_renderer.h"

//IAEX Headers
#include "printervisitor.h"
Expand Down Expand Up @@ -98,12 +99,13 @@ namespace IAEX
QTextTableFormat tableFormat;
tableFormat.setBorder( 0 );
tableFormat.setColumns( 2 );
tableFormat.setCellPadding( 5 );
tableFormat.setCellPadding( 2 );

QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::FixedLength, 50)
<< QTextLength(QTextLength::VariableLength, 620);
tableFormat.setColumnWidthConstraints(constraints);
// do not put the constraints on the columns. If we don't have chapter numbers we want to use the full space.
// QVector<QTextLength> constraints;
// constraints << QTextLength(QTextLength::PercentageLength, 20)
// << QTextLength(QTextLength::PercentageLength, 80);
// tableFormat.setColumnWidthConstraints(constraints);

// insert the table
QTextCursor cursor = printEditor_->textCursor();
Expand Down Expand Up @@ -182,7 +184,7 @@ namespace IAEX
QTextTableFormat tableFormatExpression;
tableFormatExpression.setBorder( 0 );
tableFormatExpression.setColumns( 1 );
tableFormatExpression.setCellPadding( 5 );
tableFormatExpression.setCellPadding( 2 );
// tableFormatExpression.setBackground( QColor(235, 235, 220) ); // 180, 180, 180
tableFormatExpression.setBackground( QColor(235, 0, 0) ); // 180, 180, 180

Expand All @@ -194,15 +196,12 @@ namespace IAEX
// QMessageBox::information(0,"uu2", node->text());

QString html = node->textHtml();
html += "<br><br>";
cursor.insertFragment( QTextDocumentFragment::fromHtml( html ));
}
else
{
QString html = node->textHtml();
html += "<br><br>";
html.remove( "file:///" );
QTextDocumentFragment frgmnt;
printEditor_->document()->setTextWidth(700);
cursor.insertFragment(QTextDocumentFragment::fromHtml( html ));
// QMessageBox::information(0, "uu3", node->text());
Expand Down Expand Up @@ -246,9 +245,8 @@ namespace IAEX
// input table
QTextTableFormat tableFormatInput;
tableFormatInput.setBorder( 0 );
tableFormatInput.setMargin( 6 );
tableFormatInput.setColumns( 1 );
tableFormatInput.setCellPadding( 8 );
tableFormatInput.setCellPadding( 2 );
tableFormatInput.setBackground( QColor(245, 245, 255) ); // 200, 200, 255

QVector<QTextLength> constraints;
Expand All @@ -258,19 +256,17 @@ namespace IAEX

QString html = node->textHtml();
// QMessageBox::information(0, "uu1", node->text());
html += "<br>";
if( !node->isEvaluated() || node->isClosed() )
html += "<br>";
html += "<br />";
cursor.insertFragment( QTextDocumentFragment::fromHtml( html ));

// output table
if( node->isEvaluated() && !node->isClosed() )
{
QTextTableFormat tableFormatOutput;
tableFormatOutput.setBorder( 0 );
tableFormatOutput.setMargin( 6 );
tableFormatOutput.setColumns( 1 );
tableFormatOutput.setCellPadding( 8 );
tableFormatOutput.setCellPadding( 2 );
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatOutput.setColumnWidthConstraints(constraints);
Expand All @@ -279,8 +275,6 @@ namespace IAEX
cursor.insertTable( 1, 1, tableFormatOutput );

QString outputHtml( node->textOutputHtml() );
outputHtml += "<br><br>";


outputHtml.remove( "file:///" );
cursor.insertFragment( QTextDocumentFragment::fromHtml( outputHtml ));
Expand Down Expand Up @@ -334,28 +328,25 @@ namespace IAEX
// input table
QTextTableFormat tableFormatInput;
tableFormatInput.setBorder( 0 );
tableFormatInput.setMargin( 6 );
tableFormatInput.setColumns( 1 );
tableFormatInput.setCellPadding( 8 );
tableFormatInput.setCellPadding( 2 );
tableFormatInput.setBackground( QColor(245, 245, 255) ); // 200, 200, 255
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatInput.setColumnWidthConstraints(constraints);
cursor.insertTable( 1, 1, tableFormatInput );

QString html = node->textHtml();
html += "<br>";
if( !node->isEvaluated() || node->isClosed() )
html += "<br>";
html += "<br />";
cursor.insertFragment( QTextDocumentFragment::fromHtml( html ));

if( node->isEvaluated() && !node->isClosed() )
{
QTextTableFormat tableFormatOutput;
tableFormatOutput.setBorder( 0 );
tableFormatOutput.setMargin( 6 );
tableFormatOutput.setColumns( 1 );
tableFormatOutput.setCellPadding( 8 );
tableFormatOutput.setCellPadding( 2 );
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatOutput.setColumnWidthConstraints(constraints);
Expand All @@ -364,14 +355,52 @@ namespace IAEX
cursor.insertTable( 1, 1, tableFormatOutput );

QString outputHtml( node->textOutputHtml() );
outputHtml += "<br><br>";


outputHtml.remove( "file:///" );
cursor.insertFragment( QTextDocumentFragment::fromHtml( outputHtml ));
}

}
// print the plot
if (node->mpPlotWindow && node->mpPlotWindow->isVisible()) {
++currentTableRow_;
table_->insertRows( currentTableRow_, 1 );

// first column
tableCell = table_->cellAt( currentTableRow_, 1 );
if( tableCell.isValid() )
{
QTextCursor cursor( tableCell.firstCursorPosition() );

// input table
QTextTableFormat tableFormatInput;
tableFormatInput.setBorder( 0 );
tableFormatInput.setColumns( 1 );
tableFormatInput.setCellPadding( 2 );
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatInput.setColumnWidthConstraints(constraints);
cursor.insertTable( 1, 1, tableFormatInput );

OMPlot::Plot *pPlot = node->mpPlotWindow->getPlot();
// calculate height for widht while preserving aspect ratio.
int width, height;
if (pPlot->size().width() > 600) {
width = 600;
qreal ratio = (double)pPlot->size().height() / pPlot->size().width();
height = width * qCeil(ratio);
} else {
width = pPlot->size().width();
height = pPlot->size().height();
}
// create a pixmap and render the plot on it
QPixmap plotPixmap(width, height);
QwtPlotRenderer plotRenderer;
plotRenderer.renderTo(pPlot, plotPixmap);
// insert the pixmap to table
cursor.insertImage(plotPixmap.toImage());
}
}

if( firstChild_ )
firstChild_ = false;
Expand Down Expand Up @@ -413,28 +442,25 @@ namespace IAEX
// input table
QTextTableFormat tableFormatInput;
tableFormatInput.setBorder( 0 );
tableFormatInput.setMargin( 6 );
tableFormatInput.setColumns( 1 );
tableFormatInput.setCellPadding( 8 );
tableFormatInput.setCellPadding( 2 );
tableFormatInput.setBackground( QColor(245, 245, 255) ); // 200, 200, 255
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatInput.setColumnWidthConstraints(constraints);
cursor.insertTable( 1, 1, tableFormatInput );

QString html = node->textHtml();
html += "<br>";
if( !node->isEvaluated() || node->isClosed() )
html += "<br>";
html += "<br />";
cursor.insertFragment( QTextDocumentFragment::fromHtml( html ));

if( node->isEvaluated() && !node->isClosed() )
{
QTextTableFormat tableFormatOutput;
tableFormatOutput.setBorder( 0 );
tableFormatOutput.setMargin( 6 );
tableFormatOutput.setColumns( 1 );
tableFormatOutput.setCellPadding( 8 );
tableFormatOutput.setCellPadding( 2 );
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatOutput.setColumnWidthConstraints(constraints);
Expand All @@ -443,8 +469,6 @@ namespace IAEX
cursor.insertTable( 1, 1, tableFormatOutput );

QString outputHtml( node->textOutputHtml() );
outputHtml += "<br><br>";


outputHtml.remove( "file:///" );
cursor.insertFragment( QTextDocumentFragment::fromHtml( outputHtml ));
Expand Down

0 comments on commit cb438f2

Please sign in to comment.