void PrinterVisitor::visitLatexCellNodeBefore(LatexCell *node) { if( !ignore_ || firstChild_ ) { ++currentTableRow_; table_->insertRows( currentTableRow_, 1 ); // first column QTextTableCell tableCell( table_->cellAt( currentTableRow_, 0 ) ); if( tableCell.isValid() ) { if( !node->ChapterCounterHtml().isNull() ) { QTextCursor cursor( tableCell.firstCursorPosition() ); cursor.insertFragment( QTextDocumentFragment::fromHtml( node->ChapterCounterHtml() )); } } // second column tableCell = table_->cellAt( currentTableRow_, 1 ); if( tableCell.isValid() ) { QTextCursor cursor( tableCell.firstCursorPosition() ); // input table QTextTableFormat tableFormatInput; tableFormatInput.setBorder( 0 ); tableFormatInput.setMargin( 6 ); tableFormatInput.setColumns( 1 ); tableFormatInput.setCellPadding( 8 ); 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>"; cursor.insertFragment( QTextDocumentFragment::fromHtml( html )); if( node->isEvaluated() && !node->isClosed() ) { QTextTableFormat tableFormatOutput; tableFormatOutput.setBorder( 0 ); tableFormatOutput.setMargin( 6 ); tableFormatOutput.setColumns( 1 ); tableFormatOutput.setCellPadding( 8 ); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 100); tableFormatOutput.setColumnWidthConstraints(constraints); cursor = tableCell.lastCursorPosition(); cursor.insertTable( 1, 1, tableFormatOutput ); QString outputHtml( node->textOutputHtml() ); outputHtml += "<br><br>"; outputHtml.remove( "file:///" ); cursor.insertFragment( QTextDocumentFragment::fromHtml( outputHtml )); } } if( firstChild_ ) firstChild_ = false; } }
void PrinterVisitor::visitGraphCellNodeBefore(GraphCell *node) { if( !ignore_ || firstChild_ ) { ++currentTableRow_; table_->insertRows( currentTableRow_, 1 ); // first column QTextTableCell tableCell( table_->cellAt( currentTableRow_, 0 ) ); if( tableCell.isValid() ) { if( !node->ChapterCounterHtml().isNull() ) { QTextCursor cursor( tableCell.firstCursorPosition() ); cursor.insertFragment( QTextDocumentFragment::fromHtml( node->ChapterCounterHtml() )); } } // second 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 ); 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(); if( !node->isEvaluated() || node->isClosed() ) html += "<br />"; cursor.insertFragment( QTextDocumentFragment::fromHtml( html )); if( node->isEvaluated() && !node->isClosed() ) { QTextTableFormat tableFormatOutput; tableFormatOutput.setBorder( 0 ); tableFormatOutput.setColumns( 1 ); tableFormatOutput.setCellPadding( 2 ); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 100); tableFormatOutput.setColumnWidthConstraints(constraints); cursor = tableCell.lastCursorPosition(); cursor.insertTable( 1, 1, tableFormatOutput ); QString outputHtml( node->textOutputHtml() ); 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; } }