void BoardGame::drawEdgeLines(QPixmap *cache, QPainter *painter) { painter->setPen(COLOR_LINE); painter->setBrush(NoBrush); for (int r = 0; r < size().height(); r++) for (int c = 0; c < size().width(); c++) painter->drawRect(pointRect(cache->size(), QPoint(c, r))); }
void BoardGame::drawPoint(QPixmap *cache, QPainter *painter, const QPoint& point, const int player) { if (player == -1) return; painter->setPen(NoPen); painter->setBrush(QBrush(playerColor(player))); paintPoint(painter, pointRect(cache->size(), point), player); }
void TransferFunctionAlphaWidget::paintOpacityGraph(QPainter& painter) { QPen pointPen, pointLinePen; pointPen.setColor(QColor(0, 0, 150)); pointLinePen.setColor(QColor(150, 100, 100)); // Go through each point and draw squares and lines IntIntMap opacityMap = mImageTF->getOpacityMap(); QPoint lastScreenPoint; this->mPointRects.clear(); for (IntIntMap::iterator opPoint = opacityMap.begin(); opPoint != opacityMap.end(); ++opPoint) { // Get the screen (plot) position of this point AlphaPoint pt(opPoint->first, opPoint->second); QPoint screenPoint = this->alpha2screen(pt); // draw line from left edge to first point: if (opPoint==opacityMap.begin()) { lastScreenPoint = QPoint(mPlotArea.left(), screenPoint.y()); } // Draw line from previous point painter.setPen(pointLinePen); painter.drawLine(lastScreenPoint, screenPoint); // Draw the rectangle QRect pointRect(screenPoint.x() - mBorder, screenPoint.y() - mBorder, mBorder*2, mBorder*2); if (opPoint->first==mSelectedAlphaPoint.position) { pointPen.setWidth(2); painter.setPen(pointPen); } else { pointPen.setWidth(1); painter.setPen(pointPen); } painter.drawRect(pointRect); this->mPointRects[opPoint->first] = pointRect; // Store the point lastScreenPoint = screenPoint; } // draw a line from the last point to the right end QPoint screenPoint(mPlotArea.right(), lastScreenPoint.y()); painter.setPen(pointLinePen); painter.drawLine(lastScreenPoint, screenPoint); }
void BoardGame::hoverPixmap(QPixmap *cache, QPixmap *hover, const int player) { QRect rect = pointRect(cache->size(), QPoint(0, 0)); hover->resize(rect.size()); QPainter painter(hover); drawHover(hover, &painter, player); if (boardType() != EdgeLine) return; painter.setPen(COLOR_LINE); painter.setBrush(NoBrush); painter.drawRect(hover->rect()); }
void ReportEntityLabel::buildXML(QDomDocument & doc, QDomElement & parent) { kDebug(); //kdDebug() << "ReportEntityLabel::buildXML()"); QDomElement entity = doc.createElement("label"); // bounding rect buildXMLRect(doc, entity, pointRect()); // name QDomElement n = doc.createElement("name"); n.appendChild(doc.createTextNode(entityName())); entity.appendChild(n); // z QDomElement z = doc.createElement("zvalue"); z.appendChild(doc.createTextNode(QString::number(zValue()))); entity.appendChild(z); // font info //buildXMLFont ( doc,entity,font() ); //text style info buildXMLTextStyle(doc, entity, textStyle()); //Line Style buildXMLLineStyle(doc, entity, lineStyle()); // text alignment int align = textFlags(); // horizontal if ((align & Qt::AlignRight) == Qt::AlignRight) entity.appendChild(doc.createElement("right")); else if ((align & Qt::AlignHCenter) == Qt::AlignHCenter) entity.appendChild(doc.createElement("hcenter")); else // Qt::AlignLeft entity.appendChild(doc.createElement("left")); // vertical if ((align & Qt::AlignBottom) == Qt::AlignBottom) entity.appendChild(doc.createElement("bottom")); else if ((align & Qt::AlignVCenter) == Qt::AlignVCenter) entity.appendChild(doc.createElement("vcenter")); else // Qt::AlignTop entity.appendChild(doc.createElement("top")); // the text string QDomElement string = doc.createElement("string"); string.appendChild(doc.createTextNode(text())); entity.appendChild(string); parent.appendChild(entity); }
void Stroke::paint(QPainter &painter, qreal zoom, bool last) { if (points.length() == 1) { QRectF pointRect(zoom * points[0], QSizeF(0, 0)); qreal pad = penWidth * zoom / 2; painter.setPen(Qt::NoPen); painter.setBrush(QBrush(color)); painter.drawEllipse(pointRect.adjusted(-pad, -pad, pad, pad)); } else { QPen pen; pen.setColor(color); if (pattern != solidLinePattern) { pen.setDashPattern(pattern); } pen.setCapStyle(Qt::RoundCap); painter.setPen(pen); qreal dashOffset = 0.0; for (int j = 1; j < points.length(); ++j) { qreal tmpPenWidth = zoom * penWidth * (pressures.at(j - 1) + pressures.at(j)) / 2.0; if (pattern != solidLinePattern) { pen.setDashOffset(dashOffset); } pen.setWidthF(tmpPenWidth); painter.setPen(pen); // painter.drawLine(zoom * points.at(j-1), zoom * points.at(j)); if (last == false) { painter.drawLine(zoom * points.at(j - 1), zoom * points.at(j)); } else if (last == true && j == points.length() - 1) { painter.drawLine(zoom * points.at(j - 1), zoom * points.at(j)); } if (tmpPenWidth != 0) dashOffset += 1.0 / tmpPenWidth * (QLineF(zoom * points.at(j - 1), zoom * points.at(j))).length(); } } }
QPixmap BrushStyle::getSample(qreal scale, qreal alpha, bool selected, const QColor &color, bool emptyBackground) { QPixmap backgroundPixmap( (selected) ? BRUSH_SAMPLE_SELECTED_BG : BRUSH_SAMPLE_BACKGROUND); if (emptyBackground) backgroundPixmap.fill(Qt::transparent); // Scale the sample QSizeF pointSize(BRUSH_SAMPLE_SIDE, BRUSH_SAMPLE_SIDE); if (scale != 1.0) { pointSize.setWidth(pointSize.width() * scale); pointSize.setHeight(pointSize.height() * scale); } // Apply color and alpha QColor alphaColor(Qt::black); if (color.isValid()) alphaColor = color; if (alpha != 1.0) alphaColor.setAlphaF(alpha); // Draw sample in the middle of background QPainter painter(&backgroundPixmap); painter.setRenderHint(QPainter::Antialiasing); QRectF pointRect(QPointF(0, 0), pointSize); pointRect.moveTo(backgroundPixmap.width() / 2 - pointSize.width() / 2, backgroundPixmap.height() / 2 - pointSize.height() / 2); if (color.isValid() && color.value() > 210 && color.saturation() < 50) painter.setPen("#d0d0d0"); else painter.setPen(Qt::NoPen); painter.setBrush(alphaColor); painter.drawEllipse(pointRect); painter.end(); return backgroundPixmap; }
bool Collide::circleRect(const Position& circleCenter, Position::value_type circleRadius, const Shape& rect) { // TODO: actually algorithm can ran on any convex polygon, just need to generalize it REQUIRE(TAG, rect.geometry().points() == 4, "Rect must have four points"); Position a = rect.transformation().position() + rect.geometry().pointAt(0); Position b = rect.transformation().position() + rect.geometry().pointAt(1); Position c = rect.transformation().position() + rect.geometry().pointAt(2); Position d = rect.transformation().position() + rect.geometry().pointAt(3); return pointRect (circleCenter, a, b, c, d) || lineCircle(circleCenter, circleRadius, a, b) || lineCircle(circleCenter, circleRadius, b, c) || lineCircle(circleCenter, circleRadius, c, d) || lineCircle(circleCenter, circleRadius, d, a); }
void QtGradientWidgetPrivate::paintPoint(QPainter *painter, const QPointF &point, double size) const { QPointF pf = toViewport(point); QRectF rf = pointRect(pf, size); QPen pen; pen.setWidthF(1); QColor alphaZero = Qt::white; alphaZero.setAlpha(0); painter->save(); painter->drawEllipse(rf); /* painter->save(); QLinearGradient lgV(0, rf.top(), 0, rf.bottom()); lgV.setColorAt(0, alphaZero); lgV.setColorAt(0.25, Qt::white); lgV.setColorAt(0.25, Qt::white); lgV.setColorAt(1, alphaZero); pen.setBrush(lgV); painter->setPen(pen); painter->drawLine(QPointF(pf.x(), rf.top()), QPointF(pf.x(), rf.bottom())); QLinearGradient lgH(rf.left(), 0, rf.right(), 0); lgH.setColorAt(0, alphaZero); lgH.setColorAt(0.5, Qt::white); lgH.setColorAt(1, alphaZero); pen.setBrush(lgH); painter->setPen(pen); painter->drawLine(QPointF(rf.left(), pf.y()), QPointF(rf.right(), pf.y())); painter->restore(); */ painter->restore(); }
void ReportEntityCheck::buildXML(QDomDocument & doc, QDomElement & parent) { kDebug() << endl; QDomElement entity = doc.createElement("check"); // bounding rect buildXMLRect(doc, entity, pointRect()); // name QDomElement n = doc.createElement("name"); n.appendChild(doc.createTextNode(entityName())); entity.appendChild(n); // z QDomElement z = doc.createElement("zvalue"); z.appendChild(doc.createTextNode(QString::number(zValue()))); entity.appendChild(z); //Line Style buildXMLLineStyle(doc, entity, lineStyle()); //Color QDomElement fc = doc.createElement("fgcolor"); fc.appendChild(doc.createTextNode(m_foregroundColor->value().value<QColor>().name())); entity.appendChild(fc); QDomElement cs = doc.createElement("controlsource"); cs.appendChild(doc.createTextNode(m_controlSource->value().toString())); entity.appendChild(cs); // the check style QDomElement sty = doc.createElement("checkstyle"); sty.appendChild(doc.createTextNode(m_checkStyle->value().toString())); entity.appendChild(sty); parent.appendChild(entity); }
void BoardGame::drawLast(QPixmap *cache, QPainter *painter, const QPoint& point, const int player) { painter->setPen(QPen(playerColor(player), 0, DashLine)); painter->setBrush(NoBrush); painter->drawRect(pointRect(cache->size(), point)); }
// ------------------------------------------------------------------------- void ctkQImageView::update( bool zoomChanged, bool sizeChanged ) { Q_D( ctkQImageView ); if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() ) { const QImage * img = & ( d->ImageList[ d->SliceNumber ] ); if( zoomChanged || sizeChanged ) { if( this->width() > 0 && this->height() > 0 && d->TmpXMax > d->TmpXMin && d->TmpYMax > d->TmpYMin) { int tmpXRange = d->TmpXMax - d->TmpXMin; int tmpYRange = d->TmpYMax - d->TmpYMin; double tmpAspectRatio = static_cast<double>(tmpYRange) / tmpXRange; double screenAspectRatio = static_cast<double>(this->height()) / this->width(); if( screenAspectRatio > tmpAspectRatio ) { int extraTmpYAbove = d->TmpYMin; int extraTmpYBelow = img->height() - d->TmpYMax; int extraTmpYNeeded = tmpXRange * screenAspectRatio - tmpYRange; int minExtra = extraTmpYAbove; if( extraTmpYBelow < minExtra ) { minExtra = extraTmpYBelow; } if(2 * minExtra >= extraTmpYNeeded) { int minNeeded = extraTmpYNeeded / 2.0; int maxNeeded = extraTmpYNeeded - minNeeded; d->TmpYMin -= minNeeded; d->TmpYMax += maxNeeded; } else if(extraTmpYAbove + extraTmpYBelow >= extraTmpYNeeded) { if(extraTmpYAbove < extraTmpYBelow) { d->TmpYMin = 0; d->TmpYMax += extraTmpYNeeded - extraTmpYAbove; } else { d->TmpYMax = img->height(); d->TmpYMin -= extraTmpYNeeded - extraTmpYBelow; } } else { d->TmpYMin = 0; d->TmpYMax = img->height(); } d->TmpImage = QPixmap( this->width(), static_cast<unsigned int>( static_cast<double>(d->TmpYMax - d->TmpYMin) / (d->TmpXMax - d->TmpXMin) * this->width() + 0.5 ) ); } else if(screenAspectRatio < tmpAspectRatio) { int extraTmpXLeft = d->TmpXMin; int extraTmpXRight = img->width() - d->TmpXMax; int extraTmpXNeeded = static_cast<double>(tmpYRange) / screenAspectRatio - tmpXRange; int minExtra = extraTmpXLeft; if( extraTmpXRight < minExtra ) { minExtra = extraTmpXRight; } if(2 * minExtra >= extraTmpXNeeded) { int minNeeded = extraTmpXNeeded / 2.0; int maxNeeded = extraTmpXNeeded - minNeeded; d->TmpXMin -= minNeeded; d->TmpXMax += maxNeeded; } else if(extraTmpXLeft + extraTmpXRight >= extraTmpXNeeded) { if(extraTmpXLeft < extraTmpXRight) { d->TmpXMin = 0; d->TmpXMax += extraTmpXNeeded - extraTmpXLeft; } else { d->TmpXMax = img->width(); d->TmpXMin -= extraTmpXNeeded - extraTmpXRight; } } else { d->TmpXMin = 0; d->TmpXMax = img->width(); } d->TmpImage = QPixmap( static_cast<unsigned int>( this->height() / ( static_cast<double>(d->TmpYMax - d->TmpYMin) / (d->TmpXMax - d->TmpXMin) ) + 0.5 ), this->height() ); } else { d->TmpImage = QPixmap( this->width(), this->height() ); } } } if( d->TmpImage.width() > 0 && d->TmpImage.height() > 0) { QRectF target( 0, 0, d->TmpImage.width(), d->TmpImage.height() ); double sourceX = d->TmpXMin; double sourceY = d->TmpYMin; double sourceW = d->TmpXMax - d->TmpXMin; double sourceH = d->TmpYMax - d->TmpYMin; QPainter painter( &(d->TmpImage) ); QImage tmpI = *img; if( d->InvertImage ) { tmpI.invertPixels(); } if( d->FlipXAxis || d->FlipYAxis ) { tmpI = tmpI.mirrored( d->FlipXAxis, d->FlipYAxis ); if( d->FlipXAxis ) { sourceX = tmpI.width() - (d->TmpXMax - d->TmpXMin) - d->TmpXMin; } if( d->FlipYAxis ) { sourceY = tmpI.height() - (d->TmpYMax - d->TmpYMin) - d->TmpYMin; } } QRectF source( sourceX, sourceY, sourceW, sourceH ); painter.drawPixmap( target, QPixmap::fromImage( tmpI ), source ); //if( ! sizeChanged ) { int maxNumCharsPerLine = 50; int fontPointSize = 12; if( fontPointSize * maxNumCharsPerLine > this->width() ) { fontPointSize = this->width() / maxNumCharsPerLine; } if( fontPointSize > 7 ) { QString fontFamily( "Helvetica" ); QFont textFont( fontFamily, fontPointSize ); painter.setFont( textFont ); QColor textColor; textColor.setNamedColor( "lime" ); textColor.setAlpha( 128 ); painter.setPen( textColor ); int textFlags = Qt::AlignLeft | Qt::TextDontClip; QRectF pointRect( 0, 0, 1, 1 ); QRectF spaceBound = painter.boundingRect( pointRect, textFlags, "X" ); if( img->isGrayscale() ) { QString intString = "Intensity Range = "; intString.append( QString::number( d->IntensityMin, 'f', 3 ) ); intString.append( " - " ); intString.append( QString::number( d->IntensityMax, 'f', 3 ) ); QRectF intBound = painter.boundingRect( pointRect, textFlags, intString ); QRectF intRect( spaceBound.width()/2, spaceBound.height()/8, intBound.width(), intBound.height() ); painter.drawText( intRect, textFlags, intString, &intBound ); QString wlString = "W / L = "; wlString.append( QString::number( this->intensityWindow(), 'f', 3 ) ); wlString.append( " / " ); wlString.append( QString::number( this->intensityLevel(), 'f', 3 ) ); QRectF wlBound = painter.boundingRect( pointRect, textFlags, wlString ); QRectF wlRect( spaceBound.width()/2, intRect.y() + intRect.height() + spaceBound.height()/8, wlBound.width(), wlBound.height() ); painter.drawText( wlRect, textFlags, wlString, &wlBound ); } QString spacingString = "Spacing = "; spacingString.append( QString::number( this->xSpacing(), 'f', 3 ) ); spacingString.append( ", " ); spacingString.append( QString::number( this->ySpacing(), 'f', 3 ) ); spacingString.append( ", " ); spacingString.append( QString::number( this->sliceThickness(), 'f', 3 ) ); QRectF spacingBound = painter.boundingRect( pointRect, textFlags, spacingString ); QRectF spacingRect( this->width() - spacingBound.width() - spaceBound.width()/2, this->height() - spacingBound.height() - spaceBound.height()/8, spacingBound.width(), spacingBound.height() ); painter.drawText( spacingRect, textFlags, spacingString, &spacingBound ); QString dimString = "Size = "; dimString.append( QString::number( d->ImageList[ d->SliceNumber ].width() ) ); dimString.append( ", " ); dimString.append( QString::number( d->ImageList[ d->SliceNumber ].height() ) ); dimString.append( ", " ); dimString.append( QString::number( d->ImageList.size() ) ); QRectF dimBound = painter.boundingRect( pointRect, textFlags, dimString ); QRectF dimRect( this->width() - dimBound.width() - spaceBound.width()/2, spacingBound.y() - dimBound.height() - spaceBound.height()/8, dimBound.width(), dimBound.height() ); painter.drawText( dimRect, textFlags, dimString, &dimBound ); QString rasString = "RAS = "; rasString.append( QString::number( this->xPosition() * this->xSpacing(), 'f', 3 ) ); rasString.append( ", " ); rasString.append( QString::number( this->yPosition() * this->ySpacing(), 'f', 3 ) ); rasString.append( ", " ); rasString.append( QString::number( this->slicePosition() * this->sliceSpacing(), 'f', 3 ) ); QRectF rasBound = painter.boundingRect( pointRect, textFlags, rasString ); QRectF rasRect( spaceBound.width()/2, this->height() - rasBound.height() - spaceBound.height()/8, rasBound.width(), rasBound.height() ); painter.drawText( rasRect, textFlags, rasString, &rasBound ); QString ijkString = "IJK = "; ijkString.append( QString::number( this->xPosition() ) ); ijkString.append( ", " ); ijkString.append( QString::number( this->yPosition() ) ); ijkString.append( ", " ); ijkString.append( QString::number( this->slicePosition() ) ); QRectF ijkBound = painter.boundingRect( pointRect, textFlags, ijkString ); QRectF ijkRect( spaceBound.width()/2, rasBound.y() - ijkBound.height() - spaceBound.height()/8, ijkBound.width(), ijkBound.height() ); painter.drawText( ijkRect, textFlags, ijkString, &ijkBound ); QString valString = "Value = "; valString.append( QString::number( this->positionValue(), 'f', 3 ) ); QRectF valBound = painter.boundingRect( pointRect, textFlags, valString ); QRectF valRect( spaceBound.width()/2, ijkBound.y() - valBound.height() - spaceBound.height()/8, valBound.width(), valBound.height() ); painter.drawText( valRect, textFlags, valString, &valBound ); } QColor lineColor; lineColor.setNamedColor( "red" ); lineColor.setAlpha( 128 ); painter.setPen( lineColor ); double x = ( this->xPosition() - d->TmpXMin ) / (d->TmpXMax - d->TmpXMin) * this->width(); double y = ( this->yPosition() - d->TmpYMin ) / (d->TmpYMax - d->TmpYMin) * this->height(); if( d->FlipXAxis ) { x = this->width() - x; } if( d->FlipYAxis ) { y = this->height() - y; } QLine lineX( x, 0, x, this->height() ); painter.drawLine( lineX ); QLine lineY( 0, y, this->width(), y ); painter.drawLine( lineY ); } } d->Window->setPixmap( d->TmpImage ); } else { d->Window->setText( "No Image Loaded." ); } }