From ff043a5990583242e83b1cf11697a77f35af7198 Mon Sep 17 00:00:00 2001 From: Jorge Cuadrado Date: Thu, 25 Oct 2007 14:49:54 -0500 Subject: [PATCH] - Load group properly - Improved Polyline, Contour and Select tools --- yamf/model/command/processor.cpp | 3 +-- yamf/model/command/ungroupitem.cpp | 5 ++--- yamf/model/frame.cpp | 37 ++++++++++++++++++++++++++++++++++++- yamf/model/objectgroup.cpp | 1 - yamf/tools/polyline/polyline.cpp | 11 +++++++++++ yamf/tools/polyline/polyline.h | 2 +- yamf/tools/selection/contour.cpp | 28 +++++++++++++++------------- yamf/tools/selection/select.cpp | 18 ++++++++++++++++-- 8 files changed, 82 insertions(+), 23 deletions(-) diff --git a/yamf/model/command/processor.cpp b/yamf/model/command/processor.cpp index d3e75a0..9a2553c 100644 --- a/yamf/model/command/processor.cpp +++ b/yamf/model/command/processor.cpp @@ -599,7 +599,6 @@ bool Processor::execute(const QString &xml) if( reader.name().toString() == "information" ) { QString str = reader.attributes().value("items").toString(); - dfDebug << str; QString::const_iterator istr = str.constBegin(); QList pts = Item::Private::Svg2Qt::parseIntList( istr ); @@ -796,7 +795,7 @@ bool Processor::execute(const QString &xml) dWarning() << "Unhandled command: " << command; } - dfDebug << ret; + D_SHOW_VAR(ret); return ret; } diff --git a/yamf/model/command/ungroupitem.cpp b/yamf/model/command/ungroupitem.cpp index 029a2b5..77a6374 100644 --- a/yamf/model/command/ungroupitem.cpp +++ b/yamf/model/command/ungroupitem.cpp @@ -48,8 +48,8 @@ struct UngroupItem::Private UngroupItem::UngroupItem(Item::Group *group, Model::Frame *frame) : Base(), d(new Private) { setText(QObject::tr("Ungroup items")); - d->group = static_cast(frame->graphic(frame->visualIndexOf(group))); + d->objects = d->group->children(); d->frame = frame; @@ -117,7 +117,6 @@ void UngroupItem::writeCommandBody(QXmlStreamWriter *writer) const QString indices; - indices += "("; QList::iterator it = d->objects.begin(); @@ -126,7 +125,7 @@ void UngroupItem::writeCommandBody(QXmlStreamWriter *writer) const if(it != d->objects.end()-1) indices += QString("%1,").arg((*it)->visualIndex()); else - indices += QString("%1)").arg((*it)->visualIndex()); + indices += QString("%1").arg((*it)->visualIndex()); ++it; } diff --git a/yamf/model/frame.cpp b/yamf/model/frame.cpp index 01e40a8..166002c 100644 --- a/yamf/model/frame.cpp +++ b/yamf/model/frame.cpp @@ -36,9 +36,13 @@ #include "model/command/renameframe.h" #include "model/library.h" +#include "model/object.h" +#include "model/objectgroup.h" + #include "item/group.h" #include "item/tweener.h" + namespace YAMF { namespace Model { @@ -55,6 +59,28 @@ struct Frame::Private int repeat; int objectCount; + + ObjectGroup *createObjectGroup(Frame *frame , QGraphicsItem *item) + { + ObjectGroup *oGroup = new ObjectGroup(frame); + if(Item::Group *group = static_cast(item)) + { + foreach(QGraphicsItem *child, group->childs()) + { + if(child->type() == Item::Group::Type) + { + oGroup->addToGroup(createObjectGroup(frame, child)); + } + else + { + Object *object = new Object(child, frame); + oGroup->addToGroup(object); + } + } + } + return oGroup; + } + }; /** @@ -566,7 +592,16 @@ void Frame::fromXml(const QString &xml ) Object *last = new Object(this); last->fromXml(objectXml); - addObject(last); + + if(last->item()->type() == Item::Group::Type) + { + ObjectGroup *oGroup = d->createObjectGroup(this, last->item()); + addObject(oGroup); + } + else + { + addObject(last); + } } } diff --git a/yamf/model/objectgroup.cpp b/yamf/model/objectgroup.cpp index 10dedc3..ae38b8d 100644 --- a/yamf/model/objectgroup.cpp +++ b/yamf/model/objectgroup.cpp @@ -65,7 +65,6 @@ void ObjectGroup::removeFromGroup(Object *object) object->frame()->attach(object); } - } } diff --git a/yamf/tools/polyline/polyline.cpp b/yamf/tools/polyline/polyline.cpp index 8de6242..380f511 100644 --- a/yamf/tools/polyline/polyline.cpp +++ b/yamf/tools/polyline/polyline.cpp @@ -46,6 +46,8 @@ #include #include +#include + namespace YAMF { namespace Drawing { @@ -333,6 +335,15 @@ void PolyLine::doubleClick(const QGraphicsSceneMouseEvent *input, PaintArea *con } +void PolyLine::keyPressEvent(QKeyEvent *event) +{ + if(event->key() == Qt::Key_Escape) + { + endItem(); + event->accept(); + } +} + /** * @~spanish * Retorna la acción que representa la herramienta. diff --git a/yamf/tools/polyline/polyline.h b/yamf/tools/polyline/polyline.h index 3480b0d..bd1a02e 100644 --- a/yamf/tools/polyline/polyline.h +++ b/yamf/tools/polyline/polyline.h @@ -51,7 +51,7 @@ class YAMF_EXPORT PolyLine : public Drawing::AbstractTool virtual void move(const QGraphicsSceneMouseEvent *input, PaintArea *const paintArea); virtual void release(const QGraphicsSceneMouseEvent *input, PaintArea *const paintArea); virtual void doubleClick(const QGraphicsSceneMouseEvent *input, PaintArea *const paintArea); - + void keyPressEvent(QKeyEvent *event); virtual DGui::Action *action() const; int type() const; diff --git a/yamf/tools/selection/contour.cpp b/yamf/tools/selection/contour.cpp index cf92eda..3014700 100644 --- a/yamf/tools/selection/contour.cpp +++ b/yamf/tools/selection/contour.cpp @@ -160,22 +160,24 @@ void Contour::release(const QGraphicsSceneMouseEvent *input, PaintArea *const pa } else { - Command::ConvertItem *convertItem = new Command::ConvertItem(item, Item::Path::Type, paintArea->currentFrame()); - paintArea->addCommand(convertItem); - - if(convertItem->isValid()) + if(item->type() != QGraphicsItemGroup::Type) { - if(Item::Path *path = qgraphicsitem_cast( paintArea->currentFrame()->item(index) ) ) + Command::ConvertItem *convertItem = new Command::ConvertItem(item, Item::Path::Type, paintArea->currentFrame()); + paintArea->addCommand(convertItem); + + if(convertItem->isValid()) { - d->editors << new Drawing::Tool::Private::ContourEditor(path, paintArea->photogram()); - } - else if(Item::Proxy *proxy = qgraphicsitem_cast( paintArea->currentFrame()->item(index) )) - { - if(Item::Path *path = qgraphicsitem_cast( proxy->item() ) ) + if(Item::Path *path = qgraphicsitem_cast( paintArea->currentFrame()->item(index) ) ) + { + d->editors << new Drawing::Tool::Private::ContourEditor(path, paintArea->photogram()); + } + else if(Item::Proxy *proxy = qgraphicsitem_cast( paintArea->currentFrame()->item(index) )) { - d->editors << new Drawing::Tool::Private::ContourEditor(path, paintArea->photogram()); - - d->editors.last()->setProxyItem(proxy); + if(Item::Path *path = qgraphicsitem_cast( proxy->item() ) ) + { + d->editors << new Drawing::Tool::Private::ContourEditor(path, paintArea->photogram()); + d->editors.last()->setProxyItem(proxy); + } } } } diff --git a/yamf/tools/selection/select.cpp b/yamf/tools/selection/select.cpp index 8c50228..4ef0a34 100644 --- a/yamf/tools/selection/select.cpp +++ b/yamf/tools/selection/select.cpp @@ -218,9 +218,17 @@ void Select::photogramChanged(Photogram *const photogram) { if(photogram->selectedItems().count() > 0) { + QList seleceteds = photogram->selectedItems(); foreach(DGraphics::ItemTransformer *transformer, d->transformers) { - transformer->show(); + if(seleceteds.contains(transformer->item())) + { + transformer->show(); + } + else + { + d->transformers.removeAll(transformer); + } } } else @@ -248,11 +256,17 @@ int Select::type() const return AbstractTool::Selection; } +/** + * @~spanish + * Elimina los nodos cuando se cambia de herramienta. + */ void Select::aboutToChangeTool() { - + qDeleteAll(d->transformers); + d->transformers.clear(); } + } } } -- 2.11.4.GIT