GraphicsPortItem::GraphicsPortItem(GraphicsClientItemsClient *client_, const QString &fullPortName_, int style_, QFont font_, int padding, QGraphicsItem *parent) : QGraphicsPathItem(parent), client(client_), fullPortName(fullPortName_), shortPortName(fullPortName.split(":")[1]), dataType(client->getPortType(fullPortName)), isInput(client->getPortFlags(fullPortName) & JackPortIsInput), style(style_), font(font_), showMenu(false) { bool gradient = false; QColor captionColor(0xfc, 0xf9, 0xc2); setPen(QPen(QBrush(Qt::black), 2)); setBrush(QBrush(captionColor)); setFlags(QGraphicsItem::ItemSendsScenePositionChanges); setCursor(Qt::ArrowCursor); font.setStyleStrategy(QFont::PreferAntialias); QFontMetrics fontMetrics(font); int portPadding = padding; QGraphicsSimpleTextItem *portTextItem = new QGraphicsSimpleTextItem(shortPortName, this); portTextItem->setFont(font); portTextItem->setPos(portPadding, 0); portRect = portTextItem->boundingRect().adjusted(-portPadding, -portPadding, portPadding, portPadding).translated(portTextItem->pos()); QPainterPath portPath; if (style == 0) { portPath = portPath.united(EllipsePath(portRect)); } else if (style == 1) { portPath = portPath.united(SpeechBubblePath(portRect, portRect.height() / 4, portRect.height() / 4, Qt::AbsoluteSize)); } else if (style == 2) { portPath = portPath.united(RoundedRectanglePath(portRect, portPadding + fontMetrics.height() / 2, portPadding + fontMetrics.height() / 2)); } else if (style == 3) { portPath = portPath.united(RectanglePath(portRect)); } setPath(portPath); // register the port registration callback at the jack server: QObject::connect(client, SIGNAL(portRegistered(QString,QString,int)), this, SLOT(onPortRegistered(QString,QString,int)), Qt::QueuedConnection); QObject::connect(client, SIGNAL(portUnregistered(QString,QString,int)), this, SLOT(onPortUnregistered(QString,QString,int)), Qt::QueuedConnection); QObject::connect(client, SIGNAL(portConnected(QString,QString)), this, SLOT(onPortConnected(QString,QString)), Qt::QueuedConnection); QObject::connect(client, SIGNAL(portDisconnected(QString,QString)), this, SLOT(onPortDisconnected(QString,QString)), Qt::QueuedConnection); if (gradient) { QLinearGradient gradient(portRect.topLeft(), portRect.bottomRight()); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, QColor("wheat")); setBrush(QBrush(gradient)); } // create the context menu: connectMenu = contextMenu.addMenu("Connect"); disconnectMenu = contextMenu.addMenu("Disconnect"); // create the entries in connect- and disconnect-menus, as well as graphical representations of existing connections: QStringList connectedPorts = client->getConnectedPorts(fullPortName); QSet<QString> connectedPortsSet; for (int i = 0; i < connectedPorts.size(); i++) { // create an entry in the disconnect-menu: QAction *action = disconnectMenu->addAction(connectedPorts[i]); action->setData(connectedPorts[i]); QObject::connect(action, SIGNAL(triggered()), this, SLOT(onDisconnectAction())); mapPortNamesToActions[connectedPorts[i]] = action; connectedPortsSet.insert(connectedPorts[i]); // create a graphical representation of the connection: if (isInput) { client->getPortConnectionItem(connectedPorts[i], fullPortName)->setPos(fullPortName, getConnectionScenePos()); } else { client->getPortConnectionItem(fullPortName, connectedPorts[i])->setPos(fullPortName, getConnectionScenePos()); } } // get all available ports that can be connected to this: QStringList connectablePorts = client->getPorts(0, dataType.toAscii().data(), isInput ? JackPortIsOutput : JackPortIsInput); for (int i = 0; i < connectablePorts.size(); i++) { // skip ports that are already connected: if (!connectedPortsSet.contains(connectablePorts[i])) { // create an entry in the connect-menu: QAction *action = connectMenu->addAction(connectablePorts[i]); action->setData(connectablePorts[i]); QObject::connect(action, SIGNAL(triggered()), this, SLOT(onConnectAction())); mapPortNamesToActions[connectablePorts[i]] = action; } } disconnectMenu->setEnabled(disconnectMenu->actions().size()); connectMenu->setEnabled(connectMenu->actions().size()); }
QGraphicsSimpleTextItem * TscoreTie::newTie(TscoreNote* parentNote) { auto tie = new QGraphicsSimpleTextItem(QString(QChar(0xe18c)), parentNote); // tie symbol tie->setFont(TnooFont(5)); tie->setBrush(QBrush(parentNote->color())); return tie; }
YigSynthGraphic::YigSynthGraphic(QString synthType, QString mapKey, const QPointF &point, float param1, float param2, int outBus, QGraphicsScene *scene) : mMapKey(mapKey), audioOutBus(outBus), selectingUser(" "), QGraphicsEllipseItem(0, 0, ELLIPSE_SIZE, ELLIPSE_SIZE, 0) { mSynthType = synthType; autoCableCounter = 0; moveBy(point.x(), point.y()); setFlag( QGraphicsItem::ItemIsSelectable, true ); setFlag( QGraphicsItem::ItemIsMovable, true ); setFlag(QGraphicsItem::ItemSendsGeometryChanges); setZValue(10); //setCacheMode(QGraphicsItem::DeviceCoordinateCache); //setAcceptsHoverEvents(true); // MOD FIELD 1 modField1 = new YigModField(this, param1, 0, 0, MOD_FIELD_SIZE, MOD_FIELD_SIZE, this); modField1->moveBy((-MOD_FIELD_SIZE/2) + (ELLIPSE_SIZE/2), (-MOD_FIELD_SIZE/2) + (ELLIPSE_SIZE/2)); modField1->setFlag( QGraphicsItem::ItemIsSelectable, true ); modField1->setFlag( QGraphicsItem::ItemIsMovable, false ); QColor outlineColor = YigColorKit::background2; pen.setColor(QColor(0, 0, 0, 25)); pen.setColor( outlineColor ); modField1->setPen( pen ); //modField1->setCacheMode(QGraphicsItem::DeviceCoordinateCache); /* QRadialGradient gradient(QPointF(MOD_FIELD_SIZE/2, MOD_FIELD_SIZE/2), MOD_FIELD_SIZE/2, QPointF(MOD_FIELD_SIZE/2, MOD_FIELD_SIZE/2)); gradient.setColorAt(0, QColor(0, 0, 0, 0)); gradient.setColorAt(0.3, QColor(0, 0, 0, 100)); gradient.setColorAt(0.75, QColor(0, 0, 0, 170)); gradient.setColorAt(1, QColor(0, 0, 0, 50)); QBrush radialBrush(gradient);*/ //modField1->setBrush( QColor(0, 0, 0, 160) ); modField1->setBrush(Qt::NoBrush); QColor modColor = YigColorKit::background2; modColor.setAlpha(150); //brush.setColor(modColor); //modField1->setBrush(QBrush(modColor)); modField1->setFlag(QGraphicsItem::ItemStacksBehindParent, true); modField1->setZValue(0); //modField1->setCacheMode( QGraphicsItem::DeviceCoordinateCache ); // MOD FIELD 2 modField2 = new YigModField2(this, param2, 0, 0, MOD_FIELD_2_SIZE, MOD_FIELD_2_SIZE, this); modField2->moveBy(((-MOD_FIELD_2_SIZE/2) + (ELLIPSE_SIZE/2)), ((-MOD_FIELD_2_SIZE/2) + (ELLIPSE_SIZE/2))); modField2->setFlag( QGraphicsItem::ItemIsSelectable, true ); modField2->setFlag( QGraphicsItem::ItemIsMovable, false ); //modField2->setPen( pen ); modField2->setPen(Qt::NoPen); /* QRadialGradient gradient2(QPointF(MOD_FIELD_2_SIZE/2, MOD_FIELD_2_SIZE/2), MOD_FIELD_2_SIZE/2, QPointF(MOD_FIELD_2_SIZE/2, MOD_FIELD_2_SIZE/2)); gradient2.setColorAt(0, QColor(255, 255, 255, 0)); gradient2.setColorAt(0.5, QColor(0, 0, 0, 0)); gradient2.setColorAt(0.7, QColor(255, 255, 255, 160)); gradient2.setColorAt(0.8, QColor(255, 255, 255, 160)); gradient2.setColorAt(0.95, QColor(255, 255, 255, 100)); gradient2.setColorAt(1, QColor(0, 0, 0, 100)); QBrush radialBrush2(gradient2); modField2->setBrush( radialBrush2 );*/ modField2->setBrush(Qt::NoBrush); //modColor = YigColorKit::focus1Highlight; //modColor.setAlpha(100); //modField2->setBrush(modColor); //modField2->setCacheMode(QGraphicsItem::DeviceCoordinateCache);; modField2->setFlag(QGraphicsItem::ItemStacksBehindParent); //modField2->setZValue(3); //modField2->setCacheMode( QGraphicsItem::DeviceCoordinateCache ); // AUDIO OUTPUT /* audioOutput = new YigEllipseItem( this, 0, 0, SMALL_ELLIPSE_SIZE, SMALL_ELLIPSE_SIZE, this ); //audioOutput->moveBy((ELLIPSE_SIZE/2) - (SMALL_ELLIPSE_SIZE/2), ELLIPSE_SIZE - SMALL_ELLIPSE_SIZE); audioOutput->moveBy(7.5 + TRI_OFFSET_X, 7.5*SQRT_THREE + TRI_OFFSET_Y); audioOutput->setFlag( QGraphicsItem::ItemIsSelectable, false ); audioOutput->setFlag( QGraphicsItem::ItemIsMovable, false ); audioOutput->setCacheMode(QGraphicsItem::DeviceCoordinateCache);*/ // AUDIO INPUT /* audioInput = new YigEllipseItem( this, 0, 0, SMALL_ELLIPSE_SIZE, SMALL_ELLIPSE_SIZE, this ); //audioInput->moveBy((ELLIPSE_SIZE/2) - (SMALL_ELLIPSE_SIZE/2), 0); audioInput->moveBy(0 + TRI_OFFSET_X, 0 + TRI_OFFSET_Y);*/ audioInput = new QGraphicsEllipseItem(0, 0, AUDIO_ELLIPSE_SIZE, AUDIO_ELLIPSE_SIZE, this); audioInput->moveBy((ELLIPSE_SIZE/2) - (AUDIO_ELLIPSE_SIZE/2), (ELLIPSE_SIZE/2) - (AUDIO_ELLIPSE_SIZE/2)); audioInput->setFlag( QGraphicsItem::ItemIsSelectable, false ); audioInput->setFlag( QGraphicsItem::ItemIsMovable, false ); //audioInput->setCacheMode(QGraphicsItem::DeviceCoordinateCache); audioInput->setZValue(20); // MOD INPUT /* modInput = new YigEllipseItem( this, 0, 0, SMALL_ELLIPSE_SIZE, SMALL_ELLIPSE_SIZE, this ); //modInput->moveBy(0, (ELLIPSE_SIZE/2) - (SMALL_ELLIPSE_SIZE/2)); modInput->moveBy(15 + TRI_OFFSET_X, 0 + TRI_OFFSET_Y);*/ modInput = new QGraphicsEllipseItem(0, 0, MOD_ELLIPSE_SIZE, MOD_ELLIPSE_SIZE, this); modInput->moveBy((ELLIPSE_SIZE/2) - (MOD_ELLIPSE_SIZE/2), (ELLIPSE_SIZE/2) - (MOD_ELLIPSE_SIZE/2)); modInput->setFlag( QGraphicsItem::ItemIsSelectable, false ); modInput->setFlag( QGraphicsItem::ItemIsMovable, false ); //modInput->setCacheMode(QGraphicsItem::DeviceCoordinateCache); modInput->setZValue(20); // Synth Label synthLabel = new QGraphicsSimpleTextItem(this); synthLabel->moveBy( ELLIPSE_SIZE + 5, ELLIPSE_SIZE/2 - 4); synthLabel->setText(synthType); //QFont labelFont("Helvetica [Cronyx]", 11); QFont labelFont("monaco", 10); synthLabel->setFont(labelFont); synthLabel->setFlag( QGraphicsItem::ItemIsSelectable, false ); synthLabel->setFlag( QGraphicsItem::ItemIsMovable, false ); //synthLabel->setPen(YigColorKit::accent); //synthLabel->setCacheMode(QGraphicsItem::DeviceCoordinateCache); synthLabel->setCacheMode(QGraphicsItem::DeviceCoordinateCache); outlineColor = QColor( 0, 0, 0, 255 ); pen.setColor( outlineColor ); audioInput->setPen(Qt::NoPen); //audioOutput->setPen(pen); modInput->setPen(Qt::NoPen); /* QRadialGradient gradient3(QPointF(ELLIPSE_SIZE/2, ELLIPSE_SIZE/2), ELLIPSE_SIZE/2, QPointF(ELLIPSE_SIZE/2, ELLIPSE_SIZE/2)); gradient3.setColorAt(0, QColor(0, 0, 0, 255)); gradient3.setColorAt(0.8, QColor(0, 0, 0, 255)); gradient3.setColorAt(1, QColor(0, 0, 0, 0));*/ //setCacheMode( QGraphicsItem::DeviceCoordinateCache ); /* QRadialGradient gradient4(QPointF(AUDIO_ELLIPSE_SIZE/2, AUDIO_ELLIPSE_SIZE/2), AUDIO_ELLIPSE_SIZE/2, QPointF(AUDIO_ELLIPSE_SIZE/2, AUDIO_ELLIPSE_SIZE/2)); gradient4.setColorAt(0, QColor(0, 0, 0, 255)); gradient4.setColorAt(0.9, QColor(33, 33, 33, 255)); gradient4.setColorAt(1, QColor(0, 0, 0, 255)); audioInput->setBrush( QBrush(gradient4) );*/ audioInput->setBrush(Qt::NoBrush); audioInput->setPen(Qt::NoPen); /* QRadialGradient gradient5(QPointF(MOD_ELLIPSE_SIZE/2, MOD_ELLIPSE_SIZE/2), MOD_ELLIPSE_SIZE/2, QPointF(MOD_ELLIPSE_SIZE/2, MOD_ELLIPSE_SIZE/2)); gradient5.setColorAt(0, YigColorKit::accent); gradient5.setColorAt(0.85, YigColorKit::accent); gradient5.setColorAt(1, QColor(0, 0, 0)); modInput->setBrush( gradient5 ); modInput->setPen(Qt::NoPen);*/ // Arrows audioInArrow = new YigSignalArrow(AUDIO_INPUT, this); //audioOutArrow = new YigSignalArrow(AUDIO_OUTPUT, this); modInArrow = new YigSignalArrow(MOD_INPUT, this); //audioInput->setCacheMode( QGraphicsItem::DeviceCoordinateCache ); //modInput->setCacheMode( QGraphicsItem::DeviceCoordinateCache ); //setCacheMode( QGraphicsItem::DeviceCoordinateCache ); audioInput->setFlag(QGraphicsItem::ItemHasNoContents); modInput->setFlag(QGraphicsItem::ItemHasNoContents); //setFlag(QGraphicsItem::ItemHasNoContents); modField1->setFlag(QGraphicsItem::ItemHasNoContents); modField2->setFlag(QGraphicsItem::ItemHasNoContents); /* audioInput->setZValue(25); QColor penColor = YigColorKit::background2; penColor.setAlpha(200); pen = QPen(penColor); pen.setWidth(2);*/ //setBrush(gradient3); setBrush(Qt::NoBrush); setPen(Qt::NoPen); scene->addItem(this); }
void SkyQPainter::drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle) { float x = pos.x(); float y = pos.y(); float zoom = Options::zoomFactor(); int isize = int(size); float dx1 = -0.5*size; float dx2 = 0.5*size; float dy1 = -1.0*e*size/2.; float dy2 = e*size/2.; float x1 = x + dx1; float x2 = x + dx2; float y1 = y + dy1; float y2 = y + dy2; float dxa = -size/4.; float dxb = size/4.; float dya = -1.0*e*size/4.; float dyb = e*size/4.; float xa = x + dxa; float xb = x + dxb; float ya = y + dya; float yb = y + dyb; QString color; float psize; QBrush tempBrush; std::function<void( float, float, float, float )> lambdaDrawEllipse; std::function<void( float, float, float, float )> lambdaDrawLine; std::function<void( float, float, float, float )> lambdaDrawCross; if ( Options::useAntialias() ) { lambdaDrawEllipse = [this]( float x, float y, float width, float height ) { drawEllipse( QRectF( x, y, width, height ) ); }; lambdaDrawLine = [this]( float x1, float y1, float x2, float y2 ) { drawLine( QLineF( x1, y1, x2, y2 ) ); }; lambdaDrawCross = [this]( float centerX, float centerY, float sizeX, float sizeY ) { drawLine( QLineF( centerX - sizeX/2., centerY, centerX + sizeX/2., centerY ) ); drawLine( QLineF( centerX, centerY - sizeY/2., centerX, centerY + sizeY/2. ) ); }; } else { lambdaDrawEllipse = [this]( float x, float y, float width, float height ) { drawEllipse( QRect( x, y, width, height ) ); }; lambdaDrawLine = [this]( float x1, float y1, float x2, float y2 ) { drawLine( QLine( x1, y1, x2, y2 ) ); }; lambdaDrawCross = [this]( float centerX, float centerY, float sizeX, float sizeY ) { drawLine( QLine( centerX - sizeX/2., centerY, centerX + sizeX/2., centerY ) ); drawLine( QLine( centerX, centerY - sizeY/2., centerX, centerY + sizeY/2. ) ); }; } switch ( type ) { case 0: case 1: //catalog star //Some NGC/IC objects are stars...changed their type to 1 (was double star) if (size<2.) size = 2.; lambdaDrawEllipse( x1, y1, size/2., size/2. ); break; case 2: //Planet break; case 3: //Open cluster; draw circle of points case 13: { // Asterism tempBrush = brush(); color = pen().color().name(); setBrush( pen().color() ); psize = 2.; if ( size > 50. ) psize *= 2.; if ( size > 100. ) psize *= 2.; auto putDot = [this, psize, &lambdaDrawEllipse]( float x, float y ) { lambdaDrawEllipse( x, y, psize, psize ); }; putDot( xa, y1 ); putDot( xb, y1 ); putDot( xa, y2 ); putDot( xb, y2 ); putDot( x1, ya ); putDot( x1, yb ); putDot( x2, ya ); putDot( x2, yb ); setBrush( tempBrush ); break; } case 4: //Globular Cluster if (size<2.) size = 2.; save(); translate( x, y ); color = pen().color().name(); rotate( positionAngle ); //rotate the coordinate system lambdaDrawEllipse( dx1, dy1, size, e*size ); lambdaDrawCross( 0, 0, size, e*size ); restore(); //reset coordinate system break; case 5: //Gaseous Nebula case 15: // Dark Nebula if (size <2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system color = pen().color().name(); lambdaDrawLine( dx1, dy1, dx2, dy1 ); lambdaDrawLine( dx2, dy1, dx2, dy2 ); lambdaDrawLine( dx2, dy2, dx1, dy2 ); lambdaDrawLine( dx1, dy2, dx1, dy1 ); restore(); //reset coordinate system break; case 6: //Planetary Nebula if (size<2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system color = pen().color().name(); lambdaDrawEllipse( dx1, dy1, size, e*size ); lambdaDrawLine( 0., dy1, 0., dy1 - e*size/2. ); lambdaDrawLine( 0., dy2, 0., dy2 + e*size/2. ); lambdaDrawLine( dx1, 0., dx1 - size/2., 0. ); lambdaDrawLine( dx2, 0., dx2 + size/2., 0. ); restore(); //reset coordinate system break; case 7: //Supernova remnant // FIXME: Why is SNR drawn different from a gaseous nebula? if (size<2) size = 2; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system color = pen().color().name(); lambdaDrawLine( 0., dy1, dx2, 0. ); lambdaDrawLine( dx2, 0., 0., dy2 ); lambdaDrawLine( 0., dy2, dx1, 0. ); lambdaDrawLine( dx1, 0., 0., dy1 ); restore(); //reset coordinate system break; case 8: //Galaxy case 16: // Quasar color = pen().color().name(); if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20 if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5 if ( size>2. ) { save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system lambdaDrawEllipse( dx1, dy1, size, e*size ); restore(); //reset coordinate system } else if ( size>0. ) { drawPoint( QPointF(x, y) ); } break; case 14: { // Galaxy cluster - draw a dashed circle tempBrush = brush(); setBrush( QBrush() ); psize = 1.; if ( size > 50. ) psize *= 2.; color = pen().color().name(); save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system QPen newPen = pen(); newPen.setStyle( Qt::DashLine ); setPen( newPen ); lambdaDrawEllipse( dx1, dy1, size, e*size ); restore(); setBrush( tempBrush ); break; } default: // Unknown object or something we don't know how to draw. Just draw an ellipse with a ?-mark color = pen().color().name(); if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20 if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5 if ( size>2. ) { save(); QFont f = font(); const QString qMark = " ? "; double scaleFactor = 0.8 * size / fontMetrics().width( qMark ); f.setPointSizeF( f.pointSizeF() * scaleFactor ); setFont( f ); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system lambdaDrawEllipse( dx1, dy1, size, e*size ); if ( Options::useAntialias() ) drawText( QRectF(dx1, dy1, size, e*size), Qt::AlignCenter, qMark ); else { int idx1 = int(dx1); int idy1 = int(dy1); drawText( QRect(idx1, idy1, isize, int(e*size)), Qt::AlignCenter, qMark ); } restore(); //reset coordinate system (and font?) } else if ( size>0. ) { if ( Options::useAntialias() ) drawPoint( QPointF(x, y) ); else drawPoint( QPoint( x, y ) ); } } }
bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& doc ) { Q_UNUSED( doc ); if ( itemElem.isNull() ) { return false; } //rotation mRotation = itemElem.attribute( "rotation", "0" ).toDouble(); //uuid mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() ); //id QString id = itemElem.attribute( "id", "" ); setId( id ); //frame QString frame = itemElem.attribute( "frame" ); if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 ) { mFrame = true; } else { mFrame = false; } //frame QString background = itemElem.attribute( "background" ); if ( background.compare( "true", Qt::CaseInsensitive ) == 0 ) { mBackground = true; } else { mBackground = false; } //position lock for mouse moves/resizes QString positionLock = itemElem.attribute( "positionLock" ); if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 ) { mItemPositionLocked = true; } else { mItemPositionLocked = false; } //position double x, y, width, height; bool xOk, yOk, widthOk, heightOk, positionModeOK; x = itemElem.attribute( "x" ).toDouble( &xOk ); y = itemElem.attribute( "y" ).toDouble( &yOk ); width = itemElem.attribute( "width" ).toDouble( &widthOk ); height = itemElem.attribute( "height" ).toDouble( &heightOk ); mLastUsedPositionMode = ( ItemPositionMode )itemElem.attribute( "positionMode" ).toInt( &positionModeOK ); if ( !positionModeOK ) { mLastUsedPositionMode = UpperLeft; } if ( !xOk || !yOk || !widthOk || !heightOk ) { return false; } mLastValidViewScaleFactor = itemElem.attribute( "lastValidViewScaleFactor", "-1" ).toDouble(); setSceneRect( QRectF( x, y, width, height ) ); setZValue( itemElem.attribute( "zValue" ).toDouble() ); //pen QDomNodeList frameColorList = itemElem.elementsByTagName( "FrameColor" ); if ( frameColorList.size() > 0 ) { QDomElement frameColorElem = frameColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk, widthOk; int penRed, penGreen, penBlue, penAlpha; double penWidth; penWidth = itemElem.attribute( "outlineWidth" ).toDouble( &widthOk ); penRed = frameColorElem.attribute( "red" ).toDouble( &redOk ); penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk ); penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk ); penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk && widthOk ) { QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) ); framePen.setWidthF( penWidth ); setPen( framePen ); } } //brush QDomNodeList bgColorList = itemElem.elementsByTagName( "BackgroundColor" ); if ( bgColorList.size() > 0 ) { QDomElement bgColorElem = bgColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int bgRed, bgGreen, bgBlue, bgAlpha; bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk ); bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk ); bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk ); bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha ); setBrush( QBrush( brushColor ) ); } } //blend mode setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "blendMode", "0" ).toUInt() ) ); //transparency setTransparency( itemElem.attribute( "transparency" , "0" ).toInt() ); return true; }
void SunMenuItemView::updateBrush(const QBrush &brush) { setBrush(brush); }
/*! Sets the color of the brush in \a gr used for color role \a r to \a c. \sa color() setBrush() QColorGroup::ColorRole */ void QPalette::setColor( QColorGroup::ColorRole r, const QColor &c ) { setBrush( r, QBrush(c) ); }
void QArcItem::SetPattern(int nPATTERN) { nPatternType = nPATTERN; //样式类型 //QRectF nrect(0,0,qWidth,qHeight); QRectF nrect = this->m_qrcEllipseBndRect; QLinearGradient gradient(nrect.topLeft(),nrect.bottomRight()); QRadialGradient Radial(nrect.center(),nrect.width()/2,nrect.center()); gradient.setSpread(QGradient::PadSpread);// RepeatSpread QBrush br=brush(); br.setColor(nFrontColor); //设置前景色即样式颜色 switch(nPATTERN) { // case 0:br.setStyle(Qt::NoBrush);break; // case 1:br.setColor(nBackColor);br.setStyle(Qt::SolidPattern);break; // case 2:br.setStyle(Qt::Dense1Pattern);break; // case 3:br.setStyle(Qt::Dense2Pattern);break; // case 4:br.setStyle(Qt::Dense3Pattern);break; // case 5:br.setStyle(Qt::Dense4Pattern);break; // case 6:br.setStyle(Qt::Dense5Pattern);break; // case 7:br.setStyle(Qt::Dense6Pattern);break; // case 8:br.setStyle(Qt::Dense7Pattern);break; // case 9:br.setStyle(Qt::HorPattern);break;//setBrush(Qt::HorPattern);break; // case 10:br.setStyle(Qt::VerPattern);break; // case 11:br.setStyle(Qt::CrossPattern);break; // case 12:br.setStyle(Qt::BDiagPattern);break; // case 13:br.setStyle(Qt::FDiagPattern);break; // case 14:br.setStyle(Qt::DiagCrossPattern);break; case 0:br.setStyle(Qt::NoBrush);break;//透明 case 1:br.setColor(nBackColor);br.setStyle(Qt::SolidPattern);break;//纯色 case 2: //横向过度 gradient.setStart(nrect.x(),nrect.y()+nrect.height()); gradient.setColorAt(0,nFrontColor ); gradient.setColorAt(1,nBackColor ); break; case 3: //横向对称过度 gradient.setStart(nrect.x(),nrect.y()+nrect.height()); gradient.setColorAt(0,nFrontColor ); gradient.setColorAt(0.5,nBackColor ); gradient.setColorAt(1,nFrontColor ); break; case 4: //纵向过度 gradient.setStart(nrect.x()+nrect.width(),nrect.y()); gradient.setColorAt(0,nFrontColor ); gradient.setColorAt(1,nBackColor); break; case 5: //纵向对称过度 gradient.setStart(nrect.x()+nrect.width(),nrect.y()); gradient.setColorAt(0,nFrontColor ); gradient.setColorAt(0.5,nBackColor); gradient.setColorAt(1,nFrontColor ); break; case 6: //斜上过度 gradient.setColorAt(0,nFrontColor ); gradient.setColorAt(1,nBackColor ); break; case 7: //斜上对称过度 gradient.setColorAt(0,nFrontColor ); gradient.setColorAt(0.5,nBackColor ); gradient.setColorAt(1,nFrontColor ); break; case 8: //斜下过度 gradient.setStart(nrect.x(),nrect.y()+nrect.height()); gradient.setFinalStop(nrect.x()+nrect.width(),nrect.y()); gradient.setColorAt(0,nBackColor ); gradient.setColorAt(1,nFrontColor); break; case 9: //斜下对称过度 gradient.setStart(nrect.x(),nrect.y()+nrect.height()); gradient.setFinalStop(nrect.x()+nrect.width(),nrect.y()); gradient.setColorAt(0,nFrontColor ); gradient.setColorAt(0.5,nBackColor ); gradient.setColorAt(1,nFrontColor ); break; case 10: //右上角辐射 gradient.setStart(nrect.x()+nrect.width(),nrect.y()); gradient.setFinalStop(nrect.x(),nrect.y()+nrect.height()); gradient.setColorAt(0,nBackColor ); gradient.setColorAt(1,nFrontColor ); break; case 11: //左上角辐射 gradient.setColorAt(0,nBackColor ); gradient.setColorAt(1, nFrontColor); break; case 12: //中心辐射 Radial.setColorAt(0,nBackColor ); Radial.setColorAt(1,nFrontColor ); setBrush(Radial); return; break; case 13: //待操作 Radial.setFocalPoint(nrect.x(),nrect.y()+nrect.height()/2); Radial.setColorAt(0,nBackColor ); Radial.setColorAt(1,nFrontColor ); setBrush(Radial); return; break; default: break; } if(nPATTERN >= 2 ) { setBrush(gradient); } else { setBrush(br); } }
void LinkBox::hoverEnterEvent(QGraphicsSceneHoverEvent * event) { setBrush(QBrush(backgrounds[1])); setFocus(Qt::MouseFocusReason); route->slotDisplayStatus("Connection "+QString::number(m1->m->connectionDst[m2->m]->rx)+"%"); }
/*! Sets the brush used for color role \a r to a solid color \a c. \sa brush() setColor() ColorRole */ void QColorGroup::setColor( ColorRole r, const QColor &c ) { setBrush( r, QBrush(c) ); }
void LinkBox::hoverLeaveEvent(QGraphicsSceneHoverEvent * event) { setBrush(QBrush(backgrounds[0])); clearFocus(); route->slotClearStatus(); }
DividerItem::DividerItem( Step *_step, Meta *_meta, int offsetX, int offsetY) { step = _step; AllocEnc allocEnc; Steps *steps = step->grandparent(); Range *range = step->range(); parentRelativeType = steps->relativeType; if (parentRelativeType == CalloutType) { allocEnc = steps->meta.LPub.callout.alloc.value(); } else { allocEnc = steps->meta.LPub.multiStep.alloc.value(); } SepData sepData = range->sepMeta.valuePixels(); /* Size the rectangle around the divider */ if (allocEnc == Vertical) { setRect(offsetX, offsetY, 2*sepData.margin[XX] +sepData.thickness, range->size[YY]); } else { setRect(offsetX, offsetY, range->size[XX], 2*sepData.margin[YY] +sepData.thickness); } setPen(QPen(Qt::NoPen)); setBrush(QBrush(Qt::NoBrush)); setToolTip("Divider - popup menu"); lineItem = new DividerLine(this); BorderData borderData; if (steps->relativeType == CalloutType) { borderData = _meta->LPub.callout.border.valuePixels(); } else { borderData.margin[0] = 0; borderData.margin[1] = 0; borderData.thickness = 0; } if (sepData.thickness > 0.5) { if (allocEnc == Vertical) { int left = offsetX+sepData.margin[XX]+sepData.thickness/2; lineItem->setLine(left, offsetY, left, offsetY +range->size[YY]); } else { int top = offsetY+sepData.margin[YY]+sepData.thickness/2; lineItem->setLine(offsetX, top, offsetX +range->size[XX], top); } QPen pen(LDrawColor::color(sepData.color)); pen.setWidth(sepData.thickness); pen.setCapStyle(Qt::RoundCap); lineItem->setPen(pen); lineItem->setZValue(100); setZValue(99); } }
//FIXME: Do we really need two versions of all of this code? (int/float) void SkyQPainter::drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle) { float x = pos.x(); float y = pos.y(); float zoom = Options::zoomFactor(); int isize = int(size); float dx1 = -0.5*size; float dx2 = 0.5*size; float dy1 = -1.0*e*size/2.; float dy2 = e*size/2.; float x1 = x + dx1; float x2 = x + dx2; float y1 = y + dy1; float y2 = y + dy2; float dxa = -size/4.; float dxb = size/4.; float dya = -1.0*e*size/4.; float dyb = e*size/4.; float xa = x + dxa; float xb = x + dxb; float ya = y + dya; float yb = y + dyb; float psize; QBrush tempBrush; switch ( type ) { case 0: case 1: //catalog star //Some NGC/IC objects are stars...changed their type to 1 (was double star) if (size<2.) size = 2.; if ( Options::useAntialias() ) drawEllipse( QRectF(x1, y1, size/2., size/2.) ); else drawEllipse( QRect(int(x1), int(y1), int(size/2), int(size/2)) ); break; case 2: //Planet break; case 3: //Open cluster; draw circle of points case 13: // Asterism tempBrush = brush(); setBrush( pen().color() ); psize = 2.; if ( size > 50. ) psize *= 2.; if ( size > 100. ) psize *= 2.; if ( Options::useAntialias() ) { drawEllipse( QRectF(xa, y1, psize, psize) ); drawEllipse( QRectF(xb, y1, psize, psize) ); drawEllipse( QRectF(xa, y2, psize, psize) ); drawEllipse( QRectF(xb, y2, psize, psize) ); drawEllipse( QRectF(x1, ya, psize, psize) ); drawEllipse( QRectF(x1, yb, psize, psize) ); drawEllipse( QRectF(x2, ya, psize, psize) ); drawEllipse( QRectF(x2, yb, psize, psize) ); } else { int ix1 = int(x1); int iy1 = int(y1); int ix2 = int(x2); int iy2 = int(y2); int ixa = int(xa); int iya = int(ya); int ixb = int(xb); int iyb = int(yb); drawEllipse( QRect(ixa, iy1, int(psize), int(psize)) ); drawEllipse( QRect(ixb, iy1, int(psize), int(psize)) ); drawEllipse( QRect(ixa, iy2, int(psize), int(psize)) ); drawEllipse( QRect(ixb, iy2, int(psize), int(psize)) ); drawEllipse( QRect(ix1, iya, int(psize), int(psize)) ); drawEllipse( QRect(ix1, iyb, int(psize), int(psize)) ); drawEllipse( QRect(ix2, iya, int(psize), int(psize)) ); drawEllipse( QRect(ix2, iyb, int(psize), int(psize)) ); } setBrush( tempBrush ); break; case 4: //Globular Cluster if (size<2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawEllipse( QRectF(dx1, dy1, size, e*size) ); drawLine( QPointF(0., dy1), QPointF(0., dy2) ); drawLine( QPointF(dx1, 0.), QPointF(dx2, 0.) ); restore(); //reset coordinate system } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawEllipse( QRect(idx1, idy1, isize, int(e*size)) ); drawLine( QPoint(0, idy1), QPoint(0, idy2) ); drawLine( QPoint(idx1, 0), QPoint(idx2, 0) ); restore(); //reset coordinate system } break; case 5: //Gaseous Nebula case 15: // Dark Nebula if (size <2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawLine( QPointF(dx1, dy1), QPointF(dx2, dy1) ); drawLine( QPointF(dx2, dy1), QPointF(dx2, dy2) ); drawLine( QPointF(dx2, dy2), QPointF(dx1, dy2) ); drawLine( QPointF(dx1, dy2), QPointF(dx1, dy1) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawLine( QPoint(idx1, idy1), QPoint(idx2, idy1) ); drawLine( QPoint(idx2, idy1), QPoint(idx2, idy2) ); drawLine( QPoint(idx2, idy2), QPoint(idx1, idy2) ); drawLine( QPoint(idx1, idy2), QPoint(idx1, idy1) ); } restore(); //reset coordinate system break; case 6: //Planetary Nebula if (size<2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawEllipse( QRectF(dx1, dy1, size, e*size) ); drawLine( QPointF(0., dy1), QPointF(0., dy1 - e*size/2. ) ); drawLine( QPointF(0., dy2), QPointF(0., dy2 + e*size/2. ) ); drawLine( QPointF(dx1, 0.), QPointF(dx1 - size/2., 0.) ); drawLine( QPointF(dx2, 0.), QPointF(dx2 + size/2., 0.) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawEllipse( QRect( idx1, idy1, isize, int(e*size) ) ); drawLine( QPoint(0, idy1), QPoint(0, idy1 - int(e*size/2) ) ); drawLine( QPoint(0, idy2), QPoint(0, idy2 + int(e*size/2) ) ); drawLine( QPoint(idx1, 0), QPoint(idx1 - int(size/2), 0) ); drawLine( QPoint(idx2, 0), QPoint(idx2 + int(size/2), 0) ); } restore(); //reset coordinate system break; case 7: //Supernova remnant if (size<2) size = 2; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawLine( QPointF(0., dy1), QPointF(dx2, 0.) ); drawLine( QPointF(dx2, 0.), QPointF(0., dy2) ); drawLine( QPointF(0., dy2), QPointF(dx1, 0.) ); drawLine( QPointF(dx1, 0.), QPointF(0., dy1) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawLine( QPoint(0, idy1), QPoint(idx2, 0) ); drawLine( QPoint(idx2, 0), QPoint(0, idy2) ); drawLine( QPoint(0, idy2), QPoint(idx1, 0) ); drawLine( QPoint(idx1, 0), QPoint(0, idy1) ); } restore(); //reset coordinate system break; case 8: //Galaxy case 16: // Quasar if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20 if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5 if ( size>2. ) { save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawEllipse( QRectF(dx1, dy1, size, e*size) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); drawEllipse( QRect(idx1, idy1, isize, int(e*size)) ); } restore(); //reset coordinate system } else if ( size>0. ) { drawPoint( QPointF(x, y) ); } break; case 14: // Galaxy cluster - draw a circle of + marks tempBrush = brush(); setBrush( pen().color() ); psize = 1.; if ( size > 50. ) psize *= 2.; if ( Options::useAntialias() ) { drawLine( QLineF( xa - psize, y1, xa + psize, y1 ) ); drawLine( QLineF( xa, y1 - psize, xa, y1 + psize ) ); drawLine( QLineF( xb - psize, y1, xb + psize, y1 ) ); drawLine( QLineF( xb, y1 - psize, xb, y1 + psize ) ); drawLine( QLineF( xa - psize, y2, xa + psize, y2 ) ); drawLine( QLineF( xa, y2 - psize, xa, y2 + psize ) ); drawLine( QLineF( xb - psize, y2, xb + psize, y2 ) ); drawLine( QLineF( xb, y2 - psize, xb, y2 + psize ) ); drawLine( QLineF( x1 - psize, ya, x1 + psize, ya ) ); drawLine( QLineF( x1, ya - psize, x1, ya + psize ) ); drawLine( QLineF( x1 - psize, yb, x1 + psize, yb ) ); drawLine( QLineF( x1, yb - psize, x1, yb + psize ) ); drawLine( QLineF( x2 - psize, ya, x2 + psize, ya ) ); drawLine( QLineF( x2, ya - psize, x2, ya + psize ) ); drawLine( QLineF( x2 - psize, yb, x2 + psize, yb ) ); drawLine( QLineF( x2, yb - psize, x2, yb + psize ) ); } else { int ix1 = int(x1); int iy1 = int(y1); int ix2 = int(x2); int iy2 = int(y2); int ixa = int(xa); int iya = int(ya); int ixb = int(xb); int iyb = int(yb); drawLine( QLineF( ixa - int(psize), iy1, ixa + int(psize), iy1 ) ); drawLine( QLineF( ixa, iy1 - int(psize), ixa, iy1 + int(psize) ) ); drawLine( QLineF( ixb - int(psize), iy1, ixb + int(psize), iy1 ) ); drawLine( QLineF( ixb, iy1 - int(psize), ixb, iy1 + int(psize) ) ); drawLine( QLineF( ixa - int(psize), iy2, ixa + int(psize), iy2 ) ); drawLine( QLineF( ixa, iy2 - int(psize), ixa, iy2 + int(psize) ) ); drawLine( QLineF( ixb - int(psize), iy2, ixb + int(psize), iy2 ) ); drawLine( QLineF( ixb, iy2 - int(psize), ixb, iy2 + int(psize) ) ); drawLine( QLineF( ix1 - int(psize), iya, ix1 + int(psize), iya ) ); drawLine( QLineF( ix1, iya - int(psize), ix1, iya + int(psize) ) ); drawLine( QLineF( ix1 - int(psize), iyb, ix1 + int(psize), iyb ) ); drawLine( QLineF( ix1, iyb - int(psize), ix1, iyb + int(psize) ) ); drawLine( QLineF( ix2 - int(psize), iya, ix2 + int(psize), iya ) ); drawLine( QLineF( ix2, iya - int(psize), ix2, iya + int(psize) ) ); drawLine( QLineF( ix2 - int(psize), iyb, ix2 + int(psize), iyb ) ); drawLine( QLineF( ix2, iyb - int(psize), ix2, iyb + int(psize) ) ); } setBrush( tempBrush ); break; } }
void PlotCurve::restoreCurveLayout(const QStringList& lst) { QStringList::const_iterator line = lst.begin(); for (line++; line != lst.end(); line++){ QString s = *line; if (s == "<Pen>"){ QPen pen; while(s != "</Pen>"){ s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } setPen(pen); } else if (s == "<Brush>"){ QBrush brush; while(s != "</Brush>"){ s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle(s.remove("<Style>").remove("</Style>").toInt())); } setBrush(brush); } else if (s == "<Symbol>"){ QwtSymbol symbol; while(s != "</Symbol>"){ s = (*(++line)).stripWhiteSpace(); if (s.contains("<Style>")) symbol.setStyle(SymbolBox::style(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Size>")) symbol.setSize((QwtSymbol::Style)s.remove("<Size>").remove("</Size>").toInt()); else if (s == "<SymbolPen>"){ QPen pen; while(s != "</SymbolPen>"){ s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } symbol.setPen(pen); } else if (s == "<SymbolBrush>"){ QBrush brush; while(s != "</SymbolBrush>"){ s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle(s.remove("<Style>").remove("</Style>").toInt())); } symbol.setBrush(brush); } setSymbol(symbol); } } else if (s.contains("<xAxis>")) setXAxis(s.remove("<xAxis>").remove("</xAxis>").toInt()); else if (s.contains("<yAxis>")) setYAxis(s.remove("<yAxis>").remove("</yAxis>").toInt()); else if (s.contains("<Visible>")) setVisible(s.remove("<Visible>").remove("</Visible>").toInt()); } }
void GraphicsClientItem::initItem() { // delete all children (except the inner item): QList<QGraphicsItem*> children = childItems(); for (int i = 0; i < children.size(); i++) { if (children[i] != controlsItem) { if (GraphicsPortItem *portItem = dynamic_cast<GraphicsPortItem*>(children[i])) { portItem->deleteLater(); } else { delete children[i]; } } } bool gradient = false; QFont commandsFont = font; commandsFont.setBold(true); commandsFont.setStyleStrategy(QFont::PreferAntialias); QFontMetrics fontMetrics(font); int portPadding = fontMetrics.height() / 3; int padding = fontMetrics.height() + portPadding * 2; QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(clientName, this); textItem->setFont(font); textItem->setPos(padding, padding); QStringList inputPorts = clientItemsClient->getPorts(QString(QRegExp::escape(clientName) + ":.*").toAscii().data(), 0, JackPortIsInput); QList<GraphicsPortItem*> inputPortItems; int inputPortsWidth = -portPadding; int minimumInputPortWidth = 0; for (int i = 0; i < inputPorts.size(); i++) { inputPortItems.append(new GraphicsPortItem(clientItemsClient, inputPorts[i], 3, font, portPadding, this)); if (isMacroItem()) { QPen pen = inputPortItems.back()->pen(); pen.setColor(QColor("steelblue")); inputPortItems.back()->setPen(pen); } inputPortsWidth += inputPortItems[i]->getRect().width() + portPadding; if ((i == 0) || (inputPortItems[i]->getRect().width() < minimumInputPortWidth)) { minimumInputPortWidth = inputPortItems[i]->getRect().width(); } } QStringList outputPorts = clientItemsClient->getPorts(QString(QRegExp::escape(clientName) + ":.*").toAscii().data(), 0, JackPortIsOutput); QList<GraphicsPortItem*> outputPortItems; int outputPortsWidth = -portPadding; int minimumOutputPortWidth = 0; for (int i = 0; i < outputPorts.size(); i++) { outputPortItems.append(new GraphicsPortItem(clientItemsClient, outputPorts[i], 3, font, portPadding, this)); if (isMacroItem()) { QPen pen = outputPortItems.back()->pen(); pen.setColor(QColor("steelblue")); outputPortItems.back()->setPen(pen); } outputPortsWidth += outputPortItems[i]->getRect().width() + portPadding; if ((i == 0) || (outputPortItems[i]->getRect().width() < minimumOutputPortWidth)) { minimumOutputPortWidth = outputPortItems[i]->getRect().width(); } } rect = (textItem->boundingRect().translated(textItem->pos())).adjusted(-padding, -padding, padding, padding); // if (rect.width() < inputPortsWidth + (portPadding - minimumInputPortWidth) * 2) { // rect.setWidth(inputPortsWidth + (portPadding - minimumInputPortWidth) * 2); // } // if (rect.width() < outputPortsWidth + (portPadding - minimumOutputPortWidth) * 2) { // rect.setWidth(outputPortsWidth + (portPadding - minimumOutputPortWidth) * 2); // } if (rect.width() < inputPortsWidth) { rect.setWidth(inputPortsWidth); } if (rect.width() < outputPortsWidth) { rect.setWidth(outputPortsWidth); } if (gradient) { QLinearGradient gradient(rect.topLeft(), rect.bottomRight()); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, QColor(0xfc, 0xf9, 0xc2));//QColor("royalblue").lighter()); setBrush(QBrush(gradient)); } QPainterPath bodyPath; if (clientStyle == 0) { bodyPath = EllipsePath(rect); } else if (clientStyle == 1) { bodyPath = SpeechBubblePath(rect, rect.height() / 4, rect.height() / 4, Qt::AbsoluteSize); } else if (clientStyle == 2){ bodyPath = RoundedRectanglePath(rect, padding + fontMetrics.height(), padding + fontMetrics.height()); } else if (clientStyle == 3) { bodyPath = RectanglePath(rect); } for (int i = 0, x = (inputPortsWidth > rect.width() ? (rect.width() - inputPortsWidth) / 2 : 0); i < inputPorts.size(); i++) { GraphicsPortItem *portItem = inputPortItems[i]; portItem->setFlag(QGraphicsItem::ItemStacksBehindParent, true); portItem->setPos(x, 0); QRectF portRect(portItem->getRect().translated(portItem->pos())); QPainterPath portPath; portPath.addRect(QRectF(portRect.topLeft(), 0.5 * (portRect.topRight() + portRect.bottomRight()))); int portStyle = (portItem->isAudioType() ? audioPortStyle : midiPortStyle); if (portStyle == 0) { portPath += EllipsePath(portRect); } else if (portStyle == 1) { portPath += SpeechBubblePath(portRect, 0.7, 0.7); } else if (portStyle == 2) { portPath += RoundedRectanglePath(portRect, portPadding + fontMetrics.height() / 2, portPadding + fontMetrics.height() / 2); } else if (portStyle == 3) { portPath += RectanglePath(portRect); } bodyPath -= portPath; x += portRect.width() + portPadding; } for (int i = 0, x = (outputPortsWidth > rect.width() ? (rect.width() - outputPortsWidth) / 2 : 0); i < outputPorts.size(); i++) { GraphicsPortItem *portItem = outputPortItems[i]; portItem->setFlag(QGraphicsItem::ItemStacksBehindParent, true); portItem->setPos(x, rect.height() - fontMetrics.height()); QRectF portRect(portItem->getRect().translated(portItem->pos())); QPainterPath portPath; portPath.addRect(QRectF(0.5 * (portRect.topLeft() + portRect.bottomLeft()), portRect.bottomRight())); int portStyle = (portItem->isAudioType() ? audioPortStyle : midiPortStyle); if (portStyle == 0) { portPath += EllipsePath(portRect); } else if (portStyle == 1) { portPath += SpeechBubblePath(portRect, 0.7, 0.7); } else if (portStyle == 2) { portPath += RoundedRectanglePath(portRect, portPadding + fontMetrics.height() / 2, portPadding + fontMetrics.height() / 2); } else if (portStyle == 3) { portPath += RectanglePath(portRect); } bodyPath -= portPath; x += portRect.width() + portPadding; } QPainterPath combinedPath = bodyPath; setPath(combinedPath); }
centreTerrain::centreTerrain(): QGraphicsRectItem() { setRect(0,200,300,100); setBrush(QBrush(Qt::red)); }
HEESGraphicsItem::HEESGraphicsItem(int t) { leftArrow = NULL; rightArrow = NULL; portAItem = NULL; portBItem = NULL; qreal xPos = 0; qreal yPos = 0; type = ItemType(t); type = ItemType(t); QPainterPath path; QPolygonF myPolygon; switch (type) { case SOURCE: path.moveTo(xPos, yPos); path.arcTo(xPos - 50, yPos - 25, 50, 50, 0, 360); myPolygon = path.toFillPolygon(); break; case BANK: path.moveTo(xPos, yPos); path.arcTo(xPos - 39, yPos - 10, 40, 20, 0, 360); path.lineTo(xPos, yPos + 40); path.arcTo(xPos - 39, yPos + 40, 40, 20, 0, -180); path.lineTo(xPos - 39, yPos); path.arcTo(xPos - 39, yPos - 10, 40, 20, 180, 180); myPolygon = path.toFillPolygon(); break; case LOAD: path.moveTo(xPos, yPos); path.lineTo(xPos, yPos + 50); path.lineTo(xPos - 36, yPos + 50); path.lineTo(xPos - 36, yPos); myPolygon = path.toFillPolygon(); break; case CTI: path.moveTo(xPos, yPos); path.lineTo(xPos + 20, yPos + 20); path.lineTo(xPos + 10, yPos + 20); path.lineTo(xPos + 10, yPos + 120); path.lineTo(xPos + 20, yPos + 120); path.lineTo(xPos, yPos + 140); path.lineTo(xPos - 20, yPos + 120); path.lineTo(xPos - 10, yPos + 120); path.lineTo(xPos - 10, yPos + 20); path.lineTo(xPos - 20, yPos + 20); myPolygon = path.toFillPolygon(); break; case CONVERTER: leftArrow = new ArrowItem(true, this); rightArrow = new ArrowItem(false, this); path.moveTo(xPos, yPos); path.lineTo(xPos + 5, yPos + 5); path.lineTo(xPos + 5, yPos + 25); path.lineTo(xPos, yPos + 30); path.lineTo(xPos - 30, yPos + 30); path.lineTo(xPos - 35, yPos + 25); path.lineTo(xPos - 35, yPos + 5); path.lineTo(xPos - 30, yPos); myPolygon = path.toFillPolygon(); break; } QBrush brush(QColor(255,255,255)); setBrush(brush); setPolygon(myPolygon); setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setPos(qrand() % 200 - 100, qrand() % 200 - 100); // Make other components stay on top of the converter and arrows if( type != CONVERTER) setZValue(1); willBeRemoved = false; }
void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { if (!shouldCalculateStuff(topLeft, bottomRight)) return; AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight); if (polygon().isEmpty()) return; show_reported_ceiling = prefs.dcceiling; reported_ceiling_in_red = prefs.redceiling; profileColor = getColor(DEPTH_BOTTOM); int currState = qobject_cast<ProfileWidget2 *>(scene()->views().first())->currentState; if (currState == ProfileWidget2::PLAN) { plot_data *entry = dataModel->data().entry + dataModel->rowCount() - 1; for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) { int max = maxCeiling(i); if (entry->depth < max) { profileColor = QColor(Qt::red); } } } /* Show any ceiling we may have encountered */ if (prefs.dcceiling && !prefs.redceiling) { QPolygonF p = polygon(); plot_data *entry = dataModel->data().entry + dataModel->rowCount() - 1; for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) { if (!entry->in_deco) { /* not in deco implies this is a safety stop, no ceiling */ p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0))); } else { p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(qMin(entry->stopdepth, entry->depth)))); } } setPolygon(p); } // This is the blueish gradient that the Depth Profile should have. // It's a simple QLinearGradient with 2 stops, starting from top to bottom. QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom()); pat.setColorAt(1, profileColor); pat.setColorAt(0, getColor(DEPTH_TOP)); setBrush(QBrush(pat)); int last = -1; for (int i = 0, count = dataModel->rowCount(); i < count; i++) { struct plot_data *entry = dataModel->data().entry + i; if (entry->depth < 2000) continue; if ((entry == entry->max[2]) && entry->depth / 100 != last) { plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignBottom, getColor(SAMPLE_DEEP)); last = entry->depth / 100; } if ((entry == entry->min[2]) && entry->depth / 100 != last) { plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignTop, getColor(SAMPLE_SHALLOW)); last = entry->depth / 100; } if (entry->depth != last) last = -1; } }
BoxItem::BoxItem(View *parent) : ViewItem(parent) { setName("Box"); setZValue(BOX_ZVALUE); setBrush(Qt::white); }
/*! * Initializes the path (only once). */ void BridgeItem::createPath() { if (path_) { delete path_; } path_ = new QPainterPath(); setBrush(QBrush(outerColor_)); setPen(QPen(outerColor_, 2.0)); if (bridge_->getLength() > NUMERICAL_ZERO3) // Bridge is repeated { double totalLength = 0.0; double currentS = bridge_->getSStart(); // Left and right side // // while ((totalLength < bridge_->getLength()) && (currentS < road_->getLength())) { LaneSection *laneSection = road_->getLaneSection(currentS); double t = laneSection->getLaneSpanWidth(0, laneSection->getRightmostLaneId() - 1, currentS); QPointF currentPos = road_->getGlobalPoint(currentS, t); if (totalLength == 0) { path_->moveTo(currentPos.x(), currentPos.y()); } else { path_->lineTo(currentPos.x(), currentPos.y()); path_->moveTo(currentPos.x(), currentPos.y()); } // double dist = 4; // TODO get configured tesselation length Jutta knows where to get this from double dist = 1 / getProjectGraph()->getProjectWidget()->getLODSettings()->TopViewEditorPointsPerMeter; if ((totalLength + dist) > bridge_->getLength()) { QPointF currentPos = road_->getGlobalPoint(currentS + (bridge_->getLength() - totalLength), t); path_->lineTo(currentPos.x(), currentPos.y()); } totalLength += dist; currentS += dist; } totalLength = 0.0; currentS = bridge_->getSStart(); // Left and right side // // while ((totalLength < bridge_->getLength()) && (currentS < road_->getLength())) { LaneSection *laneSection = road_->getLaneSection(currentS); double t = -laneSection->getLaneSpanWidth(laneSection->getLeftmostLaneId(), 0, currentS); QPointF currentPos = road_->getGlobalPoint(currentS, t); if (totalLength == 0) { path_->moveTo(currentPos.x(), currentPos.y()); } else { path_->lineTo(currentPos.x(), currentPos.y()); path_->moveTo(currentPos.x(), currentPos.y()); } // double dist = 4; // TODO get configured tesselation length Jutta knows where to get this from double dist = 1 / getProjectGraph()->getProjectWidget()->getLODSettings()->TopViewEditorPointsPerMeter; if ((totalLength + dist) > bridge_->getLength()) { QPointF currentPos = road_->getGlobalPoint(currentS + (bridge_->getLength() - totalLength), t); path_->lineTo(currentPos.x(), currentPos.y()); } totalLength += dist; currentS += dist; } } setPath(*path_); }
void toolBarSwitch(WPARAM wParam, HWND hwnd){ switch(wParam){ case IDM_CURSOR: unselectAllTools(); break; case IDM_PEN: unselectAllTools(); freeformLine->setStatus(true); break; case IDM_BRUSH: feelColor = !feelColor; if(!feelColor) resetBrush(); else setBrush(); break; case IDM_LINE: unselectAllTools(); straightLine->setStatus(true); break; case IDM_VERT_LINE: unselectAllTools(); straightLine->setStatus(true); straightLine->setVertical(true); break; case IDM_HORIZ_LINE: unselectAllTools(); straightLine->setStatus(true); straightLine->setHorizontal(true); break; case IDM_ELLIPSE: unselectAllTools(); elipse->setStatus(true); break; case IDM_TETTRA: unselectAllTools(); tetragon->setStatus(true); break; case IDM_CONECTED_LINE: unselectAllTools(); straightLine->setStatus(true); straightLine->setConected(true); break; case IDM_BEZIER: unselectAllTools(); bezier->setStatus(true); break; case IDM_GRADIENT: OnEraseBkGnd(hwnd); break; case IDM_ERASER_1: unselectAllTools(); eraser->setThickenss(8); eraser->setStatus(true); break; case IDM_ERASER_2: unselectAllTools(); eraser->setThickenss(16); eraser->setStatus(true); break; case IDM_ERASER_3: unselectAllTools(); eraser->setThickenss(32); eraser->setStatus(true); break; case IDM_ERASER_4: unselectAllTools(); eraser2->setStatus(true); break; } }
void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { bool eventAdded = false; if (!shouldCalculateStuff(topLeft, bottomRight)) return; AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight); if (polygon().isEmpty()) return; show_reported_ceiling = prefs.dcceiling; reported_ceiling_in_red = prefs.redceiling; profileColor = getColor(DEPTH_BOTTOM); #ifdef SUBSURFACE_MOBILE Q_UNUSED(eventAdded); #else int currState = qobject_cast<ProfileWidget2 *>(scene()->views().first())->currentState; if (currState == ProfileWidget2::PLAN) { plot_data *entry = dataModel->data().entry; for (int i = 0; i < dataModel->rowCount(); i++, entry++) { int max = maxCeiling(i); // Don't scream if we violate the ceiling by a few cm if (entry->depth < max - 100 && entry->sec > 0) { profileColor = QColor(Qt::red); if (!eventAdded) { add_event(&displayed_dive.dc, entry->sec, SAMPLE_EVENT_CEILING, -1, max / 1000, QT_TRANSLATE_NOOP("gettextFromC", "planned waypoint above ceiling")); eventAdded = true; } } } } #endif /* Show any ceiling we may have encountered */ if (prefs.dcceiling && !prefs.redceiling) { QPolygonF p = polygon(); plot_data *entry = dataModel->data().entry + dataModel->rowCount() - 1; for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) { if (!entry->in_deco) { /* not in deco implies this is a safety stop, no ceiling */ p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0))); } else { p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(qMin(entry->stopdepth, entry->depth)))); } } setPolygon(p); } // This is the blueish gradient that the Depth Profile should have. // It's a simple QLinearGradient with 2 stops, starting from top to bottom. QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom()); pat.setColorAt(1, profileColor); pat.setColorAt(0, getColor(DEPTH_TOP)); setBrush(QBrush(pat)); int last = -1; for (int i = 0, count = dataModel->rowCount(); i < count; i++) { struct plot_data *pd = dataModel->data().entry; struct plot_data *entry = pd + i; // "min/max" are the 9-minute window min/max indices struct plot_data *min_entry = pd + entry->min; struct plot_data *max_entry = pd + entry->max; if (entry->depth < 2000) continue; if ((entry == max_entry) && entry->depth / 100 != last) { plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignBottom, getColor(SAMPLE_DEEP)); last = entry->depth / 100; } if ((entry == min_entry) && entry->depth / 100 != last) { plot_depth_sample(entry, Qt::AlignHCenter | Qt::AlignTop, getColor(SAMPLE_SHALLOW)); last = entry->depth / 100; } if (entry->depth != last) last = -1; } }
void Histogram::setColor(const QColor &color) { setPen(QPen(color)); setBrush(QBrush(color)); }
void Letter::setHighlight(bool highlight) { if (m_movable) { setBrush(highlight ? QColor("#0057ae") : QColor("#bbbbbb")); } }
BoardScene::BoardScene(const SLFormat::Board* inBoard, QWidget* inParent) :QGraphicsScene(inParent), mBoard(inBoard) { this->setSceneRect(0, 0, mBoard->size().x, mBoard->size().y); // background const unsigned activeLayer = mBoard->activeLayer(); QBrush brush(gSettings().backgroundColor()); QPen pen(brush.color()); mBackground = this->addRect(this->sceneRect(), pen, brush); // ground planes (initially invisible) for (unsigned i = 0; i < SLFormat::Board::cNumberLayers; i++) { unsigned layer = gSettings().layerFromOrderNumber(i); if (mBoard->isGroundPlaneSupported(layer)) { QGraphicsItemGroup* plane = new QGraphicsItemGroup; mGroundPlanes[layer] = plane; addItem(plane); plane->setVisible(false); auto rect = new QGraphicsRectItem(this->sceneRect()); const QColor color = gSettings().groundPlaneLayerColor(layer); rect->setBrush(QBrush(color)); rect->setPen(QPen(color)); plane->addToGroup(rect); } else { mGroundPlanes[layer] = nullptr; } } // grid mGrid = new BoardGrid(mBoard); addItem(mGrid); // layers for (unsigned i = 0; i < SLFormat::Board::cNumberLayers; i++) { unsigned layer = gSettings().layerFromOrderNumber(i); mLayerGroups[layer] = new QGraphicsItemGroup; addItem(mLayerGroups[layer]); } mDrillHoles = new QGraphicsItemGroup; addItem(mDrillHoles); // components on layers for (auto comp : mBoard->components()) { ComponentItem* item = ComponentFactory::createItem(comp); if (item) { unsigned layer = comp->layer(); mLayerGroups[layer]->addToGroup(item->mainItem()); if (mBoard->isGroundPlaneSupported(layer)) { mGroundPlanes[layer]->addToGroup(item->groundPlaneItem()); } mDrillHoles->addToGroup(item->drillItem()); } } // show ground plane for active layer if (mBoard->isGroundPlaneEnabled(activeLayer)) { assert(mGroundPlanes[activeLayer]); mGroundPlanes[activeLayer]->setVisible(true); } }