diff --git a/src/gui/protein_view/proteinwindow.cpp b/src/gui/protein_view/proteinwindow.cpp index 8a63248d95e18d4bca3010a5293afb80435f7763..15e215346a1cb70f15857f35e1226a828e9ee664 100644 --- a/src/gui/protein_view/proteinwindow.cpp +++ b/src/gui/protein_view/proteinwindow.cpp @@ -145,11 +145,11 @@ void ProteinWindow::doSaveSvg() { QSettings settings; QString default_location = settings.value("path/export_svg", "").toString(); - QString proposed_filename = QString("%1/protein_%1.svg").arg(_p_protein_match->getProteinXtpSp().get()->getAccession()); + QString proposed_filename = QString("%1/protein_%1.pdf").arg(_p_protein_match->getProteinXtpSp().get()->getAccession()); - QString filename = QFileDialog::getSaveFileName(this, tr("Save SVG file"), + QString filename = QFileDialog::getSaveFileName(this, tr("Save PDF file"), proposed_filename, - tr("Scalable Vector Graphic (*.svg)")); + tr("pdf (*.pdf)")); if (filename.isEmpty()) { return; @@ -157,13 +157,21 @@ void ProteinWindow::doSaveSvg() { settings.setValue("path/export_svg", QFileInfo(filename).absolutePath()); - QSvgGenerator generator; - //generator.setOutputDevice(&buffer); - QSize size(600, 1000); - generator.setFileName(filename); - generator.setSize(size); - generator.setViewBox(QRect(0, 0, size.width(), size.height())); - generator.setTitle(_p_protein_match->getProteinXtpSp().get()->getAccession()); + //https://bugreports.qt.io/browse/QTBUG-52538 + QPrinter printer(QPrinter::PrinterResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setPaperSize(QPrinter::A4); + printer.setOutputFileName(filename); + /* + QSvgGenerator generator; + //generator.setOutputDevice(&buffer); + QSize size(600, 1000); + generator.setFileName(filename); + generator.setSize(size); + generator.setViewBox(QRect(0, 0, size.width(), size.height())); + generator.setTitle(_p_protein_match->getProteinXtpSp().get()->getAccession()); + */ + //generator.setDescription(description); //QPainter painter; //painter.begin(&generator); @@ -176,7 +184,7 @@ void ProteinWindow::doSaveSvg() { font.setStyleHint(QFont::Monospace); font.setLetterSpacing(QFont::AbsoluteSpacing,0); font.setPointSize(16); //generator.setDefaultFont(font); - + QTextOption text_option; text_option.setWrapMode(QTextOption::WrapAnywhere); text_option.setFlags(QTextOption::IncludeTrailingSpaces|QTextOption::ShowTabsAndSpaces); @@ -185,21 +193,22 @@ void ProteinWindow::doSaveSvg() { QTextDocument *doc = ui->sequenceTextEdit->document()->clone(); doc->setUndoRedoEnabled(false); //doc->setHtml("<p><span style=\"color:#000000; font-weight:600\">"+text_x+"</span></p>"); - doc->setTextWidth(size.width()); + doc->setTextWidth(printer.pageRect().size().width()); doc->setDefaultFont(font); - doc->setPageSize(size); - doc->setUseDesignMetrics(true); - doc->setDefaultTextOption ( QTextOption (Qt::AlignHCenter ) ); - doc->setDefaultTextOption(text_option); + doc->setPageSize(printer.pageRect().size()); //// height from doc QTextDocument //// http://fop-miniscribus.googlecode.com/svn/trunk/fop_miniscribus.1.0.0/src/floating_box/floatdiagram.cpp //////setMaximumHeight(DocumentHighgtActual()); + doc->setPageSize(printer.pageRect().size()); // This is necessary if you want to hide the page number + doc->print(&printer); - QPainter *painter = new QPainter(&generator); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->setFont(font); - doc->drawContents(painter); - painter->end(); + /* + QPainter *painter = new QPainter(&generator); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->setFont(font); + doc->drawContents(painter); + painter->end(); + */ /*