Exemple #1
0
//------------------------------------------------------------------------------
void TStaticObject::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
    if (mFixed) {
        return;
    }

    bool fixedAngle = event->modifiers() == Qt::ControlModifier;
    if (mButton == Qt::LeftButton) {
        // Rotate object
        if (event->modifiers() == Qt::ShiftModifier || fixedAngle) {
            int angle = (int)(event->pos().x() - mCursorPosition.x());
            if (!fixedAngle) {
                angle %= 4;
            }
            angle += rotation();
            angle %= 360;

            if (fixedAngle) {
                angle = (int) angle / 45 * 45;
            }

            setTransformOriginPoint(centerPoint());
            setRotation(angle);
            return;
        }

        // Move object
        setTransformOriginPoint(0, 0);
        QGraphicsItem::setPos(mapToScene(
                event->pos().x() - mCursorPosition.x(),
                event->pos().y() - mCursorPosition.y()));
        setTransformOriginPoint(centerPoint());
    }
}
Exemple #2
0
Wall::Wall(int code): QGraphicsPixmapItem()
{
    if(code%2){
        door = true;
    }
    else{
        door = false;
    }

    switch (code) {
    case 1: //rightwall
                setPixmap(QPixmap(":/images /bg_side_wall.png"));
                setPos(x()+274,y());
        break;
    case 2: //rightdoor
                setPixmap(QPixmap(":/images /bg_side_door.png"));
                setPos(x()+230,y());
        break;
    case 3: //leftwall
                setPixmap(QPixmap(":/images /bg_side_wall.png"));
                setPos(x()-274,y());
                setTransformOriginPoint(25,248);
                setRotation(180);
        break;
    case 4: //leftdoor
                setPixmap(QPixmap(":/images /bg_side_door.png"));
                setPos(x()-230,y());
                setTransformOriginPoint(25,248);
                setRotation(180);
        break;
    case 5: //topwall
                setPixmap(QPixmap(":/images /bg_End_wall.png"));
                setPos(x()-274,y());
        break;
    case 6: //topdoor
                setPixmap(QPixmap(":/images /bg_End_Door.png"));
                setPos(x()-274,y());
        break;
    case 7: //bottomwall
                setPixmap(QPixmap(":/images /bg_End_wall.png"));
                setPos(x()+274,y());
                setTransformOriginPoint(25,248);
                setRotation(180);
        break;
    case 8: //bottomdoor
                setPixmap(QPixmap(":/images /bg_End_Door.png"));
                setPos(x()+274,y());
                setTransformOriginPoint(25,248);
                setRotation(180);
        break;
    default:
        break;
    }

}
Exemple #3
0
BigBird::BigBird(b2World * inputWorld)
{
    //基本設定
    setPos(70 , 370);
    inWorld = inputWorld;
    setPixmap(QPixmap("./GameData/DefaultResources/Images/BirdImages/bigBird.png"));
    setTransformOriginPoint(0 , 0);
    health = 5;

    //設定鳥的ItemData
    itemData->objectType =  "Bird";
    itemData->sceneObject = this;
    itemData->bodyObject = physicBody;

    //設定鳥的物體結構
    bodyStruct->type = b2_dynamicBody;
    bodyStruct->position.Set( PixToMeter_x(x()) , PixToMeter_y(y()) );
    bodyStruct->angle = 0 ;

    //設定鳥的物體的定製器

        //設定一種形狀
        b2CircleShape * circleShape = new b2CircleShape();
        circleShape->m_p.Set(45 , -45);
        circleShape->m_radius = 45 ;

    bodyFixture->shape = circleShape ;
    bodyFixture->density = 1 * 10;
    bodyFixture->friction = 1.0f ;
    bodyFixture->restitution = 0.75f;
}
void MozQWidget::orientationChanged()
{
    if (!scene() || !scene()->views().size()) {
        return;
    }

    NS_ASSERTION(scene()->views().size() == 1, "Not exactly one view for our scene!");
    QTransform& transform = MozQOrientationSensorFilter::GetRotationTransform();
    QRect scrTrRect = transform.mapRect(scene()->views()[0]->rect());

    setTransformOriginPoint(scene()->views()[0]->size().width() / 2, scene()->views()[0]->size().height() / 2);
    scene()->views()[0]->setTransform(transform);
    int orientation = MozQOrientationSensorFilter::GetWindowRotationAngle();
    if (orientation == 0 || orientation ==  180) {
        setPos(0,0);
    } else {
        setPos(-(scrTrRect.size().width() - scrTrRect.size().height()) / 2,
               (scrTrRect.size().width() - scrTrRect.size().height()) / 2);
    }
    resize(scrTrRect.size());
    scene()->setSceneRect(QRectF(QPointF(0, 0), scrTrRect.size()));
#ifdef MOZ_X11
    Display* display = QX11Info::display();
    if (!display) {
        return;
    }

    Atom orientationAngleAtom = XInternAtom(display, "_MEEGOTOUCH_ORIENTATION_ANGLE", False);
    XChangeProperty(display, scene()->views()[0]->effectiveWinId(),
                    orientationAngleAtom, XA_CARDINAL, 32,
                    PropModeReplace, (unsigned char*)&orientation, 1);
#endif
}
Exemple #5
0
void Shuttle::advance(int step) {
     if (!step)
        return;

        // necessary to rotate around the centre of the rectangle
        // (default: rotation around the top left corner)
        setTransformOriginPoint(QPoint(width/2,height/2));

        // handling of different KeyEvents
        if (keys[Qt::Key_Left]) {
            setRotation(qRound(rotation() - turnspeed) % 360);
        }
        if (keys[Qt::Key_Right]) {
            setRotation(qRound(rotation() + turnspeed) % 360);
        }
        if (keys[Qt::Key_Up]) {
            qreal nextX = x() + qSin(rotation() * M_PI/180) * speed;
            qreal nextY = y() - qCos(rotation() * M_PI/180) * speed;

            setPos(QPointF(nextX, nextY));
        }
        if (keys[Qt::Key_Down]) {
            qreal nextX = x() - qSin(rotation() * M_PI/180) * speed;
            qreal nextY = y() + qCos(rotation() * M_PI/180) * speed;

            setPos(QPointF(nextX, nextY));
        }
        if(keys[Qt::Key_Space]){
            shotstrategy->shoot();
        }

        deleteIfCollidesWith(asteroid);
        itemCollisionHandling();
}
Exemple #6
0
void Ellipse::calculate()
{
    d12 = qSqrt(qPow((p2.x() - p1.x()), 2) + qPow((p2.y() - p1.y()), 2));
    d13 = qSqrt(qPow((p3.x() - p1.x()), 2) + qPow((p3.y() - p1.y()), 2));

    if (d12 > d13)
    {
        majRadius = d12;
        minRadius = d13;
        theta = atan2((p2.y() - p1.y()), (p2.x() - p1.x())) * (180 / M_PI);
    }
    else
    {
        majRadius = d13;
        minRadius = d12;
        theta = atan2((p3.y() - p1.y()), (p3.x() - p1.x())) * (180 / M_PI);
    }

    topLeft.setX(p1.x() - majRadius);
    topLeft.setY(p1.y() - minRadius);
    bottomRight.setX(p1.x() + majRadius);
    bottomRight.setY(p1.y() + minRadius);

    setTransformOriginPoint(p1);
    setRotation(theta);
}
void QgsComposerItem::setItemRotation( double r, bool adjustPosition )
{
  if ( adjustPosition )
  {
    //adjustPosition set, so shift the position of the item so that rotation occurs around item center
    //create a line from the centrepoint of the rect() to its origin, in scene coordinates
    QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ) , mapToScene( QPointF( 0 , 0 ) ) );
    //rotate this line by the current rotation angle
    refLine.setAngle( refLine.angle() - r + mItemRotation );
    //get new end point of line - this is the new item position
    QPointF rotatedReferencePoint = refLine.p2();
    setPos( rotatedReferencePoint );
    emit sizeChanged();
  }

  if ( r > 360 )
  {
    mItemRotation = (( int )r ) % 360;
  }
  else
  {
    mItemRotation = r;
  }

  setTransformOriginPoint( 0, 0 );
  QGraphicsItem::setRotation( mItemRotation );

  emit itemRotationChanged( r );
  update();
}
DeformJoint::DeformJoint(QGraphicsItem *parent)
    : QGraphicsRectItem(QRectF(QPointF(), QSize(WIDTH, HEIGHT)), parent)
{
    setTransformOriginPoint(getCenter());
    setFlag(QGraphicsItem::ItemIsMovable);
    setFlag(QGraphicsItem::ItemIsSelectable);
}
void EllipseScatterer::paint ( QGraphicsScene * scene, double xMin, double xMax, double yMin, double yMax ) {
    //QLOG_DEBUG() << "EllipseScatterer::paint";
    innerState->form.show();
    state->xMax = xMax;
    state->yMax = yMax;
    state->xMin = xMin;
    state->yMin = yMin;
    state->scene = scene;

    double x = getXscene( state->rect.x(), xMin, xMax, scene->width() );
    double y = getYscene( state->rect.y(), yMin, yMax, scene->height() );
    double width = getWidthOnScene( state->rect.width(), xMin, xMax, scene->width() );
    double height = getHeightOnScene( state->rect.height(),  yMin, yMax, scene->height() );

    QRectF rectScene( x - state->posX, y - state->posY, width, height ); // if we drug on ( delta_x, delta_y ) then  origin shift on ( delta_x, delta_y ) - I DON'T KNOW WHY!
    QPainterPath path_;
    path_.arcMoveTo( rectScene, innerState->startAngle );
    path_.arcTo( rectScene, innerState->startAngle , innerState->spanAngle );
    setPath( path_ );

    setTransformOriginPoint( x + width/2 - state->posX, y + height/2 - state->posY );  //posX, posY - because of mouse drag
    setRotation( state->rotationAngle );

    if ( !state->isAdded ) {
        scene->addItem( this );
        state->isAdded = true;
    }
    state->boundingRectBeforeDrag = sceneBoundingRect();

}
void LineScatterer::paint ( QGraphicsScene * scene, double xMin, double xMax, double yMin, double yMax ) {
    //QLOG_DEBUG() << "LineScatterer::paint";
    innerState->form.show();
    state->xMax = xMax;
    state->yMax = yMax;
    state->xMin = xMin;
    state->yMin = yMin;
    state->scene = scene;

    double x1Scene = getXscene( innerState->x1, xMin, xMax, scene->width() ) - state->posX;
    double y1Scene = getYscene( innerState->y1, yMin, yMax, scene->height() ) - state->posY;
    double x2Scene = getXscene( innerState->x2, xMin, xMax, scene->width() ) - state->posX;
    double y2Scene = getYscene( innerState->y2,  yMin, yMax, scene->height() ) - state->posY;

    QPainterPath path_;
    path_.moveTo( x1Scene, y1Scene );
    path_.lineTo( x2Scene, y2Scene );

    setPath( path_ );

    setTransformOriginPoint( (x1Scene + x2Scene) / 2, ( y1Scene + y2Scene ) / 2 );  //posX, posY - because of mouse drag
   // setRotation( state->rotationAngle );

    double angle = calcAngle();
    //QLOG_INFO() << "angle = " << angle;

    if ( !state->isAdded ) {
        scene->addItem( this );
        state->isAdded = true;
    }
    state->boundingRectBeforeDrag = sceneBoundingRect();
}
Exemple #11
0
CardItem::CardItem(const Card *card)
    :Pixmap(card->getPixmapPath(), false), card(card), filtered_card(card), auto_back(true), frozen(false)

{
    Q_ASSERT(card != NULL);

    suit_pixmap.load(QString("image/system/suit/%1.png").arg(card->getSuitString()));
    cardsuit_pixmap.load(QString("image/system/cardsuit/%1.png").arg(card->getSuitString()));
    number_pixmap.load(QString("image/system/%1/%2.png").arg(card->isBlack()?"black":"red").arg(card->getNumberString()));
    icon_pixmap.load(card->getIconPath());
    setTransformOriginPoint(pixmap.width()/2, pixmap.height()/2);

    setToolTip(card->getDescription());
    setAcceptHoverEvents(true);

    QPixmap frame_pixmap("image/system/frame/good.png");
    frame = new QGraphicsPixmapItem(frame_pixmap, this);
    frame->setPos(-6, -6);
    frame->hide();

    avatar = NULL;
    owner_pixmap = NULL;
    owner_text = new QGraphicsSimpleTextItem(this);
    QPen pen(Qt::black);
    pen.setWidthF(0.5);
    owner_text->setPen(pen);
    owner_text->setBrush(Qt::yellow);
    owner_text->hide();
}
void UIGraphicsRotatorButton::refresh()
{
    /* Update rotation center: */
    QSizeF sh = minimumSizeHint();
    setTransformOriginPoint(sh.width() / 2, sh.height() / 2);
    /* Update rotation state: */
    updateRotationState();
    /* Call to base-class: */
    UIGraphicsButton::refresh();
}
Exemple #13
0
void ItemElement::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
//    if(mItemDragged && mScaleEnabled) {
//        setNonUniformScale (event->pos(), event->lastPos());
    if(mItemDragged && mRotateEnabled) {
        setTransformOriginPoint(pixmap().rect().center());
        setDraggedRotation(event->pos(),event->lastPos());
    } else {
          AbstractTreePixmapItem::mouseMoveEvent (event);
    }
}
chicken_level_2::chicken_level_2(){

    //draw a enemy
   setPixmap(QPixmap(":/image/rock.png"));
   setTransformOriginPoint(250,550);
   setRotation(180);
         //connect
        QTimer *timer=new QTimer();
        connect(timer,SIGNAL(timeout()),this,SLOT(move()));
        timer->start(50);

}
Exemple #15
0
CardItem::CardItem(const Card *card)
    :Pixmap(card->getPixmapPath(), false), card(card)
{
    Q_ASSERT(card != NULL);

    suit_pixmap.load(QString(":/suit/%1.png").arg(card->getSuitString()));
    icon_pixmap.load(card->getIconPath());
    pixmap = pixmap.scaled(CardItemRect.width(), CardItemRect.height());
    setTransformOriginPoint(pixmap.width()/2, pixmap.height()/2);

    setToolTip(card->getDescription());
}
ItemGroup::ItemGroup(QGraphicsItem *parent, QGraphicsScene *scene)
    : QGraphicsItemGroup( parent, scene),
    mScale(QPointF(1.0, 1.0))
{
    setTransform(QTransform(1,0,0,0,1,0,0,0,1));
    setPos(0, 0);
	setTransformOriginPoint(0, 0);
	setRotation(0);

    setFlag(QGraphicsItem::ItemIsMovable);
    setFlag(QGraphicsItem::ItemIsSelectable);
    setHandlesChildEvents(true);
}
void ArtificialHorizon::updateArtificialHorizon(int roll_angle,
	int pitch_angle)
{
	// Update roll and pitch
	roll = roll_angle;
	pitch = pitch_angle;

	// Translate pixmap (pitch)
	setPos(x(), -1.0 * center_y + offset - pitch);

	// Update transformation point and rotate pixmap
	setTransformOriginPoint(center_x, center_y + pitch);
	setRotation(-roll);
}
Exemple #18
0
SchemeItem::SchemeItem(ItemTemplate::TYPE Type, QGraphicsItem* Parent)
: QGraphicsSvgItem(ItemTemplate::GetIcons()[Type], Parent), TYPE(Type)
{
	setTransformOriginPoint(boundingRect().width() / 2, boundingRect().height() / 2);
	setFlag(QGraphicsItem::ItemIsMovable, true);

	if (TYPE == ItemTemplate::VoltageSource ||
	    TYPE == ItemTemplate::CurrentSource ||
	    TYPE == ItemTemplate::Resistor)
	{
		Connections.append(nullptr);
		Connections.append(nullptr);
	}
}
Exemple #19
0
void ObjetVolant::init()
{
    //Initialise les variables
    setZValue(1);
    setPilotage(manuel);
    setDessinerTrajectoire(false);
    creerImageParDefaut();
    setLooping(0);

    setVitesseAngulaireObjet(180.0 / 1000.0);
    setAccelerationObjet(100.0 / 1000000.0);
    setVitesseMinObjet(100.0 / 1000.0);
    setVitesseMaxObjet(300.0 / 1000.0);

    setPosition(QPointF(0, 0));
    setVitesseAngulaire(0);
    setAngle(vitesseAngulaire() * 0);
    setAcceleration(0);
    setVitesse(vitesseMinObjet());

    //Animation du looping
    animationLooping = new QPropertyAnimation(this, "looping");
    animationLooping->setDuration(500);
    animationLoopingRoot = new QSequentialAnimationGroup(this);
    animationLoopingRoot->addPause(1500); //Attend un moment avant de se retourner
    animationLoopingRoot->addAnimation(animationLooping);

    //Animation de la position
    animationPosition = new QPropertyAnimation(this, "position");
    animationPosition->setDuration(25);

    //Animation de l'angle
    setTransformOriginPoint(boundingRect().center()); //Met le centre de rotation au centre de l'Item
    animationAngle = new QPropertyAnimation(this, "angle");
    animationAngle->setDuration(25);

    //Animation de la vitesse
    animationVitesse = new QPropertyAnimation(this, "vitesse");
    animationVitesse->setDuration(25);

    //Animation principale des déplacements
    animationRoot = new QParallelAnimationGroup(this);
    animationRoot->addAnimation(animationAngle);
    animationRoot->addAnimation(animationVitesse);
    animationRoot->addAnimation(animationPosition);
    connect(animationRoot, SIGNAL(finished()), this, SLOT(seDeplacer()));

    temps.start();
    seDeplacer();
}
Exemple #20
0
void QgsComposerItem::refreshRotation( const bool updateItem, const bool adjustPosition, const QgsExpressionContext& context )
{
  double rotation = mItemRotation;

  //data defined rotation set?
  QVariant exprVal;
  if ( dataDefinedEvaluate( QgsComposerObject::ItemRotation, exprVal, context ) )
  {
    bool ok;
    double rotD = exprVal.toDouble( &ok );
    QgsDebugMsg( QString( "exprVal Rotation:%1" ).arg( rotD ) );
    if ( ok && !exprVal.isNull() )
    {
      rotation = rotD;
    }
  }

  if ( qgsDoubleNear( rotation, mEvaluatedItemRotation ) )
  {
    return;
  }

  if ( adjustPosition )
  {
    //adjustPosition set, so shift the position of the item so that rotation occurs around item center
    //create a line from the centrepoint of the rect() to its origin, in scene coordinates
    QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ), mapToScene( QPointF( 0, 0 ) ) );
    //rotate this line by the current rotation angle
    refLine.setAngle( refLine.angle() - rotation + mEvaluatedItemRotation );
    //get new end point of line - this is the new item position
    QPointF rotatedReferencePoint = refLine.p2();
    setPos( rotatedReferencePoint );
    emit sizeChanged();
  }

  setTransformOriginPoint( 0, 0 );
  QGraphicsItem::setRotation( rotation );

  mEvaluatedItemRotation = rotation;

  emit itemRotationChanged( rotation );

  //update bounds of scene, since rotation may affect this
  mComposition->updateBounds();

  if ( updateItem )
  {
    update();
  }
}
Exemple #21
0
Pixmap::Pixmap(const QString &filename, bool center_as_origin)
    :pixmap(filename), markable(false), marked(false)
{
    if(pixmap.isNull()){
        QImageReader reader(filename);
        QString error_string = reader.errorString();

        QString warning = tr("Can not load image %1[%2], error string is %3")
                          .arg(filename).arg(metaObject()->className()).arg(error_string);
        QMessageBox::warning(NULL, tr("Warning"), warning);
    }

    if(center_as_origin)
        setTransformOriginPoint(pixmap.width()/2, pixmap.height()/2);
}
chicken_level_1::chicken_level_1()
{
    //set random positin
    int random_number=rand()%700;
    //int random_number=rand()%700;
    setPos(random_number,100);
     //draw a enemy
    setPixmap(QPixmap(":/images/E:/monsterSpriteSheet.png"));
    setTransformOriginPoint(220,70);
    setRotation(180);
     //connect
    QTimer *timer=new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(move()));
    timer->start(50);
}
Exemple #23
0
YigModField::YigModField(YigSynthGraphic *synthGraphic, float param, qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent) :
    QGraphicsEllipseItem( x, y, width, height, parent ),
    modArc(this),
    yigAttractor(this),
    modTriangle(this)
{
    //createModCircle();
    parentGraphic = synthGraphic;
    setTransformOriginPoint(boundingRect().width()/2, boundingRect().height()/2);
    rotationAngle = param * 360;
    setRotation(fmod(rotationAngle+180, 360));
    transformOriginPoint();
    updateParameter(fmod((rotationAngle+180), 360)/360);
    modTriangle.setZValue(99);
    QPolygonF modPolygon;
    modPolygon.append(QPointF(0, 0));
    modPolygon.append(QPointF(5, 15));
    modPolygon.append(QPointF(-5, 15));
    modPolygon.translate(width/2, 0);
    modTriangle.setPolygon(modPolygon);
    QPen modPen(Qt::NoPen);
    modTriangle.setPen(modPen);
    QColor modColor(YigColorKit::background2);
    modColor.setAlpha(200);
    QBrush modBrush(modColor);
    modTriangle.setBrush(modBrush);
    // Mod amount
    /*
    modElectron = new QGraphicsEllipseItem(0, 0, 25, 25, this);
    modElectron->moveBy(0, (boundingRect().width()/2) - 3);
    modElectron->setFlag( QGraphicsItem::ItemIsSelectable, false );
    modElectron->setFlag( QGraphicsItem::ItemIsMovable, false );
    modElectron->setCacheMode( QGraphicsItem::ItemCoordinateCache );
    QColor modColor(YigColorKit::background2);
    modColor.setAlpha(200);
    modElectron->setPen(QPen(modColor));
    modColor.setAlpha(20);
    modElectron->setBrush(modColor);*/

    /*
    QColor modFill(YigColorKit::background2);
    modFill.setAlpha(100);
    QColor modOutline(YigColorKit::background2);
    modOutline.setAlpha(220);
    modArc.setBrush(modFill);
    modArc.setPen(Qt::NoPen);*/
    //redrawArc();
}
Exemple #24
0
void Wall::setEnd(bool end)
{
    setPixmap(QPixmap(":/images /bg_End_wall.png"));
    if(end){
        //Top wall

       setPos(x()-274,y());
    }
    else{
        //Bottom wall
        setPos(x()-274,y()+460);
        setTransformOriginPoint(300,25);
        setRotation(180);
       // setRotation(180);
    }
}
Exemple #25
0
void Wall::setSide(bool side)
{
    setPixmap(QPixmap(":/images /bg_side_wall.png"));
    if(side){
        //rightsdie wall

       setPos(x()+274,y());
    }
    else{
        //leftside wall
        setPos(x()-274,y());
        setTransformOriginPoint(25,248);
        setRotation(180);
       // setRotation(180);
    }
}
Exemple #26
0
Enemy::Enemy(QGraphicsItem *parent)
    : QObject(), QGraphicsPixmapItem(parent)
{
    int r_pos = rand() % 600;
    setPos(r_pos, 0);

    setPixmap(QPixmap(":/textures/res/textures/enemy.png"));
    setTransformOriginPoint(50, 50);
    setRotation(0);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()),
            this, SLOT(move()));

    timer->start(50);

}
Exemple #27
0
CardItem::CardItem(const Card *card)
    :Pixmap(card->getPixmapPath(), false), card(card), filtered_card(card), auto_back(true)
{
    Q_ASSERT(card != NULL);

    suit_pixmap.load(QString("image/system/suit/%1.png").arg(card->getSuitString()));
    icon_pixmap.load(card->getIconPath());
    setTransformOriginPoint(pixmap.width()/2, pixmap.height()/2);

    setToolTip(card->getDescription());

    QPixmap frame_pixmap("image/system/frame/good.png");
    frame = new QGraphicsPixmapItem(frame_pixmap, this);
    frame->setPos(-6, -6);
    frame->hide();

    avatar = NULL;
}
Exemple #28
0
Button::Button(Image i, qreal z, Character* p, QGraphicsPixmapItem* parent, QGraphicsScene* scene) : QGraphicsPixmapItem(parent, scene)
{
    image_ = i;
    character_ = p;
    QPixmap pix(image_.width(), image_.height());
    pix = QPixmap::fromImage(image_);

    setPixmap(pix);
    setZValue(z);
    setOpacity(0.5);
    setTransformOriginPoint(image_.width()/2, image_.height()/2);
    setParentItem(parent);
    setAcceptsHoverEvents(true);
    setFlags(QGraphicsItem::ItemIsSelectable);
    setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);

    animations_ = new Animations();
}
void imgWidgetDisplayBigItem::wheelEvent(QWheelEvent *e){
    int numDegrees = e->delta() / 8;//滚动的角度,*8就是鼠标滚动的距离
    int numSteps = numDegrees / 15;//滚动的步数,*15就是鼠标滚动的角度
    if (e->orientation() == Qt::Vertical) {
        //qDebug()<<"垂直滚动 = "<<numSteps;//垂直滚动
        scaleNum+=numSteps;
        if(scaleNum<0){
            scaleNum++;
        }else if(scaleNum>30){
            //scaleNum--;
        }
        qDebug()<<e->x()<<e->y();
        setTransformOriginPoint(e->x(),e->y());
        setScale(scaleNum/5.0);
    } else {
     qDebug()<<"水平滚动 = ";      //水平滚动
    }
    e->accept();      //接收该事件
}
Exemple #30
0
FlipFlop::FlipFlop(QGraphicsObject *parent) :
    Element(parent)
{
    height=50;
    minHeight=50;
    width=50;
    qRegisterMetaType<FlipFlop>("FlipFlop");
    myOnWhichValue=true;
    setFlipFlopType(SetReset);
    setFlipFlopTrigger(None);
    setClockNegated(false);
    myValue=false;
    recalculate();
    myType="flipflop";
    setProperty("recalcs",0);
	setTransformOriginPoint(QPointF(25,25));
	toggled=false;
	setTitle("FF");
}