#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 "imageelement.h"
#include "rectangle.h"
#include "pointer.h"
+#include "compass.h"
#include "settings.h"
+#include "effect.h"
+#include "poialerts.h"
+#include "speedalarm.h"
-GraphicsElement::GraphicsElement(Reader* reader): reader_(reader), error_("")
+GraphicsElement::GraphicsElement(Reader* reader): QObject(0),
+reader_(reader), error_(""), effect_(0), visibleWhen_(ALWAYS), canBeVisible_(true)
{
}
return new Pointer(reader, animate);
}
+ if(name == "compass")
+ {
+ bool animate = Settings::instance().value("animate_pointer", true).toBool();
+ return new Compass(reader, animate);
+ }
+
qDebug() << "Element not found: " << name;
return 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)
+{
+ effect_ = Effect::getEffect(name);
+
+ if(!effect_)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool GraphicsElement::setEffectAttribute(QString const& name, QString const& value)
+{
+ if(!effect_)
+ {
+ qDebug() << "Effect not set";
+ return false;
+ }
+
+ return effect_->setAttribute(name, value);
+}
+
+void GraphicsElement::applyEffect()
+{
+ effect_->apply(this);
+}
+
+void GraphicsElement::setVisibleWhen(VisibleWhen when)
+{
+ if(when != visibleWhen_)
+ {
+ visibleWhen_ = when;
+
+ switch(when)
+ {
+ case POI_VISIBLE:
+ updateVisibility(false);
+ connect(&(PoiAlerts::instance()), SIGNAL(visibilityChanged(bool)), this, SLOT(updateVisibility(bool)));
+ break;
+ case SPEED_EXCEEDED:
+ updateVisibility(false);
+ connect(&(SpeedAlarm::instance()), SIGNAL(speedExceedChanged(bool)), this, SLOT(updateVisibility(bool)));
+ break;
+ case ALWAYS:
+ disconnect(&(PoiAlerts::instance()), SIGNAL(visibilityChanged(bool)), this, SLOT(updateVisibility(bool)));
+ disconnect(&(SpeedAlarm::instance()), SIGNAL(speedExceedChanged(bool)), this, SLOT(updateVisibility(bool)));
+ updateVisibility(true);
+ break;
+ }
+ }
+}
+
+GraphicsElement::VisibleWhen GraphicsElement::strToVisibleWhen(QString const& str) const
+{
+ if(str == "poivisible")
+ {
+ return POI_VISIBLE;
+ }
+ else if(str == "speedexceeded")
+ {
+ return SPEED_EXCEEDED;
+ }
+
+ return ALWAYS;
+}
+
+void GraphicsElement::updateVisibility(bool visible)
+{
+ QGraphicsItem* item = getElement();
+
+ if(item)
+ {
+ item->setVisible(visible);
+
+ if(!visible)
+ {
+ canBeVisible_ = false;
+ }
+ else
+ {
+ canBeVisible_ = true;
+ }
+ }
+}
+
+bool GraphicsElement::canBeVisible() const
+{
+ return canBeVisible_;
+}