void HTGAvatarView::_UpdateCounter() { char counterString[32]; int symbolsLeft = NUMBER_OF_ALLOWED_CHARS; /*Calculate the number of characters left*/ int utf8length = 0; uchar c; for(int i=0; (c=fMessage->ByteAt(i))!='\0'; i++) { if ((c&0x80) == 0) { // UTF-8 single byte char utf8length++; } else if ((c&0xc0) != 0x80) { // first byte of UTF-8 multi byte character utf8length++; } } symbolsLeft -= utf8length; sprintf(counterString, "%i", symbolsLeft); /*Check symbolsLeft, disable/enable post button and change counter color.*/ if(symbolsLeft < 0) { fCounterView->SetHighColor(255, 0, 0); fPostButton->SetEnabled(false); } else if(symbolsLeft < 140) { fCounterView->SetHighColor(128, 128, 128); fPostButton->SetEnabled(true); if(displayAvatar) { displayAvatar = false; Invalidate(); AddChild(fPostButton); AddChild(fCounterView); ResizeTo(Bounds().Width(), 83); BPoint buttonPoint(Frame().right-55, Frame().top+1+kMargin); BPoint counterPoint(Frame().right-40, Frame().top+1+kMargin+fPostButton->Bounds().Height()); fPostButton->MoveTo(buttonPoint); fCounterView->MoveTo(counterPoint); ((HTGMainWindow *)Window())->AvatarViewResized(); BRect textRect(5,22,Bounds().right-60,65); fMessage->ResizeTo(textRect.Width(), textRect.Height()); } } else if(symbolsLeft >= 140) { fPostButton->SetEnabled(false); ResizeTo(Bounds().Width(), 52); ((HTGMainWindow *)Window())->AvatarViewResized(); BRect textRect(5,22,Bounds().right-60,45); displayAvatar = true; Invalidate(); fPostButton->RemoveSelf(); fCounterView->RemoveSelf(); fMessage->ResizeTo(textRect.Width(), textRect.Height()); } fCounterView->SetText(counterString); }
void GraphicsAngleItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(widget); qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); if (lod > lodThreshold_) { painter->save(); painter->fillRect(boundingRect(), color_); if (lod > textLodThreshold_) { painter->setPen(QPen(QColor(Qt::gray), 0)); painter->drawRect(boundingRect()); painter->setPen(QPen(QColor(Qt::black))); int precision = std::min(static_cast<int>(lod / 8.0), 5); QString text = QString::number(value_, 'g', precision); QFont font("Times"); font.setStyleStrategy(QFont::ForceOutline); painter->setFont(font); qreal scaleCoeff = 1.0 / lod; painter->scale(scaleCoeff, scaleCoeff); QRectF textRect(0, 0, width_ / scaleCoeff, height_ / scaleCoeff); painter->drawText(textRect, Qt::AlignCenter, text); } painter->restore(); } }
void BarChartWidget::drawBars(QPainter &painter) { std::vector<int> sizes(BAR_COUNT, 0); fillSizes(sizes); QRect baseRectangle = rect(); int activeWidth = (int) std::floor( baseRectangle.width() * (1 - 2 * PADDING) ); int singleBarWidth = (int) std::floor((activeWidth - (BAR_COUNT + 1) * SPACING) / BAR_COUNT); int baseLineY = (int) std::floor(baseRectangle.bottom() - PADDING_BOTTOM); int currX = (int) std::floor(baseRectangle.left() + baseRectangle.width() * PADDING); currX += SPACING; for (int i = 0; i < BAR_COUNT; i++) { QPoint pointTopLeft(currX, baseLineY - sizes.at((unsigned long) i)); QPoint pointBottomRight(currX + singleBarWidth, baseLineY - 1); QRect bar(pointTopLeft, pointBottomRight); painter.setPen(mainColor); painter.drawRect(bar); painter.fillRect(bar, barColor); QPoint textTopLeft(currX, baseLineY); QPoint textBottomRight(currX + singleBarWidth, baseRectangle.bottom()); QRect textRect(textTopLeft, textBottomRight); painter.setPen(mainColor); painter.drawText(textRect, Qt::AlignCenter, labels->at((unsigned long) i)); QPoint valueTopLeft(currX, baseLineY - sizes.at((unsigned long) i) - VALUE_LABEL_HEIGHT); QPoint valueBottomRight(currX + singleBarWidth, baseLineY); QRect valueLabelRect(valueTopLeft, valueBottomRight); QString textValue = QString::number(values->at((unsigned long) i)); painter.drawText(valueLabelRect, Qt::AlignHCenter | Qt::AlignTop, textValue); currX += singleBarWidth + SPACING; } }
//-------------------------------------------------------------------------- // 그리기 함수 //-------------------------------------------------------------------------- void GText::Draw(CDC* pDC) { CFont font; font.CreateFontIndirect(&m_sLogFont); //폰트 생성 CFont *oldFont = pDC->SelectObject(&font); //폰트 지정 COLORREF oldTextColor, oldBkColor; oldTextColor = pDC->SetTextColor(m_sLineColor); //글자 색 지정 oldBkColor = pDC->SetBkColor(m_sBgColor); //배경 색 지정 int oldBkMode; if(m_bsTransparent == TRUE) //배경 투명일 경우 oldBkMode = pDC->SetBkMode(TRANSPARENT); //투명 배경 else //투명이 아닐 경우 oldBkMode = pDC->SetBkMode(OPAQUE); //지정한 배경색의 배경 CSize textSize = pDC->GetTextExtent(m_sArrayString.GetData(), m_sArrayString.GetSize()); //텍스트가 그려질 영역의 크기를 구함 //글자 끝 위치 지정 m_sEndPoint.x = m_sStartPoint.x + textSize.cx; m_sEndPoint.y = m_sStartPoint.y + textSize.cy; CRect textRect(m_sStartPoint.x, m_sStartPoint.y, m_sEndPoint.x, m_sEndPoint.y); //텍스트가 그려질 rect pDC->DrawText(m_sArrayString.GetData(), m_sArrayString.GetSize(), &textRect, DT_LEFT | DT_SINGLELINE); //글자 쓰기 //이전 설정으로 되돌리기 pDC->SetTextColor(oldTextColor); //이전 텍스트 컬러로 되돌리기 pDC->SetBkColor(oldBkColor); //이전 백그라운드 컬러로 되돌리기 pDC->SetBkMode(oldBkMode); //이전 백그라운드 모드로 되돌리기 pDC->SelectObject(oldFont); //옛날 폰트로 되돌리기 }
void OnDraw(HDC hdc) { Gdiplus::Graphics graphics(hdc); RECT rect; GetClientRect(g_hWnd, &rect); Gdiplus::Color backgroundColor(OriginalBackgroundColor); if (!g_useOriginalColor) { backgroundColor = OtherBackgroundColor; } Gdiplus::SolidBrush backgroundBrush(backgroundColor); graphics.FillRectangle(&backgroundBrush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); const TCHAR* message = _T("Click the buttons with your eyes! Look at a button and press the space bar to click. ") _T("(Make sure the window has input focus.)"); Gdiplus::Font font(_T("Arial"), 10); Gdiplus::SolidBrush textBrush(Gdiplus::Color::Black); Gdiplus::RectF textRect((Gdiplus::REAL)10, (Gdiplus::REAL)(ButtonTop + ButtonHeight + 20), (Gdiplus::REAL)(rect.right - 20), (Gdiplus::REAL)(rect.bottom - rect.top)); Gdiplus::StringFormat textFormat; graphics.DrawString(message, (INT)_tcslen(message), &font, textRect, &textFormat, &textBrush); }
void DemoQPItem::drawRuler(float x, float y, float w, float h, float t) { float posX = x + w*0.05; double space = w*0.03 + sinf(t)*w*0.02; m_testFont.setPixelSize(w/35.0); m_painter->setFont(m_testFont); m_painter->setPen("#E0E0B0"); m_painter->setBrush(Qt::NoBrush); int i = 0; QVector<QPointF> pointPairs; while (posX < w) { pointPairs.append(QPointF(posX, y)); float height = h*0.2; float ts = w*0.05; QRectF textRect(posX-ts, y+h-ts, ts*2, ts*2); if (i%10==0) { height = h*0.5; m_painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignCenter, QString::number(i)); } else if (i%5==0) { height = h*0.3; if (space > w*0.02) m_painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignCenter, QString::number(i)); } pointPairs.append(QPointF(posX, y+height)); posX += space; i++; } QPen pen(QColor("#E0E0E0"), 1); m_painter->setPen(pen); m_painter->drawLines(pointPairs); }
void ClueListBox::OnDrawItem(wxDC & dc, const wxRect & rect, size_t n) const { wxRect numRect(rect); numRect.SetWidth(m_numWidth); wxRect textRect(rect); textRect.SetX(numRect.GetRight() + GetMargins().x); textRect.SetWidth(rect.width - GetMargins().x); // Get fonts and colors dc.SetFont(GetFont()); if (IsSelected(n)) dc.SetTextForeground(GetSelectionForeground()); else dc.SetTextForeground(GetForegroundColour()); XPuzzle::Clue clue = GetItem(n); dc.DrawLabel(wxString::Format(_T("%d."), clue.Number()), numRect, wxALIGN_RIGHT|wxALIGN_TOP); wxASSERT(! m_cachedClues.at(n).empty()); dc.DrawLabel(m_cachedClues.at(n), textRect); //dc.DrawLine(textRect.x, textRect.y, textRect.x + textRect.width, textRect.y + textRect.height); }
void nodeWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * ) { QString title( "Hello" ); QList <QString> properties; properties << "Thing" << "lalala" << "bouind" << "hahaha"; QRectF originalRect( titlebarRect( painter->font() ) ); _titlePath = QPainterPath(); _titlePath.addRect( originalRect ); QRectF titleRect( originalRect ); titleRect.setHeight( titleRect.height() + ( ROUNDRADIUS * 2 + 1 ) ); QRectF contentsRect( titleRect ); contentsRect.setY( originalRect.height() ); contentsRect.setHeight( originalRect.height() + NODEPROPERTYHEIGHT*( properties.size() - 1 ) - 2*ROUNDRADIUS - 4 ); QPainterPath titleBar( makeRoundedPath( titleRect ) ); QPainterPath contents( makeRoundedPath( contentsRect ) ); QPen outlinePen( Qt::black, 3 ); if( isSelected() ) { outlinePen.setColor( SELECTED_COLOUR ); } QPainterPath globalLine( makeRoundedPath( titleRect.unite( contentsRect ) ) ); painter->setPen( outlinePen ); painter->drawPath( globalLine ); painter->fillPath( titleBar, titleGradient( titleRect ) ); painter->fillPath( contents, contentsBrush( contentsRect ) ); QColor separatingLineColor( Qt::black ); if( isSelected() ) { separatingLineColor = SELECTED_COLOUR; } separatingLineColor.setAlpha( 128 ); QPen separatingLinePen( separatingLineColor ); QPen whitePen( Qt::white ); painter->setPen( whitePen ); painter->drawText( originalRect, Qt::AlignCenter, title ); QRectF textRect( titleRect ); textRect.moveTop( textRect.top() + originalRect.height() - 2*ROUNDRADIUS - 2 ); FOREACH( properties, prop ) { painter->setPen( whitePen ); painter->drawText( textRect, Qt::AlignCenter, *prop ); if( &(*prop) != &(properties.back()) ) { painter->setPen( separatingLinePen ); painter->drawLine( titleRect.x(), textRect.y()+NODEPROPERTYHEIGHT+4, titleRect.x()+titleRect.width(), textRect.y()+NODEPROPERTYHEIGHT+4 ); } textRect.moveTop( textRect.top() + NODEPROPERTYHEIGHT ); }
reg_t kBitmapDrawText(EngineState *s, int argc, reg_t *argv) { // called e.g. from TextButton::createBitmap() in Torin's Passage, script 64894 SciBitmap &bitmap = *s->_segMan->lookupBitmap(argv[0]); Common::String text = s->_segMan->getString(argv[1]); Common::Rect textRect( argv[2].toSint16(), argv[3].toSint16(), argv[4].toSint16() + 1, argv[5].toSint16() + 1 ); int16 foreColor = argv[6].toSint16(); int16 backColor = argv[7].toSint16(); int16 skipColor = argv[8].toSint16(); GuiResourceId fontId = (GuiResourceId)argv[9].toUint16(); TextAlign alignment = (TextAlign)argv[10].toSint16(); int16 borderColor = argv[11].toSint16(); bool dimmed = argv[12].toUint16(); // NOTE: Technically the engine checks these things: // textRect.bottom > 0 // textRect.right > 0 // textRect.left < bitmap.width // textRect.top < bitmap.height // Then clips. But this seems stupid. textRect.clip(Common::Rect(bitmap.getWidth(), bitmap.getHeight())); reg_t textBitmapObject = g_sci->_gfxText32->createFontBitmap(textRect.width(), textRect.height(), Common::Rect(textRect.width(), textRect.height()), text, foreColor, backColor, skipColor, fontId, alignment, borderColor, dimmed, false, false); CelObjMem textCel(textBitmapObject); textCel.draw(bitmap.getBuffer(), textRect, Common::Point(textRect.left, textRect.top), false); s->_segMan->freeBitmap(textBitmapObject); return s->r_acc; }
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { if (option->state & QStyle::State_Sunken) { painter->setBrush(QColor(255, 105, 156, 255)); } else { painter->setBrush(QColor(0, 173, 250, 255)); } painter->setPen(Qt::NoPen); painter->drawEllipse(-20, -20, 40, 40); if(!nameNode.isEmpty()) { QRectF textRect(-20, -20, 40, 40); QFont font = painter->font(); font.setBold(false); font.setPointSize(14); painter->setFont(font); painter->setPen(Qt::white); bool ok; double number = nameNode.toDouble(&ok); if(!ok) painter->drawText(textRect, Qt::AlignCenter,GraphWidget::tr(nameNode.toLatin1())); else { // is a number painter->drawText(textRect, Qt::AlignCenter,GraphWidget::tr(QString::number(number,'g',2).toLatin1())); } } }
//! Redraw the text and focus indicator void QwtTextLabel::drawContents(QPainter *painter) { const QRect r = textRect(); if ( r.isEmpty() ) return; painter->setFont(font()); #if QT_VERSION < 0x040000 painter->setPen(palette().color(QPalette::Active, QColorGroup::Text)); #else painter->setPen(palette().color(QPalette::Active, QPalette::Text)); #endif drawText(painter, r); if ( hasFocus() ) { const int margin = 2; QRect focusRect = contentsRect(); focusRect.setRect(focusRect.x() + margin, focusRect.y() + margin, focusRect.width() - 2 * margin - 2, focusRect.height() - 2 * margin - 2); QwtPainter::drawFocusRect(painter, this, focusRect); } }
void OnDraw(HDC hdc) { Gdiplus::Graphics graphics(hdc); RECT rect; GetClientRect(g_hWnd, &rect); Gdiplus::Color backgroundColor(OriginalBackgroundColor); if (!g_useOriginalColor) { backgroundColor = OtherBackgroundColor; } Gdiplus::SolidBrush backgroundBrush(backgroundColor); graphics.FillRectangle(&backgroundBrush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); const TCHAR* message = _T("Click the buttons with your eyes! Look at a button and use the Direct Click key -- ") _T("typically the Applications key, the one next to the right Ctrl key, with a picture of a menu on it."); Gdiplus::Font font(_T("Arial"), 10); Gdiplus::SolidBrush textBrush(Gdiplus::Color::Black); Gdiplus::RectF textRect((Gdiplus::REAL)10, (Gdiplus::REAL)(ButtonTop + ButtonHeight + 20), (Gdiplus::REAL)(rect.right - 20), (Gdiplus::REAL)(rect.bottom - rect.top)); Gdiplus::StringFormat textFormat; graphics.DrawString(message, _tcslen(message), &font, textRect, &textFormat, &textBrush); }
void XProcessTablePrivate::drawText(QPainter *painter, qreal initX, qreal initY, XProcessItem *item) { qreal textX = initX; if(item->hasChild()) { textX += 2 * XPT::Constant::ExtraSpace + XPT::Constant::ExpandBoxSize.width(); } if(!item->icon().isNull()) { textX += XPT::Constant::IconSize.width() + XPT::Constant::ExtraSpace * 2; } qreal availableTextWidth = width(); if(_allColumnWidth.size() > 0) { availableTextWidth = _allColumnWidth.size() > 0 ? (_allColumnWidth.at(0) - textX) : _allColumnWidth.at(0); } QRectF textRect(QPointF(textX,initY),QPointF(textX + availableTextWidth,initY + XPT::Constant::RowHeight)); painter->setPen(XPT::Color::TextColor); QFont textFont; textFont.setBold(true); painter->setFont(textFont); QString strDecentName = getDottedString(item->name(),availableTextWidth); painter->drawText(textRect,strDecentName,Qt::AlignLeft|Qt::AlignVCenter); }
void QOpenGLTextureBlitWindow::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); m_image = QImage(size() * devicePixelRatio(), QImage::Format_ARGB32_Premultiplied); m_image.fill(Qt::gray); QPainter p(&m_image); QPen pen(Qt::red); pen.setWidth(5); p.setPen(pen); QFont font = p.font(); font.setPixelSize(qMin(m_image.height(), m_image.width()) / 20); p.setFont(font); int dx = dWidth() / 5; int dy = dHeight() / 5; for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { QRect textRect(x * dx, y*dy, dx,dy); QString text = QString("[%1,%2]").arg(x).arg(y); p.drawText(textRect,text); } } p.drawRect(QRectF(2.5,2.5,dWidth() - 5, dHeight() - 5)); m_image_mirrord = m_image.mirrored(false,true); }
bool MarbleSplashLayer::render( GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer ) { Q_UNUSED( renderPos ); Q_UNUSED( layer ); painter->save(); QPixmap logoPixmap( MarbleDirs::path( "svg/marble-logo-inverted-72dpi.png" ) ); if ( logoPixmap.width() > viewport->width() * 0.7 || logoPixmap.height() > viewport->height() * 0.7 ) { logoPixmap = logoPixmap.scaled( QSize( viewport->width(), viewport->height() ) * 0.7, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } QPoint logoPosition( ( viewport->width() - logoPixmap.width() ) / 2, ( viewport->height() - logoPixmap.height() ) / 2 ); painter->drawPixmap( logoPosition, logoPixmap ); QString message; // "Please assign a map theme!"; painter->setPen( Qt::white ); int yTop = logoPosition.y() + logoPixmap.height() + 10; QRect textRect( 0, yTop, viewport->width(), viewport->height() - yTop ); painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignTop, message ); painter->restore(); return true; }
void PicItem::drawShape( QPainter & p ) { int _x = int(x()); int _y = int(y()); p.setBrush( QColor( 0xef, 0xff, 0xef ) ); p.setFont( font() ); p.drawRoundRect( _x, _y, width(), height(), 2000/width(), 2000/height() ); p.drawText( _x+TopPadding-2, _y, width()-TopPadding+2, TopPadding, Qt::AlignVCenter, i18n("PIC Settings") ); if ( !m_bExpanded ) return; // Draw rectangle to cut off pins p.setBrush( QColor( 239, 255, 255 ) ); QRect r( _x+SidePadding, _y+TopPadding, InnerWidth, m_innerHeight ); p.drawRect(r); // Draw dimple thingy at end of pic p.drawArc( r.x()+(r.width()-ArcWidth)/2, r.y()+1-ArcWidth/2, ArcWidth, ArcWidth, 180*16, 180*16 ); // Draw vertical text centered in PIC p.translate( r.width()/2 + r.x(), r.height()/2 + r.y() ); p.rotate(90); QRect textRect( r.width()/-2, r.height()/-2, r.width(), r.height() ); p.drawText( textRect, Qt::AlignCenter, microSettings->microInfo()->id() ); p.rotate(-90); p.translate( r.width()/-2 - r.x(), r.height()/-2 - r.y() ); }
void Scene::renderPass(unsigned int passId) { assert( passId>=0 && passId<getNumPasses() ); switch( passId ) { case 0: if( _panorama ) _panorama->render(); break; case 1: _stage->setPostRenderCallback( postRenderCallback, this ); _stage->render(); _stage->setPostRenderCallback( NULL, NULL ); if( _timeSpeedMultiplier > 1 ) { std::wstring text = wstrformat( Gameplay::iLanguage->getUnicodeString(376), int( _timeSpeedMultiplier ) ); Vector3f screenSize = Gameplay::iEngine->getScreenSize(); gui::Rect textRect( 0, 0, int( screenSize[0] ) ,32 ); Gameplay::iGui->renderUnicodeText( textRect, "instruction", Vector4f( 0,0,0,0.75f ), gui::atCenter, gui::atCenter, true, text.c_str() ); textRect.left -= 1, textRect.right -= 1, textRect.top -= 1, textRect.bottom -= 1; Gameplay::iGui->renderUnicodeText( textRect, "instruction", Vector4f( 1,1,0.25,1 ), gui::atCenter, gui::atCenter, true, text.c_str() ); } break; } }
/** * Event: OnPaint * * Render the Notification Window */ LRESULT NotificationWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { PAINTSTRUCT ps; BeginPaint(&ps); { MyGdiplusHelper gdi_plus_autostart; { // get draw area RECT clientRect; ::GetClientRect(m_hWnd, &clientRect); // create Gdiplus Graphics object Gdiplus::Graphics graphics(m_hWnd, FALSE); graphics.SetClip(Gdiplus::Rect(clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top)); // draw a background Gdiplus::SolidBrush backgroundBrush(Gdiplus::Color(DEFAULT_ALPHA, 255, 255, 255)); graphics.FillRectangle(&backgroundBrush, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); // shrink draw area int inset = 4; clientRect.left += inset; clientRect.top += inset; clientRect.right -= inset; clientRect.bottom -= inset; // whack a logo TODO //Bitmap* bitmap = new Bitmap(m_icon.c_str(), FALSE); int bitmapWidth = 0;//bitmap->GetWidth(); int bitmapHeight = 15;//bitmap->GetHeight(); //graphics->DrawImage(bitmap, clientRect.left, clientRect.top, //bitmapWidth, bitmapHeight); // draw a separator Gdiplus::Pen blackPen(Gdiplus::Color(0, 0, 0), 1.0f); graphics.DrawLine(&blackPen, clientRect.left, clientRect.top + bitmapHeight + inset, clientRect.right, clientRect.top + bitmapHeight + inset); // setup text properties Gdiplus::Font titleFont(L"Verdana", 10, Gdiplus::FontStyleBold); Gdiplus::Font textFont(L"Verdana", 10, Gdiplus::FontStyleRegular); Gdiplus::RectF titleRect((float)clientRect.left + inset + bitmapWidth, (float)clientRect.top, (float)clientRect.right, 20.0f); Gdiplus::RectF textRect((float)clientRect.left, (float)clientRect.top + bitmapHeight + (inset * 2), (float)clientRect.right, (float)clientRect.bottom - bitmapHeight - (inset * 2)); Gdiplus::StringFormat format; format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter); format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit); Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0)); // draw the message graphics.DrawString(m_title.c_str(), (int)m_title.length(), &titleFont, titleRect, &format, &blackBrush); graphics.DrawString(m_message.c_str(), (int)m_message.length(), &textFont, textRect, &format, &blackBrush); } } EndPaint(&ps); bHandled = TRUE; return 0; }
void Shapes::Circle::Draw(CDC *pDC) { CPen tp2, tp3; Shapes::Shape::Draw(pDC); if (points.empty()) return; CBrush b(this->fill); pDC->SelectObject(&b); if (this->isSelected) { // pak speciale selectie pen tp2.CreatePenIndirect(&this->selectionPen); pDC->SelectObject(&tp2); } else { // neem de normale pen tp3.CreatePenIndirect(&this->pen); pDC->SelectObject(&tp3); } pDC->Ellipse(points[0].x, points[0].y, points[1].x, points[1].y); CRect textRect(points[0].x, points[0].y, points[1].x, points[1].y); pDC->DrawText(this->text.c_str(), textRect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); }
nsRect nsTextBoxFrame::CalcTextRect(nsIRenderingContext &aRenderingContext, const nsPoint &aTextOrigin) { nsRect textRect(aTextOrigin, GetSize()); nsMargin borderPadding; GetBorderAndPadding(borderPadding); textRect.Deflate(borderPadding); // determine (cropped) title and underline position nsPresContext* presContext = PresContext(); LayoutTitle(presContext, aRenderingContext, textRect); // make the rect as small as our (cropped) text. nscoord outerWidth = textRect.width; textRect.width = mTitleWidth; // Align our text within the overall rect by checking our text-align property. const nsStyleVisibility* vis = GetStyleVisibility(); const nsStyleText* textStyle = GetStyleText(); if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_CENTER) textRect.x += (outerWidth - textRect.width)/2; else if (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_RIGHT || (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_DEFAULT && vis->mDirection == NS_STYLE_DIRECTION_RTL) || (textStyle->mTextAlign == NS_STYLE_TEXT_ALIGN_END && vis->mDirection == NS_STYLE_DIRECTION_LTR)) { textRect.x += (outerWidth - textRect.width); } return textRect; }
void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) { qreal totalTextWidth = getCardTypeTextWidth(); painter->fillRect(boundingRect(), themeManager->getTableBgBrush()); painter->setPen(QColor(255, 255, 255, 100)); painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY)); painter->setPen(QColor(Qt::white)); QFont f("Serif"); f.setStyleHint(QFont::Serif); f.setPixelSize(24); f.setWeight(QFont::Bold); painter->setFont(f); painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name) + QString(": %1").arg(cards.size())); f.setPixelSize(16); painter->setFont(f); QList<QString> cardTypeList = cardsByType.uniqueKeys(); qreal yUntilNow = separatorY + paddingY; for (int i = 0; i < cardTypeList.size(); ++i) { if (i != 0) { painter->setPen(QColor(255, 255, 255, 100)); painter->drawLine(QPointF(0, yUntilNow - paddingY / 2), QPointF(width, yUntilNow - paddingY / 2)); } qreal thisRowHeight = CARD_HEIGHT * currentRowsAndCols[i].first; QRectF textRect(0, yUntilNow, totalTextWidth, thisRowHeight); yUntilNow += thisRowHeight + paddingY; QString displayString = QString("%1\n(%2)").arg(cardTypeList[i]).arg(cardsByType.count(cardTypeList[i])); painter->setPen(Qt::white); painter->drawText(textRect, Qt::AlignHCenter | Qt::AlignVCenter, displayString); } }
void nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsPoint aPt) { if (mTitle.IsEmpty()) return; nsRect textRect(CalcTextRect(aRenderingContext, aPt)); // Paint the text shadow before doing any foreground stuff const nsStyleText* textStyle = GetStyleText(); if (textStyle->mTextShadow) { // Text shadow happens with the last value being painted at the back, // ie. it is painted first. for (PRUint32 i = textStyle->mTextShadow->Length(); i > 0; --i) { PaintOneShadow(aRenderingContext.ThebesContext(), textRect, textStyle->mTextShadow->ShadowAt(i - 1), GetStyleColor()->mColor, aDirtyRect); } } DrawText(aRenderingContext, textRect, nsnull); }
void CStatusLabel::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CString str; GetWindowText(str); CRect clientRect; GetClientRect(&clientRect); CDC dc; dc.Attach(lpDrawItemStruct->hDC); dc.SetTextColor(0xffffff); dc.SetBkColor(0); CFont* old = dc.SelectObject(&m_font); const UINT style = DT_SINGLELINE | DT_NOPREFIX | (m_fAddEllipses ? DT_END_ELLIPSIS : 0); CRect textRect(clientRect); dc.DrawText(str, textRect, style | DT_CALCRECT); if (m_fRightAlign) { textRect.MoveToX(clientRect.Width() - textRect.Width()); } textRect.MoveToY((clientRect.Height() - textRect.Height()) / 2); dc.DrawText(str, textRect, style); dc.ExcludeClipRect(textRect); dc.FillSolidRect(clientRect, 0); dc.SelectObject(&old); dc.Detach(); }
void PSV_CircularIndicatorItem::drawTextRect(int zValue) { qreal rectWidth = m_coverCircleRadiusRatio * m_outerRadius / 5; QPointF topLeftPot(m_rect.center().x()-1.5*rectWidth, m_rect.center().y()+rectWidth*2); QPointF bottomRightPot(topLeftPot.x()+3*rectWidth, topLeftPot.y()+rectWidth*2); QRectF textRect(topLeftPot, bottomRightPot); qreal fontSize=textRect.height()/2; QFont font; font.setPointSizeF(fontSize); QString strValue; strValue=QString("%1").arg(m_value); // { // QGraphicsRectItem *item = new QGraphicsRectItem(this); // item->setRect(textRect); // item->setPen(QPen(Qt::NoPen)); // item->setOpacity(0.6); // item->setBrush(QColor(0, 170, 255)); // item->setZValue(zValue); // } { m_textItem = new QGraphicsSimpleTextItem(strValue, this); m_textItem->setOpacity(1); m_textItem->setFont(m_valueFont); m_textItem->setZValue(zValue); QPointF pointF = m_textItem->boundingRect().center(); // m_textItem->moveBy(textRect.center().x() - pointF.x(), textRect.center().y() - pointF.y()); m_textItem->moveBy(m_rect.center().x() - pointF.x(), m_rect.center().y() - pointF.y()); } }
void ConcreteSingerListView::paintSinger( QPainter *painter, const VSQ_NS::Event *singerEvent, int x, SingerItemState state) { static QColor singerEventBorderColor = QColor::fromRgb(182, 182, 182); int height = this->height(); QRect rc(x, 1, SINGER_ITEM_WIDTH, height - 2); switch (state) { case LEFT: { painter->fillRect(rc, Qt::lightGray); break; } default: { painter->fillRect(rc, Qt::white); break; } } painter->setPen(singerEventBorderColor); painter->drawRect(rc); painter->setPen(Qt::black); QString text(singerEvent->singerHandle.ids.c_str()); static QTextOption option(Qt::AlignLeft | Qt::AlignVCenter); QRect textRect(x + 1, 1, SINGER_ITEM_WIDTH - 1, height - 1); painter->drawText(textRect, text, option); }
void KisNodeDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { KisNodeViewColorScheme scm; const QRect rc = textRect(option, index) .adjusted(scm.textMargin(), 0, -scm.textMargin(), 0); QPen oldPen = p->pen(); const qreal oldOpacity = p->opacity(); // remember previous opacity p->setPen(option.palette.color(QPalette::Active,QPalette::Text )); if (!(option.state & QStyle::State_Enabled)) { p->setOpacity(0.55); } const QString text = index.data(Qt::DisplayRole).toString(); const QString elided = elidedText(p->fontMetrics(), rc.width(), Qt::ElideRight, text); p->drawText(rc, Qt::AlignLeft | Qt::AlignVCenter, elided); p->setPen(oldPen); // restore pen settings p->setOpacity(oldOpacity); }
void FolderDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &originalRect, const QString &text) const { static const int smoothListScrollBarWidth = 6; // Reduce the available width by the scrollbar size, if necessary QRect rect(originalRect); if (_scrollBar && _scrollBar->isVisible()) rect.setWidth(rect.width() - _parent->style()->pixelMetric(QStyle::PM_ScrollBarExtent)); else if (!_scrollBar) rect.setWidth(rect.width() - smoothListScrollBarWidth); int tw = 0; if (!_statusText.isEmpty()) { QFontMetrics fontMetrics(option.font); tw = fontMetrics.width(_statusText); } QRect textRect(rect); textRect.setWidth(rect.width() - tw); QItemDelegate::drawDisplay(painter, option, textRect, text); if (tw) { static const int margin = 5; QRect statusRect = option.direction == Qt::RightToLeft ? QRect(0, rect.top(), tw + margin, rect.height()) : QRect(rect.left()+rect.width()-tw-margin, rect.top(), tw, rect.height()); if(m_showStatus) painter->drawText(statusRect, Qt::AlignCenter, _statusText); } }
void myGauge2::drawTextRect(QPainter *painter) { painter->save(); qreal rectWidth=m_coverCircleRadius/5; QPointF topLeftPot(m_center.x()-1.5*rectWidth,m_center.y()+rectWidth*2); QPointF bottomRightPot(topLeftPot.x()+3*rectWidth,topLeftPot.y()+rectWidth*2); QRectF textRect(topLeftPot,bottomRightPot); painter->setPen(Qt::NoPen); painter->setBrush(QColor(0,170,255)); painter->setOpacity(0.6); painter->drawRoundRect(textRect,ANGLE1,ANGLE1); qreal fontSize=textRect.height()/2; QFont font; font.setPointSize(fontSize); painter->setFont(font); painter->setOpacity(1.0); painter->setPen(Qt::black); QString strValue; strValue=tr("%1").arg(m_value); painter->drawText(textRect,Qt::AlignHCenter|Qt::AlignVCenter,strValue); painter->restore(); }
void PackageTransferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyledItemDelegate::paint(painter, option, index); QImage icon(index.data(Transfer::IconRole).toString()); if (icon.isNull()) { icon = QImage(ICON_PATH + "qdl.png"); } painter->drawImage(option.rect.left() + 8, option.rect.top() + 25, icon.scaled(36, 36, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); QRect textRect(option.rect.left() + 52, option.rect.top(), option.rect.width() - 218, option.rect.height()); painter->setClipRect(textRect); painter->drawText(textRect, Qt::TextSingleLine | Qt::AlignVCenter, index.data(Transfer::NameRole).toString()); painter->setClipping(false); int progress = index.data(Transfer::ProgressRole).toInt(); QStyleOptionProgressBar progressBar; progressBar.rect = option.rect; progressBar.rect.setTop(option.rect.top() + 8); progressBar.rect.setHeight(70); progressBar.rect.setLeft(option.rect.right() - 158); progressBar.rect.setWidth(150); progressBar.minimum = 0; progressBar.maximum = 100; progressBar.progress = progress; progressBar.textVisible = true; progressBar.text = QString::number(progress) + "%"; QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBar, painter); }
void ProgressBarColor::drawBar(QPainter *painter) { painter->save(); //自动计算文字字体大小 QFont f(font()); f.setPixelSize((width() / 10) * 0.35); painter->setFont(f); //计算进度值字符的宽度 double currentValue = (double)(value - minValue) * 100 / (maxValue - minValue); QString strValue = QString("当前值:%1%").arg(currentValue, 0, 'f', precision); QString strMaxValue = QString("%1%").arg(maxValue, 0, 'f', precision); //字符的宽度取最大值字符的宽度 + 10 int textWidth = painter->fontMetrics().width(strMaxValue) + 10; //绘制进度值背景 QPointF textTopLeft(width() - space - textWidth, space); QPointF textBottomRight(width() - space, height() - space); QRectF textRect(textTopLeft, textBottomRight); painter->setPen(barBgColor); painter->setBrush(barBgColor); painter->drawRoundedRect(textRect, radius, radius); //绘制进度值 painter->setPen(textColor); painter->drawText(textRect, Qt::AlignCenter, strValue); //绘制进度条背景 QRectF barBgRect(QPointF(space, space), QPointF(width() - space * 2 - textWidth, height() - space)); painter->setPen(Qt::NoPen); painter->setBrush(barBgColor); painter->drawRoundedRect(barBgRect, radius, radius); //绘制进度条 double length = width() - space - space * 2 - textWidth; //计算每一格移动多少 double increment = length / (maxValue - minValue); QRectF barRect(QPointF(space, space), QPointF(space + increment * (value - minValue), height() - space)); painter->setBrush(barColor); painter->drawRoundedRect(barRect, radius, radius); //绘制背景分割线条 每一格长度7 painter->setPen(lineColor); int initX = 5; int lineCount = barBgRect.width() / step; double lineX = (double)barBgRect.width() / lineCount; //线条高度在进度条高度上 - 1 while (lineCount > 0) { QPointF topPot(initX + lineX, space + 1); QPointF bottomPot(initX + lineX, height() - space - 1); painter->drawLine(topPot, bottomPot); initX += lineX; lineCount--; } painter->restore(); }