void LivewireCalculator::DrawTrace(uint x, uint y, QPainter &g) const { const uint w = this->_weights->GetReducedWidth(), scale = this->_weights->GetScale(), s2 = scale / 2; if (this->_visited.Get(x /= scale, y /= scale)) // The endpoint has been solved, so we can actually draw the livewire { // Get every point from end to start by looping through the trace data QVector<QPoint> pts; uint I = x + y * w; do { QPoint p = QPoint((x = I % w) * scale + s2, (y = I / w) * scale + s2); pts.push_back(p); pts.push_back(p); } while ((I = this->_trace.Get(x, y)) != UINT_MAX); // Draw the points if (pts.size() >= 4) { pts.pop_back(); pts.pop_front(); g.drawLines(pts); } } }
void VpGrid::drawCrossGrid(GridGC &gridGC) { int x,y; VpGC *vpgc = gridGC.m_gc; QPainter *gc = vpgc->getGC(); // Assuming QPainter has already established begin(). gc->setRenderHint(QPainter::Antialiasing, true); // Set the pen. QPen pen; pen.setColor(m_color); pen.setStyle(Qt::SolidLine); gc->setPen(pen); // Create a cross Marker. QLine cross[2]; for (int i = 0; i < gridGC.m_ynum + 1; i++) { y = gridGC.m_yll + (i * gridGC.m_dy); for (int j = 0; j < gridGC.m_xnum; j++) { x = gridGC.m_xll + (j * gridGC.m_dx); cross[0].setLine(x-1, y, x+1, y); cross[1].setLine(x, y-1, x, y+1); gc->drawLines(cross, 2); } } // Flush graphics to display. //gc.flush(); //delete gc; }
void VpGrid::drawReference(GridGC &gridGC) { int x,y; VpGC *vpgc = gridGC.m_gc; QPainter *gc = vpgc->getGC(); // Assuming QPainter has already established begin(). gc->setRenderHint(QPainter::Antialiasing, true); if (m_referenceStyle == VpGrid::REFSTYLE_SQUARE) { // Set the pen. QPen pen; pen.setStyle(Qt::NoPen); gc->setPen(pen); // Set the brush. QBrush brush; brush.setColor(m_referenceColor); brush.setStyle(Qt::SolidPattern); gc->setBrush(brush); QRectF origin; origin.setLeft(-1.5 + m_xAlignment); origin.setRight(1.5 + m_xAlignment); origin.setBottom(-1.5 + m_yAlignment); origin.setTop(1.5 + m_yAlignment); gc->drawRect(origin); } else if (m_referenceStyle == VpGrid::REFSTYLE_CIRCLE) { // Set the pen. QPen pen; pen.setStyle(Qt::NoPen); gc->setPen(pen); // Set the brush. QBrush brush; brush.setColor(m_referenceColor); brush.setStyle(Qt::SolidPattern); gc->setBrush(brush); gc->drawEllipse(QPoint(m_xAlignment, m_yAlignment), 2, 2); } else { // Set the pen, no brush. QPen pen; pen.setColor(m_referenceColor); pen.setStyle(Qt::SolidLine); pen.setWidth(2); gc->setPen(pen); // Create a 'X' pattern. QLineF cross[2]; cross[0].setLine(-1.5 + m_xAlignment, -1.5 + m_yAlignment, 1.5 + m_xAlignment, 1.5 + m_yAlignment); cross[1].setLine(-1.5 + m_xAlignment, 1.5 + m_yAlignment, 1.5 + m_xAlignment, -1.5 + m_yAlignment); gc->drawLines(cross, 2); } //delete gc; }
int drv_painter(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9) { handle_head* head = (handle_head*)a0; QPainter *self = (QPainter*)head->native; switch (drvid) { case PAINTER_INIT: { drvNewHead(a0,new QPainter); break; } case PAINTER_DESTROY: { drvDelObj(a0,self); break; } case PAINTER_BEGIN: { self->begin(drvGetWidget(a1)); break; } case PAINTER_END: { self->end(); break; } case PAINTER_SETFONT: { self->setFont(drvGetFont(a1)); break; } case PAINTER_FONT: { drvSetFont(a1,self->font()); break; } case PAINTER_DRAWPOINT: { self->drawPoint(drvGetPoint(a1)); break; } case PAINTER_DRAWLINE: { self->drawLine(drvGetPoint(a1),drvGetPoint(a2)); break; } case PAINTER_DRAWLINES: { self->drawLines(drvGetPoints(a1)); break; } case PAINTER_DRAWPOLYLINE: { self->drawPolyline(drvGetPoints(a1)); break; } case PAINTER_DRAWTEXT: { self->drawText(drvGetPoint(a1),drvGetString(a2)); break; } default: return 0; } return 1; }
void FlowWidget::paintEvent(QPaintEvent *event) { QPainter *painter = new QPainter(this); painter->setPen(QPen(Qt::black, 2)); //重画所有箭头组 for (int i = 0; i < numLine; i++){ painter->drawLines(lines[i], 4); } //画实时显示的箭头 painter->drawLines(lineShow, 4); if (clearFlag == 1) //如果有清除画线命令传来 { numLine = 0; memset(lines, 0,sizeof(lines));//清空画线组 clearFlag = 0; } }
/*! \fn TitleBar::draw_close_btn() */ void TitleBar::draw_close_btn() { //draw close button int ih1 = 13; int iw1 = 30; QPainter painter; QPen pen; QLinearGradient gradient1(0, ih1, 0, 0); gradient1.setColorAt(0, QColor::fromRgb(131, 3, 3)); rightPm = QPixmap(iw1, ih1); painter.begin(&rightPm); if(bpress) { gradient1.setColorAt(1, QColor::fromRgb(237, 26, 86)); painter.fillRect(0, 0, iw1, ih1, QBrush(gradient1)); //draw frame close button painter.setPen(QColor(0,0,0)); painter.drawLine(0,0,iw1,0); painter.drawLine(0,ih1,0,0); painter.drawLine(0, ih1-1, iw1,ih1-1); pen.setColor(QColor(83,31,31)); } else { gradient1.setColorAt(1, QColor::fromRgb(243, 115, 115)); painter.fillRect(0, 0, iw1, ih1, QBrush(gradient1)); //draw frame close button painter.setPen(QColor(66,67,70)); painter.drawLine(0,0,iw1,0); painter.setPen(QColor(71,71,74)); painter.drawLine(0,ih1,0,0); painter.setPen(QColor(88,88,90)); painter.drawLine(0, ih1-1, iw1,ih1-1); pen.setColor(QColor(255,255,255)); } //draw line close button painter.setPen(pen); QVector<QLine> lines; lines << QLine(iw1-16,ih1-10,iw1-11,ih1-5) << QLine(iw1-11,ih1-10,iw1-16,ih1-5); painter.drawLines(lines); update(); painter.end(); }
void LogicSignal::paint_caps(QPainter &p, QLineF *const lines, vector< pair<int64_t, bool> > &edges, bool level, double samples_per_pixel, double pixels_offset, float x_offset, float y_offset) { QLineF *line = lines; for (auto i = edges.begin(); i != (edges.end() - 1); i++) if ((*i).second == level) { *line++ = QLineF( ((*i).first / samples_per_pixel - pixels_offset) + x_offset, y_offset, ((*(i+1)).first / samples_per_pixel - pixels_offset) + x_offset, y_offset); } p.drawLines(lines, line - lines); }
void ReRulerWidget::DrawMarks( QPainter& _painter ) { // For horizontal ruler: // Draw the mark just left to or on the viewport position, even if // it's hidden. This hidden mark would be clipped by Qt, but would // be visually correct if the mark is thicker than one pixel. // For vertical ruler: // The above applies. QVector< QPoint > markerList; int markIndex = m_viewport / m_unit; int pos = -m_viewport % m_unit; int limit = IsHorizontal() ? width() : height(); while( pos < limit ) { bool isShortMark = ( 0 == ( markIndex % m_longMarkDivision ) ? false : true ); if( IsMarkOnSizeA() ) { markerList.push_back( IsHorizontal() ? QPoint( pos, m_rulerHeight ) : QPoint( m_rulerHeight, pos ) ); markerList.push_back( IsHorizontal() ? QPoint( pos, m_rulerHeight - ( isShortMark ? gsShortMarkLength : gsLongMarkLength ) ) : QPoint( m_rulerHeight - ( isShortMark ? gsShortMarkLength : gsLongMarkLength ), pos ) ); } else { markerList.push_back( IsHorizontal() ? QPoint( pos, 0 ) : QPoint( 0, pos ) ); markerList.push_back( IsHorizontal() ? QPoint( pos, isShortMark ? gsShortMarkLength : gsLongMarkLength ) : QPoint( isShortMark ? gsShortMarkLength : gsLongMarkLength, pos ) ); } // Advance to the next mark. pos += m_unit; ++markIndex; } _painter.setPen( QColor( 250, 250, 250 ) ); _painter.drawLines( markerList ); }
void UmlCanvas::drawBackground(QPainter& painter, const QRect& clip) { if (show_grid()) { int s = grid_size(); qreal left = int(clip.left())-(int(clip.left()) % s); qreal top = int(clip.top())-(int(clip.top()) % s); QVarLengthArray<QLineF, 100> lines; for (qreal x = left; x < clip.right(); x += s) lines.append(QLineF(x, clip.top(), x, clip.bottom())); for (qreal y = top; y < clip.bottom(); y += s) lines.append(QLineF(clip.left(), y, clip.right(), y)); painter.save(); painter.setPen(Qt::lightGray); painter.drawLines(lines.data(), lines.size()); painter.restore(); } }
void KateRenderer::paintNonBreakSpace(QPainter &paint, qreal x, qreal y) { QPen penBackup( paint.pen() ); QPen pen( config()->tabMarkerColor() ); pen.setWidthF(qMax(1.0, spaceWidth() / 10.0)); paint.setPen( pen ); paint.setRenderHint(QPainter::Antialiasing, false); const int height = fontHeight(); const int width = spaceWidth(); QPoint points[6]; points[0] = QPoint(x+width/10, y+height/4); points[1] = QPoint(x+width/10, y+height/3); points[2] = QPoint(x+width/10, y+height/3); points[3] = QPoint(x+width-width/10, y+height/3); points[4] = QPoint(x+width-width/10, y+height/3); points[5] = QPoint(x+width-width/10, y+height/4); paint.drawLines(points, 3); paint.setPen( penBackup ); }
void WTextSourceViewerLine::drawFoldingLineVisible(QPainter &p,const QPointF &p1,const QPointF &p2) { QPolygonF area; float demi_char_space=char_space/2.0f; QPointF pos(0.0f,(p1.y()+p2.y())/2.0f-demi_char_space); QRectF text_pos(pos,QSizeF(char_space,char_space)); QPointF p3(demi_char_space,p2.y()); QRectF endPoint2(p2.x()-2,p2.y()-2,4,4); QBrush b=p.brush(); p.setBrush(Qt::black); if (p1!=p2) { QPointF p0(demi_char_space,p1.y()); QPointF p1b(demi_char_space,pos.y()); QPointF p2b(demi_char_space,pos.y()+char_space); QRectF endPoint1(p1.x()-2,p1.y()-2,4,4); area << p0 << p1 ; area << p0 << p1b ; area << p2b << p3 ; area << p3 << p2 ; p.drawEllipse(endPoint1); } else { QPointF p1c(char_space,p2.y()); area << p1c << p2 ; } p.drawEllipse(endPoint2); p.setBrush(b); p.drawLines(area); float pos_size=char_space; QRectF rectangle(pos.x(),pos.y(),pos_size,pos_size); p.drawRoundRect(rectangle); float _x1=pos.x()+3.0f; float _y=pos.y()+pos_size/2.0f; float _x2=pos.x()+pos_size-3.0f; p.drawLine(QPointF(_x1,_y),QPointF(_x2,_y)); }
int BC_GEN::encode(const QString& input){ if(input.size() < LEAST_CHAR){ bc_pix->fill(); update(); return -4;//too short } code=input; encode_buf->clear();//clean these chksum=0; global_Xposition=start_Xposition-INTER_GAP_LEN;//init position global_Yposition=start_Yposition; int width=lenth_calc(input.size()+ADD_CODE_LEN);//calc width global_height=width*RATIO_H_W;//barcode height setMinimumSize(width+2*start_Xposition,global_height+2*start_Yposition); resize(minimumSize()); //code39 start if(insertbuf(QChar('*'))!=1) return -5;//start character for(int i=0; i< input.size(); ++i){ if(insertbuf(input.at(i))!=1) return -5; } if(insertbuf(code39_table[chksum%CODE39_SIZE])!=1) return -5;//chksum if(insertbuf(QChar('*'))!=1) return -5;//end character delete bc_pix;//begin to draw barcode bc_pix = new QPixmap(width+2*start_Xposition,global_height+2*start_Yposition);//init bc_pix bc_pix->fill(); QPainter p;//draw barcode p.begin(bc_pix); p.drawLines(*encode_buf); p.end(); update();//update display return 1;//successfully }
void LogicSignal::paint_caps(QPainter &p, QLineF *const lines, vector< pair<uint64_t, bool> > &edges, bool level, double samples_per_pixel, double pixels_offset, float x_offset, float y_offset) { QLineF *line = lines; uint64_t curX = 0; uint64_t nxtX = 0; for (vector<pv::data::LogicSnapshot::EdgePair>::const_iterator i = edges.begin(); i != (edges.end() - 1); i++) if ((*i).second == level) { curX = ((*i).first / samples_per_pixel - pixels_offset) + x_offset; nxtX = ((*(i+1)).first / samples_per_pixel - pixels_offset) + x_offset; if (nxtX > curX) *line++ = QLineF(curX, y_offset, nxtX, y_offset); } p.drawLines(lines, line - lines); }
void KateRenderer::paintTabstop(QPainter &paint, qreal x, qreal y) { QPen penBackup( paint.pen() ); QPen pen( config()->tabMarkerColor() ); pen.setWidthF(qMax(1.0, spaceWidth() / 10.0)); paint.setPen( pen ); paint.setRenderHint(QPainter::Antialiasing, false); int dist = spaceWidth() * 0.3; QPoint points[8]; points[0] = QPoint(x - dist, y - dist); points[1] = QPoint(x, y); points[2] = QPoint(x, y); points[3] = QPoint(x - dist, y + dist); x += spaceWidth() / 3.0; points[4] = QPoint(x - dist, y - dist); points[5] = QPoint(x, y); points[6] = QPoint(x, y); points[7] = QPoint(x - dist, y + dist); paint.drawLines(points, 4); paint.setPen( penBackup ); }
void Thumbnail::paintOverImage( QPainter& painter, QTransform const& image_to_display, QTransform const& thumb_to_display) { painter.setRenderHint(QPainter::Antialiasing, false); QPen pen(QColor(0, 0, 255, 70)); pen.setWidth(1); pen.setCosmetic(true); painter.setPen(pen); QRectF const bounding_rect(boundingRect()); double const cell_size = 8; double const left = bounding_rect.left(); double const right = bounding_rect.right(); double const top = bounding_rect.top(); double const bottom = bounding_rect.bottom(); double const w = bounding_rect.width(); double const h = bounding_rect.height(); QPointF const center(bounding_rect.center()); QVector<QLineF> lines; for (double y = center.y(); y > 0.0; y -= cell_size) { lines.push_back(QLineF(left, y, right, y)); } for (double y = center.y(); (y += cell_size) < h;) { lines.push_back(QLineF(left, y, right, y)); } for (double x = center.x(); x > 0.0; x -= cell_size) { lines.push_back(QLineF(x, top, x, bottom)); } for (double x = center.x(); (x += cell_size) < w;) { lines.push_back(QLineF(x, top, x, bottom)); } painter.drawLines(lines); }
void TikzEditor::paintTabstop(QPainter &painter, qreal x, qreal y) { QPen penBackup(painter.pen()); QPen pen(m_tabulatorsColor); pen.setWidthF(qMax(0.5, spaceWidth() * .1)); pen.setCapStyle(Qt::RoundCap); painter.setPen(pen); // FIXME: optimize for speed! qreal dist = spaceWidth() * 0.3; QPointF points[8]; points[0] = QPointF(x - dist, y - dist); points[1] = QPointF(x, y); points[2] = QPointF(x, y); points[3] = QPointF(x - dist, y + dist); x += spaceWidth() / 3.0; points[4] = QPointF(x - dist, y - dist); points[5] = QPointF(x, y); points[6] = QPointF(x, y); points[7] = QPointF(x - dist, y + dist); painter.drawLines(points, 4); painter.setPen(penBackup); }
void plotLinesToPainter(QPainter& painter, const Numpy1DObj& x1, const Numpy1DObj& y1, const Numpy1DObj& x2, const Numpy1DObj& y2, const QRectF* clip, bool autoexpand) { const int maxsize = min(x1.dim, x2.dim, y1.dim, y2.dim); // if autoexpand, expand rectangle by line width QRectF clipcopy; if ( clip != 0 && autoexpand ) { const qreal lw = painter.pen().widthF(); qreal x1, y1, x2, y2; clip->getCoords(&x1, &y1, &x2, &y2); clipcopy.setCoords(x1, y1, x2, y2); clipcopy.adjust(-lw, -lw, lw, lw); } if( maxsize != 0 ) { QVector<QLineF> lines; for(int i = 0; i < maxsize; ++i) { QPointF pt1(x1(i), y1(i)); QPointF pt2(x2(i), y2(i)); if( clip != 0 ) { if( clipLine(clipcopy, pt1, pt2) ) lines << QLineF(pt1, pt2); } else lines << QLineF(pt1, pt2); } painter.drawLines(lines); } }
void Text::draw(QPainter& p,const QRect& r,const QString& text,unsigned long attr) { p.fillRect(r,widget()->bgColor(attr)); p.setFont(widget()->font(attr)); if(isLdc(text.at(0))) { p.setPen(QPen(widget()->fgColor(attr),(attr&ATTR_BOLD)?2:1)); LDC key; QMetaEnum me=metaObject()->enumerator(metaObject()->indexOfEnumerator("LDC")); for(int i=2;i<me.keyCount();++i) { if(text.at(0).unicode()<me.value(i)) { key=(LDC)me.value(i-1); break; } } if(text.at(0).unicode()==end) { key=lhlv; } const QPolygon& polygon=_ldcMap.value(key); for(int j=0;j<text.size();++j) { p.drawLines(polygon.translated(r.topLeft().x()+j*_fontSize.x(),r.topLeft().y())); } } else { p.setPen(widget()->fgColor(attr)); QFontMetrics fm(widget()->font(attr)); QRect br=fm.boundingRect(text); p.drawText(r.x(),r.y()-br.y(),text); } }
//-------------------------------------------------------------------------------------------- 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 ColorPalette::drawPannel(QPainter &painter, int m, int n, float dt, float *ts, float fdt) { painter.save(); QPen pen; pen.setColor(QColor(255,255,255)); pen.setWidthF(0.01); painter.setPen(pen); float x = draw_erae_.left(); float y = draw_erae_.top(); float diff = draw_erae_.height()/1020; float l_x = draw_erae_.left() + draw_erae_.width() - 40; float l_y = draw_erae_.bottom(); QRgb srgb = QRgb(0x660000); int sred = qRed(srgb); QRgb ergb = QRgb(0xff0000); int ered = qRed(ergb); int k = 0; while(k<1020) { QRectF rect = QRectF(draw_erae_.left(),draw_erae_.top() + k*diff,draw_erae_.width() - 40,diff); painter.drawRect(rect); if (k<153) { painter.fillRect(rect,QBrush(QColor(sred + k,0,0))); } else if (k < 408 && k >= 153) { painter.fillRect(rect,QBrush(QColor(255,k - 153,0))); } else if ( k < 663 && k >= 408) { painter.fillRect(rect,QBrush(QColor(255 - (k - 408),255,0))); } else if (k < 918 && k>= 663) { painter.fillRect(rect,QBrush(QColor(0,255 - (k - 663),k - 663))); } else { painter.fillRect(rect,QBrush(QColor(0,0,255- (k - 918)))); } k++; } // for(int i=0;i<58;i++) // { // QRectF colorrect = QRectF(draw_erae_.left(),draw_erae_.top() + i*diff,draw_erae_.width(),diff); // painter.drawRect(colorrect); // painter.fillRect(colorrect,QColor(color[i])); // } float max = ts[0]; float min = ts[0]; for (int i=0;i<n*m;i++) { float temp = ts[i]; if (temp - max > 0) { max = temp; } if ( temp - min < 0) { min = temp; } } max_ = max; min_ = min; float dx = (l_y - y)/6; QLineF line[5]; pen.setColor(QColor(0,0,0)); pen.setWidth(XCOORDINATERULERWIDTH); painter.setFont(QFont(QObject::tr("WenQuanYi"),6)); painter.setPen(pen); float dp = max_ - min_; QString strs_max; strs_max.sprintf("%e",max_); strs_max = strs_max.left(3); int show_max = (int)(strs_max.toFloat() + 0.5); float fdp = (float)(show_max)/5; QString strs_; strs_.sprintf("%e",max_); strs_ = strs_.right((strs_.length() - 1) - strs_.lastIndexOf('e')); QRectF index = QRectF(l_x + 2,y + 10,18,8); painter.drawText(index,"x10"); QRectF po = QRectF(index.right() - 1,index.top() - 8,20,8); painter.drawText(po,strs_); for (int k=0;k<5;k++) { line[k].setP1(QPointF(l_x,y + (k + 1)*dx)); line[k].setP2(QPointF(l_x + 8,y+ (k + 1)*dx)); QRectF rect = QRectF(l_x + 8,y + (k + 1)*dx - 4,100,8); QString str; str.sprintf("%0.1f",show_max - fdp*k); //截取字符串 //str = str.left(3); painter.drawText(rect,str); } painter.drawLines(line,5); painter.restore(); }
void ImageView::onPaint(QPainter& painter, InteractionState const& interaction) { painter.setWorldMatrixEnabled(false); painter.setRenderHints(QPainter::Antialiasing, false); double const w = maxViewportRect().width(); double const h = maxViewportRect().height(); QPointF const center(getImageRotationOrigin()); // Draw the semi-transparent grid. QPen pen(QColor(0, 0, 255, 90)); pen.setCosmetic(true); pen.setWidth(1); painter.setPen(pen); QVector<QLineF> lines; for (double y = center.y(); (y -= m_cellSize) > 0.0;) { lines.push_back(QLineF(0.5, y, w - 0.5, y)); } for (double y = center.y(); (y += m_cellSize) < h;) { lines.push_back(QLineF(0.5, y, w - 0.5, y)); } for (double x = center.x(); (x -= m_cellSize) > 0.0;) { lines.push_back(QLineF(x, 0.5, x, h - 0.5)); } for (double x = center.x(); (x += m_cellSize) < w;) { lines.push_back(QLineF(x, 0.5, x, h - 0.5)); } painter.drawLines(lines); // Draw the horizontal and vertical line crossing at the center. pen.setColor(QColor(0, 0, 255)); painter.setPen(pen); painter.setBrush(Qt::NoBrush); painter.drawLine( QPointF(0.5, center.y()), QPointF(w - 0.5, center.y()) ); painter.drawLine( QPointF(center.x(), 0.5), QPointF(center.x(), h - 0.5) ); // Draw the rotation arcs. // Those will look like this ( ) QRectF const arc_square(getRotationArcSquare()); painter.setRenderHints(QPainter::Antialiasing, true); pen.setWidthF(1.5); painter.setPen(pen); painter.setBrush(Qt::NoBrush); painter.drawArc( arc_square, qRound(16 * -m_maxRotationDeg), qRound(16 * 2 * m_maxRotationDeg) ); painter.drawArc( arc_square, qRound(16 * (180 - m_maxRotationDeg)), qRound(16 * 2 * m_maxRotationDeg) ); std::pair<QPointF, QPointF> const handles( getRotationHandles(arc_square) ); QRectF rect(m_handlePixmap.rect()); rect.moveCenter(handles.first); painter.drawPixmap(rect.topLeft(), m_handlePixmap); rect.moveCenter(handles.second); painter.drawPixmap(rect.topLeft(), m_handlePixmap); }
void ColorPalette::draw3DPannel(QPainter &painter) { QPen pen; pen.setColor(QColor(255,255,255)); pen.setWidthF(0.01); painter.setPen(pen); float x = draw_erae_.left(); float y = draw_erae_.top(); float diff = draw_erae_.height()/1020; float l_x = draw_erae_.right(); float l_y = draw_erae_.bottom(); QRgb srgb = QRgb(0x660000); int sred = qRed(srgb); QRgb ergb = QRgb(0xff0000); int ered = qRed(ergb); int k = 0; while(k<1020) { QRectF rect = QRectF(draw_erae_.left(),draw_erae_.top() + k*diff,draw_erae_.width() - 40,diff); painter.drawRect(rect); if (k<153) { painter.fillRect(rect,QBrush(QColor(sred + k,0,0).toHsv())); } else if (k < 408 && k >= 153) { painter.fillRect(rect,QBrush(QColor(255,k - 153,0).toHsv())); } else if ( k < 663 && k >= 408) { painter.fillRect(rect,QBrush(QColor(255 - (k - 408),255,0).toHsv())); } else if (k < 918 && k>= 663) { painter.fillRect(rect,QBrush(QColor(0,255 - (k - 663),k - 663).toHsv())); } else { painter.fillRect(rect,QBrush(QColor(0,0,255- (k - 918)).toHsv())); } k++; } float temp = (point3ddeepmax_ - point3ddeepmin_) / 9; float colordiff = draw_erae_.height() / 9; QLineF line[10]; pen.setColor(QColor(0,0,0)); pen.setWidth(XCOORDINATERULERWIDTH); painter.setFont(QFont(QObject::tr("WenQuanYi"),6)); painter.setPen(pen); int num = point3ddeepmax_; for (int i = 0;i<10;i++) { line[i].setP1(QPointF(draw_erae_.left(),draw_erae_.top()+(i)*colordiff)); line[i].setP2(QPointF(draw_erae_.right() -40,draw_erae_.top() + (i)*colordiff)); QString deep = QString::number(num); float width = painter.fontMetrics().width(deep); float height = painter.fontMetrics().height(); QRectF rect; if (i == 0) { rect = QRectF(draw_erae_.right() -35,draw_erae_.top() + colordiff*(i),width,height + 5); } else if (i == 9) { rect = QRectF(draw_erae_.right() -35,draw_erae_.top()-10 + colordiff*(i),width,height + 5); } else { rect = QRectF(draw_erae_.right() -35,draw_erae_.top()-5 + colordiff*(i),width,height + 5); } painter.drawText(rect,deep); num = point3ddeepmax_ - (i+1)*temp; } painter.drawLines(line,10); }
void DrawWidget::drawChannelFilled(Channel *ch, QPainter &p, double leftTime, double currentTime, double zoomX, double viewBottom, double zoomY, int viewType) { ZoomLookup *z; if(viewType == DRAW_VIEW_SUMMARY) z = &ch->summaryZoomLookup; else z = &ch->normalZoomLookup; ChannelLocker channelLocker(ch); QColor current = ch->color; QColor invert(255 - current.red(), 255 - current.green(), 255 - current.blue()); p.setPen(current); int viewBottomOffset = toInt(viewBottom / zoomY); viewBottom = double(viewBottomOffset) * zoomY; // baseX is the no. of chunks a pixel must represent. double baseX = zoomX / ch->timePerChunk(); z->setZoomLevel(baseX); double currentChunk = ch->chunkFractionAtTime(currentTime); double leftFrameTime = currentChunk - ((currentTime - leftTime) / ch->timePerChunk()); //double leftFrameTime = leftTime / ch->timePerChunk(); double frameTime = leftFrameTime; //if(frameTime < 0.0) frameTime = 0.0; int n = 0; int baseElement = int(floor(frameTime / baseX)); if(baseElement < 0) { n -= baseElement; baseElement = 0; } int lastBaseElement = int(floor(double(ch->totalChunks()) / baseX)); int firstN = n; int lastN = firstN; //QPointArray pointArray(width()*2); //QPointArray topPoints(width()*2); /* Q3PointArray bottomPoints(width()*2); Q3PointArray evenMidPoints(width()*2); Q3PointArray oddMidPoints(width()*2); Q3PointArray evenMidPoints2(width()*2); Q3PointArray oddMidPoints2(width()*2);*/ QPolygon bottomPoints(width()*2); QPolygon evenMidPoints(width()*2); QPolygon oddMidPoints(width()*2); QPolygon evenMidPoints2(width()*2); QPolygon oddMidPoints2(width()*2); std::vector<QRect> noteRect(width()*2); std::vector<QRect> noteRect2(width()*2); std::vector<bool> isNoteRectEven(width()*2); //int pointIndex = 0; int pointIndex = 0; int evenMidPointIndex = 0; int oddMidPointIndex = 0; int evenMidPointIndex2 = 0; int oddMidPointIndex2 = 0; int rectIndex = 0; int rectIndex2 = 0; if (baseX > 1) { // More samples than pixels int theWidth = width(); //if(baseElement + theWidth > z->size()) z->setSize(baseElement + theWidth); if(lastBaseElement > z->size()) z->setSize(lastBaseElement); for(; n < theWidth && baseElement < lastBaseElement; n++, baseElement++) { myassert(baseElement >= 0); ZoomElement &ze = z->at(baseElement); //if(!z->hasValue(baseElement)) { if(!ze.isValid()) { if(!calcZoomElement(ch, ze, baseElement, baseX)) continue; } /*p.setPen(gdata->shading1Color()); p.moveTo(n, 0); p.lineTo(n, height() - 1 - toInt(ze.high / zoomY) + viewBottomOffset); p.setPen(gdata->shading2Color()); p.lineTo(n, height());*/ int y = height() - 1 - toInt(ze.high() / zoomY) + viewBottomOffset; int y2, y3; //if(ze.noteIndex >= 0) { if(ze.noteIndex() != -1 && ch->dataAtChunk(ze.midChunk())->getNoteIndex() != -1) { myassert(ze.noteIndex() >= 0); myassert(ze.noteIndex() < int(ch->noteData.size())); myassert(ch->isValidChunk(ze.midChunk())); AnalysisData *data = ch->dataAtChunk(ze.midChunk()); //double avgNote = ch->noteData[ze.noteIndex()].avgNote(); //printf("avgFreq = %f, ", ch->noteData[ze.noteIndex].avgFreq()); //printf("numPeriods = %f, ", ch->noteData[ze.noteIndex].numPeriods()); //printf("noteLength = %f\n", ch->noteData[ze.noteIndex].noteLength()); //y2 = height() - 1 - toInt((avgNote+0.5) / zoomY) + viewBottomOffset; //y3 = height() - 1 - toInt((avgNote-0.5) / zoomY) + viewBottomOffset; //y2 = height() - 1 - toInt((data->shortTermMean + data->shortTermDeviation) / zoomY) + viewBottomOffset; //y3 = height() - 1 - toInt((data->shortTermMean - data->shortTermDeviation) / zoomY) + viewBottomOffset; if(gdata->showMeanVarianceBars()) { //longTermMean bars y2 = height() - 1 - toInt((data->getLongTermMean() + data->getLongTermDeviation()) / zoomY) + viewBottomOffset; y3 = height() - 1 - toInt((data->getLongTermMean() - data->getLongTermDeviation()) / zoomY) + viewBottomOffset; if(ze.noteIndex() % 2 == 0) { evenMidPoints.setPoint(evenMidPointIndex++, n, y2); evenMidPoints.setPoint(evenMidPointIndex++, n, y3); } else { oddMidPoints.setPoint(oddMidPointIndex++, n, y2); oddMidPoints.setPoint(oddMidPointIndex++, n, y3); } //shortTermMean bars y2 = height() - 1 - toInt((data->getShortTermMean() + data->getShortTermDeviation()) / zoomY) + viewBottomOffset; y3 = height() - 1 - toInt((data->getShortTermMean() - data->getShortTermDeviation()) / zoomY) + viewBottomOffset; if(ze.noteIndex() % 2 == 0) { evenMidPoints2.setPoint(evenMidPointIndex2++, n, y2); evenMidPoints2.setPoint(evenMidPointIndex2++, n, y3); } else { oddMidPoints2.setPoint(oddMidPointIndex2++, n, y2); oddMidPoints2.setPoint(oddMidPointIndex2++, n, y3); } } //} else { // y2 = y3 = 0; } //topPoints.setPoint(pointIndex, n, 0); //topPoints.setPoint(pointIndex, n, y); bottomPoints.setPoint(pointIndex++, n, y); bottomPoints.setPoint(pointIndex++, n, height()); lastN = n; } //p.setPen(gdata->shading1Color()); //p.drawLineSegments(topPoints, 0, pointIndex/2); p.setPen(Qt::NoPen); p.setBrush(gdata->shading1Color()); p.drawRect(firstN, 0, lastN, height()); p.setPen(gdata->shading2Color()); //p.drawLineSegments(bottomPoints, 0, pointIndex/2); if(pointIndex > 1) p.drawLines(bottomPoints.constData(), pointIndex/2); if(gdata->showMeanVarianceBars()) { //shortTermMean bars p.setPen(Qt::green); //p.drawLineSegments(evenMidPoints2, 0, evenMidPointIndex2/2); if(evenMidPointIndex2 > 1) p.drawLines(evenMidPoints2.constData(), evenMidPointIndex2/2); p.setPen(Qt::yellow); //p.drawLineSegments(oddMidPoints2, 0, oddMidPointIndex2/2); if(oddMidPointIndex2 > 1) p.drawLines(oddMidPoints2.constData(), oddMidPointIndex2/2); //longTermMean bars p.setPen(Qt::yellow); //p.drawLineSegments(evenMidPoints, 0, evenMidPointIndex/2); if(evenMidPointIndex > 1) p.drawLines(evenMidPoints.constData(), evenMidPointIndex/2); p.setPen(Qt::green); //p.drawLineSegments(oddMidPoints, 0, oddMidPointIndex/2); if(oddMidPointIndex > 1) p.drawLines(oddMidPoints.constData(), oddMidPointIndex/2); } } else { // More pixels than samples float err = 0.0; float pitch = 0.0; int intChunk = (int) floor(frameTime); // Integer version of frame time if(intChunk < 0) intChunk = 0; double stepSize = 1.0 / baseX; // So we skip some pixels int x = 0, y, y2, y3; //double start = 0 - stepSize; double start = (double(intChunk) - frameTime) * stepSize; double stop = width() + (2 * stepSize); //int squareSize = (int(sqrt(stepSize)) / 2) * 2 + 1; //make it an odd number //int halfSquareSize = squareSize/2; //QPointArray topPoints(0); //QPointArray bottomPoints(0); //int pointIndex = 0; //topPoints.putPoints(pointIndex, 1, toInt(start), 0); //bottomPoints.putPoints(pointIndex, 1, toInt(start), height()); //pointIndex++; //topPoints.setPoint(pointIndex, toInt(start), 0); bottomPoints.setPoint(pointIndex++, toInt(start), height()); lastN = firstN = toInt(start); for (double n = start; n < stop && intChunk < (int)ch->totalChunks(); n += stepSize, intChunk++) { myassert(intChunk >= 0); //if (intChunk < 0) continue; // So we don't go off the beginning of the array AnalysisData *data = ch->dataAtChunk(intChunk); err = data->getCorrelation(); //if (err >= CERTAIN_THRESHOLD) { //float val = MIN(ch->dataAtChunk(intChunk)->volumeValue, 1.0); if(gdata->pitchContourMode() == 0) //p.setPen(QPen(colorBetween(colorGroup().background(), ch->color, err*2.0-1.0), lineWidth)); //p.setPen(QPen(colorBetween(gdata->backgroundColor(), ch->color, err*sqrt(data->rms)*10.0), lineWidth)); p.setPen(QPen(colorBetween(QColor(255, 255, 255), ch->color, err * dB2ViewVal(data->getLogRms())), lineWidth)); else p.setPen(QPen(ch->color, lineWidth)); x = toInt(n); lastN = x; //note = (data->isValid()) ? data->note : 0.0f; //note = (ch->isVisibleNote(data->noteIndex)) ? data->note : 0.0f; pitch = (ch->isVisibleChunk(data)) ? data->getPitch() : 0.0f; //if(ch->isVisibleChunk(data)) { if(data->getNoteIndex() >= 0) { isNoteRectEven[rectIndex] = (data->getNoteIndex() % 2) == 0; //note = data->note; //double avgNote = ch->noteData[data->noteIndex].avgNote(); //y2 = height() - 1 - toInt((avgNote+0.5) / zoomY) + viewBottomOffset; //y3 = height() - 1 - toInt((avgNote-0.5) / zoomY) + viewBottomOffset; //y2 = height() - 1 - toInt((data->shortTermMean + data->shortTermDeviation) / zoomY) + viewBottomOffset; //y3 = height() - 1 - toInt((data->shortTermMean - data->shortTermDeviation) / zoomY) + viewBottomOffset; if(gdata->showMeanVarianceBars()) { //longTermMean bars y2 = height() - 1 - toInt((data->getLongTermMean() + data->getLongTermDeviation()) / zoomY) + viewBottomOffset; y3 = height() - 1 - toInt((data->getLongTermMean() - data->getLongTermDeviation()) / zoomY) + viewBottomOffset; noteRect[rectIndex].setLeft(x); noteRect[rectIndex].setRight(toInt(n+stepSize)); noteRect[rectIndex].setTop(y2); noteRect[rectIndex++].setBottom(y3); //shortTermMean bars y2 = height() - 1 - toInt((data->getShortTermMean() + data->getShortTermDeviation()) / zoomY) + viewBottomOffset; y3 = height() - 1 - toInt((data->getShortTermMean() - data->getShortTermDeviation()) / zoomY) + viewBottomOffset; noteRect2[rectIndex2].setLeft(x); noteRect2[rectIndex2].setRight(toInt(n+stepSize)); noteRect2[rectIndex2].setTop(y2); noteRect2[rectIndex2++].setBottom(y3); } //} else { // note = 0.0f; } myassert(pitch >= 0.0 && pitch <= gdata->topPitch()); //note = bound(note, 0, gdata->topNote()); y = height() - 1 - toInt(pitch / zoomY) + viewBottomOffset; //y = height() - 1 - int((note / zoomY) - (viewBottom / zoomY)); //topPoints.putPoints(pointIndex, 1, x, y); //bottomPoints.putPoints(pointIndex, 1, x, y); //pointIndex++; //topPoints.setPoint(pointIndex, x, y); bottomPoints.setPoint(pointIndex++, x, y); } //topPoints.putPoints(pointIndex, 1, topPoints.point(pointIndex-1).x(), 0); //bottomPoints.putPoints(pointIndex, 1, bottomPoints.point(pointIndex-1).x(), height()); //pointIndex++; //topPoints.setPoint(pointIndex, topPoints.point(pointIndex-1).x(), 0); bottomPoints.setPoint(pointIndex, bottomPoints.point(pointIndex-1).x(), height()); pointIndex++; //p.setPen(gdata->shading1Color()); //p.setBrush(gdata->shading1Color()); //p.drawPolygon(topPoints); //p.setPen(gdata->shading2Color()); //p.setBrush(gdata->shading2Color()); //p.drawPolygon(bottomPoints); myassert(pointIndex <= width()*2); //p.setPen(gdata->shading1Color()); p.setPen(Qt::NoPen); p.setBrush(gdata->shading1Color()); //p.drawPolygon(topPoints, false, 0, pointIndex); p.drawRect(firstN, 0, lastN, height()); //p.setPen(gdata->shading2Color()); p.setBrush(gdata->shading2Color()); //p.drawPolygon(bottomPoints, false, 0, pointIndex); p.drawPolygon(bottomPoints.constData(), pointIndex, Qt::OddEvenFill); if(gdata->showMeanVarianceBars()) { //shortTermMean bars for(int j=0; j<rectIndex2; j++) { if(isNoteRectEven[j]) p.setBrush(Qt::green); else p.setBrush(Qt::yellow); p.drawRect(noteRect2[j]); } //longTermMean bars QColor seeThroughYellow = Qt::yellow; seeThroughYellow.setAlpha(255); QColor seeThroughGreen = Qt::green; seeThroughGreen.setAlpha(255); for(int j=0; j<rectIndex; j++) { //if(isNoteRectEven[j]) p.setBrush(QBrush(Qt::yellow, Qt::Dense3Pattern)); //else p.setBrush(QBrush(Qt::green, Qt::Dense3Pattern)); if(isNoteRectEven[j]) p.setBrush(seeThroughYellow); else p.setBrush(seeThroughGreen); p.drawRect(noteRect[j]); } } } }
void ColorPalette::drawPannel(QPainter &painter) { QPen pen; pen.setColor(QColor(255,255,255)); pen.setWidthF(0.01); painter.setPen(pen); float x = draw_erae_.left(); float y = draw_erae_.top(); float diff = draw_erae_.height()/1020; float l_x = draw_erae_.right(); float l_y = draw_erae_.bottom(); QRgb srgb = QRgb(0x660000); int sred = qRed(srgb); QRgb ergb = QRgb(0xff0000); int ered = qRed(ergb); int k = 0; while(k<919) //1020) { QRectF rect = QRectF(draw_erae_.left(),draw_erae_.top() + k*diff,draw_erae_.width() - 40,diff); painter.drawRect(rect); if (k<153) { painter.fillRect(rect,QBrush(QColor(sred + k,0,0))); } else if (k < 408 && k >= 153) { painter.fillRect(rect,QBrush(QColor(255,k - 153,0))); } else if ( k < 663 && k >= 408) { painter.fillRect(rect,QBrush(QColor(255 - (k - 408),255,0))); } else if (k < 918 && k>= 663) { painter.fillRect(rect,QBrush(QColor(0,255 - (k - 663),k - 663))); } else { painter.fillRect(rect,QBrush(QColor(0,0,255- (k - 918)))); } k++; } QList<float> earthquk; for (int i = 0;i<locationpoints.size();i++) { earthquk.push_back(locationpoints.value(i).quk_level); } qSort(earthquk); //earthquk.sort(Complear); int num = earthquk.size() * 0.1; QList<float> templist; for (int i = num;i<earthquk.size() - num;i++) { templist.push_back(earthquk.value(i)); } //从1020个色彩中选出与震级幅度相同的颜色 //震级的最大值为第一个颜色,最小值为最后一个颜色 //int colordiff = 1020/templist.size(); float tempmin = earthquk.value(0); float tempmax = earthquk.value(earthquk.size() - 1); float temp = (tempmax - tempmin) / 10; float colordiff = draw_erae_.height() / 9; QLineF line[10]; pen.setColor(QColor(0,0,0)); pen.setWidth(XCOORDINATERULERWIDTH); painter.setFont(QFont(QObject::tr("WenQuanYi"),6)); painter.setPen(pen); for (int i = 0;i<10;i++) { line[i].setP1(QPointF(draw_erae_.left(),draw_erae_.top()+(i)*colordiff)); line[i].setP2(QPointF(draw_erae_.right() -40,draw_erae_.top() + (i)*colordiff)); QString str_earthquake; str_earthquake.sprintf("%0.1f",tempmax - i*temp); float width = painter.fontMetrics().width(str_earthquake); float height = painter.fontMetrics().height(); QRectF rect; if (i == 0) { rect = QRectF(draw_erae_.right() -35,draw_erae_.top() + colordiff*(i),width,height + 5); } else if (i == 9) { rect = QRectF(draw_erae_.right() -35,draw_erae_.top()-10 + colordiff*(i),width,height + 5); } else { rect = QRectF(draw_erae_.right() -35,draw_erae_.top()-5 + colordiff*(i),width,height + 5); } painter.drawText(rect,str_earthquake,QTextOption(Qt::AlignRight)); } painter.drawLines(line,10); }
void LogicSignal::paint_mid(QPainter &p, int left, int right) { using pv::view::View; QLineF *line; vector< pair<int64_t, bool> > edges; assert(_probe); assert(_data); assert(right >= left); assert(_view); const int y = _v_offset - _view->v_offset(); const double scale = _view->scale(); assert(scale > 0); const double offset = _view->offset(); if (!_probe->enabled) return; const float high_offset = y - View::SignalHeight + 0.5f; const float low_offset = y + 0.5f; const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots = _data->get_snapshots(); if (snapshots.empty()) return; const shared_ptr<pv::data::LogicSnapshot> &snapshot = snapshots.front(); double samplerate = _data->samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0) samplerate = 1.0; const double pixels_offset = offset / scale; const double start_time = _data->get_start_time(); const int64_t last_sample = snapshot->get_sample_count() - 1; const double samples_per_pixel = samplerate * scale; const double start = samplerate * (offset - start_time); const double end = start + samples_per_pixel * (right - left); snapshot->get_subsampled_edges(edges, min(max((int64_t)floor(start), (int64_t)0), last_sample), min(max((int64_t)ceil(end), (int64_t)0), last_sample), samples_per_pixel / Oversampling, _probe->index); assert(edges.size() >= 2); // Paint the edges const unsigned int edge_count = edges.size() - 2; QLineF *const edge_lines = new QLineF[edge_count]; line = edge_lines; for (vector<pv::data::LogicSnapshot::EdgePair>::const_iterator i = edges.begin() + 1; i != edges.end() - 1; i++) { const float x = ((*i).first / samples_per_pixel - pixels_offset) + left; *line++ = QLineF(x, high_offset, x, low_offset); } p.setPen(EdgeColour); p.drawLines(edge_lines, edge_count); delete[] edge_lines; // Paint the caps const unsigned int max_cap_line_count = edges.size(); QLineF *const cap_lines = new QLineF[max_cap_line_count]; p.setPen(HighColour); paint_caps(p, cap_lines, edges, true, samples_per_pixel, pixels_offset, left, high_offset); p.setPen(LowColour); paint_caps(p, cap_lines, edges, false, samples_per_pixel, pixels_offset, left, low_offset); delete[] cap_lines; }
void CFlightVisualiser::drawCords(QPainter& painter, const QRect& fieldLimit) { Point3D zero3D(0, 0, 0), x3D(100, 0, 0), y3D(0, 100, 0), z3D(0, 0, 100); Point2D zeroPoint = getScreenPoint(zero3D, fieldLimit); Point2D x = getScreenPoint(x3D, fieldLimit); Point2D y = getScreenPoint(y3D, fieldLimit); Point2D z = getScreenPoint(z3D, fieldLimit); painter.setPen(QPen(QColor(), 1)); painter.drawLine(QPointF(zeroPoint), QPointF(x)); painter.drawText(QRectF(QPointF(x), QPointF(x.X() + 20, x.Y() + 20)), "X"); painter.drawLine(QPointF(zeroPoint), QPointF(y)); painter.drawText(QRectF(QPointF(y), QPointF(y.X() + 20, y.Y() + 20)), "Y"); painter.drawLine(QPointF(zeroPoint), QPointF(z)); painter.drawText(QRectF(QPointF(z), QPointF(z.X() + 20, z.Y() + 20)), "Z"); painter.setPen(Qt::SolidLine); const int distance = 1; std::vector<QPoint> frameVec = {QPoint(distance, distance), QPoint(distance, this->height() - distance), QPoint(distance, this->height() - distance), QPoint(this->width() - distance, this->height() - distance), QPoint(this->width() - distance, this->height() - distance), QPoint(this->width() - distance, distance), QPoint(this->width() - distance, distance), QPoint(distance, distance)}; QVector<QPoint> frameCords; for(const auto& p: frameVec) { frameCords.push_back(p); } painter.drawLines(frameCords); Rectangle3D max3dRect = getMaximumRect(); float xPosStart = max3dRect.minX; float yPosStart = max3dRect.minY; float xPosEnd = max3dRect.maxX; float yPosEnd = max3dRect.maxY; float xPos = xPosStart; float yPos = yPosStart; for(int i = 0; i < 11; ++i) { Point2D curXMinYWebPoint = getScreenPoint(Point3D(xPos, yPosStart, 0), fieldLimit); Point2D curXMaxYWebPoint = getScreenPoint(Point3D(xPos, yPosEnd, 0), fieldLimit); Point2D minXCurYWebPoint = getScreenPoint(Point3D(xPosStart, yPos, 0), fieldLimit); Point2D maxXCurYWebPoint = getScreenPoint(Point3D(xPosEnd, yPos, 0), fieldLimit); painter.drawLine(QPointF(curXMinYWebPoint.X(), curXMinYWebPoint.Y()), QPointF(curXMaxYWebPoint.X(), curXMaxYWebPoint.Y())); //x painter.drawLine(QPointF(minXCurYWebPoint.X(), minXCurYWebPoint.Y()), QPointF(maxXCurYWebPoint.X(), maxXCurYWebPoint.Y())); xPos += (xPosEnd - xPosStart) / 10; yPos += (yPosEnd - yPosStart) / 10; } }
void ezQGridBarWidget::paintEvent(QPaintEvent* e) { if (!MapFromSceneFunc.IsValid()) { QWidget::paintEvent(e); return; } QPainter Painter(this); QPainter* painter = &Painter; painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::TextAntialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing); QRect areaRect = rect(); // background painter->fillRect(areaRect, palette().button()); painter->translate(0.5, 0.5); // render fine grid stop lines { double fSceneMinX, fSceneMaxX; ezWidgetUtils::ComputeGridExtentsX(m_viewportSceneRect, m_fFineGridStops, fSceneMinX, fSceneMaxX); fSceneMinX = ezMath::Max(fSceneMinX, 0.0); painter->setPen(palette().buttonText().color()); ezHybridArray<QLine, 100> lines; // some overcompensation for the case that the GraphicsView displays a scrollbar at the side for (double x = fSceneMinX; x <= fSceneMaxX + m_fTextGridStops; x += m_fFineGridStops) { const QPoint pos = MapFromSceneFunc(QPointF(x, 0)); QLine& l = lines.ExpandAndGetRef(); l.setLine(pos.x(), areaRect.bottom() - 3, pos.x(), areaRect.bottom()); } painter->drawLines(lines.GetData(), lines.GetCount()); } // Grid Stop Value Text { double fSceneMinX, fSceneMaxX; ezWidgetUtils::ComputeGridExtentsX(m_viewportSceneRect, m_fTextGridStops, fSceneMinX, fSceneMaxX); fSceneMinX = ezMath::Max(fSceneMinX, 0.0); QTextOption textOpt(Qt::AlignCenter); QRectF textRect; painter->setPen(palette().buttonText().color()); ezStringBuilder tmp; for (double x = fSceneMinX; x <= fSceneMaxX; x += m_fTextGridStops) { const QPoint pos = MapFromSceneFunc(QPointF(x, 0)); textRect.setRect(pos.x() - 50, areaRect.top(), 99, areaRect.height()); tmp.Format("{0}", ezArgF(x)); painter->drawText(textRect, tmp.GetData(), textOpt); } } }
void LogicSignal::paint_mid(QPainter &p, int left, int right) { using pv::view::View; QLineF *line; assert(_data); assert(_view); assert(right >= left); const int y = get_y() + _signalHeight * 0.5; const double scale = _view->scale(); assert(scale > 0); const double offset = _view->offset(); const float high_offset = y - _signalHeight + 0.5f; const float low_offset = y + 0.5f; const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots = _data->get_snapshots(); if (snapshots.empty()) return; const boost::shared_ptr<pv::data::LogicSnapshot> &snapshot = snapshots.front(); if (snapshot->buf_null()) return; double samplerate = _data->samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0) samplerate = 1.0; const double pixels_offset = offset / scale; const double start_time = _data->get_start_time(); const int64_t last_sample = snapshot->get_sample_count() - 1; const double samples_per_pixel = samplerate * scale; const double start = samplerate * (offset - start_time); const double end = start + samples_per_pixel * (right - left); snapshot->get_subsampled_edges(_cur_edges, min(max((int64_t)floor(start), (int64_t)0), last_sample), min(max((int64_t)ceil(end), (int64_t)0), last_sample), samples_per_pixel / Oversampling, _probe->index); if (_cur_edges.size() < 2) return; // Paint the edges const unsigned int edge_count = 2 * _cur_edges.size() - 3; QLineF *const edge_lines = new QLineF[edge_count]; line = edge_lines; double preX = ((*(_cur_edges.begin())).first / samples_per_pixel - pixels_offset) + left; double preY = (*(_cur_edges.begin())).second ? high_offset : low_offset; vector<pv::data::LogicSnapshot::EdgePair>::const_iterator i; for ( i = _cur_edges.begin() + 1; i != _cur_edges.end() - 1; i++) { const double x = ((*i).first / samples_per_pixel - pixels_offset) + left; const double y = (*i).second ? high_offset : low_offset; *line++ = QLineF(preX, preY, x, preY); *line++ = QLineF(x, high_offset, x, low_offset); preX = x; preY = y; } const double x = ((*i).first / samples_per_pixel - pixels_offset) + left; *line++ = QLineF(preX, preY, x, preY); p.setPen(_colour); p.drawLines(edge_lines, edge_count); delete[] edge_lines; }