src/mainmenu.cpp \
src/buttonselector.cpp \
src/themeselector.cpp \
- src/unitselector.cpp
+ src/unitselector.cpp \
+ src/effect.cpp \
+ src/blureffect.cpp \
+ src/opacityeffect.cpp \
+ src/dropshadoweffect.cpp
HEADERS += src/mainwindow.h \
src/mainwindowstack.h \
src/location.h \
src/mainmenu.h \
src/buttonselector.h \
src/themeselector.h \
- src/unitselector.h
+ src/unitselector.h \
+ src/effect.h \
+ src/blureffect.h \
+ src/opacityeffect.h \
+ src/dropshadoweffect.h
RESOURCES = src/resources.qrc
CONFIG += link_pkgconfig
PKGCONFIG += liblocation libzip
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QString>
+#include <QtCore/QDebug>
+#include <QtGui/QGraphicsBlurEffect>
+#include <QtGui/QGraphicsItem>
+#include "blureffect.h"
+
+namespace
+{
+ Effect::AttributeDetails ATTRIBUTES[BlurEffect::ATTRIBUTE_COUNT] =
+ {
+ {"radius", true}
+ };
+}
+
+BlurEffect::BlurEffect(): Effect()
+{
+ effect_ = new QGraphicsBlurEffect;
+}
+
+bool BlurEffect::setAttribute(QString const& name, QString const& value)
+{
+ qreal realVal = 0;
+ int attrId = -1;
+
+ if((attrId = getAttribute(name, value, ATTRIBUTES, ATTRIBUTE_COUNT, realVal)) != -1)
+ {
+ Attribute attr = static_cast<Attribute>(attrId);
+
+ switch(attr)
+ {
+ case RADIUS:
+ effect_->setBlurRadius(realVal);
+ break;
+ default:
+ qDebug() << "Unknown attribute: " << attr;
+ return false;
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void BlurEffect::apply(QGraphicsItem* item)
+{
+ item->setGraphicsEffect(effect_);
+}
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef BLUREFFECT_H
+#define BLUREFFECT_H
+
+#include "effect.h"
+
+class QGraphicsBlurEffect;
+
+class BlurEffect : public Effect
+{
+public:
+ enum Attribute {RADIUS, ATTRIBUTE_COUNT};
+ BlurEffect();
+ virtual bool setAttribute(QString const& name, QString const& value);
+ virtual void apply(QGraphicsItem* item);
+
+private:
+ QGraphicsBlurEffect* effect_;
+};
+
+#endif
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QString>
+#include <QtCore/QDebug>
+#include <QtCore/QRectF>
+#include <QtGui/QGraphicsDropShadowEffect>
+#include <QtGui/QGraphicsItem>
+#include "dropshadoweffect.h"
+
+namespace
+{
+ Effect::AttributeDetails ATTRIBUTES[DropshadowEffect::ATTRIBUTE_COUNT] =
+ {
+ {"radius", true},
+ {"color", false},
+ {"xoffset", true},
+ {"yoffset", true}
+ };
+}
+
+DropshadowEffect::DropshadowEffect(): Effect()
+{
+ effect_ = new QGraphicsDropShadowEffect;
+}
+
+bool DropshadowEffect::setAttribute(QString const& name, QString const& value)
+{
+ qreal realVal = 0;
+ int attrId = -1;
+
+ if((attrId = getAttribute(name, value, ATTRIBUTES, ATTRIBUTE_COUNT, realVal)) != -1)
+ {
+ Attribute attr = static_cast<Attribute>(attrId);
+
+ switch(attr)
+ {
+ case RADIUS:
+ effect_->setBlurRadius(realVal);
+ break;
+ case COLOR:
+ effect_->setColor(QColor(value));
+ break;
+ case XOFFSET:
+ effect_->setXOffset(realVal);
+ break;
+ case YOFFSET:
+ effect_->setYOffset(realVal);
+ break;
+ default:
+ qDebug() << "Unknown attribute: " << attr;
+ return false;
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void DropshadowEffect::apply(QGraphicsItem* item)
+{
+ item->setGraphicsEffect(effect_);
+}
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef DROPSHADOWEFFECT_H
+#define DROPSHADOWEFFECT_H
+
+#include "effect.h"
+
+class QGraphicsDropShadowEffect;
+class QGraphicsItem;
+
+class DropshadowEffect : public Effect
+{
+public:
+ enum Attribute {RADIUS, COLOR, XOFFSET, YOFFSET, ATTRIBUTE_COUNT};
+ DropshadowEffect();
+ virtual bool setAttribute(QString const& name, QString const& value);
+ virtual void apply(QGraphicsItem* item);
+
+private:
+ QGraphicsDropShadowEffect* effect_;
+};
+
+#endif
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QString>
+#include <QtGui/QGraphicsItem>
+#include "effect.h"
+#include "dropshadoweffect.h"
+#include "blureffect.h"
+#include "opacityeffect.h"
+
+
+Effect::Effect()
+{
+}
+
+Effect* Effect::getEffect(QString const& name)
+{
+ if(name == "dropshadow")
+ {
+ return new DropshadowEffect;
+ }
+ else if(name == "blur")
+ {
+ return new BlurEffect;
+ }
+ else if(name == "opacity")
+ {
+ return new OpacityEffect;
+ }
+
+ return 0;
+}
+
+int Effect::getAttribute(QString const& name,
+ QString const& value,
+ const Effect::AttributeDetails details[],
+ int count,
+ qreal& realValue)
+{
+ QString lower = name.toLower();
+
+ for(int i = 0; i < count; i++)
+ {
+ if(details[i].name == lower)
+ {
+ if(!details[i].isQreal)
+ {
+ return i;
+ }
+ else
+ {
+ bool ok = true;
+ double tmp = value.toDouble(&ok);
+
+ if(ok)
+ {
+ realValue = static_cast<qreal>(tmp);
+ return i;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ }
+ }
+
+ return -1;
+}
+
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef EFFECT_H
+#define EFFECT_H
+
+class QString;
+class QGraphicsItem;
+
+class Effect
+{
+public:
+ struct AttributeDetails
+ {
+ QString name;
+ bool isQreal;
+ };
+
+ Effect();
+ static Effect* getEffect(QString const& name);
+ virtual bool setAttribute(QString const& name, QString const& value) = 0;
+ virtual void apply(QGraphicsItem* item) = 0;
+
+protected:
+ int getAttribute(QString const& name, QString const& value, const AttributeDetails details[], int count, qreal& realValue);
+
+};
+
+#endif
#include <QtGui/QGraphicsScene>
#include <QtGui/QFont>
#include <QtGui/QFontDatabase>
+#include <QtGui/QGraphicsEffect>
+#include <QtGui/QGraphicsDropShadowEffect>
+#include <QtGui/QGraphicsItem>
#include "graphicselement.h"
#include "reader.h"
#include "textelement.h"
#include "rectangle.h"
#include "pointer.h"
#include "settings.h"
+#include "effect.h"
-GraphicsElement::GraphicsElement(Reader* reader): reader_(reader), error_("")
+GraphicsElement::GraphicsElement(Reader* reader): reader_(reader), error_(""), effect_(0)
{
}
bool GraphicsElement::readFile(QString const& filename, QByteArray& data)
{
-
if(!reader_->readFile(filename, data))
{
setError(reader_->errorString());
setError("Unknown attribute: " + name);
return -1;
}
+
+bool GraphicsElement::setEffect(QString const& name)
+{
+ /* QGraphicsDropShadowEffect* eff = new QGraphicsDropShadowEffect;
+ eff->setOffset(1);
+ eff->setBlurRadius(3);
+
+ getElement()->setGraphicsEffect(eff);
+
+ return true;*/
+
+ effect_ = Effect::getEffect(name);
+
+ if(!effect_)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool GraphicsElement::setEffectAttribute(QString const& name, QString const& value)
+{
+ //return true;
+ if(!effect_)
+ {
+ qDebug() << "Effect not set";
+ return false;
+ }
+
+ return effect_->setAttribute(name, value);
+}
+
+void GraphicsElement::applyEffect()
+{
+ //return;
+ effect_->apply(getElement());
+}
class QFont;
class QGraphicsItem;
class GraphicsScene;
+class QGraphicsEffect;
class Reader;
+class Effect;
class GraphicsElement
{
virtual void update() = 0;
virtual QGraphicsItem* getElement() const = 0;
QString const& getError() const;
+ bool setEffect(QString const& effect);
+ bool setEffectAttribute(QString const& name, QString const& value);
+ void applyEffect();
protected:
int getAttribute(QString const& name, QString const& value, const AttributeDetails details[], int count, int& intValue);
private:
Reader* reader_;
QString error_;
+ Effect* effect_;
QMap<QString, QString> loadedFonts_;
};
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QString>
+#include <QtCore/QDebug>
+#include <QtGui/QGraphicsOpacityEffect>
+#include <QtGui/QGraphicsItem>
+#include "opacityeffect.h"
+
+namespace
+{
+ Effect::AttributeDetails ATTRIBUTES[OpacityEffect::ATTRIBUTE_COUNT] =
+ {
+ {"opacity", true}
+ };
+}
+
+OpacityEffect::OpacityEffect(): Effect()
+{
+ effect_ = new QGraphicsOpacityEffect;
+}
+
+bool OpacityEffect::setAttribute(QString const& name, QString const& value)
+{
+ qreal realVal = 0;
+ int attrId = -1;
+
+ if((attrId = getAttribute(name, value, ATTRIBUTES, ATTRIBUTE_COUNT, realVal)) != -1)
+ {
+ Attribute attr = static_cast<Attribute>(attrId);
+
+ switch(attr)
+ {
+ case OPACITY:
+ effect_->setOpacity(realVal);
+ break;
+ default:
+ qDebug() << "Unknown attribute: " << attr;
+ return false;
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void OpacityEffect::apply(QGraphicsItem* item)
+{
+ item->setGraphicsEffect(effect_);
+}
--- /dev/null
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef OPACITYEFFECT_H
+#define OPACITYEFFECT_H
+
+#include "effect.h"
+
+class QGraphicsOpacityEffect;
+
+class OpacityEffect : public Effect
+{
+public:
+ enum Attribute {OPACITY, ATTRIBUTE_COUNT};
+ OpacityEffect();
+ virtual bool setAttribute(QString const& name, QString const& value);
+ virtual void apply(QGraphicsItem* item);
+
+private:
+ QGraphicsOpacityEffect* effect_;
+};
+
+#endif
<align>right</align>
<width>600</width>
<format>%.0f</format>
+ <effect name="dropshadow">
+ <xoffset>0</xoffset>
+ <yoffset>0</yoffset>
+ <radius>35</radius>
+ <color>#a5efff</color>
+ </effect>
</text>
</orientation>
<orientation name="portrait">
<align>right</align>
<width>470</width>
<format>%.0f</format>
+ <effect name="dropshadow">
+ <xoffset>0</xoffset>
+ <yoffset>0</yoffset>
+ <radius>35</radius>
+ <color>#a5efff</color>
+ </effect>
</text>
</orientation>
</theme>
{
specialFields_.push_back(static_cast<Field>(i));
}
+
}
QString replaced = data_;
*
*/
+#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QGraphicsItem>
#include <QtCore/QString>
for(int i = 0; i < options.size(); i++)
{
- if(!element->setAttribute(options.at(i).nodeName(), options.at(i).toElement().text()))
+ QString nodeName = options.at(i).nodeName();
+
+
+
+ if(nodeName == "effect")
+ {
+ QDomNode effectName = options.at(i).attributes().namedItem("name");
+
+ if(effectName.isNull())
+ {
+ qDebug() << "Missing name for effect";
+ }
+ else
+ {
+ if(!element->setEffect(effectName.toAttr().value()))
+ {
+ qDebug() << "Invalid effect: " << effectName.toAttr().value();
+ }
+ else
+ {
+ QDomNodeList themeOptions = options.at(i).childNodes();
+
+ for(int i = 0; i < themeOptions.size(); i++)
+ {
+ if(!element->setEffectAttribute(themeOptions.at(i).nodeName(), themeOptions.at(i).toElement().text()))
+ {
+ qDebug() << "Warning: invalid effect option: " << themeOptions.at(i).nodeName();
+ }
+ }
+
+ element->applyEffect();
+ }
+ }
+ }
+ else
{
- qDebug() << "Warning: invalid option: " << options.at(i).nodeName();
+ if(!element->setAttribute(nodeName, options.at(i).toElement().text()))
+ {
+ qDebug() << "Warning: invalid option: " << options.at(i).nodeName();
+ }
}
}
}
+ forceRepaint();
+
return true;
}
elements_.at(i)->update();
}
}
+
+void ThemeScreen::forceRepaint()
+{
+ rotate(0.0001);
+ QApplication::processEvents();
+ rotate(-0.0001);
+}
bool load(QDomNode const& data, Reader* reader);
virtual void update();
void removeElements();
+ void forceRepaint();
private:
QList<GraphicsElement*> elements_;