void AVTPlotWidget::paintEvent( QPaintEvent *e ) { Q_UNUSED(e) QPainter p; p.begin( this ); p.setRenderHint( QPainter::Antialiasing, antialiasing() ); p.fillRect( rect(), backgroundColor() ); p.translate( leftPadding(), topPadding() ); setPixRect(); p.setClipRect( pixRect() ); p.setClipping( true ); int pW = pixRect().width(); int pH = pixRect().height(); QColor SkyColor( 0, 100, 200 ); //draw daytime sky if the Sun rises for the current date/location if ( SunMaxAlt > -18.0 ) { //Display centered on midnight, so need to modulate dawn/dusk by 0.5 int rise = int( pW * ( 0.5 + SunRise ) ); int set = int( pW * ( SunSet - 0.5 ) ); int da = int( pW * ( 0.5 + Dawn ) ); int du = int( pW * ( Dusk - 0.5 ) ); if ( SunMinAlt > 0.0 ) { // The sun never set and the sky is always blue p.fillRect( rect(), SkyColor ); } else if ( SunMaxAlt < 0.0 && SunMinAlt < -18.0 ) { // The sun never rise but the sky is not completely dark QLinearGradient grad = QLinearGradient( QPointF( 0.0, 0.0 ), QPointF( du, 0.0 ) ); grad.setColorAt( 0, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) ); grad.setColorAt( 1, Qt::black ); p.fillRect( QRectF( 0.0, 0.0, du+20.0, pH ), grad ); grad.setStart( QPointF( pW, 0.0 ) ); grad.setFinalStop( QPointF( da-20.0, 0.0 ) ); p.fillRect( QRectF( da-20.0, 0.0, pW, pH ), grad ); } else if ( SunMaxAlt < 0.0 && SunMinAlt > -18.0 ) { // The sun never rise but the sky is NEVER completely dark QLinearGradient grad = QLinearGradient( QPointF( 0.0, 0.0 ), QPointF( pW, 0.0 ) ); grad.setColorAt( 0, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) ); grad.setColorAt( 0.5, SkyColor.darker( SunMinAlt / -18.0 * 1000 ) ); grad.setColorAt( 1, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) ); p.fillRect( QRectF( 0.0, 0.0, pW, pH ), grad ); } else if ( Dawn < 0.0 ) { // The sun sets and rises but the sky is never completely dark p.fillRect( 0, 0, set, int( 0.5 * pH ), SkyColor ); p.fillRect( rise, 0, pW, int( 0.5 * pH ), SkyColor ); QLinearGradient grad = QLinearGradient( QPointF( set-20.0, 0.0 ), QPointF( rise, 0.0 ) ); grad.setColorAt( 0, SkyColor ); grad.setColorAt( 0.5, SkyColor.darker( SunMinAlt / -18.0 * 1000 ) ); grad.setColorAt( 1, SkyColor ); p.fillRect( QRectF( set-20.0, 0.0, rise-set+20.0, pH ), grad ); } else { p.fillRect( 0, 0, set, pH, SkyColor ); p.fillRect( rise, 0, pW, pH, SkyColor ); QLinearGradient grad = QLinearGradient( QPointF( set-20.0, 0.0 ), QPointF( du, 0.0 ) ); grad.setColorAt( 0, SkyColor ); grad.setColorAt( 1, Qt::black ); p.fillRect( QRectF( set-20.0, 0.0, du-set+20.0, pH ), grad ); grad.setStart( QPointF( rise+20.0, 0.0 ) ); grad.setFinalStop( QPointF( da, 0.0 ) ); p.fillRect( QRectF( da, 0.0, rise-da+20.0, pH ), grad ); } } //draw ground p.fillRect( 0, int(0.5*pH), pW, int(0.5*pH), QColor( "#002200" ) ); foreach( KPlotObject *po, plotObjects() ) po->draw( &p, this ); p.setClipping( false ); drawAxes( &p ); //Add vertical line indicating "now" QTime t = QTime::currentTime(); double x = 12.0 + t.hour() + t.minute()/60.0 + t.second()/3600.0; while ( x > 24.0 ) x -= 24.0; int ix = int(x*pW/24.0); //convert to screen pixel coords p.setPen( QPen( QBrush("white"), 2.0, Qt::DotLine ) ); p.drawLine( ix, 0, ix, pH ); //Label this vertical line with the current time p.save(); QFont smallFont = p.font(); smallFont.setPointSize( smallFont.pointSize() - 2 ); p.setFont( smallFont ); p.translate( ix + 10, pH - 20 ); p.rotate(-90); p.drawText(0, 0, KGlobal::locale()->formatTime( t ) ); p.restore(); //Draw crosshairs at clicked position if ( MousePoint.x() > 0 ) { p.setPen( QPen( QBrush("gold"), 1.0, Qt::SolidLine ) ); p.drawLine( QLineF( MousePoint.x()+0.5, 0.5, MousePoint.x()+0.5, pixRect().height()-0.5 ) ); p.drawLine( QLineF( 0.5, MousePoint.y()+0.5, pixRect().width()-0.5, MousePoint.y()+0.5 ) ); //Label each crosshair line (time and altitude) p.setFont( smallFont ); double a = (pH - MousePoint.y())*180.0/pH - 90.0; p.drawText( 20, MousePoint.y() + 10, QString::number(a,'f',2) + QChar(176) ); double h = MousePoint.x()*24.0/pW - 12.0; if ( h < 0.0 ) h += 24.0; t = QTime( int(h), int(60.*(h - int(h))) ); p.save(); p.translate( MousePoint.x() + 10, pH - 20 ); p.rotate(-90); p.drawText( 0, 0, KGlobal::locale()->formatTime( t ) ); p.restore(); } p.end(); }
void MapIcon::paintPlus(QPainter&p, const QPoint& point, int size, int sizeWH) { p.drawLine(point.x(), point.y() - size, point.x(), point.y() + size ); p.drawLine(point.x() - size, point.y(), point.x() + size, point.y() ); }
void MapIcons::paintSpawnIcon(MapParameters& param, QPainter& p, const MapIcon& mapIcon, const Spawn* spawn, const EQPoint& location, const QPoint& point) { // ------------------------ // Draw Walk Path if (mapIcon.showWalkPath() || (m_showNPCWalkPaths && spawn->isNPC())) { SpawnTrackListIterator trackIt(spawn->trackList()); const SpawnTrackPoint* trackPoint = trackIt.current(); if (trackPoint) { if (!mapIcon.useWalkPathPen()) p.setPen(blue); else p.setPen(mapIcon.walkPathPen()); p.moveTo (param.calcXOffsetI(trackPoint->x()), param.calcYOffsetI(trackPoint->y())); while ((trackPoint = ++trackIt) != NULL) p.lineTo (param.calcXOffsetI (trackPoint->x()), param.calcYOffsetI (trackPoint->y())); p.lineTo (point.x(), point.y()); } } // Draw Line if (mapIcon.showLine0()) { p.setPen(mapIcon.line0Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } // calculate distance and draw distance related lines uint32_t distance = UINT32_MAX; if (mapIcon.line1Distance() || mapIcon.line2Distance() || m_showSpawnNames) { if (!showeq_params->fast_machine) distance = location.calcDist2DInt(param.player()); else distance = (int)location.calcDist(param.player()); if (mapIcon.line1Distance() > distance) { p.setPen(mapIcon.line1Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } if (mapIcon.line2Distance() > distance) { p.setPen(mapIcon.line2Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } } // Draw Spawn Names if (mapIcon.showName() || (m_showSpawnNames && (distance < m_fovDistance))) { QString spawnNameText; spawnNameText.sprintf("%2d: %s", spawn->level(), (const char*)spawn->name()); QFontMetrics fm(param.font()); int width = fm.width(spawnNameText); p.setPen(gray); p.drawText(point.x() - (width / 2), point.y() + fm.height() + 1, spawnNameText); } // Draw the Icon if (mapIcon.image() && (!mapIcon.imageFlash() || m_flash) && (mapIcon.imageStyle() != tIconStyleNone)) { if (mapIcon.imageUseSpawnColorPen()) { QPen pen = mapIcon.imagePen(); pen.setColor(pickSpawnColor(spawn)); p.setPen(pen); } else p.setPen(mapIcon.imagePen()); if (mapIcon.imageUseSpawnColorBrush()) { QBrush brush = mapIcon.imageBrush(); brush.setColor(pickSpawnColor(spawn)); p.setBrush(brush); } else p.setBrush(mapIcon.imageBrush()); mapIcon.paintIconImage(mapIcon.imageStyle(), p, point, *m_mapIconSizes[mapIcon.imageSize()], *m_mapIconSizesWH[mapIcon.imageSize()]); } // Draw the highlight if (mapIcon.highlight() && (!mapIcon.highlightFlash() || m_flash) && (mapIcon.highlightStyle() != tIconStyleNone)) { if (mapIcon.highlightUseSpawnColorPen()) { QPen pen = mapIcon.highlightPen(); pen.setColor(pickSpawnColor(spawn)); p.setPen(pen); } else p.setPen(mapIcon.highlightPen()); if (mapIcon.highlightUseSpawnColorBrush()) { QBrush brush = mapIcon.highlightBrush(); brush.setColor(pickSpawnColor(spawn)); p.setBrush(brush); } else p.setBrush(mapIcon.highlightBrush()); mapIcon.paintIconImage(mapIcon.highlightStyle(), p, point, *m_mapIconSizes[mapIcon.highlightSize()], *m_mapIconSizesWH[mapIcon.highlightSize()]); } }
void NoteCanvas::draw(QPainter & p) { if (! visible()) return; p.setRenderHint(QPainter::Antialiasing, true); QRect r = rect(); QBrush brsh = p.brush(); QColor bckgrnd = p.backgroundColor(); QPen fgcolor = p.pen(); Q3PointArray a(7); used_color = (itscolor == UmlDefaultColor) ? the_canvas()->browser_diagram()->get_color(UmlNote) : itscolor; QColor co = color(used_color); const int corner_size = (int) (NOTE_MARGIN * the_canvas()->zoom()); a.setPoint(0, r.left(), r.top()); a.setPoint(1, r.right() - corner_size, r.top()); a.setPoint(2, r.right() - corner_size, r.top() + corner_size); a.setPoint(3, r.right(), r.top() + corner_size); a.setPoint(4, r.right(), r.bottom()); a.setPoint(5, r.left(), r.bottom()); a.setPoint(6, r.left(), r.top()); FILE * fp = svg(); if (fp != 0) fputs("<g>\n", fp); if (used_color == UmlTransparent) { p.setBackgroundMode(::Qt::TransparentMode); p.setBackgroundColor(co); p.drawPolyline(a); if (fp != 0) draw_poly(fp, a, UmlTransparent); } else { p.setBackgroundMode(::Qt::OpaqueMode); p.setBrush(co); p.drawPolygon(a, TRUE, 0, 6); p.setBrush(brsh); p.setBackgroundColor(co); if (fp != 0) draw_poly(fp, a, used_color); } p.drawLine(r.right() - corner_size, r.top(), r.right(), r.top() + corner_size); if (fp != 0) fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.right() - corner_size, r.top(), r.right(), r.top() + corner_size); p.setFont(the_canvas()->get_font(itsfont)); if (fg_c != UmlTransparent) p.setPen(color(fg_c)); p.drawText (r.left() + corner_size, r.top() + corner_size, r.width() - 2*corner_size, r.height() - 2*corner_size, ::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::TextWordWrap, note); if (fp != 0) { draw_text(r.left() + corner_size, r.top() + corner_size, r.width() - 2*corner_size, r.height() - 2*corner_size, ::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::TextWordWrap, note, p.font(), fp, fg_c); fputs("</g>\n", fp); } p.setFont(the_canvas()->get_font(UmlNormalFont)); p.setBackgroundColor(bckgrnd); p.setPen(fgcolor); if (selected()) show_mark(p, r); }
void HeatmapView::paintRow(QPainter& painter, HeatmapRowIterator* itr) { bool selection = m_selectionState ? m_selectionState->type != SelectionState::None : false; while (itr->next()) { double heat = itr->heat(); int width = itr->width(); int x = itr->step(); /* Gamma correction */ heat = qPow(heat, 1.0 / 2.0); if (width == 1) { /* Draw single line */ if (selection) { double selectedHeat = itr->selectedHeat(); if (selectedHeat >= 0.999) { heat = 255.0 - qBound(0.0, heat * 255.0, 255.0); if (itr->isGpu()) { painter.setPen(QColor(255, heat, heat)); } else { painter.setPen(QColor(heat, heat, 255)); } painter.drawLine(x, 0, x, m_rowHeight - 1); } else { heat = 255.0 - qBound(0.0, heat * 100.0, 100.0); painter.setPen(QColor(heat, heat, heat)); painter.drawLine(x, 0, x, m_rowHeight - 1); if (selectedHeat > 0.001) { selectedHeat = qPow(selectedHeat, 1.0 / 2.0); selectedHeat = qBound(0.0, selectedHeat * 255.0, 255.0); if (itr->isGpu()) { painter.setPen(QColor(255, 0, 0, selectedHeat)); } else { painter.setPen(QColor(0, 0, 255, selectedHeat)); } painter.drawLine(x, 0, x, m_rowHeight - 1); } } } else { heat = qBound(0.0, heat * 255.0, 255.0); if (itr->isGpu()) { painter.setPen(QColor(255, 255 - heat, 255 - heat)); } else { painter.setPen(QColor(255 - heat, 255 - heat, 255)); } painter.drawLine(x, 0, x, m_rowHeight - 1); } } else { double selectedHeat = itr->selectedHeat(); if (selection && selectedHeat < 0.9) { painter.fillRect(x, 0, width, m_rowHeight, QColor(255 - 100, 255 - 100, 255 - 100)); } else if (itr->isGpu()) { painter.fillRect(x, 0, width, m_rowHeight, QColor(255, 0, 0)); } else { painter.fillRect(x, 0, width, m_rowHeight, QColor(0, 0, 255)); } if (width > 6) { painter.setPen(Qt::white); QString elided = painter.fontMetrics().elidedText(itr->label(), Qt::ElideRight, width - 1); painter.drawText(x + 1, 0, width - 1, m_rowHeight - 1, Qt::AlignLeft | Qt::AlignVCenter, elided); } } } }
void PlastikButtonProvider::drawObject(QPainter &p, Object object, int x, int y, int length, int lineWidth) { switch(object) { case DiagonalLine: if (lineWidth <= 1) { for (int i = 0; i < length; ++i) { p.drawPoint(x+i,y+i); } } else if (lineWidth <= 2) { for (int i = 0; i < length; ++i) { p.drawPoint(x+i,y+i); } for (int i = 0; i < (length-1); ++i) { p.drawPoint(x+1+i,y+i); p.drawPoint(x+i,y+1+i); } } else { for (int i = 1; i < (length-1); ++i) { p.drawPoint(x+i,y+i); } for (int i = 0; i < (length-1); ++i) { p.drawPoint(x+1+i,y+i); p.drawPoint(x+i,y+1+i); } for (int i = 0; i < (length-2); ++i) { p.drawPoint(x+2+i,y+i); p.drawPoint(x+i,y+2+i); } } break; case CrossDiagonalLine: if (lineWidth <= 1) { for (int i = 0; i < length; ++i) { p.drawPoint(x+i,y-i); } } else if (lineWidth <= 2) { for (int i = 0; i < length; ++i) { p.drawPoint(x+i,y-i); } for (int i = 0; i < (length-1); ++i) { p.drawPoint(x+1+i,y-i); p.drawPoint(x+i,y-1-i); } } else { for (int i = 1; i < (length-1); ++i) { p.drawPoint(x+i,y-i); } for (int i = 0; i < (length-1); ++i) { p.drawPoint(x+1+i,y-i); p.drawPoint(x+i,y-1-i); } for (int i = 0; i < (length-2); ++i) { p.drawPoint(x+2+i,y-i); p.drawPoint(x+i,y-2-i); } } break; case HorizontalLine: for (int i = 0; i < lineWidth; ++i) { p.drawLine(x,y+i, x+length-1, y+i); } break; case VerticalLine: for (int i = 0; i < lineWidth; ++i) { p.drawLine(x+i,y, x+i, y+length-1); } break; default: break; } }
void UcClassCanvas::draw(QPainter & p) { if (! visible()) return; p.setRenderHint(QPainter::Antialiasing, true); QRect r = rect(); QFontMetrics fm(the_canvas()->get_font(UmlNormalFont)); QFontMetrics fim(the_canvas()->get_font(UmlNormalItalicFont)); QColor bckgrnd = p.backgroundColor(); double zoom = the_canvas()->zoom(); FILE * fp = svg(); if (fp != 0) fputs("<g>\n", fp); p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode); QColor co = color(used_color); if (used_view_mode == asClass) { if (used_color != UmlTransparent) { const int shadow = the_canvas()->shadow(); if (shadow != 0) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); p.fillRect (r.right(), r.top() + shadow, shadow, r.height() - 1, ::Qt::darkGray); p.fillRect (r.left() + shadow, r.bottom(), r.width() - 1, shadow, ::Qt::darkGray); if (fp != 0) { fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", QColor(::Qt::darkGray).rgb()&0xffffff, r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1); fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", QColor(::Qt::darkGray).rgb()&0xffffff, r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1); } } } p.setBackgroundColor(co); if (used_color != UmlTransparent) { p.fillRect(r, co); if (fp != 0) fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(used_color), r.x(), r.y(), r.width() - 1, r.height() - 1); } else if (fp != 0) fprintf(fp, "\t<rect fill=\"none\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", r.x(), r.y(), r.width() - 1, r.height() - 1); p.drawRect(r); } const ClassData * data = ((ClassData *) browser_node->get_data()); const int two = (int) (2 * zoom); int he = fm.height() + two; if (data->get_n_formalparams() != 0) r.setTop(r.top() + fm.height()); switch (used_view_mode) { case asInterface: draw_interface_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (INTERFACE_SIZE * zoom) + two); break; case asControl: draw_control_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (CONTROL_HEIGHT * zoom) + two); break; case asBoundary: draw_boundary_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (BOUNDARY_HEIGHT * zoom) + two); break; case asEntity: draw_entity_icon(p, r, used_color, zoom); r.setTop(r.top() + (int) (ENTITY_SIZE * zoom) + two); break; case asActor: { QRect ra = r; ra.setHeight((int) (ACTOR_SIZE * zoom)); ra.setLeft(ra.left() + (int) ((ra.width() - ACTOR_SIZE * zoom)/2)); ra.setWidth(ra.height()); draw_actor(&p, ra); } r.setTop(r.top() + (int) (ACTOR_SIZE * zoom) + two); break; case Natural: { const QPixmap * px = ProfiledStereotypes::diagramPixmap(data->get_stereotype(), zoom); int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x(); p.drawPixmap(lft, r.y(), *px); if (fp != 0) // pixmap not really exported in SVG fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1); r.setTop(r.top() + px->height()); } break; default: // class r.setTop(r.top() + two); if (data->get_stereotype()[0]) { p.setFont(the_canvas()->get_font(UmlNormalFont)); p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, QString("<<") + toUnicode(data->get_short_stereotype()) + ">>"); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, QString("<<") + toUnicode(data->get_short_stereotype()) + ">>", p.font(), fp); r.setTop(r.top() + he + two); } } p.setBackgroundMode(::Qt::TransparentMode); p.setFont((data->get_is_abstract()) ? the_canvas()->get_font(UmlNormalItalicFont) : the_canvas()->get_font(UmlNormalFont)); p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name, p.font(), fp); p.setFont(the_canvas()->get_font(UmlNormalFont)); if (used_view_mode == asClass) { r.setTop(r.top() + he); p.drawLine(r.topLeft(), r.topRight()); if (fp != 0) fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.left(), r.top(), r.right(), r.top()); r.setTop(r.top() + (int) (8 * zoom)); p.drawLine(r.topLeft(), r.topRight()); if (fp != 0) fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.left(), r.top(), r.right(), r.top()); } if (fp != 0) fputs("</g>\n", fp); p.setBackgroundColor(bckgrnd); if (selected()) show_mark(p, rect()); }
void HeatMapVisualization::renderVisualization() { QColor color; int h, v, s, a; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { if (heatMap[i][j] == 0) {// er is niet geklikt h = 255; v = 0; s = 255; a = 0; color.setHsv(h,v,s,a); heatMapImage->setPixel(j, i, color.rgba()); } else {// geklikt s = 255; float value = float(heatMap[i][j])/float(maxClicks);// verhouding: is op deze plaats veel geklikt v = value * 255.0; a = v * 1/30; if (value > 0.333){//matig tot veel geklikt => de kleuren geel tot rood hiervoor gebruiken float inversDiff = 3/2, min = 1/3; int color = 60;//==colorRange //0 rood //60 geel h = color - (inversDiff * (value - min)) * color; if (heatMap[i][j] > maxClicks) { h = 0; v = 255;//in deze omgeving is heel veel geklikt s = 230;// => extra benadrukken } } else {// weinig geklikt (marge rond klik) => blauw tinten float inversDiff = 3/1, min = 0; int color = 240; int colorRange = 180; //60 geel //240 blauw h = color - (inversDiff * (value - min)) * colorRange; } //qDebug() << "color " << h << v << s; color.setHsv(h,v,s,a); heatMapImage->setPixel(j, i, color.rgba()); } } } //muisbewigingen tekenen QPainter painter; painter.begin(heatMapImage); for(int i = 0; i + 1 < mouseRoute->size(); ++i){ QLineF line(mouseRoute->at(i), mouseRoute->at(i+1)); painter.drawLine(line); } painter.end(); scene->setBackgroundImage(determineBackgroundImage(lastEventTime)); scene->setForegroundImage(heatMapImage); scene->invalidate(); }
BalloonMsg::BalloonMsg(void *param, const QString &_text, QStringList &btn, QWidget *parent, const QRect *rcParent, bool bModal, bool bAutoHide, unsigned bwidth, const QString &box_msg, bool *bChecked) : QDialog(parent, "ballon", bModal, (bAutoHide ? WType_Popup : WType_TopLevel | WStyle_StaysOnTop) | WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool | WDestructiveClose | WX11BypassWM) { m_param = param; m_parent = parent; m_width = bwidth; m_bAutoHide = bAutoHide; m_bYes = false; m_bChecked = bChecked; bool bTailDown = true; setPalette(QToolTip::palette()); text = _text; QFrame *frm = new QFrame(this); frm->setPalette(palette()); QVBoxLayout *vlay = new QVBoxLayout(frm); vlay->setMargin(0); m_check = NULL; if (!box_msg.isEmpty()){ m_check = new QCheckBox(box_msg, frm); vlay->addWidget(m_check); if (m_bChecked) m_check->setChecked(*m_bChecked); } QHBoxLayout *lay = new QHBoxLayout(vlay); lay->setSpacing(5); lay->addStretch(); unsigned id = 0; bool bFirst = true; for (QStringList::Iterator it = btn.begin(); it != btn.end(); ++it, id++){ BalloonButton *b = new BalloonButton(*it, frm, id); connect(b, SIGNAL(action(int)), this, SLOT(action(int))); lay->addWidget(b); if (bFirst){ b->setDefault(true); bFirst = false; } } setButtonsPict(this); lay->addStretch(); int wndWidth = frm->minimumSizeHint().width(); int hButton = frm->minimumSizeHint().height(); int txtWidth = bwidth; QRect rc; if (rcParent){ rc = *rcParent; }else{ QPoint p = parent->mapToGlobal(parent->rect().topLeft()); rc = QRect(p.x(), p.y(), parent->width(), parent->height()); } if (rc.width() > txtWidth) txtWidth = rc.width(); QSimpleRichText richText(_text, font(), "", QStyleSheet::defaultSheet(), QMimeSourceFactory::defaultFactory(), -1, Qt::blue, false); richText.setWidth(wndWidth); richText.adjustSize(); QSize s(richText.widthUsed(), richText.height()); QSize sMin = frm->minimumSizeHint(); if (s.width() < sMin.width()) s.setWidth(sMin.width()); int BALLOON_SHADOW = BALLOON_SHADOW_DEF; #ifdef WIN32 /* FIXME */ /* if ((GetClassLong(winId(), GCL_STYLE) & CS_DROPSHADOW) && style().inherits("QWindowsXPStyle")) BALLOON_SHADOW = 0; */ #endif resize(s.width() + BALLOON_R * 2 + BALLOON_SHADOW, s.height() + BALLOON_R * 2 + BALLOON_TAIL + BALLOON_SHADOW + hButton + BALLOON_MARGIN); mask = QBitmap(width(), height()); int w = width() - BALLOON_SHADOW; int tailX = w / 2; int posX = rc.left() + rc.width() / 2 + BALLOON_TAIL_WIDTH - tailX; if (posX <= 0) posX = 1; QRect rcScreen = screenGeometry(); if (posX + width() >= rcScreen.width()) posX = rcScreen.width() - 1 - width(); int tx = posX + tailX - BALLOON_TAIL_WIDTH; if (tx < rc.left()) tx = rc.left(); if (tx > rc.left() + rc.width()) tx = rc.left() + rc.width(); tailX = tx + BALLOON_TAIL_WIDTH - posX; if (tailX < BALLOON_R) tailX = BALLOON_R; if (tailX > width() - BALLOON_R - BALLOON_TAIL_WIDTH) tailX = width() - BALLOON_R - BALLOON_TAIL_WIDTH; if (rc.top() <= height() + 2){ bTailDown = false; move(posX, rc.top() + rc.height() + 1); }else{ move(posX, rc.top() - height() - 1); } int pos = 0; int h = height() - BALLOON_SHADOW - BALLOON_TAIL; if (!bTailDown) pos += BALLOON_TAIL; textRect.setRect(BALLOON_R, pos + BALLOON_R, w - BALLOON_R * 2, h); frm->resize(s.width(), hButton); frm->move(BALLOON_R, pos + h - BALLOON_R - hButton); QPainter p; p.begin(&mask); #ifdef WIN32 QColor bg(255, 255, 255); QColor fg(0, 0, 0); #else QColor bg(0, 0, 0); QColor fg(255, 255, 255); #endif p.fillRect(0, 0, width(), height(), bg); p.fillRect(0, pos + BALLOON_R, w, h - BALLOON_R * 2, fg); p.fillRect(BALLOON_R, pos, w - BALLOON_R * 2, h, fg); p.fillRect(BALLOON_SHADOW, pos + BALLOON_R + BALLOON_SHADOW, w, h - BALLOON_R * 2, fg); p.fillRect(BALLOON_R + BALLOON_SHADOW, pos + BALLOON_SHADOW, w - BALLOON_R * 2, h, fg); p.setBrush(fg); p.drawEllipse(0, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(0, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(BALLOON_SHADOW, pos + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2 + BALLOON_SHADOW, pos + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2 + BALLOON_SHADOW, pos + h - BALLOON_R * 2 + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(BALLOON_SHADOW, pos + h - BALLOON_R * 2 + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); QPointArray arr(3); arr.setPoint(0, tailX, bTailDown ? h : pos); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH, bTailDown ? h : pos); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH, bTailDown ? height() - BALLOON_SHADOW : 0); p.drawPolygon(arr); arr.setPoint(0, tailX + BALLOON_SHADOW, (bTailDown ? h : pos) + BALLOON_SHADOW); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH + BALLOON_SHADOW, (bTailDown ? h : pos) + BALLOON_SHADOW); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH + BALLOON_SHADOW, bTailDown ? height() : BALLOON_SHADOW); p.drawPolygon(arr); p.end(); setMask(mask); qApp->syncX(); QPixmap pict = QPixmap::grabWindow(QApplication::desktop()->winId(), x(), y(), width(), height()); intensity(pict, -0.50f); p.begin(&pict); p.setBrush(colorGroup().background()); p.drawEllipse(0, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(0, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); arr.setPoint(0, tailX, bTailDown ? h - 1 : pos + 1); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH, bTailDown ? h - 1 : pos + 1); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH, bTailDown ? height() - BALLOON_SHADOW : 0); p.drawPolygon(arr); p.fillRect(0, pos + BALLOON_R, w, h - BALLOON_R * 2, colorGroup().background()); p.fillRect(BALLOON_R, pos, w - BALLOON_R * 2, h, colorGroup().background()); p.drawLine(0, pos + BALLOON_R, 0, pos + h - BALLOON_R); p.drawLine(w - 1, pos + BALLOON_R, w - 1, pos + h - BALLOON_R); if (bTailDown){ p.drawLine(BALLOON_R, 0, w - BALLOON_R, 0); p.drawLine(BALLOON_R, h - 1, tailX, h - 1); p.drawLine(tailX + BALLOON_TAIL_WIDTH, h - 1, w - BALLOON_R, h - 1); }else{ p.drawLine(BALLOON_R, pos + h - 1, w - BALLOON_R, pos + h - 1); p.drawLine(BALLOON_R, pos, tailX, pos); p.drawLine(tailX + BALLOON_TAIL_WIDTH, pos, w - BALLOON_R, pos); } p.end(); setBackgroundPixmap(pict); setAutoMask(true); if (!bAutoHide) setFocusPolicy(NoFocus); QWidget *top = NULL; if (parent) top = parent->topLevelWidget(); if (top){ raiseWindow(top); top->installEventFilter(this); } }
void Graph::paintGraph(QPainter &painter) const { // reset brush and pen, paint the edge painter.setBrush(Qt::black); painter.setPen(QColor(0,0,0)); // paint all the nodes based on their state for (long i = 0; i < nodeNum_; ++i) { switch(nodes_[i].currentState_) { case CANDIDATE: painter.setBrush(Qt::black); painter.setPen(QColor(0,0,0)); break; case DOMINATOR: painter.setBrush(Qt::red); painter.setPen(QColor(255, 0, 0)); break; case DOMINATEE: painter.setBrush(Qt::green); painter.setPen(QColor(0, 255, 0)); break; case CONNECTOR: painter.setBrush(Qt::blue); painter.setPen(QColor(0, 0, 255)); break; } painter.drawEllipse(nodes_[i].position_.first, nodes_[i].position_.second, 5, 5); } // reset brush and pen, paint the edge painter.setBrush(Qt::black); painter.setPen(QColor(0,0,0)); for(long i = 0; i < edgeNum_; ++i) { long s = edges_[i].start_; long e = edges_[i].end_; #if 0 // whether the two nodes are CONNECTOR or DOMINATOR if ( (nodes_[s].currentState_ == DOMINATOR || nodes_[s].currentState_ == CONNECTOR) && (nodes_[e].currentState_ == DOMINATOR || nodes_[e].currentState_ == CONNECTOR) ) { painter.setBrush(Qt::red); painter.setPen(QColor(255, 0, 0)); } else { painter.setBrush(Qt::black); painter.setPen(QColor(0, 0, 0)); } #endif // painter.drawLine(nodes_[s].position_.first, nodes_[s].position_.second, nodes_[e].position_.first, nodes_[e].position_.second); } // if the keylinks is not empty, paint the keylinks if (keyLinks_.empty()) { return; } painter.setBrush(Qt::red); painter.setPen(QColor(255, 0, 0)); for (auto it = keyLinks_.begin(); it != keyLinks_.end(); ++it) { long s = it->start_; long e = it->end_; painter.drawLine(nodes_[s].position_.first, nodes_[s].position_.second, nodes_[e].position_.first, nodes_[e].position_.second); } }
//-------------------------------------------------------------------------------------------- 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 Matrix::print() { QPrinter printer; printer.setColorMode (QPrinter::GrayScale); if (printer.setup()) { printer.setFullPage( TRUE ); QPainter p; if ( !p.begin(&printer ) ) return; // paint on printer QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins QHeader *hHeader = d_table->horizontalHeader(); QHeader *vHeader = d_table->verticalHeader(); int rows=d_table->numRows(); int cols=d_table->numCols(); int height=margin; int i,vertHeaderWidth=vHeader->width(); int right = margin + vertHeaderWidth; // print header p.setFont(QFont()); QRect br=p.boundingRect(br,Qt::AlignCenter, hHeader->label(0),-1,0); p.drawLine(right,height,right,height+br.height()); QRect tr(br); for (i=0;i<cols;i++) { int w=d_table->columnWidth (i); tr.setTopLeft(QPoint(right,height)); tr.setWidth(w); tr.setHeight(br.height()); p.drawText(tr,Qt::AlignCenter,hHeader->label(i),-1); right+=w; p.drawLine(right,height,right,height+tr.height()); if (right >= metrics.width()-2*margin ) break; } p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line height+=tr.height(); p.drawLine(margin,height,right-1,height); // print d_table values for (i=0;i<rows;i++) { right=margin; QString text=vHeader->label(i)+"\t"; tr=p.boundingRect(tr,Qt::AlignCenter,text,-1,0); p.drawLine(right,height,right,height+tr.height()); br.setTopLeft(QPoint(right,height)); br.setWidth(vertHeaderWidth); br.setHeight(tr.height()); p.drawText(br,Qt::AlignCenter,text,-1); right+=vertHeaderWidth; p.drawLine(right,height,right,height+tr.height()); for (int j=0;j<cols;j++) { int w=d_table->columnWidth (j); text=d_table->text(i,j)+"\t"; tr=p.boundingRect(tr,Qt::AlignCenter,text,-1,0); br.setTopLeft(QPoint(right,height)); br.setWidth(w); br.setHeight(tr.height()); p.drawText(br,Qt::AlignCenter,text,-1); right+=w; p.drawLine(right,height,right,height+tr.height()); if (right >= metrics.width()-2*margin ) break; } height+=br.height(); p.drawLine(margin,height,right-1,height); if (height >= metrics.height()-margin ) { printer.newPage(); height=margin; p.drawLine(margin,height,right,height); } } } }
void PaintLine::draw(QPainter& painter) { QPointF p1(m_from[0], m_from[1]); QPointF p2(m_to[0], m_to[1]); painter.drawLine(p1, p2); }
void WaveformRenderMark::generateMarkImage(WaveformMark& mark) { // Load the pixmap from file -- takes precedence over text. if (mark.m_pixmapPath != "") { QString path = mark.m_pixmapPath; QImage image = QImage(path); // If loading the image didn't fail, then we're done. Otherwise fall // through and render a label. if (!image.isNull()) { mark.m_image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); WImageStore::correctImageColors(&mark.m_image); return; } } QPainter painter; int labelRectWidth = 0; int labelRectHeight = 0; // If no text is provided, leave m_markImage as a null image if (!mark.m_text.isNull()) { //QFont font("Bitstream Vera Sans"); //QFont font("Helvetica"); QFont font; // Uses the application default font.setPointSize(10); font.setStretch(100); QFontMetrics metrics(font); //fixed margin ... QRect wordRect = metrics.tightBoundingRect(mark.m_text); const int marginX = 1; const int marginY = 1; wordRect.moveTop(marginX + 1); wordRect.moveLeft(marginY + 1); wordRect.setWidth(wordRect.width() + (wordRect.width())%2); //even wordrect to have an even Image >> draw the line in the middle ! labelRectWidth = wordRect.width() + 2*marginX + 4; labelRectHeight = wordRect.height() + 2*marginY + 4 ; QRectF labelRect(0, 0, (float)labelRectWidth, (float)labelRectHeight); mark.m_image = QImage(labelRectWidth+1, m_waveformRenderer->getHeight(), QImage::Format_ARGB32_Premultiplied); if (mark.m_align == Qt::AlignBottom) { labelRect.moveBottom(mark.m_image.height()-1); } // Fill with transparent pixels mark.m_image.fill(QColor(0,0,0,0).rgba()); painter.begin(&mark.m_image); painter.setRenderHint(QPainter::TextAntialiasing); painter.setWorldMatrixEnabled(false); //draw the label rect QColor rectColor = mark.m_color; rectColor.setAlpha(150); painter.setPen(mark.m_color); painter.setBrush(QBrush(rectColor)); painter.drawRoundedRect(labelRect, 2.0, 2.0); //painter.drawRect(labelRect); //draw text painter.setBrush(QBrush(QColor(0,0,0,0))); font.setWeight(75); painter.setFont(font); painter.setPen(mark.m_textColor); painter.drawText(labelRect, Qt::AlignCenter, mark.m_text); //draw line QColor lineColor = mark.m_color; lineColor.setAlpha(200); painter.setPen(lineColor); float middle = mark.m_image.width() / 2.0; //Default line align top float lineTop = labelRectHeight + 1; float lineBottom = mark.m_image.height(); if (mark.m_align == Qt::AlignBottom) { lineTop = 0.0; lineBottom = mark.m_image.height() - labelRectHeight - 1; } painter.drawLine(middle, lineTop, middle, lineBottom); //other lines to increase contrast painter.setPen(QColor(0,0,0,120)); painter.drawLine(middle - 1, lineTop, middle - 1, lineBottom); painter.drawLine(middle + 1, lineTop, middle + 1, lineBottom); } else //no text draw triangle { float triangleSize = 9.0; mark.m_image = QImage(labelRectWidth+1, m_waveformRenderer->getHeight(), QImage::Format_ARGB32_Premultiplied); mark.m_image.fill(QColor(0,0,0,0).rgba()); painter.begin(&mark.m_image); painter.setRenderHint(QPainter::TextAntialiasing); painter.setWorldMatrixEnabled(false); QColor triangleColor = mark.m_color; triangleColor.setAlpha(140); painter.setPen(QColor(0,0,0,0)); painter.setBrush(QBrush(triangleColor)); //vRince: again don't ask about the +-0.1 0.5 ... // just to make it nice in Qt ... QPolygonF triangle; triangle.append(QPointF(0.5,0)); triangle.append(QPointF(triangleSize+0.5,0)); triangle.append(QPointF(triangleSize*0.5 + 0.1, triangleSize*0.5)); painter.drawPolygon(triangle); triangle.clear(); triangle.append(QPointF(0.0,mark.m_image.height())); triangle.append(QPointF(triangleSize+0.5,mark.m_image.height())); triangle.append(QPointF(triangleSize*0.5 + 0.1, mark.m_image.height() - triangleSize*0.5 - 2.1)); painter.drawPolygon(triangle); //TODO vRince duplicated code make a method //draw line QColor lineColor = mark.m_color; lineColor.setAlpha(140); painter.setPen(lineColor); float middle = mark.m_image.width() / 2.0; float lineTop = triangleSize * 0.5 + 1; float lineBottom = mark.m_image.height() - triangleSize * 0.5 - 1; painter.drawLine(middle, lineTop, middle, lineBottom); //other lines to increase contrast painter.setPen(QColor(0,0,0,100)); painter.drawLine(middle - 1, lineTop, middle - 1, lineBottom); painter.drawLine(middle + 1, lineTop, middle + 1, lineBottom); } }
void ZoomWidget::doPainting(QPainter& painter) { //paint the screenshot if(!m_pixmap.isNull()) { QPixmap scaled = m_pixmap.copy(QRect(QPoint(0, 0), size() / m_zoomFactor)); scaled = scaled.scaled(scaled.size()*m_zoomFactor); painter.drawPixmap(rulerWidth, rulerWidth, scaled); } //mark active pixels QPen pen; pen.setStyle(Qt::SolidLine); pen.setColor(QColor(255, 0, 0, 100)); painter.setPen(pen); QBrush brush(QColor(255, 0, 0, 100)); if(m_markColor.isValid()) { QImage image = m_pixmap.toImage(); for(int x=0;x<m_pixmap.size().width();x++) { for(int y=0;y<m_pixmap.size().height();y++) { if(image.pixel(x, y)==m_markColor.rgb()) { //painter.drawRect(rulerWidth+x*m_zoomFactor, rulerWidth+y*m_zoomFactor, m_zoomFactor, m_zoomFactor); painter.fillRect(QRect(rulerWidth+x*m_zoomFactor, rulerWidth+y*m_zoomFactor, m_zoomFactor, m_zoomFactor), brush); } } } } //draw grid if(m_gridColor.isValid()) { pen.setStyle(Qt::SolidLine); QColor gridPenColor(m_gridColor); gridPenColor.setAlpha(200); pen.setColor(gridPenColor); painter.setPen(pen); static const int gridSize=10; for(int x=rulerWidth;x<width();x+=gridSize*m_zoomFactor) { painter.drawLine(x, rulerWidth, x, height()-rulerWidth); } for(int y=rulerWidth;y<height();y+=gridSize*m_zoomFactor) { painter.drawLine(rulerWidth, y, width()-rulerWidth, y); } } pen.setStyle(Qt::SolidLine); pen.setColor(QColor(0, 0, 0)); painter.setPen(pen); //draw the rulers: painter.fillRect (0, 0, width(), rulerWidth, QBrush(QColor(255, 255, 255))); painter.fillRect (0, 0, rulerWidth, height(), QBrush(QColor(255, 255, 255))); //draw the ruler ticks QFont font; font.setPointSize(6); painter.setFont(font); for(int i=0;i<(width()-rulerWidth)/(20);i++) { int x = i*20 + rulerWidth; if(i%2==0) { painter.drawLine(x, rulerWidth-8, x, rulerWidth); painter.drawText(QRect(x-9, 2, 18, 10), Qt::AlignCenter, QString("%1").arg(i*20/m_zoomFactor)); } else { painter.drawLine(x, rulerWidth-5, x, rulerWidth); } } for(int i=0;i<(height()-rulerWidth)/(20);i++) { int y = i*20 + rulerWidth; if(i%2==0) { painter.drawLine(rulerWidth-8, y, rulerWidth, y); painter.drawText(QRect(2, y-9, 10, 18), Qt::AlignCenter, QString("%1").arg(i*20/m_zoomFactor)); } else { painter.drawLine(rulerWidth-5, y, rulerWidth, y); } } //draw the lines QList<int> posX; QList<int> posY; for(int i=0;i<lines.count();i++) { if(hasCurrentLine && i==currentLine) { QPen pen; pen.setStyle(Qt::DashLine); pen.setColor(QColor(255, 0, 0)); painter.setPen(pen); } else { QPen pen; pen.setStyle(Qt::SolidLine); pen.setColor(QColor(0, 0, 255)); painter.setPen(pen); } Line* line = lines.at(i); if(line->orientation == Qt::Horizontal) { painter.drawLine(line->position*m_zoomFactor + rulerWidth, rulerWidth, line->position*m_zoomFactor + rulerWidth, height()); posX << line->position; } else if (line->orientation == Qt::Vertical) { painter.drawLine(rulerWidth, line->position*m_zoomFactor + rulerWidth, width(), line->position*m_zoomFactor + rulerWidth); posY << line->position; } } //on the edgre make 30px lighter painter.fillRect(rulerWidth, height()-30, width(), 30, QBrush(QColor(255, 255, 255, 200))); painter.fillRect(width()-30, rulerWidth, 30, height()-rulerWidth-30, QBrush(QColor(255, 255, 255, 200))); //array for the pointer <---> static const QPoint arrowPoints[3] = { QPoint(0, 0), QPoint(8, 4), QPoint(0, 8) }; //measure the number of px between the lines (x) qSort(posX); font.setPointSize(8); painter.setFont(font); painter.setPen(QColor(0, 0, 0)); int last = 0; foreach(int x, posX) { painter.drawLine(last*m_zoomFactor + rulerWidth, height()-10, x*m_zoomFactor + rulerWidth, height()-10); painter.drawText(QRect(last*m_zoomFactor + rulerWidth, height()-30, (x-last)*m_zoomFactor, 20), Qt::AlignCenter | Qt::AlignBottom, QString("%1").arg(x-last)); bool arrowOnOutside = false; if((x-last)*m_zoomFactor < 40) { qSwap(x, last); arrowOnOutside = true; } painter.save(); //arrow right painter.setBrush(QBrush(QColor(0, 0, 0))); painter.translate(x*m_zoomFactor + rulerWidth-8, height()-10 -4); painter.drawPolygon(arrowPoints, 3, Qt::WindingFill); //arrow left painter.translate((last-x)*m_zoomFactor+16, 8); painter.rotate(180); painter.drawPolygon(arrowPoints, 3); painter.restore(); if(!arrowOnOutside) //else qSwaped allready last = x; }
void Annotation1DCaret::draw(Spectrum1DCanvas* const canvas, QPainter& painter, bool flipped) { painter.save(); painter.setPen(color_); // translate mz/intensity to pixel coordinates QPoint position_widget, caret_position_widget; canvas->dataToWidget(position_.getX(), position_.getY(), position_widget, flipped, true); canvas->dataToWidget(caret_positions_[0].getX(), caret_positions_[0].getY(), caret_position_widget, flipped, true); //std::cerr << "color" << color_.value() << " "; // draw ticks (for now) if (!caret_positions_.empty()) { QPoint caret; // draw ^ to indicate theoretical position for (PositionsType::iterator it = caret_positions_.begin(); it != caret_positions_.end(); ++it) { canvas->dataToWidget(it->getX(), it->getY(), caret, flipped, true); painter.drawLine(caret.x(), caret.y(), caret.x()+4, caret.y() + 4); painter.drawLine(caret.x(), caret.y(), caret.x()-4, caret.y() + 4); //std::cout << "caret: " << caret.x() << "," << caret.y() << "\n"; } } // compute bounding box of text_item on the specified painter bounding_box_ = QRectF(position_widget, st_.size()); //std::cout << "posP: " << position_.getX() << "," << position_.getY() << "\n"; //std::cout << "posW: " << position_widget.x() << "," << position_widget.y() << "\n"; //std::cout <<"init BB topleft: " << bounding_box_.topLeft().x() << "," << bounding_box_.topLeft().y() <<"\n"; DoubleReal vertical_shift = 0; DoubleReal horizontal_shift = 0; if (canvas->isMzToXAxis()) { // shift pos - annotation should be over peak or, if not possible, next to it vertical_shift = bounding_box_.height() / 2 + 5; if (!flipped) { vertical_shift *= -1; } bounding_box_.translate(0.0, vertical_shift); if (flipped && bounding_box_.bottom() > canvas->height()) { bounding_box_.moveBottom(canvas->height()); bounding_box_.moveLeft(position_widget.x() + 5.0); } else if (!flipped && bounding_box_.top() < 0.0) { bounding_box_.moveTop(0.0); bounding_box_.moveLeft(position_widget.x() + 5.0); } } else { // annotation should be next to the peak (to its right) horizontal_shift = bounding_box_.width() / 2 + 5; bounding_box_.translate(horizontal_shift, 0.0); if (bounding_box_.right() > canvas->width()) { bounding_box_.moveRight(canvas->width()); } } // draw connection line between anchor point and current position if pixel coordinates differ significantly if ((position_widget - caret_position_widget).manhattanLength() > 2) { // check if line crosses bounding box, if so move line startpoint to correct bounding box intersection QLineF line(caret_position_widget, position_widget + QPoint(horizontal_shift, vertical_shift)); QLineF top(bounding_box_.x(), bounding_box_.y(), bounding_box_.x() + bounding_box_.width(), bounding_box_.y()); QLineF left(bounding_box_.x(), bounding_box_.y(), bounding_box_.x(), bounding_box_.y() + bounding_box_.height()); QLineF right(bounding_box_.x() + bounding_box_.width(), bounding_box_.y(), bounding_box_.x() + bounding_box_.width(), bounding_box_.y() + bounding_box_.height()); QLineF bottom(bounding_box_.x(), bounding_box_.y() + bounding_box_.height(), bounding_box_.x() + bounding_box_.width(), bounding_box_.y() + bounding_box_.height()); QLineF::IntersectType itype; QPointF * ip = new QPointF(); QPointF * closest_ip = new QPointF(-10e10, -10e10); bool found_intersection = false; // intersection with top itype = line.intersect(top, ip); if (itype == QLineF::BoundedIntersection && QLineF(caret_position_widget, *ip).length() < QLineF(caret_position_widget, *closest_ip).length()) { found_intersection = true; *closest_ip = *ip; } // intersection with left itype = line.intersect(left, ip); if (itype == QLineF::BoundedIntersection && QLineF(caret_position_widget, *ip).length() < QLineF(caret_position_widget, *closest_ip).length()) { found_intersection = true; *closest_ip = *ip; } // intersection with right itype = line.intersect(right, ip); if (itype == QLineF::BoundedIntersection && QLineF(caret_position_widget, *ip).length() < QLineF(caret_position_widget, *closest_ip).length()) { found_intersection = true; *closest_ip = *ip; } // intersection with bottom itype = line.intersect(bottom, ip); if (itype == QLineF::BoundedIntersection && QLineF(caret_position_widget, *ip).length() < QLineF(caret_position_widget, *closest_ip).length()) { found_intersection = true; *closest_ip = *ip; } painter.save(); painter.setPen(Qt::DashLine); if (!found_intersection) // no intersection with bounding box of text -> normal drawing { painter.drawLine(caret_position_widget, position_widget); painter.drawLine(caret_position_widget, position_widget); } else { painter.drawLine(caret_position_widget, *closest_ip); painter.drawLine(caret_position_widget, *closest_ip); } painter.restore(); delete(ip); delete(closest_ip); } //painter.drawText(bounding_box_, Qt::AlignLeft, text_); //std::cout << "Text to draw: " << st_.text() << " @ " << bounding_box_.topLeft().x() << "," << bounding_box_.topLeft().y() << "\n\n"; painter.drawStaticText(bounding_box_.topLeft(), st_); //QRect rect = QRect(10, 30, 180, 20); //painter.translate( rect.topLeft() ); //doc_.drawContents( &painter, bounding_box_ ); //painter. if (selected_) { drawBoundingBox_(painter); } painter.restore(); }
/** coloridx: 0 - yellow, 1 - red, 2 - green, 3 - blue, if < 0 - only position without bounding box is drawn */ void draw_bbox(QPainter &painter, const PartBBox &part_bbox, int coloridx, int pen_width) { if (coloridx >= 0) { painter.setPen(Qt::yellow); int marker_radius = 3; int part_axis_length = 10; painter.drawEllipse(QRect((int)(part_bbox.part_pos(0) - marker_radius), (int)(part_bbox.part_pos(1) - marker_radius), 2*marker_radius, 2*marker_radius)); boost_math::double_vector v(2); v = part_bbox.part_pos + part_axis_length * part_bbox.part_x_axis; painter.drawLine((int)part_bbox.part_pos(0), (int)part_bbox.part_pos(1), (int)v(0), (int)v(1)); painter.setPen(Qt::red); v = part_bbox.part_pos + part_axis_length * part_bbox.part_y_axis; painter.drawLine((int)part_bbox.part_pos(0), (int)part_bbox.part_pos(1), (int)v(0), (int)v(1)); painter.setPen(Qt::yellow); QPen pen; if (coloridx == 0) pen.setColor(Qt::yellow); else if (coloridx == 1) pen.setColor(Qt::red); else if (coloridx == 2) pen.setColor(Qt::green); else if (coloridx == 3) pen.setColor(Qt::blue); else pen.setColor(Qt::black); pen.setJoinStyle(Qt::RoundJoin); pen.setWidth(pen_width); painter.setPen(pen); QPolygonF polygon; get_part_polygon(part_bbox, polygon); painter.drawPolygon(polygon); } else { painter.setPen(Qt::yellow); if (coloridx == -1) painter.setPen(Qt::yellow); else if (coloridx == -2) painter.setPen(Qt::red); else if (coloridx == -3) painter.setPen(Qt::green); else painter.setPen(Qt::blue); int x = part_bbox.part_pos(0); int y = part_bbox.part_pos(1); painter.drawLine(x-1, y, x+1, y); painter.drawLine(x, y-1, x, y+1); } }
void RowArea::drawOnionSkinSelection(QPainter &p) { TApp *app = TApp::instance(); OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask(); TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet(); assert(xsh); int currentRow = m_viewer->getCurrentRow(); // get onion colors TPixel frontPixel, backPixel; bool inksOnly; Preferences::instance()->getOnionData(frontPixel, backPixel, inksOnly); QColor frontColor((int)frontPixel.r, (int)frontPixel.g, (int)frontPixel.b, 128); QColor backColor((int)backPixel.r, (int)backPixel.g, (int)backPixel.b, 128); int onionDotDiam = 8; int onionHandleDiam = RowHeight - 1; int onionDotYPos = (RowHeight - onionDotDiam) / 2; // If the onion skin is disabled, draw dash line instead. if (osMask.isEnabled()) p.setPen(Qt::red); else { QPen currentPen = p.pen(); currentPen.setStyle(Qt::DashLine); currentPen.setColor(QColor(128, 128, 128, 255)); p.setPen(currentPen); } // Draw onion skin extender handles. QRectF handleRect(3, m_viewer->rowToY(currentRow) + 1, onionHandleDiam, onionHandleDiam); int angle180 = 16 * 180; p.setBrush(QBrush(backColor)); p.drawChord(handleRect, 0, angle180); p.setBrush(QBrush(frontColor)); p.drawChord(handleRect, angle180, angle180); //-- draw movable onions // draw line between onion skin range int minMos = 0; int maxMos = 0; int mosCount = osMask.getMosCount(); for (int i = 0; i < mosCount; i++) { int mos = osMask.getMos(i); if (minMos > mos) minMos = mos; if (maxMos < mos) maxMos = mos; } p.setBrush(Qt::NoBrush); if (minMos < 0) // previous frames { int y0 = m_viewer->rowToY(currentRow + minMos) + onionDotYPos + onionDotDiam; int y1 = m_viewer->rowToY(currentRow); p.drawLine(onionDotDiam*1.5, y0, onionDotDiam*1.5, y1); } if (maxMos > 0) // foward frames { int y0 = m_viewer->rowToY(currentRow + 1); int y1 = m_viewer->rowToY(currentRow + maxMos) + onionDotYPos; p.drawLine(onionDotDiam*1.5, y0, onionDotDiam*1.5, y1); } // draw onion skin dots p.setPen(Qt::red); for (int i = 0; i < mosCount; i++) { // mos : frame offset from the current frame int mos = osMask.getMos(i); // skip drawing if the frame is under the mouse cursor if (m_showOnionToSet == Mos && currentRow + mos == m_row) continue; int y = m_viewer->rowToY(currentRow + mos) + onionDotYPos; if (osMask.isEnabled()) p.setBrush(mos < 0 ? backColor : frontColor); else p.setBrush(Qt::NoBrush); p.drawEllipse(onionDotDiam, y, onionDotDiam, onionDotDiam); } //-- draw fixed onions for (int i = 0; i < osMask.getFosCount(); i++) { int fos = osMask.getFos(i); if (fos == currentRow) continue; // skip drawing if the frame is under the mouse cursor if (m_showOnionToSet == Fos && fos == m_row) continue; int y = m_viewer->rowToY(fos) + onionDotYPos; if (osMask.isEnabled()) p.setBrush(QBrush(QColor(0, 255, 255, 128))); else p.setBrush(Qt::NoBrush); p.drawEllipse(0, y, onionDotDiam, onionDotDiam); } //-- draw highlighted onion if (m_showOnionToSet != None) { int y = m_viewer->rowToY(m_row) + onionDotYPos; int xPos = (m_showOnionToSet == Fos) ? 0 : onionDotDiam; p.setPen(QColor(255, 128, 0)); p.setBrush(QBrush(QColor(255, 255, 0, 200))); p.drawEllipse(xPos, y, onionDotDiam, onionDotDiam); } }
//----------------------------------------------------------- void CenaObjetos::definirGrade(unsigned tam) { if(tam >= 20 || grade.style()==Qt::NoBrush) { QImage img_grade; float larg, alt, x, y; QSizeF tam_aux; QPrinter printer; QPainter painter; QPen pen; //Caso o tamanho do papel não seja personalizado if(tam_papel!=QPrinter::Custom) { //Configura um dispositivo QPrinter para obter os tamanhos de página printer.setPageSize(tam_papel); printer.setOrientation(orientacao_pag); printer.setPageMargins(margens_pag.left(), margens_pag.top(), margens_pag.right(), margens_pag.bottom(), QPrinter::Millimeter); tam_aux=printer.pageRect(QPrinter::DevicePixel).size(); } //Caso o tipo de papel seja personalizado, usa as margens como tamanho do papel else tam_aux=margens_pag.size(); larg=fabs(roundf(tam_aux.width()/static_cast<float>(tam)) * tam); alt=fabs(roundf(tam_aux.height()/static_cast<float>(tam)) * tam); //Cria uma instância de QImage para ser a textura do brush tam_grade=tam; img_grade=QImage(larg, alt, QImage::Format_ARGB32); //Aloca um QPaointer para executar os desenhos sobre a imagem painter.begin(&img_grade); //Limpa a imagem painter.fillRect(QRect(0,0,larg,alt), QColor(255,255,255)); if(exibir_grade) { //Cria a grade pen.setColor(QColor(225, 225, 225)); painter.setPen(pen); for(x=0; x < larg; x+=tam) for(y=0; y < alt; y+=tam) painter.drawRect(QRectF(QPointF(x,y),QPointF(x + tam,y + tam))); } //Cria as linhas que definem o limite do papel if(exibir_lim_pagina) { pen.setColor(QColor(75,115,195)); pen.setStyle(Qt::DashLine); pen.setWidthF(1.85f); painter.setPen(pen); painter.drawLine(larg-1, 0,larg-1,alt-1); painter.drawLine(0, alt-1,larg-1,alt-1); } painter.end(); grade.setTextureImage(img_grade); } }
void RowArea::drawRows(QPainter &p, int r0, int r1) { int playR0, playR1, step; XsheetGUI::getPlayRange(playR0, playR1, step); if (!XsheetGUI::isPlayRangeEnabled()) { TXsheet *xsh = m_viewer->getXsheet(); playR1 = xsh->getFrameCount() - 1; playR0 = 0; } #ifdef _WIN32 static QFont font("Arial", XSHEET_FONT_SIZE, QFont::Bold); #else static QFont font("Helvetica", XSHEET_FONT_SIZE, QFont::Normal); #endif p.setFont(font); // marker interval int distance, offset; TApp::instance()->getCurrentScene()->getScene()->getProperties()->getMarkers(distance, offset); //default value if (distance == 0) distance = 6; QRect visibleRect = visibleRegion().boundingRect(); int x0 = visibleRect.left(); int x1 = visibleRect.right(); int y0 = visibleRect.top(); int y1 = visibleRect.bottom(); for (int r = r0; r <= r1; r++) { int y = m_viewer->rowToY(r); //--- draw horizontal line QColor color = ((r - offset) % distance != 0) ? m_viewer->getLightLineColor() : m_viewer->getMarkerLineColor(); p.setPen(color); p.drawLine(x0, y, x1, y); // draw frame text if (playR0 <= r && r <= playR1) { p.setPen(((r - m_r0) % step == 0) ? m_viewer->getPreviewFrameTextColor() : m_viewer->getTextColor()); } //not in preview range else p.setPen(m_viewer->getTextColor()); switch (m_viewer->getFrameDisplayStyle()) { case XsheetViewer::SecAndFrame: { int frameRate = TApp::instance()->getCurrentScene()->getScene()->getProperties()->getOutputProperties()->getFrameRate(); QString str; int koma = (r + 1) % frameRate; if (koma == 1) { int sec = (r + 1) / frameRate; str = QString("%1' %2\"").arg(QString::number(sec).rightJustified(2, '0')).arg(QString::number(koma).rightJustified(2, '0')); } else { if (koma == 0) koma = frameRate; str = QString("%1\"").arg(QString::number(koma).rightJustified(2, '0')); } p.drawText(QRect(width() / 2 - 15, y + 1, width() / 2 + 7, RowHeight - 2), Qt::AlignRight | Qt::AlignBottom, str); break; } case XsheetViewer::Frame: { QString number = QString::number(r + 1); p.drawText(QRect(width() / 2 - 2, y + 1, width() / 2, RowHeight - 2), Qt::AlignHCenter | Qt::AlignBottom, number); break; } //6 second sheet (144frames per page) case XsheetViewer::SixSecSheet: { int frameRate = TApp::instance()->getCurrentScene()->getScene()->getProperties()->getOutputProperties()->getFrameRate(); QString str; int koma = (r + 1) % (frameRate * 6); if ((r + 1) % frameRate == 1) { int page = (r + 1) / (frameRate * 6) + 1; str = QString("p%1 %2").arg(QString::number(page)).arg(QString::number(koma).rightJustified(3, '0')); } else { if (koma == 0) koma = frameRate * 6; str = QString("%1").arg(QString::number(koma).rightJustified(3, '0')); } p.drawText(QRect(width() / 2 - 21, y + 1, width() / 2 + 7, RowHeight - 2), Qt::AlignRight | Qt::AlignBottom, str); break; } //3 second sheet (72frames per page) case XsheetViewer::ThreeSecSheet: { int frameRate = TApp::instance()->getCurrentScene()->getScene()->getProperties()->getOutputProperties()->getFrameRate(); QString str; int koma = (r + 1) % (frameRate * 3); if ((r + 1) % frameRate == 1) { int page = (r + 1) / (frameRate * 3) + 1; str = QString("p%1 %2").arg(QString::number(page)).arg(QString::number(koma).rightJustified(2, '0')); } else { if (koma == 0) koma = frameRate * 3; str = QString("%1").arg(QString::number(koma).rightJustified(2, '0')); } p.drawText(QRect(width() / 2 - 21, y + 1, width() / 2 + 7, RowHeight - 2), Qt::AlignRight | Qt::AlignBottom, str); break; } } } // hide the top-most horizontal line if (r0 == 0) { p.setPen(m_viewer->getLightLineColor()); p.drawLine(x0, m_viewer->rowToY(0), x1, m_viewer->rowToY(0)); } }
void AnimationViewerPanel::renderCross(QPainter& painter) { painter.setPen(QColor(120, 150, 200)); painter.drawLine(QPoint(0, height() / 2), QPoint(width(), height() / 2)); painter.drawLine(QPoint(width() / 2, 0), QPoint(width() / 2, height())); }
void paintTree_one::paintNext() { vector<Node> nTemp; nTemp=this->m_tree->tree; int space_x, space_y; int lowCount=0;//树中出现终结符的个数,方便计算空间间隔宽度 int upCount=0;//树中出现终结符的个数,方便计算空间间隔高度 for(int j=nTemp.size()-1;j>=0;j--) { if(nTemp[j].y==0) { lowCount=nTemp[j].x+1;//x坐标从0开始的,所以要加一 break; } else { lowCount=0; continue; } } for(int j=nTemp.size()-1;j>=0;j--) { char temp=nTemp[j].key; if(temp=='A' || temp=='B' || temp=='S' ) { upCount=nTemp[j].y+1; //y坐标从0开始的,所以要加一 break; } else { upCount=0; continue; } } // int space_x=iWidth/(lowCount+1);//横向间隔 // int space_y=iHeight/(upCount+1);//纵向间隔 space_x=iWidth/(lowCount+1);//横向间隔 if(upCount==0) space_y=iHeight/3; else space_y=iHeight/(upCount+1);//纵向间隔 QString fileName; QPainter painter; //QPen pen; //pen.setWidth(2);//设置线的宽度为2个像素 int currentX; int currentY; int x,y,nY; if(iCount<nTemp.size()&&iCount>=0) { for(int i=0;i<=iCount;i++) { painter.begin(this); //painter.setPen(pen); fileName=charToName(nTemp[i].key); currentX=space_x*(nTemp[i].x+1); currentY=iHeight-space_y*(nTemp[i].y+1); QPixmap picture; picture.load(fileName); // painter.drawPixmap(currentX,currentY,picture); if(nTemp[i].key=='A')//画A->Ab或A->b的直线 { if(nTemp[i].y>1) { painter.drawPixmap(currentX,currentY,picture); painter.drawLine(space_x*(nTemp[i-2].x+1)+16,iHeight-space_y*(nTemp[i-2].y+1)+16,currentX+16,currentY+16); painter.drawLine(space_x*(nTemp[i-1].x+1)+16,iHeight-space_y*(nTemp[i-1].y+1)+16,currentX+16,currentY+16); painter.end(); } else { painter.drawPixmap(currentX,currentY,picture); painter.drawLine(currentX+16,currentY+space_y*nTemp[i].y+16,currentX+16,currentY+16); painter.end(); } } else if(nTemp[i].key=='B')//画B->d的直线 { findXY('A',x,y); nY=y; painter.drawPixmap(currentX,iHeight-space_y*(nY+1),picture); painter.drawLine(currentX+16,currentY+space_y*nTemp[i].y+16,currentX+16,iHeight-space_y*(nY+1)+16); painter.end(); } else if(nTemp[i].key=='S')//画S->aAcBe的所有直线 { painter.drawPixmap(currentX,currentY,picture); findXY('A',x,y); nY=y; findXY('a',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,currentX+16,currentY+16); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,space_x*(x+1)+16,iHeight-space_y*(y+1)+16); findXY('A',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(y+1)+16,currentX+16,currentY+16); findXY('c',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(y+1)+16,currentX+16,currentY+16); findXY('B',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,currentX+16,currentY+16); findXY('e',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,currentX+16,currentY+16); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,space_x*(x+1)+16,iHeight-space_y*(y+1)+16); painter.end(); } else { painter.drawPixmap(currentX,currentY,picture); painter.end(); } } } else if(iCount>=0) { painter.begin(this); for(int i=0;i<=nTemp.size();i++) { fileName=charToName(nTemp[i].key); currentX=space_x*(nTemp[i].x+1); currentY=iHeight-space_y*(nTemp[i].y+1); QPixmap picture; picture.load(fileName); // painter.drawPixmap(currentX,currentY,picture); if(nTemp[i].key=='A')//画A->Ab或A->b的直线 { if(nTemp[i].y>1) { painter.drawPixmap(currentX,currentY,picture); painter.drawLine(space_x*(nTemp[i-2].x+1)+16,iHeight-space_y*(nTemp[i-2].y+1)+16,currentX+16,currentY+16); painter.drawLine(space_x*(nTemp[i-1].x+1)+16,iHeight-space_y*(nTemp[i-1].y+1)+16,currentX+16,currentY+16); } else { painter.drawPixmap(currentX,currentY,picture); painter.drawLine(currentX+16,currentY+space_y*nTemp[i].y+16,currentX+16,currentY+16); } } else if(nTemp[i].key=='B')//画B->d的直线 { findXY('A',x,y); nY=y; painter.drawPixmap(currentX,iHeight-space_y*(nY+1),picture); painter.drawLine(currentX+16,currentY+space_y*nTemp[i].y+16,currentX+16,iHeight-space_y*(nY+1)+16); } else if(nTemp[i].key=='S')//画S->aAcBe的所有直线 { painter.drawPixmap(currentX,currentY,picture); findXY('A',x,y); nY=y; findXY('a',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,currentX+16,currentY+16); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,space_x*(x+1)+16,iHeight-space_y*(y+1)+16); findXY('A',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(y+1)+16,currentX+16,currentY+16); findXY('c',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(y+1)+16,currentX+16,currentY+16); findXY('B',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,currentX+16,currentY+16); findXY('e',x,y); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,currentX+16,currentY+16); painter.drawLine(space_x*(x+1)+16,iHeight-space_y*(nY+1)+16,space_x*(x+1)+16,iHeight-space_y*(y+1)+16); } else painter.drawPixmap(currentX,currentY,picture); } painter.end(); } }
ScopePlot::ScopePlot(LockBox *parent, unsigned int configOffset, QStringList *channelNames, double *p_dataIn, int N_dataIn) : QWidget(0), parent(parent), configOffset(configOffset), SETTING_WIDGETS_FROM_CONFIG(false), curves(N_PLOT_CHANNELS), channelSelectComboBoxes(N_PLOT_CHANNELS), channelScaleSpinBoxes(N_PLOT_CHANNELS), channelOffsetSpinBoxes(N_PLOT_CHANNELS), p_dataIn(p_dataIn), N_dataIn(N_dataIn) { plot = new QwtPlot(); plot->setMinimumSize(300, 200); QPalette pal; pal.setColor(QPalette::Window, Qt::white); plot->setPalette(pal); // We don't need the cache here // plot->canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false); // plot->canvas()->setPaintAttribute(QwtPlotCanvas::Opaque, false); // Axis plot->setAxisTitle(QwtPlot::xBottom, "Time [s]"); plot->setAxisScale(QwtPlot::xBottom, 0, 100); plot->setAxisScale(QwtPlot::yLeft, -5.0, 5.0); alignScales(); // Initialize data for (int i = 0; i < N_PLOT_DATA; i++) { data_x[i] = (20./(N_PLOT_DATA-1.)) * i; // time axis for(int j = 0; j < N_PLOT_CHANNELS; j++) data_y[j][i] = 0.0+0.0*j; } // Initialize plot curves for (int j = 0; j < N_PLOT_CHANNELS; j++) { curves[j] = new QwtPlotCurve("Trace " + QString::number(j+1)); switch (j) { case 0: curves[j]->setPen(QPen(Qt::red)); break; case 1: curves[j]->setPen(QPen(Qt::blue)); break; case 2: curves[j]->setPen(QPen(Qt::green)); break; case 3: curves[j]->setPen(QPen(Qt::magenta)); break; case 4: curves[j]->setPen(QPen(Qt::cyan)); break; default: curves[j]->setPen(QPen(Qt::black)); curves[j]->setStyle(QwtPlotCurve::Dots); } curves[j]->attach(plot); // Attach (don't copy) data. All curves use the same x array. curves[j]->setRawSamples(data_x, &(data_y[j][0]), N_PLOT_DATA); curves[j]->hide(); } QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(plot); // Make the mode combobox QHBoxLayout *hLayout = new QHBoxLayout(); mainLayout->addLayout(hLayout); hLayout->addWidget(new QLabel(tr("Mode:"))); modeComboBox = new QComboBox(); modeComboBox->addItem(tr("Off")); modeComboBox->addItem(tr("Rolling")); modeComboBox->addItem(tr("Triggered")); QObject::connect(modeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_modeComboBox_currentIndexChanged(int))); hLayout->addWidget(modeComboBox); hLayout->addStretch(); // Trigger channel select combo box triggerChannelSelectLabel = new QLabel(tr("Chan:")); hLayout->addWidget(triggerChannelSelectLabel); triggerChannelSelectComboBox = new QComboBox(); triggerChannelSelectComboBox->addItem(tr("Off")); for (int i = 0; i < channelNames->length(); i ++) { triggerChannelSelectComboBox->addItem(channelNames->value(i)); } hLayout->addWidget(triggerChannelSelectComboBox); // Trigger level spin box triggerLevelLabel = new QLabel(tr("Level:")); hLayout->addWidget(triggerLevelLabel); triggerLevelSpinBox = new VariableDoubleSpinBox(); triggerLevelSpinBox->setSuffix(tr(" V")); triggerLevelSpinBox->setRange(-100, 100); triggerLevelSpinBox->setDecimals(2); triggerLevelSpinBox->setSingleStep(0.1); triggerLevelSpinBox->setValue(0); hLayout->addWidget(triggerLevelSpinBox); on_modeComboBox_currentIndexChanged(modeComboBox->currentIndex()); // Make the trace selection comboboxes for (int j = 0; j < N_PLOT_CHANNELS; j++) { QHBoxLayout *hLayout = new QHBoxLayout(); mainLayout->addLayout(hLayout); // Pictorial sample of scope trace QPicture picture; QPainter painter; painter.begin(&picture); // paint in picture painter.setPen(curves[j]->pen()); painter.drawLine(0, 0, 20, 0); painter.end(); // painting done QLabel *label = new QLabel(); label->setPicture(picture); hLayout->addWidget(label); // Channel select combo box channelSelectComboBoxes[j] = new QComboBox(); channelSelectComboBoxes[j]->addItem(tr("Off")); for (int i = 0; i < channelNames->length(); i ++) { channelSelectComboBoxes[j]->addItem(channelNames->value(i)); } QObject::connect(channelSelectComboBoxes[j], SIGNAL(currentIndexChanged(int)), this, SLOT(on_channelSelectComboBox_currentIndexChanged(int))); channelSelectComboBoxes[j]->setCurrentIndex(j + 1); hLayout->addWidget(channelSelectComboBoxes[j]); // Scale spin box hLayout->addWidget(new QLabel(tr("Scale:"))); channelScaleSpinBoxes[j] = new VariableDoubleSpinBox(); channelScaleSpinBoxes[j]->setSuffix(tr(" V/div")); channelScaleSpinBoxes[j]->setRange(0.001, 100); channelScaleSpinBoxes[j]->setDecimals(3); channelScaleSpinBoxes[j]->setSingleStep(0.1); channelScaleSpinBoxes[j]->setValue(1); hLayout->addWidget(channelScaleSpinBoxes[j]); // Offset spin box hLayout->addWidget(new QLabel(tr("Offset:"))); channelOffsetSpinBoxes[j] = new VariableDoubleSpinBox(); channelOffsetSpinBoxes[j]->setSuffix(tr(" V")); channelOffsetSpinBoxes[j]->setRange(-100, 100); channelOffsetSpinBoxes[j]->setDecimals(3); channelOffsetSpinBoxes[j]->setSingleStep(0.1); channelOffsetSpinBoxes[j]->setValue(0); hLayout->addWidget(channelOffsetSpinBoxes[j]); // Connect on_displayParametersChanged QObject::connect(channelSelectComboBoxes[j], SIGNAL(currentIndexChanged(int)), this, SLOT(on_displayParametersChanged())); QObject::connect(channelScaleSpinBoxes[j], SIGNAL(valueChanged(double)), this, SLOT(on_displayParametersChanged())); QObject::connect(channelOffsetSpinBoxes[j], SIGNAL(valueChanged(double)), this, SLOT(on_displayParametersChanged())); hLayout->addStretch(); } }
void ManoMeter::paintBackground(QPainter & painter) { static const int scaleTriangle[6] = { -6,141,6,141,0,129 }; initCoordinateSystem(painter); // Painting Malowanie obwiedni tarczy. Bia�a tarcza z czarn� skal� QPen Pen(QColor(0,0,0)); Pen.setWidth(4); painter.setPen(Pen); QRadialGradient back1(QPointF(0.0,0.0),180.0,QPointF(-35.0,145.0)); back1.setColorAt(0.0,QColor(250,250,250)); back1.setColorAt(1.0,QColor(20,20,20)); QRadialGradient back2(QPointF(0.0,0.0),225.0,QPointF(76.5,135.0)); back2.setColorAt(0.0,QColor(10,10,10)); back2.setColorAt(1.0,QColor(250,250,250)); painter.setBrush(QBrush(back1)); painter.drawEllipse(-162,-162,324,324); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(back2)); painter.drawEllipse(-152,-152,304,304); QRadialGradient shield(QPointF(0,0),182,QPointF(-12.0,-15.0)); shield.setColorAt(0.0,Qt::white); shield.setColorAt(0.5,QColor(240,240,240)); shield.setColorAt(1.0,QColor(215,215,215)); // internal scale circle painter.setBrush(QBrush(shield)); painter.setPen(Pen); painter.drawEllipse(-142,-142,284,284); painter.setPen(Qt::NoPen); // nominal painter.setBrush(QColor(0,200,0)); assert(m_max-m_min != 0); int angle = static_cast<int>( (3840 * ( m_nominal - m_min ))/(m_max-m_min) ); if (m_min <= m_nominal && m_nominal < m_max ) painter.drawPie(QRect(-141,-141,282,282),-480,3840 - angle % 5760 ); // Critical painter.setBrush(QBrush(Qt::red)); angle = static_cast<int>( (3840 * ( m_critical - m_min ))/(m_max-m_min) ); if ( m_min <= m_critical && m_critical < m_max ) painter.drawPie(QRect(-141,-141,282,282),-480, 3840 - angle % 5760 ); //-480, 3840*( m_max-m_min - critical()-abs(m_min) )/static_cast<double>(m_max-m_min)); // bia�a obwiednia painter.setBrush(QBrush(shield)); painter.drawEllipse(-129,-129,258,258); // Ustawienie si� na pocz�tku skali painter.rotate(60.0); // Rysowanie skali kreski painter.save(); painter.setBrush(QBrush(Qt::black)); int line_length=10; for (int i=0;i<33;i++) { painter.setPen(Pen); if (i % 4) painter.drawLine(0,140,0,140-line_length); else { painter.setPen(Qt::NoPen); painter.drawConvexPolygon(QPolygon(3, scaleTriangle)); } painter.rotate(7.5); Pen.setWidth(3); if (i % 2) line_length=10; else line_length=5; } painter.restore(); // Rysowanie skali liczby . if (true || digitOffset()) { painter.setPen(Qt::black); painter.rotate(-60.0); painter.setFont(digitFont()); for (int i=0;i<9;i++) { double v = m_min + i*(m_max - m_min)/8.0; if (fabs(v) < 0.000001 ) v = 0.0; QString val = QString("%1").arg(v); QSize Size = painter.fontMetrics().size(Qt::TextSingleLine, val); painter.save(); painter.translate( digitOffset() * cos((5+i)*PI/6.0), digitOffset() * sin((5+i)*PI/6.0)); painter.drawText( QPointF( Size.width()/ -2.0, Size.height() / 4.0), val); painter.restore(); } } }// paintBackground
void MapIcons::paintSpawnPointIcon(MapParameters& param, QPainter& p, const MapIcon& mapIcon, const SpawnPoint* sp, const QPoint& point) { // Draw Line if (mapIcon.showLine0()) { p.setPen(mapIcon.line0Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } // calculate distance and draw distance related lines uint32_t distance = UINT32_MAX; if (mapIcon.line1Distance() || mapIcon.line2Distance()) { if (!showeq_params->fast_machine) distance = sp->calcDist2DInt(param.player()); else distance = (int)sp->calcDist(param.player()); if (mapIcon.line1Distance() > distance) { p.setPen(mapIcon.line1Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } if (mapIcon.line2Distance() > distance) { p.setPen(mapIcon.line2Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } } // Draw Spawn Names if (mapIcon.showName()) { QString spawnNameText; spawnNameText.sprintf("sp:%s %s (%d)", (const char*)sp->name(), (const char*)sp->last(), sp->count()); QFontMetrics fm(param.font()); int width = fm.width(spawnNameText); p.setPen(gray); p.drawText(point.x() - (width / 2), point.y() + fm.height() + 1, spawnNameText); } // Draw the Icon if (mapIcon.image() && (!mapIcon.imageFlash() || m_flash) && (mapIcon.imageStyle() != tIconStyleNone)) { if (mapIcon.imageUseSpawnColorPen()) { QPen pen = mapIcon.imagePen(); pen.setColor(pickSpawnPointColor(sp, pen.color())); p.setPen(pen); } else p.setPen(mapIcon.imagePen()); if (mapIcon.imageUseSpawnColorBrush()) { QBrush brush = mapIcon.imageBrush(); brush.setColor(pickSpawnPointColor(sp, brush.color())); p.setBrush(brush); } else p.setBrush(mapIcon.imageBrush()); mapIcon.paintIconImage(mapIcon.imageStyle(), p, point, *m_mapIconSizes[mapIcon.imageSize()], *m_mapIconSizesWH[mapIcon.imageSize()]); } // Draw the highlight if (mapIcon.highlight() && (!mapIcon.highlightFlash() || m_flash) && (mapIcon.highlightStyle() != tIconStyleNone)) { if (mapIcon.highlightUseSpawnColorPen()) { QPen pen = mapIcon.highlightPen(); pen.setColor(pickSpawnPointColor(sp, pen.color())); p.setPen(pen); } else p.setPen(mapIcon.highlightPen()); if (mapIcon.highlightUseSpawnColorBrush()) { QBrush brush = mapIcon.highlightBrush(); brush.setColor(pickSpawnPointColor(sp, brush.color())); p.setBrush(brush); } else p.setBrush(mapIcon.highlightBrush()); mapIcon.paintIconImage(mapIcon.highlightStyle(), p, point, *m_mapIconSizes[mapIcon.highlightSize()], *m_mapIconSizesWH[mapIcon.highlightSize()]); } }
void TSController::printReport() { QPrinter printer; QPrintDialog *dialog = new QPrintDialog(&printer, this); dialog->setWindowTitle(tr("Предварительный просмотр")); int endIndex=curveBuffer->lenght; float listh=printer.widthMM()*printer.resolution()/25.4-60; float listw=printer.heightMM()*printer.resolution()/25.4-60; printer.setPageMargins(5,5,5,5,QPrinter::Millimeter); printer.setOrientation(QPrinter::Landscape); printer.setResolution(QPrinter::HighResolution); printer.setPaperSize(QPrinter::A4); Ui::Form pf; pf.setupUi(&wpf); pf.mainBox->setMaximumSize((int)listw,(int)listh); pf.mainBox->setMinimumSize((int)listw,(int)listh); pf.resultsTable->setMinimumWidth(40+(int)listw/3); pf.resultsTable->setRowCount(13); pf.resultsTable->setColumnCount(2); pf.resultsTable->verticalHeader()->setVisible(false); pf.resultsTable->setHorizontalHeaderLabels(QString(tr("Параметр; Значение")).split(";")); pf.resultsTable->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); int i=0,j=0; for(i=0;i<ui->resultsTable->rowCount();i++){ for(j=0;j<2;j++){ pf.resultsTable->setItem(i,j,getQTableWidgetItem(ui->resultsTable->item(i,j)->text())); } } int myH=0,myW=0; wpf.resize(pf.mainBox->size()); wpf.show(); myH = pf.gVolume->height(); myW = pf.gVolume->width(); QPixmap pmTempIn(myW,myH); QPixmap pmTempOut(myW,myH); QPixmap pmVolume(myW,myH); QPainter prTempIn; QPainter prTempOut; QPainter prVolume; prTempIn.begin(&pmTempIn); prTempOut.begin(&pmTempOut); prVolume.begin(&pmVolume); int h = pf.gVolume->height()/2; int step = h/10; if(h%10>=5) { h+=step/2; } prVolume.fillRect(0,0,myW,myH,Qt::white); prTempIn.fillRect(0,0,myW,myH,Qt::white); prTempOut.fillRect(0,0,myW,myH,Qt::white); prVolume.setPen(QColor(225,225,225)); prTempIn.setPen(QColor(225,225,225)); prTempOut.setPen(QColor(225,225,225)); for(i=step;i<h;i+=step) { prVolume.drawLine(0,h+i,myW,h+i); prTempIn.drawLine(0,h+i,myW,h+i); prTempOut.drawLine(0,h+i,myW,h+i); prVolume.drawLine(0,h-i,myW,h-i); prTempIn.drawLine(0,h-i,myW,h-i); prTempOut.drawLine(0,h-i,myW,h-i); } for(i=10;i<myW;i+=10) { prVolume.drawLine(i,0,i,h<<1); prTempIn.drawLine(i,0,i,h<<1); prTempOut.drawLine(i,0,i,h<<1); } prVolume.setPen(QColor(0,0,0)); prTempIn.setPen(QColor(0,0,0)); prTempOut.setPen(curveBuffer->toutColor); prVolume.setPen(QColor(255,0,0)); int* tinInt = curveBuffer->getTempInInterval(); int* toutInt = curveBuffer->getTempOutInterval(); int* volInt = curveBuffer->getVolumeInterval(); float tempInK = 1; float tempOutK = 1; float tempInZ = h; float tempOutZ = h; tempInAdaptive = (float)myH/(tinInt[1]-tinInt[0]); tempOutAdaptive = (float)myH/(toutInt[1]-toutInt[0]); volumeAdaptive = (float)myH/(volInt[1]-volInt[0]); tempInZ = h + ceil((float)(tinInt[1]+tinInt[0])*tempInAdaptive*tempInK/2); tempOutZ = h + ceil((float)(toutInt[1]+toutInt[0])*tempOutAdaptive*tempOutK/2); float volumeK =1; i=0; int k=ceil((float)curveBuffer->lenght/pf.gTempIn->width()); for(j=0;j<myW-35;j+=1) { if(i>=k*endIndex)break; prVolume.drawLine( j,h-volumeK*volumeAdaptive*volume[i],j+1,h-volumeK*volumeAdaptive*volume[i+k] ); prTempIn.drawLine(j,tempInZ-tempInK*tempInAdaptive*tempIn[i] ,j+1,tempInZ-tempInK*tempInAdaptive*tempIn[i+k]); prTempOut.drawLine(j,tempOutZ-tempOutK*tempOutAdaptive*tempOut[i] ,j+1,tempOutZ-tempOutK*tempOutAdaptive*tempOut[i+k]); i+=k; } pf.gVolume->setPixmap(pmVolume); pf.gTempIn->setPixmap(pmTempIn); pf.gTempOut->setPixmap(pmTempOut); pf.PatientName->setText(patientsModel->record(0).value("sname").toString()+" "+patientsModel->record(0).value("fname").toString()); wpf.hide(); if (dialog->exec() == QDialog::Accepted){ QPainter painter; painter.begin(&printer); int i=0; pf.mainBox->render(&painter); } }
void MapIcons::paintIcon(MapParameters& param, QPainter& p, const MapIcon& mapIcon, const Point3D<int16_t>& item, const QString& itemName, const QPoint& point) { // Draw Line if (mapIcon.showLine0()) { p.setPen(mapIcon.line0Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } // Calculate distance and draw distance related lines uint32_t distance = UINT32_MAX; if (mapIcon.line1Distance() || mapIcon.line2Distance()) { if (!showeq_params->fast_machine) distance = item.calcDist2DInt(param.player()); else distance = (int)item.calcDist(param.player()); if (mapIcon.line1Distance() > distance) { p.setPen(mapIcon.line1Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } if (mapIcon.line2Distance() > distance) { p.setPen(mapIcon.line2Pen()); p.drawLine(param.playerXOffset(), param.playerYOffset(), point.x(), point.y()); } } // Draw Item Name if (mapIcon.showName()) { QFontMetrics fm(param.font()); int width = fm.width(itemName); p.setPen(gray); p.drawText(point.x() - (width / 2), point.y() + fm.height() + 1, itemName); } // Draw Icon Image if (mapIcon.image() && (!mapIcon.imageFlash() || m_flash) && (mapIcon.imageStyle() != tIconStyleNone)) { p.setPen(mapIcon.imagePen()); p.setBrush(mapIcon.imageBrush()); mapIcon.paintIconImage(mapIcon.imageStyle(), p, point, *m_mapIconSizes[mapIcon.imageSize()], *m_mapIconSizesWH[mapIcon.imageSize()]); } // Draw Highlight if (mapIcon.highlight() && (!mapIcon.highlightFlash() || m_flash) && (mapIcon.highlightStyle() != tIconStyleNone)) { p.setPen(mapIcon.highlightPen()); p.setBrush(mapIcon.highlightBrush()); mapIcon.paintIconImage(mapIcon.highlightStyle(), p, point, *m_mapIconSizes[mapIcon.highlightSize()], *m_mapIconSizesWH[mapIcon.highlightSize()]); } }
void SdSelfMsgCanvas::draw(QPainter & p) { const QRect r = rect(); int ah = (r.height() - 1 - 1 - 2 - 1 - 1)/2; int he = r.top() + 1 + 2 + ah + 1; FILE * fp = svg(); p.setRenderHint(QPainter::Antialiasing, true); if (itsType == UmlSelfReturnMsg) p.setPen(::Qt::DotLine); p.drawLine(r.left() + 1, r.top() + 1, r.right() - 1, r.top() + 1); //p.lineTo(r.right() - 1, he); p.drawLine(r.right()-1, r.top() + 1, r.right() - 1, he); //p.lineTo(r.left() + 1, he); p.drawLine(r.right()-1, he, r.left() + 1, he); if (fp != 0) { fputs("<g>\n\t<path fill=\"none\" stroke=\"black\" stroke-opacity=\"1\"", fp); if (itsType == UmlSelfReturnMsg) fputs(" stroke-dasharray=\"4,4\"", fp); fprintf(fp, " d=\"M %d %d L %d %d L %d %d L %d %d\" />\n", r.left() + 1, r.top() + 1, r.right() - 1, r.top() + 1, r.right() - 1, he, r.left() + 1, he); } if (itsType == UmlSyncSelfMsg) { Q3PointArray poly(3); QBrush brsh = p.brush(); p.setBrush(Qt::black); poly.setPoint(0, r.left() + 1, he); poly.setPoint(1, r.left() + 1 + ah, he + ah); poly.setPoint(2, r.left() + 1 + ah, he - ah); p.drawPolygon(poly/*, TRUE*/); p.setBrush(brsh); if (fp != 0) { draw_poly(fp, poly, UmlBlack, FALSE); fputs("</g>\n", fp); } } else { if (itsType == UmlSelfReturnMsg) p.setPen(::Qt::SolidLine); //p.lineTo(r.left() + 1 + ah, he + ah); p.drawLine(r.left()+1+ah, he - ah, r.left() + 1 + ah, he + ah); // assuming last call poly.setPoint p.drawLine(r.left() + 1, he, r.left() + 1 + ah, he - ah); if (fp != 0) fprintf(fp, "\t<path fill=\"none\" stroke=\"black\" stroke-opacity=\"1\"" " d=\"M %d %d L %d %d L %d %d\" />\n" "</g>\n", r.left() + 1 + ah, he + ah, r.left() + 1, he, r.left() + 1 + ah, he - ah); } if (selected()) show_mark(p, r); }
void Vruler::paintEvent(QPaintEvent *e) { if (currDoc->isLoading()) return; QString tx = ""; double xl, frac; double sc = currView->scale(); QFont ff = font(); ff.setPointSize(8); setFont(ff); QPainter p; p.begin(this); p.save(); p.setClipRect(e->rect()); p.drawLine(16, 0, 16, height()); p.setBrush(Qt::black); p.setPen(Qt::black); p.setFont(font()); double cc = height() / sc; double firstMark = ceil(offs / iter) * iter - offs; while (firstMark < cc) { p.drawLine(10, qRound(firstMark * sc), 16, qRound(firstMark * sc)); firstMark += iter; } firstMark = ceil(offs / iter2) * iter2 - offs; int markC = static_cast<int>(ceil(offs / iter2)); while (firstMark < cc) { p.drawLine(3, qRound(firstMark * sc), 16, qRound(firstMark * sc)); int textY = qRound(firstMark * sc)+10; switch (currDoc->unitIndex()) { case SC_MM: tx = QString::number(markC * iter2 / (iter2 / 100) / cor); break; case SC_IN: xl = (markC * iter2 / iter2) / cor; tx = QString::number(static_cast<int>(xl)); frac = fabs(xl - static_cast<int>(xl)); if ((static_cast<int>(xl) == 0) && (frac > 0.1)) tx = ""; if ((frac > 0.24) && (frac < 0.26)) tx += QChar(0xBC); if ((frac > 0.49) && (frac < 0.51)) tx += QChar(0xBD); if ((frac > 0.74) && (frac < 0.76)) tx += QChar(0xBE); tx = tx; break; case SC_P: case SC_C: tx = QString::number(markC * iter2 / (iter2 /5) / cor); break; case SC_CM: tx = QString::number(markC * iter2 / iter2 / cor); break; default: tx = QString::number(markC * iter2); break; } drawNumber(tx, textY, &p); firstMark += iter2; markC++; } p.restore(); if (drawMark) { QPolygon cr; #ifdef OPTION_SMOOTH_MARKERS // draw new marker to pixmap static const int SCALE = 16; static const QColor BACKGROUND(255, 255, 255); static QPixmap pix( 16*SCALE, 4*SCALE ); static bool initpix = true; if (initpix) { initpix = false; QPainter pp( &pix ); pp.setBrush( BACKGROUND ); pp.drawRect( 0, 0, 16*SCALE, 4*SCALE ); pp.setPen(Qt::red); pp.setBrush(Qt::red); cr.setPoints(3, 16*SCALE, 2*SCALE, 0, 4*SCALE, 0, 0); pp.drawPolygon(cr); } // draw pixmap p.save(); p.translate(0, -currView->contentsY()); p.scale(1.0/(SCALE+1), 1.0/SCALE); p.drawPixmap(0, (where-2)*SCALE, pix); p.restore(); // repaint marks p.setBrush(Qt::black); p.setPen(Qt::black); p.setFont(font()); double sc = currView->getScale(); double cc = height() / sc; double firstMark = ceil(offs / iter) * iter - offs; while (firstMark < cc) { p.drawLine(10, qRound(firstMark * sc), 16, qRound(firstMark * sc)); firstMark += iter; } #else // draw slim marker p.translate(0, -currView->contentsY()); p.setPen(Qt::red); p.setBrush(Qt::red); cr.setPoints(5, 5, whereToDraw, 16, whereToDraw, 5, whereToDraw, 0, whereToDraw+2, 0, whereToDraw-2); p.drawPolygon(cr); #endif } p.end(); }
void AccumulateEnergy::DrawAdvanceMeter(QPainter &painter) { float y = draw_area_range.bottom() - dheight_ - 15; float x = draw_area_range.left(); if (days_ == 0) { return; } if (maxadvancemeter_ == 0) { return; } int tmaxadvancemeter = maxadvancemeter_; if (tmaxadvancemeter > ENERGYUYRULERFACTORY) { if(tmaxadvancemeter%4 != 0) { while(tmaxadvancemeter%4 != 0) { tmaxadvancemeter += 1; } } } else { tmaxadvancemeter = 8; } //int accumulatenum = 0; int r = 4; painter.save(); QPen pen; QBrush brush; //pen.setColor(QColor(0xff1493)); pen.setColor(Qt::black); brush.setColor(Qt::black); painter.setPen(pen); brush.setStyle(Qt::SolidPattern); painter.setFont(QFont(QObject::tr("WenQuanYi"),6)); painter.setRenderHint( QPainter::Antialiasing, true ); painter.setBrush(brush); for (int k = 0;k<datas_.size();k++) { EnergyData ei = datas_.value(k); if (k + 1 != datas_.size()) { EnergyData ei2 = datas_.value(k+1); float xt = x + k* draw_area_range.width() / days_; float yt = y - ei.advancemeter * (uheight_ - 15) / tmaxadvancemeter ; float xt2 = x + (k+1)* draw_area_range.width() / days_; float yt2 = y - ei2.advancemeter * (uheight_ - 15) / tmaxadvancemeter ; painter.drawEllipse(QPointF(xt,yt),r,r); painter.drawLine(QPointF(xt,yt),QPointF(xt2,yt2)); float width = painter.fontMetrics().width(QString::number(ei.advancemeter)); float height = painter.fontMetrics().height(); painter.drawText(QRectF(xt + width,yt - height,width,height),QString::number(ei.advancemeter)); } else { float xt3 = x + k* draw_area_range.width() / days_; float yt3 = y - ei.advancemeter * (uheight_ - 15) / tmaxadvancemeter ; painter.drawEllipse(QPointF(xt3,yt3),r,r); //painter.drawLine(QPointF(xt3,yt3),QPointF(draw_area_range.right(),yt3)); float width = painter.fontMetrics().width(QString::number(ei.advancemeter)); float height = painter.fontMetrics().height(); painter.drawText(QRectF(xt3 + width,yt3 - height,width,height),QString::number(ei.advancemeter)); } } painter.restore(); }