Fixed a small bug in flicker effect.
authoreshe <jessehakanen@gmail.com>
Mon, 26 Jul 2010 21:43:41 +0000 (22:43 +0100)
committereshe <jessehakanen@gmail.com>
Mon, 26 Jul 2010 21:43:41 +0000 (22:43 +0100)
13 files changed:
src/blureffect.cpp
src/blureffect.h
src/dropshadoweffect.cpp
src/dropshadoweffect.h
src/effect.h
src/flickereffect.cpp
src/flickereffect.h
src/graphicselement.cpp
src/graphicselement.h
src/opacityeffect.cpp
src/opacityeffect.h
src/poiascreader.cpp
src/unitselector.cpp

index 5635964..0a44c37 100644 (file)
@@ -21,6 +21,7 @@
 #include <QtGui/QGraphicsBlurEffect>
 #include <QtGui/QGraphicsItem>
 #include "blureffect.h"
+#include "graphicselement.h"
 
 namespace
 {
@@ -62,7 +63,7 @@ bool BlurEffect::setAttribute(QString const& name, QString const& value)
     }
 }
 
-void BlurEffect::apply(QGraphicsItem* item)
+void BlurEffect::apply(GraphicsElement* item)
 {
-    item->setGraphicsEffect(effect_);
+    item->getElement()->setGraphicsEffect(effect_);
 }
index 28ea685..61f0cd9 100644 (file)
@@ -29,7 +29,7 @@ public:
     enum Attribute {RADIUS, ATTRIBUTE_COUNT};
     BlurEffect();
     virtual bool setAttribute(QString const& name, QString const& value);
-    virtual void apply(QGraphicsItem* item);
+    virtual void apply(GraphicsElement* item);
 
 private:
     QGraphicsBlurEffect* effect_;
index 0eac608..22be213 100644 (file)
@@ -22,6 +22,7 @@
 #include <QtGui/QGraphicsDropShadowEffect>
 #include <QtGui/QGraphicsItem>
 #include "dropshadoweffect.h"
+#include "graphicselement.h"
 
 namespace
 {
@@ -75,7 +76,7 @@ bool DropshadowEffect::setAttribute(QString const& name, QString const& value)
     }
 }
 
-void DropshadowEffect::apply(QGraphicsItem* item)
+void DropshadowEffect::apply(GraphicsElement* item)
 {
-    item->setGraphicsEffect(effect_);
+    item->getElement()->setGraphicsEffect(effect_);
 }
index 864d585..56971db 100644 (file)
@@ -22,7 +22,7 @@
 #include "effect.h"
 
 class QGraphicsDropShadowEffect;
-class QGraphicsItem;
+class GraphicsElement;
 
 class DropshadowEffect : public Effect
 {
@@ -30,7 +30,7 @@ public:
     enum Attribute {RADIUS, COLOR, XOFFSET, YOFFSET, ATTRIBUTE_COUNT};
     DropshadowEffect();
     virtual bool setAttribute(QString const& name, QString const& value);
-    virtual void apply(QGraphicsItem* item);
+    virtual void apply(GraphicsElement* item);
 
 private:
     QGraphicsDropShadowEffect* effect_;
index 929680f..f06b424 100644 (file)
@@ -20,7 +20,7 @@
 #define EFFECT_H
 
 class QString;
-class QGraphicsItem;
+class GraphicsElement;
 
 class Effect
 {
@@ -34,7 +34,7 @@ public:
     Effect();
     static Effect* getEffect(QString const& name);
     virtual bool setAttribute(QString const& name, QString const& value) = 0;
-    virtual void apply(QGraphicsItem* item) = 0;
+    virtual void apply(GraphicsElement* item) = 0;
 
 protected:
     int getAttribute(QString const& name, QString const& value, const AttributeDetails details[], int count, qreal& realValue);
index 16d535d..ebca5af 100644 (file)
@@ -22,6 +22,7 @@
 #include <QtGui/QGraphicsItem>
 #include <math.h>
 #include "flickereffect.h"
+#include "graphicselement.h"
 
 namespace
 {
@@ -67,7 +68,7 @@ bool FlickerEffect::setAttribute(QString const& name, QString const& value)
     }
 }
 
-void FlickerEffect::apply(QGraphicsItem* item)
+void FlickerEffect::apply(GraphicsElement* item)
 {
     if(interval_ > 0)
     {
@@ -81,8 +82,8 @@ void FlickerEffect::apply(QGraphicsItem* item)
 
 void FlickerEffect::updateVisibility()
 {
-    if(item_)
+    if(item_ && item_->canBeVisible())
     {
-        item_->setVisible(!item_->isVisible());
+        item_->getElement()->setVisible(!item_->getElement()->isVisible());
     }
 }
index f258058..e0cf8a0 100644 (file)
@@ -23,8 +23,8 @@
 #include "effect.h"
 
 class QString;
-class QGraphicsItem;
 class QTimer;
+class GraphicsElement;
 
 class FlickerEffect : public QObject, public Effect
 {
@@ -35,7 +35,7 @@ public:
     FlickerEffect();
     ~FlickerEffect();
     virtual bool setAttribute(QString const& name, QString const& value);
-    virtual void apply(QGraphicsItem* item);
+    virtual void apply(GraphicsElement* item);
 
 private slots:
     void updateVisibility();
@@ -43,7 +43,7 @@ private slots:
 private:
     int interval_;
     QTimer* timer_;
-    QGraphicsItem* item_;
+    GraphicsElement* item_;
 };
 
 #endif
index fba0e95..0442b3a 100644 (file)
@@ -37,7 +37,8 @@
 #include "poialerts.h"
 #include "speedalarm.h"
 
-GraphicsElement::GraphicsElement(Reader* reader): QObject(0), reader_(reader), error_(""), effect_(0), visibleWhen_(ALWAYS)
+GraphicsElement::GraphicsElement(Reader* reader): QObject(0),
+reader_(reader), error_(""), effect_(0), visibleWhen_(ALWAYS), canBeVisible_(true)
 {
 }
 
@@ -205,7 +206,7 @@ bool GraphicsElement::setEffectAttribute(QString const& name, QString const& val
 
 void GraphicsElement::applyEffect()
 {
-    effect_->apply(getElement());
+    effect_->apply(this);
 }
 
 void GraphicsElement::setVisibleWhen(VisibleWhen when)
@@ -217,14 +218,17 @@ void GraphicsElement::setVisibleWhen(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;
         }
     }
@@ -251,5 +255,19 @@ void GraphicsElement::updateVisibility(bool visible)
     if(item)
     {
         item->setVisible(visible);
+
+        if(!visible)
+        {
+            canBeVisible_ = false;
+        }
+        else
+        {
+            canBeVisible_ = true;
+        }
     }
 }
+
+bool GraphicsElement::canBeVisible() const
+{
+    return canBeVisible_;
+}
index ecba5ae..3bc9756 100644 (file)
@@ -53,6 +53,7 @@ public:
     bool setEffect(QString const& effect);
     bool setEffectAttribute(QString const& name, QString const& value);
     void applyEffect();
+    bool canBeVisible() const;
 
 protected:
     enum VisibleWhen {ALWAYS, POI_VISIBLE, SPEED_EXCEEDED};
@@ -73,6 +74,7 @@ private:
     Effect* effect_;
     QMap<QString, QString> loadedFonts_;
     VisibleWhen visibleWhen_;
+    bool canBeVisible_;
 };
 
 #endif
index 2b1ea09..d43a8cf 100644 (file)
@@ -21,6 +21,7 @@
 #include <QtGui/QGraphicsOpacityEffect>
 #include <QtGui/QGraphicsItem>
 #include "opacityeffect.h"
+#include "graphicselement.h"
 
 namespace
 {
@@ -62,7 +63,7 @@ bool OpacityEffect::setAttribute(QString const& name, QString const& value)
     }
 }
 
-void OpacityEffect::apply(QGraphicsItem* item)
+void OpacityEffect::apply(GraphicsElement* item)
 {
-    item->setGraphicsEffect(effect_);
+    item->getElement()->setGraphicsEffect(effect_);
 }
index e85a5ae..d02507f 100644 (file)
@@ -29,7 +29,7 @@ public:
     enum Attribute {OPACITY, ATTRIBUTE_COUNT};
     OpacityEffect();
     virtual bool setAttribute(QString const& name, QString const& value);
-    virtual void apply(QGraphicsItem* item);
+    virtual void apply(GraphicsElement* item);
 
 private:
     QGraphicsOpacityEffect* effect_;
index 68bb048..2d01f6f 100644 (file)
@@ -19,6 +19,7 @@
 #include <QtCore/QFile>
 #include <QtCore/QString>
 #include <QtCore/QByteArray>
+#include <QtCore/QStringList>
 #include <QtCore/QDebug>
 #include <QtCore/QRegExp>
 #include "poiascreader.h"
@@ -39,22 +40,20 @@ bool PoiAscReader::read(QList<Poi>& pois)
         return false;
     }
 
-    QString data = QString(file.readAll());
-    static QRegExp matcher("([0-9]{1,3})\\.([0-9]+), ([0-9]{1,3})\\.([0-9]+), \"(.*)\"");
-    matcher.setMinimal(true);
-
-    int pos = 0;
-
-    while((pos = matcher.indexIn(data, pos)) != -1)
+    while(!file.atEnd())
     {
-        pos += matcher.matchedLength();
+        QString data(file.readLine());
+        QStringList parts = data.split(",");
 
-        Poi poi;
+        if(parts.size() < 3)
+        {
+            continue;
+        }
 
-        bool ok;
+        QString longitude = parts.at(0).trimmed();
+        QString latitude = parts.at(1).trimmed();
 
-        QString latitude = matcher.cap(3) + "." + matcher.cap(4);
-        QString longitude = matcher.cap(1) + "." + matcher.cap(2);
+        bool ok;
 
         double doubleLatitude = latitude.toDouble(&ok);
 
@@ -70,9 +69,13 @@ bool PoiAscReader::read(QList<Poi>& pois)
             continue;
         }
 
+        QString name = parts.at(2).trimmed();
+        name.remove('"');
+
+        Poi poi;
         poi.latitude = doubleLatitude;
         poi.longitude = doubleLongitude;
-        poi.name = matcher.cap(5);
+        poi.name = name;
 
         pois.push_back(poi);
 
index 742a705..e4b0e16 100644 (file)
@@ -46,6 +46,7 @@ UnitSelector::UnitSelector(QWidget* parent): QDialog(parent)
     layout->addWidget(selector_, Qt::AlignLeft);
 
     ButtonBox* buttons = new ButtonBox;
+    buttons->setOrientation(Qt::Horizontal);
     connect(buttons->addButton(tr("Save"), QDialogButtonBox::AcceptRole), SIGNAL(clicked(bool)), this, SLOT(saveUnit()));
 
     layout->addWidget(buttons);