void Printer::flowRender() { // add extra padding at the bottom to pages with height not divisible by view port int paddingBottom = pageSize.height() - (webView->page()->mainFrame()->contentsSize().height() % pageSize.height()); QString styleString = QString::fromUtf8("padding-bottom: ") + QString::number(paddingBottom) + "px;"; webView->page()->mainFrame()->findFirstElement("body").setAttribute("style", styleString); // render the Qwebview QPainter painter; QRect viewPort(0, 0, 0, 0); painter.begin(paintDevice); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); // get all references to dontbreak divs int start = 0, end = 0; int fullPageResolution = webView->page()->mainFrame()->contentsSize().height(); QWebElementCollection dontbreak = webView->page()->mainFrame()->findAllElements(".dontbreak"); foreach (QWebElement dontbreakElement, dontbreak) { if ((dontbreakElement.geometry().y() + dontbreakElement.geometry().height()) - start < pageSize.height()) { // One more element can be placed end = dontbreakElement.geometry().y() + dontbreakElement.geometry().height(); } else { // fill the page with background color QRect fullPage(0, 0, pageSize.width(), pageSize.height()); QBrush fillBrush(templateOptions->color_palette.color1); painter.fillRect(fullPage, fillBrush); QRegion reigon(0, 0, pageSize.width(), end - start); viewPort.setRect(0, start, pageSize.width(), end - start); // render the base Html template webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon); // scroll the webview to the next page webView->page()->mainFrame()->scroll(0, dontbreakElement.geometry().y() - start); // rendering progress is 4/5 of total work emit(progessUpdated((end * 80.0 / fullPageResolution) + done)); // add new pages only in print mode, while previewing we don't add new pages if (printMode == Printer::PRINT) static_cast<QPrinter*>(paintDevice)->newPage(); else { painter.end(); return; } start = dontbreakElement.geometry().y(); } } // render the remianing page QRect fullPage(0, 0, pageSize.width(), pageSize.height()); QBrush fillBrush(templateOptions->color_palette.color1); painter.fillRect(fullPage, fillBrush); QRegion reigon(0, 0, pageSize.width(), end - start); webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon); painter.end(); }
void CHeaderDockPane::DrawAd(CPaintDC & dc) { //CPaintDC dc(this); //CDC pDC; //pDC.CreateCompatibleDC(&dc); CRect rect; GetClientRect(&rect); if(rect.right > 500) { CBrush bg; bg.CreateStockObject(RGB(0,0,0)); CBrush fillBrush(RGB(250, 0, 0)); CBrush *oldFillBrush = dc.SelectObject(&fillBrush); //rect = CRect( CPoint(rect.left, rect.top), CPoint(rect.right, rect.bottom - 2) ); //rect = CRect( CPoint(200, 5), CPoint(400, 25) ); //dc.FillRect(&rect, &bg); int height = 22; int progress_x = rect.right - 300 - 1; int progress_y = -22; CPoint prorgess_border_points[5]; prorgess_border_points[0] = CPoint(progress_x, progress_y); prorgess_border_points[1] = CPoint(progress_x, progress_y + height); prorgess_border_points[2] = CPoint(progress_x+(rect.right - progress_x)-20 - 1, progress_y + height); prorgess_border_points[3] = CPoint(progress_x+(rect.right - progress_x)-20 - 1, progress_y); prorgess_border_points[4] = CPoint(progress_x, progress_y); CPen penOutline(PS_SOLID, 1, RGB(175, 175, 175)); dc.SelectObject(&penOutline); dc.Polyline(prorgess_border_points, 5); } }
//-------------------------------------------------------------------------------------------------- void ImageViewDialog::setKeyPointInstancesToDisplay( const std::vector<KeyPointInstanceData>& keyPointInstances ) { mKeyPointInstances = keyPointInstances; // Remove any existing graphic items used to display the key points for ( uint32_t itemIdx = 0; itemIdx < mKeyPointGraphicItems.size(); itemIdx++ ) { mpScene->removeItem( mKeyPointGraphicItems[ itemIdx ] ); } mKeyPointGraphicItems.clear(); const float KEYPOINT_SIDE_LENGTH = 4.0; for ( uint32_t keyPointIdx = 0; keyPointIdx < mKeyPointInstances.size(); keyPointIdx++ ) { const KeyPointInstanceData& instanceData = mKeyPointInstances[ keyPointIdx ]; float topLeftX = instanceData.mProjectedPosition[ 0 ] - KEYPOINT_SIDE_LENGTH/2.0; float topLeftY = instanceData.mProjectedPosition[ 1 ] - KEYPOINT_SIDE_LENGTH/2.0; QPen outlinePen( ( QBrush( QColor( 0, 0, 0 ) ), 1.0 ) ); QBrush fillBrush( QColor( instanceData.mR, instanceData.mG, instanceData.mB ) ); mKeyPointGraphicItems.push_back( mpScene->addEllipse( topLeftX, topLeftY, KEYPOINT_SIDE_LENGTH, KEYPOINT_SIDE_LENGTH, outlinePen, fillBrush ) ); } }
void CHeaderDockPane::OnPaint() { CPaintDC dc(this); CDC pDC; pDC.CreateCompatibleDC(&dc); // device context for painting // TODO: Add your message handler code here // Do not call CDockablePane::OnPaint() for painting messages CRect rect; GetClientRect(&rect); //Manual BG repaint CBrush bg; bg.CreateStockObject(RGB(236,236,236)); //CPen penFill(PS_NULL,0,RGB(250,0,0)); //dc.SelectObject(&penFill); CBrush fillBrush(RGB(236, 236, 236)); CBrush *oldFillBrush = dc.SelectObject(&fillBrush); dc.FillRect(&rect, &bg); //dc.Ellipse(&rect); //DrawAd(dc); //Invalidate(); }
void ASSISTANT::Oval::Draw(CDC *pDC, float _zoomFactor, double dOffX, double dOffY) { if (!visible) return; if (m_dWidth == 0 && m_dHeight == 0) return; Gdiplus::Graphics graphics(pDC->m_hDC); graphics.TranslateTransform(dOffX, dOffY); graphics.ScaleTransform(_zoomFactor, _zoomFactor); // there are problems if circles have netagive width and height double dX = m_dX; double dY = m_dY; double dWidth = m_dWidth; double dHeight = m_dHeight; if (m_dWidth < 0) { dX = m_dX + m_dWidth; dWidth = -m_dWidth; } if (m_dHeight < 0) { dY = m_dY + m_dHeight; dHeight = -m_dHeight; } graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); bool bDrawLine = true; if (m_argbFillColor != 0) { Gdiplus::Color fillColor(m_argbFillColor); Gdiplus::SolidBrush fillBrush(fillColor); if (m_argbFillColor == m_argbLineColor) { graphics.FillEllipse(&fillBrush, (Gdiplus::REAL)(dX-lineWidth/2), (Gdiplus::REAL)(dY-lineWidth/2), (Gdiplus::REAL)(dWidth+lineWidth), (Gdiplus::REAL)(dHeight+lineWidth)); bDrawLine = false; } else { graphics.FillEllipse(&fillBrush, (Gdiplus::REAL)(dX+lineWidth/2), (Gdiplus::REAL)(dY+lineWidth/2), (Gdiplus::REAL)(dWidth-lineWidth+1), (Gdiplus::REAL)(dHeight-lineWidth+1)); } } if (bDrawLine) { Gdiplus::Color lineColor(m_argbLineColor); Gdiplus::Pen pen(lineColor, lineWidth); pen.SetDashStyle(m_gdipLineStyle); graphics.DrawEllipse(&pen, (Gdiplus::REAL)dX, (Gdiplus::REAL)dY, (Gdiplus::REAL)dWidth, (Gdiplus::REAL)dHeight); } }
void GraphBlock::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) { QLinearGradient fillBrush( QPointF(0, 0), QPointF(0, m_captionBounds.height())); fillBrush.setColorAt( 0, isSelected() ? QColor( 255, 226, 96 ) : QColor( 200, 200, 200 ) ); fillBrush.setColorAt( 0.5f, QColor( 70, 70, 70 ) ); painter->save(); painter->setRenderHint( QPainter::Antialiasing, true ); painter->setRenderHint( QPainter::TextAntialiasing, true ); painter->setFont( m_font ); const float edgeRadius = 3.0f; // draw the block's layout { painter->setPen( GraphWidgetUtils::s_borderPen ); painter->setBrush( QColor( 150, 150, 150 ) ); painter->setOpacity( 0.5f ); painter->drawRoundedRect( m_bounds, edgeRadius, edgeRadius ); } // draw the header { QPainterPath path; QRectF topBB = m_captionBounds; topBB.setHeight( m_captionBounds.height() + edgeRadius ); QRectF bottomBB = m_captionBounds; bottomBB.setTop( m_captionBounds.height() ); bottomBB.setHeight( edgeRadius ); path.addRoundedRect( topBB, edgeRadius, edgeRadius ); path.addRect( bottomBB ); painter->setOpacity( 1.0f ); painter->setPen( Qt::NoPen ); painter->setBrush( fillBrush ); painter->drawPath( path ); GraphWidgetUtils::drawShadowedText( painter, m_captionBounds, m_caption.c_str(), QTextOption( Qt::AlignCenter ) ); } painter->restore(); }
KDEFX_EXPORT void kDrawRoundMask(QPainter *p, int x, int y, int w, int h, bool clear) { // round edge fills static const QCOORD btm_left_fill[]={ 0,0,1,0,2,0,3,0,4,0,0,1,1,1,2,1,3,1,4,1, 1,2,2,2,3,2,4,2,2,3,3,3,4,3,3,4,4,4 }; static const QCOORD btm_right_fill[]={ 0,0,1,0,2,0,3,0,4,0,0,1,1,1,2,1,3,1,4, 1,0,2,1,2,2,2,3,2,0,3,1,3,2,3,0,4,1,4 }; static const QCOORD top_left_fill[]={ 3,0,4,0,2,1,3,1,4,1,1,2,2,2,3,2,4,2,0,3, 1,3,2,3,3,3,4,3,0,4,1,4,2,4,3,4,4,4 }; static const QCOORD top_right_fill[]={ 0,0,1,0,0,1,1,1,2,1,0,2,1,2,2,2,3,2,0, 3,1,3,2,3,3,3,4,3,0,4,1,4,2,4,3,4,4,4 }; if(clear) p->fillRect(x, y, w, h, QBrush(Qt::color0, Qt::SolidPattern)); QBrush fillBrush(Qt::color1, Qt::SolidPattern); p->setPen(Qt::color1); if(w > 16 && h > 16){ int x2 = x+w-1; int y2 = y+h-1; QPointArray a(QCOORDARRLEN(top_left_fill), top_left_fill); a.translate(1, 1); p->drawPoints(a); a.setPoints(QCOORDARRLEN(btm_left_fill), btm_left_fill); a.translate(1, h-6); p->drawPoints(a); a.setPoints(QCOORDARRLEN(top_right_fill), top_right_fill); a.translate(w-6, 1); p->drawPoints(a); a.setPoints(QCOORDARRLEN(btm_right_fill), btm_right_fill); a.translate(w-6, h-6); p->drawPoints(a); p->fillRect(x+6, y, w-12, h, fillBrush); p->fillRect(x, y+6, x+6, h-12, fillBrush); p->fillRect(x2-6, y+6, x2, h-12, fillBrush); p->drawLine(x+6, y, x2-6, y); p->drawLine(x+6, y2, x2-6, y2); p->drawLine(x, y+6, x, y2-6); p->drawLine(x2, y+6, x2, y2-6); } else p->fillRect(x, y, w, h, fillBrush); }
void UBGraphicsProtractor::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { painter->save(); Q_UNUSED(styleOption); Q_UNUSED(widget); painter->setFont(QFont("Arial")); painter->setPen(drawColor()); painter->setBrush(fillBrush()); painter->drawPie(QRectF(rect().center().x() - radius(), rect().center().y() - radius(), 2 * radius(), 2 * radius()), mStartAngle * 16, mSpan * 16); paintGraduations(painter); paintButtons(painter); paintAngleMarker(painter); painter->restore(); }
void KisToolPan::paint(QPainter& gc, const KoViewConverter &converter) { Q_UNUSED(converter); if(m_rotationMode) { const KisCoordinatesConverter *converter = kritaCanvas()->coordinatesConverter(); QPointF centerPoint = converter->flakeCenterPoint(); QBrush fillBrush(QColor(0,0,0,100)); QPen checkerPen(QColor(255,255,255,100), 5., Qt::SolidLine, Qt::RoundCap); gc.save(); gc.setPen(Qt::NoPen); gc.setBrush(fillBrush); gc.drawEllipse(centerPoint, m_checkerRadius, m_checkerRadius); gc.setPen(checkerPen); gc.drawLine(centerPoint, centerPoint + QPointF(0, -m_checkerRadius)); gc.restore(); } }
void CGraphicsView::OnDraw(CDC* /*pDC*/) { CGraphicsDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: 在此处为本机数据添加绘制代码 CRect rc; GetClientRect(&rc); CDC dcMem; dcMem.CreateCompatibleDC(NULL); CBitmap bmMem; bmMem.CreateCompatibleBitmap(GetDC(), rc.Width(), rc.Height()); dcMem.SelectObject(&bmMem); CBrush fillBrush(RGB(255, 255, 255)); dcMem.FillRect(&rc, &fillBrush); if (m_pSrcBitmap != NULL && m_pDstBitmap != NULL) { BITMAP bm; m_pSrcBitmap->GetBitmap(&bm); int x = (rc.Width() - bm.bmWidth * 2) / 2; int y = (rc.Height() - bm.bmHeight) / 2; if (x < 0) x = 0; if (y < 0) y = 0; DrawBitmap(&dcMem, x, y, rc.Width(), rc.Height(), m_pSrcBitmap, 0, 0); x += bm.bmWidth; DrawBitmap(&dcMem, x, y, rc.Width(), rc.Height(), m_pDstBitmap, 0, 0); } if (!m_rcSelected.IsRectEmpty()) { DrawRect(&dcMem, &m_rcSelected, RGB(255, 0, 0)); } if (!m_rcClient.IsRectEmpty()) { DrawRect(&dcMem, &m_rcClient, RGB(0, 255, 0)); } if (!m_strText.IsEmpty()) { DrawString(&dcMem, 100, m_rcClient.bottom - 30, m_strText); } int N = 64; float pi = 3.141592654f; float x_re[64], x_im[64], y_re[64], y_im[64]; for (int i = 0; i < N; i++) { x_re[i] = 4 * cos(-10 * pi * i / N) + 2 * cos(-16 * pi * i / N); x_im[i] = 0; } for (int i = 0; i < N; i++) { y_re[i] = x_re[i]; y_im[i] = x_im[i]; } sort(y_re, y_im, N); fft(y_re, y_im, N); int scale = 1; int x = 0, y = 500 - y_re[0] * scale; CPen pen(PS_SOLID, 1, RGB(255, 0, 0)); dcMem.SelectObject(&pen); dcMem.MoveTo(0, 500); dcMem.LineTo(rc.right, 500); dcMem.MoveTo(x, y); for (int i = 1; i < N; i++) { x = i * 10; y = 500 - y_re[i] * scale; dcMem.LineTo(x, y); } CClientDC dc(this); dc.BitBlt(0, 0, rc.Width(), rc.Height(), &dcMem, 0, 0, SRCCOPY); }
// /// Paint the item entirely. // void TCheckList::PaintItem(DRAWITEMSTRUCT & drawInfo) { TCheckListItem* item = GetItem(drawInfo.itemID); if (item == 0) return; const bool disabled = !item->IsEnabled() || (drawInfo.itemState & ODS_DISABLED); // Prepare DC // TDC dc(drawInfo.hDC); // Erase entire line // TRect rect(drawInfo.rcItem); TBrush bkgnd(TColor::SysWindow); dc.FillRect(rect, bkgnd); // Draw checkbox // TRect checkboxRect(rect.left+1,rect.top+1, rect.left+CheckList_BoxWidth,rect.bottom-1); // Draw checkbox in 3D Windows Style // uint state; if (item->IsIndeterminate()) state = TUIPart::Button3State|TUIPart::Checked;//TUIPart::Pushed; else state = TUIPart::ButtonCheck; if(item->IsChecked()) state |= TUIPart::Checked; if (disabled) state |= TUIPart::Inactive; TUIPart().Paint(dc, checkboxRect, TUIPart::uiButton, (TUIPart::TState)state); // Draw select state with hightlight color // TRect textRect = rect; textRect.left = checkboxRect.right + 2; if (disabled) { dc.SetTextColor(TColor::SysGrayText); dc.SetBkColor(TColor::SysWindow); } else if (drawInfo.itemState & ODS_SELECTED) { TBrush fillBrush(TColor::SysHighlight); dc.FillRect(textRect, fillBrush); dc.SetTextColor(TColor::SysHighlightText); dc.SetBkColor(TColor::SysHighlight); } else { dc.SetTextColor(TColor::SysWindowText); dc.SetBkColor(TColor::SysWindow); } // Draw Text // textRect.left++; PaintText(dc, textRect, item->Text); textRect.left--; // Draw focus and selected states // if (drawInfo.itemState & ODS_FOCUS) dc.DrawFocusRect(textRect); }
void MultilineTextEdit::drawWhitespaces() { // prepare a rectangle to store the width of the whitespace found QRect space; // get the painter for the text area QPainter pa(viewport()); // get a sane color QColor col=colorGroup().link(); // and a brush of the same color QBrush fillBrush(col); // use it for line drawing pa.setPen(col); // and for filling pa.setBrush(fillBrush); // prepare the carriage return coordinates array QPointArray cr(4); // and the tabulator arrow coordinate array QPointArray tab(7); // whitespace expression QRegExp regex("\\s"); // line buffer QString line; int x,y,pos,paragraph; // start looking in every paragraph for(paragraph=0;paragraph<paragraphs();paragraph++) { // get paragraph text line=text(paragraph); // start looking for whitespaces from the beginning pos=0; while((pos=line.find(regex,pos))!=-1) { // whitespace found is not the carriage return at the end of the line? if(pos<((int)line.length()-1)) { // get whitespace rectangle space=mapToView(paragraph,pos); // extract x/y coordinates x=space.width()/2-1+space.x(); y=space.height()/2-1+space.y(); // if it was a regular blank ... if(regex.cap(0)==" ") { // dras a simple small square pa.drawRect(x-1,y,2,2); } // if it was a tabulator else if(regex.cap(0)=="\t") { // calculate arrow points and draw them filled tab.putPoints(0,7, x-5,y-1, x,y-1, x,y-3, x+3,y, x,y+3, x,y+1, x-5,y+1); pa.drawPolygon(tab); } } // go to next position and resume looking for more whitespaces pos++; } // while // end of line, get carriage return position space=mapToView(paragraph,line.length()-1); // extract x/y positions x=space.width()/2-1+space.x(); y=space.height()/2-1+space.y(); // calculate carriage return triangle coordinates and draw them filled cr.putPoints(0,4, x,y, x,y+1, x+4, y+5, x+4, y-4); pa.drawPolygon(cr); } // for }
void DrawSdk::Rectangle::Draw(HDC hdc, double offX, double offY, ZoomManager *pZm) { if (width_ == 0 && height_ == 0) return; Gdiplus::Graphics graphics(hdc); graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone); graphics.TranslateTransform(offX, offY); if (pZm != NULL) { double zoom = pZm->GetZoomFactor(); graphics.ScaleTransform(zoom, zoom); } double dX = x_; double dY = y_; double dWidth = width_; double dHeight = height_; // Gdiplus only draws rectangles with positive width and height if (width_ < 0) { dX = x_ + width_; dWidth = -width_; } if (height_ < 0) { dY = y_ + height_; dHeight = -height_; } //graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); bool bDrawLine = true; if (isFilled_) { Gdiplus::Color fillColor(m_argbFillColor); Gdiplus::SolidBrush fillBrush(fillColor); if (m_argbFillColor == m_argbLineColor) { graphics.FillRectangle(&fillBrush, (Gdiplus::REAL)(dX-(double)lineWidth_/2), (Gdiplus::REAL)(dY-(double)lineWidth_/2), (Gdiplus::REAL)(dWidth+lineWidth_), (Gdiplus::REAL)(dHeight+lineWidth_)); bDrawLine = false; } else { if (dWidth > lineWidth_ && dHeight > lineWidth_) { graphics.FillRectangle(&fillBrush, (Gdiplus::REAL)(dX+(double)lineWidth_/2), (Gdiplus::REAL)(dY+(double)lineWidth_/2), (Gdiplus::REAL)(dWidth-lineWidth_), (Gdiplus::REAL)(dHeight-lineWidth_)); } else { graphics.FillRectangle(&fillBrush, (Gdiplus::REAL)dX, (Gdiplus::REAL)dY, (Gdiplus::REAL)dWidth, (Gdiplus::REAL)dHeight); } } } if (bDrawLine && lineWidth_ > 0) { Gdiplus::Color lineColor(m_argbLineColor); Gdiplus::Pen pen(lineColor, lineWidth_); pen.SetDashStyle(m_gdipDashStyle); graphics.DrawRectangle(&pen, (Gdiplus::REAL)dX, (Gdiplus::REAL)dY, (Gdiplus::REAL)dWidth, (Gdiplus::REAL)dHeight); } }
void LinearGauge::saveSettings( QSettings& pSettings ) { // Range pSettings.setValue("orientation", orientation()); pSettings.setValue("scalePosition", scalePosition()); pSettings.setValue("minValue", minValue()); pSettings.setValue("maxValue", maxValue()); // Ticks pSettings.setValue("scaleMaxMajor", scaleMaxMajor()); pSettings.setValue("scaleMaxMinor", scaleMaxMinor()); pSettings.setValue("labels", scaleDraw()->hasComponent( QwtAbstractScaleDraw::Labels )); pSettings.setValue("font", font().family()); pSettings.setValue("fontSize", font().pointSize()); // Pipe pSettings.setValue("value", value()); pSettings.setValue("pipeWidth", pipeWidth()); pSettings.setValue("pipeColor", fillBrush().color().rgb()); // Alarm pSettings.setValue("alarmEnabled", alarmEnabled()); pSettings.setValue("alarmLevel", alarmLevel()); pSettings.setValue("alarmBrush", alarmBrush().color().rgb()); // Color pSettings.setValue("textColor", textColor().rgb()); pSettings.setValue("backgroundColor", backgroundColor().rgb()); AbstractGauge::saveSettings( pSettings ); }