void PointPortOverlay::paint(QPainter &p, bool) { p.setViewTransformEnabled(true); mTransform = p.deviceTransform(); if (mButtonDown) { QPen pen(QBrush(Qt::green), 2.0); pen.setCosmetic(true); p.setPen(pen); p.drawLine(mCurrentPoint - QPointF(0, 5), mCurrentPoint + QPointF(0, 5)); p.drawLine(mCurrentPoint - QPointF(5, 0), mCurrentPoint + QPointF(5, 0)); } }
void SXBSchView::print(QPrinter* pPrinter) { m_pDoc->resetSelect(); updateViewBuffer(true); QPainter paint; if(paint.begin(pPrinter ) ) { int dpi; #ifdef Q_WS_MACX int dpix,dpiy;; dpix = pPrinter->logicalDpiX(); dpiy = pPrinter->logicalDpiY(); dpi=((dpix < dpiy) ? dpix : dpiy); #else dpi = pPrinter->resolution(); #endif paint.setRenderHint(QPainter::Antialiasing, true); // QRect rcPaper = pPrinter->paperRect(); // printf("paperRect %d,%d,%d,%d\n",rcPaper.left(),rcPaper.top(),rcPaper.width(),rcPaper.height()); QRect rcVp = paint.viewport(); QRect rcPg = pPrinter->pageRect(); // printf("pageRect %d,%d,%d,%d\n",rcPg.left(),rcPg.top(),rcPg.width(),rcPg.height()); // int orientation = pPrinter->orientation(); // printf("orientation %d\n",orientation); int vpWidth, vpHeight; int pgLeft, pgTop, pgWidth, pgHeight; vpWidth =rcVp.width(); vpHeight = rcVp.height(); pgLeft =rcPg.left(); pgTop =rcPg.top(); pgWidth =rcPg.width(); pgHeight = rcPg.height(); //印刷時に印刷の向きを変えてもpageRect()の返す値が変わらないQtのバグ(?)の対策 if( (vpWidth > vpHeight && pgWidth < pgHeight) || (vpWidth < vpHeight && pgWidth > pgHeight) ) { int swapn; swapn = pgLeft; pgLeft = pgTop; pgTop = swapn; swapn = pgWidth; pgWidth = pgHeight; pgHeight = swapn; } QSettings *settings = g_cfg.getSettings(); int leftMargin = 15; int topMargin = 15; int rightMargin = 15; int bottomMargin = 15; settings->beginGroup("PrintOption"); bool color = settings->value("Color",true).toBool(); settings->endGroup(); settings->beginGroup("PrintMargin"); topMargin = settings->value("Top",15).toInt(); bottomMargin = settings->value("Bottom",15).toInt(); leftMargin = settings->value("Left",15).toInt(); rightMargin = settings->value("Right",15).toInt(); settings->endGroup(); if (topMargin < 0) topMargin = 0; else if (topMargin > 50) topMargin = 50; if (bottomMargin < 0) bottomMargin = 0; else if (bottomMargin > 50) bottomMargin = 50; if (leftMargin < 0) leftMargin = 0; else if (leftMargin > 50) leftMargin = 50; if (rightMargin < 0) rightMargin = 0; else if (rightMargin > 50) rightMargin = 50; topMargin = dpi * 10 * topMargin / 254; bottomMargin = dpi * 10 * bottomMargin / 254; leftMargin = dpi * 10 * leftMargin / 254; rightMargin = dpi * 10 * rightMargin / 254; // printf("SXBSchView::print() dpi:%d\n",dpi); paint.save(); paint.setViewTransformEnabled (true); paint.resetMatrix(); SSize size = m_pDoc->SheetSize(); int w = size.w(); int h = size.h(); int dw = w*10; int dh = h*10; // p->setWindow( 0,0, dw, dh ); // QRect rc = paint.viewport(); int rightWidth = vpWidth-(pgLeft+pgWidth); if(rightWidth < 0) rightWidth = 0; int bottomWidth = vpHeight-(pgTop+pgHeight); if(bottomWidth < 0) bottomWidth = 0; leftMargin -= pgLeft; if(leftMargin < 0)leftMargin = 0; topMargin -= pgTop; if(topMargin < 0) topMargin = 0; rightMargin -= rightWidth; if(rightMargin < 0) rightMargin = 0; bottomMargin -= bottomWidth; if(bottomMargin < 0) bottomMargin = 0; int vw = pgWidth-(leftMargin+rightMargin); int vh = pgHeight-(topMargin+bottomMargin); double sheetRatio=(double)w / (double)h; double viewRatio=(double)vw / (double)vh; int newW; int newH; if(sheetRatio > viewRatio) { newW = vw; newH = (int)(vw / sheetRatio); } else { newH = vh; newW = (int)(vh * sheetRatio); } // printf("newW,H=%d,%d\n",newW,newH); // p->setViewport( rc.left() + (vw-newW)/2, // rc.top() + (vh-newH)/2, // newW, newH ); // QRect rcvp = p->viewport(); // printf("x,y,w,h %d,%d,%d,%d\n",rcvp.x(),rcvp.y(),rcvp.width(),rcvp.height()); paint.setViewport( leftMargin+ (vw-newW)/2, topMargin + (vh-newH)/2, newW, newH ); paint.setWindow( 0,0, dw, dh ); // rcvp = p->viewport(); // printf("x,y,w,h %d,%d,%d,%d\n",rcvp.x(),rcvp.y(),rcvp.width(),rcvp.height()); QRect rcClip = QRect(0,0,dw,dh); SRect srcClip =SRect(0,0,w,h); paint.setBackground(Qt::white); paint.eraseRect(0,0,dw,dh); g_drawFrame(&paint,size,rcClip,Qt::black,1,10); drawMainXBSchObj(&paint,(color ? DRAW_ON : DRAW_MONO)|DRAW_FOR_PRINT,&srcClip,false,1,10); paint.restore(); paint.end(); } }