当前位置: 首页>>代码示例>>C++>>正文


C++ QPrinter::logicalDpiY方法代码示例

本文整理汇总了C++中QPrinter::logicalDpiY方法的典型用法代码示例。如果您正苦于以下问题:C++ QPrinter::logicalDpiY方法的具体用法?C++ QPrinter::logicalDpiY怎么用?C++ QPrinter::logicalDpiY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPrinter的用法示例。


在下文中一共展示了QPrinter::logicalDpiY方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: logicalDpiY

int QPrinterProto::logicalDpiY() const
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    return item->logicalDpiY();
  return 0;
}
开发者ID:AlFoX,项目名称:qt-client,代码行数:7,代码来源:qprinterproto.cpp

示例2: printf

void printerInvoice::printf(const QString &html)
{
	QPrinter p;
	QTextDocument doc;
	QFont font = doc.defaultFont();
	font.setBold(true);
	font.setPointSize(font.pointSize());
	doc.setDefaultFont(font);
	QSizeF s = QSizeF(p.logicalDpiX() * 7.5, p.logicalDpiY() * 7.5);
	doc.setPageSize(s);
	p.setOutputFormat(QPrinter::NativeFormat);
	doc.setHtml(html);
	doc.print(&p);
}
开发者ID:bighome,项目名称:Jewelry_System,代码行数:14,代码来源:printerinvoice.cpp

示例3: exportVector

void Matrix::exportVector(const QString& fileName, int res, bool color, bool keepAspect, QPrinter::PageSize pageSize)
{
    if (d_view_type != ImageView)
        return;

	if ( fileName.isEmpty() ){
		QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please provide a valid file name!"));
        return;
	}

	QPrinter printer;
    printer.setCreator("QtiPlot");
	printer.setFullPage(true);
	if (res)
		printer.setResolution(res);

    printer.setOutputFileName(fileName);
    if (fileName.contains(".eps"))
    	printer.setOutputFormat(QPrinter::PostScriptFormat);

    if (color)
		printer.setColorMode(QPrinter::Color);
	else
		printer.setColorMode(QPrinter::GrayScale);

    int cols = numCols();
    int rows = numRows();
    QRect rect = QRect(0, 0, cols, rows);
    if (pageSize == QPrinter::Custom)
        printer.setPageSize(Graph::minPageSize(printer, rect));
    else
        printer.setPageSize(pageSize);

    double aspect = (double)cols/(double)rows;
	if (aspect < 1)
		printer.setOrientation(QPrinter::Portrait);
	else
		printer.setOrientation(QPrinter::Landscape);

    if (keepAspect){// export should preserve aspect ratio
        double page_aspect = double(printer.width())/double(printer.height());
        if (page_aspect > aspect){
            int margin = (int) ((0.1/2.54)*printer.logicalDpiY()); // 1 mm margins
            int height = printer.height() - 2*margin;
            int width = int(height*aspect);
            int x = (printer.width()- width)/2;
            rect = QRect(x, margin, width, height);
        } else if (aspect >= page_aspect){
            int margin = (int) ((0.1/2.54)*printer.logicalDpiX()); // 1 mm margins
            int width = printer.width() - 2*margin;
            int height = int(width/aspect);
            int y = (printer.height()- height)/2;
            rect = QRect(margin, y, width, height);
        }
	} else {
	    int x_margin = (int) ((0.1/2.54)*printer.logicalDpiX()); // 1 mm margins
        int y_margin = (int) ((0.1/2.54)*printer.logicalDpiY()); // 1 mm margins
        int width = printer.width() - 2*x_margin;
        int height = printer.height() - 2*y_margin;
        rect = QRect(x_margin, y_margin, width, height);
	}

    QPainter paint(&printer);
    paint.drawImage(rect, d_matrix_model->renderImage());
    paint.end();
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:66,代码来源:Matrix.cpp

示例4: print

void Matrix::print(const QString& fileName)
{
	QPrinter printer;
	printer.setColorMode (QPrinter::GrayScale);

	if (!fileName.isEmpty()){
	    printer.setCreator("QtiPlot");
	    printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
	} else {
        QPrintDialog printDialog(&printer, applicationWindow());
        if (printDialog.exec() != QDialog::Accepted)
            return;
    }
		printer.setFullPage( true );
		QPainter p;
		if ( !p.begin(&printer ) )
			return; // paint on printer
		int dpiy = printer.logicalDpiY();
		const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins

        if (d_view_type == ImageView){
            p.drawImage (printer.pageRect(), d_matrix_model->renderImage());
            return;
        }

		QHeaderView *vHeader = d_table_view->verticalHeader();

		int rows = numRows();
		int cols = numCols();
		int height = margin;
		int i, vertHeaderWidth = vHeader->width();
		int right = margin + vertHeaderWidth;

		// print header
		p.setFont(QFont());
		QString header_label = d_matrix_model->headerData(0, Qt::Horizontal).toString();
		QRect br = p.boundingRect(br, Qt::AlignCenter, header_label);
		p.drawLine(right, height, right, height+br.height());
		QRect tr(br);

		for(i=0; i<cols; i++){
			int w = d_table_view->columnWidth(i);
			tr.setTopLeft(QPoint(right,height));
			tr.setWidth(w);
			tr.setHeight(br.height());
			header_label = d_matrix_model->headerData(i, Qt::Horizontal).toString();
			p.drawText(tr, Qt::AlignCenter, header_label,-1);
			right += w;
			p.drawLine(right, height, right, height+tr.height());

			if (right >= printer.width()-2*margin )
				break;
		}

		p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
		height += tr.height();
		p.drawLine(margin, height, right-1, height);

		// print table values
		for(i=0;i<rows;i++){
			right = margin;
			QString cell_text = d_matrix_model->headerData(i, Qt::Horizontal).toString()+"\t";
			tr = p.boundingRect(tr, Qt::AlignCenter, cell_text);
			p.drawLine(right, height, right, height+tr.height());

			br.setTopLeft(QPoint(right,height));
			br.setWidth(vertHeaderWidth);
			br.setHeight(tr.height());
			p.drawText(br,Qt::AlignCenter,cell_text,-1);
			right += vertHeaderWidth;
			p.drawLine(right, height, right, height+tr.height());

			for(int j=0; j<cols; j++){
				int w = d_table_view->columnWidth (j);
				cell_text = text(i,j)+"\t";
				tr = p.boundingRect(tr,Qt::AlignCenter,cell_text);
				br.setTopLeft(QPoint(right,height));
				br.setWidth(w);
				br.setHeight(tr.height());
				p.drawText(br, Qt::AlignCenter, cell_text, -1);
				right += w;
				p.drawLine(right, height, right, height+tr.height());

				if (right >= printer.width()-2*margin )
					break;
			}
			height += br.height();
			p.drawLine(margin, height, right-1, height);

			if (height >= printer.height()-margin ){
				printer.newPage();
				height = margin;
				p.drawLine(margin, height, right, height);
			}
		}
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:97,代码来源:Matrix.cpp

示例5: printAllLayers

void MultiLayer::printAllLayers(QPainter *painter) {
  if (!painter) return;

  QPrinter *printer = (QPrinter *)painter->device();
  QRect paperRect = ((QPrinter *)painter->device())->paperRect();
  QRect canvasRect = canvas->rect();
  QRect pageRect = printer->pageRect();
  QRect cr = canvasRect;  // cropmarks rectangle

  if (d_scale_on_print) {
    int margin = (int)((1 / 2.54) * printer->logicalDpiY());  // 1 cm margins
    double scaleFactorX =
        (double)(paperRect.width() - 2 * margin) / (double)canvasRect.width();
    double scaleFactorY =
        (double)(paperRect.height() - 2 * margin) / (double)canvasRect.height();

    if (d_print_cropmarks) {
      cr.moveTo(QPoint(margin + int(cr.x() * scaleFactorX),
                       margin + int(cr.y() * scaleFactorY)));
      cr.setWidth(int(cr.width() * scaleFactorX));
      cr.setHeight(int(cr.height() * scaleFactorX));
    }

    for (int i = 0; i < (int)graphsList.count(); i++) {
      Graph *gr = (Graph *)graphsList.at(i);
      Plot *myPlot = gr->plotWidget();

      QPoint pos = gr->pos();
      pos = QPoint(margin + int(pos.x() * scaleFactorX),
                   margin + int(pos.y() * scaleFactorY));

      int width = int(myPlot->frameGeometry().width() * scaleFactorX);
      int height = int(myPlot->frameGeometry().height() * scaleFactorY);

      gr->print(painter, QRect(pos, QSize(width, height)));
    }
  } else {
    int x_margin = (pageRect.width() - canvasRect.width()) / 2;
    int y_margin = (pageRect.height() - canvasRect.height()) / 2;

    if (d_print_cropmarks) cr.moveTo(x_margin, y_margin);

    for (int i = 0; i < (int)graphsList.count(); i++) {
      Graph *gr = (Graph *)graphsList.at(i);
      Plot *myPlot = (Plot *)gr->plotWidget();

      QPoint pos = gr->pos();
      pos = QPoint(x_margin + pos.x(), y_margin + pos.y());
      gr->print(painter, QRect(pos, myPlot->size()));
    }
  }
  if (d_print_cropmarks) {
    cr.addCoords(-1, -1, 2, 2);
    painter->save();
    painter->setPen(QPen(QColor(Qt::black), 0.5, Qt::DashLine));
    painter->drawLine(paperRect.left(), cr.top(), paperRect.right(), cr.top());
    painter->drawLine(paperRect.left(), cr.bottom(), paperRect.right(),
                      cr.bottom());
    painter->drawLine(cr.left(), paperRect.top(), cr.left(),
                      paperRect.bottom());
    painter->drawLine(cr.right(), paperRect.top(), cr.right(),
                      paperRect.bottom());
    painter->restore();
  }
}
开发者ID:narunlifescience,项目名称:AlphaPlot,代码行数:65,代码来源:MultiLayer.cpp


注:本文中的QPrinter::logicalDpiY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。