Added zpos attribute to all elements. Changed architecture to allow detailscreen...
[jspeed] / src / effect.cpp
1 /*
2  * This file is part of jSpeed.
3  *
4  * jSpeed is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * jSpeed 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with jSpeed.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #include <QtCore/QString>
20 #include <QtGui/QGraphicsItem>
21 #include "effect.h"
22 #include "dropshadoweffect.h"
23 #include "blureffect.h"
24 #include "opacityeffect.h"
25
26
27 Effect::Effect()
28 {
29 }
30
31 Effect* Effect::getEffect(QString const& name)
32 {
33    if(name == "dropshadow")
34    {
35        return new DropshadowEffect;
36    }
37    else if(name == "blur")
38    {
39        return new BlurEffect;
40    }
41    else if(name == "opacity")
42    {
43        return new OpacityEffect;
44    }
45
46    return 0;
47 }
48
49 int Effect::getAttribute(QString const& name,
50                          QString const& value,
51                          const Effect::AttributeDetails details[],
52                          int count,
53                          qreal& realValue)
54 {
55     QString lower = name.toLower();
56
57     for(int i = 0; i < count; i++)
58     {
59         if(details[i].name == lower)
60         {
61             if(!details[i].isQreal)
62             {
63                 return i;
64             }
65             else
66             {
67                 bool ok = true;
68                 double tmp = value.toDouble(&ok);
69
70                 if(ok)
71                 {
72                     realValue = static_cast<qreal>(tmp);
73                     return i;
74                 }
75                 else
76                 {
77                     return -1;
78                 }
79             }
80         }
81     }
82
83     return -1;
84 }
85