//show page void FastViewWidget::showPage(int page) { if(page > 0 && page < doc->numPages()+1) { if (page != -1 ){ currentPage = page - 1; emit pageChanged(page); QImage image = doc->page(currentPage) ->renderToImage(scaleFactor * physicalDpiX(), scaleFactor * physicalDpiY()); double ratio = (double)image.width() /(double)image.height(); //compute size int h = height(); int w = (int)(ratio *(double) h); if(h != image.height()) image = image.scaled(w,h,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); // set page on to widget current = new QLabel(this); current->setAlignment(Qt::AlignCenter); current->setPixmap(QPixmap::fromImage(image)); setWidget(current); updateGeometry(); } } }
void Viewer::previousPageClicked() { if (currentPage==0) return; currentPage--; pdfPage = document->page(currentPage); image = pdfPage->renderToImage(scaleFact*physicalDpiX(),scaleFact*physicalDpiY()); myItem->setPixmap(QPixmap::fromImage(image)); }
void ExportWizard::saveSvg() { if (m_ui->svgFilePath->text().isEmpty()) { QMessageBox::warning(this, tr("No file selected !"), tr("You need to choose a file path for saving.")); return; } QString svgFilePath = m_ui->svgFilePath->text(); // get the rendering size QRect svgRect(m_canvas->sceneRect().toRect()); // create the SVG writer QSvgGenerator generator; generator.setFileName(svgFilePath); generator.setSize(svgRect.size()); generator.setResolution(physicalDpiX()); generator.setViewBox(svgRect); generator.setTitle(m_canvas->titleText()); generator.setDescription(tr("Created with %1").arg(QCoreApplication::applicationName() + " " + QCoreApplication::applicationVersion())); // paint over the writer QPainter painter(&generator); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, true); m_canvas->renderVisible(&painter, svgRect, svgRect, Qt::IgnoreAspectRatio, !m_ui->svgAsIsBox->isChecked()); painter.end(); }
void Viewer::loadImageFile(QString exoFile) { if (exoFile.isEmpty()) { image=QImage(); myItem->setPixmap(QPixmap::fromImage(image)); return; } QString pdfFile; if (QFileInfo(exoFile).suffix() == "pdf") pdfFile = exoFile; else { pdfFile = QFileInfo(exoFile).path() + QDir::separator() + QFileInfo(exoFile).baseName()+"-preview.pdf"; } if (QFileInfo(pdfFile).exists()) { document = Poppler::Document::load(pdfFile); document->setRenderHint(Poppler::Document::Antialiasing,true); document->setRenderHint(Poppler::Document::TextAntialiasing,true); document->setRenderHint(Poppler::Document::TextHinting,true); document->setRenderHint(Poppler::Document::TextSlightHinting,true); numPages=document->numPages(); currentPage=0; updatePagesButtons(); pdfPage = document->page(currentPage); image = pdfPage->renderToImage(scaleFact*physicalDpiX(),scaleFact*physicalDpiY()); myItem->setPixmap(QPixmap::fromImage(image)); } else { image=QImage(); myItem->setPixmap(QPixmap::fromImage(image)); return; } }
// default: OutputFormat format = pdf, Measure m = cm, // ResolutionRatio rr = in_px ExportDialog::ExportDialog(QWidget* parent, Exportable *expo, double width, double height, OutputFormat format, Measure m, ResolutionRatio rr) : QDialog(parent), mExp(expo), mWidth(width), mHeight(height) { setupUi(this); mRes = physicalDpiX(); mWidth /= mRes; mHeight /= mRes; if(m==cm) { mWidth *= 2.54; mHeight *= 2.54; } if(rr==cm_px) mRes /= 2.54; outputFormatComboBox->setCurrentIndex(format); measureComboBox->setCurrentIndex(m); resRatioComboBox->setCurrentIndex(rr); resSpinBox->setValue(mRes); widthSpinBox->setValue(mWidth); heightSpinBox->setValue(mHeight); }
void ReportView::scaleView(qreal factor) { qreal f = matrix().scale(factor, factor).mapRect(QRectF(0, 0, 1, 1)).width(); if (f < 0.07 || f > 100) return; Report *report = (Report*)scene(); int dpiX = report ? report->dpiX() : 96; int dpiY = report ? report->dpiY() : 96; QTransform oldTransform = transform(); resetTransform(); translate(oldTransform.dx(), oldTransform.dy()); scale(factor * physicalDpiX() / dpiX, factor * physicalDpiY() / dpiY);; }
void Viewer::onButtonOutClicked() { if (image.width()==0) return; scaleFact-=0.1; image = pdfPage->renderToImage(scaleFact*physicalDpiX(),scaleFact*physicalDpiY()); myItem->setPixmap(QPixmap::fromImage(image)); }
qreal Ruler::physicalDpi() const { return (m_orientation == Qt::Horizontal) ? physicalDpiX() : physicalDpiY(); }