void RectTool::onHandleMoved(const QPointF &pos, int handleFlags) { if (d->selectedLayerInfos.size() != 1) return; auto rectLayer = d->selectedLayerInfos.at(0).rectLayer; if (!rectLayer) return; QPointSet keys; auto rect = rectLayer->rect(); keys |= d->rectKeysWithHandleMargin(rect); auto scenePos = pos * canvas()->transforms()->windowToScene; double left = rect.left(); double right = rect.right(); double top = rect.top(); double bottom = rect.bottom(); if (handleFlags & Left) left = scenePos.x(); if (handleFlags & Right) right = scenePos.x(); if (handleFlags & Top) top = scenePos.y(); if (handleFlags & Bottom) bottom = scenePos.y(); if (right < left) { std::swap(left, right); for (RectHandleItem *handle : d->handles) handle->invertHandleFlagsLeftRight(); } if (bottom < top) { std::swap(top, bottom); for (RectHandleItem *handle : d->handles) handle->invertHandleFlagsTopBottom(); } rect.setCoords(left, top, right, bottom); keys |= d->rectKeysWithHandleMargin(rect); rectLayer->setRect(rect); emit requestUpdate(keys); updateGraphicsItems(); }
void RectTool::updateLayer(const LayerConstRef &layer) { for (auto &info : d->selectedLayerInfos) { if (info.original == layer) info.setOriginalLayer(layer); } updateGraphicsItems(); }
void BI_StrokeText::init() { mText->registerObserver(*this); mText->setAttributeProvider(&mBoard); mText->setFont(&getProject().getStrokeFonts().getFont( mBoard.getDefaultFontName())); // can throw mGraphicsItem.reset( new StrokeTextGraphicsItem(*mText, mBoard.getLayerStack())); mAnchorGraphicsItem.reset(new LineGraphicsItem()); updateGraphicsItems(); // connect to the "attributes changed" signal of the board connect(&mBoard, &Board::attributesChanged, this, &BI_StrokeText::boardAttributesChanged); }
void RectTool::cursorReleaseEvent(CanvasCursorEvent *event, int id) { Q_UNUSED(event); Q_UNUSED(id); if (d->mode == NoOperation) { event->ignore(); return; } d->updateManager->setEnabled(false); bool selectLater = false; if (d->dragDistanceEnough) { switch (d->mode) { case Dragging: { commit(); break; } case Inserting: { finishAdding(); break; } default: { break; } } } else if (d->mode == Inserting && d->selectingMode == SelectLater) { selectLater = true; } d->mode = NoOperation; updateGraphicsItems(); if (selectLater) { selectLayer(d->clickedLayer, d->clickedWithShift); } }
RectTool::RectTool(AddingType type, Canvas *canvas) : Tool(canvas), d(new Data) { d->layerController = canvas->findChild<LayerUIController *>(); d->updateManager = new CanvasUpdateManager(this); connect(d->updateManager, SIGNAL(updateTilesRequested(QPointSet)), this, SIGNAL(requestUpdate(QPointSet))); // set modes d->addingType = type; if (d->addingType == NoAdding) d->selectingMode = SelectImmediately; else d->selectingMode = SelectLater; // create graphics items { auto group = new QGraphicsItemGroup(); group->setHandlesChildEvents(false); setGraphicsItem(group); { auto frame = new FrameGraphicsItem(group); d->frameItem = frame; } } addHandle(Top | Left, 1); addHandle(Top | Right, 1); addHandle(Bottom | Left, 1); addHandle(Bottom | Right, 1); addHandle(Top, 0); addHandle(Bottom, 0); addHandle(Left, 0); addHandle(Right, 0); connect(layerScene(), SIGNAL(selectionChanged(QList<LayerConstRef>,QList<LayerConstRef>)), this, SLOT(updateSelected())); connect(layerScene(), SIGNAL(layerChanged(LayerConstRef)), this, SLOT(updateLayer(LayerConstRef))); connect(canvas, SIGNAL(transformsChanged(SP<const CanvasTransforms>)), this, SLOT(updateGraphicsItems())); updateSelected(); }
void RectTool::updateSelected() { auto layers = layerScene()->selection(); clearLayerDelegation(); d->selectedLayerInfos.clear(); for (const auto &layer : layers) { Data::LayerInfo info; info.setOriginalLayer(layer); if (layer->isType<AbstractRectLayer>() || layer->isType<RasterLayer>()) addLayerDelegation(layer); d->selectedLayerInfos << info; } updateGraphicsItems(); }
void RectTool::onHandleMoveFinished() { updateGraphicsItems(); commit(); }
void RectTool::cursorMoveEvent(CanvasCursorEvent *event, int id) { Q_UNUSED(id); if (d->mode == NoOperation) { event->ignore(); return; } auto delta = event->data.pos - d->dragStartPos; if ( d->dragDistanceEnough ) { switch (d->mode) { default: { break; } case Dragging: case Inserting: { QPointSet keys; if (d->mode == Dragging) { QRectF wholeRect; for (auto &info : d->selectedLayerInfos) { // rect layer if (info.rectLayer) { auto rect = info.rectLayer->rect(); wholeRect |= rect; rect.moveTopLeft(delta + info.originalRectPos); wholeRect |= rect; info.rectLayer->setRect(rect); } // raster layer else if (info.original->isType<RasterLayer>()) { wholeRect |= info.rasterBoundingRect.translated(info.rasterOffset); info.rasterOffset = delta.toQPoint(); wholeRect |= info.rasterBoundingRect.translated(info.rasterOffset); } } keys = d->rectKeysWithHandleMargin(wholeRect); } else // inserting { QRectF rect = d->layerToAdd->rect(); keys |= d->rectKeysWithHandleMargin(rect); auto p1 = d->dragStartPos, p2 = event->data.pos; rect.setLeft(std::min(p1.x(), p2.x())); rect.setRight(std::max(p1.x(), p2.x())); rect.setTop(std::min(p1.y(), p2.y())); rect.setBottom(std::max(p1.y(), p2.y())); keys |= d->rectKeysWithHandleMargin(rect); d->layerToAdd->setRect(rect); } d->updateManager->addTiles(keys); //emit requestUpdate(keys); updateGraphicsItems(); break; } } } else { if ( ( std::abs( delta.x() ) + std::abs( delta.y() ) ) >= qApp->startDragDistance() ) { d->dragDistanceEnough = true; if (d->mode == Inserting) startAdding(); } else return; } }
void BI_StrokeText::setFootprint(BI_Footprint* footprint) noexcept { mFootprint = footprint; updateGraphicsItems(); }
void BI_StrokeText::setSelected(bool selected) noexcept { BI_Base::setSelected(selected); mGraphicsItem->setSelected(selected); updateGraphicsItems(); }