Changelog fixed.
[jspeed] / src / dropshadoweffect.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 <QtCore/QDebug>
21 #include <QtCore/QRectF>
22 #include <QtGui/QGraphicsDropShadowEffect>
23 #include <QtGui/QGraphicsItem>
24 #include "dropshadoweffect.h"
25
26 namespace
27 {
28     Effect::AttributeDetails ATTRIBUTES[DropshadowEffect::ATTRIBUTE_COUNT] =
29     {
30      {"radius", true},
31      {"color", false},
32      {"xoffset", true},
33      {"yoffset", true}
34     };
35 }
36
37 DropshadowEffect::DropshadowEffect(): Effect()
38 {
39     effect_ = new QGraphicsDropShadowEffect;
40 }
41
42 bool DropshadowEffect::setAttribute(QString const& name, QString const& value)
43 {
44     qreal realVal = 0;
45     int attrId = -1;
46
47     if((attrId = getAttribute(name, value, ATTRIBUTES, ATTRIBUTE_COUNT, realVal)) != -1)
48     {
49         Attribute attr = static_cast<Attribute>(attrId);
50
51         switch(attr)
52         {
53         case RADIUS:
54             effect_->setBlurRadius(realVal);
55             break;
56         case COLOR:
57             effect_->setColor(QColor(value));
58             break;
59         case XOFFSET:
60             effect_->setXOffset(realVal);
61             break;
62         case YOFFSET:
63             effect_->setYOffset(realVal);
64             break;
65         default:
66             qDebug() << "Unknown attribute: " << attr;
67             return false;
68         }
69
70         return true;
71     }
72     else
73     {
74         return false;
75     }
76 }
77
78 void DropshadowEffect::apply(QGraphicsItem* item)
79 {
80     item->setGraphicsEffect(effect_);
81 }