1 /***************************************************************************
2 * Copyright (C) 2005 by David Cuadrado *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include <QHeaderView>
23 #include <QVBoxLayout>
24 #include <QButtonGroup>
27 #include <dgui/application.h>
28 #include <dcore/debug.h>
29 #include <dgui/iconloader.h>
31 #include <yamf/model/scene.h>
32 #include <yamf/model/layer.h>
33 #include <yamf/model/frame.h>
34 #include <yamf/model/library.h>
35 #include <yamf/model/libraryobject.h>
38 #include "dash/datasource.h"
39 #include "dash/project.h"
42 #include <QXmlStreamReader>
48 struct TimeLine::Private
50 Private(TimeLine
*q
) : q(q
), tlWidget(0) {}
54 TimeLineWidget
*tlWidget
;
56 void updateScene( const Dash::DataSource
* datasource
, bool undo
)
58 int visualIndex
= datasource
->values("location")["scene"].toInt();
60 QString root
= datasource
->values("command")["name"];
61 if( root
== "insertscene")
65 tlWidget
->removeScene(visualIndex
);
69 tlWidget
->insertScene(visualIndex
, datasource
->values("scene")["name"]);
70 tlWidget
->setScene(visualIndex
);
73 else if(root
== "removescene")
78 YAMF::Model::Scene
*scene
= q
->project()->scene(visualIndex
);
80 tlWidget
->insertScene(visualIndex
, scene
->sceneName());
82 foreach(YAMF::Model::Layer
*layer
, scene
->layers().values())
84 int layerIndex
= layer
->visualIndex();
85 tlWidget
->insertLayer(visualIndex
, layerIndex
, layer
->layerName());
87 tlWidget
->setLayerVisibility(visualIndex
, layerIndex
, layer
->isVisible());
88 tlWidget
->setLayerLocked(visualIndex
, layerIndex
, layer
->isLocked());
90 foreach(YAMF::Model::Frame
*frame
, layer
->frames().values())
92 tlWidget
->insertFrame(visualIndex
, layerIndex
, frame
->visualIndex(), frame
->frameName());
94 tlWidget
->setFrameVisibility(visualIndex
, layerIndex
, frame
->visualIndex(), frame
->isVisible());
95 tlWidget
->setFrameLocked(visualIndex
, layerIndex
, frame
->visualIndex(),frame
->isLocked());
98 tlWidget
->setScene(visualIndex
);
102 tlWidget
->removeScene(visualIndex
);
105 else if(root
== "movescene")
107 int to
= datasource
->values("information")["to"].toInt();
108 int from
= datasource
->values("information")["from"].toInt();
112 tlWidget
->moveScene(to
, from
);
113 tlWidget
->setScene(from
);
117 tlWidget
->moveScene(from
, to
);
118 tlWidget
->setScene(to
);
121 else if(root
== "renamescene")
123 tlWidget
->blockSignals(true);
126 tlWidget
->renameScene(datasource
->values("location")["scene"].toInt(), datasource
->values("information")["oldname"]);
130 tlWidget
->renameScene(datasource
->values("location")["scene"].toInt(), datasource
->values("information")["newname"]);
132 tlWidget
->blockSignals(false);
136 void updateLayer( const Dash::DataSource
* datasource
, bool undo
)
138 int index
= datasource
->values("location")["layer"].toInt();
139 QString root
= datasource
->values("command")["name"];
141 if(root
== "insertlayer")
143 int scene
= datasource
->values("location")["scene"].toInt();
144 int type
= datasource
->values("layer")["type"].toInt();
148 tlWidget
->removeLayer(scene
, index
);
154 case YAMF::Model::Layer::Vectorial
:
156 tlWidget
->insertLayer(scene
, index
, datasource
->values("layer")["name"]);
157 tlWidget
->setLayer(scene
, index
);
160 case YAMF::Model::Layer::Audio
:
162 tlWidget
->insertAudioLayer(scene
, index
, datasource
->values("layer")["name"], 0);
163 tlWidget
->setLayer(scene
, index
);
168 else if(root
== "removelayer")
170 int sceneIndex
= datasource
->values("location")["scene"].toInt();
171 // int type = datasource->values("layer")["type"].toInt();
175 YAMF::Model::Scene
*scene
= q
->project()->scene(sceneIndex
);
176 YAMF::Model::Layer
*layer
= scene
->layer( index
);
178 tlWidget
->insertLayer(sceneIndex
, index
, layer
->layerName());
180 foreach(YAMF::Model::Frame
*frame
, layer
->frames().values())
182 tlWidget
->insertFrame(sceneIndex
, index
, frame
->visualIndex(), frame
->frameName());
184 tlWidget
->setFrameVisibility(sceneIndex
, index
, frame
->visualIndex(), frame
->isVisible());
185 tlWidget
->setFrameLocked(sceneIndex
, index
, frame
->visualIndex(),frame
->isLocked());
188 tlWidget
->setLayer(sceneIndex
, index
);
192 tlWidget
->removeLayer(sceneIndex
, index
);
195 else if( root
== "locklayer")
197 int scene
= datasource
->values("location")["scene"].toInt();
198 bool locked(datasource
->values("information")["locked"].toInt());
202 tlWidget
->setLayerLocked(scene
, index
, !locked
);
206 tlWidget
->setLayerLocked(scene
, index
, locked
);
209 else if( root
== "changelayervisibility")
211 int scene
= datasource
->values("location")["scene"].toInt();
213 bool visible(datasource
->values("information")["visible"].toInt());
217 tlWidget
->setLayerVisibility(scene
, index
, !visible
);
221 tlWidget
->setLayerVisibility(scene
, index
, visible
);
224 else if(root
== "movelayer")
226 int scene
= datasource
->values("location")["scene"].toInt();
228 int from
= datasource
->values("information")["from"].toInt();
229 int to
= datasource
->values("information")["to"].toInt();
233 tlWidget
->moveLayer(scene
, to
, from
);
235 tlWidget
->setLayer(scene
, to
);
239 tlWidget
->moveLayer(scene
, from
, to
);
241 tlWidget
->setLayer(scene
, to
);
245 else if(root
== "renamelayer")
247 int scene
= datasource
->values("location")["scene"].toInt();
248 int index
= datasource
->values("location")["layer"].toInt();
250 tlWidget
->blockSignals(true);
253 tlWidget
->renameLayer(scene
, index
, datasource
->values("information")["oldname"]);
257 tlWidget
->renameLayer(scene
, index
, datasource
->values("information")["newname"]);
259 tlWidget
->blockSignals(false);
263 void updateFrame( const Dash::DataSource
* datasource
, bool undo
)
265 int visualIndex
= datasource
->values("location")["frame"].toInt();
267 QString root
= datasource
->values("command")["name"];
268 if(root
== "insertframe")
270 int scene
= datasource
->values("location")["scene"].toInt();
271 int layer
= datasource
->values("location")["layer"].toInt();
275 tlWidget
->removeFrame(scene
, layer
, visualIndex
);
279 tlWidget
->insertFrame(scene
, layer
, visualIndex
, datasource
->values("frame")["name"]);
280 tlWidget
->setFrame(scene
, layer
, visualIndex
);
283 else if(root
== "removeframe")
285 int sceneIndex
= datasource
->values("location")["scene"].toInt();
286 int layerIndex
= datasource
->values("location")["layer"].toInt();
290 tlWidget
->insertFrame(sceneIndex
, layerIndex
, visualIndex
, datasource
->values("frame")["name"]);
294 tlWidget
->removeFrame(sceneIndex
, layerIndex
, visualIndex
);
297 else if( root
== "lockframe")
299 int scene
= datasource
->values("location")["scene"].toInt();
300 int layer
= datasource
->values("location")["layer"].toInt();
302 bool locked(datasource
->values("information")["locked"].toInt());
306 tlWidget
->setFrameLocked(scene
, layer
, visualIndex
, !locked
);
310 tlWidget
->setFrameLocked(scene
, layer
, visualIndex
, locked
);
313 else if( root
== "changeframevisibility")
315 int scene
= datasource
->values("location")["scene"].toInt();
316 int layer
= datasource
->values("location")["layer"].toInt();
318 bool visible(datasource
->values("information")["visible"].toInt());
322 tlWidget
->setFrameVisibility(scene
, layer
, visualIndex
, !visible
);
326 tlWidget
->setFrameVisibility(scene
, layer
, visualIndex
, visible
);
329 else if(root
== "moveframe")
331 int scene
= datasource
->values("location")["scene"].toInt();
332 int layer
= datasource
->values("location")["layer"].toInt();
334 int from
= datasource
->values("information")["from"].toInt();
335 int to
= datasource
->values("information")["to"].toInt();
337 dfDebug
<< "move from " << from
<< " to " << to
;
341 tlWidget
->moveFrame(scene
, layer
, to
, from
);
342 tlWidget
->setFrame(scene
, layer
, from
);
346 tlWidget
->moveFrame(scene
, layer
, from
, to
);
347 tlWidget
->setFrame(scene
, layer
, to
);
351 else if(root
== "renameframe")
353 tlWidget
->blockSignals(true);
354 int scene
= datasource
->values("location")["scene"].toInt();
355 int layer
= datasource
->values("location")["layer"].toInt();
359 tlWidget
->renameFrame(scene
, layer
, datasource
->values("location")["frame"].toInt(), datasource
->values("information")["oldname"]);
363 tlWidget
->renameFrame(scene
, layer
, datasource
->values("location")["frame"].toInt(), datasource
->values("information")["newname"]);
365 tlWidget
->blockSignals(false);
367 else if(root
== "expandframe")
369 int scene
= datasource
->values("location")["scene"].toInt();
370 int layer
= datasource
->values("location")["layer"].toInt();
371 int size
= datasource
->values("information")["size"].toInt();
375 for(int i
= 0; i
< size
; i
++)
377 tlWidget
->removeFrame(scene
, layer
, visualIndex
+1);
379 tlWidget
->destroyGroupFrames(scene
, layer
, visualIndex
, size
);
383 for(int i
= 1; i
< size
+1; i
++)
385 tlWidget
->insertFrame(scene
, layer
, visualIndex
+i
, datasource
->values("information")["name"]);
386 tlWidget
->setFrame(scene
, layer
, visualIndex
+i
);
388 tlWidget
->groupFrames(scene
, layer
, visualIndex
, visualIndex
+size
);
398 TimeLine::TimeLine(Dash::Project
*const project
, QWidget
*parent
) : Widget(project
, parent
), d(new Private(this))
400 QVBoxLayout
*layout
= new QVBoxLayout(this);
401 setWindowTitle(tr("&Time Line"));
402 setWindowIcon( DGui::IconLoader::self()->load("time_line.png"));
403 d
->tlWidget
= new TimeLineWidget(this);
404 layout
->addWidget(d
->tlWidget
);
406 connect(d
->tlWidget
, SIGNAL(postEvent(const TimeLineWidget::Event
&)), this, SLOT(onEvent(const TimeLineWidget::Event
&)));
407 connect(d
->tlWidget
, SIGNAL(frameSelected(int , int , int)), this, SLOT(onFrameSelected(int , int , int)));
414 TimeLine::~TimeLine()
421 * Retorna los espacios de trabajo donde sera visible el componente, este componente sera visible en todos los espacios de trabajo.
423 Dash::Workspace
TimeLine::workspace() const
430 * Retorna la posición inicial del componente, la cual es en la parte abajo de la ventana principal.
432 Qt::DockWidgetArea
TimeLine::area() const
434 return Qt::BottomDockWidgetArea
;
440 * Retorna el tipo de comandos de los interesa que el componente sea notificado de su ejecución, para este componente se notificara de la ejecución todos los comandos.
442 Dash::DataSource::Types
TimeLine::sources() const
444 Dash::DataSource::Type type
= Dash::DataSource::All
;
450 * Actualiza el componente despues de la ejecución de un comando.
452 void TimeLine::update(const Dash::DataSource
*datasource
, bool undo
)
455 // dfDebug << datasource->data("root").toString();
456 // dfDebug << datasource->values("location")["index"];
457 // dfDebug << "xml" << datasource->data("xml").toString();
459 switch (datasource
->type())
461 case DataSource::Scene
:
463 d
->updateScene(datasource
, undo
);
466 case DataSource::Layer
:
468 d
->updateLayer(datasource
, undo
);
471 case DataSource::Frame
:
473 d
->updateFrame(datasource
, undo
);
476 case DataSource::Library
:
477 case DataSource::Project
:
478 case DataSource::Object
:
479 case DataSource::Unknown
:
481 dfDebug
<< "Unhandled package: " << datasource
->values("command")["name"];
493 * Reinicia el componente, borra todas las escenas, frames y layers.
495 void TimeLine::reset()
497 d
->tlWidget
->closeAllScenes();
503 void TimeLine::onFrameSelected(int scenePos
, int layerPos
, int framePos
)
505 emit
frameSelected(scenePos
, layerPos
, framePos
);
511 void TimeLine::onEvent(const TimeLineWidget::Event
&event
)
513 dfDebug
<< "scene = " << event
.scene
<< " layer = " << event
.layer
<< " frame = " << event
.frame
<< " action " << event
.action
<< " data " << event
.data
.toString();
517 case TimeLineWidget::InsertFrame
:
519 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
522 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
525 layer
->createFrame(event
.frame
);
530 case TimeLineWidget::RemoveFrame
:
532 if(event
.scene
> -1 && event
.layer
> -1 && event
.frame
> -1)
534 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
537 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
540 YAMF::Model::Frame
*frame
= layer
->frame(event
.frame
);
543 layer
->removeFrame(frame
);
549 case TimeLineWidget::CopyFrame
:
551 project()->copyFrameToClipboard(event
.scene
, event
.layer
, event
.frame
);
554 case TimeLineWidget::PasteFrame
:
556 project()->pasteFrameFromClipboard(event
.scene
, event
.layer
, event
.frame
);
559 case TimeLineWidget::CutFrame
:
561 project()->cutFrame(event
.scene
, event
.layer
, event
.frame
);
564 case TimeLineWidget::MoveFrameUp
:
566 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
567 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
569 YAMF::Model::Frame
*frame
= layer
->frame(event
.frame
);
572 // int nclones = layer->clones(frame);
573 layer
->moveFrame(frame
->visualIndex(), frame
->visualIndex()-1);
577 case TimeLineWidget::MoveFrameDown
:
579 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
580 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
581 YAMF::Model::Frame
*frame
= layer
->frame(event
.frame
);
585 int nclones
= layer
->clones(frame
);
586 layer
->moveFrame(frame
->visualIndex(), frame
->visualIndex()+nclones
+1);
590 case TimeLineWidget::LockFrame
:
592 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
593 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
594 YAMF::Model::Frame
*frame
= layer
->frame(event
.frame
);
595 frame
->setLocked(event
.data
.toBool());
598 case TimeLineWidget::RenameFrame
:
602 case TimeLineWidget::ChangeFrameVisibility
:
604 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
605 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
606 YAMF::Model::Frame
*frame
= layer
->frame(event
.frame
);
607 frame
->setVisible(event
.data
.toBool());
610 case TimeLineWidget::ExpandFrame
:
612 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
613 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
614 layer
->expandFrame(event
.frame
, event
.data
.toInt());
617 case TimeLineWidget::InsertLayer
:
619 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
622 YAMF::Model::Layer
*layer
= scene
->createLayer( event
.layer
+1 );
625 layer
->createFrame();
630 case TimeLineWidget::RemoveLayer
:
632 if(event
.scene
> -1 && event
.layer
> -1)
634 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
635 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
636 scene
->removeLayer(layer
);
640 case TimeLineWidget::MoveLayerUp
:
642 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
643 scene
->moveLayer(event
.layer
, event
.layer
-1);
646 case TimeLineWidget::MoveLayerDown
:
648 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
649 scene
->moveLayer(event
.layer
, event
.layer
+1);
652 case TimeLineWidget::LockLayer
:
654 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
655 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
656 layer
->setLocked(event
.data
.toBool());
659 case TimeLineWidget::RenameLayer
:
661 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
662 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
663 layer
->setLayerName(event
.data
.toString());
666 case TimeLineWidget::ChangeLayerVisibility
:
668 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
669 YAMF::Model::Layer
*layer
= scene
->layer(event
.layer
);
670 layer
->setVisible(event
.data
.toBool());
674 case TimeLineWidget::InsertScene
:
676 YAMF::Model::Scene
*scene
= project()->createScene(event
.scene
+1);
677 YAMF::Model::Layer
*layer
= scene
->createLayer();
678 layer
->createFrame();
681 case TimeLineWidget::RemoveScene
:
685 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
688 project()->removeScene(scene
);
693 case TimeLineWidget::MoveSceneUp
:
695 project()->moveScene(event
.scene
, event
.scene
-1);
698 case TimeLineWidget::MoveSceneDown
:
700 project()->moveScene(event
.scene
, event
.scene
+1);
703 case TimeLineWidget::LockScene
:
705 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
706 scene
->setLocked(event
.data
.toBool());
709 case TimeLineWidget::RenameScene
:
711 YAMF::Model::Scene
*scene
= project()->scene(event
.scene
);
712 scene
->setSceneName(event
.data
.toString());