Пример #1
0
void MyItem::doCollision()
{
    // get a new position

    // change the angle with randomness
    if(qrand() % 1)
    {
        setRotation(rotation() + (180 + (qrand() % 10)));
    }
    else
    {
        setRotation(rotation() + (180 + (qrand() % -10)));
    }

    // check if the new position is in bounds
    QPointF newPoint = mapToParent(-(boundingRect().width()), -(boundingRect().width() + 2));

    if(!scene()->sceneRect().contains((newPoint)))
    {
        // move back in bounds
        newPoint = mapToParent(0,0);
    }
    else
    {
        // set the new position
        setPos(newPoint);
    }
}
Пример #2
0
void TabBar::updateDropMarker(const QPoint& pos)
{
    int idx = tabAt(pos);
    if(idx == -1)
    {
        m_drag_idx = -1;
        if(m_drag_insert)
            m_drag_insert->hide();
        return;
    }

    const int ARROW_SIZE = 32;
    if(!m_drag_insert)
    {
        m_drag_insert = new QLabel(parentWidget());
        m_drag_insert->resize(ARROW_SIZE, ARROW_SIZE);
        m_drag_insert->setAttribute(Qt::WA_TransparentForMouseEvents);
        m_drag_insert->setPixmap(QIcon(":/icons/arrow-down").pixmap(ARROW_SIZE, ARROW_SIZE));
    }

    QPoint p;
    QRect rect = tabRect(idx);
    if(pos.x() - rect.left() >= rect.width()/2)
    {
        m_drag_idx = idx+1;
        p = mapToParent(rect.topRight());
    }
    else
    {
        m_drag_idx = idx;
        p = mapToParent(rect.topLeft());
    }
    m_drag_insert->move(p - QPoint(ARROW_SIZE/2, ARROW_SIZE/2));
    m_drag_insert->show();
}
Пример #3
0
void pion::mouseMoveEvent(QMouseEvent *ev)
{
    // si c'est le tour du joueur 1
    if(((MainWindow*)parent())->tourDuJoueur==1)
    {
        // choix d'un pion
        if(pionNum<3) //si le pion est au joueur 1
        {
            if(((MainWindow*)parent())->toutPlacer<6)
            {
                if(oldY==412)
                {
                    // le pions prend la position de la souris
                    this->move(mapToParent(QPoint(ev->x()-25,ev->y()-25)));
                    setPixmap(QPixmap(":/pions/P1d"));
                }
                else
                {
                    ((MainWindow*)parent())->tousSurLePlateau=false;
                }
            }
            else
            {
                // le pions prend la position de la souris
                this->move(mapToParent(QPoint(ev->x()-25,ev->y()-25)));
                setPixmap(QPixmap(":/pions/P1d"));
                ((MainWindow*)parent())->tousSurLePlateau=true;
            }
        }
    }
    // si c'est le tour du joueur 2
    else
    {
        // choix d'un pion
        if(pionNum>2) //si le pion est au joueur 2
        {
            if(((MainWindow*)parent())->toutPlacer<6)
            {
                if(oldY==412)
                {
                    // le pions prend la position de la souris
                    this->move(mapToParent(QPoint(ev->x()-25,ev->y()-25)));
                    setPixmap(QPixmap(":/pions/P2d"));
                }
                else
                {
                    ((MainWindow*)parent())->tousSurLePlateau=false;
                    qDebug()<<"PLACE TES PIONS !";
                }
            }
            else
            {
                // le pions prend la position de la souris
                this->move(mapToParent(QPoint(ev->x()-25,ev->y()-25)));
                setPixmap(QPixmap(":/pions/P2d"));
                ((MainWindow*)parent())->tousSurLePlateau=true;
            }
        }
    }
}
Пример #4
0
void VideoFrame::mouseMoveEvent(QMouseEvent *AEvent)
{
	static const QSize cornerSize = QSize(10,10);

	if (FPressedPos.isNull() || FCollapsed)
	{
		FCursorCorner = -1;
		for (int i=0; FCursorCorner<0 && i<4; i++)
			if ((Corners[i].align & FAlignment)==0 && QStyle::alignedRect(Qt::LeftToRight,Corners[i].align,cornerSize,rect()).contains(AEvent->pos()))
				FCursorCorner = i;

		if (FCollapsed)
			setCursor(Qt::ArrowCursor);
		else if (FResizeEnabled && FCursorCorner>=0)
			setCursor(Corners[FCursorCorner].cursor);
		else if (FMoveEnabled)
			setCursor(Qt::OpenHandCursor);
	}
	else if (FResizeEnabled && FCursorCorner>=0)
	{
		FMoved = true;
		emit resizeTo((Qt::Corner)FCursorCorner,mapToParent(AEvent->pos()));
	}
	else if (FMoveEnabled && FMoved)
	{
		emit moveTo(mapToParent(AEvent->pos())-FPressedPos);
	}
	else if ((FGlobalPressed-AEvent->globalPos()).manhattanLength()>=qApp->startDragDistance())
	{
		FMoved = true;
	}

	QFrame::mouseMoveEvent(AEvent);
}
Пример #5
0
void MyItem::DoCollisions()
{
    // Set a new position

    // Change the angle with a little randomness
    if(qrand() % 1)
    {
        setRotation(rotation() + (180 + (qrand() % 10)));
    }
    else
    {
        setRotation(rotation() + (180 + (qrand() % -10)));
    }

    // See if the new position is in the bounds
    QPointF newPoint = mapToParent(-(boundingRect().width()),-(boundingRect().width()+2));
    if(!scene()->sceneRect().contains(newPoint))
    {
        // Move it back in bounds
        newPoint = mapToParent(0,0);
    }
    else
    {
        // Set new position
        setPos(newPoint);
    }
}
Пример #6
0
void RescaleWidget::
        updateModel()
{
    bool success1, success2;

    Heightmap::Position last = view_->getPlanePos( mapToParent(dragSource_), &success1);
    Heightmap::Position current = view_->getPlanePos( mapToParent(lastPos_), &success2);

    QPointF d = lastPos_ - dragSource_;
    float dx = d.x() / width();
    float dy = -d.y() / height();
    dx = max(-.1f, min(.1f, dx));
    dy = max(-.1f, min(.1f, dy));
    scalex_ *= exp2f(dx);
    scaley_ *= exp2f(dy);
    scalex_ = max(0.5f, min(1.8f, scalex_));
    scaley_ = max(0.5f, min(1.8f, scaley_));

    if (success1 && success2)
    {
        float r = DIRECT_RESCALING ? 4 : .1;
        float dt = r*(current.time - last.time)*view_->model->xscale/view_->model->_pz;
        float ds = r*(current.scale - last.scale)*view_->model->zscale/view_->model->_pz;

        Tools::Commands::pCommand cmd( new Tools::Commands::ZoomCameraCommand(view_->model, dt, ds, 0.f ));
        view_->model->project()->commandInvoker()->invokeCommand( cmd );
    }

    //dragSource_ = event->pos();
    recreatePolygon();
}
Пример #7
0
void Cell :: advance( int phase )
{
    if ( !phase )
    {
        return;
    }

    if ( moving )
    {
        const float dx = ( newPosition.rx() - mapToParent( 0, 0 ).rx() ) / 4;
        const float dy = ( newPosition.ry() - mapToParent( 0, 0 ).ry() ) / 4;
        const bool stopX = ( abs( dx ) < SELL_SIZE / 200.0 );
        const bool stopY = ( abs( dy ) < SELL_SIZE / 200.0 );
        if ( stopX && stopY )
        {
            setPos( newPosition );
            moving = false;
            emit positionChanged();
        }
        else
        {
            setPos( mapToParent( dx, dy ) );
        }
    }
}
Пример #8
0
void Item::doCollision()
{
    //set a new position

    //change angle
    if(qrand() % 1)
    {
        setRotation(rotation() + (180 + (qrand() % 10)));
    }
    else
    {
        setRotation(rotation() + (180 + (qrand() % -10)));
    }

    QPointF newpoint = mapToParent(-(boundingRect().width()), -(boundingRect().width() + 2));

    if(!scene()->sceneRect().contains(newpoint))
    {
        //move it back in bounds
        newpoint = mapToParent(0,0);
    }
    else
    {
        //set the new position
        setPos(newpoint);
    }
}
void MyItem::doCollision()
{
    //Get new pos
    //Change angle with randomnexx
    if(qrand() % 1)
    {
        setRotation(rotation() + 180 + qrand() % 10);
    }
    else
    {
        setRotation(rotation() + 180 + qrand() % -10);
    }

    //check if new pos is in bounds
    QPointF newPos = mapToParent(-(boundingRect().width()),
                                 -(boundingRect().width() + 2));
    if(!scene()->sceneRect().contains(newPos))
    {
        //Move back in bounds
        newPos = mapToParent(0, 0);
    }
    else
    {
        //Set the new pos
        setPos(newPos);
    }
}
Пример #10
0
QPainterPath tGauge::ClickableRegion()
{
    QPainterPath p;
    if( m_Indicators.size() > 0 )
    {
        p.addRect( QRect( mapToParent( rect().topLeft() ), mapToParent( rect().bottomRight() ) ) );
    }
    return p;
}
Пример #11
0
void LineItem::updateDataRelativeRect(bool force) {
  CartesianRenderItem* plot = dynamic_cast<CartesianRenderItem*>(parentViewItem());
  if (plot) {
    if ((!lockPosToData()) || force) {
      QPointF P1 = (rect().topLeft() + rect().bottomLeft())/2;
      QPointF P2 = (rect().topRight() + rect().bottomRight())/2;
      _dataRelativeRect.setTopLeft(plot->plotItem()->mapToProjection(mapToParent(P1)));
      _dataRelativeRect.setBottomRight(plot->plotItem()->mapToProjection(mapToParent(P2)));
    }
  }
}
Пример #12
0
void LabelItem::updateDataRelativeRect( bool force) {
  CartesianRenderItem* plot = dynamic_cast<CartesianRenderItem*>(parentViewItem());
  if (plot) {
    if ((!lockPosToData()) || force || (!_dataRelativeDimValid)) {
      _dataRelativeDimValid = ((fabs(rect().width())>1.1) && (fabs(rect().height())>1.1));
      QPointF P1 = rect().bottomLeft();
      QPointF P2 = rect().bottomRight();
      _dataRelativeRect.setTopLeft(plot->plotItem()->mapToProjection(mapToParent(P1)));
      _dataRelativeRect.setBottomRight(plot->plotItem()->mapToProjection(mapToParent(P2)));
    }
  }
}
Пример #13
0
void GraphicsLineItem::updateTextItem()
{
    textItem->setText(QString());
    if (xSpacing < 0 || ySpacing < 0) return;

    QPointF p1 = mapToParent(crossItem1->pos());
    QPointF p2 = mapToParent(crossItem2->pos());
    double deltaX = (p1.x() - p2.x()) * xSpacing;
    double deltaY = (p1.y() - p2.y()) * ySpacing;

    textItem->setText(QObject::tr("%1 mm").arg(sqrt(deltaX*deltaX + deltaY*deltaY), 0, 'f', 2));
}
Пример #14
0
/**
	Traduit en coordonnees de l'item parent un mouvement / vecteur initialement
	exprime en coordonnees locales.
	@param movement Vecteur exprime en coordonnees locales
	@return le meme vecteur, exprime en coordonnees du parent
*/
QPointF DiagramTextItem::mapMovementToParent(const QPointF &movement) const {
	// on definit deux points en coordonnees locales
	QPointF local_origin(0.0, 0.0);
	QPointF local_movement_point(movement);
	
	// on les mappe sur la scene
	QPointF parent_origin(mapToParent(local_origin));
	QPointF parent_movement_point(mapToParent(local_movement_point));
	
	// on calcule le vecteur represente par ces deux points
	return(parent_movement_point - parent_origin);
}
Пример #15
0
void Item::advance(int phase)
{
    if(!phase) return;

    QPointF location = this->pos();
    setPos(mapToParent(0,-(speed)));
}
Пример #16
0
MyItem::MyItem()
{
    // random start rotation
    angle = (qrand() % 360);  //qrand() is equalize to srand on C++
    setRotation(angle);  //设置旋转角度

    // set the speed
    speed = 5;  // 5 pixels

    // random start position
    int startX = 0;
    int startY = 0;

    //set initial position
    if(qrand() % 1)
    {
        startX = qrand() % 200;
        startY = qrand() % 200;
    }
    else
    {
        startX = qrand() % -100;
        startY = qrand() % -100;
    }
    //mapToParent means map the point position to parent coordinate
    setPos(mapToParent(startX, startY)); //Sets the position of the item to pos
}
Пример #17
0
WidgetList * WidgetList::clone(){
	WidgetList * list = WidgetList::createNiceList(parent());
	list->setStyle(style());
	list->setLocation(mapToParent(Nimble::Vector2(0, 0)));
	
	for (ItemList::iterator it = m_itemList.begin(); it != m_itemList.end(); ++it ) {
		RoundTextBox * tb = dynamic_cast<RoundTextBox*>(*it);
		RoundTextBox * tb2 = new RoundTextBox(0, 0, MultiWidgets::TextBox::HCENTER);
		tb2->setCSSClass("FloatingWord_clone");
		tb2->setStyle(tb->style());
		tb2->setText(tb->text());
		tb2->setWidth(tb->width());
		tb2->setHeight(tb->height());
		tb2->setAlignFlags(MultiWidgets::TextBox::HCENTER | MultiWidgets::TextBox::VCENTER);
		list->addItem(tb2);
	}

	//layout();
	list->layout();
	list->setDepth(depth());
	list->setScale(scale());
	list->setRotation(rotation());

	return list;	
}
Пример #18
0
void SCgVisualObject::_update(UpdateEventType eventType, SCgObject *object)
{
    switch (eventType)
    {
    case PositionChanged:
    {
        setPos(mapToParent(mapFromScene(object->position())));
        break;
    }
    case IdentifierChanged:
    {
        if (mTextItem == 0)
        {
            QFont font("Times New Roman [Arial]", 10, 10, false);
            font.setBold(true);
            font.setItalic(true);

            mTextItem = new QGraphicsTextItem(this);
            mTextItem->setFont(font);
        }

        mTextItem->setPlainText(object->identifier());
        break;
    }
    case ParentChanged:
    {
        //! \todo implement
        break;
    }
    }

    update();
}
Пример #19
0
void CSideBarUpDown::mousePressEvent(QMouseEvent *e)
{
    m_iPressedPositionY = m_iPositionY;
    m_bMouseDown = true;
    m_pointPressed = e->pos();
    m_pointParentPressed = mapToParent(m_pointPressed);
}
Пример #20
0
MyItem::MyItem()
{
    // Random start rotation
    angle = (qrand() % 360);
    setRotation(angle);

    // set the speed
    speed = 5;

    // Random start position
    int startX = 0;
    int startY = 0;

    if((qrand() % 1))
    {
        startX = (qrand() % 200);
        startX = (qrand() % 200);
    }
    else
    {
        startX = (qrand() % -100);
        startX = (qrand() % -100);
    }
    setPos(mapToParent(startX,startY));
}
Пример #21
0
void BezierControlPoint::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
    if (event->buttons() == Qt::LeftButton) {
        setPos(mapToParent(event->pos()));
        m_parent->controlPointMoved(m_index);
    }
}
Пример #22
0
void TitleShell::mousePressEvent(QMouseEvent *me)
{
    startPos = me->globalPos();
    clickPos = mapToParent(me->pos());
    m_titleBarPress = true;

}
Пример #23
0
void VCWidget::resize(QPoint p)
{
	// Grid settings
	if (_app->virtualConsole()->isGridEnabled())
	{
		p.setX(p.x() - (p.x() % _app->virtualConsole()->gridX()));
		p.setY(p.y() - (p.y() % _app->virtualConsole()->gridY()));
	}

	// Map to parent coordinates so that they can be compared
	p = mapToParent(p);

	// Don't move beyond left or right
	if (p.x() < 0)
		p.setX(0);
	else if (p.x() > parentWidget()->width())
		p.setX(parentWidget()->width());

	// Don't move beyond top or bottom
	if (p.y() < 0)
		p.setY(0);
	else if (p.y() > parentWidget()->height())
		p.setY(parentWidget()->height());

	// Map back so that this can be resized
	p = mapFromParent(p);

	// Do the resize
	QFrame::resize(p.x(), p.y());
}
Пример #24
0
void InDockW::resizeEvent(QResizeEvent *)
{
	if (w)
	{
		int mappedY = mapToParent(QPoint()).y();
		int Y = 0;
		int W = width();
		int H = height() + loseHeight;
		if (mappedY < 0)
		{
			H += mappedY;
			Y -= mappedY;
		}
		if (loseHeight && w->property("PreventFullscreen").toBool())
		{
			Y -= 1;
			H += 2;
		}
		if (w->geometry() != QRect(0, Y, W, H))
		{
			w->setGeometry(0, Y, W, H);
			emit resized(W, H);
		}
	}
}
Пример #25
0
void VideoFrame::mousePressEvent(QMouseEvent *AEvent)
{
	if (AEvent->button() == Qt::LeftButton)
	{
		FPressedPos = AEvent->pos();
		FGlobalPressed = AEvent->globalPos();
		if (!FCollapsed)
		{
			if (FMoveEnabled && FCursorCorner<0)
			{
				FPressedPos = mapToParent(AEvent->pos()) - geometry().topLeft();
				setCursor(Qt::ClosedHandCursor);
			}
			else if (!FResizeEnabled || FCursorCorner<0)
			{
				QFrame::mousePressEvent(AEvent);
			}
		}
		else
		{
			QFrame::mousePressEvent(AEvent);
		}
		FClicked = FDoubleClickTime.msecsTo(QDateTime::currentDateTime())>qApp->doubleClickInterval();
	}
	else
	{
		QFrame::mousePressEvent(AEvent);
	}
}
Пример #26
0
void PreviewLabel::mousePressEvent(QMouseEvent * event)
{
    if (!m_borderImage)
        return QLabel::mouseMoveEvent(event);

    bool bottom = false;

    if (event->button() == Qt::LeftButton) {
        if (QApplication::overrideCursor())
            QApplication::restoreOverrideCursor();
        if (rangeCheck(m_left * m_zoom, event->pos().x())) {
            QApplication::setOverrideCursor(QCursor(Qt::SizeHorCursor));
            m_dragging_left = true;
            event->accept();
            m_hooverInfo->setText("Left " + QString::number(m_left));
            m_hooverInfo->show();
        } else if (rangeCheck(m_top * m_zoom, event->pos().y())) {
            QApplication::setOverrideCursor(QCursor(Qt::SizeVerCursor));
            m_dragging_top = true;
            event->accept();
            m_hooverInfo->setText("Top " + QString::number(m_top));
            m_hooverInfo->show();
        } else if (rangeCheck(m_right * m_zoom, width() - event->pos().x())) {
            QApplication::setOverrideCursor(QCursor(Qt::SizeHorCursor));
            m_dragging_right = true;
            event->accept();
            m_hooverInfo->setText("Right " + QString::number(m_right));
            m_hooverInfo->show();
        } else if (rangeCheck(m_bottom * m_zoom, height() - event->pos().y())) {
            QApplication::setOverrideCursor(QCursor(Qt::SizeVerCursor));
            m_dragging_bottom = true;
            event->accept();
            m_hooverInfo->setText("Bottom " + QString::number(m_bottom));
            m_hooverInfo->show();
            bottom = true;
        } else {
            QLabel::mousePressEvent(event);
        }
        m_startPos = event->pos();
        if (bottom)
            m_hooverInfo->move(mapToParent(m_startPos) + QPoint(0, -10));
        else
            m_hooverInfo->move(mapToParent(m_startPos) + QPoint(0, 40));
        m_hooverInfo->resize(m_hooverInfo->sizeHint());
        m_hooverInfo->raise();
    }
}
void MovableWidget::mouseMoveEvent(QMouseEvent *event)
{
    if(event->buttons() & Qt::LeftButton)
    {
        this->move(mapToParent(event->pos() - offset));
        event->accept();
    }
}
Пример #28
0
void DraggableElement::mouseMoveEvent(QMouseEvent *event)
{
    if(event->buttons() & Qt::LeftButton)
    {
        move(mapToParent(event->pos() - _offset));
        rearrangeLowerElems();
        if(!isVisible()) show();
    }
}
Пример #29
0
item_ball_l::item_ball_l()
{
    QPixmap pix(":/ball_l.png");
    //this->
    speed = 5;
    int startx = 800;
    int starty = 0;
    setPos(mapToParent(startx,starty));
}
Пример #30
0
void PanelAppletOverlay::mousePressEvent(QMouseEvent *event)
{
    m_lastGlobalPos = event->globalPos();
    //kDebug() << m_clickDrag;
    if (m_clickDrag) {
        setMouseTracking(false);
        m_clickDrag = false;
        m_origin = QPoint();
        return;
    }

    if (!m_applet || event->button() != Qt::LeftButton) {
        return;
    }

    m_clickDrag = false;
    if (!m_spacer) {
        m_spacer = new AppletMoveSpacer(m_applet);
    } else if (m_layout) {
        m_layout->removeItem(m_spacer);
    }

    m_origin = mapToParent(event->pos());
    m_spacer->setMinimumSize(m_applet->geometry().size());
    m_spacer->setMaximumSize(m_applet->geometry().size());
    if (m_layout) {
        m_layout->removeItem(m_applet);
        m_layout->insertItem(m_index, m_spacer);
    }
    m_applet->raise();

    if (m_orientation == Qt::Horizontal) {
        m_offset = geometry().x() - m_origin.x();
    } else {
        m_offset = geometry().y() - m_origin.y();
    }

    m_dragAction = Move;

    const int margin = 9;
    if (m_applet->inherits("PanelSpacer")) {
        if (m_applet->formFactor() == Plasma::Horizontal) {
            if (event->pos().x() < margin) {
                m_dragAction = LeftResize;
            } else if (event->pos().x() > m_applet->size().width() - margin) {
                m_dragAction = RightResize;
            }
        } else if (m_applet->formFactor() == Plasma::Vertical) {
            if (event->pos().y() < margin) {
                m_dragAction = LeftResize;
            } else if (event->pos().y() > m_applet->size().height() - margin) {
                m_dragAction = RightResize;
            }
        }
    }
}