void CellScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) {
	QGraphicsItem * item = itemAt(mouseEvent->scenePos());
	QGraphicsEllipseItem * item1;
	if (mouseEvent->button() == Qt::LeftButton)
		if (item)
			if (item->data(0) == "cellpoint" && item->data(1) == "") {
//				qDebug() << "marked";
				item1 = (QGraphicsEllipseItem*) item;
				item1->setPen(QPen(color, 3));
				item->setData(1, "marked");
				item->setData(2,struct_num);
				updatePointsNumbers();
				item->setData(4,0);

//				qDebug() <<item->data(2);
			}
	if (mouseEvent->button() == Qt::RightButton)
		if (item)
			if (item->data(1) == "marked") {
				item1 = (QGraphicsEllipseItem*) item;
				item1->setPen(QPen(Qt::blue, 2));
				item->setData(1, "");
				item->setData(2, "");
				item->setData(3,"");
				item->setData(4,"");
//				qDebug() <<item->data(2);
//				qDebug() << "unmarked";
			}
}
void WLD_ModeSelect::mousePress(QGraphicsSceneMouseEvent *mouseEvent)
{
    if(!scene) return;
    WldScene *s = dynamic_cast<WldScene *>(scene);

    if(s->EditingMode == WldScene::MODE_PasteFromClip)
    {
        if( mouseEvent->buttons() & Qt::RightButton )
        {
            MainWinConnect::pMainWin->on_actionSelect_triggered();
            dontCallEvent = true;
            s->IsMoved = true;
            return;
        }
        s->PasteFromBuffer = true;
        dontCallEvent = true;
        s->IsMoved = true;
        return;
    }

    if((s->disableMoveItems) && (mouseEvent->buttons() & Qt::LeftButton)
        && (Qt::ControlModifier != QApplication::keyboardModifiers()))
    { return; }

    if( mouseEvent->buttons() & Qt::MiddleButton )
    {
        if(GlobalSettings::MidMouse_allowSwitchToPlace)
        {
            if(s->selectedItems().size()==1)
            {
                QGraphicsItem * it = s->selectedItems().first();
                QString itp = it->data(0).toString();
                long itd = it->data(1).toInt();
                if(itp=="TILE")
                {MainWinConnect::pMainWin->SwitchPlacingItem(ItemTypes::WLD_Tile, itd); return;}
                else if(itp=="SCENERY")
                {MainWinConnect::pMainWin->SwitchPlacingItem(ItemTypes::WLD_Scenery, itd); return;}
                else if(itp=="PATH")
                {MainWinConnect::pMainWin->SwitchPlacingItem(ItemTypes::WLD_Path, itd); return;}
                else if(itp=="LEVEL")
                {MainWinConnect::pMainWin->SwitchPlacingItem(ItemTypes::WLD_Level, itd); return;}
                else if(itp=="MUSICBOX")
                {MainWinConnect::pMainWin->SwitchPlacingItem(ItemTypes::WLD_MusicBox, itd); return;}
            }
        }
        if(GlobalSettings::MidMouse_allowDuplicate)
        {
            if(!s->selectedItems().isEmpty())
            {
                s->WldBuffer = s->copy();
                s->PasteFromBuffer=true;
            }
        }
    }
}
  void PeriodicTableScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
  {
    if (event->button() != Qt::LeftButton)
      return;

    QGraphicsItem *item = QGraphicsScene::itemAt(event->scenePos());
    if (item->data(0).toInt() > 0 && item->data(0).toInt() < 119)
      emit(elementChanged(item->data(0).toInt()));

    QGraphicsScene::mousePressEvent(event);
  }
bool Scene::collidingVehicles(QGraphicsItem* item_, Vehicle* v_) {
    QList<QGraphicsItem*> items = this->collidingItems(item_);
    QListIterator<QGraphicsItem*> i(items);

    while(i.hasNext()){
        QGraphicsItem* it = i.next();
        if(it->data(2).value<Vehicle*>() && it->data(2).value<Vehicle*>() != v_)
            return true;
    }

    return false;
}
Exemple #5
0
	int ThymioScene::getFocusItemId() const 
	{ 
		QGraphicsItem *item = focusItem();
		
		while( item != 0 )
		{
			if( item->data(0).toString() == "buttonset" )
				return thymioCompiler.buttonToCode(item->data(1).toInt());
			else
				item = item->parentItem();			
		}

		return -1;
	}
vector<Vehicle*> Scene::collidingVehicles(QGraphicsItem* item_){
    QList<QGraphicsItem*> items = this->collidingItems(item_);
    QListIterator<QGraphicsItem*> i(items);

    vector<Vehicle*> result;

    while(i.hasNext()){
        QGraphicsItem* it = i.next();
        if(it->data(2).value<Vehicle*>() != 0 ){
            Vehicle * v = it->data(2).value<Vehicle*>();
            result.push_back(v);
        }
    }
    return result;
}
void MyQGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    int x = mouseEvent->scenePos().x();
    int y = mouseEvent->scenePos().y();

    if(tourPortee != 0)
    {
        this->removeItem(tourPortee);
        tourPortee = 0;
        emit this->tourSelectionnee(0,0,0);
    }

    QGraphicsItem * I = itemAt(x,y);

    if(mouseEvent->button() == Qt::RightButton)
    {
        /*this->removeItem(I);
        I = this->itemAt(x,y);
        this->removeItem(I);*/
        this->removeItem(getPrecedent());
        this->removeItem(getPrecedent2());
        this->tourDemandee = "";
    }

    if(tourDemandee != "")
    {
        this->removeItem(getPrecedent());
        this->removeItem(getPrecedent2());
        I = this->itemAt(x,y);

        if(tourDemandee == "EAU" && I->data(0).toString() == "HERBE")
        {
            emit this->ajouterTour(x,y,"EAU");
        }
        else if(tourDemandee == "PIERRE" && I->data(0).toString() == "HERBE")
        {
            emit this->ajouterTour(x,y,"PIERRE");
        }
        else if(tourDemandee == "PEINTURE" && I->data(0).toString() == "HERBE")
        {
            emit this->ajouterTour(x,y,"PEINTURE");
        }
        else if(tourDemandee == "PETANQUE" && I->data(0).toString() == "HERBE")
        {
            emit this->ajouterTour(x,y,"PETANQUE");
        }
        else if(tourDemandee == "MUSICIEN" && I->data(0).toString() == "HERBE")
        {
            emit this->ajouterTour(x,y,"MUSICIEN");
        }
     }
    if(I->data(0).toString() == "EAU" || I->data(0).toString() == "PIERRE" || I->data(0).toString() == "PEINTURE" || I->data(0).toString() == "PETANQUE" || I->data(0).toString() == "MUSICIEN")
    {
        emit this->tourSelectionnee(x,y,I);
    }
    precedent = 0;
    precedent2 = 0;
}
Exemple #8
0
void DrumrollEditor::updateSelection()
      {
      QList<QGraphicsItem*> items = gv->scene()->selectedItems();
      if (items.size() == 1) {
            QGraphicsItem* item = items[0];
            Note* note = static_cast<Note*>(item->data(0).value<void*>());
            pitch->setEnabled(true);
            pitch->setValue(note->pitch());
            veloType->setEnabled(true);
            velocity->setEnabled(true);
            updateVelocity(note);
            }
      else if (items.size() == 0) {
            velocity->setValue(0);
            velocity->setEnabled(false);
            pitch->setValue(0);
            pitch->setEnabled(false);
            veloType->setEnabled(false);
            veloType->setCurrentIndex(int(Note::ValueType::OFFSET_VAL));
            }
      else {
            velocity->setEnabled(true);
            velocity->setValue(0);
            velocity->setReadOnly(false);
            pitch->setEnabled(true);
            pitch->setDeltaMode(true);
            pitch->setValue(0);
            veloType->setEnabled(true);
            veloType->setCurrentIndex(int(Note::ValueType::OFFSET_VAL));
            }
      }
vector<MapElement*> Scene::collidingMapElements(QGraphicsItem* item_){
    QList<QGraphicsItem*> items = this->collidingItems(item_);
    QListIterator<QGraphicsItem*> i(items);
    vector<MapElement*> result;


    while(i.hasNext()){
        QGraphicsItem* it = i.next();
        if(it->data(1).value<MapElement*>() != 0 ){
            MapElement* mapEl = it->data(1).value<MapElement *>();
            result.push_back(mapEl);
        }
    }

    return result;
}
void GraphiItemCtrl::OnRemoveEvent()
{
	QGraphicsItem* pItem = o_ItemScene.itemAt(o_PointB,QTransform());

	if(pItem == p_Image)
		return;// should not delete the image

	int iItemKey = pItem->data(CUSTDATA_KEY).toInt();
	int iType = pItem->type();

	switch(iType)
	{

	case ITM_TYPE_LINE:
		{
			emit NotifyLineRemove(iItemKey);
			break;
		}
	case ITM_TYPE_ELIPSE:
		{
			emit NotifyElipseRemoved(iItemKey);
			break;
		}
	case ITM_TYPE_RECTANGLE:
		{
			emit NotifyRectRemoved(iItemKey);
			break;
		}
	}

	o_ItemScene.removeItem(pItem);
}
Exemple #11
0
void GraphicsScene::showCurves (bool show,
                                bool showAll,
                                const QString &curveNameWanted)
{
  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::showCurves"
                              << " show=" << (show ? "true" : "false")
                              << " showAll=" << (showAll ? "true" : "false")
                              << " curve=" << curveNameWanted.toLatin1().data();

  const QList<QGraphicsItem*> &items = QGraphicsScene::items();
  QList<QGraphicsItem*>::const_iterator itr;
  for (itr = items.begin(); itr != items.end(); itr++) {

    QGraphicsItem* item = *itr;

    // Skip the image and only process the Points
    bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
    bool isCurve = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_LINE);

    if (isPoint || isCurve) {

      bool showThis = show;
      if (show && !showAll) {
        QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();

        if (isPoint) {

          QString curveNameGot = Point::curveNameFromPointIdentifier (identifier);
          showThis = (curveNameWanted == curveNameGot);

        } else {

          showThis = (curveNameWanted == identifier);

        }
      }

      item->setVisible (showThis);

    }
  }
}
void CmdAbstract::resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
{
  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::resetSelection";

  QList<QGraphicsItem *> items = mainWindow().view().items();
  QList<QGraphicsItem *>::iterator itrS;
  for (itrS = items.begin (); itrS != items.end (); itrS++) {

    QGraphicsItem *item = *itrS;
    bool selected = false;
    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT) {

      QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();

      selected = pointIdentifiersToSelect.contains (pointIdentifier);
    }

    item->setSelected (selected);
  }
}
void DigitizeStateSelect::unsetCursorForPoints()
{
  QList<QGraphicsItem*> items = context().mainWindow().scene().items();
  QList<QGraphicsItem*>::iterator itr;
  for (itr = items.begin (); itr != items.end (); itr++) {

    QGraphicsItem *item = *itr;
    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
      item->unsetCursor ();
    }
  }
}
Exemple #14
0
//По нажатию левой клавиши размещает смайлы, правой - удаляет. Считывает положение мыши
void MvScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
	if (mouseEvent->button() == Qt::LeftButton) 
                placeSmile(mouseEvent->scenePos().x(), mouseEvent->scenePos().y());
	if (mouseEvent->button() == Qt::RightButton) {
		QGraphicsItem * item = itemAt(mouseEvent->scenePos());
		if (item)
                        if (item->data(0) == "Smile")
				removeItem(item);
	}
			
}
Exemple #15
0
void BSplineVisDialog::on_bspView_mousePressed(QMouseEvent *event) {
    QPointF pos = ui.bspView->mapToScene(event->pos());
    QGraphicsItem* item = m_Scene.itemAt(pos);
    if (item != NULL) {
        if (!item->data(1).isNull()) {
            int key = item->data(1).toInt();
            m_Index = key;
            m_Key = 1;
        } else if (!item->data(2).isNull()) {
            int key = item->data(2).toInt();
            m_Index = key;
            m_Key = 2;
        } else {
            m_Index = -1;
            m_Key = 0;
        }
    } else {
        m_Index = -1;
        m_Key = 0;
    }
}
void DigitizeStateSelect::addHoverHighlighting()
{
  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSelect::addHoverHighlighting";

  QList<QGraphicsItem*> items = context().mainWindow().scene().items();
  QList<QGraphicsItem*>::iterator itr;
  for (itr = items.begin (); itr != items.end (); itr++) {

    QGraphicsItem *item = *itr;
    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
       item->setAcceptHoverEvents(true);
    }
  }
}
void DigitizeStateSelect::setHoverHighlighting(const MainWindowModel &modelMainWindow)
{
  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSelect::addHoverHighlighting";

  // Set the opacity for all points. It should be already set for pre-existing points
  QList<QGraphicsItem*> items = context().mainWindow().scene().items();
  QList<QGraphicsItem*>::iterator itr;
  for (itr = items.begin (); itr != items.end (); itr++) {

    QGraphicsItem *item = *itr;
    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
       item->setOpacity (modelMainWindow.highlightOpacity());
    }
  }
}
Exemple #18
0
const QGraphicsPixmapItem *GraphicsScene::image () const
{
  // Loop through items in scene to find the image
  QList<QGraphicsItem*> items = QGraphicsScene::items();
  QList<QGraphicsItem*>::iterator itr;
  for (itr = items.begin(); itr != items.end(); itr++) {

    QGraphicsItem* item = *itr;
    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_IMAGE) {

      return (QGraphicsPixmapItem *) item;
    }
  }

  return 0;
}
Exemple #19
0
void AreaWidget::doubleClickInit(AnimationItem *pItem)
{
    if(!pItem)
        return;
    QList <QGraphicsItem *> items = pItem->childItems();
    QGraphicsItem *group = NULL;
    int nCount = items.size();
    int i = 0;
    QString sName = "";
    int ikey = 0;
    m_Tinfo.clear();

    QRectF rc;
    for(i  = 0;i < nCount;i++)
    {
        group = items.at(i);
        sName = group->data(GROUP_NAME_KEY).toString();
        ikey = group->type();

        if(sName == tr("mMain")) //向量图控件
        {
//            rc = group->boundingRect();
//            ui->m_width->setValue(rc.width()); //初始化向量图的的宽度
//            ui->m_height->setValue(rc.height());//初始化向量图的的高度
//            iWidth = rc.width();
//            iHeight = rc.height();
        }
        else if(ikey == SAM_DRAW_OBJECT_ELIPSE) //记录每个点的位置
        {
            QPointF pos = group->boundingRect().topLeft()+group->scenePos();
            TrackPointInfo TrackPoint;
            TrackPoint.nXPos = pos.x();
            TrackPoint.nYPos = pos.y();
            m_Tinfo.append(TrackPoint);
        }
    }//end for

    if(2 != m_Tinfo.size())
    {
        return;
    }

    ui->m_XlineEdit->setText(QString::number(m_Tinfo[0].nXPos));
    ui->M_YlineEdit->setText(QString::number(m_Tinfo[0].nYPos));
    ui->m_WlineEdit->setText(QString::number(qAbs(m_Tinfo[1].nXPos - m_Tinfo[0].nXPos)));
    ui->m_HlineEdit->setText(QString::number(qAbs(m_Tinfo[1].nYPos - m_Tinfo[0].nYPos)));
}
Exemple #20
0
void ScatterWidget::doubleClickInit(AnimationItem *pItem)
{
    if(!pItem)
        return;
    QList <QGraphicsItem *> items = pItem->childItems();
    QGraphicsItem *group = NULL;
    int nCount = items.size();
    int i = 0;
    QString sName = "";
    int ikey = 0;
    m_Tinfo.clear();

    QRectF rc;
    for(i  = 0;i < nCount;i++)
    {
        group = items.at(i);
        sName = group->data(GROUP_NAME_KEY).toString();
        ikey = group->type();

        if(sName == tr("mMain")) //向量图控件
        {
//            rc = group->boundingRect();
//            ui->m_width->setValue(rc.width()); //初始化向量图的的宽度
//            ui->m_height->setValue(rc.height());//初始化向量图的的高度
//            iWidth = rc.width();
//            iHeight = rc.height();
        }
        else if(ikey == SAM_DRAW_OBJECT_ELIPSE) //记录每个点的位置
        {
            QPointF pos = group->boundingRect().topLeft()+group->scenePos();
            TrackPointInfo TrackPoint;
            TrackPoint.nXPos = pos.x();
            TrackPoint.nYPos = pos.y();
            m_Tinfo.append(TrackPoint);
        }
    }//end for

    ui->m_TrackspBox->setRange(0,m_Tinfo.size() - 1);
    for(i  = 0;i < m_Tinfo.size();i++)
    {
        m_Tinfo[i].nOrbitId = i;
    }
    ui->m_TrackspBox->setValue(0); //初始化轨迹点
    ui->m_xTracklineEdit->setText(QString::number(m_Tinfo.at(0).nXPos)); //初始化位置0的x坐标
    ui->m_yTracklineEdit->setText(QString::number(m_Tinfo.at(0).nYPos));//初始化位置1的y坐标
}
Exemple #21
0
void GalaGV::onSelectionChanged()
{
    QList<QGraphicsItem*> l = scene()->selectedItems();
    if(!l.isEmpty()){
        QGraphicsItem *i = l.first();
        QString t;
        if(mData->gate != NULL){
            int d = clacDis(i->data(Cords).toString(),mData->gate->data(Cords).toString());
            d=d/5;
            int h =0;
            if(d>59)
                h = d/60;

            t = QString::number(h)+"h:"+QString::number(d%60)+"min ";
        }
        mLabelInfo->setText(t+i->toolTip());
    }
}
Exemple #22
0
void GraphicsScene::hideAllItemsExceptImage()
{
  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::hideAllItemsExceptImage";

  for (int index = 0; index < QGraphicsScene::items().count(); index++) {
    QGraphicsItem *item = QGraphicsScene::items().at(index);

    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt() == GRAPHICS_ITEM_TYPE_IMAGE) {

      item->show();

    } else {

      item->hide();

    }
  }
}
Exemple #23
0
void DrumrollEditor::selectionChanged()
      {
      updateSelection();
//      _score->blockSignals(true);
      QList<QGraphicsItem*> items = gv->scene()->selectedItems();
      if (items.size() == 1) {
            QGraphicsItem* item = items[0];
            Note* note = static_cast<Note*>(item->data(0).value<void*>());
            if (note)
                  _score->select(note, SelectType::SINGLE, 0);
            }
      else if (items.size() == 0) {
            _score->select(0, SelectType::SINGLE, 0);
            }
      else {
            _score->select(0, SelectType::SINGLE, 0);
            foreach(QGraphicsItem* item, items) {
                  Note* note = static_cast<Note*>(item->data(0).value<void*>());
                  if (note)
                        _score->select(note, SelectType::ADD, 0);
                  }
            }
void DigitizeStateSelect::showCoordinatesIfSinglePointIsSelected ()
{
  // See if there is a single point selected
  QList<QGraphicsItem*> items = context().mainWindow().scene().selectedItems();
  if (items.size () == 1) {

    // There is a single item selected but we must see if it is a point
    QGraphicsItem *item = * (items.begin ());

    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {

      // Show the coordinates of the point in the status bar
      QString coordsScreen, coordsGraph, resolutionGraph;
      context().mainWindow().transformation().coordTextForStatusBar (item->pos(),
                                              coordsScreen,
                                              coordsGraph,
                                              resolutionGraph,
                                              context().mainWindow().modeMap());

      context().mainWindow().showTemporaryMessage(coordsGraph);
    }
  }
}
void MyQGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    int x = mouseEvent->scenePos().x();
    int y = mouseEvent->scenePos().y();

    QGraphicsItem * I = itemAt(x,y);

    if(I->data(0).toString() == "HERBE")
    {
        if(tourDemandee == "EAU")
        {
            emit tourMouseTracking(x,y,"EAU");
            precedent = itemAt((x/32)*32+32/2,(y/32)*32+32/2);
        }
        else if(tourDemandee == "PIERRE")
        {
            emit tourMouseTracking(x,y,"PIERRE");
            precedent = itemAt((x/32)*32+32/2,(y/32)*32+32/2);
        }
        else if(tourDemandee == "PEINTURE")
        {
            emit tourMouseTracking(x,y,"PEINTURE");
            precedent = itemAt((x/32)*32+32/2,(y/32)*32+32/2);
        }
        else if(tourDemandee == "PETANQUE")
        {
            emit tourMouseTracking(x,y,"PETANQUE");
            precedent = itemAt((x/32)*32+32/2,(y/32)*32+32/2);
        }
        else if(tourDemandee == "MUSICIEN")
        {
            emit tourMouseTracking(x,y,"MUSICIEN");
            precedent = itemAt((x/32)*32+32/2,(y/32)*32+32/2);
        }
    }
}
Exemple #26
0
// ////////////////////////////////////Draw BG image/////////////////////////////////////////////////
void LvlScene::DrawBG(int x, int y, int w, int h, int sctID,
                      QPixmap &srcimg, QPixmap &srcimg2, obj_BG &bgsetup)
{
    /* Old Algorith */
    //QPixmap BackImg;
    //QPainter * BGPaint;
    //QPixmap img;
    int si_attach, attach;

    /* New Algorith */
    QGraphicsItem * item;
    //QGraphicsRectItem * itemR=NULL;

    QColor FillColor; //Fill undrawed space with color

    long sctW,//Section Width
         sctH,//Section Height
         R1W, //Img Width  (Row1)
         R1H, //Img Height (Row1)
         R1Hc=0, //Crop height from bottom
         R1Ho=0, //Offset from top
         R2W, //Img Width  (Row2)
         R2H, //Img Height (Row2)
         R2Hc=0, //Crop height from bottom
         R2Ho=0, //Offset from top
         RectPlus=0,
         toY; //Placing position Y 0 - top

    sctW = (long)fabs(x-w);
    sctH = (long)fabs(y-h);

    WriteToLog(QtDebugMsg, "Draw BG -> Draw BG Image");

    attach = bgsetup.attached;

// ///////////////////SingleRow BG///////////////////////////
    if((bgsetup.type==0)&&(!bgsetup.editing_tiled))
    {
        WriteToLog(QtDebugMsg, "Draw BG -> Style: SingleRow BG");

        R1W = srcimg.width();
        R1H = srcimg.height();

        if(attach==0) // Get Pixel color (0 - bottom, 1 - top)
            FillColor = QColor( srcimg.toImage().pixel(0,0) ); // from top
        else
            FillColor = QColor( srcimg.toImage().pixel(0,(R1H-1)) ); //from bottom

        if(attach==0)
        {   // 0 - bottom
            toY = (sctH>R1H)? sctH-R1H : 0;
            R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom
            R1Ho = R1Hc; //Offset from top
            RectPlus=0;
        }
        else
        {   // 1 - top
            toY = 0;
            R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom
            R1Ho = 0; //Offset from top
            RectPlus=R1H;
        }

        // /////////////////////Draw row//////////////////

        item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc)));
        item->setData(0, QString("BackGround%1").arg(sctID) );
        item->setPos(x, y+toY);
        item->setZValue(bgZ);

        if(R1H < sctH)
        {
            item = addRect(0, 0, sctW, sctH-R1H, Qt::NoPen, QBrush(FillColor));
            item->setData(0, QString("BackGround%1").arg(sctID) );
            item->setPos(x,y+RectPlus);
            item->setZValue(bgZ);
        }

    }
    else

// ///////////////////DoubleRow BG////////////////////////
        if((bgsetup.type==1)&&(!bgsetup.editing_tiled))
        {
            WriteToLog(QtDebugMsg, "Draw BG -> Style: DoubleRow BG");

            si_attach = bgsetup.second_attached; // Second image attach

            R1W = srcimg.width();
            R1H = srcimg.height();

            //Fill empty space
            if((!srcimg2.isNull()) && (si_attach==0))
                FillColor = QColor( srcimg2.toImage().pixel(0,0) );
            else
                FillColor = QColor( srcimg.toImage().pixel(0,0) );

            toY = (sctH>R1H)? sctH-R1H : 0;
            R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom
            R1Ho = R1Hc; //Offset from top
            RectPlus=0;

            WriteToLog(QtDebugMsg, QString("Draw BG -> Draw first row, params: "));

            // /////////////////////Draw first row//////////////////
            item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc)));
            item->setData(0, QString("BackGround%1").arg(sctID) );
            item->setPos(x, y+toY);
            item->setZValue(bgZ);
            // /////////////////////Draw first row//////////////////

            WriteToLog(QtDebugMsg, "Draw BG -> Draw second row");

            R2W = srcimg2.width();
            R2H = srcimg2.height();

            if(si_attach==0) // over first
            {
                toY = (sctH-R1H > R2H)? sctH-R2H-R1H : 0;
                R2Hc = ((R2H+R1H>sctH) ? R2H-(sctH-R1H) : 0); //Crop height from bottom
                R2Ho = R2Hc; //Offset from top
                RectPlus=R2H;
            }
            else if(si_attach==1) // bottom
            {
                toY = (sctH > R2H)? sctH-R2H : 0;
                R2Hc = ((R2H>sctH) ? R2H-sctH : 0); //Crop height from bottom
                R2Ho = R2Hc; //Offset from top
                RectPlus=0;
            }

            if((!srcimg2.isNull()) && ((sctH > R1H)||(si_attach==1)))
            {

                // /////////////////////Draw second row//////////////////
                item = addRect(0, 0, sctW, R2H-R2Hc, Qt::NoPen, QBrush( srcimg2.copy(0, R2Ho, R2W, R2H-R2Hc) ));
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x, y+toY);
                item->setZValue(bgZ+0.0000000001);
                // /////////////////////Draw second row//////////////////

            } else if(srcimg2.isNull())
                WriteToLog(QtWarningMsg, "Draw BG -> second image is Null");


            if( R1H+RectPlus < sctH )
            {
                item = addRect(0, 0, sctW, sctH-R1H-RectPlus, Qt::NoPen, QBrush(FillColor));
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x,y);
                item->setZValue(bgZ);
            }

        }
        else

// ///////////////////////////////Tiled BG///////////////////////////////
        {

            WriteToLog(QtDebugMsg, "Draw BG -> Style: Tiled");

            R1W = srcimg.width();
            R1H = srcimg.height();
            if(attach==0)
            {
                //Attached to Bottom
                RectPlus = sctH % R1H;

                toY = (sctH>R1H)? sctH-R1H : 0;

                //R1Hc = R1H-RectPlus; // Crop height from bottom/Offset from top

                item = addRect(0, 0, sctW, RectPlus, Qt::NoPen,
                               QBrush(srcimg.copy(0, R1H-RectPlus, R1W, RectPlus))
                              );
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x,y);
                item->setZValue(bgZ);

                if(sctH >= R1H)
                {
                    item = addRect(0, 0, sctW, sctH-RectPlus, Qt::NoPen, QBrush(srcimg));
                    item->setData(0, "BackGround"+QString::number(sctID) );
                    item->setPos(x,y+RectPlus);
                    item->setZValue(bgZ);
                }

            }
            else
            {
                //Attached to Top
                item = addRect(0, 0, sctW, sctH, Qt::NoPen, QBrush(srcimg));
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x,y);
                item->setZValue(bgZ);
            }
        }

    WriteToLog(QtDebugMsg, "acceptedID is "+QString::number(sctID)+" data is "+item->data(0).toString());

    WriteToLog(QtDebugMsg, "Draw BG -> Drawed");
}
Exemple #27
0
void GalaGV::onContextMenuRequest(const QPoint &pos)
{

    QGraphicsItem *item = itemAt(pos);
    QGraphicsEllipseItem *eSystemItem;
    ESystem  e;

    SendMenu menu(ShipTreeWidget::tree());
    QMenu *m  = menu.menu();
    QAction *openSys = m->addAction("openSys");
    QAction *openLog = m->addAction("openLog");
    QAction *setCheckd = m->addAction("check");
    QAction *setWerf = m->addAction("werft");
    QAction *clearChecked = m->addAction("clear all checked");
    setCheckd->setCheckable(true);
    setWerf->setCheckable(true);

    const QHash<QString,QGraphicsEllipseItem*> &esysteme = mData->eSysteme.value(mData->showESysteme.first+";"+QString::number(mData->gala));

    if(!mData->showESysteme.second || esysteme.size() == 0)
        clearChecked->setEnabled(false);

    if(item == NULL){
        openSys->setEnabled(false);
        openLog->setEnabled(false);
        setCheckd->setEnabled(false);
        setWerf->setEnabled(false);
    } else {
        if(!mData->mPlayerLogPlanis.contains(item))
            openLog->setEnabled(false);

        eSystemItem =esysteme.value(item->data(ID).toString());
        if(eSystemItem == NULL || !mData->showESysteme.second){
            setCheckd->setEnabled(false);
            setWerf->setEnabled(false);
        }else {
            e=eSystemItem->data(Esystem).value<ESystem>();
            setCheckd->setChecked(e.isChecked);
            setWerf->setChecked(e.isWerft);
        }
    }



    if( eSystemItem == NULL || !mData->showESysteme.second)
        menu.setDisable(true);

    do {
        QAction *ret = m->exec(mapToGlobal(pos));
        if(ret == openSys){
            emit loadPage("http://www.omega-day.com/game/?op=system&sys="+item->data(Qt::UserRole).toString());
        }else if (ret == openLog){
            emit loadPage("http://www.omega-day.com/game/"+item->data(Qt::UserRole+1).toString());
        } else if(ret == setCheckd){
            setChecked(eSystemItem,setCheckd->isChecked());
        } else if(ret == clearChecked){
            int ret =QMessageBox::warning(this,"muh","wirklich löschen",QMessageBox::Yes,QMessageBox::No);
            if(ret == QMessageBox::Yes)
                clearAllChecked();

        }else if (ret == setWerf) {
            setWerft(eSystemItem,setWerf->isChecked());
        }else if( menu.checkSendClicked(ret)){
           const  QStringList & l = menu.checkedID();
            const QString &oldID = menu.orbitID();
            if(l.size()>0){
                QString planiID = eSystemItem->data(Esystem).value<ESystem>().planiID;
                if(l.size() == 1)
                    emit sendShip(l.first(),oldID,planiID);
                else
                    emit sendShips(l,planiID);
            }
        }
    }while(!menu.exit());
}
void UBGraphicsItemUndoCommand::undo()
{
    if (!mScene){
        return;
    }

    QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
    while (itAdded.hasNext())
    {
        QGraphicsItem* item = itAdded.next();

        UBApplication::boardController->freezeW3CWidget(item, true);
        item->setSelected(false);
        mScene->removeItem(item);
    }

    QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
    while (itRemoved.hasNext())
    {
        QGraphicsItem* item = itRemoved.next();
        if (item)
        {
            if (UBItemLayerType::FixedBackground == item->data(UBGraphicsItemData::ItemLayerType))
                mScene->setAsBackgroundObject(item);
            else
                mScene->addItem(item);

            if (UBGraphicsPolygonItem::Type == item->type())
            {
                UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
                if (polygonItem)
                {
                    mScene->removeItem(polygonItem);
                    mScene->removeItemFromDeletion(polygonItem);
                    polygonItem->strokesGroup()->addToGroup(polygonItem);
                }
            }

            UBApplication::boardController->freezeW3CWidget(item, false);
        }
    }

    QMapIterator<UBGraphicsGroupContainerItem*, QUuid> curMapElement(mExcludedFromGroup);
    UBGraphicsGroupContainerItem *nextGroup = NULL;
    UBGraphicsGroupContainerItem *previousGroupItem = NULL;
    bool groupChanged = false;

    while (curMapElement.hasNext()) {
        curMapElement.next();

        groupChanged = previousGroupItem != curMapElement.key();
        //trying to find the group on the scene;
        if (!nextGroup || groupChanged) {
            UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key();
            if (groupCandidate) {
                nextGroup = groupCandidate;
                if(!mScene->items().contains(nextGroup)) {
                    mScene->addItem(nextGroup);
                }
                nextGroup->setVisible(true);
            }
        }

        QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value());
        if (groupedItem) {
            nextGroup->addToGroup(groupedItem);
        }

        previousGroupItem = curMapElement.key();
        UBGraphicsItem::Delegate(nextGroup)->update();
    }

    // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
    mScene->update(mScene->sceneRect());
    mScene->updateSelectionFrame();

}
void UBGraphicsItemUndoCommand::redo()
{
    // the Undo framework calls a redo while appending the undo command.
    // as we have already plotted the elements, we do not want to do it twice
    if (!mFirstRedo)
    {
        if (!mScene){
            return;
        }

        QMapIterator<UBGraphicsGroupContainerItem*, QUuid> curMapElement(mExcludedFromGroup);
        UBGraphicsGroupContainerItem *nextGroup = NULL;
        UBGraphicsGroupContainerItem *previousGroupItem = NULL;
        bool groupChanged = false;

        while (curMapElement.hasNext()) {
            curMapElement.next();

            groupChanged = previousGroupItem != curMapElement.key();
            //trying to find the group on the scene;
            if (!nextGroup || groupChanged) {
                UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key();
                if (groupCandidate) {
                    nextGroup = groupCandidate;
                }
            }
            QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value());
            if (groupedItem) {
                if (nextGroup->childItems().count() == 1) {
                    nextGroup->destroy(false);
                    break;
                }
                nextGroup->removeFromGroup(groupedItem);
            }

            previousGroupItem = curMapElement.key();
            UBGraphicsItem::Delegate(nextGroup)->update();
        }

        QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
        while (itRemoved.hasNext())
        {
            QGraphicsItem* item = itRemoved.next();
            item->setSelected(false);
            mScene->removeItem(item);
            UBApplication::boardController->freezeW3CWidget(item, true);
        }

        QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
        while (itAdded.hasNext())
        {
            QGraphicsItem* item = itAdded.next();
            if (item)
            {
                UBApplication::boardController->freezeW3CWidget(item, false);

                if (UBItemLayerType::FixedBackground == item->data(UBGraphicsItemData::ItemLayerType))
                    mScene->setAsBackgroundObject(item);
                else
                    mScene->addItem(item);

                UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
                if (polygonItem)
                {
                    mScene->removeItem(polygonItem);
                    mScene->removeItemFromDeletion(polygonItem);
                    polygonItem->strokesGroup()->addToGroup(polygonItem);
                }
            }
        }

        // force refresh, QT is a bit lazy and take a lot of time (nb item ^2) to trigger repaint
        mScene->update(mScene->sceneRect());
    }
    else
    {
        mFirstRedo = false;
    }
}
Exemple #30
0
/*
 * TODO:
 * ====
 * - display value of a port (nice to have)
 * - triangle port (nice to have)
 * - mouse over (over a node or port) (nice to have)
 * - round shaped nodes (nice to have)
*/

namespace Magus
{
    //****************************************************************************/
    QtNodeEditor::QtNodeEditor(QWidget* parent) : QWidget(parent)
    {
        QVBoxLayout* mainLayout = new QVBoxLayout;
        mView = new QGraphicsView(this);
        mScene = new QtNodeGraphicsScene();
        mScene->installEventFilter(this);
        mView->setScene(mScene);
        mView->setRenderHint(QPainter::Antialiasing, true);
        mView->setInteractive(true);
        mView->setMouseTracking(true);
        mainLayout->addWidget(mView);
        mLastRemovedNode = 0;
        mRubberBand = 0;
        mZoom = 1.0f;
        mFisheyeViewEnabled = false;
        mFisheyeMaxZoom = 1.0f;
        mFisheyeSteps = 5;
        mHeaderTitleIcon = NODE_HEADER_COMPOUND_ICON;
        mAction1Icon = NODE_HEADER_ACTION1_ICON;
        mAction2Icon = NODE_HEADER_ACTION2_ICON;
        mCompoundNodeDropped = 0;
        mRubberbandSelection = false;
        mContextMenuEnabled = true;
        mContextMenu = new QMenu(this);
        mContextMenu->addAction(new QAction(NODE_ACTION_DELETE, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_CENTER, this));
        mZoomSubMenu = mContextMenu->addMenu(NODE_ACTION_ZOOM);
        QAction* action;
        QActionGroup actionGroupZoom(mZoomSubMenu);
        actionGroupZoom.setExclusive(true);
        action = new QAction(NODE_ACTION_ZOOM_10, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_25, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_50, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_75, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_90, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_100, this);
        action->setCheckable(true);
        action->setChecked(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_150, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_200, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_250, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_300, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        mZoomSubMenu->addActions(actionGroupZoom.actions());

        mFisheyeViewSubMenu = mContextMenu->addMenu(NODE_ACTION_FISHEY_VIEW);
        QActionGroup actionGroupFisheye(mFisheyeViewSubMenu);
        actionGroupFisheye.setExclusive(true);
        action = new QAction(NODE_ACTION_FISHEYE_DISABLED, this);
        action->setCheckable(true);
        action->setChecked(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_NORMAL, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_NORMAL_SUBTLE, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_LARGE, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_LARGE_SUBTLE, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        mFisheyeViewSubMenu->addActions(actionGroupFisheye.actions());

        mContextMenu->addAction(new QAction(NODE_ACTION_SELECTED_TO_COMPOUND, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_COLLAPSE_ALL, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_EXPAND_ALL, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_EXPAND_COMPOUNDS, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_CENTER, this));

        setMenuZoomEnabled(true);
        setMenuSelectionToCompoundEnabled(true);
        setMenuCollapseExpandEnabled(true);
        setMenuExpandCompoundsEnabled(true);
        setMenuFisheyeViewEnabled(true);
        setContextMenuPolicy(Qt::CustomContextMenu);
        connect(mContextMenu, SIGNAL(triggered(QAction*)), this, SLOT(contextMenuItemSelected(QAction*)));
        setLayout(mainLayout);
    }

    //****************************************************************************/
    QtNodeEditor::~QtNodeEditor(void)
    {
    }

    //****************************************************************************/
    void QtNodeEditor::setContextMenuEnabled(bool enabled)
    {
        mContextMenuEnabled = enabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setCompoundHeaderTitleIcon(const QString& fileNameIcon)
    {
        mHeaderTitleIcon = fileNameIcon;
    }

    //****************************************************************************/
    void QtNodeEditor::setCompoundAction1Icon(const QString& fileNameIcon)
    {
        mAction1Icon = fileNameIcon;
    }

    //****************************************************************************/
    void QtNodeEditor::setCompoundAction2Icon(const QString& fileNameIcon)
    {
        mAction2Icon = fileNameIcon;
    }

    //****************************************************************************/
    bool QtNodeEditor::isContextMenuEnabled(void)
    {
        return mContextMenuEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuZoomEnabled(bool enabled)
    {
        mMenuZoomEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_ZOOM);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuZoomEnabled(void)
    {
        return mMenuZoomEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuSelectionToCompoundEnabled(bool enabled)
    {
        mMenuSelectionToCompoundEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_SELECTED_TO_COMPOUND);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuSelectionToCompoundEnabled(void)
    {
        return mMenuSelectionToCompoundEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuCollapseExpandEnabled(bool enabled)
    {
        mMenuCollapseExpandEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_EXPAND_ALL);
        if (action)
            action->setVisible(enabled);
        action = getActionFromContextMenu(NODE_ACTION_COLLAPSE_ALL);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuCollapseExpandEnabled(void)
    {
        return mMenuCollapseExpandEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuExpandCompoundsEnabled(bool enabled)
    {
        mMenuExpandCompoundsEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_EXPAND_COMPOUNDS);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuExpandCompoundsEnabled(void)
    {
        return mMenuExpandCompoundsEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuFisheyeViewEnabled(bool enabled)
    {
        mMenuFisheyeViewEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_FISHEY_VIEW);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuFisheyeViewEnabled(void)
    {
        return mMenuFisheyeViewEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setFisheyeView(bool enabled, qreal maxZoom, unsigned int steps)
    {
        mFisheyeViewEnabled = enabled;
        mFisheyeMaxZoom = maxZoom;
        mFisheyeSteps = steps;
    }

    //****************************************************************************/
    QGraphicsItem* QtNodeEditor::itemAtExceptActiveConnection(const QPointF& pos)
    {
        QList<QGraphicsItem*> items = mScene->items(QRectF(pos - QPointF(1,1), QSize(3,3)));
        bool isActive = isActiveConnection();

        foreach(QGraphicsItem* item, items)
        {
            // If there is an active connection, it is not returned as a selected item
            // Finalized (established) connections are returned
            if (item->isVisible())
            {
                if (isConnection(item))
                {
                    if (!isActive)
                        return item;
                }
                else
                    return item;
            }
        }

        return 0;
    }

    //****************************************************************************/
    QtCompoundNode* QtNodeEditor::nodeOverCompound(QtNode* node)
    {
        if (!node)
            return 0;

        QtCompoundNode* compound;
        QList<QGraphicsItem*> items = mScene->items();
        int subType;
        qreal halfWidth;
        foreach(QGraphicsItem* item, items)
        {
            if (isCompoundNode(item) && item->isVisible())
            {
                compound = static_cast<QtCompoundNode*>(item);
                if (node != compound && !compound->isSelected())
                {
                    halfWidth = 0.5 * compound->getWidth();
                    if (node->scenePos().x() > compound->scenePos().x() - halfWidth &&
                        node->scenePos().x() < compound->scenePos().x() + halfWidth &&
                        node->scenePos().y() > compound->scenePos().y() &&
                        node->scenePos().y() < compound->scenePos().y() + compound->getHeigth())
                    {
                        return compound;
                    }
                }
            }
        }

        return 0;
    }

    //****************************************************************************/
    bool QtNodeEditor::eventFilter(QObject* object, QEvent* event)
    {
        QGraphicsSceneMouseEvent* mouseEvent = (QGraphicsSceneMouseEvent*) event;
        QGraphicsItem* item = 0;
        switch ((int) event->type())
        {
            case QEvent::GraphicsSceneMousePress:
                mouseClickHandler(mouseEvent);
            break;

            case QEvent::GraphicsSceneMouseDoubleClick:
                mouseDoubleClickHandler(mouseEvent);
            break;

            case QEvent::GraphicsSceneMouseMove:
            {
                mouseMoveHandler(mouseEvent);
            }
            break;

            case QEvent::GraphicsSceneMouseRelease:
            {
                mouseReleaseHandler(mouseEvent);
            }
            break;
        }
        return QObject::eventFilter(object, event);
    }

    //****************************************************************************/
    bool QtNodeEditor::mouseClickHandler(QGraphicsSceneMouseEvent* mouseEvent)
    {
        switch ((int) mouseEvent->button())
        {
            case Qt::LeftButton:
            {
                QGraphicsItem* item = itemAtExceptActiveConnection(mouseEvent->scenePos());
                if (!item)
                {
                    // Left-click on the canvas, but no item clicked, so deselect nodes and connections
                    deselectAll();
                    mRubberbandSelection = true;
                    mLastMousePosition.setX(mouseEvent->lastScenePos().x());
                    mLastMousePosition.setY(mouseEvent->lastScenePos().y());
                    return true;
                }
                mRubberbandSelection = false;

                // Delegate to the node; either the node itself is clicked, one of its children or a connection
                QtNode* node;
                int type = 0;
                if (item->data(NODE_KEY_GRAPHIC_ITEM_TYPE).isValid())
                {
                    type = item->data(NODE_KEY_GRAPHIC_ITEM_TYPE).toInt();
                    if (NODE_VALUE_TYPE_CONNECTION == type)
                    {
                        // ======================= Handle selected connection =======================
                        QtConnection* connection = static_cast<QtConnection*>(item);
                        selectConnection(connection);
                    }
                    else if (NODE_VALUE_TYPE_NODE == type)
                    {
                        // ======================= The node itself is clicked =======================
                        node = static_cast<QtNode*>(item);
                        selectNode(node, mouseEvent);
                    }
                    else if (NODE_VALUE_TYPE_HEADER_ICON == type || NODE_VALUE_TYPE_HEADER_TITLE == type)
                    {
                        // ======================= The header title or header icon is clicked =======================
                        node = static_cast<QtNode*>(item->parentItem());
                        selectNode(node, mouseEvent);
                    }
                    else
                    {
                        // A child item of the node is clicked
                        deselectNodes();
                        deselectConnections();
                        node = static_cast<QtNode*>(item->parentItem());

                        if (NODE_VALUE_TYPE_PORT == type)
                        {
                            // ======================= Port is clicked =======================
                            // Either make a connection to another port, or create a new connection
                            QtNode* baseNode = getNodeWithActiveConnection();
                            if (baseNode == 0)
                            {
                                // There is no active connection, so start one
                                node->mouseLeftClickHandler(mouseEvent, item, NODE_ACTION_BASE);
                                setCursor(Qt::ClosedHandCursor);
                            }
                            else if (baseNode != node)
                            {
                                // There is an active connection and the selected port is not part of the baseNode,
                                // so try to establish a connection with the other node
                                if (node->mouseLeftClickHandler(mouseEvent, item, NODE_ACTION_TARGET, baseNode->mActiveConnection))
                                {
                                    // The connection was established, so the active connection on the basenode can be set to 0
                                    baseNode->mActiveConnection = 0;
                                    setCursor(Qt::ArrowCursor);
                                }
                            }
                        }
                        else
                        {
                            node->mouseLeftClickHandler(mouseEvent, item); // Don't do anything with the node after this; it may be deleted
                        }
                    }
                    return true;
                }
            }
            break;

            case Qt::RightButton:
            {
                if (mContextMenuEnabled)
                {
                    QPoint pos;
                    pos.setX(mouseEvent->lastScreenPos().x());
                    pos.setY(mouseEvent->lastScreenPos().y());
                    showContextMenu(pos);
                }
                else
                    deselectAll();

                return true;
            }
            break;
        }

        //mouseEvent->accept();
        return true;
    }