NCL Composer  0.1.5
 All Classes Functions Variables Pages
extra/qnlycomposerplugin.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include "qnlycomposerplugin.h"
19 
20 namespace composer {
21 namespace plugin {
22 namespace layout {
23 
24 QnlyComposerPlugin::QnlyComposerPlugin(QObject* parent)
25 {
26  setParent(parent);
27 
28  createView();
29  createDocument();
30  createConnections();
31 }
32 
33 QnlyComposerPlugin::~QnlyComposerPlugin()
34 {
35 
36 }
37 
38 void QnlyComposerPlugin::createView()
39 {
40  view = new QnlyView();
41 }
42 
43 void QnlyComposerPlugin::createDocument()
44 {
45 
46 }
47 
48 void QnlyComposerPlugin::createConnections()
49 {
50  connect(view, SIGNAL(itemChanged(QString,QString,QMap<QString,QString>)), SLOT(changeRegion(QString,QString,QMap<QString,QString>)));
51 }
52 
54 {
55  return view;
56 }
57 
59 {
60 
61 }
62 
64 {
65 
66 }
67 
68 void QnlyComposerPlugin::errorMessage(QString error)
69 {
70 
71 }
72 
73 void QnlyComposerPlugin::onEntityAdded(QString pluginID, Entity *entity)
74 {
75  if (entity != NULL){
76  if (entity->getType() == "region")
77  {
78  qDebug() << "QnlyComposerPlugin::onEntityAdded (" << entity->getType();
79  addRegion(entity);
80 
81  }
82  else if (entity->getType() == "regionBase")
83  {
84  addRegionBase(entity);
85  }
86  }
87 }
88 
89 void QnlyComposerPlugin::onEntityRemoved(QString pluginID, QString entityID)
90 {
91 
92 }
93 
94 void QnlyComposerPlugin::onEntityChanged(QString pluginID, Entity *entity)
95 {
96  if (entity != NULL){
97  if (entity->getType() == "region"){
98  changeRegion(entity);
99 
100  }else if (entity->getType() == "regionBase"){
101  changeRegionBase(entity);
102  }
103  }
104 }
105 
106 void QnlyComposerPlugin::changeSelectedEntity (void*)
107 {
108 
109 }
110 
111 void QnlyComposerPlugin::addRegion(Entity* entity)
112 {
113  if (entity != NULL)
114  {
115  if (entity->getType() == "region")
116  {
117  // setting
118  QString entityUID;
119  if (!entity->getUniqueId().isEmpty())
120  {
121  entityUID = entity->getUniqueId();
122  }
123  else
124  {
125  qFatal("QnlyComposerPlugin::addRegion 1");
126  return; // cancelling addition
127  }
128 
129  QString regionUID;
130  regionUID = entityUID;
131 
132  QString parentregionUID;
133 
134  if (regions.contains(entity->getParentUniqueId()))
135  {
136  parentregionUID = entity->getParentUniqueId();
137  }
138  else
139  {
140  parentregionUID = "";
141  }
142 
143  QString regionbaseUID;
144  if (regions.contains(parentregionUID))
145  {
146  regionbaseUID = relations[parentregionUID];
147 
148  }
149  else if (regionbases.contains(entity->getParentUniqueId()))
150  {
151  regionbaseUID = entity->getParentUniqueId();
152 
153  }
154  else
155  {
156  qFatal("QnlyComposerPlugin::addRegion 2");
157  return; // cancelling addition
158  }
159 
160  QMap<QString, QString> attributes;
161 
162  if (!entity->getAttribute("id").isEmpty())
163  attributes["id"] = entity->getAttribute("id");
164 
165  if (!entity->getAttribute("title").isEmpty())
166  attributes["title"] = entity->getAttribute("title");
167 
168  if (!entity->getAttribute("zIndex").isEmpty())
169  attributes["zIndex"] = entity->getAttribute("zIndex");
170 
171  if (!entity->getAttribute("top").isEmpty())
172  attributes["top"] = entity->getAttribute("top");
173 
174  if (!entity->getAttribute("left").isEmpty())
175  attributes["left"] = entity->getAttribute("left");
176 
177  if (!entity->getAttribute("bottom").isEmpty())
178  attributes["bottom"] = entity->getAttribute("bottom");
179 
180  if (!entity->getAttribute("right").isEmpty())
181  attributes["right"] = entity->getAttribute("right");
182 
183  if (!entity->getAttribute("width").isEmpty())
184  attributes["width"] = entity->getAttribute("width");
185 
186  if (!entity->getAttribute("height").isEmpty())
187  attributes["height"] = entity->getAttribute("height");
188 
189  // adding
190  regions[regionUID] = entity;
191 
192  relations[regionUID] = regionbaseUID;
193 
194  qDebug() << "Calling view->addRegion";
195  view->addRegion(regionUID, parentregionUID, regionbaseUID,
196  attributes);
197  }
198  }
199 }
200 
201 void QnlyComposerPlugin::removeRegion(Entity* entity)
202 {
203  if (entity != NULL){
204  if (entity->getType() == "region"){
205  // setting
206  QString entityUID;
207 
208  if (!entity->getUniqueId().isEmpty()){
209  entityUID = entity->getUniqueId();
210 
211  }else{
212  return; // cancelling remotion
213  }
214 
215  QString regionUID;
216 
217  if (entities.contains(entityUID)){
218  regionUID = entities[entityUID];
219 
220  }else{
221  return; // cancelling remotion
222  }
223 
224  QString regionbaseUID;
225 
226  if (relations.contains(regionUID)){
227  regionbaseUID = relations[regionUID];
228 
229  }else{
230  return; // cancelling remotion
231  }
232 
233  view->removeRegion(regionUID, regionbaseUID);
234  }
235  }
236 }
237 
238 void QnlyComposerPlugin::selectRegion(Entity *entity)
239 {
240 
241 }
242 
243 void QnlyComposerPlugin::changeRegion(Entity *entity)
244 {
245  if (entity != NULL){
246  if (entity->getType() == "region"){
247  // setting
248  QString entityUID;
249 
250  if (!entity->getUniqueId().isEmpty()){
251  entityUID = entity->getUniqueId();
252 
253  }else{
254  return; // cancelling addition
255  }
256 
257  QString regionUID;
258 
259  if (regions.contains(entityUID)){
260  regionUID = entityUID;
261 
262  }else{
263  return; // canceling changing
264  }
265 
266  QString regionbaseUID;
267 
268  if (regionbases.contains(relations[regionUID])){
269  regionbaseUID = relations[regionUID];
270 
271  }else{
272  return; // canceling changing
273  }
274 
275  QMap<QString, QString> attributes;
276 
277  if (!entity->getAttribute("id").isEmpty()){
278  attributes["id"] = entity->getAttribute("id");
279 
280  }else{
281  // no default value
282  }
283 
284  if (!entity->getAttribute("title").isEmpty()){
285  attributes["title"] = entity->getAttribute("title");
286 
287  }else{
288  // no default value
289  }
290 
291  if (!entity->getAttribute("zIndex").isEmpty()){
292  attributes["zIndex"] = entity->getAttribute("zIndex");
293 
294  }else{
295  // no default value
296  }
297 
298  if (!entity->getAttribute("top").isEmpty()){
299  attributes["top"] = entity->getAttribute("top");
300 
301  }else{
302  // no default value
303  }
304 
305  if (!entity->getAttribute("left").isEmpty()){
306  attributes["left"] = entity->getAttribute("left");
307 
308  }else{
309  // no default value
310  }
311 
312  if (!entity->getAttribute("bottom").isEmpty()){
313  attributes["bottom"] = entity->getAttribute("bottom");
314 
315  }else{
316  // no default value
317  }
318 
319  if (!entity->getAttribute("right").isEmpty()){
320  attributes["right"] = entity->getAttribute("right");
321 
322  }else{
323  // no default value
324  }
325 
326  if (!entity->getAttribute("width").isEmpty()){
327  attributes["width"] = entity->getAttribute("width");
328 
329  }else{
330  // no default value
331  }
332 
333  if (!entity->getAttribute("height").isEmpty()){
334  attributes["height"] = entity->getAttribute("height");
335 
336  }else{
337  // no default value
338  }
339 
340  // adding
341  view->changeRegion(regionUID, regionbaseUID, attributes);
342  }
343  }
344 }
345 
346 void QnlyComposerPlugin::addRegion(const QString regionUID, const QString parentregionUID, const QString regionbaseUID, const QMap<QString, QString> &attributes)
347 {
348  if (!regions.contains(regionUID) && regionbases.contains(regionbaseUID)){
349  // setting
350  QMap<QString, QString> standard;
351 
352  if (attributes.contains("id")){
353  standard["id"] = attributes["id"];
354 
355  }else{
356  // no default value
357  }
358 
359  if (attributes.contains("title")){
360  standard["title"] = attributes["title"];
361 
362  }else{
363  // no default value
364  }
365 
366  if (attributes.contains("top")){
367  standard["top"] = attributes["top"];
368 
369  }else{
370  // no default value
371  }
372 
373  if (attributes.contains("left")){
374  standard["left"] = attributes["left"];
375 
376  }else{
377  // no default value
378  }
379 
380  if (attributes.contains("bottom")){
381  standard["bottom"] = attributes["bottom"];
382 
383  }else{
384  // no default value
385  }
386 
387  if (attributes.contains("right")){
388  standard["right"] = attributes["right"];
389 
390  }else{
391  // no default value
392  }
393 
394  if (attributes.contains("width")){
395  standard["width"] = attributes["width"];
396 
397  }else{
398  // no default value
399  }
400 
401  if (attributes.contains("height")){
402  standard["height"] = attributes["height"];
403 
404  }else{
405  // no default value
406  }
407 
408  if (attributes.contains("zIndex")){
409  standard["zIndex"] = attributes["zIndex"];
410 
411  }else{
412  // no default value
413  }
414 
415  // emitting
416  if (!parentregionUID.isEmpty()){
417  emit addEntity("region", parentregionUID, standard, false);
418 
419  }else{
420  emit addEntity("region", regionbaseUID, standard, false);
421  }
422  }
423 }
424 
425 void QnlyComposerPlugin::removeRegion(const QString regionUID, const QString regionbaseUID)
426 {
427 /* if (regions.contains(regionUID) && regionbases.contains(regionbaseUID)){
428  if (!entitystack.isEmpty()){
429  // setting
430  QString entityUID;
431 
432  entityUID = entitystack.pop();
433 
434  // removing
435  regions.remove(regionUID);
436 
437  relations.remove(regionUID);
438 
439  entities.remove(entityUID);
440 
441  }else{
442  // setting
443  QString entityUID;
444 
445  entityUID = regions[regionUID];
446 
447  regionstack.push(regionUID);
448 
449  // removing
450  regions.remove(regionUID);
451 
452  relations.remove(regionUID);
453 
454  // emitting
455  emit removeEntity(getProject()->getEntityBydId(entityUID), false);
456  }
457  }*/
458 }
459 
460 
461 
462 void QnlyComposerPlugin::selectRegion(const QString regionUID, const QString regionbaseUID)
463 {
464 
465 }
466 
467 void QnlyComposerPlugin::changeRegion(const QString regionUID, const QString regionbaseUID, const QMap<QString, QString> &attributes)
468 {
469 
470  /*if (regions.contains(regionUID) && regionbases.contains(regionbaseUID)){
471  if (!entitystack.isEmpty()){
472  // nothing to do
473 
474  }else{
475  // setting
476  QString entityUID;
477 
478  entityUID = entitystack.pop();
479 */
480  QMap<QString, QString> standard;
481 
482  if (attributes.contains("id")){
483  standard["id"] = attributes["id"];
484 
485  }else{
486  // no default value
487  }
488 
489  if (attributes.contains("title")){
490  standard["title"] = attributes["title"];
491 
492  }else{
493  // no default value
494  }
495 
496  if (attributes.contains("top")){
497  standard["top"] = attributes["top"];
498 
499  }else{
500  // no default value
501  }
502 
503  if (attributes.contains("left")){
504  standard["left"] = attributes["left"];
505 
506  }else{
507  // no default value
508  }
509 
510  if (attributes.contains("bottom")){
511  standard["bottom"] = attributes["bottom"];
512 
513  }else{
514  // no default value
515  }
516 
517  if (attributes.contains("right")){
518  standard["right"] = attributes["right"];
519 
520  }else{
521  // no default value
522  }
523 
524  if (attributes.contains("width")){
525  standard["width"] = attributes["width"];
526 
527  }else{
528  // no default value
529  }
530 
531  if (attributes.contains("height")){
532  standard["height"] = attributes["height"];
533 
534  }else{
535  // no default value
536  }
537 
538  if (attributes.contains("zIndex")){
539  standard["zIndex"] = attributes["zIndex"];
540 
541  }else{
542  // no default value
543  }
544 
545  // emitting
546  emit setAttributes(getProject()->getEntityById(regionUID), standard, false);
547 // }
548 // }
549 }
550 
551 void QnlyComposerPlugin::addRegionBase(Entity *entity)
552 {
553 
554  if (entity != NULL){
555  if (entity->getType() == "regionBase"){
556  // setting
557  QString entityUID;
558 
559  if (!entity->getUniqueId().isEmpty()){
560  entityUID = entity->getUniqueId();
561 
562  }else{
563  return; // cancelling addition
564  }
565 
566  QString regionbaseUID;
567 
568  regionbaseUID = entityUID;
569 
570  QMap<QString, QString> attributes;
571 
572  if (!entity->getAttribute("id").isEmpty()){
573  attributes["id"] = entity->getAttribute("id");
574 
575  }else{
576  // no default value
577  }
578 
579  if (!entity->getAttribute("region").isEmpty()){
580  attributes["region"] = entity->getAttribute("region");
581 
582  }else{
583  // no default value
584  }
585 
586  if (!entity->getAttribute("device").isEmpty()){
587  attributes["device"] = entity->getAttribute("device");
588 
589  }else{
590  // no default value
591  }
592 
593  // adding
594  regionbases[regionbaseUID] = entity;
595 
596  view->addRegionbase(regionbaseUID, attributes);
597 // addRegionbase(regionbaseUID, attributes);
598  }
599  }
600 }
601 
602 void QnlyComposerPlugin::removeRegionBase(Entity *entity)
603 {
604 
605 }
606 
607 void QnlyComposerPlugin::selectRegionBase(Entity *entity)
608 {
609 
610 }
611 
612 void QnlyComposerPlugin::changeRegionBase(Entity *entity)
613 {
614 
615 }
616 
617 void QnlyComposerPlugin::addRegionBase(const QString regionbaseUID, const QMap<QString, QString> &attributes)
618 {
619 
620 }
621 
622 void QnlyComposerPlugin::removeRegionBase(const QString regionbaseUID)
623 {
624 
625 }
626 
627 void QnlyComposerPlugin::selectRegionBase(const QString regionbaseUID)
628 {
629 
630 }
631 
632 void QnlyComposerPlugin::changeRegionBase(const QString regionbaseUID, const QMap<QString, QString> &attributes)
633 {
634 
635 }
636 
637 }
638 }
639 }