예제 #1
0
void ULLineEditor::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent )
{
	if ( itemAt ( mouseEvent->scenePos() ) )
	{
		QGraphicsItem * it =itemAt ( mouseEvent->scenePos() );
		it->isSelected() ? it->setSelected ( false ) : it->setSelected ( true );
	}
	else
	{
		mouseSelectBegin = mouseEvent->scenePos();
		mouseSelect = true;
		mouseSelectRect->setPos ( mouseEvent->pos() );
		addItem ( mouseSelectRect );
	}
}
예제 #2
0
void AxisInteractor::showContextMenu(const QPoint &pos)
{
    QPoint globalPos = this->mapToGlobal(pos);
    QList<QGraphicsItem *> list = this->scene->items();
    for (int i = 0; i < list.count(); ++i)
    {
        QGraphicsItem *item = list.at(i);
        if (item->type() == IndicatorItemType)
        {
            if (item->isUnderMouse())
            {
                item->setSelected(false);
                this->createContextMenu();
                QAction *selectedItem = this->indicatorContextMenu->exec(globalPos);
                if (selectedItem)
                {
                    if (QString("Delete") == selectedItem->text())
                    {
                        this->scene->removeItem(item);
                        emit this->deleteIndicator(item->toolTip());
                    }
                    if (QString("Hide") == selectedItem->text())
                    {
                        bool isVisible = !selectedItem->isChecked();
                        emit this->showOrHideIndicator(isVisible, item->toolTip());
                        static_cast<Indicator *>(item)->changeIndicatorColor(isVisible);
                    }
                }
            }
        }
    }
}
예제 #3
0
void SCnEditorScene::unselectItems()
{
    QList<QGraphicsItem*> items = selectedItems();
    QGraphicsItem *item = 0;
    foreach(item, items)
        item->setSelected(false);
}
예제 #4
0
void TupGraphicsScene::addGraphicObject(TupGraphicObject *object, double opacity)
{
    /*
    #ifdef K_DEBUG
       T_FUNCINFO;
    #endif
    */

        QGraphicsItem *item = object->item();
        k->onionSkin.opacityMap.insert(item, opacity);

        if (TupItemGroup *group = qgraphicsitem_cast<TupItemGroup *>(item))
            group->recoverChilds();

        if (! qgraphicsitem_cast<TupItemGroup *>(item->parentItem())) {

            item->setSelected(false);
            TupLayer *layer = k->scene->layer(k->framePosition.layer);

            if (layer) {

                TupFrame *frame = layer->frame(k->framePosition.frame);

                if (frame) {
                    item->setOpacity(opacity);
                    // k->objectCounter++;
                    addItem(item);
                }
            }
        } 
}
예제 #5
0
void TwoDModelScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
	if (mouseEvent->button() != Qt::LeftButton) {
		AbstractScene::mouseReleaseEvent(mouseEvent);
		return;
	}

	emit mouseReleased();

	// After dragging item may be null. We mustn`t select it in that case.
	QGraphicsItem *itemToSelect = nullptr;
	switch (mDrawingAction){
	case wall: {
		reshapeWall(mouseEvent);
		itemToSelect = mCurrentWall;
		mCurrentWall = nullptr;
		break;
	}
	case line: {
		reshapeLine(mouseEvent);
		itemToSelect = mCurrentLine;
		mCurrentLine = nullptr;
		break;
	}
	case stylus: {
		reshapeStylus(mouseEvent);
		itemToSelect = mCurrentStylus;
		mCurrentStylus = nullptr;
		break;
	}
	case ellipse: {
		reshapeEllipse(mouseEvent);
		itemToSelect = mCurrentEllipse;
		mCurrentEllipse = nullptr;
		break;
	}
	default:
		if (itemToSelect) {
			forReleaseResize(mouseEvent);
		}
		break;
	}

	if (itemToSelect) {
		itemToSelect->setSelected(true);
	}

	setMoveFlag(mouseEvent);

	for (RobotItem * const robotItem : mRobots) {
		setSceneRect(sceneRect().united(robotItem->sceneBoundingRect()));
	}

	update();
	AbstractScene::mouseReleaseEvent(mouseEvent);
}
예제 #6
0
void SchemaEditor::slotSelectAll()
{
  QList<QGraphicsItem*> all = _schemaGui->items();
  QGraphicsItem* el;
  GearGui* ggui;
  _schemaGui->setSelectionChangeBypass(true);
  foreach(el,all)
  {
    el->setSelected(true);
  }
예제 #7
0
void D2ModelScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
	mRobot->checkSelection();
	for (SensorItem *sensor : mRobot->sensors().values()) {
		if (sensor) {
			sensor->checkSelection();
		}
	}

	emit mouseReleased();

	// After dragging item may be null. We mustn`t select it in that case.
	QGraphicsItem *itemToSelect = nullptr;
	switch (mDrawingAction){
	case wall: {
		reshapeWall(mouseEvent);
		itemToSelect = mCurrentWall;
		mCurrentWall = nullptr;
		break;
	}
	case line: {
		reshapeLine(mouseEvent);
		itemToSelect = mCurrentLine;
		mCurrentLine = nullptr;
		break;
	}
	case stylus: {
		reshapeStylus(mouseEvent);
		itemToSelect = mCurrentStylus;
		mCurrentStylus = nullptr;
		break;
	}
	case ellipse: {
		reshapeEllipse(mouseEvent);
		itemToSelect = mCurrentEllipse;
		mCurrentEllipse = nullptr;
		break;
	}
	default:
		forReleaseResize(mouseEvent, mRobot->realBoundingRect());
		break;
	}

	if (itemToSelect) {
		itemToSelect->setSelected(true);
	}

	setMoveFlag(mouseEvent);

	setSceneRect(sceneRect().united(mRobot->sceneBoundingRect()));
	update();
	AbstractScene::mouseReleaseEvent(mouseEvent);
}
예제 #8
0
void AxisInteractor::clearSelections()
{
    QList<QGraphicsItem *> list = this->scene->selectedItems();
    for (int i = 0; i < list.count(); ++i)
    {
        QGraphicsItem *item = list.at(i);
        if (item->type() == IndicatorItemType)
        {
            item->setSelected(false);
        }
    }
}
bool CDiagramContextMenuHandler::onEvent(CDiagramPrivateData *p, QEvent *evt)
{
    QMenu                           *menu = NULL;
    bool							r = false;
    QGraphicsItem                   *item = NULL;
    QList<QGraphicsItem*>           items;
    CDiagram						*d = NULL;
	QGraphicsSceneContextMenuEvent	*event = NULL;

	if (!p)
		return r;

	d = p->m_d;
	switch(evt->type())
	{
	case QEvent::GraphicsSceneContextMenu:
		event = static_cast<QGraphicsSceneContextMenuEvent*>(evt);
    items = d->items( event->scenePos());
    foreach (item, items)
    {
        if (item)
        {
            d->sendEvent(item, event);
            break;
        }
    }

    if (!event->isAccepted())
		{
        menu = d->contextMenu(d->mode());
        if (!menu)
        {
            r = triggerMenu(d, event->screenPos());
        }
        else
        {
            menu->exec(event->screenPos());
            r = true;
        }
    }
    else
        {
            item->setSelected(true);
        }
		break;

	default:
		break;
	}; // End of switch

	return r;
}
예제 #10
0
/**
 * @brief Receives a mouse press event.
 * @param event The event to handle.
 */
void TilesetView::mousePressEvent(QMouseEvent* event) {

  if (model == nullptr) {
    return;
  }

  if (state == State::NORMAL) {

    QList<QGraphicsItem*> items_under_mouse = items(
          QRect(event->pos(), QSize(1, 1)),
          Qt::IntersectsItemBoundingRect  // Pick transparent items too.
    );
    QGraphicsItem* item = items_under_mouse.empty() ? nullptr : items_under_mouse.first();

    const bool control_or_shift = (event->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier));

    bool keep_selected = false;
    if (control_or_shift) {
      // If ctrl or shift is pressed, keep the existing selection.
      keep_selected = true;
    }
    else if (item != nullptr && item->isSelected()) {
      // When clicking an already selected item, keep the existing selection too.
      keep_selected = true;
    }
    if (!keep_selected) {
      scene->clearSelection();
    }

    if (event->button() == Qt::LeftButton) {
      if (item != nullptr &&
          item->isSelected() &&
          model->get_selection_count() == 1 &&
          !is_read_only()) {
        // Clicking on an already selected item: allow to move it.
        start_state_moving_pattern(event->pos());
      }
      else {
        // Otherwise initialize a selection rectangle.
        initially_selected_items = scene->selectedItems();
        start_state_drawing_rectangle(event->pos());
      }
    }
    else {
      if (item != nullptr && !item->isSelected()) {
        // Select the right-clicked item.
        item->setSelected(true);
      }
    }
  }
}
예제 #11
0
void AxisInteractor::selectIndicator(const QString &name)
{
    this->clearSelections();
    QList<QGraphicsItem *> list = this->scene->items();
    for (int i = 0; i < list.count(); ++i)
    {
        QGraphicsItem *item = list.at(i);
        if (item->type() == IndicatorItemType)
        {
            if (item->toolTip() == name)
            {
                item->setSelected(true);
            }
        }
    }
}
예제 #12
0
void QGVScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
{
    QGraphicsItem *item = itemAt(contextMenuEvent->scenePos(), QTransform());
    if(item)
    {
        item->setSelected(true);
        if(item->type() == QGVNode::Type)
            emit nodeContextMenu(qgraphicsitem_cast<QGVNode*>(item));
        else if(item->type() == QGVEdge::Type)
            emit edgeContextMenu(qgraphicsitem_cast<QGVEdge*>(item));
        else if(item->type() == QGVSubGraph::Type)
            emit subGraphContextMenu(qgraphicsitem_cast<QGVSubGraph*>(item));
        else
            emit graphContextMenuEvent();
    }
    QGraphicsScene::contextMenuEvent(contextMenuEvent);
}
예제 #13
0
void SnapshotCanvas::contextMenuEvent(QContextMenuEvent *event)
{
    QGraphicsItem *item = itemAt(event->pos());
    if (item && item != m_pixmapItem) {
        deselectItems();
        item = item->topLevelItem();
        item->setSelected(true);
        if (item == m_zIndexList.last()) {
            m_contextMenu->actions().at(0)->setEnabled(false);
        } else {
            m_contextMenu->actions().at(0)->setEnabled(true);
        }
        if (item == m_zIndexList.first()) {
            m_contextMenu->actions().at(1)->setEnabled(false);
        } else {
            m_contextMenu->actions().at(1)->setEnabled(true);
        }
        m_contextMenu->exec(event->globalPos());
    }
}
예제 #14
0
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);
  }
}
예제 #15
0
void MainWindow::onNodesTreeItemClicked(QTreeWidgetItem *item, int column){
    if(item->type() != MODULE && item->type() != PORT )
        return;

    bool state = (item->checkState(column) == Qt::Checked);
    bool needUpdate = state != ((NodeWidgetItem*)(item))->checked();
    ((NodeWidgetItem*)(item))->check(state);
    if(needUpdate)
        drawGraph(*currentGraph);

    QList<QGraphicsItem *> items = scene->selectedItems();
    foreach( QGraphicsItem *item, items )
        item->setSelected(false);
    GraphicVertex* yv = (GraphicVertex*)((NodeWidgetItem*)(item))->getVertex();
    QGraphicsItem* graphicItem = (QGraphicsItem*) yv->getGraphicItem();
    if(graphicItem) {
        graphicItem->setSelected(true);
        if(state){
            ui->graphicsView->centerOn(graphicItem);
        }
    }
}
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;
    }
}
예제 #18
0
/**
 * @brief Receives a mouse release event.
 * @param event The event to handle.
 */
void TilesetView::mouseReleaseEvent(QMouseEvent* event) {

  if (model == nullptr) {
    return;
  }

  bool do_selection = false;
  if (state == State::DRAWING_RECTANGLE) {
    // If the rectangle is empty, consider it was a click and not a drag.
    // In this case we simply select the clicked item.
    do_selection = current_area_item->rect().isEmpty();
    end_state_drawing_rectangle();
  }
  else if (state == State::MOVING_PATTERN) {
    end_state_moving_pattern();
  }

  if (do_selection) {
    if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {

      // Left or right button: possibly change the selection.
      QList<QGraphicsItem*> items_under_mouse = items(
            QRect(event->pos(), QSize(1, 1)),
            Qt::IntersectsItemBoundingRect  // Pick transparent items too.
            );
      QGraphicsItem* item = items_under_mouse.empty() ? nullptr : items_under_mouse.first();

      const bool control_or_shift = (event->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier));

      bool keep_selected = false;
      if (control_or_shift) {
        // If ctrl or shift is pressed, keep the existing selection.
        keep_selected = true;
      }
      else if (item != nullptr && item->isSelected()) {
        // When clicking an already selected item, keep the existing selection too.
        keep_selected = true;
      }

      if (!keep_selected) {
        scene->clearSelection();
      }

      if (event->button() == Qt::LeftButton) {

        if (item != nullptr) {

          if (control_or_shift) {
            // Left-clicking an item while pressing control or shift: toggle it.
            item->setSelected(!item->isSelected());
          }
          else {
            if (!item->isSelected()) {
              // Select the item.
              item->setSelected(true);
            }
          }
        }
      }
    }
  }
}