// paint a ROUND RAISED led lamp void KLed::paintRaised() { if ( paintCachedPixmap() ) return; QPainter paint; QColor color; QBrush brush; QPen pen; // Initialize coordinates, width, and height of the LED int width = ledWidth(); int scale = 3; QPixmap *tmpMap = 0; width *= scale; tmpMap = new QPixmap( width + 6, width + 6 ); tmpMap->fill( palette().color( backgroundRole() ) ); paint.begin( tmpMap ); paint.setRenderHint(QPainter::Antialiasing); // Set the color of the LED according to given parameters color = ( d->state == On ? d->color : d->offColor ); // Set the brush to SolidPattern, this fills the entire area // of the ellipse which is drawn first brush.setStyle( Qt::SolidPattern ); brush.setColor( color ); paint.setBrush( brush ); // Assign the brush to the painter // Draws a "flat" LED with the given color: paint.drawEllipse( scale, scale, width - scale * 2, width - scale * 2 ); // Draw the bright light spot of the LED now, using modified "old" // painter routine taken from KDEUI's KLed widget: // Setting the new width of the pen is essential to avoid "pixelized" // shadow like it can be observed with the old LED code pen.setWidth( 2 * scale ); // shrink the light on the LED to a size about 2/3 of the complete LED int pos = width / 5 + 1; int light_width = width; light_width *= 2; light_width /= 3; // Calculate the LED's "light factor": int light_quote = ( 130 * 2 / ( light_width ? light_width : 1 ) ) + 100; // Now draw the bright spot on the LED: while ( light_width ) { color = color.light( light_quote ); // make color lighter pen.setColor( color ); // set color as pen color paint.setPen( pen ); // select the pen for drawing paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) light_width--; if ( !light_width ) break; paint.drawEllipse( pos, pos, light_width, light_width ); light_width--; if ( !light_width ) break; paint.drawEllipse( pos, pos, light_width, light_width ); pos++; light_width--; } // Drawing of bright spot finished, now draw a thin gray border // around the LED; it looks nicer that way. We do this here to // avoid that the border can be erased by the bright spot of the LED pen.setWidth( 2 * scale + 1 ); color = palette().color( QPalette::Dark ); pen.setColor( color ); // Set the pen accordingly paint.setPen( pen ); // Select pen for drawing brush.setStyle( Qt::NoBrush ); // Switch off the brush paint.setBrush( brush ); // This avoids filling of the ellipse paint.drawEllipse( 2, 2, width, width ); paint.end(); // painting done QPixmap *&dest = ( d->state == On ? d->onMap : d->offMap ); QImage i = tmpMap->toImage(); width /= 3; i = i.scaled( width, width, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); delete tmpMap; dest = new QPixmap( QPixmap::fromImage( i ) ); paint.begin( this ); paint.drawPixmap( 0, 0, *dest ); paint.end(); }
/*! * parameters of bboxes may vary depending on whether bbox is selected or not or * whether it's label is main or not. */ void ImageHolder::drawBoundingBoxes( QPainter *aPainter, QPen *aPen ) const { if (0 == list_bounding_box_) { return; /* NOTREACHED */ } Qt::PenStyle penStyle; /* default width is hardcoded */ int width = 2; /* drawing all the bboxes */ for (int i = 0; i < list_bounding_box_->size(); i++) { penStyle = Qt::SolidLine; int labelID = list_bounding_box_->at(i)->label_ID_; /* setting color for the label of current bbox */ if (labelID < list_label_color_->count()) aPen->setColor(QColor(list_label_color_->at(labelID))); /* in case there is no color for such label */ else aPen->setColor(QColor(Qt::white)); /* checking whether labeled area is of main label or not */ if (labelID == *main_label_) width = 3; else width = 2; /* changing the line style and width if current area is selected(focused) */ if (RectFigure == focused_selection_type_ && focused_selection_ == i) { penStyle = Qt::DotLine; width = 3; } /* scaling */ QRect rect = list_bounding_box_->at(i)->rect.normalized(); QPoint topLeft = rect.topLeft() * scale_; QPoint bottomRight = rect.bottomRight() * scale_; rect.setTopLeft(topLeft); rect.setBottomRight(bottomRight); if (focused_selection_ == i && focused_selection_type_ == RectFigure) { QPen circPen; circPen.setWidth(2); circPen.setStyle(Qt::SolidLine); circPen.setColor(aPen->color()); aPainter->setPen(circPen); for (int j = 0; j < 4; j++) { QPoint point; /* getting the number of point mouse pointer hovered on */ if (!j) { point = rect.topLeft(); } else if (1 == j) { point = rect.topRight(); } else if (2 == j) { point = rect.bottomRight(); } else if (3 == j) { point = rect.bottomLeft(); } /* if current point is hovered then fill it */ if (i == hovered_point_.figureID && j == hovered_point_.pointID && RectFigure == hovered_point_.figure) { QBrush brush; brush.setColor(aPen->color()); brush.setStyle(Qt::SolidPattern); aPainter->setBrush(brush); } aPainter->drawEllipse(point, point_radius_, point_radius_); aPainter->setBrush(Qt::NoBrush); } } aPen->setWidth(width); aPen->setStyle(penStyle); aPainter->setPen(*aPen); aPainter->drawRect(rect); /* drawing label ids of these boxes */ QString labelIDText = QString("%1").arg(labelID); aPainter->drawText( rect.left() + 5, rect.top() + 5, 20, 20, Qt::AlignLeft, labelIDText ); } }
void TupGraphicsScene::addTweeningObjects(int photogram) { QList<TupGraphicObject *> tweenList = k->scene->tweeningGraphicObjects(); for (int i=0; i < tweenList.count(); i++) { TupGraphicObject *object = tweenList.at(i); if (object->frame()->layer()->isVisible()) { int origin = object->frame()->index(); if (TupItemTweener *tween = object->tween()) { int adjustX = object->item()->boundingRect().width()/2; int adjustY = object->item()->boundingRect().height()/2; if (origin == photogram) { TupTweenerStep *stepItem = tween->stepAt(0); object->item()->setToolTip(tween->tweenType() + ": " + tween->name() + tr("/Step: 0")); if (tween->type() == TupItemTweener::Compound) { object->item()->setTransformOriginPoint(tween->transformOriginPoint()); if (stepItem->has(TupTweenerStep::Position)) { // tFatal() << "TupGraphicsScene::addTweeningObjects() - Applying position..."; QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); object->item()->setPos(tween->transformOriginPoint()); } if (stepItem->has(TupTweenerStep::Rotation)) { QRectF rect = object->item()->sceneBoundingRect(); object->item()->setTransformOriginPoint(rect.center()); double angle = stepItem->rotation(); object->item()->setRotation(angle); // tFatal() << "TupGraphicsScene::addTweeningObjects() - Applying rotation - Angle: " << angle; } else { // tFatal() << "TupGraphicsScene::addTweeningObjects() - No rotation parameter!"; } } else { if (stepItem->has(TupTweenerStep::Position)) { QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); object->item()->setPos(tween->transformOriginPoint()); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->item()->setTransformOriginPoint(tween->transformOriginPoint()); object->item()->setRotation(angle); } if (stepItem->has(TupTweenerStep::Scale)) { QPointF point = tween->transformOriginPoint(); object->item()->setTransformOriginPoint(point); object->item()->setScale(1.0); } if (stepItem->has(TupTweenerStep::Shear)) { QTransform transform; transform.shear(0, 0); object->item()->setTransform(transform); } if (stepItem->has(TupTweenerStep::Coloring)) { QColor itemColor = stepItem->color(); if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(object->item())) { QPen pen = path->pen(); pen.setColor(itemColor); path->setPen(pen); } else if (TupEllipseItem *ellipse = qgraphicsitem_cast<TupEllipseItem *>(object->item())) { QPen pen = ellipse->pen(); pen.setColor(itemColor); ellipse->setPen(pen); } else if (TupLineItem *line = qgraphicsitem_cast<TupLineItem *>(object->item())) { QPen pen = line->pen(); pen.setColor(itemColor); line->setPen(pen); } else if (TupRectItem *rect = qgraphicsitem_cast<TupRectItem *>(object->item())) { QPen pen = rect->pen(); pen.setColor(itemColor); rect->setPen(pen); } } if (stepItem->has(TupTweenerStep::Opacity)) object->item()->setOpacity(stepItem->opacity()); } } else if ((origin < photogram) && (photogram < origin + tween->frames())) { int step = photogram - origin; TupTweenerStep *stepItem = tween->stepAt(step); object->item()->setToolTip(tween->tweenType() + ": " + tween->name() + tr("/Step: ") + QString::number(step)); if (tween->type() == TupItemTweener::Compound) { if (stepItem->has(TupTweenerStep::Position)) { qreal dx = stepItem->position().x() - (object->lastTweenPos().x() + adjustX); qreal dy = stepItem->position().y() - (object->lastTweenPos().y() + adjustY); object->item()->moveBy(dx, dy); QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->item()->setRotation(angle); // tFatal() << "TupGraphicsScene::addTweeningObjects() - Applying rotation - Angle: " << angle; } addGraphicObject(object); } else { if (stepItem->has(TupTweenerStep::Position)) { qreal dx = stepItem->position().x() - (object->lastTweenPos().x() + adjustX); qreal dy = stepItem->position().y() - (object->lastTweenPos().y() + adjustY); object->item()->moveBy(dx, dy); QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->item()->setRotation(angle); } if (stepItem->has(TupTweenerStep::Scale)) { QPointF point = tween->transformOriginPoint(); double scaleX = stepItem->horizontalScale(); double scaleY = stepItem->verticalScale(); QTransform transform; transform.translate(point.x(), point.y()); transform.scale(scaleX, scaleY); transform.translate(-point.x(), -point.y()); object->item()->setTransform(transform); } if (stepItem->has(TupTweenerStep::Shear)) { QPointF point = tween->transformOriginPoint(); double shearX = stepItem->horizontalShear(); double shearY = stepItem->verticalShear(); QTransform transform; transform.translate(point.x(), point.y()); transform.shear(shearX, shearY); transform.translate(-point.x(), -point.y()); object->item()->setTransform(transform); } if (stepItem->has(TupTweenerStep::Coloring)) { QColor itemColor = stepItem->color(); if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(object->item())) { QPen pen = path->pen(); pen.setColor(itemColor); path->setPen(pen); } else if (TupEllipseItem *ellipse = qgraphicsitem_cast<TupEllipseItem *>(object->item())) { QPen pen = ellipse->pen(); pen.setColor(itemColor); ellipse->setPen(pen); } else if (TupLineItem *line = qgraphicsitem_cast<TupLineItem *>(object->item())) { QPen pen = line->pen(); pen.setColor(itemColor); line->setPen(pen); } else if (TupRectItem *rect = qgraphicsitem_cast<TupRectItem *>(object->item())) { QPen pen = rect->pen(); pen.setColor(itemColor); rect->setPen(pen); } } addGraphicObject(object); if (stepItem->has(TupTweenerStep::Opacity)) object->item()->setOpacity(stepItem->opacity()); } } } } } }
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 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); } }
bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &, const QgsReadWriteContext &context ) { mSettings.setHeight( itemElem.attribute( QStringLiteral( "height" ), QStringLiteral( "5.0" ) ).toDouble() ); mSettings.setLabelBarSpace( itemElem.attribute( QStringLiteral( "labelBarSpace" ), QStringLiteral( "3.0" ) ).toDouble() ); mSettings.setBoxContentSpace( itemElem.attribute( QStringLiteral( "boxContentSpace" ), QStringLiteral( "1.0" ) ).toDouble() ); mSettings.setNumberOfSegments( itemElem.attribute( QStringLiteral( "numSegments" ), QStringLiteral( "2" ) ).toInt() ); mSettings.setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral( "numSegmentsLeft" ), QStringLiteral( "0" ) ).toInt() ); mSettings.setUnitsPerSegment( itemElem.attribute( QStringLiteral( "numUnitsPerSegment" ), QStringLiteral( "1.0" ) ).toDouble() ); mSettings.setSegmentSizeMode( static_cast<QgsScaleBarSettings::SegmentSizeMode>( itemElem.attribute( QStringLiteral( "segmentSizeMode" ), QStringLiteral( "0" ) ).toInt() ) ); mSettings.setMinimumBarWidth( itemElem.attribute( QStringLiteral( "minBarWidth" ), QStringLiteral( "50" ) ).toDouble() ); mSettings.setMaximumBarWidth( itemElem.attribute( QStringLiteral( "maxBarWidth" ), QStringLiteral( "150" ) ).toDouble() ); mSegmentMillimeters = itemElem.attribute( QStringLiteral( "segmentMillimeters" ), QStringLiteral( "0.0" ) ).toDouble(); mSettings.setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QStringLiteral( "1.0" ) ).toDouble() ); mSettings.setLineWidth( itemElem.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "0.3" ) ).toDouble() ); mSettings.setUnitLabel( itemElem.attribute( QStringLiteral( "unitLabel" ) ) ); mSettings.setLineJoinStyle( QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "lineJoinStyle" ), QStringLiteral( "miter" ) ) ) ); mSettings.setLineCapStyle( QgsSymbolLayerUtils::decodePenCapStyle( itemElem.attribute( QStringLiteral( "lineCapStyle" ), QStringLiteral( "square" ) ) ) ); QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral( "text-style" ) ); if ( !textFormatNodeList.isEmpty() ) { QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement(); mSettings.textFormat().readXml( textFormatElem, context ); } else { QFont f; if ( !QgsFontUtils::setFromXmlChildNode( f, itemElem, QStringLiteral( "scaleBarFont" ) ) ) { f.fromString( itemElem.attribute( QStringLiteral( "font" ), QString() ) ); } mSettings.textFormat().setFont( f ); if ( f.pointSizeF() > 0 ) { mSettings.textFormat().setSize( f.pointSizeF() ); mSettings.textFormat().setSizeUnit( QgsUnitTypes::RenderPoints ); } else if ( f.pixelSize() > 0 ) { mSettings.textFormat().setSize( f.pixelSize() ); mSettings.textFormat().setSizeUnit( QgsUnitTypes::RenderPixels ); } } //colors //fill color QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral( "fillColor" ) ); if ( !fillColorList.isEmpty() ) { QDomElement fillColorElem = fillColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int fillRed, fillGreen, fillBlue, fillAlpha; fillRed = fillColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk ); fillGreen = fillColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk ); fillBlue = fillColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk ); fillAlpha = fillColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { mSettings.setFillColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) ); } } else { mSettings.setFillColor( QColor( itemElem.attribute( QStringLiteral( "brushColor" ), QStringLiteral( "#000000" ) ) ) ); } //fill color 2 QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral( "fillColor2" ) ); if ( !fillColor2List.isEmpty() ) { QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int fillRed, fillGreen, fillBlue, fillAlpha; fillRed = fillColor2Elem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk ); fillGreen = fillColor2Elem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk ); fillBlue = fillColor2Elem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk ); fillAlpha = fillColor2Elem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { mSettings.setFillColor2( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) ); } } else { mSettings.setFillColor2( QColor( itemElem.attribute( QStringLiteral( "brush2Color" ), QStringLiteral( "#ffffff" ) ) ) ); } //stroke color QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral( "strokeColor" ) ); if ( !strokeColorList.isEmpty() ) { QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int strokeRed, strokeGreen, strokeBlue, strokeAlpha; strokeRed = strokeColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk ); strokeGreen = strokeColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk ); strokeBlue = strokeColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk ); strokeAlpha = strokeColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { mSettings.setLineColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) ); QPen p = mSettings.pen(); p.setColor( mSettings.lineColor() ); mSettings.setPen( p ); } } else { mSettings.setLineColor( QColor( itemElem.attribute( QStringLiteral( "penColor" ), QStringLiteral( "#000000" ) ) ) ); QPen p = mSettings.pen(); p.setColor( mSettings.lineColor() ); mSettings.setPen( p ); } //font color QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral( "textColor" ) ); if ( !textColorList.isEmpty() ) { QDomElement textColorElem = textColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int textRed, textGreen, textBlue, textAlpha; textRed = textColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk ); textGreen = textColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk ); textBlue = textColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk ); textAlpha = textColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { mSettings.textFormat().setColor( QColor( textRed, textGreen, textBlue, textAlpha ) ); } } else if ( itemElem.hasAttribute( QStringLiteral( "fontColor" ) ) ) { QColor c; c.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) ); mSettings.textFormat().setColor( c ); } //style QString styleString = itemElem.attribute( QStringLiteral( "style" ), QString() ); setStyle( styleString.toLocal8Bit().data() ); if ( itemElem.attribute( QStringLiteral( "unitType" ) ).isEmpty() ) { QgsUnitTypes::DistanceUnit u = QgsUnitTypes::DistanceUnknownUnit; switch ( itemElem.attribute( QStringLiteral( "units" ) ).toInt() ) { case 0: u = QgsUnitTypes::DistanceUnknownUnit; break; case 1: u = QgsUnitTypes::DistanceMeters; break; case 2: u = QgsUnitTypes::DistanceFeet; break; case 3: u = QgsUnitTypes::DistanceNauticalMiles; break; } mSettings.setUnits( u ); } else { mSettings.setUnits( QgsUnitTypes::decodeDistanceUnit( itemElem.attribute( QStringLiteral( "unitType" ) ) ) ); } mSettings.setAlignment( static_cast< QgsScaleBarSettings::Alignment >( itemElem.attribute( QStringLiteral( "alignment" ), QStringLiteral( "0" ) ).toInt() ) ); //map disconnectCurrentMap(); mMap = nullptr; mMapUuid = itemElem.attribute( QStringLiteral( "mapUuid" ) ); return true; }
void CtrlMemView::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setBrush(Qt::white); painter.setPen(Qt::white); painter.drawRect(rect()); if (!debugger) return; int width = rect().width(); int numRows=(rect().bottom()/rowHeight)/2+1; QPen nullPen(0xFFFFFF); QPen currentPen(0xFF000000); QPen selPen(0x808080); QBrush lbr(0xFFFFFF); QBrush nullBrush(0xFFFFFF); QBrush currentBrush(0xFFEFE8); QBrush pcBrush(0x70FF70); QPen textPen; QFont normalFont("Arial", 10); QFont alignedFont("Monospace", 10); alignedFont.setStyleHint(QFont::Monospace); painter.setFont(normalFont); int i; curAddress&=~(align-1); for (i=-numRows; i<=numRows; i++) { unsigned int address=curAddress + i*align*alignMul; int rowY1 = rect().bottom()/2 + rowHeight*i - rowHeight/2; int rowY2 = rect().bottom()/2 + rowHeight*i + rowHeight/2; char temp[256]; painter.setBrush(currentBrush); if (selecting && address == (unsigned int)selection) painter.setPen(selPen); else painter.setPen(i==0 ? currentPen : nullPen); painter.drawRect(0, rowY1, 16-1, rowY2 - rowY1 - 1); painter.drawRect(16, rowY1, width - 16 -1, rowY2 - rowY1 - 1); painter.setBrush(nullBrush); textPen.setColor(0x600000); painter.setPen(textPen); painter.setFont(alignedFont); painter.drawText(17,rowY1-2+rowHeight, QString("%1").arg(address,8,16,QChar('0'))); textPen.setColor(0xFF000000); painter.setPen(textPen); if (debugger->isAlive()) { switch(mode) { case MV_NORMAL: { const char *m = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; if (Memory::IsValidAddress(address)) { EmuThread_LockDraw(true); u32 memory[4] = { debugger->readMemory(address), debugger->readMemory(address+4), debugger->readMemory(address+8), debugger->readMemory(address+12) }; EmuThread_LockDraw(false); m = (const char*)memory; sprintf(temp, "%08x %08x %08x %08x ................", memory[0],memory[1],memory[2],memory[3]); } for (int i=0; i<16; i++) { int c = (unsigned char)m[i]; if (c>=32 && c<255) temp[i+37]=c; } } painter.setFont(alignedFont); painter.drawText(85,rowY1 - 2 + rowHeight, temp); break; case MV_SYMBOLS: { textPen.setColor(0x0000FF); painter.setPen(textPen); int fn = symbolMap.GetSymbolNum(address); if (fn==-1) { sprintf(temp, "%s (ns)", Memory::GetAddressName(address)); } else sprintf(temp, "%s (0x%x b)", symbolMap.GetSymbolName(fn),symbolMap.GetSymbolSize(fn)); painter.drawText(205,rowY1 - 2 + rowHeight, temp); textPen.setColor(0xFF000000); painter.setPen(textPen); if (align==4) { u32 value = Memory::ReadUnchecked_U32(address); int symbolnum = symbolMap.GetSymbolNum(value); if(symbolnum>=0) sprintf(temp, "%08x [%s]", value, symbolMap.GetSymbolName(symbolnum)); } else if (align==2) { u16 value = Memory::ReadUnchecked_U16(address); int symbolnum = symbolMap.GetSymbolNum(value); if(symbolnum>=0) sprintf(temp, "%04x [%s]", value, symbolMap.GetSymbolName(symbolnum)); } painter.drawText(85,rowY1 - 2 + rowHeight, temp); break; } case MV_MAX: break; } } } }
void MathPlot::setupSincScatterDemo(QCustomPlot *customPlot) { customPlot->legend->setVisible(true); customPlot->legend->setFont(QFont("Helvetica",9)); // set locale to english, so we get english decimal separator: customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // add confidence band graphs: customPlot->addGraph(); QPen pen; pen.setStyle(Qt::DotLine); pen.setWidth(1); pen.setColor(QColor(180,180,180)); customPlot->graph(0)->setName("Confidence Band 68%"); customPlot->graph(0)->setPen(pen); customPlot->graph(0)->setBrush(QBrush(QColor(255,50,30,20))); customPlot->addGraph(); customPlot->legend->removeItem(customPlot->legend->itemCount()-1); // don't show two confidence band graphs in legend customPlot->graph(1)->setPen(pen); customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1)); // add theory curve graph: customPlot->addGraph(); pen.setStyle(Qt::DashLine); pen.setWidth(2); pen.setColor(Qt::red); customPlot->graph(2)->setPen(pen); customPlot->graph(2)->setName("Theory Curve"); // add data point graph: customPlot->addGraph(); customPlot->graph(3)->setPen(QPen(Qt::blue)); customPlot->graph(3)->setLineStyle(QCPGraph::lsNone); customPlot->graph(3)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 4)); customPlot->graph(3)->setErrorType(QCPGraph::etValue); customPlot->graph(3)->setErrorPen(QPen(QColor(180,180,180))); customPlot->graph(3)->setName("Measurement"); // generate ideal sinc curve data and some randomly perturbed data for scatter plot: QVector<double> x0(250), y0(250); QVector<double> yConfUpper(250), yConfLower(250); for (int i=0; i<250; ++i) { x0[i] = (i/249.0-0.5)*30+0.01; // by adding a small offset we make sure not do divide by zero in next code line y0[i] = sin(x0[i])/x0[i]; // sinc function yConfUpper[i] = y0[i]+0.15; yConfLower[i] = y0[i]-0.15; x0[i] *= 1000; } QVector<double> x1(50), y1(50), y1err(50); for (int i=0; i<50; ++i) { // generate a gaussian distributed random number: double tmp1 = rand()/(double)RAND_MAX; double tmp2 = rand()/(double)RAND_MAX; double r = sqrt(-2*log(tmp1))*cos(2*M_PI*tmp2); // box-muller transform for gaussian distribution // set y1 to value of y0 plus a random gaussian pertubation: x1[i] = (i/50.0-0.5)*30+0.25; y1[i] = sin(x1[i])/x1[i]+r*0.15; x1[i] *= 1000; y1err[i] = 0.15; } // pass data to graphs and let QCustomPlot determine the axes ranges so the whole thing is visible: customPlot->graph(0)->setData(x0, yConfUpper); customPlot->graph(1)->setData(x0, yConfLower); customPlot->graph(2)->setData(x0, y0); customPlot->graph(3)->setDataValueError(x1, y1, y1err); customPlot->graph(2)->rescaleAxes(); customPlot->graph(3)->rescaleAxes(true); // setup look of bottom tick labels: customPlot->xAxis->setTickLabelRotation(30); customPlot->xAxis->setAutoTickCount(9); customPlot->xAxis->setNumberFormat("ebc"); customPlot->xAxis->setNumberPrecision(1); customPlot->xAxis->moveRange(-10); // make top right axes clones of bottom left axes. Looks prettier: customPlot->axisRect()->setupFullAxesBox(); }
void MathPlot::setupScatterStyleDemo(QCustomPlot *customPlot) { customPlot->legend->setVisible(true); customPlot->legend->setFont(QFont("Helvetica", 9)); customPlot->legend->setRowSpacing(-3); QVector<QCPScatterStyle::ScatterShape> shapes; shapes << QCPScatterStyle::ssCross; shapes << QCPScatterStyle::ssPlus; shapes << QCPScatterStyle::ssCircle; shapes << QCPScatterStyle::ssDisc; shapes << QCPScatterStyle::ssSquare; shapes << QCPScatterStyle::ssDiamond; shapes << QCPScatterStyle::ssStar; shapes << QCPScatterStyle::ssTriangle; shapes << QCPScatterStyle::ssTriangleInverted; shapes << QCPScatterStyle::ssCrossSquare; shapes << QCPScatterStyle::ssPlusSquare; shapes << QCPScatterStyle::ssCrossCircle; shapes << QCPScatterStyle::ssPlusCircle; shapes << QCPScatterStyle::ssPeace; shapes << QCPScatterStyle::ssCustom; QPen pen; // add graphs with different scatter styles: for (int i=0; i<shapes.size(); ++i) { customPlot->addGraph(); pen.setColor(QColor(sin(i*0.3)*100+100, sin(i*0.6+0.7)*100+100, sin(i*0.4+0.6)*100+100)); // generate data: QVector<double> x(10), y(10); for (int k=0; k<10; ++k) { x[k] = k/10.0 * 4*3.14 + 0.01; y[k] = 7*sin(x[k])/x[k] + (shapes.size()-i)*5; } customPlot->graph()->setData(x, y); customPlot->graph()->rescaleAxes(true); customPlot->graph()->setPen(pen); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) customPlot->graph()->setName(QCPScatterStyle::staticMetaObject.enumerator(QCPScatterStyle::staticMetaObject.indexOfEnumerator("ScatterShape")).valueToKey(shapes.at(i))); #endif customPlot->graph()->setLineStyle(QCPGraph::lsLine); // set scatter style: if (shapes.at(i) != QCPScatterStyle::ssCustom) { customPlot->graph()->setScatterStyle(QCPScatterStyle(shapes.at(i), 10)); } else { QPainterPath customScatterPath; for (int i=0; i<3; ++i) customScatterPath.cubicTo(qCos(2*M_PI*i/3.0)*9, qSin(2*M_PI*i/3.0)*9, qCos(2*M_PI*(i+0.9)/3.0)*9, qSin(2*M_PI*(i+0.9)/3.0)*9, 0, 0); customPlot->graph()->setScatterStyle(QCPScatterStyle(customScatterPath, QPen(), QColor(40, 70, 255, 50), 10)); } } // set blank axis lines: customPlot->rescaleAxes(); customPlot->xAxis->setTicks(false); customPlot->yAxis->setTicks(false); customPlot->xAxis->setTickLabels(false); customPlot->yAxis->setTickLabels(false); // make top right axes clones of bottom left axes: customPlot->axisRect()->setupFullAxesBox(); }
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 Led::paintEvent(QPaintEvent *) { QPainter paint; QColor color; QBrush brush; QPen pen; // First of all we want to know what area should be updated // Initialize coordinates, width, and height of the LED int width = this->width(); // Make sure the LED is round! if (width > this->height()) width = this->height(); width -= 2; // leave one pixel border if (width < 0) width = 0; // maybe we could stop HERE, if width <=0 ? int scale = 1; QPixmap *tmpMap = 0; bool smooth = true; if (smooth) { if (led_state) { if (d->on_map) { paint.begin(this); paint.drawPixmap(0, 0, *d->on_map); paint.end(); return ; } } else { if (d->off_map) { paint.begin(this); paint.drawPixmap(0, 0, *d->off_map); paint.end(); return ; } } scale = 3; width *= scale; tmpMap = new QPixmap(width, width); QColor bg = m_Thorn ? QColor::fromRgb(0xDD, 0xDD, 0xDD) : palette().window().color(); tmpMap->fill(bg); paint.begin(tmpMap); } else { paint.begin(this); } paint.setRenderHint(QPainter::Antialiasing, false); // Set the color of the LED according to given parameters color = ( led_state ) ? led_color : d->offcolor; // Set the brush to SolidPattern, this fills the entire area // of the ellipse which is drawn first brush.setStyle( Qt::SolidPattern ); brush.setColor( color ); paint.setBrush( brush ); // Assign the brush to the painter // Draws a "flat" LED with the given color: paint.drawEllipse( scale, scale, width - scale*2, width - scale*2 ); // Draw the bright light spot of the LED now, using modified "old" // painter routine taken from KDEUI´s Led widget: // Setting the new width of the pen is essential to avoid "pixelized" // shadow like it can be observed with the old LED code pen.setWidth( 2 * scale ); // shrink the light on the LED to a size about 2/3 of the complete LED int pos = width / 5 + 1; int light_width = width; light_width *= 2; light_width /= 3; // Calculate the LED´s "light factor": int light_quote = (130 * 2 / (light_width ? light_width : 1)) + 100; // Now draw the bright spot on the LED: while (light_width) { color = color.light( light_quote ); // make color lighter pen.setColor( color ); // set color as pen color paint.setPen( pen ); // select the pen for drawing paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) light_width--; if (!light_width) break; paint.drawEllipse( pos, pos, light_width, light_width ); light_width--; if (!light_width) break; paint.drawEllipse( pos, pos, light_width, light_width ); pos++; light_width--; } paint.drawPoint(pos, pos); // Drawing of bright spot finished, now draw a thin border // around the LED which resembles a shadow with light coming // from the upper left. pen.setWidth( 2 * scale + 1 ); // ### shouldn't this value be smaller for smaller LEDs? brush.setStyle( Qt::NoBrush ); // Switch off the brush paint.setBrush( brush ); // This avoids filling of the ellipse // Set the initial color value to palette().light() (bright) and start // drawing the shadow border at 45° (45*16 = 720). int angle = -720; //color = palette().light(); color = Qt::white; for ( int arc = 120; arc < 2880; arc += 240 ) { pen.setColor( color ); paint.setPen( pen ); int w = width - pen.width() / 2 - scale + 1; paint.drawArc( pen.width() / 2, pen.width() / 2, w, w, angle + arc, 240 ); paint.drawArc( pen.width() / 2, pen.width() / 2, w, w, angle - arc, 240 ); color = color.dark( 110 ); //FIXME: this should somehow use the contrast value } // end for ( angle = 720; angle < 6480; angle += 160 ) paint.end(); // // painting done if (smooth) { QPixmap *&dest = led_state ? d->on_map : d->off_map; QImage i = tmpMap->toImage(); width /= 3; i = i.scaled(width, width, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); delete tmpMap; dest = new QPixmap(QPixmap::fromImage(i)); paint.begin(this); paint.drawPixmap(0, 0, *dest); paint.end(); } }
void CharsetWidget::paintEvent(QPaintEvent *event) { QPainter painter; painter.begin(this); painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole())); painter.setBrush(QColor(0,0,0)); painter.setPen(Qt::NoPen); auto state = State::getInstance(); int end_x = 8; int pixel_size_x = _pixelSize.width(); int increment_x = 1; int bits_to_mask = 1; if (state->shouldBeDisplayedInMulticolor()) { end_x = 4; pixel_size_x = _pixelSize.width() * 2; increment_x = 2; bits_to_mask = 3; } QPen pen; pen.setColor({149,195,244,255}); if (hasFocus()) pen.setWidth(3); else pen.setWidth(1); pen.setStyle(Qt::PenStyle::SolidLine); for (int w=0; w<COLUMNS; w++) { for (int h=0; h<ROWS; h++) { int index = w + h * COLUMNS; quint8* charPtr = state->getCharAtIndex(index); for (int y=0; y<8; y++) { char letter = charPtr[y]; for (int x=0; x<end_x; x++) { // Warning: Don't use 'char'. Instead use 'unsigned char'. // 'char' doesn't work Ok with << and >> // only mask the bits are needed unsigned char mask = bits_to_mask << (((end_x-1)-x) * increment_x); unsigned char color = letter & mask; // now transform those bits into values from 0-3 since those are the // possible colors int bits_to_shift = (((end_x-1)-x) * increment_x); int color_pen = color >> bits_to_shift; if (!state->shouldBeDisplayedInMulticolor() && color_pen ) color_pen = State::PEN_FOREGROUND; painter.setBrush(Palette::getColorForPen(color_pen)); painter.drawRect((w*end_x+x) * pixel_size_x + OFFSET, (h*8+y) * _pixelSize.height() + OFFSET, pixel_size_x, _pixelSize.height()); } } painter.setPen(Qt::NoPen); } } if (_selecting) { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(149,195,244,64)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, _selectingSize.width() * 8 * _pixelSize.width(), _selectingSize.height() * 8 * _pixelSize.height()); } else { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(128,0,0,0)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, 8 * _pixelSize.width(), 8 * _pixelSize.height()); } paintFocus(painter); painter.end(); }
void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) { Q_UNUSED( itemStyle ); Q_UNUSED( pWidget ); if ( !painter ) { return; } if ( !shouldDrawItem() ) { return; } if ( mComposition->plotStyle() == QgsComposition::Print || mComposition->plotStyle() == QgsComposition::Postscript ) { //exporting composition, so force an attribute refresh //we do this in case vector layer has changed via an external source (eg, another database user) refreshAttributes(); } drawBackground( painter ); painter->save(); //antialiasing on painter->setRenderHint( QPainter::Antialiasing, true ); painter->setPen( Qt::SolidLine ); //now draw the text double currentX = mGridStrokeWidth; double currentY; QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); int col = 0; double cellHeaderHeight = QgsComposerUtils::fontAscentMM( mHeaderFont ) + 2 * mLineTextDistance; double cellBodyHeight = QgsComposerUtils::fontAscentMM( mContentFont ) + 2 * mLineTextDistance; QRectF cell; for ( ; columnIt != mColumns.constEnd(); ++columnIt ) { currentY = mGridStrokeWidth; currentX += mLineTextDistance; cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellHeaderHeight ); //calculate alignment of header Qt::AlignmentFlag headerAlign = Qt::AlignLeft; switch ( mHeaderHAlignment ) { case FollowColumn: headerAlign = ( *columnIt )->hAlignment(); break; case HeaderLeft: headerAlign = Qt::AlignLeft; break; case HeaderCenter: headerAlign = Qt::AlignHCenter; break; case HeaderRight: headerAlign = Qt::AlignRight; break; } QgsComposerUtils::drawText( painter, cell, ( *columnIt )->heading(), mHeaderFont, mHeaderFontColor, headerAlign, Qt::AlignVCenter, Qt::TextDontClip ); currentY += cellHeaderHeight; currentY += mGridStrokeWidth; //draw the attribute values QList<QgsAttributeMap>::const_iterator attIt = mAttributeMaps.begin(); for ( ; attIt != mAttributeMaps.end(); ++attIt ) { cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellBodyHeight ); const QgsAttributeMap ¤tAttributeMap = *attIt; QString str = currentAttributeMap[ col ].toString(); QgsComposerUtils::drawText( painter, cell, str, mContentFont, mContentFontColor, ( *columnIt )->hAlignment(), Qt::AlignVCenter, Qt::TextDontClip ); currentY += cellBodyHeight; currentY += mGridStrokeWidth; } currentX += mMaxColumnWidthMap[ col ]; currentX += mLineTextDistance; currentX += mGridStrokeWidth; col++; } //and the borders if ( mShowGrid ) { QPen gridPen; gridPen.setWidthF( mGridStrokeWidth ); gridPen.setColor( mGridColor ); gridPen.setJoinStyle( Qt::MiterJoin ); painter->setPen( gridPen ); drawHorizontalGridLines( painter, mAttributeMaps.size() ); drawVerticalGridLines( painter, mMaxColumnWidthMap ); } painter->restore(); //draw frame and selection boxes if necessary drawFrame( painter ); if ( isSelected() ) { drawSelectionBoxes( painter ); } }
// paint a ROUND SUNKEN led lamp void KLed::paintSunken() { if ( paintCachedPixmap() ) return; QPainter paint; QColor color; QBrush brush; QPen pen; // First of all we want to know what area should be updated // Initialize coordinates, width, and height of the LED int width = ledWidth(); int scale = 3; QPixmap *tmpMap = 0; width *= scale; tmpMap = new QPixmap( width, width ); tmpMap->fill( palette().color( backgroundRole() ) ); paint.begin( tmpMap ); paint.setRenderHint(QPainter::Antialiasing); // Set the color of the LED according to given parameters color = ( d->state == On ) ? d->color : d->offColor; // Set the brush to SolidPattern, this fills the entire area // of the ellipse which is drawn first brush.setStyle( Qt::SolidPattern ); brush.setColor( color ); paint.setBrush( brush ); // Assign the brush to the painter // Draws a "flat" LED with the given color: paint.drawEllipse( scale, scale, width - scale * 2, width - scale * 2 ); // Draw the bright light spot of the LED now, using modified "old" // painter routine taken from KDEUI's KLed widget: // Setting the new width of the pen is essential to avoid "pixelized" // shadow like it can be observed with the old LED code pen.setWidth( 2 * scale ); // shrink the light on the LED to a size about 2/3 of the complete LED int pos = width / 5 + 1; int light_width = width; light_width *= 2; light_width /= 3; // Calculate the LED's "light factor": int light_quote = ( 130 * 2 / ( light_width ? light_width : 1 ) ) + 100; // Now draw the bright spot on the LED: while ( light_width ) { color = color.light( light_quote ); // make color lighter pen.setColor( color ); // set color as pen color paint.setPen( pen ); // select the pen for drawing paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) light_width--; if ( !light_width ) break; paint.drawEllipse( pos, pos, light_width, light_width ); light_width--; if ( !light_width ) break; paint.drawEllipse( pos, pos, light_width, light_width ); pos++; light_width--; } // Drawing of bright spot finished, now draw a thin border // around the LED which resembles a shadow with light coming // from the upper left. pen.setWidth( 2 * scale + 1 ); // ### shouldn't this value be smaller for smaller LEDs? brush.setStyle( Qt::NoBrush ); // Switch off the brush paint.setBrush( brush ); // This avoids filling of the ellipse // Set the initial color value to QColorGroup(palette()).light() (bright) and start // drawing the shadow border at 45° (45*16 = 720). int angle = -720; color = palette().color( QPalette::Light ); for ( int arc = 120; arc < 2880; arc += 240 ) { pen.setColor( color ); paint.setPen( pen ); int w = width - pen.width() / 2 - scale + 1; paint.drawArc( pen.width() / 2, pen.width() / 2, w, w, angle + arc, 240 ); paint.drawArc( pen.width() / 2, pen.width() / 2, w, w, angle - arc, 240 ); color = color.dark( 110 ); //FIXME: this should somehow use the contrast value } // end for ( angle = 720; angle < 6480; angle += 160 ) paint.end(); // painting done QPixmap *&dest = ( d->state == On ? d->onMap : d->offMap ); QImage i = tmpMap->toImage(); width /= 3; i = i.scaled( width, width, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); delete tmpMap; dest = new QPixmap( QPixmap::fromImage( i ) ); paint.begin( this ); paint.setCompositionMode(QPainter::CompositionMode_Source); paint.drawPixmap( 0, 0, *dest ); paint.end(); }
void NetworkGraphics::updateNetwork(){ qDebug() << "NetworkGraphics::updateNetwork()"; scene->clear(); linkMap.clear(); rebuildNetwork(); QPointF position = QPointF(0.0, 0.0); QList<raw_address> rootAddrs = network->getTopLevelAddresses(); for(int i=0; i<rootAddrs.size(); i++){ if(positionBranch(rootAddrs[i], position)){ QSizeF size = computeSize(rootAddrs[i]); QRectF rect = QRectF(position, size); //scene->addRect(rect);*/ position.setX( position.x() + size.width() + (3.0*CLOUD_X_MARGIN) ); //scene->update(rect); } } //Draw links QList<NetLink*> links = network->getLinks(); QPen blackPen = QPen(); blackPen.setColor(Qt::gray); blackPen.setWidth(2); for(int i=0; i<links.size(); i++){ NetLink* link = links[i]; GraphicNetCloud* firstCloud = cloudMap[nodeMap[link->getFirst()]]; GraphicNetCloud* secondCloud = cloudMap[nodeMap[link->getSecond()]]; if(firstCloud != secondCloud){ QPointF startPoint = firstCloud->boundingRect().center(); QPointF endPoint = secondCloud->boundingRect().center(); startPoint.setX(firstCloud->pos().x() + startPoint.x()); startPoint.setY(firstCloud->pos().y() + startPoint.y()); endPoint.setX(secondCloud->pos().x() + endPoint.x()); endPoint.setY(secondCloud->pos().y() + endPoint.y()); QLineF line(startPoint, endPoint); QGraphicsLineItem* lineItem = new QGraphicsLineItem(line); lineItem->setPen(blackPen); lineItem->setZValue(1); lineItem->setOpacity(.8); scene->addItem(lineItem); //qDebug() << "Line: " << line ; linkMap.insert(link, lineItem); } } }
void MathPlot::setupMultiAxisDemo(QCustomPlot *customPlot) { customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator customPlot->legend->setVisible(true); QFont legendFont = font(); // start out with MainWindow's font.. legendFont.setPointSize(9); // and make a bit smaller for legend customPlot->legend->setFont(legendFont); customPlot->legend->setBrush(QBrush(QColor(255,255,255,230))); // by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement: customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight); // setup for graph 0: key axis left, value axis bottom // will contain left maxwell-like function customPlot->addGraph(customPlot->yAxis, customPlot->xAxis); customPlot->graph(0)->setPen(QPen(QColor(255, 100, 0))); customPlot->graph(0)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // fill with texture of specified image customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); customPlot->graph(0)->setName("Left maxwell function"); // setup for graph 1: key axis bottom, value axis left (those are the default axes) // will contain bottom maxwell-like function customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(Qt::red)); customPlot->graph(1)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // same fill as we used for graph 0 customPlot->graph(1)->setLineStyle(QCPGraph::lsStepCenter); customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::white, 7)); customPlot->graph(1)->setErrorType(QCPGraph::etValue); customPlot->graph(1)->setName("Bottom maxwell function"); // setup for graph 2: key axis top, value axis right // will contain high frequency sine with low frequency beating: customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2); customPlot->graph(2)->setPen(QPen(Qt::blue)); customPlot->graph(2)->setName("High frequency sine"); // setup for graph 3: same axes as graph 2 // will contain low frequency beating envelope of graph 2 customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2); QPen blueDotPen; blueDotPen.setColor(QColor(30, 40, 255, 150)); blueDotPen.setStyle(Qt::DotLine); blueDotPen.setWidthF(4); customPlot->graph(3)->setPen(blueDotPen); customPlot->graph(3)->setName("Sine envelope"); // setup for graph 4: key axis right, value axis top // will contain parabolically distributed data points with some random perturbance customPlot->addGraph(customPlot->yAxis2, customPlot->xAxis2); customPlot->graph(4)->setPen(QColor(50, 50, 50, 255)); customPlot->graph(4)->setLineStyle(QCPGraph::lsNone); customPlot->graph(4)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4)); customPlot->graph(4)->setName("Some random data around\na quadratic function"); // generate data, just playing with numbers, not much to learn here: QVector<double> x0(25), y0(25); QVector<double> x1(15), y1(15), y1err(15); QVector<double> x2(250), y2(250); QVector<double> x3(250), y3(250); QVector<double> x4(250), y4(250); for (int i=0; i<25; ++i) // data for graph 0 { x0[i] = 3*i/25.0; y0[i] = exp(-x0[i]*x0[i]*0.8)*(x0[i]*x0[i]+x0[i]); } for (int i=0; i<15; ++i) // data for graph 1 { x1[i] = 3*i/15.0;; y1[i] = exp(-x1[i]*x1[i])*(x1[i]*x1[i])*2.6; y1err[i] = y1[i]*0.25; } for (int i=0; i<250; ++i) // data for graphs 2, 3 and 4 { x2[i] = i/250.0*3*M_PI; x3[i] = x2[i]; x4[i] = i/250.0*100-50; y2[i] = sin(x2[i]*12)*cos(x2[i])*10; y3[i] = cos(x3[i])*10; y4[i] = 0.01*x4[i]*x4[i] + 1.5*(rand()/(double)RAND_MAX-0.5) + 1.5*M_PI; } // pass data points to graphs: customPlot->graph(0)->setData(x0, y0); customPlot->graph(1)->setDataValueError(x1, y1, y1err); customPlot->graph(2)->setData(x2, y2); customPlot->graph(3)->setData(x3, y3); customPlot->graph(4)->setData(x4, y4); // activate top and right axes, which are invisible by default: customPlot->xAxis2->setVisible(true); customPlot->yAxis2->setVisible(true); // set ranges appropriate to show data: customPlot->xAxis->setRange(0, 2.7); customPlot->yAxis->setRange(0, 2.6); customPlot->xAxis2->setRange(0, 3.0*M_PI); customPlot->yAxis2->setRange(-70, 35); // set pi ticks on top axis: QVector<double> piTicks; QVector<QString> piLabels; piTicks << 0 << 0.5*M_PI << M_PI << 1.5*M_PI << 2*M_PI << 2.5*M_PI << 3*M_PI; piLabels << "0" << QString::fromUtf8("½π") << QString::fromUtf8("π") << QString::fromUtf8("1½π") << QString::fromUtf8("2π") << QString::fromUtf8("2½π") << QString::fromUtf8("3π"); customPlot->xAxis2->setAutoTicks(false); customPlot->xAxis2->setAutoTickLabels(false); customPlot->xAxis2->setTickVector(piTicks); customPlot->xAxis2->setTickVectorLabels(piLabels); // add title layout element: customPlot->plotLayout()->insertRow(0); customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, "Way too many graphs in one plot")); // set labels: customPlot->xAxis->setLabel("Bottom axis with outward ticks"); customPlot->yAxis->setLabel("Left axis label"); customPlot->xAxis2->setLabel("Top axis label"); customPlot->yAxis2->setLabel("Right axis label"); // make ticks on bottom axis go outward: customPlot->xAxis->setTickLength(0, 5); customPlot->xAxis->setSubTickLength(0, 3); // make ticks on right axis go inward and outward: customPlot->yAxis2->setTickLength(3, 3); customPlot->yAxis2->setSubTickLength(1, 1); }
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { ITEM_HEIGHT = index.model()->property("item_height").toInt(); ITEM_WIDTH = index.model()->property("item_width").toInt(); if(ITEM_HEIGHT == 0 || ITEM_WIDTH == 0){ ITEM_WIDTH = 200; ITEM_HEIGHT = 200; } if(!qVariantCanConvert<MoviePtr>(index.data())) return; MoviePtr movie = index.data().value<MoviePtr>(); if(!movie) return; QPixmap pixmap("/Users/Blecam/Developpement/Fourre-tout/Mooztik/ressources/nopreview/no-preview-movie.jpg"); /*QPixmap pixmap(movie->poster()->pathThumbnail()); if(!QPixmapCache::find(movie->poster()->pathThumbnail(), &pixmap)){ QPixmapCache::insert(movie->poster()->pathThumbnail(), pixmap); }*/ const bool isSelected = option.state & QStyle::State_Selected; const bool isHovered = option.state & QStyle::State_MouseOver; const bool playSelected = index.model()->property("play_clicked").toBool(); QRect rect(0, 10, ITEM_WIDTH, ITEM_HEIGHT); rect.setWidth(option.rect.width()-10); painter->setRenderHint(QPainter::Antialiasing); painter->save(); painter->translate(option.rect.topLeft()); QRect posterRect(10, 10, ITEM_WIDTH-20, ITEM_HEIGHT-70); painter->drawPixmap(posterRect, pixmap); QRectF selectionRect(9, 9, posterRect.width()+2, posterRect.height()+2); QPen penBorder; penBorder.setWidth(7); penBorder.setColor(Qt::white); painter->setPen(penBorder); painter->drawRoundedRect(selectionRect, 10, 10); if(isSelected) { penBorder.setWidth(4); penBorder.setColor(QColor(38, 161, 241)); painter->setPen(penBorder); painter->drawRoundedRect(posterRect, 10, 10); } painter->restore(); painter->save(); QFont fontText(painter->font()); fontText.setFamily("Helvetia"); fontText.setBold(true); painter->setFont(fontText); painter->translate(option.rect.topLeft()); QString movie_title = movie->title(); QFontMetrics fm(painter->font()); if(movie_title.size() > 28) { movie_title.truncate(25); movie_title += "..." ; } painter->setPen(Qt::black); QRect textRect(0, rect.height()-60, option.rect.width(), 30); painter->drawText(textRect, Qt::AlignCenter, movie_title); painter->restore(); painter->save(); painter->translate(option.rect.topLeft()); QRect ratingRect(0, rect.height()-35, option.rect.width(), 15); //painter->fillRect(ratingRect, QColor(0, 0, 0, 230)); if(movie->rating() > 0) { QIcon iconRating(":/icons/rating"+QString::number(movie->rating())); iconRating.paint(painter, ratingRect, Qt::AlignCenter); } painter->restore(); if(movie->isFavorite()) { painter->save(); painter->translate(option.rect.topLeft()); QRect rectFav; rectFav = QRect(pixmap.rect().topLeft().x()+5, pixmap.rect().topLeft().y()+5, 20, 20); QIcon iconFav(":/icons/favorite"); iconFav.paint(painter, rectFav, Qt::AlignCenter); painter->restore(); } if(isHovered) { if(playSelected) { } } }
QVariant RelationshipView::itemChange(GraphicsItemChange change, const QVariant &value) { if(change==ItemPositionChange) { this->setFlag(QGraphicsItem::ItemIsMovable, false); } else if(change==ItemSelectedHasChanged) { unsigned i, count; QPen pen; QColor color, line_color=this->getSourceObject()->getCustomColor(); vector<QGraphicsLineItem *> rel_lines; this->setSelectionOrder(value.toBool()); pos_info_rect->setVisible(value.toBool()); pos_info_txt->setVisible(value.toBool()); obj_selection->setVisible(value.toBool()); this->configurePositionInfo(); for(i=0; i < 3; i++) { if(labels[i]) labels[i]->itemChange(change, value); } //Show tha graphical points if 'value' is true count=graph_points.size(); for(i=0; i < count; i++) graph_points[i]->setVisible(value.toBool()); //Alter the relationship line color when it is selected if(line_color==Qt::transparent) line_color=BaseObjectView::getBorderStyle(ParsersAttributes::RELATIONSHIP).color(); if(value.toBool()) { QColor cor1=BaseObjectView::getBorderStyle(ParsersAttributes::OBJ_SELECTION).color(), cor2=line_color; color.setRedF((cor1.redF() + cor2.greenF())/2.0f); color.setGreenF((cor1.greenF() + cor2.greenF())/2.0f); color.setBlueF((cor1.blueF() + cor2.blueF())/2.0f); color.setAlphaF((cor1.alphaF() + cor2.alphaF())/2.0f); } else color=line_color; rel_lines=lines; rel_lines.insert(rel_lines.end(), fk_lines.begin(), fk_lines.end()); rel_lines.insert(rel_lines.end(), pk_lines.begin(), pk_lines.end()); for(auto lin : rel_lines) { pen=lin->pen(); pen.setColor(color); lin->setPen(pen); } //Shows/hides the attribute's selection count=attributes.size(); for(i=0; i < count; i++) attributes[i]->childItems().at(3)->setVisible(value.toBool()); emit s_objectSelected(dynamic_cast<BaseGraphicObject *>(this->getSourceObject()), value.toBool()); } return(value); }
void SectionViewWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.save(); MainFrame* pMainFrame = (MainFrame*)s_pMainFrame; QPen LinePen; LinePen.setColor(QColor(255,0,0)); LinePen.setWidth(2); painter.setPen(LinePen); painter.fillRect(rect(), pMainFrame->m_BackgroundColor); painter.setFont(pMainFrame->m_TextFont); if(m_bZoomIn&& !m_ZoomRect.isEmpty()) { QRect ZRect = m_ZoomRect.normalized(); QPen ZoomPen(QColor(100,100,100)); ZoomPen.setStyle(Qt::DashLine); painter.setPen(ZoomPen); painter.drawRect(ZRect); } if(m_bNeutralLine) { QPen NPen(m_NeutralColor); NPen.setStyle(GetStyle(m_NeutralStyle)); NPen.setWidth(m_NeutralWidth); painter.setPen(NPen); painter.drawLine(rect().right(), m_ptOffset.y(), rect().left(), m_ptOffset.y()); painter.drawLine(m_ptOffset.x(), rect().bottom(), m_ptOffset.x(), rect().top()); } if(!s_bCurrentOnly && m_pSail /* && m_pSail->IsSailcutSail()*/) { QColor clr = m_pSailSection->m_SCSpline.m_SplineColor; clr.setHsv(clr.hue(), (int)(clr.saturation()), (int)(clr.value()*.29)); QPen OtherPen(clr); OtherPen.setStyle(Qt::DashLine); OtherPen.setWidth(1.0); painter.setPen(OtherPen); for(int is=0; is<m_pSail->m_oaSection.size(); is++) { SailSection *pSection = (SailSection*)m_pSail->m_oaSection.at(is); if(pSection != m_pSailSection) { if(m_pSail->IsSailcutSail()) pSection->DrawSpline(painter, m_Scale,m_Scale*m_ScaleY, m_ptOffset, false); else { NURBSSail *pNSail = (NURBSSail*)m_pSail; int index = m_pSail->m_oaSection.indexOf(m_pSailSection); if(is!=index) pNSail->DrawFrame(is, painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } } } } if(m_pSailSection) { if(m_pSail->IsNURBSSail()) { NURBSSail *pNSail = (NURBSSail*)m_pSail; int index = m_pSail->m_oaSection.indexOf(m_pSailSection); QPen SplinePen; SplinePen.setStyle(GetStyle(m_pSailSection->m_SCSpline.m_Style)); SplinePen.setWidth(m_pSailSection->m_SCSpline.m_Width); SplinePen.setColor(m_pSailSection->m_SCSpline.m_SplineColor); painter.setPen(SplinePen); // if(index==0 || index==m_pSail->m_oaSection.size()-1) { pNSail->DrawFrame(index, painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } m_pSailSection->DrawCtrlPoints(painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } else { m_pSailSection->DrawSpline(painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } } QPen TextPen(pMainFrame->m_TextColor); painter.setPen(TextPen); PaintLegend(painter); QString str; str = QString("X-Scale = %1").arg(m_Scale/m_RefScale,4,'f',1); painter.drawText(5,10, str); str = QString("Y-Scale = %1").arg(m_ScaleY*m_Scale/m_RefScale,4,'f',1); painter.drawText(5,22, str); str = QString("x = %1").arg(m_MousePos.x,7,'f',4); painter.drawText(5,34, str); str = QString("y = %1").arg(m_MousePos.y,7,'f',4); painter.drawText(5,46, str); painter.restore(); }
void RelationshipView::configureLine(void) { if(!configuring_line) { BaseRelationship *base_rel=this->getSourceObject(); Relationship *rel=dynamic_cast<Relationship *>(base_rel); vector<QPointF> points, fk_points, pk_points; QGraphicsLineItem *lin=nullptr; QPointF pos, p_int, p_central[2], pk_pnt, fk_pnt; QRectF rect; QPen pen; QGraphicsPolygonItem *pol=nullptr; QPolygonF pol_aux; QString tool_tip; QGraphicsItem *item=nullptr; int i, i1, count, idx_lin_desc=0; bool bidirectional=base_rel->isBidirectional(); configuring_line=true; pen.setCapStyle(Qt::RoundCap); if(base_rel->isSelfRelationship()) { float fator=font_config[ParsersAttributes::GLOBAL].font().pointSizeF()/DEFAULT_FONT_SIZE; /* Sefl-relationshihp line format: +----<> | | ---------- | | Table |---+ ---------- This line cannot be moved or have points added */ pos=tables[0]->pos(); rect=tables[0]->boundingRect(); p_central[0].setX(pos.x() + rect.width()); p_central[0].setY(pos.y() + (rect.height()/2.5f)); p_central[1].setX(pos.x() + (rect.width()/1.5f)); p_central[1].setY(pos.y()); points.push_back(QPointF(p_central[0].x() + (10 * fator), p_central[0].y())); points.push_back(QPointF(p_central[0].x() + (10 * fator), p_central[1].y() - (10 * fator))); points.push_back(QPointF(p_central[1].x(), p_central[1].y() - (10 * fator))); base_rel->setPoints(points); } else { Relationship *rel=dynamic_cast<Relationship *>(base_rel); bool rel_1n=( !bidirectional && (base_rel->getRelationshipType()==Relationship::RELATIONSHIP_11 || base_rel->getRelationshipType()==Relationship::RELATIONSHIP_1N || base_rel->getRelationshipType()==Relationship::RELATIONSHIP_FK)); if(rel && rel->getRelationshipType()==Relationship::RELATIONSHIP_11 && rel->isIdentifier()) { tables[0]=dynamic_cast<BaseTableView *>(rel->getReferenceTable()->getReceiverObject()); tables[1]=dynamic_cast<BaseTableView *>(rel->getReceiverTable()->getReceiverObject()); } if(line_conn_mode==CONNECT_CENTER_PNTS || !rel_1n) { vector<vector<QGraphicsLineItem *> *> ref_lines={ &fk_lines, &pk_lines }; for(i=0; i < 2; i++) p_central[i]=tables[i]->getCenter(); //Destroying the fk and pk connection lines when the line mode changes for(i=0; i < 2; i++) { while(!ref_lines[i]->empty()) { item=ref_lines[i]->back(); ref_lines[i]->pop_back(); this->removeFromGroup(item); delete(item); } } } else if(line_conn_mode==CONNECT_FK_TO_PK && rel_1n) { QPointF pnt; QRectF rec_tab_rect, ref_tab_rect; float fk_py=0, pk_py=0, fk_px=0, pk_px=0; vector<Constraint *> fks; Table *ref_tab=nullptr, *rec_tab=nullptr; TableView *ref_tab_view=nullptr, *rec_tab_view=nullptr; unsigned cnt=0, i=0, pk_pnt_type=0, fk_pnt_type=0; if(!rel) { ref_tab=dynamic_cast<Table *>(base_rel->getTable(BaseRelationship::DST_TABLE)); rec_tab=dynamic_cast<Table *>(base_rel->getTable(BaseRelationship::SRC_TABLE)); } else { ref_tab=rel->getReferenceTable(); rec_tab=rel->getReceiverTable(); } rec_tab->getForeignKeys(fks, true, ref_tab); ref_tab_view=dynamic_cast<TableView *>(ref_tab->getReceiverObject()); rec_tab_view=dynamic_cast<TableView *>(rec_tab->getReceiverObject()); //Create the table's rectangles to detect where to connect the relationship ref_tab_rect=QRectF(ref_tab_view->pos(), ref_tab_view->boundingRect().size()); //In this case the receiver table rect Y must be equal to reference table Y in order to do the correct comparison rec_tab_rect=QRectF(QPointF(rec_tab_view->pos().x(), ref_tab_view->pos().y()), rec_tab_view->boundingRect().size()); if(ref_tab_rect.intersects(rec_tab_rect)) { //Connects the rectangle at the same sides on both tables if(rec_tab_rect.center().x() >= ref_tab_rect.center().x()) pk_pnt_type=fk_pnt_type=BaseTableView::LEFT_CONN_POINT; else if(rec_tab_rect.center().x() < ref_tab_rect.center().x()) pk_pnt_type=fk_pnt_type=BaseTableView::RIGHT_CONN_POINT; } else { //Connecting the relationship on the opposite sides depending on the tables' position if(ref_tab_rect.right() <= rec_tab_rect.left()) { pk_pnt_type=BaseTableView::RIGHT_CONN_POINT; fk_pnt_type=BaseTableView::LEFT_CONN_POINT; } else { pk_pnt_type=BaseTableView::LEFT_CONN_POINT; fk_pnt_type=BaseTableView::RIGHT_CONN_POINT; } } for(auto constr : fks) { cnt=constr->getColumnCount(Constraint::SOURCE_COLS); for(i=0; i < cnt; i++) { pnt=rec_tab_view->getConnectionPoints(constr->getColumn(i, Constraint::SOURCE_COLS), fk_pnt_type); fk_py+=pnt.y(); fk_px=pnt.x(); fk_points.push_back(this->mapFromItem(rec_tab_view, pnt)); pnt=ref_tab_view->getConnectionPoints(constr->getColumn(i, Constraint::REFERENCED_COLS), pk_pnt_type); pk_py+=pnt.y(); pk_px=pnt.x(); pk_points.push_back(this->mapFromItem(ref_tab_view, pnt)); } } if(!fks.empty()) { float pk_dx=(pk_pnt_type==BaseTableView::LEFT_CONN_POINT ? -CONN_LINE_LENGTH : CONN_LINE_LENGTH), fk_dx=(fk_pnt_type==BaseTableView::LEFT_CONN_POINT ? -CONN_LINE_LENGTH : CONN_LINE_LENGTH); pk_pnt=this->mapFromItem(ref_tab_view, QPointF(pk_px + pk_dx, pk_py/pk_points.size())); fk_pnt=this->mapFromItem(rec_tab_view, QPointF(fk_px + fk_dx, fk_py/fk_points.size())); if(base_rel->getRelationshipType()==Relationship::RELATIONSHIP_FK) { p_central[1]=pk_pnt; p_central[0]=fk_pnt; } else { p_central[0]=pk_pnt; p_central[1]=fk_pnt; } } } points=base_rel->getPoints(); count=points.size(); pol_aux.append(QPointF(0,0)); pol_aux.append(QPointF(5,0)); pol_aux.append(QPointF(5,5)); pol_aux.append(QPointF(0,5)); for(i=0; i < count; i++) { if(i >= static_cast<int>(graph_points.size())) { pol=new QGraphicsPolygonItem; graph_points.push_back(pol); pol->setZValue(0); pol->setPolygon(pol_aux); pol->setBrush(BaseObjectView::getFillStyle(ParsersAttributes::OBJ_SELECTION)); pol->setPen(BaseObjectView::getBorderStyle(ParsersAttributes::OBJ_SELECTION)); this->addToGroup(pol); } else pol=graph_points[i]; pol->setPos(points[i]); pol->moveBy(-GRAPHIC_PNT_RADIUS/2.5, -GRAPHIC_PNT_RADIUS/2.5); pol->setVisible(this->isSelected()); } //Destroy the graphical points not used i=graph_points.size()-1; while(i > count-1) { item=graph_points.back(); graph_points.pop_back(); this->removeFromGroup(item); delete(item); i--; } } conn_points[0]=p_central[0]; conn_points[1]=p_central[1]; //Configuring the relationship line color if(base_rel->getCustomColor()!=Qt::transparent) //Using custom color pen.setColor(base_rel->getCustomColor()); else //Using the default color pen=BaseObjectView::getBorderStyle(ParsersAttributes::RELATIONSHIP); //For dependency relationships the line is dashed if(base_rel->getRelationshipType()==BaseRelationship::RELATIONSHIP_DEP) pen.setStyle(Qt::DashLine); points.insert(points.begin(),p_central[0]); points.push_back(p_central[1]); /* For identifier relationships an additional point is created on the center of the line that supports the descriptor in order to modify the line thickness on the weak entity side */ if(rel && rel->isIdentifier()) { //Calculates the index of the initial point, on the line that supports the descriptor idx_lin_desc=(points.size()/2); p_central[0]=points[idx_lin_desc]; //Gets the second line point if(idx_lin_desc + 1 > static_cast<int>(points.size())) p_central[1]=points[idx_lin_desc+1]; else p_central[1]=points[idx_lin_desc-1]; //Calculates the middle point and inserts it on the point vector p_int.setX((p_central[0].x() + p_central[1].x())/2.0f); p_int.setY((p_central[0].y() + p_central[1].y())/2.0f); points.insert(points.begin() + idx_lin_desc, p_int); } if(line_conn_mode==CONNECT_FK_TO_PK) { vector<QPointF> ref_points={ fk_pnt, pk_pnt }; vector<vector<QPointF> *> ref_pnt_vects={ &fk_points, &pk_points }; vector<vector<QGraphicsLineItem *> *> ref_lines={ &fk_lines, &pk_lines }; vector<QPointF> *ref_pnt=nullptr; vector<QGraphicsLineItem *> *ref_lin=nullptr; for(unsigned vet_idx=0; vet_idx < 2; vet_idx++) { ref_pnt=ref_pnt_vects[vet_idx]; ref_lin=ref_lines[vet_idx]; count=ref_pnt->size(); for(i=0; i < count; i++) { if(i >= static_cast<int>(ref_lin->size())) { lin=new QGraphicsLineItem; lin->setZValue(-1); ref_lin->push_back(lin); this->addToGroup(lin); } else lin=ref_lin->at(i); //If the relationship is identifier or bidirectional, the line has its thickness modified if(rel && (rel->isIdentifier() && vet_idx==0)) pen.setWidthF(1.75f); else pen.setWidthF(1.15f); lin->setLine(QLineF(ref_pnt->at(i), ref_points[vet_idx])); lin->setPen(pen); } //Destroy the unused pk or fk lines i=ref_lin->size()-1; while(i > static_cast<int>(count-1)) { item=ref_lin->back(); ref_lin->pop_back(); this->removeFromGroup(item); delete(item); i--; } } } //Create the relationship lines count=points.size(); for(i=0; i < count-1; i++) { if(i >= static_cast<int>(lines.size())) { lin=new QGraphicsLineItem; lin->setZValue(-1); lines.push_back(lin); this->addToGroup(lin); } else lin=lines[i]; //If the relationship is identifier or bidirectional, the line has its thickness modified if(bidirectional || (rel && (rel->isIdentifier() && i >= idx_lin_desc))) pen.setWidthF(1.75f); else pen.setWidthF(1.15f); lin->setLine(QLineF(points[i], points[i+1])); lin->setPen(pen); } //Removing unused lines if(!base_rel->isSelfRelationship()) { i=points.size()-1; i1=lines.size(); while(i1 > i) { item=lines.back(); lines.pop_back(); this->removeFromGroup(item); delete(item); i1--; } } this->configureDescriptor(); this->configureLabels(); this->configureProtectedIcon(); configuring_line=false; /* Making a little tweak on the foreign key type name. Despite being of class BaseRelationship, for semantics purposes shows the type of this relationship as "Relationship" unlike "Link" */ if(base_rel->getRelationshipType()==BaseRelationship::RELATIONSHIP_FK) tool_tip=/*Utf8String::create(*/base_rel->getName(true) + QString(" (") + BaseObject::getTypeName(OBJ_RELATIONSHIP) + QString(")"); else tool_tip=/*Utf8String::create(*/base_rel->getName(true) + QString(" (") + base_rel->getTypeName() + QString(")"); tool_tip += QString("\nId: %1").arg(base_rel->getObjectId()); this->setToolTip(tool_tip); for(i=0; i < 3; i++) { if(labels[i]) labels[i]->setToolTip(tool_tip); } descriptor->setToolTip(tool_tip); } }
void PrinterSettings::updatePreview() { QRect rectImg(QPoint(0, 0), ui->marginsPereview->size()); QImage img(rectImg.size(), QImage::Format_ARGB32); img.fill(Qt::transparent); QPainter painter(&img); QRectF rect1Up(0.5, 5.5, 70.5, 100.5); QRectF rect2Up(0.5, 5.5, 101.5, 70.5); rect1Up.moveCenter(ui->marginsPereview->rect().center()); rect1Up.moveLeft((rectImg.width() - rect1Up.width() - rect2Up.width()) / 3.0); rect2Up.moveCenter(ui->marginsPereview->rect().center()); rect2Up.moveRight(rectImg.right() - rect1Up.left()); painter.fillRect(rect1Up, Qt::white); painter.fillRect(rect2Up, Qt::white); QRectF rect1UpPage = rect1Up.adjusted(3, 3, -3, -3); QRectF rect2UpPage1 = rect2Up.adjusted(3, 3, -3, -3); rect2UpPage1.setRight(rect2Up.center().x() - 2); QRectF rect2UpPage2 = rect2Up.adjusted(3, 3, -3, -3); rect2UpPage2.setLeft(rect2Up.center().x() + 4); QPen pen = painter.pen(); if (ui->borderCbx->isChecked()) { pen.setColor(Qt::lightGray); pen.setStyle(Qt::SolidLine); } else { pen.setColor(Qt::lightGray); pen.setStyle(Qt::DotLine); } painter.setPen(pen); painter.drawRect(rect1UpPage); painter.drawRect(rect2UpPage1); painter.drawRect(rect2UpPage2); QColor mark("#CC7373"); if (ui->topMarginSpin->hasFocus()) { QRectF rect; rect.setTop(rect1Up.top()); rect.setLeft(rect1UpPage.left()); rect.setBottom(rect1UpPage.top()); rect.setRight(rect1UpPage.right()); painter.fillRect(rect, mark); rect.setTop(rect2UpPage1.top()); rect.setLeft(rect2Up.left()); rect.setBottom(rect2UpPage1.bottom()); rect.setRight(rect2UpPage1.left()); painter.fillRect(rect, mark); } if (ui->bottomMarginSpin->hasFocus()) { QRectF rect; rect.setTop(rect1UpPage.bottom()); rect.setLeft(rect1UpPage.left()); rect.setBottom(rect1Up.bottom()); rect.setRight(rect1UpPage.right()); painter.fillRect(rect, mark); rect.setTop(rect2UpPage1.top()); rect.setLeft(rect2UpPage2.right() + 0.5); rect.setBottom(rect2UpPage1.bottom()); rect.setRight(rect2Up.right()); painter.fillRect(rect, mark); } if (ui->leftMarginSpin->hasFocus()) { QRectF rect; rect.setTop(rect1UpPage.top()); rect.setLeft(rect1Up.left()); rect.setBottom(rect1UpPage.bottom()); rect.setRight(rect1UpPage.left()); painter.fillRect(rect, mark); rect.setTop(rect2UpPage1.bottom()); rect.setLeft(rect2UpPage1.left()); rect.setBottom(rect2Up.bottom()); rect.setRight(rect2UpPage2.right()); painter.fillRect(rect, mark); } if (ui->rightMarginSpin->hasFocus()) { QRectF rect; rect.setTop(rect1UpPage.top()); rect.setLeft(rect1Up.left()); rect.setBottom(rect1UpPage.bottom()); rect.setRight(rect1UpPage.left()); painter.fillRect(rect, mark); rect.setTop(rect2Up.top()); rect.setLeft(rect2UpPage1.left()); rect.setBottom(rect2UpPage1.top()); rect.setRight(rect2UpPage2.right()); painter.fillRect(rect, mark); } if (ui->internalMarginSpin->hasFocus()) { QRectF rect; rect.setTop(rect2UpPage1.top()); rect.setLeft(rect2UpPage1.right()); rect.setBottom(rect2UpPage1.bottom()); rect.setRight(rect2Up.center().x()); painter.fillRect(rect, mark); rect.setTop(rect2UpPage2.top()); rect.setLeft(rect2Up.center().x() + 1); rect.setBottom(rect2UpPage2.bottom()); rect.setRight(rect2UpPage2.left()-1); painter.fillRect(rect, mark); } ui->marginsPereview->setPixmap(QPixmap::fromImage(img)); }
void RelationshipView::configureDescriptor(void) { QLineF lin; QPolygonF pol; BaseRelationship *base_rel=this->getSourceObject(); Relationship *rel=dynamic_cast<Relationship *>(base_rel); unsigned rel_type=base_rel->getRelationshipType(); float x, y, x1, y1, factor=font_config[ParsersAttributes::GLOBAL].font().pointSizeF()/DEFAULT_FONT_SIZE; QPen pen; QPointF pnt; vector<QPointF> points=base_rel->getPoints(); QColor line_color=base_rel->getCustomColor(); QGraphicsPolygonItem *pol_item=nullptr; //Configuring the relationship descriptor color if(base_rel->getCustomColor()!=Qt::transparent) //Using custom color pen.setColor(base_rel->getCustomColor()); else //Using the default color pen=BaseObjectView::getBorderStyle(ParsersAttributes::RELATIONSHIP); if(rel_type==BaseRelationship::RELATIONSHIP_DEP) pen.setStyle(Qt::DashLine); descriptor->setPen(pen); if(line_color!=Qt::transparent) { QColor colors[2]; QLinearGradient grad; BaseObjectView::getFillStyle(ParsersAttributes::RELATIONSHIP, colors[0], colors[1]); for(unsigned i=0; i < 2; i++) { colors[i].setRed((colors[i].red() + line_color.red() + 255)/3); colors[i].setGreen((colors[i].green() + line_color.green() + 255)/3); colors[i].setBlue((colors[i].blue() + line_color.blue() + 255)/3); grad.setColorAt(i, colors[i]); } grad.setCoordinateMode(QGradient::ObjectBoundingMode);; descriptor->setBrush(grad); } else descriptor->setBrush(BaseObjectView::getFillStyle(ParsersAttributes::RELATIONSHIP)); if(rel_type==BaseRelationship::RELATIONSHIP_DEP || rel_type==BaseRelationship::RELATIONSHIP_GEN) { pol.append(QPointF(0,0)); pol.append(QPointF(21,13)); pol.append(QPointF(0,26)); pol.append(QPointF(0,13)); } else { pol.append(QPointF(13,0)); pol.append(QPointF(26,13)); pol.append(QPointF(13,26)); pol.append(QPointF(0,13)); } //Resizes the polygon according the font factor if(factor!=1.0f) this->resizePolygon(pol, pol.boundingRect().width() * factor , pol.boundingRect().height() * factor); if(base_rel->isSelfRelationship()) pnt=points.at(points.size()/2); else { lin=lines.at(lines.size()/2)->line(); if(rel && rel->isIdentifier()) pnt=lin.p1(); else { pnt.setX((lin.p1().x() + lin.p2().x()) / 2.0f); pnt.setY((lin.p1().y() + lin.p2().y()) / 2.0f); } descriptor->setRotation(-lin.angle()); obj_selection->setRotation(-lin.angle()); obj_shadow->setRotation(-lin.angle()); } x=x1=pnt.x() - (pol.boundingRect().width()/2.0f); y=y1=pnt.y() - (pol.boundingRect().height()/2.0f); protected_icon->setPos(x + ((pol.boundingRect().width()/2.0f) * 0.60f), y + ((pol.boundingRect().height()/2.0f) * 0.55f)); configureSQLDisabledInfo(); x1+=6 * HORIZ_SPACING; y1-=3 * VERT_SPACING; sql_disabled_box->setPos(x1, y1); sql_disabled_txt->setPos(x1 + HORIZ_SPACING, y1 + VERT_SPACING); descriptor->setPolygon(pol); descriptor->setTransformOriginPoint(descriptor->boundingRect().center()); descriptor->setPos(x, y); pol_item=dynamic_cast<QGraphicsPolygonItem *>(obj_selection); pol_item->setPolygon(pol); pol_item->setTransformOriginPoint(obj_selection->boundingRect().center()); pol_item->setPos(x,y); pol_item->setBrush(this->getFillStyle(ParsersAttributes::OBJ_SELECTION)); pol_item->setPen(this->getBorderStyle(ParsersAttributes::OBJ_SELECTION)); pol_item=dynamic_cast<QGraphicsPolygonItem *>(obj_shadow); pol_item->setPolygon(pol); pol_item->setTransformOriginPoint(obj_shadow->boundingRect().center()); pol_item->setPos(x + 2.5f, y + 3.5f); pol_item->setPen(Qt::NoPen); pol_item->setBrush(QColor(50,50,50,60)); this->configureAttributes(); this->configurePositionInfo(); }
/** 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 ImagePane::paintEvent(QPaintEvent* /*event*/) { QPainter painter(this); //draw the transformed version of the text-object image painter.drawImage(0, 0, transformedImage); //then we draw the bounding boxes //TODO inscriptions with at least one graph are a different color (?) //in case index numbers are visible, set font QFont font; font.setPixelSize(30/zoom); //TODO make font size dependent on resolution painter.setFont(font); QPen pen; pen.setWidth(0); pen.setColor(Qt::red); painter.setPen(pen); //make a list of bounding boxes according to current mode BoxList currentBoxList; //this is a list of all boxes currentBoxList.clear(); switch(mode) { case SURFACE: currentBoxList.append(*surf); //list of one item, consting of the surface bounding box break; case INSCRIPTION: for(int i=0; i < surf->inscriptionCount(); i++) currentBoxList.insertBox(surf->inscrAt(i), i); break; case GRAPH: for(int i=0; i < surf->ptrInscrAt(currentInscrIndex)->count(); i++) currentBoxList.insertBox(surf->ptrInscrAt(currentInscrIndex)->at(i), i); break; default: break; } //iterate through the list of bounding boxes for (int i=0; i<currentBoxList.size(); i++) { BoundingBox currentBox = currentBoxList.at(i); //the bounding boxes need to be rotated and scaled QTransform boxTransform; //identity matrix //first we need to handle the bounding box's own rotation //by inverting the true matrix that was applied to the image //at the time each bounding box was created //(note: we don't need to worry about scale, as we took account of that //when the bounding box was created) boxTransform.rotate(currentBox.getRotation()); boxTransform = QImage::trueMatrix(boxTransform, currentImage.width(), currentImage.height()); boxTransform = boxTransform.inverted(); //then we compound the above matrix with the current transformation of the image QTransform imageTrueTransform = QImage::trueMatrix(transform, currentImage.width(), currentImage.height()); painter.setWorldTransform(boxTransform * imageTrueTransform); //now draw the box //pen color is red; set the pen-color to green if this is the current box. if(i==currentBoxIndex) { QPen pen; pen.setWidth(0); pen.setColor(Qt::green); painter.setPen(pen); } painter.drawRect(currentBox); //and add an (optional) index number if(indexNumbersVisible) { painter.drawText(currentBox.left(), currentBox.top(), 50/zoom, 50/zoom, Qt::AlignBottom, QString("%1").arg(i+1)); //visible index, so base = 1, not zero } //return pen color to red (might be green) QPen pen; pen.setWidth(0); pen.setColor(Qt::red); painter.setPen(Qt::red); } //if label is not resized, it will stay large on zoom out //resulting in misleading / redundant scroll bars resize(transformedImage.size()); // keep label same size as image }
void CtrlRegisterList::paintEvent(QPaintEvent *) { int numRowsTotal = cpu->GetNumRegsInCategory(category); int maxRowsDisplay =rect().bottom()/rowHeight - 1; selection = std::min(std::max(selection,0),numRowsTotal); curVertOffset = std::max(std::min(curVertOffset,numRowsTotal - maxRowsDisplay),0); QScrollBar *bar = findChild<QScrollBar*>("RegListScroll"); if(bar) { bar->setMinimum(0); bar->setMaximum(numRowsTotal - maxRowsDisplay); bar->setPageStep(1); bar->setValue(curVertOffset); } QPainter painter(this); painter.setBrush(Qt::white); painter.setPen(Qt::white); painter.drawRect(rect()); if (!cpu) return; QFont normalFont = QFont("Arial", 10); painter.setFont(normalFont); int width = rect().width(); QColor bgColor(0xffffff); QPen nullPen(bgColor); QPen currentPen(QColor(0xFF000000)); QPen selPen(0x808080); QPen textPen; QBrush lbr; lbr.setColor(bgColor); QBrush nullBrush(bgColor); QBrush currentBrush(0xFFEfE8); QBrush pcBrush(0x70FF70); int nc = cpu->GetNumCategories(); for (int i=0; i<nc; i++) { painter.setPen(i==category?currentPen:nullPen); painter.setBrush(i==category?pcBrush:nullBrush); painter.drawRect(width*i/nc,0,width*(i+1)/nc - width*i/nc -1,rowHeight-1); QString name = cpu->GetCategoryName(i); painter.setPen(currentPen); painter.drawText(width*i/nc+1,-3+rowHeight,name); } int numRows=rect().bottom()/rowHeight; for (int i=curVertOffset; i<curVertOffset+numRows; i++) { int rowY1 = rowHeight*(i-curVertOffset+1); int rowY2 = rowHeight*(i-curVertOffset+2)-1; lbr.setColor(i==selection?0xffeee0:0xffffff); painter.setBrush(currentBrush); painter.setPen(nullPen); painter.drawRect(0,rowY1,16-1,rowY2-rowY1); if (selecting && i == selection) painter.setPen(selPen); else painter.setPen(nullPen); QBrush mojsBrush(lbr.color()); painter.setBrush(mojsBrush); painter.drawRect(16,rowY1,width-16-1,rowY2-rowY1); // Check for any changes in the registers. if (lastPC != cpu->GetPC()) { for (int i = 0, n = cpu->GetNumRegsInCategory(0); i < n; ++i) { u32 v = cpu->GetRegValue(0, i); changedCat0Regs[i] = v != lastCat0Values[i]; lastCat0Values[i] = v; } lastPC = cpu->GetPC(); } painter.setBrush(currentBrush); if (i<cpu->GetNumRegsInCategory(category)) { QString regName = cpu->GetRegName(category,i); textPen.setColor(0x600000); painter.setPen(textPen); painter.drawText(17,rowY1-3+rowHeight,regName); textPen.setColor(0xFF000000); painter.setPen(textPen); char temp[256]; cpu->PrintRegValue(category,i,temp); if (category == 0 && changedCat0Regs[i]) { textPen.setColor(0x0000FF); painter.setPen(textPen); } else { textPen.setColor(0x004000); painter.setPen(textPen); } painter.drawText(77,rowY1-3+rowHeight,temp); } } }
// Paint event handler. void SeqScreen::paintEvent(QPaintEvent*) { QPainter p(this); QPen pen; pen.setWidth(1); p.setFont(QFont("Helvetica", 8)); p.setPen(pen); int l1, l2; double nsteps = 0.0; int beat = 4; int tmpval = 0; int ypos, xpos, xscale, yscale; w = QWidget::width(); h = QWidget::height(); int ofs; int x, x1; int minOctave = baseOctave; int maxOctave = nOctaves + minOctave; int notestreak_thick = 16 / nOctaves; int beatRes = 1.0; int beatDiv = 0; l2 = 0; //Grid setup if (p_data.isEmpty()) return; nsteps = p_data.at(p_data.count() - 1).tick / TPQN; beatRes = (p_data.count() - 1) / nsteps; beatDiv = (beatRes * nsteps > 64) ? 64 / nsteps : beatRes; int npoints = beatRes * nsteps; xscale = (w - 2 * SEQSCR_HMARG) / nsteps; yscale = h - 2 * SEQSCR_VMARG; //Blue Filled Frame if (isMuted) p.fillRect(0, 0, w, h, QColor(70, 70, 70)); else p.fillRect(0, 0, w, h, QColor(10, 10, 50)); p.setViewport(0, 0, w, h); p.setWindow(0, 0, w, h); p.setPen(QColor(20, 20, 160)); //Draw current record step if (recordMode) p.fillRect(currentRecStep * xscale * nsteps / npoints + SEQSCR_HMARG , SEQSCR_VMARG , xscale * nsteps / npoints , h - 2*SEQSCR_VMARG, QColor(5, 40, 100)); //Beat separators for (l1 = 0; l1 < nsteps + 1; l1++) { if (l1 < 10) { ofs = w / nsteps * .5 - 4 + SEQSCR_HMARG; } else { ofs = w / nsteps * .5 - 6 + SEQSCR_HMARG; } if ((bool)(l1%beat)) { p.setPen(QColor(60, 100, 180)); } else { p.setPen(QColor(100, 100, 180)); } x = l1 * xscale; p.drawLine(SEQSCR_HMARG + x, SEQSCR_VMARG, SEQSCR_HMARG + x, h-SEQSCR_VMARG); if (l1 < nsteps) { p.setPen(QColor(100, 150, 180)); //Beat numbers p.drawText(ofs + x, SEQSCR_VMARG, QString::number(l1+1)); // Beat divisor separators p.setPen(QColor(20, 60, 120)); x1 = x; for (l2 = 1; l2 < beatDiv; l2++) { x1 = x + l2 * xscale / beatDiv; if (x1 < xscale * nsteps) p.drawLine(SEQSCR_HMARG + x1, SEQSCR_VMARG, SEQSCR_HMARG + x1, h - SEQSCR_VMARG); } } } //Horizontal separators and numbers int l3 = 0; for (l1 = 0; l1 <= nOctaves * 12; l1++) { l3 = l1%12; ypos = yscale * l1 / nOctaves / 12 + SEQSCR_VMARG; if (!l3) { p.setPen(QColor(30, 60, 180)); p.drawText(w - SEQSCR_HMARG / 2 - 4, ypos + SEQSCR_VMARG - 5 - yscale / nOctaves / 2, QString::number(maxOctave - l1 / 12)); } else p.setPen(QColor(10, 20, 100)); p.drawLine(0, ypos, w - SEQSCR_HMARG, ypos); if ((l3 == 2) || (l3 == 4) || (l3 == 6) || (l3 == 9) || (l3 == 11)) { pen.setColor(QColor(20, 60, 180)); pen.setWidth(notestreak_thick); p.setPen(pen); p.drawLine(0, ypos - notestreak_thick / 2, SEQSCR_HMARG / 2, ypos- notestreak_thick / 2); pen.setWidth(1); p.setPen(pen); } } //Draw function pen.setWidth(notestreak_thick); p.setPen(pen); for (l1 = 0; l1 < npoints; l1++) { x = (l1 + .01 * (double)grooveTick * (l1 % 2)) * nsteps * xscale / npoints; tmpval = p_data.at(l1).value; if ((tmpval >= 12 * baseOctave) && (tmpval < 12 * maxOctave)) { ypos = yscale - yscale * (p_data.at(l1).value - 12 * baseOctave) / nOctaves / 12 + SEQSCR_VMARG - pen.width() / 2; xpos = SEQSCR_HMARG + x + pen.width() / 2; if (p_data.at(l1).muted) { pen.setColor(QColor(5, 40, 100)); } else { pen.setColor(QColor(50, 130, 180)); } p.setPen(pen); p.drawLine(xpos, ypos, xpos + (xscale / beatRes) - pen.width(), ypos); } } ypos = int((mouseY - SEQSCR_VMARG + 3)/4) * 4 + SEQSCR_VMARG - 2; pen.setWidth(2); pen.setColor(QColor(50, 160, 220)); p.setPen(pen); p.drawLine(SEQSCR_HMARG / 2, ypos, SEQSCR_HMARG *2 / 3, ypos); // Loop Marker if (loopMarker) { QPolygon trg; pen.setWidth(2); pen.setColor(QColor(80, 250, 120)); p.setPen(pen); x = abs(loopMarker) * xscale * (int)nsteps / npoints; xpos = SEQSCR_HMARG + x + pen.width() / 2; ypos = h - SEQSCR_VMARG; tmpval = SEQSCR_VMARG / 2; trg << QPoint(xpos, ypos); if (loopMarker > 0) trg << QPoint(xpos - tmpval, ypos + tmpval); else trg << QPoint(xpos + tmpval, ypos + tmpval); trg << QPoint(xpos, h); p.drawPolygon(trg, Qt::WindingFill); } }
/*! * parameters of polygons may vary depending on whether poly is selected or not or * whether it's label is main or not. */ void ImageHolder::drawPolygons( QPainter *aPainter, QPen *aPen ) const { if (0 == list_polygon_) { return; /* NOTREACHED */ } Qt::PenStyle penStyle = Qt::SolidLine; /* default width is hardcoded */ int width = 2; /* drawing all the polygons */ for (int i = 0; i < list_polygon_->size(); i++) { penStyle = Qt::SolidLine; int labelID = list_polygon_->at(i)->label_ID_; /* setting color for the label of current bbox */ if (labelID < list_label_color_->count()) aPen->setColor(QColor(list_label_color_->at(labelID))); /* in case there is no color for such label */ else aPen->setColor(QColor(Qt::white)); /* checking whether labeled area is of main object or not */ if (labelID == *main_label_) width = 3; else width = 2; /* changing the line style and width if current area is selected(focused) */ if (PolyFigure == focused_selection_type_ && focused_selection_ == i) { penStyle = Qt::DotLine; width = 3; } QPoint point; QPolygon poly = list_polygon_->at(i)->poly; for (int j = 0; j < poly.size(); j++) { point.setX(poly.at(j).x()); point.setY(poly.at(j).y()); /* scaling */ point *= scale_; poly.remove(j); poly.insert(j, point); /* in case if it's focused */ if (focused_selection_ == i && focused_selection_type_ == PolyFigure) { QPen circPen; circPen.setWidth(2); circPen.setStyle(Qt::SolidLine); circPen.setColor(aPen->color()); aPainter->setPen(circPen); /* filling the point if it is hovered */ if ((j == hovered_point_.pointID && i == hovered_point_.figureID && PolyFigure == hovered_point_.figure) || j == selected_point_) { QBrush brush; brush.setColor(aPen->color()); brush.setStyle(Qt::SolidPattern); aPainter->setBrush(brush); } aPainter->drawEllipse(point, point_radius_, point_radius_); aPainter->setBrush(Qt::NoBrush); } } aPen->setWidth(width); aPen->setStyle(penStyle); aPainter->setPen(*aPen); aPainter->drawPolygon(poly); /* drawing label IDs of these polygons */ QString labelIDText = QString("%1").arg(labelID); QRect rect = poly.boundingRect(); int x = rect.center().x(); int y = rect.center().y(); aPainter->drawText( x, y, 20, 20, Qt::AlignHCenter, labelIDText ); } }
void EPGItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget*) { QPen pen; QColor gradientColor; // Draw in view's coordinates painter->setWorldMatrixEnabled( false ); // Draw high-quality items //painter->setRenderHint( QPainter::Antialiasing ); // Get the transformations required to map the text on the viewport QTransform viewPortTransform = m_view->viewportTransform(); QRectF mapped = deviceTransform( viewPortTransform ).mapRect( boundingRect() ); QLinearGradient gradient( mapped.topLeft(), mapped.bottomLeft() ); bool b_simultaneous = playsAt( m_view->baseTime() ); if ( m_current || b_simultaneous ) gradientColor.setRgb( 244, 125, 0 , b_simultaneous ? 192 : 255 ); else gradientColor.setRgb( 201, 217, 242 ); gradient.setColorAt( 0.0, gradientColor.lighter( 120 ) ); gradient.setColorAt( 1.0, gradientColor ); pen.setColor( option->state & QStyle::State_MouseOver || hasFocus() ? QColor( 0, 0, 0 ) : QColor( 192, 192, 192 ) ); pen.setStyle( option->state & QStyle::State_MouseOver && !hasFocus() ? Qt::DashLine : Qt::SolidLine ); painter->setBrush( QBrush( gradient ) ); painter->setPen( pen ); mapped.adjust( 1, 2, -1, -2 ); painter->drawRoundedRect( mapped, 10, 10 ); /* Draw text */ // Setup the font QFont f = painter->font(); // Get the font metrics QFontMetrics fm = painter->fontMetrics(); // Adjust the drawing rect mapped.adjust( 6, 6, -6, -6 ); painter->setPen( Qt::black ); /* Draw the title. */ painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft, fm.elidedText( m_name, Qt::ElideRight, mapped.width() ) ); mapped.adjust( 0, 20, 0, 0 ); QDateTime m_end = m_start.addSecs( m_duration ); f.setPixelSize( 10 ); f.setItalic( true ); painter->setFont( f ); /* Draw the hours. */ painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft, fm.elidedText( start().toString( "hh:mm" ) + " - " + m_end.toString( "hh:mm" ), Qt::ElideRight, mapped.width() ) ); }
void QtArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->setRenderHint(QPainter::Antialiasing); if (this->isSelected()) { const QColor color(255,0,0); QPen pen; pen.setColor(color); pen.setWidth(3); painter->setPen(pen); QBrush brush; brush.setColor(color); brush.setStyle(Qt::SolidPattern); painter->setBrush(brush); } else { const QColor color(0,0,0); QPen pen; pen.setColor(color); pen.setWidth(1); painter->setPen(pen); QBrush brush; brush.setColor(color); brush.setStyle(Qt::SolidPattern); painter->setBrush(brush); } painter->drawLine( m_tail_x,m_tail_y, m_mid_x ,m_mid_y); painter->drawLine( m_mid_x,m_mid_y, m_head_x,m_head_y); const double sz = 10.0; //pixels if (m_tail) { const double dx = m_mid_x - m_tail_x; const double dy = m_mid_y - m_tail_y; double angle = GetAngle(dx,dy); if (dy >= 0.0) angle = (1.0 * boost::math::constants::pi<double>()) + angle; const QPointF p0(m_tail_x,m_tail_y); const QPointF p1 = p0 + QPointF( std::sin(angle + boost::math::constants::pi<double>() + (boost::math::constants::pi<double>() * 0.1)) * sz, -std::cos(angle + boost::math::constants::pi<double>() + (boost::math::constants::pi<double>() * 0.1)) * sz); const QPointF p2 = p0 + QPointF( std::sin(angle + boost::math::constants::pi<double>() - (boost::math::constants::pi<double>() * 0.1)) * sz, -std::cos(angle + boost::math::constants::pi<double>() - (boost::math::constants::pi<double>() * 0.1)) * sz); painter->drawPolygon(QPolygonF() << p0 << p1 << p2); } if (m_head) { const double dx = m_head_x - m_mid_x; const double dy = m_head_y - m_mid_y; double angle = GetAngle(dx,dy); if (dy >= 0.0) angle = (1.0 * boost::math::constants::pi<double>()) + angle; const QPointF p0(m_head_x,m_head_y); const QPointF p1 = p0 + QPointF( std::sin(angle + 0.0 + (boost::math::constants::pi<double>() * 0.1)) * sz, -std::cos(angle + 0.0 + (boost::math::constants::pi<double>() * 0.1)) * sz); const QPointF p2 = p0 + QPointF( std::sin(angle + 0.0 - (boost::math::constants::pi<double>() * 0.1)) * sz, -std::cos(angle + 0.0 - (boost::math::constants::pi<double>() * 0.1)) * sz); painter->drawPolygon(QPolygonF() << p0 << p1 << p2); } }
/** * Paint event method for window display. */ void RollingballApplet::paintEvent(QPaintEvent *) { QPainter painter( this ); painter.setRenderHint( QPainter::Antialiasing ); // // Background // QPointF start(0, height()); QPointF stop(0, 0); //QPointF stop = start - this->height()*QPointF(sin(M_PI/180.0 * (-m_alpha/2.0)), // cos(M_PI/180.0 * (-m_alpha/2.0))); QLinearGradient g(start, stop); g.setColorAt( 0, Qt::black ); g.setColorAt( 1, Qt::white ); painter.setBrush( QBrush(g) ); painter.drawRect( rect() ); // // Draw Lives // painter.save(); for(int i=0; i<mLives; ++i) { painter.drawPixmap(10, 10, 32, 32, mImgBall); painter.drawPixmap(10, 10, 32, 32, mImgShadow); painter.drawPixmap(10, 10, 32, 32, mImgReflexion); painter.translate(40, 0); } painter.restore(); // // Display Game Over // if( mGameOver ) { painter.setPen(Qt::red); painter.setBrush(Qt::red); painter.setFont(QFont("Times", 48, QFont::Bold)); QRect r = this->rect(); r.setHeight(this->height()/2); painter.drawText(r, Qt::AlignCenter, QString("GAME OVER")); } // // Draw plate depending on angle // W = 0.9 * this->width()/2.0; // half width of the main plate const int H = 0.05 * this->height()/2.0; // height of the main plate ballRadius = 2.0 * H; // radius of the ball // Point p0: center of mainPlate const int x0 = this->width()/2; const int y0 = this->height()/2; // // Check for Ball / Coin collision // if( mCoinVisible ) { if(std::abs(mStep - mCoinPos) < 1.5*ballRadius) { this->getCoin(); } } // // Draw main plate // QPen pen; pen.setColor( Qt::black ); pen.setCapStyle( Qt::RoundCap ); pen.setWidth( 2 ); painter.setPen( pen ); painter.setBrush( Qt::green ); painter.translate( x0, y0 ); painter.rotate( -mAlpha ); painter.drawRect( -W, 0, 2*W, 2*H ); // // draw the coin // if(mCoinVisible) { painter.save(); painter.translate( mCoinPos, - ballRadius ); QRect r( -ballRadius/2, -ballRadius/2, ballRadius, ballRadius ); painter.drawPixmap( r, mImgCoin ); painter.restore(); } // // draw the ball // ///painter.save(); painter.translate( mStep, - ballRadius ); QRect r( -ballRadius, -ballRadius, 2*ballRadius, 2*ballRadius ); // draw ball painter.save(); painter.rotate( (180.0 / M_PI) * ( mStep / ballRadius ) ); painter.drawPixmap( r, mImgBall ); painter.restore(); // draw light reflexion and shadow painter.drawPixmap (r, mImgShadow ); painter.drawPixmap( r, mImgReflexion ); //painter.restore(); }