MultiLineStringGraphics::MultiLineStringGraphics(OGRMultiLineString* OGRMultiLine, const QPen& Pen): LinearGraphics(Pen.color()) { QPainterPath Path; for (int i=0; i<OGRMultiLine->getNumGeometries();i++) { QPainterPath LinePath; OGRLineString* OGRLine = dynamic_cast<OGRLineString*>(OGRMultiLine->getGeometryRef(i)); LinePath.moveTo(OGRLine->getX(0),OGRLine->getY(0)); for (int i=1; i < OGRLine->getNumPoints(); i++) { LinePath.lineTo(OGRLine->getX(i),OGRLine->getY(i)); } Path.addPath(LinePath); } setPen(Pen); setPath(Path); }
QPainterPath FreehandShape::buildPainterPath(void) { QPainterPath path; StlStrokeList::iterator sEnd = _geometry.strokes.end(); for (StlStrokeList::iterator s = _geometry.strokes.begin(); s != sEnd; ++s) { StlStroke::iterator pBegin = (*s).begin(); StlStroke::iterator pEnd = (*s).end(); for (StlStroke::iterator p = pBegin; p != pEnd; ++p) { if (p == pBegin) { // First point. path.moveTo(QPointF((*p).x, (*p).y)); } else { path.lineTo(QPointF((*p).x, (*p).y)); } } } return path; }
extern "C" void pathext_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *, const fz_matrix *ctm, fz_colorspace *, float *, float) { PathExt *ext = static_cast<PathExt*>(dev->user); if( ext == 0 ) { return; } QPainterPath qPath; float *c = path->coords; for(int i = 0; i < path->cmd_len; i++) { if( path->cmds[i] == FZ_MOVETO ) { qPath.moveTo(c[0], c[1]); c += 2; } else if( path->cmds[i] == FZ_LINETO ) { qPath.lineTo(c[0], c[1]); c += 2; } else if( path->cmds[i] == FZ_CURVETO ) { qPath.cubicTo(c[0], c[1], c[2], c[3], c[4], c[5]); c += 6; } else if( path->cmds[i] == FZ_CLOSE_PATH ) { if( !ext->closed ) { return; } qPath.closeSubpath(); } else { return; } } const QTransform qCtm = toTransform(ctm); qPath = qCtm.map(qPath); ext->paths.push_back(qPath); }
QPainterPath AscanWidget::paint_wave() { QPainterPath path; float xRatio1 = 1.0; float xRatio2 = 1.0; float yRatio = y_axis_length() / 255.0; int drawPoints = 0; if ( m_beam.size() < x_axis_length()) { xRatio1 = x_axis_length() / 1.0 / m_beam.size(); drawPoints = m_beam.size(); } else { xRatio2 = m_beam.size() / 1.0 / x_axis_length(); drawPoints = x_axis_length(); } for (int i = 0; i < drawPoints; ++i) { path.lineTo( i*xRatio1, ((quint8)(m_beam.at((int)(i*xRatio2)))) * yRatio + 0.5); } return path; }
QRect AGenericBrush::move(const QString &brush, QPainter &painter,const QPoint &oldPos, const QPoint &newPos) { painter.save(); int rad = painter.pen().width(); QRect boundingRect = QRect(oldPos, newPos).normalized().adjusted(-rad, -rad, +rad, +rad); QColor color = painter.pen().color(); int thickness = painter.pen().width(); QColor transparentColor(color.red(), color.green(), color.blue(), 0); QPainterPath path; path.setFillRule ( Qt::WindingFill ); // m_path.setFillRule ( Qt::WindingFill ); path.moveTo(oldPos); path.lineTo(newPos); m_path.closeSubpath(); m_path.addPath(path); painter.drawPath(path); painter.restore(); return boundingRect; }
void SunMenuItemView::updateShape() { QPainterPath newPath; qreal tmp = qAbs(sweepLength()); if (width() != 0 && tmp > 0.001) { qint32 innerRad = innerRadius(); qint32 outerRadius = innerRad + width(); QRectF r = QRect(-outerRadius, -outerRadius, outerRadius * 2, outerRadius * 2); if (innerRad == 0 && qAbs(sweepLength() - 360) < 0.0001) { newPath.addEllipse(r); } else { newPath.arcMoveTo(r, startAngle()); newPath.arcTo(r, startAngle(), sweepLength()); if(innerRad == 0) { newPath.lineTo(0,0); }else { r = QRect(-innerRad, -innerRad, innerRad * 2, innerRad * 2); newPath.arcTo(r, startAngle() + sweepLength(), -sweepLength()); } newPath.closeSubpath(); } } // setPath(newPath); reinitializeDisplayedItemPosition(); }
void PAData::paintToScene(QGraphicsScene &scene, QGraphicsItemGroup *group) { CODEBOOK *ts = static_cast<CODEBOOK*>(this->associatedData.data()->getData()); PARTITIONING *pa = &this->partition; CONVEXHULLSET *hull = NULL; ConstructConvexHulls(ts, pa, &hull); QGraphicsItem *item = NULL; CONVEXVERTEX* CV; for (int index=0; index < CHS_size(hull); index++ ) { CV = CHS_hullfirst(hull, index); if(!CV) continue; QPointF start_point = QPointF(VectorScalar(ts, CV->index, 0), VectorScalar(ts, CV->index, 1)); QPainterPath path = QPainterPath(start_point); CV = CV_next(CV); while( CV != NULL ) { QPointF point = QPointF(VectorScalar(ts, CV->index, 0), VectorScalar(ts, CV->index, 1)); path.lineTo(point); CV = CV_next(CV); } item = new QGraphicsPathItem(path); if (group) group->addToGroup(item); else scene.addItem(item); } if (hull != NULL) FreeConvexHulls(hull); }
QPainterPath Previewer::magnifierPath( const QSize & top , const QRect & rct , int padding ) const { QPainterPath path; path.setFillRule( Qt::WindingFill ); /*! ======= Draw Top of the Magnifier ======= */ path.moveTo( (rct.width()-top.width())/2 , padding+top.height() ); path.lineTo( rct.width()/2 , padding ); path.lineTo( (rct.width()+top.width())/2 , padding+top.height() ); /*! ========================================= */ /*! ===== Draw Bottom of the Magnifier ====== */ path.lineTo( rct.width()-padding-ROUNDED_PIXEL , padding+top.height() ); path.quadTo( rct.width()-padding , padding+top.height() , rct.width()-padding , padding+top.height()+ROUNDED_PIXEL ); path.lineTo( rct.width()-padding , rct.height()-padding-ROUNDED_PIXEL ); path.quadTo( rct.width()-padding , rct.height()-padding , rct.width()-padding-ROUNDED_PIXEL , rct.height()-padding ); path.lineTo( padding+ROUNDED_PIXEL , rct.height()-padding ); path.quadTo( padding , rct.height()-padding , padding , rct.height()-padding-ROUNDED_PIXEL ); path.lineTo( padding , padding+top.height()+ROUNDED_PIXEL ); path.quadTo( padding , padding+top.height() , padding+ROUNDED_PIXEL , padding+top.height() ); path.lineTo( (rct.width()-top.width())/2 , padding+top.height() ); /*! ========================================= */ return path; }
void UIMiniToolBar::rebuildShape() { #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR /* Rebuild shape: */ QPainterPath shape; switch (m_alignment) { case Qt::AlignTop: { shape.moveTo(0, 0); shape.lineTo(shape.currentPosition().x(), height() - 10); shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(0, -10), 180, 90); shape.lineTo(width() - 10, shape.currentPosition().y()); shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(-10, -20), 270, 90); shape.lineTo(shape.currentPosition().x(), 0); shape.closeSubpath(); break; } case Qt::AlignBottom: { shape.moveTo(0, height()); shape.lineTo(shape.currentPosition().x(), 10); shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(0, -10), 180, -90); shape.lineTo(width() - 10, shape.currentPosition().y()); shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(-10, 0), 90, -90); shape.lineTo(shape.currentPosition().x(), height()); shape.closeSubpath(); break; } default: break; } m_shape = shape; /* Update: */ update(); #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ }
void PianoKeyItem::setType(int val) { type = val; QPainterPath path; switch(type) { case 0: path.moveTo(0,0); path.lineTo(0, KEY_HEIGHT-2); path.lineTo(2.0, KEY_HEIGHT); path.lineTo(KEY_WIDTH-2, KEY_HEIGHT); path.lineTo(KEY_WIDTH, KEY_HEIGHT-2); path.lineTo(KEY_WIDTH, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, 0); break; case 1: path.moveTo(BKEY_WIDTH * 4/9, 0); path.lineTo(BKEY_WIDTH * 4/9, BKEY_HEIGHT); path.lineTo(0, BKEY_HEIGHT); path.lineTo(0, KEY_HEIGHT-2); path.lineTo(2.0, KEY_HEIGHT); path.lineTo(KEY_WIDTH-2, KEY_HEIGHT); path.lineTo(KEY_WIDTH, KEY_HEIGHT-2); path.lineTo(KEY_WIDTH, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, 0); break; case 2: path.moveTo(BKEY_WIDTH * 5/9, 0); path.lineTo(BKEY_WIDTH * 5/9, BKEY_HEIGHT); path.lineTo(0, BKEY_HEIGHT); path.lineTo(0, KEY_HEIGHT-2); path.lineTo(2.0, KEY_HEIGHT); path.lineTo(KEY_WIDTH-2, KEY_HEIGHT); path.lineTo(KEY_WIDTH, KEY_HEIGHT-2); path.lineTo(KEY_WIDTH, BKEY_HEIGHT); path.lineTo(KEY_WIDTH, 0); break; case 3: path.moveTo(BKEY_WIDTH * 4/9, 0); path.lineTo(BKEY_WIDTH * 4/9, BKEY_HEIGHT); path.lineTo(0, BKEY_HEIGHT); path.lineTo(0, KEY_HEIGHT-2); path.lineTo(2.0, KEY_HEIGHT); path.lineTo(KEY_WIDTH-2, KEY_HEIGHT); path.lineTo(KEY_WIDTH, KEY_HEIGHT-2); path.lineTo(KEY_WIDTH, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 5/9, 0); break; case 4: path.moveTo(BKEY_WIDTH * 5/9, 0); path.lineTo(BKEY_WIDTH * 5/9, BKEY_HEIGHT); path.lineTo(0, BKEY_HEIGHT); path.lineTo(0, KEY_HEIGHT-2); path.lineTo(2.0, KEY_HEIGHT); path.lineTo(KEY_WIDTH-2, KEY_HEIGHT); path.lineTo(KEY_WIDTH, KEY_HEIGHT-2); path.lineTo(KEY_WIDTH, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, 0); break; case 5: path.moveTo(0,0); path.lineTo(0, KEY_HEIGHT-2); path.lineTo(2.0, KEY_HEIGHT); path.lineTo(KEY_WIDTH-2, KEY_HEIGHT); path.lineTo(KEY_WIDTH, KEY_HEIGHT-2); path.lineTo(KEY_WIDTH, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, BKEY_HEIGHT); path.lineTo(KEY_WIDTH - BKEY_WIDTH * 4/9, 0); break; case 6: path.moveTo(0,0); path.lineTo(0, KEY_HEIGHT-2); path.lineTo(2.0, KEY_HEIGHT); path.lineTo(KEY_WIDTH-2, KEY_HEIGHT); path.lineTo(KEY_WIDTH, KEY_HEIGHT-2); path.lineTo(KEY_WIDTH, 0); break; case 7: path.moveTo(0,0); path.lineTo(0, BKEY_HEIGHT-1); path.lineTo(1.0, BKEY_HEIGHT); path.lineTo(BKEY_WIDTH-1, BKEY_HEIGHT); path.lineTo(BKEY_WIDTH, BKEY_HEIGHT-1); path.lineTo(BKEY_WIDTH, 0); break; default: break; } path.closeSubpath(); setPath(path); }
void render_qt_text(QPainter *painter, int w, int h, const QColor &color) { QPainterPath path; path.moveTo(-0.083695, 0.283849); path.cubicTo(-0.049581, 0.349613, -0.012720, 0.397969, 0.026886, 0.428917); path.cubicTo(0.066493, 0.459865, 0.111593, 0.477595, 0.162186, 0.482108); path.lineTo(0.162186, 0.500000); path.cubicTo(0.115929, 0.498066, 0.066565, 0.487669, 0.014094, 0.468810); path.cubicTo(-0.038378, 0.449952, -0.088103, 0.423839, -0.135082, 0.390474); path.cubicTo(-0.182061, 0.357108, -0.222608, 0.321567, -0.256722, 0.283849); path.cubicTo(-0.304712, 0.262250, -0.342874, 0.239362, -0.371206, 0.215184); path.cubicTo(-0.411969, 0.179078, -0.443625, 0.134671, -0.466175, 0.081963); path.cubicTo(-0.488725, 0.029255, -0.500000, -0.033043, -0.500000, -0.104932); path.cubicTo(-0.500000, -0.218407, -0.467042, -0.312621, -0.401127, -0.387573); path.cubicTo(-0.335212, -0.462524, -0.255421, -0.500000, -0.161752, -0.500000); path.cubicTo(-0.072998, -0.500000, 0.003903, -0.462444, 0.068951, -0.387331); path.cubicTo(0.133998, -0.312218, 0.166522, -0.217440, 0.166522, -0.102998); path.cubicTo(0.166522, -0.010155, 0.143394, 0.071325, 0.097138, 0.141441); path.cubicTo(0.050882, 0.211557, -0.009396, 0.259026, -0.083695, 0.283849); path.moveTo(-0.167823, -0.456963); path.cubicTo(-0.228823, -0.456963, -0.277826, -0.432624, -0.314831, -0.383946); path.cubicTo(-0.361665, -0.323340, -0.385082, -0.230335, -0.385082, -0.104932); path.cubicTo(-0.385082, 0.017569, -0.361376, 0.112025, -0.313964, 0.178433); path.cubicTo(-0.277248, 0.229368, -0.228534, 0.254836, -0.167823, 0.254836); path.cubicTo(-0.105088, 0.254836, -0.054496, 0.229368, -0.016045, 0.178433); path.cubicTo(0.029055, 0.117827, 0.051605, 0.028691, 0.051605, -0.088975); path.cubicTo(0.051605, -0.179562, 0.039318, -0.255803, 0.014744, -0.317698); path.cubicTo(-0.004337, -0.365409, -0.029705, -0.400548, -0.061362, -0.423114); path.cubicTo(-0.093018, -0.445680, -0.128505, -0.456963, -0.167823, -0.456963); path.moveTo(0.379011, -0.404739); path.lineTo(0.379011, -0.236460); path.lineTo(0.486123, -0.236460); path.lineTo(0.486123, -0.197292); path.lineTo(0.379011, -0.197292); path.lineTo(0.379011, 0.134913); path.cubicTo(0.379011, 0.168117, 0.383276, 0.190442, 0.391804, 0.201886); path.cubicTo(0.400332, 0.213330, 0.411246, 0.219052, 0.424545, 0.219052); path.cubicTo(0.435531, 0.219052, 0.446227, 0.215264, 0.456635, 0.207689); path.cubicTo(0.467042, 0.200113, 0.474993, 0.188910, 0.480486, 0.174081); path.lineTo(0.500000, 0.174081); path.cubicTo(0.488436, 0.210509, 0.471957, 0.237911, 0.450564, 0.256286); path.cubicTo(0.429170, 0.274662, 0.407054, 0.283849, 0.384215, 0.283849); path.cubicTo(0.368893, 0.283849, 0.353859, 0.279094, 0.339115, 0.269584); path.cubicTo(0.324371, 0.260074, 0.313530, 0.246534, 0.306592, 0.228965); path.cubicTo(0.299653, 0.211396, 0.296184, 0.184075, 0.296184, 0.147002); path.lineTo(0.296184, -0.197292); path.lineTo(0.223330, -0.197292); path.lineTo(0.223330, -0.215667); path.cubicTo(0.241833, -0.224049, 0.260697, -0.237992, 0.279922, -0.257495); path.cubicTo(0.299147, -0.276999, 0.316276, -0.300129, 0.331310, -0.326886); path.cubicTo(0.338826, -0.341070, 0.349523, -0.367021, 0.363400, -0.404739); path.lineTo(0.379011, -0.404739); path.moveTo(-0.535993, 0.275629); painter->translate(w / 2, h / 2); double scale = qMin(w, h) * 8 / 10.0; painter->scale(scale, scale); painter->setRenderHint(QPainter::Antialiasing); painter->save(); painter->translate(.1, .1); painter->fillPath(path, QColor(0, 0, 0, 63)); painter->restore(); painter->setBrush(color); painter->setPen(QPen(Qt::black, 0.02, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin)); painter->drawPath(path); }
void KeyBoardPreview::paintEvent(QPaintEvent* event) { QPainter p(this); p.setRenderHint(QPainter::Antialiasing); p.setBrush(QColor(0xd6, 0xd6, 0xd6)); p.drawRect(rect()); QPen pen; pen.setWidth(1); pen.setColor(QColor(0x58, 0x58, 0x58)); p.setPen(pen); p.setBrush(QColor(0x58, 0x58, 0x58)); p.setBackgroundMode(Qt::TransparentMode); p.translate(0.5, 0.5); int rx = 3; int x=6; int y=6; int first_key_w = 0; int remaining_x[] = {0,0,0,0}; int remaining_widths[] = {0,0,0,0}; for (int i = 0; i < 4; i++) { if (first_key_w > 0) { first_key_w = first_key_w*1.375; if (kb == &kbList[KB_105] && i == 3) first_key_w = key_w * 1.275; p.drawRoundedRect(QRectF(6, y, first_key_w, key_w), rx, rx); x = 6 + first_key_w + space; } else { first_key_w = key_w; } bool last_end = (i==1 && ! kb->kb_extended_return); int rw=usable_width-x; int ii=0; for (int k : kb->keys.at(i)) { QRectF rect = QRectF(x, y, key_w, key_w); if (ii == kb->keys.at(i).size()-1 && last_end) rect.setWidth(rw); p.drawRoundedRect(rect, rx, rx); rect.adjust(5, 1, 0, 0); p.setPen(QColor(0x9e, 0xde, 0x00)); p.setFont(upperFont); p.drawText(rect, Qt::AlignLeft | Qt::AlignTop, shift_text(k)); rect.setBottom(rect.bottom() - 2.5); p.setPen(QColor(0xff, 0xff, 0xff)); p.setFont(lowerFont); p.drawText(rect, Qt::AlignLeft | Qt::AlignBottom, regular_text(k)); rw = rw - space - key_w; x = x + space + key_w; ii = ii+1; p.setPen(pen); } remaining_x[i] = x; remaining_widths[i] = rw; if (i != 1 && i != 2) p.drawRoundedRect(QRectF(x, y, rw, key_w), rx, rx); y = y + space + key_w; } if (kb->kb_extended_return) { rx=rx*2; int x1 = remaining_x[1]; int y1 = 6 + key_w*1 + space*1; int w1 = remaining_widths[1]; int x2 = remaining_x[2]; int y2 = 6 + key_w*2 + space*2; // this is some serious crap... but it has to be so // maybe one day keyboards won't look like this... // one can only hope QPainterPath pp; pp.moveTo(x1, y1+rx); pp.arcTo(x1, y1, rx, rx, 180, -90); pp.lineTo(x1+w1-rx, y1); pp.arcTo(x1+w1-rx, y1, rx, rx, 90, -90); pp.lineTo(x1+w1, y2+key_w-rx); pp.arcTo(x1+w1-rx, y2+key_w-rx, rx, rx, 0, -90); pp.lineTo(x2+rx, y2+key_w); pp.arcTo(x2, y2+key_w-rx, rx, rx, -90, -90); pp.lineTo(x2, y1+key_w); pp.lineTo(x1+rx, y1+key_w); pp.arcTo(x1, y1+key_w-rx, rx, rx, -90, -90); pp.closeSubpath(); p.drawPath(pp); } else { x= remaining_x[2]; y = 6 + key_w*2 + space*2; p.drawRoundedRect(QRectF(x, y, remaining_widths[2], key_w), rx, rx); } QWidget::paintEvent(event); }
void QcWaveform::draw( QPixmap *pix, int x, int width, double f_beg, double f_dur ) { // FIXME anomaly: when _fpp reaching 1.0 rms can go outside min-max! pix->fill( QColor( 0, 0, 0, 0 ) ); QPainter p( pix ); if( !_cache || !_cache->ready() ) return; // check for sane situation: if( f_beg < _rangeBeg || f_beg + f_dur > _rangeEnd ) return; // data indexes sf_count_t i_beg = floor(f_beg); // data beginning; sf_count_t i_count = ceil( f_beg + f_dur ) - i_beg; // data count; bool haveOneMore; if( i_beg + i_count < _rangeEnd ) { ++i_count; haveOneMore = true; } else { haveOneMore = false; } // data source - choose according to horiz. zoom (data-display resolution) bool canUseCache = _fpp < 1.0 ? _cache->fpu() == 1.0 : _fpp >= _cache->fpu(); SoundStream *soundStream; SoundFileStream sfStream; if( canUseCache ) { qcDebugMsg( 2, QString("using cache") ); soundStream = _cache; } else if( sf ) { qcDebugMsg( 2, QString("using file") ); soundStream = &sfStream; sfStream.load( sf, sfInfo, i_beg, i_count ); } else { qcWarningMsg( "QSoundFileView: can't paint waveform: view resolution exceeds data cache resolution," " and soundfile is not given." ); return; } // geometry float spacing = pix->height() * 0.15f / (sfInfo.channels + 1); float chHeight = pix->height() * 0.85f / (float) sfInfo.channels; float yScale = -chHeight / 65535.f * _yZoom; //spacing /= yscale; // initial painter setup QPen minMaxPen; QPen rmsPen; float halfChH = chHeight * 0.5; p.translate( 0.f, halfChH + spacing ); int waveColorN = _waveColors.count(); int ch; for( ch = 0; ch < soundStream->channels(); ++ch ) { if( ch < waveColorN && _waveColors[ch].isValid() ) { QColor clr( _waveColors[ch] ); rmsPen.setColor( clr ); minMaxPen.setColor( clr.darker( 140 ) ); } else { rmsPen.setColor( _rmsColor ); minMaxPen.setColor( _peakColor ); } // draw center line p.setPen( QColor(90,90,90) ); p.drawLine( x, 0, x + width, 0 ); // draw bounding lines p.setPen( QColor(100,100,100) ); p.drawLine( x, halfChH, x+width, halfChH ); p.drawLine( x, -halfChH, x+width, -halfChH ); p.save(); p.setClipping(true); p.setClipRect( x, -halfChH, x+width, chHeight ); p.scale( 1.f, yScale ); if( _fpp > 1.0 ) { // draw min-max regions and RMS short minBuffer[width]; short maxBuffer[width]; short minRMS[width]; short maxRMS[width]; bool ok = soundStream->displayData( ch, f_beg, f_dur, minBuffer, maxBuffer, minRMS, maxRMS, width ); // printf("integration ok: %i\n", ok); Q_ASSERT( ok ); int i; for( i = 0; i < width; ++i ) { short min = minBuffer[i]; short max = maxBuffer[i]; if( max != min ) { p.setPen( minMaxPen ); p.drawLine( x + i, min, x + i, max ); } else { p.setPen( minMaxPen ); p.drawPoint( x + i, min ); } p.setPen( rmsPen ); p.drawLine( x + i, minRMS[i], x + i, maxRMS[i] ); } } else { // draw lines between actual values qreal ppf = 1.0 / _fpp; qreal dx = (i_beg - f_beg) * ppf; bool interleaved = false; short *data = soundStream->rawFrames( ch, i_beg, i_count, &interleaved ); //printf("got raw frames ok: %i\n", data != 0 ); Q_ASSERT( data != 0 ); int step = interleaved ? soundStream->channels() : 1; QPainterPath path; if( i_count ) { QPointF pt( dx, (qreal) *data ); path.moveTo( pt ); } int f; // frame for( f = 1; f < i_count; ++f ) { data += step; QPointF pt( f * ppf + dx, (qreal) *data ); path.lineTo( pt ); } if( i_count && !haveOneMore ) { path.lineTo( QPointF( f * ppf + dx, (qreal)*data ) ); } p.setPen( rmsPen ); p.drawPath( path ); } p.restore(); p.translate( 0.f, chHeight + spacing ); } }
void XYVirtualKeyboard::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); int btn_w = 60; QPainterPath path; path.moveTo(width() - 40, 15); path.lineTo(width() - 30, 25); path.lineTo(width() - 20, 15); painter.setPen(XYSKIN->borderPen); if (!XYSKIN->topBKPixmap.isNull()) { painter.setBrush(XYSKIN->topBKPixmap.scaled(width(), letterLabel->height() + 8)); } else { painter.setBrush(XYSKIN->topColor); } painter.drawRect(rect().x(), rect().y(), rect().width(), letterLabel->height() + 8); triangleBtnRect = QRect(rect().width() - btn_w, rect().y(), btn_w, letterLabel->height() + 8); if (triangleBtnPressed) { if (!XYSKIN->triangleBKPressedPixmap.isNull()) { painter.setBrush(XYSKIN->triangleBKPressedPixmap.scaled(triangleBtnRect.size())); painter.drawRect(triangleBtnRect); } else { painter.setBrush(XYSKIN->trianglePressedBKColor); painter.setPen(painter.brush().color()); painter.drawRect(triangleBtnRect); painter.setPen(XYSKIN->trianglePen); painter.drawPath(path); } } else { if (!XYSKIN->triangleBKPixmap.isNull()) { painter.setBrush(XYSKIN->triangleBKPixmap.scaled(triangleBtnRect.size())); painter.drawRect(triangleBtnRect); } else { painter.setBrush(XYSKIN->topColor); painter.setPen(XYSKIN->trianglePen); painter.drawPath(path); } } painter.setPen(XYSKIN->borderPen); if (stackedWidget->currentWidget() == symbolDragableWidget || stackedWidget->currentWidget() == translateVDragableWidget) { painter.setBrush(XYSKIN->bottomColor1); } else { if (!XYSKIN->bottomBKPixmap.isNull()) { painter.setBrush(XYSKIN->bottomBKPixmap.scaled(width(), height() - letterLabel->height() - 8)); } else { painter.setBrush(XYSKIN->bottomColor2); } } painter.drawRect(rect().x(), rect().y() + letterLabel->height() + 8, rect().width(), rect().height() - letterLabel->height() - 8); }
void AverageSceneItem::paintAveragePath(QPainter *painter) { if(m_lAverageData.size() == 0) return; //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value) float dMaxValue = 1e-9f; switch(m_iChannelKind) { case FIFFV_MEG_CH: { if(m_iChannelUnit == FIFF_UNIT_T_M) { //gradiometers dMaxValue = 1e-10f; if(m_scaleMap.contains(FIFF_UNIT_T_M)) dMaxValue = m_scaleMap[FIFF_UNIT_T_M]; } else if(m_iChannelUnit == FIFF_UNIT_T) //magnitometers { dMaxValue = 1e-11f; if(m_scaleMap.contains(FIFF_UNIT_T)) dMaxValue = m_scaleMap[FIFF_UNIT_T]; } break; } case FIFFV_REF_MEG_CH: { /*11/04/14 Added by Limin: MEG reference channel */ dMaxValue = 1e-11f; if(m_scaleMap.contains(FIFF_UNIT_T)) dMaxValue = m_scaleMap[FIFF_UNIT_T]; break; } case FIFFV_EEG_CH: { dMaxValue = 1e-4f; if(m_scaleMap.contains(FIFFV_EEG_CH)) dMaxValue = m_scaleMap[FIFFV_EEG_CH]; break; } case FIFFV_EOG_CH: { dMaxValue = 1e-3f; if(m_scaleMap.contains(FIFFV_EOG_CH)) dMaxValue = m_scaleMap[FIFFV_EOG_CH]; break; } case FIFFV_STIM_CH: { dMaxValue = 5; if(m_scaleMap.contains(FIFFV_STIM_CH)) dMaxValue = m_scaleMap[FIFFV_STIM_CH]; break; } case FIFFV_MISC_CH: { dMaxValue = 1e-3f; if(m_scaleMap.contains(FIFFV_MISC_CH)) dMaxValue = m_scaleMap[FIFFV_MISC_CH]; break; } } //Plot averaged data QRectF boundingRect = this->boundingRect(); double dScaleY = (boundingRect.height()*10)/(2*dMaxValue); QPointF qSamplePosition; //do for all currently stored evoked set data for(int dataIndex = 0; dataIndex<m_lAverageData.size(); dataIndex++) { //plot data from averaged data m_lAverageData with the calculated downsample factor const double* averageData = m_lAverageData.at(dataIndex).first; int totalCols = m_lAverageData.at(dataIndex).second; //Calculate downsampling factor of averaged data in respect to the items width int dsFactor; totalCols / boundingRect.width()<1 ? dsFactor = 1 : dsFactor = totalCols / boundingRect.width(); if(dsFactor == 0) dsFactor = 1; //Create path //float offset = (*(averageData+(abs(m_firstLastSample.first)*m_iTotalNumberChannels)+m_iChannelNumber)); //choose offset to be the signal value at time instance 0 QPainterPath path = QPainterPath(QPointF(boundingRect.x(), boundingRect.y() + boundingRect.height()/2)); QPen pen; pen.setStyle(Qt::SolidLine); pen.setColor(Qt::yellow); if(!m_cAverageColors.isEmpty() && !(dataIndex<m_cAverageColors.size())) pen.setColor(m_cAverageColors.at(dataIndex)); pen.setWidthF(5); painter->setPen(pen); for(int i = 0; i < totalCols && path.elementCount() <= boundingRect.width(); i += dsFactor) { //evoked matrix is stored in column major double val = ((*(averageData+(i*m_iTotalNumberChannels)+m_iChannelNumber))/*-offset*/) * dScaleY; qSamplePosition.setY(-val); qSamplePosition.setX(path.currentPosition().x()+1); path.lineTo(qSamplePosition); } painter->drawPath(path); } }
void tst_QPainterPath::testOperatorEquals_fuzzy() { // if operator== returns true for two paths it should // also return true when the same transform is applied to both paths { QRectF a(100, 100, 100, 50); QRectF b = a.translated(1e-14, 1e-14); QPainterPath pa; pa.addRect(a); QPainterPath pb; pb.addRect(b); QVERIFY(pa == pb); QTransform transform; transform.translate(-100, -100); QVERIFY(transform.map(pa) == transform.map(pb)); } // higher tolerance for error when path's bounding rect is big { QRectF a(1, 1, 1e6, 0.5e6); QRectF b = a.translated(1e-7, 1e-7); QPainterPath pa; pa.addRect(a); QPainterPath pb; pb.addRect(b); QVERIFY(pa == pb); QTransform transform; transform.translate(-1, -1); QVERIFY(transform.map(pa) == transform.map(pb)); } // operator== should return true for a path that has // been transformed and then inverse transformed { QPainterPath a; a.addRect(0, 0, 100, 100); QTransform transform; transform.translate(100, 20); transform.scale(1.5, 1.5); QPainterPath b = transform.inverted().map(transform.map(a)); QVERIFY(a == b); } { QPainterPath a; a.lineTo(10, 0); a.lineTo(10, 10); a.lineTo(0, 10); QPainterPath b; b.lineTo(10, 0); b.moveTo(10, 10); b.lineTo(0, 10); QVERIFY(a != b); } }
void Chip::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color; if (option->state & QStyle::State_MouseOver) fillColor = fillColor.light(125); if (option->levelOfDetail < 0.2) { if (option->levelOfDetail < 0.125) { painter->fillRect(QRectF(0, 0, 110, 70), fillColor); return; } painter->setPen(QPen(Qt::black, 0)); painter->setBrush(fillColor); painter->drawRect(13, 13, 97, 57); return; } QPen oldPen = painter->pen(); QPen pen = oldPen; int width = 0; if (option->state & QStyle::State_Selected) width += 2; pen.setWidth(width); painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100))); painter->drawRect(QRect(14, 14, 79, 39)); if (option->levelOfDetail >= 1) { painter->setPen(QPen(Qt::gray, 1)); painter->drawLine(15, 54, 94, 54); painter->drawLine(94, 53, 94, 15); painter->setPen(QPen(Qt::black, 0)); } // Draw text if (option->levelOfDetail >= 2) { QFont font("Times", 10); font.setStyleStrategy(QFont::ForceOutline); painter->setFont(font); painter->save(); painter->scale(0.1, 0.1); painter->drawText(170, 180, QString("Model: VSC-2000 (Very Small Chip) at %1x%2").arg(x).arg(y)); painter->drawText(170, 200, QString("Serial number: DLWR-WEER-123L-ZZ33-SDSJ")); painter->drawText(170, 220, QString("Manufacturer: Chip Manufacturer")); painter->restore(); } // Draw lines QVarLengthArray<QLineF, 36> lines; if (option->levelOfDetail >= 0.5) { for (int i = 0; i <= 10; i += (option->levelOfDetail > 0.5 ? 1 : 2)) { lines.append(QLineF(18 + 7 * i, 13, 18 + 7 * i, 5)); lines.append(QLineF(18 + 7 * i, 54, 18 + 7 * i, 62)); } for (int i = 0; i <= 6; i += (option->levelOfDetail > 0.5 ? 1 : 2)) { lines.append(QLineF(5, 18 + i * 5, 13, 18 + i * 5)); lines.append(QLineF(94, 18 + i * 5, 102, 18 + i * 5)); } } if (option->levelOfDetail >= 0.4) { const QLineF lineData[] = { QLineF(25, 35, 35, 35), QLineF(35, 30, 35, 40), QLineF(35, 30, 45, 35), QLineF(35, 40, 45, 35), QLineF(45, 30, 45, 40), QLineF(45, 35, 55, 35) }; lines.append(lineData, 6); } painter->drawLines(lines.data(), lines.size()); // Draw red ink if (stuff.size() > 1) { painter->setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter->setBrush(Qt::NoBrush); QPainterPath path; path.moveTo(stuff.first()); for (int i = 1; i < stuff.size(); ++i) path.lineTo(stuff.at(i)); painter->drawPath(path); } }
void tst_QPainterPath::closing() { // lineto's { QPainterPath triangle(QPoint(100, 100)); triangle.lineTo(200, 100); triangle.lineTo(200, 200); QCOMPARE(triangle.elementCount(), 3); triangle.closeSubpath(); QCOMPARE(triangle.elementCount(), 4); QCOMPARE(triangle.elementAt(3).type, QPainterPath::LineToElement); triangle.moveTo(300, 300); QCOMPARE(triangle.elementCount(), 5); QCOMPARE(triangle.elementAt(4).type, QPainterPath::MoveToElement); triangle.lineTo(400, 300); triangle.lineTo(400, 400); QCOMPARE(triangle.elementCount(), 7); triangle.closeSubpath(); QCOMPARE(triangle.elementCount(), 8); // this will should trigger implicit moveto... triangle.lineTo(600, 300); QCOMPARE(triangle.elementCount(), 10); QCOMPARE(triangle.elementAt(8).type, QPainterPath::MoveToElement); QCOMPARE(triangle.elementAt(9).type, QPainterPath::LineToElement); triangle.lineTo(600, 700); QCOMPARE(triangle.elementCount(), 11); } // curveto's { QPainterPath curves(QPoint(100, 100)); curves.cubicTo(200, 100, 100, 200, 200, 200); QCOMPARE(curves.elementCount(), 4); curves.closeSubpath(); QCOMPARE(curves.elementCount(), 5); QCOMPARE(curves.elementAt(4).type, QPainterPath::LineToElement); curves.moveTo(300, 300); QCOMPARE(curves.elementCount(), 6); QCOMPARE(curves.elementAt(5).type, QPainterPath::MoveToElement); curves.cubicTo(400, 300, 300, 400, 400, 400); QCOMPARE(curves.elementCount(), 9); curves.closeSubpath(); QCOMPARE(curves.elementCount(), 10); // should trigger implicit moveto.. curves.cubicTo(100, 800, 800, 100, 800, 800); QCOMPARE(curves.elementCount(), 14); QCOMPARE(curves.elementAt(10).type, QPainterPath::MoveToElement); QCOMPARE(curves.elementAt(11).type, QPainterPath::CurveToElement); } { QPainterPath rects; rects.addRect(100, 100, 100, 100); QCOMPARE(rects.elementCount(), 5); QCOMPARE(rects.elementAt(0).type, QPainterPath::MoveToElement); QCOMPARE(rects.elementAt(4).type, QPainterPath::LineToElement); rects.addRect(300, 100, 100,100); QCOMPARE(rects.elementCount(), 10); QCOMPARE(rects.elementAt(5).type, QPainterPath::MoveToElement); QCOMPARE(rects.elementAt(9).type, QPainterPath::LineToElement); rects.lineTo(0, 0); QCOMPARE(rects.elementCount(), 12); QCOMPARE(rects.elementAt(10).type, QPainterPath::MoveToElement); QCOMPARE(rects.elementAt(11).type, QPainterPath::LineToElement); } { QPainterPath ellipses; ellipses.addEllipse(100, 100, 100, 100); QCOMPARE(ellipses.elementCount(), 13); QCOMPARE(ellipses.elementAt(0).type, QPainterPath::MoveToElement); QCOMPARE(ellipses.elementAt(10).type, QPainterPath::CurveToElement); ellipses.addEllipse(300, 100, 100,100); QCOMPARE(ellipses.elementCount(), 26); QCOMPARE(ellipses.elementAt(13).type, QPainterPath::MoveToElement); QCOMPARE(ellipses.elementAt(23).type, QPainterPath::CurveToElement); ellipses.lineTo(0, 0); QCOMPARE(ellipses.elementCount(), 28); QCOMPARE(ellipses.elementAt(26).type, QPainterPath::MoveToElement); QCOMPARE(ellipses.elementAt(27).type, QPainterPath::LineToElement); } { QPainterPath path; path.moveTo(10, 10); path.lineTo(40, 10); path.lineTo(25, 20); path.lineTo(10 + 1e-13, 10 + 1e-13); QCOMPARE(path.elementCount(), 4); path.closeSubpath(); QCOMPARE(path.elementCount(), 4); } }
void dmz::QtPluginGraph::_update_power_law ( const BarStruct *LastBar, const Float64 EndOfXAxis) { Boolean foundFirstBar (False); Float32 offset = _spaceWidth; Float64 p (0.0); Float64 q (0.0); Float64 nonZeroCount (0.0); Float64 x (0.0); Float64 y (0.0); Float64 sumX (0.0); Float64 sumY (0.0); Float64 sumXY (0.0); Float64 sumX2 (0.0); HashTableUInt32Iterator it; BarStruct *bar (_ascendingOrder ? _barTable.get_first (it) : _barTable.get_last (it)); while (bar) { if (!foundFirstBar && bar->count) { foundFirstBar = True; } if (foundFirstBar) { if (bar->Id == 0) { x = 1.0; } else { x = log (Float64 (bar->Id)); } if (bar->height < 0.0f) { y = log (-bar->height); sumY += y; sumX += x; sumXY += x * y; sumX2 += x * x; nonZeroCount++; } } if (LastBar == bar) { bar = 0; } else { bar = (_ascendingOrder ? _barTable.get_next (it) : _barTable.get_prev (it)); } } if (nonZeroCount > 0.0) { q = ((nonZeroCount * sumXY) - (sumX * sumY)) / ((nonZeroCount * sumX2) - (sumX * sumX)); p = exp ((sumY - (q * sumX)) / nonZeroCount); } foundFirstBar = false; QPainterPath path; bar = (_ascendingOrder ? _barTable.get_first (it) : _barTable.get_last (it)); const Float32 Offset (_barWidth * 0.5f); while (bar) { if (!foundFirstBar && bar->count) { path.moveTo (bar->offset + Offset, -local_power (p, q, bar->Id)); foundFirstBar = True; } else if (foundFirstBar) { path.lineTo (bar->offset + Offset, -local_power (p, q, bar->Id)); } if (LastBar == bar) { bar = 0; } else { bar = (_ascendingOrder ? _barTable.get_next (it) : _barTable.get_prev (it)); } } if (path.elementCount () > 1) { if (!_powerLawPath) { _powerLawPath = new QGraphicsPathItem; _powerLawPath->setPen (_powerStroke); _powerLawPath->setZValue (2.0); if (_scene) { _scene->addItem (_powerLawPath); } } if (_powerLawPath) { _powerLawPath->setPath (path); } if (!_powerLabel) { _powerLabel = new QGraphicsTextItem; _powerLabel->setPos (260.0, -_barHeight); if (_scene) { _scene->addItem (_powerLabel); } } if (_powerLabel) { _powerLabel->setPlainText ( QString::fromAscii ("Exponent = ") + QString::number (q)); } } else if (_scene) { if (_powerLawPath) { _scene->removeItem (_powerLawPath); delete _powerLawPath; _powerLawPath = 0; } if (_powerLabel) { _scene->removeItem (_powerLabel); delete _powerLabel; _powerLabel = 0; } } }
void LibraryFilterLineEdit::paintEvent(QPaintEvent *) { QStylePainter p(this); QStyleOptionFrame o; initStyleOption(&o); o.palette = QApplication::palette(); //o.rect.adjust(0, 0, -1, 0); p.fillRect(rect(), o.palette.base().color()); QRect rLeft = QRect(o.rect.x(), o.rect.y() + 1, o.rect.height(), o.rect.y() + o.rect.height() - 2); QRect rRight = QRect(o.rect.x() + o.rect.width() - o.rect.height(), o.rect.y() + 1, o.rect.height(), o.rect.y() + o.rect.height() - 2); QRect rText = QRect(rLeft.x() + rLeft.width(), rLeft.y(), rRight.x(), rRight.y() + rRight.height()); //rLeft.adjust(0, 1, 0, -1); //rRight.adjust(0, 1, 0, -1); if (hasFocus()) { p.setPen(QPen(o.palette.highlight().color())); } else { p.setPen(QPen(o.palette.mid().color())); } p.save(); p.setRenderHint(QPainter::Antialiasing, true); QPainterPath painterPath; // 2---1----> Left curve is painted with 2 calls to cubicTo, starting in 1 <----10--9 // | | First cubic call is with points p1, p2 and p3 | | // 3 + Second is with points p3, p4 and p5 + 8 // | | With that, a half circle can be filled with linear gradient | | // 4---5----> <----6---7 painterPath.moveTo(rLeft.x() + rLeft.width(), rLeft.y()); painterPath.cubicTo(rLeft.x() + rLeft.width(), rLeft.y(), rLeft.x() + rLeft.width() / 2.0f, rLeft.y(), rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height() / 2.0f); painterPath.cubicTo(rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height() / 2.0f, rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height(), rLeft.x() + rLeft.width(), rLeft.y() + rLeft.height()); painterPath.lineTo(rRight.x(), rRight.y() + rRight.height()); painterPath.cubicTo(rRight.x(), rRight.y() + rRight.height(), rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height(), rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height() / 2.0f); painterPath.cubicTo(rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height() / 2.0f, rRight.x() + rRight.width() / 2.0f, rRight.y(), rRight.x(), rRight.y()); painterPath.closeSubpath(); p.drawPath(painterPath); p.setRenderHint(QPainter::Antialiasing, false); p.restore(); // Paint text and cursor if (hasFocus() || !text().isEmpty()) { // Highlight selected text p.setPen(o.palette.text().color()); if (hasSelectedText()) { QRect rectTextLeft, rectTextMid, rectTextRight; QString leftText, midText, rightText; int sStart = selectionStart(); int sEnd = selectedText().length() - 1; // Four uses cases to highlight a text if (sStart > 0 && sEnd < text().size() - 1) { // a[b]cd leftText = text().left(sStart); midText = selectedText(); rightText = text().mid(sStart + selectedText().length()); rectTextLeft.setX(rText.x()); rectTextLeft.setY(rText.y()); rectTextLeft.setWidth(fontMetrics().width(leftText)); rectTextLeft.setHeight(rText.height()); rectTextMid.setX(rectTextLeft.x() + rectTextLeft.width()); rectTextMid.setY(rText.y()); rectTextMid.setWidth(fontMetrics().width(midText)); rectTextMid.setHeight(rText.height()); rectTextRight.setX(rectTextMid.x() + rectTextMid.width()); rectTextRight.setY(rText.y()); rectTextRight.setWidth(fontMetrics().width(rightText)); rectTextRight.setHeight(rText.height()); p.fillRect(rectTextLeft, o.palette.base()); p.fillRect(rectTextMid, o.palette.highlight()); p.fillRect(rectTextRight, o.palette.base()); p.drawText(rectTextLeft, Qt::AlignLeft | Qt::AlignVCenter, leftText); p.save(); p.setPen(o.palette.highlightedText().color()); p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText); p.restore(); p.drawText(rectTextRight, Qt::AlignLeft | Qt::AlignVCenter, rightText); } else if (sStart == 0 && sEnd < text().size() - 1) { // [ab]cd midText = selectedText(); rightText = text().mid(sStart + selectedText().length()); rectTextMid.setX(rText.x()); rectTextMid.setY(rText.y()); rectTextMid.setWidth(fontMetrics().width(midText)); rectTextMid.setHeight(rText.height()); rectTextRight.setX(rectTextMid.x() + rectTextMid.width()); rectTextRight.setY(rText.y()); rectTextRight.setWidth(fontMetrics().width(rightText)); rectTextRight.setHeight(rText.height()); p.fillRect(rectTextMid, o.palette.highlight()); p.fillRect(rectTextRight, o.palette.base()); p.save(); p.setPen(o.palette.highlightedText().color()); p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText); p.restore(); p.drawText(rectTextRight, Qt::AlignLeft | Qt::AlignVCenter, rightText); } else if (sStart == 0 && sEnd == text().size() - 1) { // [abcd] midText = selectedText(); rectTextMid.setX(rText.x()); rectTextMid.setY(rText.y()); rectTextMid.setWidth(fontMetrics().width(midText)); rectTextMid.setHeight(rText.height()); p.fillRect(rectTextMid, o.palette.highlight()); p.save(); p.setPen(o.palette.highlightedText().color()); p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText); p.restore(); } else { // ab[cd] // never? } } else { p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, text()); } rText.adjust(0, 2, 0, -2); this->drawCursor(&p, rText); } else { p.setPen(o.palette.mid().color()); p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, placeholderText()); } }
void Stem::draw(QPainter* painter) const { // hide if second chord of a cross-measure pair if (chord() && chord()->crossMeasure() == CrossMeasure::SECOND) return; Staff* st = staff(); bool useTab = st && st->isTabStaff(); qreal lw = lineWidth(); painter->setPen(QPen(curColor(), lw, Qt::SolidLine, Qt::RoundCap)); painter->drawLine(line); if (!useTab || !chord()) return; // TODO: adjust bounding rectangle in layout() for dots and for slash StaffType* stt = st->staffType(); qreal sp = spatium(); bool _up = up(); // slashed half note stem if (chord()->durationType().type() == TDuration::DurationType::V_HALF && stt->minimStyle() == TablatureMinimStyle::SLASHED) { // position slashes onto stem qreal y = _up ? -(_len+_userLen) + STAFFTYPE_TAB_SLASH_2STARTY_UP*sp : (_len+_userLen) - STAFFTYPE_TAB_SLASH_2STARTY_DN*sp; // if stems through, try to align slashes within or across lines if (stt->stemThrough()) { qreal halfLineDist = stt->lineDistance().val() * sp * 0.5; qreal halfSlashHgt = STAFFTYPE_TAB_SLASH_2TOTHEIGHT * sp * 0.5; y = lrint( (y + halfSlashHgt) / halfLineDist) * halfLineDist - halfSlashHgt; } // draw slashes qreal hlfWdt= sp * STAFFTYPE_TAB_SLASH_WIDTH * 0.5; qreal sln = sp * STAFFTYPE_TAB_SLASH_SLANTY; qreal thk = sp * STAFFTYPE_TAB_SLASH_THICK; qreal displ = sp * STAFFTYPE_TAB_SLASH_DISPL; QPainterPath path; for (int i = 0; i < 2; ++i) { path.moveTo( hlfWdt, y); // top-right corner path.lineTo( hlfWdt, y+thk); // bottom-right corner path.lineTo(-hlfWdt, y+thk+sln); // bottom-left corner path.lineTo(-hlfWdt, y+sln); // top-left corner path.closeSubpath(); y += displ; } painter->setBrush(QBrush(curColor())); painter->setPen(Qt::NoPen); painter->drawPath(path); } // dots // NOT THE BEST PLACE FOR THIS? // with tablatures and stems beside staves, dots are not drawn near 'notes', but near stems int nDots = chord()->dots(); if (nDots > 0 && !stt->stemThrough()) { qreal x = chord()->dotPosX(); qreal y = ( (STAFFTYPE_TAB_DEFAULTSTEMLEN_DN * 0.2) * sp) * (_up ? -1.0 : 1.0); qreal step = score()->styleS(StyleIdx::dotDotDistance).val() * sp; for (int dot = 0; dot < nDots; dot++, x += step) drawSymbol(SymId::augmentationDot, painter, QPointF(x, y)); } }
void TemporalConstraintView::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { // Draw the rack bg if(auto rack = presenter().rack()) { auto rackRect = rack->view().boundingRect(); painter->fillRect(rackRect, QColor::fromRgba(qRgba(0, 127, 229, 76))); auto color = qApp->palette("ScenarioPalette").base().color(); QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; painter->setPen(pen); painter->drawLine(rackRect.topLeft(), rackRect.bottomLeft()); painter->drawLine(rackRect.topRight(), rackRect.bottomRight()); } QPainterPath solidPath, dashedPath, leftBrace, rightBrace; // m_endState->setPos(defaultWidth(), 0); // Paths if(infinite()) { if(minWidth() != 0) { solidPath.lineTo(minWidth(), 0); leftBrace.moveTo(minWidth(), -10); leftBrace.arcTo(minWidth() - 10, -10, 20, 20, 90, 180); } // TODO end state should be hidden dashedPath.moveTo(minWidth(), 0); dashedPath.lineTo(defaultWidth(), 0); } else if(minWidth() == maxWidth()) // TODO rigid() { solidPath.lineTo(defaultWidth(), 0); } else { if(minWidth() != 0) solidPath.lineTo(minWidth(), 0); dashedPath.moveTo(minWidth(), 0); dashedPath.lineTo(maxWidth(), 0); leftBrace.moveTo(minWidth(), -10); leftBrace.arcTo(minWidth() - 10, -10, 20, 20, 90, 180); rightBrace.moveTo(maxWidth(), 10); rightBrace.arcTo(maxWidth() - 10, -10, 20, 20, 270, 180); } QPainterPath playedPath; if(playWidth() != 0) { playedPath.lineTo(playWidth(), 0); } // Colors QColor constraintColor; if(isSelected()) { constraintColor = QColor::fromRgbF(0.188235, 0.54902, 0.776471); } else { constraintColor = qApp->palette("ScenarioPalette").base().color(); } if(warning()) { constraintColor = QColor{200,150,0}; } if(! isValid()) { constraintColor = Qt::red; } m_solidPen.setColor(constraintColor); m_dashPen.setColor(constraintColor); // Drawing painter->setPen(m_solidPen); if(!solidPath.isEmpty()) painter->drawPath(solidPath); if(!leftBrace.isEmpty()) painter->drawPath(leftBrace); if(!rightBrace.isEmpty()) painter->drawPath(rightBrace); painter->setPen(m_dashPen); if(!dashedPath.isEmpty()) painter->drawPath(dashedPath); leftBrace.closeSubpath(); rightBrace.closeSubpath(); QPen anotherPen(Qt::transparent, 4); painter->setPen(anotherPen); QColor blueish = m_solidPen.color().lighter(); blueish.setAlphaF(0.3); painter->setBrush(blueish); painter->drawPath(leftBrace); painter->drawPath(rightBrace); static const QPen playedPen{ QBrush{Qt::green}, 4, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin }; static const QPen dashedPlayedPen{ QBrush{Qt::green}, 4, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin }; painter->setPen(playedPen); if(!playedPath.isEmpty()) painter->drawPath(playedPath); int fontSize = 12; QRectF labelRect{0,0, defaultWidth(), (-fontSize - 2.)}; QFont f("Ubuntu"); f.setPixelSize(fontSize); painter->setFont(f); painter->setPen(m_labelColor); painter->drawText(labelRect, Qt::AlignCenter, m_label); /* painter->setPen(Qt::darkRed); painter->setBrush(Qt::NoBrush); painter->drawRect(boundingRect()); */ }
void SkeletonTool::drawDrawingBrowser(const TXshCell &cell, const TPointD ¢er) { if (!cell.m_level || cell.m_level->getFrameCount() <= 1) return; double pixelSize = getPixelSize(); std::string name = ::to_string(cell.m_level->getName()) + "." + std::to_string(cell.m_frameId.getNumber()); QString qText = QString::fromStdString(name); QFont font("Arial", 10); // ,QFont::Bold); QFontMetrics fm(font); QSize textSize = fm.boundingRect(qText).size(); int arrowHeight = 10; int minTextWidth = 2 * arrowHeight + 5; if (textSize.width() < minTextWidth) textSize.setWidth(minTextWidth); QSize totalSize(textSize.width(), textSize.height() + 2 * arrowHeight); TPointD p = center + TPointD(30, -arrowHeight) * pixelSize; QRect textRect(0, arrowHeight, textSize.width(), textSize.height()); assert(glGetError() == 0); if (isPicking()) { double x0 = p.x, x1 = p.x + totalSize.width() * pixelSize; double y0 = p.y, y3 = p.y + totalSize.height() * pixelSize; double y1 = y0 + arrowHeight * pixelSize; double y2 = y3 - arrowHeight * pixelSize; double x = (x0 + x1) * 0.5; double d = arrowHeight * pixelSize; glColor3d(0, 1, 0); glPushName(TD_ChangeDrawing); glRectd(x0, y1, x1, y2); glPopName(); glPushName(TD_IncrementDrawing); glBegin(GL_POLYGON); glVertex2d(x, y0); glVertex2d(x + d, y0 + d); glVertex2d(x - d, y0 + d); glEnd(); glPopName(); glPushName(TD_DecrementDrawing); glBegin(GL_POLYGON); glVertex2d(x, y3); glVertex2d(x + d, y3 - d); glVertex2d(x - d, y3 - d); glEnd(); glPopName(); return; } else { assert(glGetError() == 0); bool active = m_device == TD_ChangeDrawing || m_device == TD_IncrementDrawing || m_device == TD_DecrementDrawing; QImage img(totalSize.width(), totalSize.height(), QImage::Format_ARGB32); img.fill(Qt::transparent); QPainter imgPainter(&img); imgPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); //imgPainter.setPen(Qt::black); //imgPainter.drawRect(0,0,totalSize.width(),totalSize.height()); imgPainter.setPen(Qt::NoPen); imgPainter.setBrush(QColor(200, 200, 200, 200)); imgPainter.drawRect(textRect); imgPainter.setPen(active ? Qt::red : Qt::black); imgPainter.setBrush(Qt::NoBrush); imgPainter.setFont(font); imgPainter.drawText(textRect, Qt::AlignCenter, qText); if (active) { int x = textRect.center().x(); int d = arrowHeight - 4; int y = 0; QPainterPath upArrow; upArrow.moveTo(x, y); upArrow.lineTo(x + d, y + d); upArrow.lineTo(x - d, y + d); upArrow.lineTo(x, y); y = totalSize.height() - 1; QPainterPath dnArrow; dnArrow.moveTo(x, y); dnArrow.lineTo(x + d, y - d); dnArrow.lineTo(x - d, y - d); dnArrow.lineTo(x, y); imgPainter.setPen(Qt::NoPen); imgPainter.setBrush(m_device == TD_DecrementDrawing ? QColor(255, 0, 0) : QColor(200, 100, 100)); imgPainter.drawPath(upArrow); imgPainter.setBrush(m_device == TD_IncrementDrawing ? QColor(255, 0, 0) : QColor(200, 100, 100)); imgPainter.drawPath(dnArrow); } QImage texture = QGLWidget::convertToGLFormat(img); glRasterPos2f(p.x, p.y); // glBitmap(0,0,0,0, 0,-size.height()+(y+delta.y), NULL); // glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDrawPixels(texture.width(), texture.height(), GL_RGBA, GL_UNSIGNED_BYTE, texture.bits()); glDisable(GL_BLEND); glColor3d(0, 0, 0); assert(glGetError() == 0); } }
void OrthogonalRenderer::drawMapObject(QPainter *painter, const MapObject *object, const QColor &color) const { painter->save(); const QRectF bounds = object->bounds(); QRectF rect(tileToPixelCoords(bounds.topLeft()), tileToPixelCoords(bounds.bottomRight())); painter->translate(rect.topLeft()); rect.moveTopLeft(QPointF(0, 0)); if(object->getPoly()!=NULL) { Poly* pPoly=object->getPoly(); unsigned int size=pPoly->getPointCount(); if(size>1) { QPainterPath path; path.moveTo(pPoly->getPointByIndex(0)); for(unsigned int i=1;i<size;++i) { path.lineTo(pPoly->getPointByIndex(i)); } painter->drawPath(path); } }else if (object->tile()) { const QPixmap &img = object->tile()->image(); const QPoint paintOrigin(0, -img.height()); painter->drawPixmap(paintOrigin, img); QPen pen(Qt::SolidLine); painter->setPen(pen); painter->drawRect(QRect(paintOrigin, img.size())); pen.setStyle(Qt::DotLine); pen.setColor(color); painter->setPen(pen); painter->drawRect(QRect(paintOrigin, img.size())); } else { if (rect.isNull()) rect = QRectF(QPointF(-10, -10), QSizeF(20, 20)); const QFontMetrics fm = painter->fontMetrics(); QString name = fm.elidedText(object->name(), Qt::ElideRight, rect.width() + 2); painter->setRenderHint(QPainter::Antialiasing); // Draw the shadow QPen pen(Qt::black, 2); painter->setPen(pen); painter->drawRect(rect.translated(QPointF(1, 1))); if (!name.isEmpty()) painter->drawText(QPoint(1, -5 + 1), name); QColor brushColor = color; brushColor.setAlpha(50); QBrush brush(brushColor); pen.setColor(color); painter->setPen(pen); painter->setBrush(brush); painter->drawRect(rect); if (!name.isEmpty()) painter->drawText(QPoint(0, -5), name); } painter->restore(); }
//#include <QTime> void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { /* static int frames = 0; static QTime time; if (frames++ % 100 == 0) { frames = 1; time.restart(); } if (time.elapsed() > 0) { painter->setPen(Qt::white); painter->drawText(0, 0, QString::number(frames / (time.elapsed() / 1000.0))); }*/ stabilize(); if (m_sticks) { painter->setPen(Qt::white); for (int i=0; i<BoneCount; ++i) { int n1 = Bones[i * 2]; int n2 = Bones[i * 2 + 1]; Node *node1 = m_nodes[n1]; Node *node2 = m_nodes[n2]; painter->drawLine(node1->pos(), node2->pos()); } } else { // first bone is neck and will be used for head QPainterPath path; path.moveTo(posFor(0)); path.lineTo(posFor(1)); // right arm path.lineTo(posFor(2)); path.lineTo(posFor(6)); path.lineTo(posFor(7)); // left arm path.moveTo(posFor(3)); path.lineTo(posFor(8)); path.lineTo(posFor(9)); // body path.moveTo(posFor(2)); path.lineTo(posFor(4)); path.lineTo(posFor(10)); path.lineTo(posFor(11)); path.lineTo(posFor(5)); path.lineTo(posFor(3)); path.lineTo(posFor(1)); // right leg path.moveTo(posFor(10)); path.lineTo(posFor(12)); path.lineTo(posFor(13)); // left leg path.moveTo(posFor(11)); path.lineTo(posFor(14)); path.lineTo(posFor(15)); painter->setPen(QPen(m_penColor, 5.0, Qt::SolidLine, Qt::RoundCap)); painter->drawPath(path); { int n1 = Bones[0]; int n2 = Bones[1]; Node *node1 = m_nodes[n1]; Node *node2 = m_nodes[n2]; QPointF dist = node2->pos() - node1->pos(); qreal sinAngle = dist.x() / sqrt(pow(dist.x(), 2) + pow(dist.y(), 2)); qreal angle = asin(sinAngle) * 180.0 / M_PI; QPointF headPos = node1->pos(); painter->translate(headPos); painter->rotate(-angle); painter->setBrush(m_fillColor); painter->drawEllipse(QPointF(0,0), 50.0, 50.0); painter->setBrush(m_penColor); painter->setPen(QPen(m_penColor, 2.5, Qt::SolidLine, Qt::RoundCap)); // eyes if (m_isDead) { painter->drawLine(-30.0, -30.0, -20.0, -20.0); painter->drawLine(-20.0, -30.0, -30.0, -20.0); painter->drawLine(20.0, -30.0, 30.0, -20.0); painter->drawLine(30.0, -30.0, 20.0, -20.0); } else { painter->drawChord(QRectF(-30.0, -30.0, 25.0, 70.0), 30.0*16, 120.0*16); painter->drawChord(QRectF(5.0, -30.0, 25.0, 70.0), 30.0*16, 120.0*16); } // mouth if (m_isDead) { painter->drawLine(-28.0, 2.0, 29.0, 2.0); } else { painter->setBrush(QColor(128, 0, 64 )); painter->drawChord(QRectF(-28.0, 2.0-55.0/2.0, 57.0, 55.0), 0.0, -180.0*16); } // pupils if (!m_isDead) { painter->setPen(QPen(m_fillColor, 1.0, Qt::SolidLine, Qt::RoundCap)); painter->setBrush(m_fillColor); painter->drawEllipse(QPointF(-12.0, -25.0), 5.0, 5.0); painter->drawEllipse(QPointF(22.0, -25.0), 5.0, 5.0); } } } }
// Draw curve. void samplv1widget_filt::paintEvent ( QPaintEvent *pPaintEvent ) { QPainter painter(this); const QRect& rect = QWidget::rect(); const int h = rect.height(); const int w = rect.width(); const int h2 = h >> 1; const int h4 = h >> 2; const int w4 = w >> 2; const int w8 = w >> 3; const int iSlope = int(m_fSlope); const int ws = w8 - (iSlope == 1 ? (w8 >> 1) : 0); int x = w8 + int(m_fCutoff * float(w - w4)); int y = h2 - int(m_fReso * float(h + h4)); QPolygon poly(6); QPainterPath path; const int iType = (iSlope == 3 ? 4 : int(m_fType)); // Low, Notch if (iType == 0 || iType == 3) { if (iType == 3) x -= w8; poly.putPoints(0, 6, 0, h2, x - w8, h2, x, h2, x, y, x + ws, h, 0, h); path.moveTo(poly.at(0)); path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); path.lineTo(poly.at(5)); if (iType == 3) x += w8; } // Band if (iType == 1) { const int y2 = (y + h4) >> 1; poly.putPoints(0, 6, 0, h, x - w8 - ws, h, x - ws, y2, x + ws, y2, x + w8 + ws, h, 0, h); path.moveTo(poly.at(0)); path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); path.lineTo(poly.at(5)); } // High, Notch if (iType == 2 || iType == 3) { if (iType == 3) { x += w8; y = h2; } poly.putPoints(0, 6, x - ws, h, x, y, x, h2, x + w8, h2, w, h2, w, h); path.moveTo(poly.at(0)); path.cubicTo(poly.at(1), poly.at(2), poly.at(3)); path.lineTo(poly.at(4)); path.lineTo(poly.at(5)); if (iType == 3) x -= w8; } // Formant if (iType == 4) { const int x2 = (x - w4) >> 2; const int y2 = (y - h4) >> 2; poly.putPoints(0, 6, 0, h2, x2, h2, x - ws, h2, x, y2, x + ws, h, 0, h); path.moveTo(poly.at(0)); #if 0 path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); #else const int n3 = 5; // num.formants const int w3 = (x + ws - x2) / n3 - 1; const int w6 = (w3 >> 1); const int h3 = (h4 >> 1); int x3 = x2; int y3 = y2; for (int i = 0; i < n3; ++i) { poly.putPoints(1, 3, x3, h2, x3 + w6, y3, x3 + w3, y3 + h2); path.cubicTo(poly.at(1), poly.at(2), poly.at(3)); x3 += w3; y3 += h3; } path.lineTo(poly.at(4)); #endif path.lineTo(poly.at(5)); } const QPalette& pal = palette(); const bool bDark = (pal.window().color().value() < 0x7f); const QColor& rgbLite = (isEnabled() ? (bDark ? Qt::darkYellow : Qt::yellow) : pal.mid().color()); const QColor& rgbDark = pal.window().color().darker(180); painter.fillRect(rect, rgbDark); painter.setPen(bDark ? Qt::gray : Qt::darkGray); QLinearGradient grad(0, 0, w << 1, h << 1); grad.setColorAt(0.0f, rgbLite); grad.setColorAt(1.0f, Qt::black); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(grad); painter.drawPath(path); #ifdef CONFIG_DEBUG_0 painter.drawText(QFrame::rect(), Qt::AlignTop|Qt::AlignHCenter, tr("Cutoff(%1) Reso(%2)") .arg(int(100.0f * cutoff())) .arg(int(100.0f * reso()))); #endif painter.setRenderHint(QPainter::Antialiasing, false); painter.end(); QFrame::paintEvent(pPaintEvent); }
void TemporalConstraintView::paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) { qreal min_w = minWidth(); qreal max_w = maxWidth(); qreal def_w = defaultWidth(); qreal play_w = playWidth(); // Draw the stuff present if there is a rack *in the model* ? if(presenter().rack()) { // Background auto rect = boundingRect(); rect.adjust(0,15,0,-10); rect.setWidth(this->defaultWidth()); painter->fillRect(rect, m_bgColor); // Fake timenode continuation auto color = ScenarioStyle::instance().RackSideBorder; QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; painter->setPen(pen); painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); } QPainterPath solidPath, dashedPath, leftBrace, rightBrace; // Paths if(infinite()) { if(min_w != 0.) { solidPath.lineTo(min_w, 0); leftBrace.moveTo(min_w, -10); leftBrace.arcTo(min_w - 10, -10, 20, 20, 90, 180); } // TODO end state should be hidden dashedPath.moveTo(min_w, 0); dashedPath.lineTo(def_w, 0); } else if(min_w == max_w) // TODO rigid() { solidPath.lineTo(def_w, 0); } else { if(min_w != 0.) solidPath.lineTo(min_w, 0); dashedPath.moveTo(min_w, 0); dashedPath.lineTo(max_w, 0); leftBrace.moveTo(min_w + 10, -10); leftBrace.arcTo(min_w, -10, 20, 20, 90, 180); leftBrace.closeSubpath(); rightBrace.moveTo(max_w, 10); rightBrace.arcTo(max_w - 10, -10, 20, 20, 270, 180); rightBrace.closeSubpath(); rightBrace.translate(-10, 0); // TODO bleh. } QPainterPath playedPath; if(play_w != 0.) { playedPath.lineTo(play_w, 0); } // Colors QColor constraintColor; // TODO make a switch instead if(isSelected()) { constraintColor = ScenarioStyle::instance().ConstraintSelected; } else if(warning()) { constraintColor = ScenarioStyle::instance().ConstraintWarning; } else { constraintColor = ScenarioStyle::instance().ConstraintBase; } if(! isValid()) { constraintColor = ScenarioStyle::instance().ConstraintInvalid; this->setZValue(this->zValue()+ 1); } else { this->setZValue(parentObject()->zValue() + 3); } m_solidPen.setColor(constraintColor); m_dashPen.setColor(constraintColor); // Drawing painter->setPen(m_solidPen); if(!solidPath.isEmpty()) painter->drawPath(solidPath); if(!leftBrace.isEmpty()) painter->drawPath(leftBrace); if(!rightBrace.isEmpty()) painter->drawPath(rightBrace); painter->setPen(m_dashPen); if(!dashedPath.isEmpty()) painter->drawPath(dashedPath); leftBrace.closeSubpath(); rightBrace.closeSubpath(); QPen anotherPen(Qt::transparent, 4); painter->setPen(anotherPen); QColor blueish = m_solidPen.color().lighter(); blueish.setAlphaF(0.3); painter->setBrush(blueish); painter->drawPath(leftBrace); painter->drawPath(rightBrace); static const QPen playedPen{ QBrush{ScenarioStyle::instance().ConstraintPlayFill}, 4, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin }; painter->setPen(playedPen); if(!playedPath.isEmpty()) painter->drawPath(playedPath); static const int fontSize = 12; QRectF labelRect{0,0, defaultWidth(), (-fontSize - 2.)}; auto f = ProcessFonts::Sans(); f.setPointSize(fontSize); painter->setFont(f); painter->setPen(m_labelColor); painter->drawText(labelRect, Qt::AlignCenter, m_label); #if defined(ISCORE_SCENARIO_DEBUG_RECTS) painter->setPen(Qt::darkRed); painter->setBrush(Qt::NoBrush); painter->drawRect(boundingRect()); #endif }
void MacroPinItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) { graph::VertexItem* vertexItem = static_cast<graph::VertexItem*>(parentItem()); Q_ASSERT(vertexItem != 0); const graph::Palette& pal = palette(); QRectF rect = boundingRect(); switch(vertexItem->itemLayout()) { case graph::Defines::TopToBottom: { QPainterPath pinPath; if (pin().direction() == graph::Defines::Incoming) { painter->setPen(pal.pen(graph::Palette::PinIncomingBorder)); pinPath.moveTo(rect.right(),rect.top() + rect.height() / 2.0); pinPath.lineTo(rect.topRight()); pinPath.lineTo(rect.topLeft()); pinPath.lineTo(rect.left(),rect.top() + rect.height() / 2.0); pinPath.arcTo(rect,180.0,180.0); pinPath.closeSubpath(); painter->setBrush(pal.brush(graph::Palette::PinIncomingFill)); painter->drawPath(pinPath); } else { painter->setPen(pal.pen(graph::Palette::PinOutgoingBorder)); pinPath.moveTo(rect.right(),rect.top() + rect.height() / 2.0); pinPath.lineTo(rect.bottomRight()); pinPath.lineTo(rect.bottomLeft()); pinPath.lineTo(rect.left(),rect.top() + rect.height() / 2.0); pinPath.arcTo(rect,180.0,-180.0); pinPath.closeSubpath(); painter->setBrush(pal.brush(graph::Palette::PinOutgoingFill)); painter->drawPath(pinPath); } break; } case graph::Defines::LeftToRight: { QPainterPath pinPath; if (pin().direction() == graph::Defines::Incoming) { painter->setPen(pal.pen(graph::Palette::PinIncomingBorder)); pinPath.moveTo(rect.left() + rect.width() / 2.0,rect.top()); pinPath.lineTo(rect.topLeft()); pinPath.lineTo(rect.bottomLeft()); pinPath.lineTo(rect.left() + rect.width() / 2.0,rect.bottom()); pinPath.arcTo(rect,270.0,180.0); pinPath.closeSubpath(); painter->setBrush(pal.brush(graph::Palette::PinIncomingFill)); painter->drawPath(pinPath); } else { painter->setPen(pal.pen(graph::Palette::PinOutgoingBorder)); pinPath.moveTo(rect.left() + rect.width() / 2.0,rect.top()); pinPath.lineTo(rect.topRight()); pinPath.lineTo(rect.bottomRight()); pinPath.lineTo(rect.left() + rect.width() / 2.0,rect.bottom()); pinPath.arcTo(rect,270.0,-180.0); pinPath.closeSubpath(); painter->setBrush(pal.brush(graph::Palette::PinOutgoingFill)); painter->drawPath(pinPath); } break; } case graph::Defines::RightToLeft: { QPainterPath pinPath; if (pin().direction() == graph::Defines::Incoming) { painter->setPen(pal.pen(graph::Palette::PinIncomingBorder)); pinPath.moveTo(rect.left() + rect.width() / 2.0,rect.top()); pinPath.lineTo(rect.topRight()); pinPath.lineTo(rect.bottomRight()); pinPath.lineTo(rect.left() + rect.width() / 2.0,rect.bottom()); pinPath.arcTo(rect,270.0,-180.0); pinPath.closeSubpath(); painter->setBrush(pal.brush(graph::Palette::PinIncomingFill)); painter->drawPath(pinPath); } else { painter->setPen(pal.pen(graph::Palette::PinOutgoingBorder)); pinPath.moveTo(rect.left() + rect.width() / 2.0,rect.top()); pinPath.lineTo(rect.topLeft()); pinPath.lineTo(rect.bottomLeft()); pinPath.lineTo(rect.left() + rect.width() / 2.0,rect.bottom()); pinPath.arcTo(rect,270.0,180.0); pinPath.closeSubpath(); painter->setBrush(pal.brush(graph::Palette::PinOutgoingFill)); painter->drawPath(pinPath); } break; } } }
QPainterPath ZigZagWipeStrategy::clipPath(int step, const QRect &area) { const int zigZagCount = 10; const qreal zigZagHeight = area.height() / static_cast<qreal>(zigZagCount); const qreal zigZagWidth = area.width() / static_cast<qreal>(zigZagCount); qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount); if(reverse()) percent = static_cast<qreal>(StepCount-step) / static_cast<qreal>(StepCount); int stepx = static_cast<int>((area.width() + 2*zigZagWidth) * percent); int stepy = static_cast<int>((area.height() + 2*zigZagHeight) * percent); qreal zigZagHeight_2 = 0.5 * zigZagHeight; qreal zigZagWidth_2 = 0.5 * zigZagWidth; QPainterPath path; switch(subType()) { case ZigZagWipeEffectFactory::FromTop: case ZigZagWipeEffectFactory::FromBottom: { qreal zigZagBase = stepy - zigZagHeight; qreal zigZagTip = stepy; path.moveTo(area.topLeft() - QPointF(0, zigZagHeight)); path.lineTo(QPointF(area.left(), zigZagBase)); for(int i = 0; i < zigZagCount; ++i) { path.lineTo(area.topLeft() + QPointF((2*i+1) * zigZagWidth_2, zigZagTip)); path.lineTo(area.topLeft() + QPointF((i+1) * zigZagWidth, zigZagBase)); } path.lineTo(area.topRight() - QPointF(0, zigZagHeight)); break; } case ZigZagWipeEffectFactory::FromLeft: case ZigZagWipeEffectFactory::FromRight: { qreal zigZagBase = stepx - zigZagWidth; qreal zigZagTip = stepx; path.moveTo(area.topLeft() - QPointF(zigZagWidth, 0)); path.lineTo(QPointF(zigZagBase, area.top())); for(int i = 0; i < zigZagCount; ++i) { path.lineTo(area.topLeft() + QPointF(zigZagTip, (2*i+1) * zigZagHeight_2)); path.lineTo(area.topLeft() + QPointF(zigZagBase, (i+1) * zigZagHeight)); } path.lineTo(area.bottomLeft() - QPointF(zigZagWidth, 0)); break; } default: return QPainterPath(); } path.closeSubpath(); if(reverse()) { QPainterPath areaPath; areaPath.addRect(area); path = areaPath.subtracted(path); } return path; }
//! [1] Window::Window() { QPainterPath rectPath; rectPath.moveTo(20.0, 30.0); rectPath.lineTo(80.0, 30.0); rectPath.lineTo(80.0, 70.0); rectPath.lineTo(20.0, 70.0); rectPath.closeSubpath(); //! [1] //! [2] QPainterPath roundRectPath; roundRectPath.moveTo(80.0, 35.0); roundRectPath.arcTo(70.0, 30.0, 10.0, 10.0, 0.0, 90.0); roundRectPath.lineTo(25.0, 30.0); roundRectPath.arcTo(20.0, 30.0, 10.0, 10.0, 90.0, 90.0); roundRectPath.lineTo(20.0, 65.0); roundRectPath.arcTo(20.0, 60.0, 10.0, 10.0, 180.0, 90.0); roundRectPath.lineTo(75.0, 70.0); roundRectPath.arcTo(70.0, 60.0, 10.0, 10.0, 270.0, 90.0); roundRectPath.closeSubpath(); //! [2] //! [3] QPainterPath ellipsePath; ellipsePath.moveTo(80.0, 50.0); ellipsePath.arcTo(20.0, 30.0, 60.0, 40.0, 0.0, 360.0); //! [3] //! [4] QPainterPath piePath; piePath.moveTo(50.0, 50.0); piePath.arcTo(20.0, 30.0, 60.0, 40.0, 60.0, 240.0); piePath.closeSubpath(); //! [4] //! [5] QPainterPath polygonPath; polygonPath.moveTo(10.0, 80.0); polygonPath.lineTo(20.0, 10.0); polygonPath.lineTo(80.0, 30.0); polygonPath.lineTo(90.0, 70.0); polygonPath.closeSubpath(); //! [5] //! [6] QPainterPath groupPath; groupPath.moveTo(60.0, 40.0); groupPath.arcTo(20.0, 20.0, 40.0, 40.0, 0.0, 360.0); groupPath.moveTo(40.0, 40.0); groupPath.lineTo(40.0, 80.0); groupPath.lineTo(80.0, 80.0); groupPath.lineTo(80.0, 40.0); groupPath.closeSubpath(); //! [6] //! [7] QPainterPath textPath; QFont timesFont("Times", 50); timesFont.setStyleStrategy(QFont::ForceOutline); textPath.addText(10, 70, timesFont, tr("Qt")); //! [7] //! [8] QPainterPath bezierPath; bezierPath.moveTo(20, 30); bezierPath.cubicTo(80, 0, 50, 50, 80, 80); //! [8] //! [9] QPainterPath starPath; starPath.moveTo(90, 50); for (int i = 1; i < 5; ++i) { starPath.lineTo(50 + 40 * cos(0.8 * i * Pi), 50 + 40 * sin(0.8 * i * Pi)); } starPath.closeSubpath(); //! [9] //! [10] #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) renderAreas.push_back(new RenderArea(rectPath)); renderAreas.push_back(new RenderArea(roundRectPath)); renderAreas.push_back(new RenderArea(ellipsePath)); renderAreas.push_back(new RenderArea(piePath)); renderAreas.push_back(new RenderArea(polygonPath)); renderAreas.push_back(new RenderArea(groupPath)); #endif renderAreas.push_back(new RenderArea(textPath)); renderAreas.push_back(new RenderArea(bezierPath)); renderAreas.push_back(new RenderArea(starPath)); //! [10] //! [11] fillRuleComboBox = new QComboBox; fillRuleComboBox->addItem(tr("Odd Even"), Qt::OddEvenFill); fillRuleComboBox->addItem(tr("Winding"), Qt::WindingFill); fillRuleLabel = new QLabel(tr("Fill &Rule:")); fillRuleLabel->setBuddy(fillRuleComboBox); //! [11] //! [12] fillColor1ComboBox = new QComboBox; populateWithColors(fillColor1ComboBox); fillColor1ComboBox->setCurrentIndex( fillColor1ComboBox->findText("mediumslateblue")); fillColor2ComboBox = new QComboBox; populateWithColors(fillColor2ComboBox); fillColor2ComboBox->setCurrentIndex( fillColor2ComboBox->findText("cornsilk")); fillGradientLabel = new QLabel(tr("&Fill Gradient:")); fillGradientLabel->setBuddy(fillColor1ComboBox); fillToLabel = new QLabel(tr("to")); fillToLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); penWidthSpinBox = new QSpinBox; penWidthSpinBox->setRange(0, 20); penWidthLabel = new QLabel(tr("&Pen Width:")); penWidthLabel->setBuddy(penWidthSpinBox); penColorComboBox = new QComboBox; populateWithColors(penColorComboBox); penColorComboBox->setCurrentIndex( penColorComboBox->findText("darkslateblue")); penColorLabel = new QLabel(tr("Pen &Color:")); penColorLabel->setBuddy(penColorComboBox); rotationAngleSpinBox = new QSpinBox; rotationAngleSpinBox->setRange(0, 359); rotationAngleSpinBox->setWrapping(true); rotationAngleSpinBox->setSuffix("\xB0"); rotationAngleLabel = new QLabel(tr("&Rotation Angle:")); rotationAngleLabel->setBuddy(rotationAngleSpinBox); //! [12] //! [16] connect(fillRuleComboBox, SIGNAL(activated(int)), this, SLOT(fillRuleChanged())); connect(fillColor1ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); connect(fillColor2ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); connect(penColorComboBox, SIGNAL(activated(int)), this, SLOT(penColorChanged())); for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) { connect(penWidthSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setPenWidth(int))); connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setRotationAngle(int))); } //! [16] //! [17] QGridLayout *topLayout = new QGridLayout; #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) topLayout->setSizeConstraint(QLayout::SetNoConstraint); #endif int i=0; for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++, i++) topLayout->addWidget(*it, i / 3, i % 3); QGridLayout *mainLayout = new QGridLayout; #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) mainLayout->setSizeConstraint(QLayout::SetNoConstraint); #endif mainLayout->addLayout(topLayout, 0, 0, 1, 4); mainLayout->addWidget(fillRuleLabel, 1, 0); mainLayout->addWidget(fillRuleComboBox, 1, 1, 1, 3); mainLayout->addWidget(fillGradientLabel, 2, 0); mainLayout->addWidget(fillColor1ComboBox, 2, 1); mainLayout->addWidget(fillToLabel, 2, 2); mainLayout->addWidget(fillColor2ComboBox, 2, 3); mainLayout->addWidget(penWidthLabel, 3, 0); mainLayout->addWidget(penWidthSpinBox, 3, 1, 1, 3); mainLayout->addWidget(penColorLabel, 4, 0); mainLayout->addWidget(penColorComboBox, 4, 1, 1, 3); #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) mainLayout->addWidget(rotationAngleLabel, 5, 0); mainLayout->addWidget(rotationAngleSpinBox, 5, 1, 1, 3); #endif setLayout(mainLayout); //! [17] //! [18] fillRuleChanged(); fillGradientChanged(); penColorChanged(); penWidthSpinBox->setValue(2); setWindowTitle(tr("Painter Paths")); }