本文整理汇总了C++中QPainter::drawLine方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::drawLine方法的具体用法?C++ QPainter::drawLine怎么用?C++ QPainter::drawLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::drawLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
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
//.........这里部分代码省略.........
示例2: draw
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);
}
示例3: paintRow
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);
}
}
}
}
示例4: drawObject
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;
}
}
示例5: draw
//.........这里部分代码省略.........
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());
}
示例6: renderVisualization
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();
}
示例7: paintGraph
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);
}
}
示例8: paintEvent
//.........这里部分代码省略.........
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);
示例9: print
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);
}
}
}
}
示例10: draw
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);
}
示例11: generateMarkImage
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
{
//.........这里部分代码省略.........
示例12: doPainting
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);
//.........这里部分代码省略.........
示例13: if
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
//.........这里部分代码省略.........
示例14: draw_bbox
/**
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);
}
}
示例15: drawOnionSkinSelection
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);
}
//.........这里部分代码省略.........