Exemple #1
0
void ArrangementDemoWindow::updateMode( QAction* newMode )
{
  // QWidget* widget = this->ui->tabWidget->currentWidget( );
  // ArrangementDemoTabBase* demoTab =
  //   static_cast< ArrangementDemoTabBase* >( widget );
  const unsigned int TabIndex = this->ui->tabWidget->currentIndex( );
  if (TabIndex == static_cast<unsigned int>(-1)) return;
  ArrangementDemoTabBase* activeTab = this->tabs[ TabIndex ];
  QGraphicsScene* activeScene = activeTab->getScene( );
  QGraphicsView* activeView = activeTab->getView( );

  this->resetCallbackState( TabIndex );
  this->removeCallback( TabIndex );

  // update the active mode
  this->activeModes.at( 0 ) = newMode;

  // hook up the new active mode
  if ( newMode == this->ui->actionInsert )
  {
    activeScene->installEventFilter( activeTab->getCurveInputCallback( ) );
  }
  else if ( newMode == this->ui->actionDrag )
  {
    activeView->setDragMode( QGraphicsView::ScrollHandDrag );
  }
  else if ( newMode == this->ui->actionDelete )
  {
    activeScene->installEventFilter( activeTab->getDeleteCurveCallback( ) );
  }
  else if ( newMode == this->ui->actionPointLocation )
  {
    activeScene->installEventFilter( activeTab->getPointLocationCallback( ) );
  }
  else if ( newMode == this->ui->actionRayShootingUp )
  {
    // -y is up for Qt, so we shoot down
    activeTab->getVerticalRayShootCallback( )->setShootingUp( true );
    activeScene->installEventFilter( activeTab->getVerticalRayShootCallback());
  }
  else if ( newMode == this->ui->actionRayShootingDown )
  {
    // the bottom of the viewport for Qt is +y, so we shoot up
    activeTab->getVerticalRayShootCallback( )->setShootingUp( false );
    activeScene->installEventFilter( activeTab->getVerticalRayShootCallback());
  }
  else if ( newMode == this->ui->actionMerge )
  {
    activeScene->installEventFilter( activeTab->getMergeEdgeCallback( ) );
  }
  else if ( newMode == this->ui->actionSplit )
  {
    activeScene->installEventFilter( activeTab->getSplitEdgeCallback( ) );
  }
  else if ( newMode == this->ui->actionFill )
  {
    activeScene->installEventFilter( activeTab->getFillFaceCallback( ) );
  }
  this->updateFillColorSwatch( );
}
GenomNode * TreeDrawer::setCoordAndDraw(std::multimap<int, GenomNode*> * treeMap, QGraphicsView *treeView, int count)
{

    GenomNode * firstNode;
    int height = treeView->height();
    int width = treeView->width();
    int step = (treeView->width()) / (count + 1);
    QGraphicsScene * graphScen = new QGraphicsScene();
    graphScen->installEventFilter(graphScen);
    graphScen->setSceneRect(0,0, treeView->width(),treeView->height());
    treeView->setScene(graphScen);
    for (int i = count; i > 0; i--) {
        std::pair<std::multimap<int, GenomNode*>::iterator, std::multimap<int, GenomNode*>::iterator> currentLevel = treeMap->equal_range(i);
        for (std::multimap<int, GenomNode*>::iterator iter = currentLevel.first; iter != currentLevel.second;++iter)
        {
            std::cout << "  [" << (*iter).first << ", " << (*iter).second->getGenomName().toAscii().data() << "]" << std::endl;
            GenomNode * node = (iter)->second;            
            node->setNodeX(node->getIndex() * step );
            node->setNodeY((node->getLeftChild()->getNodeY() + node->getRightChild()->getNodeY()) / 2);
            setAndShowNode(treeView, node);
            drawLine(node->getNodeX() + node->genomBody->width(), node->getNodeY() + node->getGenomBody()->height() / 2,node->getLeftChild()->getNodeX() + node->getLeftChild()->genomBody->width(), node->getLeftChild()->getNodeY() + node->getLeftChild()->genomBody->height() / 2, graphScen);
            drawLine(node->getNodeX() + node->genomBody->width(), node->getNodeY() + node->getGenomBody()->height() / 2, node->getRightChild()->getNodeX() + node->getRightChild()->genomBody->width(), node->getRightChild()->getNodeY()  + node->getRightChild()->genomBody->height() / 2, graphScen);
            firstNode = node;
        }

    }
    return firstNode;
}
QVariant MInverseMouseArea::itemChange(GraphicsItemChange change, const QVariant &value)
{
    switch (change) {
    case QGraphicsItem::ItemSceneChange: {
        QGraphicsScene *oldScene = scene();

        if (oldScene)
            oldScene->removeEventFilter(this);

        m_pressed = false;
        if (value.canConvert<QGraphicsScene *>()) {
            QGraphicsScene *newScene = value.value<QGraphicsScene *>();
            if (newScene)
                newScene->installEventFilter(this);
        }
        break;
    }
    case QGraphicsItem::ItemVisibleHasChanged: {
        if (!isVisible())
            m_pressed = false;
        break;
    }
    default:
        break;
    }

    return QDeclarativeItem::itemChange(change, value);
}
Exemple #4
0
GameController::GameController(QGraphicsScene &scene, QObject *parent) :
    QObject(parent),
    scene(scene),
    snake(new Snake(*this))
{
    timer.start(1000/33);

    //Food *a1 = new Food(0, -50);
    addNewFood();
    //scene.addItem(a1);

    scene.addItem(snake);
    scene.installEventFilter(this);

    resume();
}
void LabelROIsAdapter::setupUi(QBoxLayout* layout)
{
    QGraphicsScene* scene = view_->scene();
    if (scene == nullptr) {
        scene = new QGraphicsScene();
        view_->setScene(scene);
        scene->installEventFilter(this);
    }

    view_->setFixedSize(QSize(state.width, state.height));
    view_->setMouseTracking(true);
    view_->setAcceptDrops(false);
    view_->setDragMode(QGraphicsView::RubberBandDrag);
    view_->scene()->installEventFilter(this);

    layout->addWidget(view_);

    QHBoxLayout* sub = new QHBoxLayout;
    QPushButton* fit = new QPushButton("fit size");
    sub->addWidget(fit, 0, Qt::AlignLeft);
    QObject::connect(fit, SIGNAL(clicked()), this, SLOT(fitInView()));

    sub->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
    layout_->addLayout(sub);

    pixmap_ = new QGraphicsPixmapItem;
    view_->scene()->addItem(pixmap_);

    connect(this, SIGNAL(displayRequest(QImage)), this, SLOT(display(QImage)));
    connect(this, SIGNAL(submitRequest()), this, SLOT(submit()));
    connect(this, SIGNAL(dropRequest()), this, SLOT(drop()));
    connect(this, SIGNAL(clearRequest()), this, SLOT(clear()));
    connect(this, SIGNAL(setColorRequest(int, int, int)), this, SLOT(setColor(int, int, int)));
    connect(this, SIGNAL(setClassRequest(int)), this, SLOT(setClass(int)));

    DefaultNodeAdapter::setupUi(layout);
}