void tGraph::draw(QPainter & paint) { //QPainter paint(this); paint.save(); int gx1 = hPadding() + _rect.x(); int gy1 = vPadding() + _rect.y(); int gx2 = _rect.x() + width() - hPadding(); int gy2 = _rect.y() + height() - vPadding(); //paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1); QFontMetrics fm(font()); //QRect brect; // get the dimensions of the title label and then draw it if(title().length() > 0) { fm = QFontMetrics(titleFont()); //brect = fm.boundingRect(title()); paint.setFont(titleFont()); paint.drawText(gx1, gy1, gx2 - gx1, fm.height(), titleAlignment(), title()); gy1 += fm.height(); } // we need to do some drawing that depends on some other elements having // already been placed... since those require that these have already been // placed we will just save the old value of gy2 and then calculate the // value that we should have after the other code runs without actually // drawing anything right now int gy2_old = gy2; if(dataLabel().length() > 0) { fm = QFontMetrics(dataLabelFont()); gy2 -= fm.height(); } fm = QFontMetrics(dataFont()); double tlh = 0.0; QMapIterator<int, GReference> dlit(_data); while(dlit.hasNext()) { dlit.next(); tlh = qMax(sin45deg * fm.width(dlit.value().first), tlh); } // don't change this variable as we use it later int th = (tlh == 0.0 ? 0 : (int)(tlh + (fm.height() * sin45deg)) + 2); gy2 -= th; // get the dimensions of the value label then draw it if(valueLabel().length() > 0) { fm = QFontMetrics(valueLabelFont()); //brect = fm.boundingRect(valueLabel()); paint.setFont(valueLabelFont()); paint.save(); paint.rotate(-90); paint.drawText(-gy2, gx1, gy2 - gy1, fm.height(), valueLabelAlignment(), valueLabel()); paint.restore(); gx1 += fm.height(); } fm = QFontMetrics(valueFont()); QString min_str = QString().sprintf("%-.0f",minValue()); QString org_str = ( minValue() == 0.0 ? QString::null : QString("0") ); QString max_str = QString().sprintf("%-.0f",maxValue()); int width = qMax(fm.width(min_str), fm.width(max_str)); if(org_str.length() > 0) width = qMax(width, fm.width(org_str)); gx1 += width; int gy_max = gy1; int gy_min = gy2 - 1; int gy_org = gy_min; paint.setFont(valueFont()); int tfa = Qt::AlignTop | Qt::AlignRight; paint.drawText(gx1 - fm.width(min_str), gy_min, fm.width(min_str), fm.height(), tfa, min_str); paint.drawLine(gx1 - 3, gy_min, gx1 + 2, gy_min); paint.drawText(gx1 - fm.width(max_str), gy_max, fm.width(max_str), fm.height(), tfa, max_str); paint.drawLine(gx1 - 3, gy_max, gx1 + 2, gy_max); int gheight = gy2 - gy1; double grng = maxValue() - minValue(); if(org_str.length() > 0) { double perc = (0 - minValue()) / grng; gy_org = gy2 - (int)(perc * (double)gheight); paint.drawText(gx1 - fm.width(org_str), gy_org, fm.width(org_str), fm.height(), tfa, org_str); paint.drawLine(gx1 - 3, gy_org, gx1 + 2, gy_org); } gx1 += 3; // put the old value back so all the code to come draw correctly! gy2 = gy2_old; // get the dimensions of the data label then draw it if(dataLabel().length() > 0) { fm = QFontMetrics(dataLabelFont()); //brect = fm.boundingRect(dataLabel()); paint.setFont(dataLabelFont()); gy2 -= fm.height(); paint.drawText(gx1, gy2, gx2 - gx1, fm.height(), dataLabelAlignment(), dataLabel()); } gy2 -= th; int ref_cnt = _data.count(); int gwidth = gx2 - gx1; gheight = gy2 - gy1; if(ref_cnt > 0) { paint.save(); fm = QFontMetrics(dataFont()); paint.setFont(dataFont()); int refwidth = qMax(1, gwidth / ref_cnt); int buf = (int)(refwidth / 5); int buf2 = buf * 2; int pos = gx1 + (int)((gwidth - (refwidth * ref_cnt)) / 2); int bar_height; int fmheight = fm.height(); int fmheight_div_2 = fmheight / 2; int refwidth_div_2 = refwidth / 2; int label_offset = (int)(fmheight_div_2 * cos45deg); int last_label_at = -1000; QMap<int, double> last_map; QMap<int, double> this_map; QMapIterator<int, GReference> rit(_data); while(rit.hasNext()) { rit.next(); GReference ref = rit.value(); QString label = ref.first; if(label.length() > 0 && ((pos + refwidth_div_2) - last_label_at) > ((label_offset * 2) + 1)) { last_label_at = pos + refwidth_div_2; int lx = (int)(((pos + refwidth_div_2) * cos45deg) - ((gy2 + label_offset) * sin45deg)); int ly = (int)(((pos + refwidth_div_2) * sin45deg) + ((gy2 + label_offset) * cos45deg)); int fmwidth = fm.width(label); paint.save(); paint.rotate(-45); paint.drawText(lx - fmwidth, ly - fmheight_div_2, fmwidth, fmheight, Qt::AlignRight | Qt::AlignTop, label); paint.restore(); } QMapIterator<int, double> sit(ref.second); paint.save(); if(drawBars() == true) { TSetValue tval; QMap<double, TSetValue> sort_map; sit = ref.second; while(sit.hasNext()) { sit.next(); if(sit.value() != 0.0 && _setStyle[sit.key()].bar == true) { tval.first = sit.key(); tval.second = sit.value(); sort_map[(tval.second < 0.0 ? minValue() : maxValue()) - (tval.second < 0.0 ? -tval.second : tval.second)] = tval; } } QMapIterator<double, TSetValue> it(sort_map); while(it.hasNext()) { it.next(); tval = it.value(); if(tval.second != 0.0) { if(tval.second < 0) { bar_height = (int)((tval.second / minValue()) * (gy_org - gy_min)); } else { bar_height = (int)((tval.second / maxValue()) * (gy_org - gy_max)); } paint.fillRect(pos + buf, gy_org - bar_height, refwidth - buf2, bar_height, getSetColor(tval.first)); } } } if(drawLines() == true) { this_map.clear(); sit = ref.second; while(sit.hasNext()) { sit.next(); if(_setStyle[sit.key()].line == true) { this_map[sit.key()] = sit.value(); if(last_map.contains(sit.key())) { paint.setPen(getSetColor(sit.key())); double old_val = last_map[sit.key()]; double new_val = sit.value(); int ly1; if(old_val < 0.0) ly1 = (int)((old_val / minValue()) * (gy_org - gy_min)); else ly1 = (int)((old_val / maxValue()) * (gy_org - gy_max)); ly1 = gy_org - ly1; int lx1 = pos - refwidth_div_2; int ly2; if(new_val < 0.0) ly2 = (int)((new_val / minValue()) * (gy_org - gy_min)); else ly2 = (int)((new_val / maxValue()) * (gy_org - gy_max)); ly2 = gy_org - ly2; int lx2 = pos + refwidth_div_2; paint.drawLine(lx1, ly1, lx2, ly2); } } } last_map = this_map; } if(drawPoints() == true) { sit = ref.second; while(sit.hasNext()) { sit.next(); if(_setStyle[sit.key()].point == true) { paint.setBrush(getSetColor(sit.key())); paint.setPen(QColor(0,0,0)); int ly1; if(sit.value() < 0.0) ly1 = (int)((sit.value() / minValue()) * (gy_org - gy_min)); else ly1 = (int)((sit.value() / maxValue()) * (gy_org - gy_max)); ly1 = gy_org - ly1; int lx1 = pos + refwidth_div_2; paint.drawEllipse(lx1 - 2, ly1 - 2, 5, 5); } } } paint.restore(); pos += refwidth; } paint.restore(); } paint.drawLine(gx1, gy_org, gx2 - 1, gy_org); paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1); // Now that we are done return the paint device back to the state // it was when we started to mess with it paint.restore(); }
void QmaxButton::createButton(QPainter &painter) { QRect scaledRect; scaledRect = matrix.mapRect(QRect(0,0,this->logicalSize.width(),this->logicalSize.height())); QImage bg(this->m_strImage); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); QLinearGradient brush1(0,0,0,scaledRect.height()); painter.drawImage(-2, -2, bg); if(Colors::useEightBitPalette) { painter.setPen(QColor(120,120,120)); if(this->m_nPressed) painter.setBrush(QColor(60,60,60)); else if(this->m_nHighlight) painter.setBrush(QColor(100,100,100)); else painter.setBrush(QColor(80,80,80)); } else { QLinearGradient outlinebrush(0,0,0,scaledRect.height()); QLinearGradient brush(0,0,0,scaledRect.height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255,255,255,128); QColor shadow(0,0,0,70); QColor sunken(220,220,220,30); QColor normal1(255,255,245,60); QColor normal2(255,255,235,10); QColor normal3(200,200,200,10); QColor normal4(255,255,250,255); if(m_nType && m_nType != 5 ) { normal1 = QColor(200,170,160,50); normal2 = QColor(50,10,0,50); } if(m_nPressed) { outlinebrush.setColorAt(0.0f,shadow); outlinebrush.setColorAt(1.0f,highlight); brush.setColorAt(1.0f,sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal1); if(m_nHighlight) brush.setColorAt(1.0f,normal2); painter.setPen(QPen(outlinebrush,1)); } if(this->isEnabled()==false ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal3); painter.setPen(QPen(outlinebrush,1)); } if(m_nStatus ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal4); painter.setPen(QPen(outlinebrush,1)); } painter.setBrush(brush); } if(m_nType == 1) painter.drawRect(0,0,scaledRect.width(),scaledRect.height()); else if(m_nType == 0) painter.drawRoundedRect(0,0,scaledRect.width(),scaledRect.height(),40.0,40.0,Qt::RelativeSize); else if(m_nType == 5) painter.drawEllipse(0,0,scaledRect.width(),scaledRect.height()); QFont font( "DejaVu Sans" ); font.setPointSize( 12 ); painter.setFont( font ); brush1.setColorAt(1.0f,QColor(255,255,255,255)); if(this->isEnabled()==false) { brush1.setColorAt(1.0f,QColor(200,200,200,100)); } painter.setPen(QPen(brush1,1)); painter.setBrush(brush1); QFontMetrics fMetrics = painter.fontMetrics(); QSize sz = fMetrics.size( Qt::TextWordWrap, m_strText ); QRectF txtRect( scaledRect.center(), sz ); int xPoint = (scaledRect.width()/2)- ((m_strText.count()/2)*10); int yPoint = scaledRect.height()/2; painter.drawText(xPoint,yPoint,m_strText); }
void QgsLayoutTable::render( QgsLayoutItemRenderContext &context, const QRectF &, const int frameIndex ) { bool emptyTable = mTableContents.length() == 0; if ( emptyTable && mEmptyTableMode == QgsLayoutTable::HideTable ) { //empty table set to hide table mode, so don't draw anything return; } if ( !mLayout->renderContext().isPreviewRender() ) { //exporting composition, so force an attribute refresh //we do this in case vector layer has changed via an external source (e.g., another database user) refreshAttributes(); } //calculate which rows to show in this frame QPair< int, int > rowsToShow = rowRange( frameIndex ); double gridSizeX = mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0; double gridSizeY = mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0; double cellHeaderHeight = QgsLayoutUtils::fontAscentMM( mHeaderFont ) + 2 * mCellMargin; double cellBodyHeight = QgsLayoutUtils::fontAscentMM( mContentFont ) + 2 * mCellMargin; QRectF cell; //calculate whether a header is required bool drawHeader = ( ( mHeaderMode == QgsLayoutTable::FirstFrame && frameIndex < 1 ) || ( mHeaderMode == QgsLayoutTable::AllFrames ) ); //calculate whether drawing table contents is required bool drawContents = !( emptyTable && mEmptyTableMode == QgsLayoutTable::ShowMessage ); int numberRowsToDraw = rowsToShow.second - rowsToShow.first; int numberEmptyRows = 0; if ( drawContents && mShowEmptyRows ) { numberRowsToDraw = rowsVisible( frameIndex, rowsToShow.first, true ); numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first; } bool mergeCells = false; if ( emptyTable && mEmptyTableMode == QgsLayoutTable::ShowMessage ) { //draw a merged row for the empty table message numberRowsToDraw++; rowsToShow.second++; mergeCells = true; } QPainter *p = context.renderContext().painter(); p->save(); // painter is scaled to dots, so scale back to layout units p->scale( context.renderContext().scaleFactor(), context.renderContext().scaleFactor() ); //draw the text p->setPen( Qt::SolidLine ); double currentX = gridSizeX; double currentY = gridSizeY; if ( drawHeader ) { //draw the headers int col = 0; for ( const QgsLayoutTableColumn *column : qgis::as_const( mColumns ) ) { //draw background p->save(); p->setPen( Qt::NoPen ); p->setBrush( backgroundColor( -1, col ) ); p->drawRect( QRectF( currentX, currentY, mMaxColumnWidthMap[col] + 2 * mCellMargin, cellHeaderHeight ) ); p->restore(); currentX += mCellMargin; Qt::TextFlag textFlag = static_cast< Qt::TextFlag >( 0 ); if ( column->width() <= 0 ) { //automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text //which may slightly exceed the calculated width //if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width textFlag = Qt::TextDontClip; } cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellHeaderHeight ); //calculate alignment of header Qt::AlignmentFlag headerAlign = Qt::AlignLeft; switch ( mHeaderHAlignment ) { case FollowColumn: headerAlign = column->hAlignment(); break; case HeaderLeft: headerAlign = Qt::AlignLeft; break; case HeaderCenter: headerAlign = Qt::AlignHCenter; break; case HeaderRight: headerAlign = Qt::AlignRight; break; } QgsLayoutUtils::drawText( p, cell, column->heading(), mHeaderFont, mHeaderFontColor, headerAlign, Qt::AlignVCenter, textFlag ); currentX += mMaxColumnWidthMap[ col ]; currentX += mCellMargin; currentX += gridSizeX; col++; } currentY += cellHeaderHeight; currentY += gridSizeY; } //now draw the body cells int rowsDrawn = 0; if ( drawContents ) { //draw the attribute values for ( int row = rowsToShow.first; row < rowsToShow.second; ++row ) { rowsDrawn++; currentX = gridSizeX; int col = 0; //calculate row height double rowHeight = mMaxRowHeightMap[row + 1] + 2 * mCellMargin; for ( const QgsLayoutTableColumn *column : qgis::as_const( mColumns ) ) { //draw background p->save(); p->setPen( Qt::NoPen ); p->setBrush( backgroundColor( row, col ) ); p->drawRect( QRectF( currentX, currentY, mMaxColumnWidthMap[col] + 2 * mCellMargin, rowHeight ) ); p->restore(); // currentY = gridSize; currentX += mCellMargin; QVariant cellContents = mTableContents.at( row ).at( col ); QString str = cellContents.toString(); Qt::TextFlag textFlag = static_cast< Qt::TextFlag >( 0 ); if ( column->width() <= 0 && mWrapBehavior == TruncateText ) { //automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text //which may slightly exceed the calculated width //if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width textFlag = Qt::TextDontClip; } else if ( textRequiresWrapping( str, column->width(), mContentFont ) ) { str = wrappedText( str, column->width(), mContentFont ); } cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], rowHeight ); QgsLayoutUtils::drawText( p, cell, str, mContentFont, mContentFontColor, column->hAlignment(), column->vAlignment(), textFlag ); currentX += mMaxColumnWidthMap[ col ]; currentX += mCellMargin; currentX += gridSizeX; col++; } currentY += rowHeight; currentY += gridSizeY; } } if ( numberRowsToDraw > rowsDrawn ) { p->save(); p->setPen( Qt::NoPen ); //draw background of empty rows for ( int row = rowsDrawn; row < numberRowsToDraw; ++row ) { currentX = gridSizeX; int col = 0; if ( mergeCells ) { p->setBrush( backgroundColor( row + 10000, 0 ) ); p->drawRect( QRectF( gridSizeX, currentY, mTableSize.width() - 2 * gridSizeX, cellBodyHeight ) ); } else { for ( QgsLayoutTableColumn *column : qgis::as_const( mColumns ) ) { Q_UNUSED( column ); //draw background //we use a bit of a hack here - since we don't want these extra blank rows to match the firstrow/lastrow rule, add 10000 to row number p->setBrush( backgroundColor( row + 10000, col ) ); p->drawRect( QRectF( currentX, currentY, mMaxColumnWidthMap[col] + 2 * mCellMargin, cellBodyHeight ) ); // currentY = gridSize; currentX += mMaxColumnWidthMap[ col ] + 2 * mCellMargin; currentX += gridSizeX; col++; } } currentY += cellBodyHeight + gridSizeY; } p->restore(); } //and the borders if ( mShowGrid ) { QPen gridPen; gridPen.setWidthF( mGridStrokeWidth ); gridPen.setColor( mGridColor ); gridPen.setJoinStyle( Qt::MiterJoin ); p->setPen( gridPen ); if ( mHorizontalGrid ) { drawHorizontalGridLines( p, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader ); } if ( mVerticalGrid ) { drawVerticalGridLines( p, mMaxColumnWidthMap, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader, mergeCells ); } } //special case - no records and table is set to ShowMessage mode if ( emptyTable && mEmptyTableMode == QgsLayoutTable::ShowMessage ) { double messageX = gridSizeX + mCellMargin; double messageY = gridSizeY + ( drawHeader ? cellHeaderHeight + gridSizeY : 0 ); cell = QRectF( messageX, messageY, mTableSize.width() - messageX, cellBodyHeight ); QgsLayoutUtils::drawText( p, cell, mEmptyTableMessage, mContentFont, mContentFontColor, Qt::AlignHCenter, Qt::AlignVCenter, static_cast< Qt::TextFlag >( 0 ) ); } p->restore(); }
void Brick::show(QPainter &painter) { painter.drawRect(x(), y(), width(), height()); }
void paint(QPaintDevice* pd) { QPainter p; if (!p.begin(pd)) return; QPen pe(QColor("black")); pe.setWidthF(6.0); pe.setStyle(Qt::DashLine); p.setPen(pe); p.drawLine(QPointF(0,0),QPointF(100.0,100.0)); pe.setColor("red"); pe.setStyle(Qt::DotLine); p.setPen(pe); p.drawLine(QPointF(0,0),QPointF(50.0,25.0)); pe.setColor("green"); pe.setStyle(Qt::SolidLine); p.setPen(pe); p.drawLine(QPointF(0,0),QPointF(25.0,50.0)); pe.setColor("blue"); p.setPen(pe); p.drawText(50,10, QString("Hello World!")); p.drawLine(50,10,55,15); QFont f; QImage img(QString("qfe_plotterexportercairo.png")); pe.setWidthF(0.5); p.setPen(pe); p.drawImage(QRectF(50,25,50,50), img); //p.drawRect(QRectF(50,25,50,50)); p.drawImage(QRectF(25,50,15,10), img); //p.drawRect(QRectF(25,50,15,10)); p.drawImage(QRectF(225,50,100,100), img, QRect(5,5,12,12)); p.drawRect(QRectF(125,50,15,10)); pe.setWidthF(2); pe.setColor("red"); p.setPen(pe); f.setFamily("Times New Roman"); f.setPointSizeF(10); p.setFont(f); p.drawText(50,30, QString("Hello World!")); p.drawLine(50,30,55,35); f.setFamily("Arial"); f.setPointSizeF(16); p.setFont(f); p.drawText(250,30, QString("Unicode-test: ")+QChar(0x2190)+QChar(0x2591)+QChar(0x2665)+QChar(0x039B)+QChar(0x03B6)); p.drawLine(250,30,255,35); pe.setWidthF(1); p.setPen(pe); QBrush b(QColor("salmon")); p.fillRect(QRectF(100,10,50,50), b); p.drawRect(QRectF(100,10,50,50)); QColor c=b.color(); c.setAlphaF(0.5); b.setColor(c); pe.setWidthF(5); p.setPen(pe); p.setBrush(b); p.drawEllipse(QRectF(130,40,50,30)); //p.drawRect(QRectF(130,40,50,30)); QPolygonF poly; for (int phi=0; phi<60; phi++) { double p=double(phi)/20.0*M_PI; poly<<QPointF(50.0+cos(p)*35.0*double(phi)/60.0, 50.0-sin(p)*35.0*double(phi)/60.0); } p.setClipRect(0,0,200,50); pe.setWidthF(1); p.setPen(pe); p.drawPolygon(poly); pe.setColor("red"); pe.setStyle(Qt::DashDotDotLine); p.setPen(pe); p.setClipping(false); p.drawPolyline(poly); p.end(); }
void MapIcon::paintSquare(QPainter&p, const QPoint& point, int size, int sizeWH) { p.drawRect(point.x() - size, point.y() - size, sizeWH, sizeWH); }
void CannonField::paintShot(QPainter &painter) { painter.setPen(Qt::NoPen); painter.setBrush(Qt::black); painter.drawRect(shotRect()); }
void SpaceElement::paint( QPainter& painter, AttributeManager* ) { painter.setBrush( QBrush( Qt::lightGray, Qt::DiagCrossPattern ) ); painter.drawRect( QRectF( 0.0, 0.0, width(), height() ) ); }
void QgsColorSwatchGrid::draw( QPainter &painter ) { QPalette pal = QPalette( qApp->palette() ); QColor headerBgColor = pal.color( QPalette::Mid ); QColor headerTextColor = pal.color( QPalette::BrightText ); QColor highlight = pal.color( QPalette::Highlight ); //draw header background painter.setBrush( headerBgColor ); painter.setPen( Qt::NoPen ); painter.drawRect( QRect( 0, 0, width(), LABEL_SIZE ) ); //draw header text painter.setPen( headerTextColor ); painter.drawText( QRect( LABEL_MARGIN, 0, width() - 2 * LABEL_MARGIN, LABEL_SIZE ), Qt::AlignLeft | Qt::AlignVCenter, mScheme->schemeName() ); //draw color swatches QgsNamedColorList::iterator colorIt = mColors.begin(); int index = 0; for ( ; colorIt != mColors.end(); ++colorIt ) { int row = index / NUMBER_COLORS_PER_ROW; int column = index % NUMBER_COLORS_PER_ROW; QRect swatchRect = QRect( column * ( SWATCH_SIZE + SWATCH_SPACING ) + LEFT_MARGIN, row * ( SWATCH_SIZE + SWATCH_SPACING ) + TOP_MARGIN + LABEL_SIZE, SWATCH_SIZE, SWATCH_SIZE ); if ( mCurrentHoverBox == index ) { //hovered boxes are slightly larger swatchRect.adjust( -1, -1, 1, 1 ); } //start with checkboard pattern for semi-transparent colors if (( *colorIt ).first.alpha() != 255 ) { QBrush checkBrush = QBrush( transparentBackground() ); painter.setPen( Qt::NoPen ); painter.setBrush( checkBrush ); painter.drawRect( swatchRect ); } if ( mCurrentHoverBox == index ) { if ( mDrawBoxDepressed ) { painter.setPen( QColor( 100, 100, 100 ) ); } else { //hover color painter.setPen( QColor( 220, 220, 220 ) ); } } else if ( mFocused && index == mCurrentFocusBox ) { painter.setPen( highlight ); } else if (( *colorIt ).first.name() == mBaseColor.name() ) { //currently active color painter.setPen( QColor( 75, 75, 75 ) ); } else { painter.setPen( QColor( 197, 197, 197 ) ); } painter.setBrush(( *colorIt ).first ); painter.drawRect( swatchRect ); index++; } }
//*************************************************************************** void Kwave::LogoWidget::paintEvent(QPaintEvent *) { // if image has to be resized ... if ((rect().height() != m_height) || (rect().width() != m_width)) { m_height = rect().height(); m_width = rect().width(); if (m_image) delete m_image; m_image = new QImage(size(), QImage::Format_ARGB32_Premultiplied); m_repaint = true; } if ((m_repaint) && (m_image)) { QPainter p; QPolygon si(20 + 3); p.begin(m_image); // erase everything to black p.setPen(Qt::black); p.setBrush(Qt::black); p.drawRect(0, 0, m_width, m_height); // blit logo bitmap int ampx = (m_logo.width() - m_width ) / 2; int ampy = (m_logo.height() - m_height) / 2; p.setCompositionMode(QPainter::CompositionMode_Source); p.drawPixmap( -ampx + Kwave::toInt(sin(m_deg[0]) * ampx), -ampy + Kwave::toInt(sin(m_deg[1]) * ampy), m_logo); // draw the sine waves with XOR p.setCompositionMode(QPainter::CompositionMode_Exclusion); p.setBrush(QColor::fromHsvF(m_color_h, 1.0, 1.0)); m_color_h += COLOR_INCREMENT; // this gives the nice color change :-) if (m_color_h > 1.0) m_color_h -= 1.0; double amp = sin(m_deg[MAXSIN - 1] * 3); for (int j = 0; j < MAXSIN; j++) { for (int i = 0; i < 21; i++) { si.setPoint(i, (j * m_width / MAXSIN) + Kwave::toInt(amp * sin(M_PI * i / 10 + m_deg[j]) * m_width / 2), m_height * i / 20); } si.setPoint(21, m_width / 2, m_height); si.setPoint(22, m_width / 2, 0); p.drawPolygon(si); amp = sin(m_deg[j] * 3); } p.end(); m_repaint = false; } // blit the result to the display if (m_image) { QPainter p(this); p.drawImage(0, 0, *m_image); p.end(); } }
void CharsetWidget::paintEvent(QPaintEvent *event) { QPainter painter; painter.begin(this); painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole())); painter.setBrush(QColor(0,0,0)); painter.setPen(Qt::NoPen); auto state = State::getInstance(); int end_x = 8; int pixel_size_x = _pixelSize.width(); int increment_x = 1; int bits_to_mask = 1; if (state->shouldBeDisplayedInMulticolor()) { end_x = 4; pixel_size_x = _pixelSize.width() * 2; increment_x = 2; bits_to_mask = 3; } QPen pen; pen.setColor({149,195,244,255}); if (hasFocus()) pen.setWidth(3); else pen.setWidth(1); pen.setStyle(Qt::PenStyle::SolidLine); for (int w=0; w<COLUMNS; w++) { for (int h=0; h<ROWS; h++) { int index = w + h * COLUMNS; quint8* charPtr = state->getCharAtIndex(index); for (int y=0; y<8; y++) { char letter = charPtr[y]; for (int x=0; x<end_x; x++) { // Warning: Don't use 'char'. Instead use 'unsigned char'. // 'char' doesn't work Ok with << and >> // only mask the bits are needed unsigned char mask = bits_to_mask << (((end_x-1)-x) * increment_x); unsigned char color = letter & mask; // now transform those bits into values from 0-3 since those are the // possible colors int bits_to_shift = (((end_x-1)-x) * increment_x); int color_pen = color >> bits_to_shift; if (!state->shouldBeDisplayedInMulticolor() && color_pen ) color_pen = State::PEN_FOREGROUND; painter.setBrush(Palette::getColorForPen(color_pen)); painter.drawRect((w*end_x+x) * pixel_size_x + OFFSET, (h*8+y) * _pixelSize.height() + OFFSET, pixel_size_x, _pixelSize.height()); } } painter.setPen(Qt::NoPen); } } if (_selecting) { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(149,195,244,64)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, _selectingSize.width() * 8 * _pixelSize.width(), _selectingSize.height() * 8 * _pixelSize.height()); } else { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(128,0,0,0)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, 8 * _pixelSize.width(), 8 * _pixelSize.height()); } paintFocus(painter); painter.end(); }
//-------------------------------------------------------------------------------------------- void MGyrohorizon::paintEvent(QPaintEvent * event) { //-- QImage imgagePaint(size(), QImage::Format_ARGB32_Premultiplied); QPainter painter; painter.begin(&imgagePaint); //-- painter.setRenderHint(QPainter::Antialiasing, true); QLinearGradient linearGrad; QPointF mpointsF[5]; qreal yh; //============================= bool isUpDawn = false; while(PitchAngle < -90.0) { PitchAngle += 180.0; isUpDawn = !isUpDawn; //true; } while(PitchAngle > 90.0) { PitchAngle -= 180.0; isUpDawn = !isUpDawn; //true; } if(isUpDawn) { RollAngle += 180.0; } while(RollAngle < -180.0) { RollAngle += 360.0; } while(RollAngle > 180.0) { RollAngle -= 360.0; } qreal hPitchAngle = HeightHalf/AngleHeightHalf*PitchAngle;//здвиг по пикселям в соответсвии с градусами if(isUpDawn) { hPitchAngle = -hPitchAngle; } painter.translate(WidthHalf,HeightHalf);//переместили цент с 0,0 на центр painter.rotate(-RollAngle); //===== Pitch: ===== painter.setPen(Qt::NoPen); //-Sky: // 0: yh = hPitchAngle; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh-H1); linearGrad.setColorAt(0, ColorSky0); linearGrad.setColorAt(1, ColorSky1); QBrush brushSky1(linearGrad); painter.setBrush(brushSky1); painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-H1-2.0);//первый верхний четерехугольник yh -= H1; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh-H2); linearGrad.setColorAt(0, ColorSky1); linearGrad.setColorAt(1, ColorSky2); QBrush brushSky2(linearGrad); painter.setBrush(brushSky2); painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,-H2-2.0)); //90 yh -= H2; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh-H2); linearGrad.setColorAt(0, ColorSky2); linearGrad.setColorAt(1, ColorSky1); QBrush brushSky3(linearGrad); painter.setBrush(brushSky3); painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,-H2-2.0)); yh -= H2; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh-H1); linearGrad.setColorAt(0, ColorSky1); linearGrad.setColorAt(1, ColorSky0); QBrush brushSky4(linearGrad); painter.setBrush(brushSky4); painter.drawRect(QRectF(-MaxDimHalf,yh+0.5, MaxDim,-H1-2.0)); //180 //-Ground: // 0: yh = hPitchAngle; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh+H1); linearGrad.setColorAt(0, ColorGround0); linearGrad.setColorAt(1, ColorGround1); QBrush brushGround1(linearGrad); painter.setBrush(brushGround1); painter.drawRect(QRectF(-MaxDimHalf,yh-0.5, MaxDim,H1+2.0)); yh += H1; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh+H2); linearGrad.setColorAt(0, ColorGround1); linearGrad.setColorAt(1, ColorGround2); QBrush brushGround2(linearGrad); painter.setBrush(brushGround2); painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,H2+2.0)); //90: yh += H2; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh+H2); linearGrad.setColorAt(0, ColorGround2); linearGrad.setColorAt(1, ColorGround1); QBrush brushGround3(linearGrad); painter.setBrush(brushGround3); painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,H2+2.0)); yh += H2; linearGrad.setStart(0.0, yh); linearGrad.setFinalStop(0.0, yh+H1); linearGrad.setColorAt(0, ColorGround1); linearGrad.setColorAt(1, ColorGround0); QBrush brushGround4(linearGrad); painter.setBrush(brushGround4); painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,H1+2)); //180 //== Pitch Scale: QPen pen(ColorPitch); pen.setWidthF(1.0); painter.setPen(pen); QVector<QLineF> lines; //- (2)-degrees: qreal y; bool isHas = false; for(int k = -1; k <= 1; k += 2) { y = hPitchAngle; while(y >= 2.0*(H1+H2)-2.0*HeightHalfVisible) { y -= 2.0*(H1+H2); } while(y <= -(2.0*(H1+H2)-2.0*HeightHalfVisible)) { y += 2.0*(H1+H2); } for(int i = 1; i <= 4; i++) { y += -2.0*HOneDegreeAngle*k; if(qAbs(y) <= HeightHalfVisible) { isHas = true; lines << QLineF(-8.0,y, 8.0,y); } } } if(isHas) painter.drawLines(lines); lines.clear(); pen.setWidthF(1.5); painter.setPen(pen); qreal xoff, yoff; qreal angle; //- 10-degrees: mpointsF[0].setX(-24.0); mpointsF[1].setX(-24.0); mpointsF[2].setX(24.0); mpointsF[3].setX(24.0); for(int k = -1; k <= 1; k += 2) { for(int i = 0; i <= 9; i++) { angle = 10.0*i; y = hPitchAngle - angle*HOneDegreeAngle*k; while(y >= 2.0*(H1+H2)-2.0*HeightHalfVisible) { y -= 2.0*(H1+H2); } while(y <= -(2.0*(H1+H2)-2.0*HeightHalfVisible)) { y += 2.0*(H1+H2); } if(qAbs(y) <= HeightHalfVisible) { if(i == 0) { painter.drawLine(QLineF(-48.0,y, 48.0,y)); } else if(i < 9) { mpointsF[0].setY(y + 5.0*k); mpointsF[1].setY(y); mpointsF[2].setY(y); mpointsF[3].setY(y + 5.0*k); painter.drawPolyline(mpointsF, 4); //int pointCount) DrawText(painter, -24.0-12.0+0.5, y+5.0/2.0*k, angle); DrawText(painter, 24.0+12.0+1.0, y+5.0/2.0*k, angle); } else { lines << QLineF(-36.0,y-7.0, -36.0,y+7.0); lines << QLineF(-36.0,y, 36.0,y); lines << QLineF( 36.0,y-7.0, 36.0,y+7.0); painter.drawLines(lines); lines.clear(); DrawText(painter, -36.0-12.0+1.0, y, angle); DrawText(painter, 36.0+12.0+1.0, y, angle); } } } } //- (15)-degrees: for(int k = -1; k <= 1; k += 2) { y = hPitchAngle - 10.0*HOneDegreeAngle*(1.0+0.5)*k; while(y >= 2.0*(H1+H2)-2.0*HeightHalfVisible) { y -= 2.0*(H1+H2); } while(y <= -(2.0*(H1+H2)-2.0*HeightHalfVisible)) { y += 2.0*(H1+H2); } if(qAbs(y) <= HeightHalfVisible) painter.drawLine(QLineF(-16.0,y, 16.0,y)); } //===== Roll: ===== painter.setBrush(QBrush(ColorRoll)); //- Triangle: painter.setPen(Qt::NoPen); mpointsF[0].setX(0.0); mpointsF[0].setY(-rRoll); mpointsF[1].setX(-6.5); mpointsF[1].setY(-rRoll - 11.258); // 11.258 = sqrt(3.0)/2.0 * 13.0 mpointsF[2].setX(6.5); mpointsF[2].setY(-rRoll - 11.258); painter.drawPolygon(mpointsF,3); //- Arc: pen.setColor(ColorRoll); pen.setWidthF(1.5); painter.setPen(pen); painter.drawArc(QRectF(-rRoll, -rRoll, 2.0*rRoll, 2.0*rRoll), 30*16, 120*16); //для крючочков qreal hs1 = 5.0; qreal hs2 = 12.0; qreal ws2 = 5.0; qreal hs3 = 10.0; yoff = -rRoll - hs2 - 10.0; // - 5.0 angle = 0.0; qreal dopangle; // QString text; for(int k = -1; k <= 1; k += 2) { xoff = ws2/2.0*k; //- (5), (10): dopangle = 10.0*k; painter.rotate(dopangle); for(int i = 1; i <= 2; i++) { painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs1)); painter.rotate(dopangle); } //- 30, (45), 60, (75): dopangle = 15.0*k; angle = 15.0; for(int i = 1; i <= 2; i++) { // 30, 60: angle += dopangle*k; // text.sprintf(("%.0f"),angle); DrawText(painter, xoff, yoff, angle); //text); mpointsF[0].setX(0.0); mpointsF[0].setY(-rRoll); mpointsF[1].setX(0.0); mpointsF[1].setY(-rRoll-hs2); mpointsF[2].setX(ws2*k); mpointsF[2].setY(-rRoll-hs2); painter.drawPolyline(mpointsF, 3); // (45), (75): painter.rotate(dopangle); painter.drawLine(QPointF(0.0,-rRoll), QPointF(0.0,-rRoll-hs3)); painter.rotate(dopangle); angle += dopangle*k; } //- 90: xoff = 1.0; angle += dopangle*k; // text.sprintf(("%.0f"),angle); DrawText(painter, xoff, yoff, angle); //text); lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2); lines << QLineF(-4.0,-rRoll-hs2, 4.0,-rRoll-hs2); painter.drawLines(lines); lines.clear(); //- 120, 150: xoff = -ws2/2.0*k; dopangle = 30.0*k; painter.rotate(dopangle); for(int i = 1; i <= 2; i++) { angle += dopangle*k; // text.sprintf(("%.0f"),angle); DrawText(painter, xoff, yoff, angle); //text); mpointsF[0].setX(0.0); mpointsF[0].setY(-rRoll); mpointsF[1].setX(0.0); mpointsF[1].setY(-rRoll-hs2); mpointsF[2].setX(-ws2*k); mpointsF[2].setY(-rRoll-hs2); painter.drawPolyline(mpointsF, 3); painter.rotate(dopangle); } if(k == -1) painter.rotate(180.0); } //- 180: xoff = -1.0; angle += dopangle; // text.sprintf(("%.0f"),angle); DrawText(painter, xoff, yoff, angle); //text); lines << QLineF(0.0,-rRoll, 0.0,-rRoll-hs2); lines << QLineF(-3.0,-rRoll-hs2+4.0, 3.0,-rRoll-hs2+4.0); lines << QLineF(-6.0,-rRoll-hs2, 6.0,-rRoll-hs2); painter.drawLines(lines); lines.clear(); painter.rotate(-180.0); //===== Static: ===== painter.rotate(RollAngle); //==Balance: pen.setColor(ColorStaticBalanceOutline); pen.setWidthF(0.5); painter.setPen(pen); linearGrad.setStart(0.0, -3.5+1.5); linearGrad.setFinalStop(0.0, 3.5); linearGrad.setColorAt(0, ColorStaticBalance0); linearGrad.setColorAt(1, ColorStaticBalance1); QBrush brushBalance(linearGrad); painter.setBrush(brushBalance); //-Left: mpointsF[0].setX(-48.0-1.0); mpointsF[0].setY(0.0); mpointsF[1].setX(-48.0-1.0-8.0); mpointsF[1].setY(-3.5); mpointsF[2].setX(-48.0-1.0-8.0-24.0); mpointsF[2].setY(-3.5); mpointsF[3].setX(-48.0-1.0-8.0-24.0); mpointsF[3].setY(3.5); mpointsF[4].setX(-48.0-1.0-8.0); mpointsF[4].setY(3.5); painter.drawPolygon(mpointsF,5); //-Right: mpointsF[0].setX(48.0+1.0); mpointsF[1].setX(48.0+1.0+8.0); mpointsF[2].setX(48.0+1.0+8.0+24.0); mpointsF[3].setX(48.0+1.0+8.0+24.0); mpointsF[4].setX(48.0+1.0+8.0); painter.drawPolygon(mpointsF,5); //-Center: linearGrad.setStart(0.0, 0.0); linearGrad.setFinalStop(0.0, 12.0+6.0); linearGrad.setColorAt(0, ColorStaticBalance0); linearGrad.setColorAt(1, ColorStaticBalance1); QBrush brushBalanceCenter(linearGrad); painter.setBrush(brushBalanceCenter); mpointsF[0].setX(0.0); mpointsF[0].setY(0.0); mpointsF[1].setX(-30.0); mpointsF[1].setY(12.0); mpointsF[2].setX(0.0); mpointsF[2].setY(6.0); mpointsF[3].setX(30.0); mpointsF[3].setY(12.0); painter.drawPolygon(mpointsF,4); //- Triangle: painter.setBrush(QBrush(ColorStaticTriangle)); mpointsF[0].setX(0.0); mpointsF[0].setY(-rRoll); mpointsF[1].setX(6.5); mpointsF[1].setY(-rRoll + 11.258); // 11.258 = sqrt(3.0)/2.0 * 13.0 mpointsF[2].setX(-6.5); mpointsF[2].setY(-rRoll + 11.258); painter.drawPolygon(mpointsF,3); //============================= painter.setOpacity(0.6); QPixmap pixmap = PEkranoplanGL->renderPixmap(); //80,80);//,false); pixmap.setMask(pixmap.createMaskFromColor(QColor(0,0,0, 255))); painter.drawPixmap(-WidthHalf+1,HeightHalf-pixmap.rect().height()-1, pixmap); //-- painter.end(); QPainter paint(this); paint.drawImage(0,0, imgagePaint); }
void ScrollPanner::drawSlider(QPainter& p, QRect r) { p.drawRect(r); }
void ScrollPanner::drawBackground(QPainter& p, QRect r) { p.drawRect(r); }
bool c_graph_item::sceneEventFilter(QGraphicsItem *watched, QEvent *event){ //ajout fleche rouge sur le hover if(event->type() == QEvent::GraphicsSceneHoverEnter && !model_graph->getTransClicked() && !model_graph->getNodeCLicked() && !model_graph->getFinalClicked() ){ if( !model_graph->addedToScene){ std::cout << "mouse enter QGraphics item\n"; //creation de la ligne bleu m_transition * selectedTransition = getTransitionFromQGraphicsItem(watched,event); QLineF * transition_line = selectedTransition->getGraphicalComponentLine(); QPointF p1(transition_line->p1().x(),transition_line->p1().y()); QPointF p2(transition_line->p2().x(),transition_line->p2().y()); //creation du polygon bleu QPointF destPoint = p2.toPoint(); int arrowSize = 10; double angle = ::acos(transition_line->dx() / transition_line->length()); if (transition_line->dy() >= 0) angle = TwoPi - angle; QPointF destArrowP1 = destPoint + QPointF( sin(angle - Pi / 3) * arrowSize, cos(angle - Pi / 3) * arrowSize); QPointF destArrowP2 = destPoint + QPointF( sin(angle - Pi + Pi / 3) * arrowSize, cos(angle - Pi + Pi / 3) * arrowSize); QPolygonF tmp_polygon; tmp_polygon << p2 << destArrowP1 << destArrowP2; model_graph->line = new QGraphicsLineItem(QLineF(p1,p2)); model_graph->arrow = new QGraphicsPolygonItem(tmp_polygon); QPen * pen = new QPen(); pen->setColor(Qt::red); pen->setBrush(Qt::red); pen->setWidth(3); model_graph->line->setPen(*pen); model_graph->arrow->setPen(*pen); model_graph->arrow->setBrush(Qt::red); model_graph->view_graph->scene()->addItem(dynamic_cast<QGraphicsItem *>(model_graph->line)); model_graph->view_graph->scene()->addItem(dynamic_cast<QGraphicsItem *>(model_graph->arrow)); //view_graph->scene()->update(); model_graph->addedToScene = true; } } if(event->type() == QEvent::GraphicsSceneHoverLeave && !model_graph->getTransClicked() && !model_graph->getNodeCLicked() && !model_graph->getFinalClicked()){ if(model_graph->addedToScene){ model_graph->view_graph->scene()->removeItem(dynamic_cast<QGraphicsItem *>(model_graph->line)); model_graph->view_graph->scene()->removeItem(dynamic_cast<QGraphicsItem *>(model_graph->arrow)); delete model_graph->line; delete model_graph->arrow; model_graph->addedToScene = false; } } if(event->type() == QEvent::GraphicsSceneMousePress && !model_graph->getTransClicked() && !model_graph->getNodeCLicked() && !model_graph->getFinalClicked()){ if(QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event)){ if(mouseEvent->button() == Qt::RightButton){ //ajoute un menu pour le changement de couleur de la transition CLICK DROIT std::cout << " the right button :D\n"; std::cout <<"declanche right button \n"; QSize iconSize = QSize (30,30); QPixmap iconPmap (iconSize); iconPmap.fill (Qt::transparent); QPainter painter (&iconPmap); painter.setBrush (QBrush (*m_colors::colorNonParcouru)); painter.setPen(QPen(Qt::NoPen)); painter.drawRect (0,0,30,30); painter.drawPixmap (0, 0, iconPmap); QIcon retIconNonParoucru; retIconNonParoucru.addPixmap(iconPmap, QIcon::Normal, QIcon::Off); retIconNonParoucru.addPixmap(iconPmap, QIcon::Normal, QIcon::On); painter.setBrush (QBrush (*m_colors::colorActif)); painter.drawRect (0,0,30,30); painter.drawPixmap (0, 0, iconPmap); QIcon retIconActif; retIconActif.addPixmap(iconPmap, QIcon::Normal, QIcon::Off); retIconActif.addPixmap(iconPmap, QIcon::Normal, QIcon::On); painter.setBrush (QBrush (*m_colors::colorParcouru)); painter.drawRect (0,0,30,30); painter.drawPixmap (0, 0, iconPmap); QIcon retIconParcouru; retIconParcouru.addPixmap(iconPmap, QIcon::Normal, QIcon::Off); retIconParcouru.addPixmap(iconPmap, QIcon::Normal, QIcon::On); painter.setBrush (QBrush (*m_colors::colorSolution)); painter.drawRect (0,0,30,30); painter.drawPixmap (0, 0, iconPmap); QIcon retIconSolution; retIconSolution.addPixmap(iconPmap, QIcon::Normal, QIcon::Off); retIconSolution.addPixmap(iconPmap, QIcon::Normal, QIcon::On); menu = new QMenu(watched->scene()->views().at(0)); menu->setStyleSheet("background-color:#8e8e8e;"); action_non_parcouru = new QAction(retIconNonParoucru,"Non parcouru", watched->scene()->views().at(0)); action_actif = new QAction(retIconActif,"Actif", watched->scene()->views().at(0)); action_parcouru = new QAction(retIconParcouru, "Parcouru", watched->scene()->views().at(0)); action_solution = new QAction(retIconSolution,"Solution",watched->scene()->views().at(0)); model_graph->setRightClickedTransition(getTransitionFromQGraphicsItem(watched,event)); QObject::connect(action_solution,SIGNAL(triggered()),this, SLOT(setSolutionTransColor())); QObject::connect(action_non_parcouru,SIGNAL(triggered()),this, SLOT(setNonParcouruTransColor())); QObject::connect(action_parcouru,SIGNAL(triggered()),this, SLOT(setParcouruTransColor())); QObject::connect(action_actif,SIGNAL(triggered()),this, SLOT(setActifTransColor())); menu->addAction(action_non_parcouru); menu->addAction(action_actif); menu->addAction(action_parcouru); menu->addAction(action_solution); menu->exec(mouseEvent->screenPos()); //euqivalent au global pos } else if(mouseEvent->button() == Qt::LeftButton){//ajoute fleche bleue sur le clic model_graph->removeAllSelectedTransitions(); std::cout << "transClicked \n"; model_graph->transition_clicked = true; //supprime les transition de hover (qui pourron donc etre reutiliser apres) // view_graph->scene()->removeItem(dynamic_cast<QGraphicsItem *>(line)); //view_graph->scene()->removeItem(dynamic_cast<QGraphicsItem *>(arrow)); model_graph->addedToScene = false; std::cout << "mouse enter QGraphics item\n"; //creation de la ligne bleu m_transition * selectedTransition = getTransitionFromQGraphicsItem(watched,event); model_graph->clickedTransition = selectedTransition; QLineF * transition_line = selectedTransition->getGraphicalComponentLine(); QPointF p1(transition_line->p1().x(),transition_line->p1().y()); QPointF p2(transition_line->p2().x(),transition_line->p2().y()); //creation du polygon bleu QPointF destPoint = p2.toPoint(); int arrowSize = 10; double angle = ::acos(transition_line->dx() / transition_line->length()); if (transition_line->dy() >= 0) angle = TwoPi - angle; QPointF destArrowP1 = destPoint + QPointF( sin(angle - Pi / 3) * arrowSize, cos(angle - Pi / 3) * arrowSize); QPointF destArrowP2 = destPoint + QPointF( sin(angle - Pi + Pi / 3) * arrowSize, cos(angle - Pi + Pi / 3) * arrowSize); QPolygonF tmp_polygon; tmp_polygon << p2 << destArrowP1 << destArrowP2; model_graph->line_click = new QGraphicsLineItem(QLineF(p1,p2)); model_graph->arrow_click = new QGraphicsPolygonItem(tmp_polygon); QPen * pen = new QPen(); pen->setColor(Qt::blue); pen->setBrush(Qt::blue); pen->setWidth(3); model_graph->line_click->setPen(*pen); model_graph->arrow_click->setPen(*pen); model_graph->arrow_click->setBrush(Qt::blue); model_graph->view_graph->scene()->addItem(dynamic_cast<QGraphicsItem *>(model_graph->line_click)); model_graph->view_graph->scene()->addItem(dynamic_cast<QGraphicsItem *>(model_graph->arrow_click)); //view_graph->scene()->update(); model_graph->addedToScene = true; //supression des eventuelle selection de nodes (on ne peut pas selectionner a la fois une transition et un node) std::vector<m_node *> * nodes = model_graph->getNodes(); for(int i =0;i<(int)nodes->size();i++){ m_node * tmp_node = nodes->at(i); tmp_node->removePermanentSelection(); } } } } return true; }
void SurfaceImpl::drawRect(const PRectangle &rc) { painter->drawRect( QRectF(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top)); }
/* * Let us pre-render the tiles. Either we've a Custom Image as * background or we use the drawRect to fill the background and * last we put the number on it */ void PiecesTable::slotCustomImage( const QString& _str ) { QString str = _str; /* couldn't load image fall back to plain tiles*/ QImage img = QImage(str); QPixmap pix; if(img.isNull()) str = QString::null; else{ img = img.smoothScale( width(),height() ); pix.convertFromImage( img ); } /* initialize base point */ uint image=0; /* clear the old tiles */ clear(); /* used variables */ int cols = numCols(); int rows = numRows(); int cellW = cellWidth(); int cellH = cellHeight(); int x2 = cellW-1; int y2 = cellH-1; bool empty = str.isEmpty(); double bw = empty ? 0.9 : 0.98; int x_offset = cellW - int(cellW * bw); // 10% should be enough int y_offset = cellH - int(cellH * bw); /* border polygon calculation*/ initPolygon(cellW, cellH, x_offset, y_offset ); /* avoid crashes with isNull() pixmap later */ if ( cellW == 0 || cellH == 0 ) { _pixmap.resize( 0 ); return; } /* make it bold and bigger */ QFont f = font(); f.setPixelSize(18); f.setBold( TRUE ); /* for every tile */ for(int row = 0; row < rows; ++row ) { for(int col= 0; col < cols; ++col) { QPixmap *pip = new QPixmap(cellW, cellH ); QPainter *p = new QPainter(pip ); p->setFont( f ); /* draw the tradional tile or a part of the pixmap*/ if(empty) { p->setBrush(_colors[image]); p->setPen(NoPen); p->drawRect(0,0,cellW,cellH); }else p->drawPixmap(0, 0, pix,col*cellW, row*cellH, cellW, cellH ); // draw borders if (height() > 40) { p->setBrush(_colors[image].light(130)); p->drawPolygon(light_border); p->setBrush(_colors[image].dark(130)); p->drawPolygon(dark_border); } // draw number p->setPen(black); p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(image+1)); delete p; _pixmap[image++] = pip; } } _image = str; }
//--------------------------------------------------------------------------- // makePixmap // //! Create a pixmap representation of the rack. // //! @return the pixmap //--------------------------------------------------------------------------- QPixmap CrosswordGameRackWidget::makePixmap() const { QPixmap pixmap (getRackSize()); QPainter painter (&pixmap); // FIXME: most of this is duplicated between BoardWidget and here QColor backgroundColor = BACKGROUND_COLOR; QPalette backgroundPalette; backgroundPalette.setColor(QPalette::Light, backgroundColor.light(SQUARE_SHADE_VALUE)); backgroundPalette.setColor(QPalette::Mid, backgroundColor); backgroundPalette.setColor(QPalette::Dark, backgroundColor.dark(SQUARE_SHADE_VALUE)); for (int i = 0; i < NUM_TILES; ++i) { QRect rect (i * COLUMN_WIDTH, 0, COLUMN_WIDTH, ROW_HEIGHT); painter.setPen(backgroundColor); painter.setBrush(backgroundColor); painter.drawRect(rect); qDrawShadePanel(&painter, rect, backgroundPalette, false, SQUARE_SHADE_PANEL_WIDTH); if (i >= letters.length()) continue; QRect tileRect(i * COLUMN_WIDTH + TILE_MARGIN, TILE_MARGIN, COLUMN_WIDTH - 2 * TILE_MARGIN - SQUARE_SHADE_PANEL_WIDTH, ROW_HEIGHT - 2 * TILE_MARGIN - SQUARE_SHADE_PANEL_WIDTH); QColor color = TILE_COLOR; QPalette palette; palette.setColor(QPalette::Light, color.light(TILE_SHADE_VALUE)); palette.setColor(QPalette::Mid, color); palette.setColor(QPalette::Dark, color.dark(TILE_SHADE_VALUE)); painter.setPen(QColor("black")); painter.setBrush(color); painter.drawRect(tileRect); qDrawShadePanel(&painter, tileRect, palette, false, TILE_SHADE_PANEL_WIDTH); QFont tileFont = font(); tileFont.setPixelSize(LETTER_HEIGHT); tileFont.setWeight(QFont::Black); painter.setFont(tileFont); switch (playerNum) { case 1: color = PLAYER1_LETTER_COLOR; break; case 2: color = PLAYER2_LETTER_COLOR; break; default: color = DEFAULT_LETTER_COLOR; break; } painter.setPen(QPen(color)); QChar letter = letters[i]; if (letter == '?') { QPen pen (color); pen.setWidth(1); painter.setPen(pen); painter.setBrush(Qt::NoBrush); QRect blankRect(rect.x() + BLANK_SQUARE_MARGIN, rect.y() + BLANK_SQUARE_MARGIN, rect.width() - 2 * BLANK_SQUARE_MARGIN - SQUARE_SHADE_PANEL_WIDTH - 1, rect.height() - 2 * BLANK_SQUARE_MARGIN - SQUARE_SHADE_PANEL_WIDTH - 1); painter.drawRect(blankRect); } else { painter.drawText(rect, Qt::AlignCenter, letter); } } return pixmap; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL"); //maBase=new QSqlDatabase(db); db.setHostName("172.16.63.111"); db.setDatabaseName("dbtrouxNewWorld"); db.setUserName("troux"); db.setPassword("PscX57Q16"); bool ok = db.open(); if(!ok) { cout<<"Connection impossible"<<endl; } else { cout<<"Connection réussie"<<endl; } Connexion co; QVector<int> idUser = co.getTabIdUser(); int nbUser = idUser.size(); for(int comp=0; comp<nbUser; comp++) { QString userNom = co.getUserNom(idUser[comp]); QString userPrenom = co.getUserPrenom(idUser[comp]); QVector<int> numPDV = co.getUserTabPointDeVente(idUser[comp]); QVector<int> numProduit; for(int compPDV=0; compPDV<numPDV.size(); compPDV++) { QVector<int> tabInstNumProd = co.getProdByPDV(numPDV[compPDV]); for(int compProd=0; compProd < tabInstNumProd.size(); compProd++) { bool uniqueNumProd = true; for(int compVerifDoubleProd=0; compVerifDoubleProd < numProduit.size(); compVerifDoubleProd++) { if(numProduit[compVerifDoubleProd] == tabInstNumProd[compProd]) { uniqueNumProd = false; } } if(uniqueNumProd){ numProduit.push_back(tabInstNumProd[compProd]); } } } QVector<int> numRayon = co.getTabRayon(numProduit); QVector<int> numCategorie = co.getTabCategorie(numRayon); QPrinter printer(QPrinter::HighResolution); //create your QPrinter (don't need to be high resolution, anyway) printer.setFullPage(QPrinter::A4); printer.setOutputFormat(QPrinter::NativeFormat); printer.setOutputFileName("pdfClient/"+ QString::number(idUser[comp]) +".pdf"); QPen pen; int decalage = -100; int tailleImage = 1800; QPainter painter; painter.begin(&printer); QRectF rectangle(700, decalage,1000,900); QImage monImage; monImage.load("images/presentation/logoNw.jpg"); painter.drawImage(rectangle, monImage); QRectF rectangle2(1200, decalage,8000,1000); QImage monImage2; monImage2.load("images/presentation/ecritureNw.png"); painter.drawImage(rectangle2, monImage2); decalage += 2000; painter.setFont(QFont("Arial",15)); painter.drawText(0, decalage, userNom +" "+ userPrenom +","); decalage += 250; painter.drawText(0, decalage,"Bienvenue sur votre catalogue personnalisé "); decalage += 400; painter.setFont(QFont("Arial",9)); painter.drawText(0, decalage, "Liste des points de vente associés :"); decalage += 200; pen.setWidth(10); painter.setPen(pen); for(int compNbPDV=0; compNbPDV<numPDV.size(); compNbPDV++) { painter.drawRect(0, decalage, 3000, 300); painter.drawText(100, decalage+200, QString::number(compNbPDV+1)+ " : " +co.getNomPDV(numPDV[compNbPDV])); painter.drawText(2000, decalage+200, QString::number(co.getProdByPDV(numPDV[compNbPDV]).size())+ " Produits"); decalage += 300; } decalage += 1000; painter.setFont(QFont("Arial",12)); painter.drawText(0, decalage,"Nous vous proposerons cette semaine "+QString::number(numProduit.size()) +" produits parmi les "+ QString::number(numPDV.size()) +" points de vente choisis."); decalage += 650; foreach(const int &idCategorie, numCategorie) { painter.drawText(0, decalage, co.getCategorieName(idCategorie)); decalage += 200; foreach(const int &idRayon, numRayon) { if(co.getCategorieByRayon(idRayon) == idCategorie) { painter.drawText(500,decalage, co.getRayonName(idRayon)); decalage += 500; int decalageV = 1000; foreach(const int &idProduit, numProduit) { if(co.getRayonByProd(idProduit) == idRayon) { painter.drawText(decalageV, decalage-300, co.getProdName(idProduit)); QRectF rectangle(decalageV, decalage-100, tailleImage, tailleImage); QImage monImage; monImage.load("images/produit/"+ QString::number(idProduit) +".png"); painter.drawImage(rectangle, monImage); pen.setColor(Qt::magenta); painter.setPen(pen); painter.setFont(QFont("Arial",10)); painter.drawText(decalageV, decalage+tailleImage+100, QString::number(co.getPriceByIdProd(idProduit)) +" € par "+ co.getUniteByIdProd(idProduit)); QColor color; color.setNamedColor("#04B404"); pen.setColor(color); painter.setPen(pen); painter.drawText(decalageV, decalage+tailleImage+300, "Restant : "+ QString::number(co.getQteRestanteByIdProd(idProduit))); QVector<int> tabAssociatePDV = co.getTabPDVByIdProd(numPDV, idProduit); QString letterPDV = "| "; for(int compNoAPDV=0; compNoAPDV<tabAssociatePDV.size(); compNoAPDV++) { letterPDV += QString::number(compNoAPDV+1)+" | "; } pen.setColor(Qt::blue); painter.setPen(pen); painter.drawText(decalageV, decalage+tailleImage+500, "Disponible à : "+ letterPDV); pen.setColor(Qt::black); painter.setPen(pen); painter.setFont(QFont("Arial",12)); decalageV += tailleImage+300; } } decalage += tailleImage+900; if(decalage > 10500){ printer.newPage(); decalage = 0; } } } }
//----------------------------------------------------------- void CenaObjetos::definirGrade(unsigned tam) { if(tam >= 20 || grade.style()==Qt::NoBrush) { QImage img_grade; float larg, alt, x, y; QSizeF tam_aux; QPrinter printer; QPainter painter; QPen pen; //Caso o tamanho do papel não seja personalizado if(tam_papel!=QPrinter::Custom) { //Configura um dispositivo QPrinter para obter os tamanhos de página printer.setPageSize(tam_papel); printer.setOrientation(orientacao_pag); printer.setPageMargins(margens_pag.left(), margens_pag.top(), margens_pag.right(), margens_pag.bottom(), QPrinter::Millimeter); tam_aux=printer.pageRect(QPrinter::DevicePixel).size(); } //Caso o tipo de papel seja personalizado, usa as margens como tamanho do papel else tam_aux=margens_pag.size(); larg=fabs(roundf(tam_aux.width()/static_cast<float>(tam)) * tam); alt=fabs(roundf(tam_aux.height()/static_cast<float>(tam)) * tam); //Cria uma instância de QImage para ser a textura do brush tam_grade=tam; img_grade=QImage(larg, alt, QImage::Format_ARGB32); //Aloca um QPaointer para executar os desenhos sobre a imagem painter.begin(&img_grade); //Limpa a imagem painter.fillRect(QRect(0,0,larg,alt), QColor(255,255,255)); if(exibir_grade) { //Cria a grade pen.setColor(QColor(225, 225, 225)); painter.setPen(pen); for(x=0; x < larg; x+=tam) for(y=0; y < alt; y+=tam) painter.drawRect(QRectF(QPointF(x,y),QPointF(x + tam,y + tam))); } //Cria as linhas que definem o limite do papel if(exibir_lim_pagina) { pen.setColor(QColor(75,115,195)); pen.setStyle(Qt::DashLine); pen.setWidthF(1.85f); painter.setPen(pen); painter.drawLine(larg-1, 0,larg-1,alt-1); painter.drawLine(0, alt-1,larg-1,alt-1); } painter.end(); grade.setTextureImage(img_grade); } }
void CannonField::paintTarget (QPainter &painter) { painter.setPen (Qt::black); painter.setBrush (Qt::red); painter.drawRect (targetRect()); }
void UcClassCanvas::draw(QPainter & p) { if (! visible()) return; p.setRenderHint(QPainter::Antialiasing, true); QRect r = rect(); QFontMetrics fm(the_canvas()->get_font(UmlNormalFont)); QFontMetrics fim(the_canvas()->get_font(UmlNormalItalicFont)); QColor bckgrnd = p.backgroundColor(); double zoom = the_canvas()->zoom(); FILE * fp = svg(); if (fp != 0) fputs("<g>\n", fp); p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode); QColor co = color(used_color); if (used_view_mode == asClass) { if (used_color != UmlTransparent) { const int shadow = the_canvas()->shadow(); if (shadow != 0) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); p.fillRect (r.right(), r.top() + shadow, shadow, r.height() - 1, ::Qt::darkGray); p.fillRect (r.left() + shadow, r.bottom(), r.width() - 1, shadow, ::Qt::darkGray); if (fp != 0) { fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", QColor(::Qt::darkGray).rgb()&0xffffff, r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1); fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", QColor(::Qt::darkGray).rgb()&0xffffff, r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1); } } } p.setBackgroundColor(co); if (used_color != UmlTransparent) { p.fillRect(r, co); if (fp != 0) fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(used_color), r.x(), r.y(), r.width() - 1, r.height() - 1); } else if (fp != 0) fprintf(fp, "\t<rect fill=\"none\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", r.x(), r.y(), r.width() - 1, r.height() - 1); p.drawRect(r); } const ClassData * data = ((ClassData *) browser_node->get_data()); const int two = (int) (2 * zoom); int he = fm.height() + two; if (data->get_n_formalparams() != 0) r.setTop(r.top() + fm.height()); switch (used_view_mode) { case asInterface: draw_interface_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (INTERFACE_SIZE * zoom) + two); break; case asControl: draw_control_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (CONTROL_HEIGHT * zoom) + two); break; case asBoundary: draw_boundary_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (BOUNDARY_HEIGHT * zoom) + two); break; case asEntity: draw_entity_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (ENTITY_SIZE * zoom) + two); break; case asActor: { QRect ra = r; ra.setHeight((int) (ACTOR_SIZE * zoom)); ra.setLeft(ra.left() + (int) ((ra.width() - ACTOR_SIZE * zoom)/2)); ra.setWidth(ra.height()); draw_actor(&p, ra); } r.setTop(r.top() + (int) (ACTOR_SIZE * zoom) + two); break; case Natural: { const QPixmap * px = ProfiledStereotypes::diagramPixmap(data->get_stereotype(), zoom); int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x(); p.drawPixmap(lft, r.y(), *px); if (fp != 0) // pixmap not really exported in SVG fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1); r.setTop(r.top() + px->height()); } break; default: // class r.setTop(r.top() + two); if (data->get_stereotype()[0]) { p.setFont(the_canvas()->get_font(UmlNormalFont)); p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, QString("<<") + toUnicode(data->get_short_stereotype()) + ">>"); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, QString("<<") + toUnicode(data->get_short_stereotype()) + ">>", p.font(), fp); r.setTop(r.top() + he + two); } } p.setBackgroundMode(::Qt::TransparentMode); p.setFont((data->get_is_abstract()) ? the_canvas()->get_font(UmlNormalItalicFont) : the_canvas()->get_font(UmlNormalFont)); p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name, p.font(), fp); p.setFont(the_canvas()->get_font(UmlNormalFont)); if (used_view_mode == asClass) { r.setTop(r.top() + he); p.drawLine(r.topLeft(), r.topRight()); if (fp != 0) fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.left(), r.top(), r.right(), r.top()); r.setTop(r.top() + (int) (8 * zoom)); p.drawLine(r.topLeft(), r.topRight()); if (fp != 0) fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.left(), r.top(), r.right(), r.top()); } if (fp != 0) fputs("</g>\n", fp); p.setBackgroundColor(bckgrnd); if (selected()) show_mark(p, rect()); }
void QgsColorSwatchGrid::draw( QPainter &painter ) { QPalette pal = QPalette( qApp->palette() ); QColor headerBgColor = pal.color( QPalette::Mid ); QColor headerTextColor = pal.color( QPalette::BrightText ); QColor highlight = pal.color( QPalette::Highlight ); //draw header background painter.setBrush( headerBgColor ); painter.setPen( Qt::NoPen ); painter.drawRect( QRect( 0, 0, width(), mLabelHeight + 0.5 * mLabelMargin ) ); //draw header text painter.setPen( headerTextColor ); painter.drawText( QRect( mLabelMargin, 0.25 * mLabelMargin, width() - 2 * mLabelMargin, mLabelHeight ), Qt::AlignLeft | Qt::AlignVCenter, mScheme->schemeName() ); //draw color swatches QgsNamedColorList::const_iterator colorIt = mColors.constBegin(); int index = 0; for ( ; colorIt != mColors.constEnd(); ++colorIt ) { int row = index / NUMBER_COLORS_PER_ROW; int column = index % NUMBER_COLORS_PER_ROW; QRect swatchRect = QRect( column * ( mSwatchSize + mSwatchSpacing ) + mSwatchMargin, row * ( mSwatchSize + mSwatchSpacing ) + mSwatchMargin + mLabelHeight + 0.5 * mLabelMargin, mSwatchSize, mSwatchSize ); if ( mCurrentHoverBox == index ) { //hovered boxes are slightly larger swatchRect.adjust( -1, -1, 1, 1 ); } //start with checkboard pattern for semi-transparent colors if ( ( *colorIt ).first.alpha() != 255 ) { QBrush checkBrush = QBrush( transparentBackground() ); painter.setPen( Qt::NoPen ); painter.setBrush( checkBrush ); painter.drawRect( swatchRect ); } if ( mCurrentHoverBox == index ) { if ( mDrawBoxDepressed ) { painter.setPen( QPen( QColor( 100, 100, 100 ), mSwatchOutlineSize ) ); } else { //hover color painter.setPen( QPen( QColor( 220, 220, 220 ), mSwatchOutlineSize ) ); } } else if ( mFocused && index == mCurrentFocusBox ) { painter.setPen( highlight ); } else if ( ( *colorIt ).first.name() == mBaseColor.name() ) { //currently active color painter.setPen( QPen( QColor( 75, 75, 75 ), mSwatchOutlineSize ) ); } else { painter.setPen( QPen( QColor( 197, 197, 197 ), mSwatchOutlineSize ) ); } painter.setBrush( ( *colorIt ).first ); painter.drawRect( swatchRect ); index++; } }
void HSI::createCard(void){ QImage _cardImage = QImage(QSize(600,600), QImage::Format_ARGB32); _cardImage.fill(0x00ff0000); //_cardImage.moveTo(10,10); uint midx, midy, width, height; width = _cardImage.width(); midx = width/2; height = _cardImage.height(); midy = height/2; QPainter p; p.setRenderHint(QPainter::Antialiasing, true); p.begin(&_cardImage); p.translate(midx, midy); p.setPen(Qt::black); p.setBrush(Qt::black); p.drawChord(-midx,-midy,width,height,0,360*16); p.setPen(Qt::white); p.setBrush(Qt::white); if(_thickBars > 0) { for (float i = 0 ; i <= 360; i+=_thickBars) { p.save(); p.rotate(value2Angle(i)); p.drawRect(-2.5, -300, 5.0, 30); p.restore(); } } if(_thinBars > 0) { for (float i = 0 ; i <= 360; i+=_thinBars) { p.save(); p.rotate(value2Angle(i)); p.drawRect(-1.0, -300, 2.0, 20); p.restore(); } } p.setPen(QColor(200,200,200)); p.setFont(QFont(QString("Helvetica"), 48, QFont::Bold, false)); if(1) { for (float i = 0 ; i < 360; i+=_numbers) { p.save(); p.rotate(value2Angle(i)); p.save(); QString lineNumber; switch (int(i)) { case 0: lineNumber = QString("N"); break; case 90: lineNumber = QString("E"); break; case 180: lineNumber = QString("S"); break; case 270: lineNumber = QString("W"); break; default: lineNumber = QString::number(i/10); break; } p.translate(0,-234); int width = p.fontMetrics().width(lineNumber); int height = p.fontMetrics().height(); p.drawText(-width/2,-height/2,width,height, Qt::AlignCenter, lineNumber); p.restore(); p.restore(); } } p.end(); _card = QPixmap::fromImage(_cardImage, Qt::AutoColor); }
void FieldView::drawField(QPainter& p, const LogFrame* frame) { p.save(); // reset to center p.translate(-Field_Dimensions::Current_Dimensions.FloorLength() / 2.0, -Field_Dimensions::Current_Dimensions.FloorWidth() / 2.0); p.translate(Field_Dimensions::Current_Dimensions.Border(), Field_Dimensions::Current_Dimensions.Border()); p.setPen(QPen(Qt::white, Field_Dimensions::Current_Dimensions.LineWidth() * 2.0)); // double-width pen for visibility //(although its less accurate) p.setBrush(Qt::NoBrush); p.drawRect(QRectF(0, 0, Field_Dimensions::Current_Dimensions.Length(), Field_Dimensions::Current_Dimensions.Width())); // set brush alpha to 0 p.setBrush(QColor(0, 130, 0, 0)); // reset to center p.translate(Field_Dimensions::Current_Dimensions.Length() / 2.0, Field_Dimensions::Current_Dimensions.Width() / 2.0); // centerline p.drawLine(QLineF(0, Field_Dimensions::Current_Dimensions.Width() / 2, 0, -Field_Dimensions::Current_Dimensions.Width() / 2.0)); // center circle p.drawEllipse( QRectF(-Field_Dimensions::Current_Dimensions.CenterRadius(), -Field_Dimensions::Current_Dimensions.CenterRadius(), Field_Dimensions::Current_Dimensions.CenterDiameter(), Field_Dimensions::Current_Dimensions.CenterDiameter())); p.translate(-Field_Dimensions::Current_Dimensions.Length() / 2.0, 0); // goal areas p.drawArc(QRectF(-Field_Dimensions::Current_Dimensions.ArcRadius(), -Field_Dimensions::Current_Dimensions.ArcRadius() + Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f, 2.f * Field_Dimensions::Current_Dimensions.ArcRadius(), 2.f * Field_Dimensions::Current_Dimensions.ArcRadius()), -90 * 16, 90 * 16); p.drawArc(QRectF(-Field_Dimensions::Current_Dimensions.ArcRadius(), -Field_Dimensions::Current_Dimensions.ArcRadius() - Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f, 2.f * Field_Dimensions::Current_Dimensions.ArcRadius(), 2.f * Field_Dimensions::Current_Dimensions.ArcRadius()), 90 * 16, -90 * 16); p.drawLine(QLineF(Field_Dimensions::Current_Dimensions.ArcRadius(), -Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f, Field_Dimensions::Current_Dimensions.ArcRadius(), Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f)); // Penalty Mark p.drawEllipse( QRectF(-Field_Dimensions::Current_Dimensions.PenaltyDiam() / 2.0f + Field_Dimensions::Current_Dimensions.PenaltyDist(), -Field_Dimensions::Current_Dimensions.PenaltyDiam() / 2.0f, Field_Dimensions::Current_Dimensions.PenaltyDiam(), Field_Dimensions::Current_Dimensions.PenaltyDiam())); p.translate(Field_Dimensions::Current_Dimensions.Length(), 0); p.drawArc(QRectF(-Field_Dimensions::Current_Dimensions.ArcRadius(), -Field_Dimensions::Current_Dimensions.ArcRadius() + Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f, 2.f * Field_Dimensions::Current_Dimensions.ArcRadius(), 2.f * Field_Dimensions::Current_Dimensions.ArcRadius()), -90 * 16, -90 * 16); p.drawArc(QRectF(-Field_Dimensions::Current_Dimensions.ArcRadius(), -Field_Dimensions::Current_Dimensions.ArcRadius() - Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f, 2.f * Field_Dimensions::Current_Dimensions.ArcRadius(), 2.f * Field_Dimensions::Current_Dimensions.ArcRadius()), 90 * 16, 90 * 16); p.drawLine(QLineF(-Field_Dimensions::Current_Dimensions.ArcRadius(), -Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f, -Field_Dimensions::Current_Dimensions.ArcRadius(), Field_Dimensions::Current_Dimensions.GoalFlat() / 2.f)); // Penalty Mark p.drawEllipse( QRectF(-Field_Dimensions::Current_Dimensions.PenaltyDiam() / 2.0f - Field_Dimensions::Current_Dimensions.PenaltyDist(), -Field_Dimensions::Current_Dimensions.PenaltyDiam() / 2.0f, Field_Dimensions::Current_Dimensions.PenaltyDiam(), Field_Dimensions::Current_Dimensions.PenaltyDiam())); // goals float x[2] = {0, Field_Dimensions::Current_Dimensions.GoalDepth()}; float y[2] = {Field_Dimensions::Current_Dimensions.GoalWidth() / 2.0f, -Field_Dimensions::Current_Dimensions.GoalWidth() / 2.0f}; bool flip = frame->blue_team() ^ frame->defend_plus_x(); QColor goalColor = flip ? Qt::yellow : Qt::blue; p.setPen( QPen(goalColor, Field_Dimensions::Current_Dimensions.LineWidth() * 2.0)); // double-width for visibility, not real-life accuracy p.drawLine(QLineF(x[0], y[0], x[1], y[0])); p.drawLine(QLineF(x[0], y[1], x[1], y[1])); p.drawLine(QLineF(x[1], y[1], x[1], y[0])); x[0] -= Field_Dimensions::Current_Dimensions.Length(); x[1] -= Field_Dimensions::Current_Dimensions.Length() + 2 * Field_Dimensions::Current_Dimensions.GoalDepth(); goalColor = flip ? Qt::blue : Qt::yellow; p.setPen(QPen(goalColor, Field_Dimensions::Current_Dimensions.LineWidth() * 2.0)); p.drawLine(QLineF(x[0], y[0], x[1], y[0])); p.drawLine(QLineF(x[0], y[1], x[1], y[1])); p.drawLine(QLineF(x[1], y[1], x[1], y[0])); p.restore(); }
void DAbstractSliderSpinBox::paintPlastique(QPainter& painter) { Q_D(DAbstractSliderSpinBox); QStyleOptionSpinBox spinOpts = spinBoxOptions(); QStyleOptionProgressBar progressOpts = progressBarOptions(); style()->drawComplexControl(QStyle::CC_SpinBox, &spinOpts, &painter, d->dummySpinBox); painter.save(); QRect rect = progressOpts.rect.adjusted(2, 0, -2, 0); QRect leftRect; int progressIndicatorPos = (progressOpts.progress - double(progressOpts.minimum)) / qMax(double(1.0), double(progressOpts.maximum) - progressOpts.minimum) * rect.width(); if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) { leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height()); } else if (progressIndicatorPos > rect.width()) { painter.setPen(palette().highlightedText().color()); } else { painter.setPen(palette().buttonText().color()); } QRegion rightRect = rect; rightRect = rightRect.subtracted(leftRect); QTextOption textOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter); textOption.setWrapMode(QTextOption::NoWrap); if (!(d->edit && d->edit->isVisible())) { painter.setClipRegion(rightRect); painter.setClipping(true); painter.drawText(rect.adjusted(-2, 0, 2, 0), progressOpts.text, textOption); painter.setClipping(false); } if (!leftRect.isNull()) { painter.setPen(palette().highlight().color()); painter.setBrush(palette().highlight()); painter.drawRect(leftRect.adjusted(0, 0, 0, -1)); if (!(d->edit && d->edit->isVisible())) { painter.setPen(palette().highlightedText().color()); painter.setClipRect(leftRect.adjusted(0, 0, 1, 0)); painter.setClipping(true); painter.drawText(rect.adjusted(-2, 0, 2, 0), progressOpts.text, textOption); painter.setClipping(false); } } painter.restore(); }
void RealPaintWidget::paintFrameTo( QPainter &to, const QRect &r, qreal frame ) { /*qreal currentFrame = layers[currentLayer]->frame(); QRect viewportRect( rect() ); if( fixedSize ) { QSize sz = viewportRect.size() - size; viewportRect.setSize( size ); } to.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform ); to.save(); to.scale( qreal( r.width() ) / qreal( viewportRect.width() ), qreal( r.height() ) / qreal( viewportRect.height() ) ); to.translate( r.x(), r.y() ); viewportRect.setWidth( viewportRect.width() - 1 ); viewportRect.setHeight( viewportRect.height() - 1 ); FILL( background, to, viewportRect ); to.setPen( QColor( 0, 0, 0 ) ); to.drawRect( viewportRect ); int size = layers.size(); for (int i = 0; i < size; i++) { layers[i]->setFrame( frame ); layers[i]->paint( to ); layers[i]->setFrame( currentFrame ); } to.restore();*/ qreal currentFrame = layers[currentLayer]->frame(); layers[currentLayer]->setFrame( frame ); QRect viewportRect( rect() ); if( fixedSize ) { QSize sz = viewportRect.size() - size; viewportRect.setSize( size ); } to.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform ); to.save(); to.scale( qreal( r.width() ) / qreal( viewportRect.width() ), qreal( r.height() ) / qreal( viewportRect.height() ) ); to.translate( r.x(), r.y() ); viewportRect.setWidth( viewportRect.width() - 1 ); viewportRect.setHeight( viewportRect.height() - 1 ); //FILL( background, to, viewportRect ); to.setPen( QColor( 0, 0, 0 ) ); to.drawRect( viewportRect ); layers[currentLayer]->paint( to ); layers[currentLayer]->setFrame( currentFrame); to.restore(); }
void RenderGlyph::paint(PaintInfo &paintInfo, int _tx, int _ty) { if(paintInfo.phase != PaintActionForeground) return; if(style()->visibility() != VISIBLE) return; _tx += m_x; _ty += m_y; if((_ty > paintInfo.r.bottom()) || (_ty + m_height <= paintInfo.r.top())) return; QPainter *p = paintInfo.p; const QColor color(style()->color()); p->setPen(color); int xHeight = m_height; int bulletWidth = (xHeight + 1) / 2; int yoff = (xHeight - 1) / 4; QRect marker(_tx, _ty + yoff, bulletWidth, bulletWidth); switch(m_type) { case LDISC: p->setBrush(color); p->drawEllipse(marker); return; case LCIRCLE: p->setBrush(Qt::NoBrush); p->drawEllipse(marker); return; case LSQUARE: p->setBrush(color); p->drawRect(marker); return; case LBOX: p->setBrush(Qt::NoBrush); p->drawRect(marker); return; case LDIAMOND: { static QPointArray diamond(4); int x = marker.x(); int y = marker.y(); int s = bulletWidth / 2; diamond[0] = QPoint(x + s, y); diamond[1] = QPoint(x + 2 * s, y + s); diamond[2] = QPoint(x + s, y + 2 * s); diamond[3] = QPoint(x, y + s); p->setBrush(color); p->drawConvexPolygon(diamond, 0, 4); return; } case LNONE: return; default: // not a glyph assert(false); } }
void QDeclarativeRectangle::drawRect(QPainter &p) { Q_D(QDeclarativeRectangle); if ((d->gradient && d->gradient->gradient()) || d->radius > width()/2 || d->radius > height()/2 || width() < 3 || height() < 3) { // XXX This path is still slower than the image path // Image path won't work for gradients or invalid radius though bool oldAA = p.testRenderHint(QPainter::Antialiasing); if (d->smooth) p.setRenderHint(QPainter::Antialiasing); if (d->pen && d->pen->isValid()) { QPen pn(QColor(d->pen->color()), d->pen->width()); pn.setJoinStyle(Qt::MiterJoin); p.setPen(pn); } else { p.setPen(Qt::NoPen); } if (d->gradient && d->gradient->gradient()) p.setBrush(*d->gradient->gradient()); else p.setBrush(d->color); const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; QRectF rect; if (pw%2) rect = QRectF(0.5, 0.5, width()-1, height()-1); else rect = QRectF(0, 0, width(), height()); qreal radius = d->radius; if (radius > width()/2 || radius > height()/2) radius = qMin(width()/2, height()/2); if (radius > 0.) p.drawRoundedRect(rect, radius, radius); else p.drawRect(rect); if (d->smooth) p.setRenderHint(QPainter::Antialiasing, oldAA); } else { bool oldAA = p.testRenderHint(QPainter::Antialiasing); bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); if (d->smooth) p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; if (d->radius > 0) generateRoundedRect(); else generateBorderedRect(); int xOffset = (d->rectImage.width()-1)/2; int yOffset = (d->rectImage.height()-1)/2; Q_ASSERT(d->rectImage.width() == 2*xOffset + 1); Q_ASSERT(d->rectImage.height() == 2*yOffset + 1); // check whether we've eliminated the center completely if (2*xOffset > width()+pw) xOffset = (width()+pw)/2; if (2*yOffset > height()+pw) yOffset = (height()+pw)/2; QMargins margins(xOffset, yOffset, xOffset, yOffset); QTileRules rules(Qt::StretchTile, Qt::StretchTile); //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); if (d->smooth) { p.setRenderHint(QPainter::Antialiasing, oldAA); p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); } } }
void PackageCanvas::draw(QPainter & p) { if (! visible()) return; p.setRenderHint(QPainter::Antialiasing, true); QRect r = rect(); const BasicData * data = browser_node->get_data(); const QPixmap * px = ProfiledStereotypes::diagramPixmap(data->get_stereotype(), the_canvas()->zoom()); FILE * fp = svg(); if (fp != 0) fputs("<g>\n", fp); if (px != 0) { p.setBackgroundMode(::Qt::TransparentMode); int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x(); p.drawPixmap(lft, r.y(), *px); if (fp != 0) // pixmap not really exported in SVG fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1); r.moveBy(0, px->height()); p.setFont(the_canvas()->get_font(UmlNormalBoldFont)); p.drawText(r, ::Qt::AlignHCenter, browser_node->get_name()); // pixmap not yet exported in SVG if (fp != 0) draw_text(r, ::Qt::AlignHCenter, browser_node->get_name(), p.font(), fp); p.setFont(the_canvas()->get_font(UmlNormalFont)); } else { QColor bckgrnd = p.backgroundColor(); QColor co = color(used_color); p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode); p.setBackgroundColor(co); p.setFont(the_canvas()->get_font(UmlNormalFont)); QFontMetrics fm(the_canvas()->get_font(UmlNormalFont)); const int four = (int) (4 * the_canvas()->zoom()); const int he = fm.height(); const int shadow = the_canvas()->shadow(); if ((used_color != UmlTransparent) && (shadow != 0)) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); } r.setWidth(r.width() * 2 / 5); r.setHeight(he + four); if (used_color != UmlTransparent) p.fillRect(r, co); if (fp != 0) fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(used_color), r.x(), r.y(), r.width() - 1, r.height() - 1); p.drawRect(r); if ((used_color != UmlTransparent) && (shadow != 0)) { p.fillRect (r.right(), r.top() + shadow, shadow, r.height() - 1 - shadow, ::Qt::darkGray); if (fp != 0) fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", QColor(::Qt::darkGray).rgb()&0xffffff, r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - shadow - 1); } const char * name = browser_node->get_name(); if (in_tab) { p.drawText(r, ::Qt::AlignCenter, name); if (fp != 0) draw_text(r, ::Qt::AlignCenter, name, p.font(), fp); } r = rect(); if ((used_color != UmlTransparent) && (shadow != 0)) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); } r.setTop(r.top() + he + four - 1); if (used_color != UmlTransparent) p.fillRect(r, co); if (fp != 0) fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(used_color), r.x(), r.y(), r.width() - 1, r.height() - 1); p.drawRect(r); if ((used_color != UmlTransparent) && (shadow != 0)) { p.fillRect (r.right(), r.top() + shadow, shadow, r.height() - 1, ::Qt::darkGray); p.fillRect (r.left() + shadow, r.bottom(), r.width() - 1, shadow, ::Qt::darkGray); if (fp != 0) { fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", QColor(::Qt::darkGray).rgb()&0xffffff, r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1); fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", QColor(::Qt::darkGray).rgb()&0xffffff, r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1); } } const int three = (int) (3 * the_canvas()->zoom()); r.setTop(r.top() + three); if (! in_tab) { p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name, p.font(), fp); r.setTop(r.top() + he + three); } if (data->get_stereotype()[0]) { p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, QString("<<") + toUnicode(data->get_short_stereotype()) + ">>"); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, QString("<<") + toUnicode(data->get_short_stereotype()) + ">>", p.font(), fp); r.setTop(r.top() + he + three); } if (full_name != name) { p.setFont(the_canvas()->get_font(UmlNormalItalicFont)); p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name, p.font(), fp); p.setFont(the_canvas()->get_font(UmlNormalFont)); } p.setBackgroundColor(bckgrnd); } if (fp != 0) fputs("</g>\n", fp); if (selected()) show_mark(p, rect()); }