QRectF Zone::boundingRect() const { // Assuming that (0,0) is the center of the object QRectF rectF(-width/2, -height/2, width, height); return rectF; }
void KPaintShape::paintEllipse(QPainter &painter, const QPointF &startPoint, const QPointF &endPoint, float rotateAngle, bool bScale) { QPointF central = calShapeCentralPoint(startPoint,endPoint); setShapePainter(painter, central, rotateAngle, bScale); QRectF rectF(startPoint, endPoint); painter.drawEllipse(rectF); }
void RenderContext::DrawStringRectWithFlags(const wchar_t* text, size_t len, const Font& font, Color color, const Rect& rect, int flags) { Gdiplus::Graphics graphics(dc_); Gdiplus::SolidBrush brush(Gdiplus::Color((unsigned int)color)); Gdiplus::Font gdi_font(dc_, font.ToHFONT()); Gdiplus::StringFormat format; Gdiplus::RectF rectF(rect.x(), rect.y(), rect.width(), rect.height()); GetStringFormat(format, flags); graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); graphics.DrawString(text, len, &gdi_font, rectF, &format, &brush); }
//获取grid的str的作画rect QRectF CDigitalStatusPrinter::CenterInGrid(int left,int right,int y,QString str) { QFontMetrics metics(m_font); int nDescWidth = metics.width(str); int nHeight = metics.height(); int nStart = (left+right)/2; nStart = nStart - nDescWidth/2; int nWidth = right-nStart; QRectF rectF(nStart,y,nWidth,nHeight); return rectF; }
//______________________________________ void ShadowDemoWidget::updateBackgroundPixmap( void ) { // check if background pixmap needs update QRect backgroundRect( QPoint( 0, 0 ), size() - QSize( 2*_shadowSize, 2*_shadowSize ) ); if( !_backgroundPixmap.isNull() && _backgroundPixmap.size() == backgroundRect.size() ) { return; } _backgroundPixmap = QPixmap( backgroundRect.size() ); _backgroundPixmap.fill( Qt::transparent ); QPainter painter( &_backgroundPixmap ); painter.setRenderHint( QPainter::Antialiasing ); _dummy.resize( backgroundRect.size() ); helper().renderWindowBackground( &painter, backgroundRect, &_dummy, &_dummy, palette().color( QPalette::Window ), 0, 64 ); // float frame helper().drawFloatFrame( &painter, backgroundRect.adjusted( -1, -1, 1, 1 ), palette().color( QPalette::Window ), false ); // add rounded mask painter.save(); painter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); painter.setBrush( Qt::black ); painter.setPen( Qt::NoPen ); if( _square ) { QRectF rectF( backgroundRect ); QPainterPath path; // rotate counterclockwise, cause that makes angles easier path.moveTo( rectF.topLeft() + QPointF( 3.5, 0 ) ); path.arcTo( QRectF( rectF.topLeft(), QSize( 7, 7 ) ), 90, 90 ); path.lineTo( rectF.bottomLeft() ); path.lineTo( rectF.bottomRight() ); path.lineTo( rectF.topRight() + QPointF( 0, 3.5 ) ); path.arcTo( QRectF( rectF.topRight() + QPointF( -7, 0 ), QSize( 7, 7 ) ), 0, 90 ); path.lineTo( rectF.topLeft() + QPointF( 3.5, 0 ) ); painter.drawPath( path ); } else { painter.drawRoundedRect( QRectF( backgroundRect ), 3.5, 3.5 ); } painter.restore(); }
void RenderContext::CalcStringSizeWithFlags(const wchar_t* text, size_t text_len, const Font& font, const Size& sz, int flags, Size& out, size_t* len /*= NULL*/, int* lines /*= NULL*/) { HDC hdc = GetDC(NULL); Gdiplus::Graphics graphics(hdc); Gdiplus::Font gdi_font(hdc, font.ToHFONT()); Gdiplus::StringFormat format; Gdiplus::RectF rectF(0, 0, sz.width(), sz.height()); Gdiplus::RectF outF; GetStringFormat(format, flags); graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); graphics.MeasureString(text, text_len, &gdi_font, rectF, &format, &outF, (int*)len, lines); out.SetSize(outF.Width, outF.Height); ::ReleaseDC(NULL, hdc); }
void RenderContext::CalcStringRectWithFlags(const std::wstring& text, const Font& font, const Rect& rect, int flags, Rect& out, size_t* len, int* lines) { HDC hdc = GetDC(NULL); Gdiplus::Graphics graphics(hdc); Gdiplus::Font gdi_font(hdc, font.ToHFONT()); Gdiplus::StringFormat format; Gdiplus::RectF rectF(rect.x(), rect.y(), rect.width(), rect.height()); Gdiplus::RectF outF; GetStringFormat(format, flags); graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); graphics.MeasureString(text.c_str(), text.size(), &gdi_font, rectF, &format, &outF, (int*)len, lines); out.SetRect(outF.X, outF.Y, outF.Width, outF.Height); ::ReleaseDC(NULL, hdc); }
void KDoor::drawCurImageEffect(QPainter &painter,const QImage &curImage, const float& frame) { float switchAreaWidth = curImage.width(); float switchAreaHeight = curImage.height(); float offsetWide = (switchAreaWidth * 0.6) / 2; float offsetHeight = (switchAreaHeight * 0.6) / 2; //计算当前image增长的大小 float m_fIncreasedWidth = offsetWide * frame; float m_fIncreasedHeight = offsetHeight * frame; QImage image = curImage.scaled(switchAreaWidth * 0.4 + m_fIncreasedWidth * 2, switchAreaHeight * 0.4 + m_fIncreasedHeight * 2); QPointF widgetCenter = curImage.rect().center(); painter.save(); QRectF rectF(widgetCenter.x() - image.width() / 2, widgetCenter.y() - image.height() / 2, image.width(), image.height()); painter.drawImage(rectF,image); painter.restore(); }
void LineGraphWidget::paintEvent(QPaintEvent *) { qDebug() << "akb"; int i; int a,b,c,d; Counter = 0; QPixmap pix(widgetX,widgetY); QPainter painter(&pix); pix.fill(Qt::white); QPen pen; pen.setBrush(Qt::black); pen.setStyle(Qt::DotLine); painter.setPen(pen); QPen pen1; pen1.setBrush(Qt::black); painter.setRenderHint(QPainter::Antialiasing); for(i = 0;i < sumUnitX+1; ++i) { a = basePoint.x + i*singleUnitX; b = basePoint.y; c = a; d = yAxisEndPoint.y; painter.drawLine(a,b,c,d); } for(i = 0; i < sumUnitY+1; ++i) { a = basePoint.x; b = basePoint.y - singleUnitY*i; c = xAxisEndPoint.x; d = b; painter.drawLine(a,b,c,d); } painter.setPen(pen1); for (i = 0;i <sumUnitY+1; i++) { QRectF rectF(5,basePoint.y - singleUnitY*i-10,singleUnitX+5,singleUnitY);//长宽与位数的关系 2015/06/05 double temp = (sumUnitY > 0) ? ((static_cast<double>(rangeMax-rangeMin))/static_cast<double>(sumUnitY))*static_cast<double>(i) : 0; painter.drawText(rectF,Qt::AlignLeft,QString::number(static_cast<int>(temp))); } for (i = 0;i < sumUnitX+1;++i) { QRectF rectF(singleUnitX*i+35,basePoint.y+10,singleUnitX,singleUnitY); painter.drawText(rectF,Qt::AlignLeft,QString::number((i+this->second)%60)); } for(int i = 0; i<yList.size()-1;i++) { painter.drawLine(basePoint.x+i*singleUnitX, yList.at(i), basePoint.x + (i + 1)*singleUnitX, yList.at(i+1) ); } if(yList.size() > sumUnitX) { yList.removeFirst(); } int temp = basePoint.y - qrand() % 150; yList.append(temp); painter.end(); painter.begin(this); painter.drawPixmap(0,0,pix); painter.end(); Counter = 0; if(this->second%60==0 && this->second > 60 ) { this->second = 1; } else { this->second +=1; } }
void CButtonCx::DrawString(CDC *drawDC, LPDRAWITEMSTRUCT lpDrawItemStruct) { // テキストを得る。 CString title; GetWindowText(title); // テキストが空の場合および GDI+ Font/Brush が設定されていない場合何もしない。 if (title.IsEmpty() || m_GpFont == NULL || m_GpBrush == NULL) { return; } // 透過モードにする。 drawDC->SetBkMode(TRANSPARENT); // テキストの描画位置 CRect rect = (CRect) (lpDrawItemStruct->rcItem); // クライアント四角形の取得 // マージン設定 rect.top += m_Margin.top; rect.left += m_Margin.left; rect.bottom -= m_Margin.bottom; rect.right -= m_Margin.right; CArray<CString, CString> arr; arr.RemoveAll(); CString resToken; int curPos = 0; resToken = title.Tokenize(L"\r\n", curPos); while (resToken != L"") { arr.Add(resToken); resToken = title.Tokenize(L"\r\n", curPos); } if (m_FontType == FT_GDI_PLUS || m_FontType == FT_AUTO) // GDI+ { Gdiplus::Graphics g(drawDC->m_hDC); const Gdiplus::PointF pointF(0.0, 0.0); Gdiplus::RectF extentF; for (int i = 0; i < arr.GetCount(); i++) { CRect r; r.top = (LONG) (((double) rect.Height()) / arr.GetCount() * i); r.bottom = (LONG) (((double) rect.Height()) / arr.GetCount() * (i + 1)); r.left = rect.left; r.right = rect.right; g.MeasureString(arr.GetAt(i), arr.GetAt(i).GetLength() + 1, m_GpFont, pointF, &extentF); // "+ 1" for workdaround REAL y; FontFamily ff; m_GpFont->GetFamily(&ff); REAL ascent = (REAL) ff.GetCellAscent(FontStyleRegular); REAL lineSpacing = (REAL) ff.GetLineSpacing(FontStyleRegular); y = r.CenterPoint().y - (extentF.Height * ascent / lineSpacing) / 2; Gdiplus::PointF pt(rect.CenterPoint().x - (extentF.Width / 2), y); Gdiplus::RectF rectF(pt.X, pt.Y, (REAL) extentF.Width, (REAL) extentF.Height); g.SetTextRenderingHint(TextRenderingHintAntiAlias); g.DrawString(arr.GetAt(i), -1, m_GpFont, rectF, m_GpStringformat, m_GpBrush); } } else // GDI { for (int i = 0; i < arr.GetCount(); i++) { CRect r; r.top = rect.top + (LONG) (((double) rect.Height()) / arr.GetCount() * i); r.bottom = rect.top + (LONG) (((double) rect.Height()) / arr.GetCount() * (i + 1)); r.left = rect.left; r.right = rect.right; CRect rectI; CSize extent; HGDIOBJ oldFont = drawDC->SelectObject(m_Font); GetTextExtentPoint32(drawDC->m_hDC, arr.GetAt(i), arr.GetAt(i).GetLength() + 1, &extent); rectI.top = r.top + (r.Height() - extent.cy) / 2; rectI.bottom = rectI.top + extent.cy; rectI.left = r.left; rectI.right = r.right; DrawText(drawDC->m_hDC, arr.GetAt(i), arr.GetAt(i).GetLength(), r, DT_CENTER | DT_VCENTER | DT_SINGLELINE); drawDC->SelectObject(oldFont); } } // いつか DirectWrite 描画に対応したいものである。。。 }