void SunMenuItemView::recalculateChildMenusAngles() { Q_ASSERT(mItemModel != 0); qint32 leafCount = mItemModel->leafCount(); if (leafCount == 0) return; qreal sweepLengthForLeafs = sweepLength() / leafCount; qreal childStartAngle = startAngle(); foreach(SunMenuItemView* m, childMenus()) { m->setStartAngle(childStartAngle); if (m->mItemModel->leafCount() == 0) { m->setSweepLength(sweepLengthForLeafs); childStartAngle += sweepLengthForLeafs; } else { qreal tmp = m->mItemModel->leafCount() * sweepLengthForLeafs; m->setSweepLength(tmp); childStartAngle += tmp; } }
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { painter->setPen(pen()); painter->setBrush(brush()); painter->drawArc(rect(), startAngle(), spanAngle()); // fix me, need to adjust the rect size so that it's only as big as the arc // if (option->state & QStyle::State_Selected) // qt_graphicsItem_highlightSelected(this, painter, option); }
int QtSvgDialGauge::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 1) qt_static_metacall(this, _c, _id, _a); _id -= 1; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { if (_id < 1) *reinterpret_cast<int*>(_a[0]) = -1; _id -= 1; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = skin(); break; case 1: *reinterpret_cast< int*>(_v) = minimum(); break; case 2: *reinterpret_cast< int*>(_v) = maximum(); break; case 3: *reinterpret_cast< qreal*>(_v) = startAngle(); break; case 4: *reinterpret_cast< qreal*>(_v) = endAngle(); break; } _id -= 5; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setSkin(*reinterpret_cast< QString*>(_v)); break; case 1: setMinimum(*reinterpret_cast< int*>(_v)); break; case 2: setMaximum(*reinterpret_cast< int*>(_v)); break; case 3: setStartAngle(*reinterpret_cast< qreal*>(_v)); break; case 4: setEndAngle(*reinterpret_cast< qreal*>(_v)); break; } _id -= 5; } else if (_c == QMetaObject::ResetProperty) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 5; } else if (_c == QMetaObject::RegisterPropertyMetaType) { if (_id < 5) *reinterpret_cast<int*>(_a[0]) = -1; _id -= 5; } #endif // QT_NO_PROPERTIES return _id; }
float Arc2D::angularDistanceToStartPoint(const Point2D& i_point) const { traceType angle((i_point-m_centrePoint).getAlpha()); traceType startAngle((m_firstPoint-m_centrePoint).getAlpha()); traceType distance; if (m_isClockwise) { distance = startAngle -angle; } else { distance = angle - startAngle; } if (distance < 0) { distance+= 2 * PI; } return distance; }
void SunMenuItemView::updateShape() { QPainterPath newPath; qreal tmp = qAbs(sweepLength()); if (width() != 0 && tmp > 0.001) { qint32 innerRad = innerRadius(); qint32 outerRadius = innerRad + width(); QRectF r = QRect(-outerRadius, -outerRadius, outerRadius * 2, outerRadius * 2); if (innerRad == 0 && qAbs(sweepLength() - 360) < 0.0001) { newPath.addEllipse(r); } else { newPath.arcMoveTo(r, startAngle()); newPath.arcTo(r, startAngle(), sweepLength()); if(innerRad == 0) { newPath.lineTo(0,0); }else { r = QRect(-innerRad, -innerRad, innerRad * 2, innerRad * 2); newPath.arcTo(r, startAngle() + sweepLength(), -sweepLength()); } newPath.closeSubpath(); } } // setPath(newPath); reinitializeDisplayedItemPosition(); }
//- Container manipulators are composed of one or more base manipulators. //- When base manipulators are added to a container manipulator, they are referred to //- as children of the container manipulator, and are added using the createChildren method. MStatus arrowLocatorManip::createChildren() { MStatus status = MStatus::kSuccess; //- Add a base disc manip into this manip container MString manipName("angleManip"); MString angleName("yRotation"); fDiscManip = addDiscManip(manipName,angleName); //- Initialize the angle and starting position of this manipulator MPoint startPoint(0.0, 0.0, 0.0); MAngle startAngle(0.0,MAngle::kDegrees); MFnDiscManip fnDisc(fDiscManip,&status); fnDisc.setCenterPoint(startPoint); fnDisc.setAngle(startAngle); return status; }
void LCVArc::draw(LcPainter* painter, LcDrawOptions* options, const lc::geo::Area& rect) const { bool modified = false; if (this->selected()) { modified = true; painter->save(); painter->source_rgba( options->selectedColor().redF(), options->selectedColor().greenF(), options->selectedColor().blueF(), options->selectedColor().alphaF() ); } if (radius() /** painter->scale() > 5 */) { painter->arc(center().x(), center().y(), radius(), startAngle(), endAngle()); painter->stroke(); } if (modified) { painter->restore(); } }
int QElipseItem::GetStartAngle() //获得开始度角度值 { int nstartAngle=startAngle(); return nstartAngle/16; }
void Plant::draw( Vector3D *inPosition, double inScale, double inMaxZ, double inMinZ ) { if( mPoisoned && mPoisonStatus >= 1) { // draw nothing return; } double drawScale = inScale; if( mPoisoned ) { // shrink with poisoning drawScale *= ( 1 - mPoisonStatus ); } double radius = drawScale * ( mGrowth * 0.8 + 0.2 ); // leaves become black with poisoning // (shades of white to allow texture color to dominate) Color leafColor( 1 - mPoisonStatus, 1 - mPoisonStatus, 1 - mPoisonStatus, 1 ); if( ! Features::drawNicePlantLeaves ) { // set color to shades of green green for leaves if we're drawing // simple boxes, since there's no texture color leafColor.setValues( 0, 1 - mPoisonStatus, 0, 1 ); } Angle3D zeroAngle( 0, 0, 0 ); PlantGenetics *genetics = &( mSeeds.mGenetics ); int maxNumJoints = (int)( genetics->getParameter( jointCount ) ); double growthFactor = mGrowth * 0.8 + 0.2; int numFullJoints = (int)( growthFactor * maxNumJoints ); double partialJoint = growthFactor * maxNumJoints - numFullJoints; int numLeavesPerJoint = (int)( genetics->getParameter( leavesPerJoint ) ); Angle3D angleIncrement( 0, 0, 2 * M_PI / numLeavesPerJoint ); Angle3D startAngle( 0, 0, mStartZAngle ); double currentScale = 1; double scaleDecrement = currentScale / ( maxNumJoints + 1 ); Vector3D leafPosition( inPosition ); Vector3D positionIncrement( 0, 0, -0.5 ); Vector3D leafWalkerTerminus; SimpleVector<Vector3D *> thisLayerLeafTerminii; for( int j=0; j<numFullJoints; j++ ) { // lower leaves are darker double colorScaleFactor = (double)(j+1) / (double)maxNumJoints; // min scaling of 0.5 colorScaleFactor = colorScaleFactor * 0.5 + 0.5; Color thisLevelColor; thisLevelColor.setValues( &leafColor ); thisLevelColor.weightColor( colorScaleFactor ); Angle3D currentAngle( &startAngle ); double zValue = leafPosition.mZ; if( zValue <= inMaxZ && zValue >= inMaxZ ) { // draw this joint for( int g=0; g<numLeavesPerJoint; g++ ) { if( Features::drawShadows ) { // draw shadow glColor4f( 0, 0, 0, 0.5 ); mLeaf.draw( &leafPosition, ¤tAngle, currentScale * radius * 1.05 ); } // draw leaf setGLColor( &thisLevelColor ); mLeaf.draw( &leafPosition, ¤tAngle, currentScale * radius, &leafWalkerTerminus ); thisLayerLeafTerminii.push_back( new Vector3D( &leafWalkerTerminus ) ); currentAngle.add( &angleIncrement ); } // finally cap this joint setGLColor( &thisLevelColor ); mJointCapTexture->enable(); glBegin( GL_QUADS ); { double capRadius = currentScale * radius * 0.1; double capZ = leafPosition.mZ; glTexCoord2f( 0, 0 ); glVertex3d( leafPosition.mX - capRadius, leafPosition.mY - capRadius, capZ ); glTexCoord2f( 1, 0 ); glVertex3d( leafPosition.mX + capRadius, leafPosition.mY - capRadius, capZ ); glTexCoord2f( 1, 1 ); glVertex3d( leafPosition.mX + capRadius, leafPosition.mY + capRadius, capZ ); glTexCoord2f( 0, 1 ); glVertex3d( leafPosition.mX - capRadius, leafPosition.mY + capRadius, capZ ); } glEnd(); mJointCapTexture->disable(); } Angle3D angleToNextJoint( &angleIncrement ); angleToNextJoint.scale( 0.5 ); currentAngle.add( &angleToNextJoint ); // start next joint at our current angle startAngle.setComponents( ¤tAngle ); currentScale -= scaleDecrement; leafPosition.add( &positionIncrement ); } if( partialJoint > 0 ) { Angle3D currentAngle( &startAngle ); // darker as growing completes // lower leaves are darker double colorScaleFactor = (double)(numFullJoints+1) / (double)maxNumJoints; // min scaling of 0.5 colorScaleFactor = colorScaleFactor * 0.5 + 0.5; // scale factor comes into effect as partial joint reaches 1 colorScaleFactor = (1 - partialJoint) + colorScaleFactor * partialJoint; Color thisLevelColor; thisLevelColor.setValues( &leafColor ); thisLevelColor.weightColor( colorScaleFactor ); double zValue = leafPosition.mZ; if( zValue <= inMaxZ && zValue >= inMaxZ ) { // draw this joint for( int g=0; g<numLeavesPerJoint; g++ ) { if( Features::drawShadows ) { // draw shadow glColor4f( 0, 0, 0, 0.5 ); mLeaf.draw( &leafPosition, ¤tAngle, partialJoint * currentScale * radius * 1.05 ); } setGLColor( &thisLevelColor ); mLeaf.draw( &leafPosition, ¤tAngle, // scale down further by partial fraction partialJoint * currentScale * radius ); currentAngle.add( &angleIncrement ); } // finally cap this joint setGLColor( &thisLevelColor ); mJointCapTexture->enable(); glBegin( GL_QUADS ); { double capRadius = currentScale * radius * 0.1; double capZ = leafPosition.mZ; glTexCoord2f( 0, 0 ); glVertex3d( leafPosition.mX - capRadius, leafPosition.mY - capRadius, capZ ); glTexCoord2f( 1, 0 ); glVertex3d( leafPosition.mX + capRadius, leafPosition.mY - capRadius, capZ ); glTexCoord2f( 1, 1 ); glVertex3d( leafPosition.mX + capRadius, leafPosition.mY + capRadius, capZ ); glTexCoord2f( 0, 1 ); glVertex3d( leafPosition.mX - capRadius, leafPosition.mY + capRadius, capZ ); } glEnd(); mJointCapTexture->disable(); } } int numTerminii = thisLayerLeafTerminii.size(); int t; if( mGrowth >= 1 ) { // NOTE: // This method of collecting all leaf terminii for the plant ASSUMES // that each terminus is at a unique location // This seems like a safe assumption, given the way leaves are // arranged now, but it is not safe in the general case. // If two terminii are at the same location, the terminus collection // would finish before collecting all terminii if( !mLeafTerminiiSet ) { // not done collecting leaf terminii for full-growth plant int numExisting = mLeafTerminii.size(); char collision = false; for( int t=0; t<numTerminii && !collision; t++ ) { Vector3D *newTerminus = *( thisLayerLeafTerminii.getElement( t ) ); // make sure not the same as existing char same = false; for( int e=0; e<numExisting && !same; e++ ) { Vector3D *existing = *( mLeafTerminii.getElement( e ) ); if( existing->equals( newTerminus ) ) { same = true; collision = true; } } if( !same ) { // add to list of all terminii mLeafTerminii.push_back( new Vector3D( newTerminus ) ); } } if( collision ) { // we are back to drawing a layer that we've already drawn // before // so we're not gathering new leaf terminii anymore mLeafTerminiiSet = true; } } else { // don't try adding flowers if we already have more than // numTerminii // flowers int numTotalTerminii = mLeafTerminii.size(); int numFlowers = mFlowerTerminusIndicies.size(); int numFruit = mFruitTerminusIndices.size(); if( numFlowers < numTotalTerminii && mTimeSinceLastFlower >= genetics->getParameter( timeBetweenFlowers ) ) { // new flower // pick random, unflowered, unfruited terminus int numTries = 0; char found = false; int foundIndex = -1; while( ! found && numTries < 100 ) { foundIndex = globalRandomSource.getRandomBoundedInt( 0, numTotalTerminii - 1 ); found = true; int f; for( f=0; f<numFlowers && found; f++ ) { if( *( mFlowerTerminusIndicies.getElement( f ) ) == foundIndex ) { // collision with existing flower location found = false; } } for( f=0; f<numFruit && found; f++ ) { if( *( mFruitTerminusIndices.getElement( f ) ) == foundIndex ) { // collision with existing fruit location found = false; } } numTries++; } if( found ) { mFlowerTerminusIndicies.push_back( foundIndex ); mFlowerStages.push_back( 0 ); mFlowerAngles.push_back( new Angle3D( 0, 0, globalRandomSource.getRandomBoundedDouble( 0, 2 * M_PI ) ) ); } mTimeSinceLastFlower = 0; } // recount, since we may have added some numFlowers = mFlowerTerminusIndicies.size(); for( int f=0; f<numFlowers; f++ ) { int terminusIndex = *( mFlowerTerminusIndicies.getElement( f ) ); Vector3D *terminus = *( mLeafTerminii.getElement( terminusIndex ) ); double zValue = terminus->mZ; if( zValue <= inMaxZ && zValue >= inMaxZ ) { Angle3D *flowerAngle = *( mFlowerAngles.getElement( f ) ); double flowerStage = *( mFlowerStages.getElement( f ) ); mFlower.draw( terminus, flowerAngle, drawScale, flowerStage ); } } } // draw fruit int numFruit = mFruit.size(); for( int f=0; f<numFruit; f++ ) { int terminusIndex = *( mFruitTerminusIndices.getElement( f ) ); Vector3D *terminus = *( mLeafTerminii.getElement( terminusIndex ) ); double zValue = terminus->mZ; if( zValue <= inMaxZ && zValue >= inMaxZ ) { Angle3D *fruitAngle = *( mFruitAngles.getElement( f ) ); Fruit *thisFruit = *( mFruit.getElement( f ) ); double fruitScale = drawScale * 0.2; thisFruit->draw( terminus, fruitAngle, fruitScale ); if( mHighlightRipeFruit && thisFruit->isRipe() ) { // make sure this is the fruit that we will harvest // next // (the z-range drawing can screw us // up here, since we might draw fruits out-of-order) // thus, the first-drawn ripe fruit is not necessarily // the fruit that will be next harvested Fruit *fruitNextHarvested = peekAtRipeFruit(); if( thisFruit == fruitNextHarvested ) { // this fruit will be harvested next glColor4f( 1, 1, 1, 0.25 ); // highlight brightens only glBlendFunc( GL_SRC_ALPHA, GL_ONE ); drawBlurCircle( terminus, fruitScale ); // back to normal blend function glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // only highlight one mHighlightRipeFruit = false; } } } } } // delete this layer's terminus points for( t=0; t<numTerminii; t++ ) { delete *( thisLayerLeafTerminii.getElement( t ) ); } }
void SunMenuItemView::reinitializeDisplayedItemPosition() { qint32 maxWidth = width(); qint32 maxHeight; QGraphicsItem* gi = displayedItem()->graphicsItem(); //default gi->resetTransform(); // Calculate maxHeight as smaller chord(only for small sweepLengths) if (sweepLength() <= 90) { qreal biggerChord = 2 * (innerRadius() + maxWidth) * /*qAbs*/(qSin((M_PI / 180) * sweepLength() / 2)); qreal smallerChord = 2 * innerRadius() * /*qAbs*/(qSin((M_PI / 180) * sweepLength() / 2)); maxHeight = (0.2 * smallerChord + 1.4 * biggerChord) / 2; } else maxHeight = displayedItem()->maximumHeight(); //hide item if it too small if (maxWidth < 10 || maxHeight < 5) { gi->hide(); return; } QRectF graphicsItemRect; if (sweepLength() == 360 && innerRadius() == 0) { displayedItem()->setMaximumSize(2 * maxWidth /*diameter*/, maxHeight); graphicsItemRect = gi->boundingRect(); gi->setPos(-graphicsItemRect.width() / 2, -graphicsItemRect.height() / 2); gi->show(); return; } displayedItem()->setMaximumSize(maxWidth - 10, maxHeight); graphicsItemRect = gi->boundingRect(); ///////////////////////////////////////////////////////////////////////////////// //positioning mDisplayedItem (rotation and coordinates). qreal rotationAngle = startAngle() + sweepLength() / 2; // Getting distance and angle (polar coordinates) + some centering adjustments // We assume that (0,0) item's coordinate is it's top left corner //(like QGraphicsSimpleTextItem and QGraphicsProxyWidget). qreal angle, distance; if (rotationAngle >= 270 || rotationAngle <= 90) { distance = innerRadius() + maxWidth / 2 - graphicsItemRect.width() / 2; angle = rotationAngle + (180 / M_PI) * qAtan(graphicsItemRect.height() / (2 * distance)); } else { distance = innerRadius() + maxWidth / 2 + graphicsItemRect.width() / 2; angle = rotationAngle - (180 / M_PI) * qAtan(graphicsItemRect.height() / (2 * distance)); rotationAngle -= 180; } gi->setPos(distance * qCos((M_PI / 180) * angle), -distance * qSin((M_PI / 180) * angle)); gi->setRotation(-rotationAngle); //minus - because this function rotates clockwise. gi->show(); /////////////////////////////////////////////////////////////////////////////////// }