Ejemplo n.º 1
0
EnemyShip::EnemyShip()
{
    QGraphicsItem *spaceshipTail = new EnemyShipTail(this);
    QGraphicsItem *oneWing = new EnemyShipWing1(this);
    QGraphicsItem *secondWing = new EnemyShipWing2(this);
    QGraphicsItem *spaceshipBody = new EnemyShipBody(this);
    QGraphicsItem *spaceshipWindow = new EnemyShipWindow(this);

    spaceshipTail->setPos(602, 293);
    oneWing->setPos(565, 310);
    secondWing->setPos(623, 310);
    spaceshipBody->setPos(600, 300);
    spaceshipWindow->setPos(607, 332);

    timeline = new QTimeLine;

    QGraphicsItemAnimation *tailAnim = new QGraphicsItemAnimation;
    tailAnim->setItem(spaceshipTail);
    tailAnim->setTimeLine(timeline);
    tailAnim->setTranslationAt(0, 20, 0);
    tailAnim->setTranslationAt(1, -20, 0);

    QGraphicsItemAnimation *oneWingAnim = new QGraphicsItemAnimation;
    oneWingAnim->setItem(oneWing);
    oneWingAnim->setTimeLine(timeline);
    oneWingAnim->setTranslationAt(0, 20, 0);
    oneWingAnim->setTranslationAt(1, -20, 0);

    QGraphicsItemAnimation *secondWingAnim = new QGraphicsItemAnimation;
    secondWingAnim->setItem(secondWing);
    secondWingAnim->setTimeLine(timeline);
    secondWingAnim->setTranslationAt(0, 20, 0);
    secondWingAnim->setTranslationAt(1, -20, 0);

    QGraphicsItemAnimation *bodyAnim = new QGraphicsItemAnimation;
    bodyAnim->setItem(spaceshipBody);
    bodyAnim->setTimeLine(timeline);
    bodyAnim->setTranslationAt(0, 20, 0);
    bodyAnim->setTranslationAt(1, -20, 0);

    QGraphicsItemAnimation *windowAnim = new QGraphicsItemAnimation;
    windowAnim->setItem(spaceshipWindow);
    windowAnim->setTimeLine(timeline);
    windowAnim->setTranslationAt(0, 20, 0);
    windowAnim->setTranslationAt(1, -20, 0);

    timeline->setUpdateInterval(1000/25);
    timeline->setCurveShape(QTimeLine::SineCurve);
    timeline->setLoopCount(0);
    timeline->setDuration(2000);
    timeline->start();

}
Ejemplo n.º 2
0
// draw text
void ScenePainter::drawText(const char * const *strs, double *x, double *y,
                            int n, Qt::Alignment flags, double rot, double hcex,
                            double vcex)
{
  if (indexMode()) {
    QVector<QRectF> rects = textExtents(strs, n, flags);
    for (int i = 0; i < n; i++) {
      QString qstr = QString::fromLocal8Bit(strs[i]);
      QPointF center = rects[i].center();
      double xi = x[i] + center.x();
      double yi = y[i] + center.y();
      drawPoints(&xi, &yi, 1);
    }
    return;
  }
  // FIXME: alignment is ignored -- translate to HTML?
  QTransform posTform = transform();
  QTransform textTform;
  textTform.rotate(-rot);
  textTform.scale(hcex, vcex);
  for (int i = 0; i < n; i++) {
    QString qstr = QString::fromLocal8Bit(strs[i]);
    QGraphicsItem *item = STORE_INDEX(_scene->addText(qstr, _scene->font()));
    item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    item->setPos(posTform.map(QPointF(x[i], y[i])));
    item->setTransform(textTform);
  }
}
Ejemplo n.º 3
0
void MainWindow::populateScene()
{
    scene = new QGraphicsScene;

    QImage image(":/qt4logo.png");

    // Populate scene
    int xx = 0;
    int nitems = 0;
    for (int i = -11000; i < 11000; i += 110) {
        ++xx;
        int yy = 0;
        for (int j = -7000; j < 7000; j += 70) {
            ++yy;
            qreal x = (i + 11000) / 22000.0;
            qreal y = (j + 7000) / 14000.0;

            QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
            QGraphicsItem *item = new Chip(color, xx, yy);
            item->setPos(QPointF(i, j));
            scene->addItem(item);

            ++nitems;
        }
    }
}
Ejemplo n.º 4
0
void QGraphicsWebViewPrivate::updateCompositingScrollPosition()
{
    if (rootGraphicsLayer && q->page() && q->page()->mainFrame()) {
        const QPoint scrollPosition = q->page()->mainFrame()->scrollPosition();
        rootGraphicsLayer->setPos(-scrollPosition);
    }
}
void BandWidgetTestWidget::addNewPoint()
{
    SettingArgument &argument = SettingArgument::Setting();
    qreal upRange = argument.getBWUpRange();
    qreal lowRange = argument.getBWLowRange();
    int testTimes = argument.getBWTestTimes();

    qreal px = (ui->graphicsView->width()-90)/(testTimes-1);
    qreal py  = (value-lowRange)*(ui->graphicsView->height()-40)/(upRange-lowRange);
    QGraphicsItem *item = scene->addEllipse(-5, -5, 10, 10, QPen(), QBrush(QColor(Qt::blue)));
    item->setPos(px*(count), -py);
    item->setGroup(group);
    pointArray[count] = item;

    //两点之间使用直线连接
    if (count != 0 &&  pointArray[count-1] != NULL) {
        QGraphicsItem *line;
        QPointF point1 = pointArray[count-1]->pos();
        QPointF point2 = pointArray[count]->pos();
        QPen pen(Qt::blue);
        pen.setWidth(3);
        line = scene->addLine(point1.x(), point1.y(), point2.x(), point2.y(), pen);
        line->setGroup(group);
    }
}
void DataPlot::addPointSeries(QList<QPointF*>* v,QString series_name, QColor color, bool progressive_show){
    if(!available_class_colors.contains(color)&&available_class_colors.size()>0)
        color = available_class_colors.at(0);

    available_class_colors.removeOne(color);

    if(!progressive_show){
        for(int i=0;i<v->length();i++)
            paintPoint(i,color,v);
    }
    else{
        incomplete_series.append(v);
        incomplete_series_colors.append(color);
        incomplete_series_isPointSeries.append(true);

        if(current_progressive_show_ind>=0)
            for(int i=0;i<=current_progressive_show_ind && i<v->size();i++)
                paintPoint(i,color,v);
    }


    QGraphicsTextItem *t_item = scene->addText(series_name);
    t_item->setPos(initial_width+40,(initial_height/2)-(40-class_labels_offset));
    QGraphicsItem* item = scene->addEllipse(0,0,3,3,QPen(color),QBrush(color));
    item->setPos(initial_width+35,(initial_height/2)-(30-class_labels_offset));

    class_labels_offset+=15;
}
Ejemplo n.º 7
0
/**
 * @brief MapView::blitTile
 * @param i
 * @param j
 * @param bl
 * @param layer
 * @param opacity
 */
void MapView::blitTile(int i, int j, int bl, int layer, float opacity)
{
    QPixmap tile = chipset.copy((bl%(chipset.width()/BLOCSIZE))*BLOCSIZE,(bl/(chipset.width()/BLOCSIZE))*BLOCSIZE,BLOCSIZE,BLOCSIZE);
    QGraphicsItem * item = this->addPixmap(tile);
    item->setZValue(layer);
    item->setOpacity(opacity);
    item->setPos(i*BLOCSIZE,j*BLOCSIZE);
}
Ejemplo n.º 8
0
void ScenePainter::drawCircle(double x, double y, int r) {
  QRectF rect;
  if (indexMode()) {
    float minFloat = std::numeric_limits<float>::min();
    rect = QRectF(0, 0, minFloat, minFloat);
  } else rect = QRectF(-r, -r, 2*r, 2*r);
  QGraphicsItem *item = STORE_INDEX(_scene->addEllipse(rect, pen(), brush()));
  item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
  item->setPos(transform().map(QPointF(x, y)));
}
Ejemplo n.º 9
0
void IdentityItem::updateItem( const Polka::Identity &identity )
{
  m_identity = identity;

  foreach( QGraphicsItem *child, childItems() ) {
    delete child;
  }

  if ( identity.type() == "group" ) {
    int circleSize = m_itemSize + 14;
    QGraphicsEllipseItem *groupCircle = new QGraphicsEllipseItem( this );
    groupCircle->setRect( -circleSize/2, -circleSize/2,
      circleSize, circleSize );
    QPen pen;
    pen.setBrush( Qt::white );
    pen.setWidth( 4 );
    groupCircle->setPen( pen );
  }

  QPixmap pixmap = m_model->pixmap( identity );

  QGraphicsItem *item = new QGraphicsPixmapItem( pixmap, this );
  item->setPos( -pixmap.width() / 2, -pixmap.height() / 2 );

  QGraphicsTextItem *textItem = new QGraphicsTextItem( identity.name().value() );

  int textWidth = textItem->boundingRect().width();
  int textHeight = textItem->boundingRect().height();

  m_nameItem = new RoundedRectItem( this );
  m_nameItem->setRect( 0, 0, textWidth, textHeight );
  m_nameItem->setBrush( QColor( 255,255,230 ) );
  m_nameItem->setZValue( 10 );

  textItem->setParentItem( m_nameItem );

  m_nameItem->setPos( - textWidth / 2, 30 );

  m_fanMenu = new FanMenu( this );
  m_fanMenu->setZValue( 50 );

  FanMenuItem *menuItem = m_fanMenu->addItem( i18n("Remove") );
  connect( menuItem, SIGNAL( clicked() ), SLOT( emitRemoveIdentity() ) );
  m_checkMenuItem = m_fanMenu->addItem( i18n("Check") );
  connect( m_checkMenuItem, SIGNAL( clicked() ), SLOT( checkItem() ) );
  if ( identity.type() == "group" ) {
    menuItem = m_fanMenu->addItem( i18n("Go to") );
  } else {
    menuItem = m_fanMenu->addItem( i18n("Show") );
  }
  connect( menuItem, SIGNAL( clicked() ), SLOT( emitShowIdentity() ) );
  m_fanMenu->setupItems();

  hidePopups();
}
Ejemplo n.º 10
0
void HomeScreen::initSprite()
{
	_sprite = new QGraphicsWidget();

	QGraphicsItem* item;
	QGraphicsSimpleTextItem* text;
	QGraphicsProxyWidget* proxy;
	QLabel* label;
	QFont font;

	item = new QGraphicsPixmapItem();
	item->setParentItem(_sprite);
	item->setPos((BACKGROUND_W - (400.0f / 0.75f)) * 0.5f, BACKGROUND_H - 400.0f);
	_avatar = static_cast<QGraphicsPixmapItem*>(item);

	item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_TITLE));
	item->setParentItem(_sprite);
	item->setPos(232.0f, 128.0f);

	font = QFont("Arial");
	font.setPixelSize(12);
	font.setWeight(QFont::Normal);
	font.setStretch(80);

	text = new QGraphicsSimpleTextItem("http://conanchen.com/Kinetris");
	text->setBrush(QColor::fromRgb(0xFF, 0xFF, 0xFF));
	text->setFont(font);
	text->setParentItem(_sprite);
	text->setPos(248.0f, 264.0f - 3.0f);

	label = new QLabel();
	label->resize(784, 24);
	label->setStyleSheet("background-color: transparent; color: #FFFFFF;");
	label->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
	proxy = new QGraphicsProxyWidget();
	proxy->setParentItem(_sprite);
	proxy->setWidget(label);
	proxy->setPos(248.0f, 592.0f - 6.0f);
	_sprite_status = proxy;
	_status = label;
}
Ejemplo n.º 11
0
// Converts the value into an percentage:
// this enables smooth movement in moveIndex below
void TelemetryMonitorWidget::showTelemetry()
{
    txIndex = (txValue-minValue)/(maxValue-minValue) * NODE_NUMELEM;
    rxIndex = (rxValue-minValue)/(maxValue-minValue) * NODE_NUMELEM;

    if (connected)
        this->setToolTip(QString("Tx: %0 bytes/sec\nRx: %1 bytes/sec").arg(txValue).arg(rxValue));
    else
        this->setToolTip(QString("Disconnected"));

    int i;
    int nodeMargin = 8;
    int leftMargin = 60;
    QGraphicsItem* node;

    for (i=0; i < txNodes.count(); i++) {
        node = txNodes.at(i);
        node->setPos((i*(node->boundingRect().width() + nodeMargin)) + leftMargin, (node->boundingRect().height()/2) - 2);
        node->setVisible(connected && i < txIndex);
        node->update();
    }

    for (i=0; i < rxNodes.count(); i++) {
        node = rxNodes.at(i);
        node->setPos((i*(node->boundingRect().width() + nodeMargin)) + leftMargin, (node->boundingRect().height()*2) - 2);
        node->setVisible(connected && i < rxIndex);
        node->update();
    }

    QRectF rect = graph->boundingRect();
    txSpeed->setPos(rect.right() - 110, rect.top());
    txSpeed->setPlainText(QString("%0").arg(txValue));
    txSpeed->setVisible(connected);

    rxSpeed->setPos(rect.right() - 110, rect.top() + (rect.height() / 2));
    rxSpeed->setPlainText(QString("%0").arg(rxValue));
    rxSpeed->setVisible(connected);

    update();
}
Ejemplo n.º 12
0
// draw points (pixels)
void ScenePainter::drawPoints(double *x, double *y, int n) {
  QTransform tform = transform();
  QPen pen = this->pen();
  // seems that 0-size items are ignored, so we use min size
  float minFloat = std::numeric_limits<float>::min();
  QSizeF size = indexMode() ? QSizeF(minFloat, minFloat) : QSizeF(1, 1);
  for (int i = 0; i < n; i++) {
    QRectF rect = QRectF(QPointF(0, 0), size);
    QGraphicsItem *item = STORE_INDEX(_scene->addRect(rect, pen));
    item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    item->setPos(tform.map(QPointF(x[i], y[i])));
  }
}
Ejemplo n.º 13
0
void ObjectsScene::addObject(int id, const Object& obj)
{
    const XY& p = obj.pos();
    const QPointF position(p.x, p.y);

    BaseType radius = obj.radius();

    QGraphicsItem* item = createItem(radius);
    item->setPos(position);
    item->setData(ObjectData::Id, id);
    item->setData(ObjectData::Radius, radius);

    m_objects.insert( std::make_pair(id, item) );
}
void DataPlot::paintPoint(int i, QColor color, QList<QPointF*>*v){
    QPointF original = *v->at(i);
    qreal size = calcDotSize(v->size());

    QGraphicsItem* item = scene->addEllipse(0,0,size,size,QPen(color),QBrush(color));

    qreal x = (v->at(v->length()-1)->x())!=0 ? original.x()/(v->at(v->length()-1)->x()) : 0;
    x*=plot_width;
    x+=x_offset;
    qreal y = 1 - original.y();
    y*=(plot_height-y_offset);
    y+=y_offset;
    QPointF ccords(x-size/2,y-size/2);

    item->setPos(ccords);
}
Ejemplo n.º 15
0
void NewItemInteractor::mousePressEvent ( QMouseEvent * event ) {
    if (event->button() != Qt::LeftButton) {
        return;
    }

    QPointF scenePos = theView->mapToScene(event->pos());

    QGraphicsItem* newItem = itemFactory();
    newItem->setPos(scenePos);
    theView->scene()->clearSelection();
    theItem = dynamic_cast<InteractableItem*>(newItem);
    theView->scene()->addItem(newItem);
    theItem->setItemSelected(true);
    // theFrame->setZValue(theScene->zOrder++);
    offset = QPointF(0,0);
}
Ejemplo n.º 16
0
/**
 * A layer has changed. This can mean that the layer visibility, opacity or
 * offset changed.
 */
void MapItem::layerChanged(Layer *layer)
{
    Preferences *prefs = Preferences::instance();
    QGraphicsItem *layerItem = mLayerItems.value(layer);
    Q_ASSERT(layerItem);

    layerItem->setVisible(layer->isVisible());

    qreal multiplier = 1;
    if (prefs->highlightCurrentLayer() && isAbove(mapDocument()->currentLayer(), layer))
        multiplier = opacityFactor;

    layerItem->setOpacity(layer->opacity() * multiplier);
    layerItem->setPos(layer->offset());

    updateBoundingRect();   // possible layer offset change
}
Ejemplo n.º 17
0
void ObjectsScene::updateRadius(int id, BaseType r)
{
    auto obj = m_objects.find(id);
    assert(obj != m_objects.end());

    QGraphicsItem* item = createItem(r);
    item->setData(ObjectData::Id, id);
    item->setData(ObjectData::Radius, r);

    const QPointF pos = obj->second->pos();
    item->setPos(pos);

    // swap items
    removeItem(obj->second);
    delete obj->second;
    obj->second = item;
}
Ejemplo n.º 18
0
void MainWindow::evolveNext()
{
    int state = CS_UNKNOWN;
    QVector<QPoint> add_cells;
    QVector<QPoint> dead_cells;
    int x,y, tx, ty;
    QGraphicsItem *item = NULL;

    for (int x = 0; x < this->gcnt; ++x) {
        for (int y = 0; y < this->gcnt; ++y) {
            state = this->calcCellState(x, y);
            qLogx()<<x<<y<<this->cellStateToString(state);
            if (state == CS_ADD) {
                add_cells.append(QPoint(x, y));
            } else if (state == CS_DEAD) {
                dead_cells.append(QPoint(x, y));
            }
        }
    }

    for (int i = 0; i < add_cells.count(); ++i) {
        x = add_cells.at(i).x();
        y = add_cells.at(i).y();
        tx = x * this->glen;
        ty = y * this->glen;
        // item = this->gs->addPixmap(this->dotpm);
        item = this->takeCachedItem();
        item->setPos(tx, ty);
        this->gs->addItem(item);
    }

    for (int i = 0; i < dead_cells.count(); ++i) {
        x = dead_cells.at(i).x();
        y = dead_cells.at(i).y();
        tx = x * this->glen;
        ty = y * this->glen;
        item = this->gs->itemAt(tx, ty);
        Q_ASSERT(item != NULL);
        this->gcCachedItem(item);
        this->gs->removeItem(item);
        // delete item;
    }

    // this->stopEvolve();
}
Ejemplo n.º 19
0
void SchemeView::dropEvent(QDropEvent* Event)
{
	if (QListWidget* Object = qobject_cast<QListWidget*>(Event->source()))
	{
		QGraphicsItem* Item = new SchemeItem(static_cast<ItemTemplate::TYPE>(Object->currentItem()->data(Qt::UserRole).toUInt()));

		Item->setPos(mapToScene(Event->pos()));

		scene()->addItem(Item);
	}

	if (scene()->items().size() == 2)
	{

	}

	QGraphicsView::dropEvent(Event);
}
Ejemplo n.º 20
0
/**
 * A layer has changed. This can mean that the layer visibility, opacity or
 * offset changed.
 */
void MapScene::layerChanged(int index)
{
    const Layer *layer = mMapDocument->map()->layerAt(index);
    QGraphicsItem *layerItem = mLayerItems.at(index);

    layerItem->setVisible(layer->isVisible());

    qreal multiplier = 1;
    if (mHighlightCurrentLayer && mMapDocument->currentLayerIndex() < index)
        multiplier = opacityFactor;

    layerItem->setOpacity(layer->opacity() * multiplier);
    layerItem->setPos(layer->offset());

    // Layer offset may have changed, affecting the scene rect and grid
    updateSceneRect();
    if (mGridVisible)
        update();
}
Ejemplo n.º 21
0
// drawing glyphs (same path, many places)    
void ScenePainter::drawGlyphs(const QPainterPath &path, double *x, double *y,
                              double *size, QColor *stroke, QColor *fill, int n)
{
  if (indexMode()) {
    drawPoints(x, y, n);
  } else if (!rasterize()) { 
    QTransform tform = transform();
    double curSize = glyphSize();
    for (int i = 0; i < n; i++) {
      if (stroke) setStrokeColor(stroke[i]);
      if (fill) setFillColor(fill[i]);
      QGraphicsItem *item = STORE_INDEX(_scene->addPath(path, pen(), brush()));
      item->setPos(tform.map(QPointF(x[i], y[i])));
      item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
      if (size) curSize = size[i];
      item->scale(curSize, curSize);
    }
  } else QtBasePainter::drawGlyphs(path, x, y, size, stroke, fill, n);
}
Ejemplo n.º 22
0
void BlurPicker::setIndex(qreal index)
{
    m_index = index;

    qreal baseline = 0;
    for (int i = 0; i < m_icons.count(); ++i) {
        QGraphicsItem *icon = m_icons[i];
        qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count();
        qreal xs = 170 * sin(a);
        qreal ys = 100 * cos(a);
        QPointF pos(xs, ys);
        pos = QTransform().rotate(-20).map(pos);
        pos -= QPointF(40, 40);
        icon->setPos(pos);
        baseline = qMax(baseline, ys);
        static_cast<BlurEffect *>(icon->graphicsEffect())->setBaseLine(baseline);
    }

    scene()->update();
}
Ejemplo n.º 23
0
// image
void ScenePainter::drawImage(const QImage &image, double x, double y,
                             int sx, int sy, int sw, int sh)
{
  if (indexMode()) {
    x = (sw < 0 ? image.width() : sw) / 2.0;
    y = (sh < 0 ? image.height() : sh) / 2.0;
    drawPoints(&x, &y, 1);
    return;
  }
  QImage subImage;
  if (sw >= 0 || sh >= 0 || sx > 0 || sy > 0) {
    sw = sw < 0 ? image.width() : sw;
    sh = sh < 0 ? image.height() : sh;
    subImage = image.copy(sx, sy, sw, sh);
  } else subImage = image;
  QPixmap pixmap = QPixmap::fromImage(subImage);
  QGraphicsItem *item = STORE_INDEX(_scene->addPixmap(pixmap));
  item->setPos(transform().map(QPointF(x, y)));
  item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
}
Ejemplo n.º 24
0
//---------------------------------------------------------------------------
void CRenderWidget::mouseMoveEvent(QMouseEvent *event)
{
    if (mIsLeftMouseDown && mSelectedItems.size() > 0)
    {
        // Lookup the entity
        CEntity* entity = Globals::getCurrentScene()->getEntityFromGraphicsView(mSelectedItems.first());

        if (!entity)
        {
            QMessageBox::critical(this, "Erreur!", "Impossible de retrouver l'entité attachée au graphique sélectionné!");
            return;
        }

        QPoint delta = event->pos() - mMouseDownPosition;

        if (mDoCopySelection)
        {
            // Hep, stop right there! We want to duplicate the selection, and switch our current pick to the copied
            // entity, and move it.
            entity = Globals::getCurrentScene()->cloneEntity(entity);
            selectEntity(entity->getSceneItem());

            mDoCopySelection = false;
        }

        // Move the entity
        QPoint gridDelta = delta;//QPoint(ceil(delta.x() / 16.f) * 16.f, ceil(delta.y() / 16.f) * 16.f);
        Vector2D finalPos = mOriginalPosition + Vector2D(gridDelta.x(), gridDelta.y());

        entity->setPosition(finalPos);

        emit itemChanged();

        // Move selection rects
        for (QList<QGraphicsItem*>::iterator it = mSelectionRects.begin(); it != mSelectionRects.end(); ++it)
        {
            QGraphicsItem* rect = (*it);
            rect->setPos(gridDelta);
        }
    }
}
Ejemplo n.º 25
0
void CSharedPainterScene::updateItem( boost::shared_ptr<CPaintItem> item )
{
	if( ! item )
		return;

	if( ! item->drawingObject() )
		return;

	clearLastItemBorderRect();

	QGraphicsItem* i = reinterpret_cast<QGraphicsItem *>(item->drawingObject());

	if( item->isScalable() )
	{
		if( item->type() == PT_IMAGE_FILE )
			setScaleImageFileItem( boost::static_pointer_cast<CImageFileItem>(item), (QGraphicsPixmapItem *)i );
		else
			i->setScale( item->scale() );
	}
	i->setPos( item->posX(), item->posY() );
}
Ejemplo n.º 26
0
void CSharedPainterScene::moveItem( boost::shared_ptr<CPaintItem> item, double x, double y  )
{
	if( ! item )
		return;

	if( ! item->drawingObject() )
		return;

	clearLastItemBorderRect();

	QGraphicsItem* i = reinterpret_cast<QGraphicsItem *>(item->drawingObject());

	// freeze move changes notify
	i->setFlag( QGraphicsItem::ItemSendsGeometryChanges, false );

	i->setPos( x, y );
	
	// thaw move changes notify
	i->setFlag( QGraphicsItem::ItemSendsGeometryChanges, true );
	invalidate( i->boundingRect() );
}
Ejemplo n.º 27
0
Interface::Interface(unsigned int _cellSizeX, unsigned int _cellSizeY,
                     unsigned int _cellCountX, unsigned int _cellCountY,
                     QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Interface),
    cellSizeX(_cellSizeX), cellSizeY(_cellSizeY), cellCountX(_cellCountX), cellCountY(_cellCountY)
{
    QUiLoader loader;
    QFile file("Graphics/interface.ui");
    file.open(QFile::ReadOnly);
    QWidget *formWidget = loader.load(&file, this);
    file.close();
    QVBoxLayout* firstLayer = formWidget->findChild<QVBoxLayout*>("FirstLayer");
    timeTree = new CustomView;

    firstLayer->addWidget(timeTree);
    QVBoxLayout* gameFieldLayout = firstLayer->findChild<QVBoxLayout*>("gameFieldLayout");
    gameField = new CustomView;
    gameFieldLayout->addWidget(gameField);

    ui->setupUi(formWidget);
    QGraphicsItem *item = new Grid(QColor(Qt::red), cellSizeX, cellSizeY, cellCountX, cellCountY);
    item->setPos(QPointF(0, 0));
    gameFieldScene.addItem(item);
    m_field = new GraphicsCell**[cellCountX];
    for(unsigned int i=0;i<cellCountX;++i){
        m_field[i] = new GraphicsCell*[cellCountY];
        for(unsigned int j=0;j<cellCountY;++j){
            m_field[i][j] = new GraphicsCell((i+j)%2==0);
            m_field[i][j]->setPos(i*GraphicsCell::getCellSizeX()+i+0.5, j*GraphicsCell::getCellSizeY()+j+0.5);
            gameFieldScene.addItem(m_field[i][j]);
        }
    }
    gameField->setScene(&gameFieldScene);
    gameField->setDragMode(QGraphicsView::RubberBandDrag);
    //gameField->setDragMode(QGraphicsView::ScrollHandDrag);
    gameField->setInteractive(true);
    gameField->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    gameField->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
}
Ejemplo n.º 28
0
void Scene::dropEvent(QGraphicsSceneDragDropEvent* event)
{
  //qDebug() << "DragNDrop Drop";
  if (event->mimeData()->hasFormat("application/x-chestnutpaletteitem")) {
    QByteArray encodedData = event->mimeData()->data("application/x-chestnutpaletteitem");
    QDataStream stream(&encodedData, QIODevice::ReadOnly);
    QStringList newItems;

    while (!stream.atEnd()) {
        QString text;
        stream >> text;
        newItems << text;
    }
    QString droppedItem = newItems.first();
    
    
    QGraphicsItem *newItem = 0;
    
    // Data
    if (droppedItem == "Value") { newItem = new Value("value"); } 
    else if (droppedItem == "Data Block") { newItem = new DataBlock("datablock", "float", 10, 10); }
    
    //Functions
    else if (droppedItem == "Map") { newItem = new Map(); }
    else if (droppedItem == "Reduce") { newItem = new Reduce(); }
    else if (droppedItem == "Sort") { newItem = new Sort(); }
    else if (droppedItem == "Print") { newItem = new Print(); }
    else if (droppedItem == "Write") { newItem = new Write(); }
  
    else {
      qDebug() << "Unknown Item: " << droppedItem;
      return QGraphicsScene::dropEvent(event);
    }
    
    addItem(newItem);
    newItem->setPos(event->scenePos());
    qDebug() << event->scenePos();
    return;
  } else {
Ejemplo n.º 29
0
void MainWindow::initRandUniState()
{
    // QGraphicsItem *item = this->gs->addPixmap(this->dotpm);
    // item->setPos(50, 50);
    // this->gs->addText("hahaha");
    // 这个值控制初始化的细胞数量
    // int rand_rate = this->gcnt * this->gcnt * 1/100;
    int rand_rate = 5;
    QGraphicsItem *item = NULL, *nit = NULL;
    for (int x = 0 ; x < this->gcnt; ++x) {
        for (int y = 0; y < this->gcnt; ++y) {
            if (qrand() % rand_rate == 0) {
                // item = this->gs->addPixmap(this->dotpm);
                item = this->takeCachedItem();
                item->setPos(x*glen, y*glen);
                this->gs->addItem(item);
                nit = this->gs->itemAt(x*glen, y*glen);
                qLogx()<<x<<y<<item<<nit;
            }
        }
    }
}
Ejemplo n.º 30
0
 void MainWindow::initSpecificUniState(int *matrix, int mx, int my)
 {
     int ci;
     int tx, ty;
     QGraphicsItem *item = NULL;

     this->clearUniState();

     for (int m = 0; m < mx; ++m) {
         for (int n = 0; n < my; ++n) {
             ci = matrix[n*mx + m];
             if (ci == 1) {
                 tx = 3 + m;
                 ty = 3 + n;
                  // item = this->gs->addPixmap(this->dotpm);
                 item = this->takeCachedItem();
                 item->setPos(tx * glen, ty * glen);
                 this->gs->addItem(item);
             }
         }
     }

 }