Fixes to speed alarm and poi alerts. Added flicker effect. Some new fields to text...
[jspeed] / src / graphicselement.cpp
index 452af54..fba0e95 100644 (file)
 #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_(""), effect_(0)
+GraphicsElement::GraphicsElement(Reader* reader): QObject(0), reader_(reader), error_(""), effect_(0), visibleWhen_(ALWAYS)
 {
 }
 
@@ -61,6 +64,12 @@ GraphicsElement* GraphicsElement::getElement(QString const& name, Reader* reader
         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;
 }
@@ -173,14 +182,6 @@ int GraphicsElement::getAttribute(QString const& name,
 
 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_)
@@ -193,7 +194,6 @@ bool GraphicsElement::setEffect(QString const& name)
 
 bool GraphicsElement::setEffectAttribute(QString const& name, QString const& value)
 {
-    //return true;
     if(!effect_)
     {
         qDebug() << "Effect not set";
@@ -205,6 +205,51 @@ bool GraphicsElement::setEffectAttribute(QString const& name, QString const& val
 
 void GraphicsElement::applyEffect()
 {
-    //return;
     effect_->apply(getElement());
 }
+
+void GraphicsElement::setVisibleWhen(VisibleWhen when)
+{
+    if(when != visibleWhen_)
+    {
+        visibleWhen_ = when;
+
+        switch(when)
+        {
+        case POI_VISIBLE:
+            connect(&(PoiAlerts::instance()), SIGNAL(visibilityChanged(bool)), this, SLOT(updateVisibility(bool)));
+            break;
+        case SPEED_EXCEEDED:
+            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)));
+            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);
+    }
+}