From a1c4b0cdd446bc9ed331f17fa7d6e69cfa02d45d Mon Sep 17 00:00:00 2001 From: eshe Date: Mon, 26 Jul 2010 22:43:41 +0100 Subject: [PATCH] Fixed a small bug in flicker effect. --- src/blureffect.cpp | 5 +++-- src/blureffect.h | 2 +- src/dropshadoweffect.cpp | 5 +++-- src/dropshadoweffect.h | 4 ++-- src/effect.h | 4 ++-- src/flickereffect.cpp | 7 ++++--- src/flickereffect.h | 6 +++--- src/graphicselement.cpp | 22 ++++++++++++++++++++-- src/graphicselement.h | 2 ++ src/opacityeffect.cpp | 5 +++-- src/opacityeffect.h | 2 +- src/poiascreader.cpp | 29 ++++++++++++++++------------- src/unitselector.cpp | 1 + 13 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/blureffect.cpp b/src/blureffect.cpp index 5635964..0a44c37 100644 --- a/src/blureffect.cpp +++ b/src/blureffect.cpp @@ -21,6 +21,7 @@ #include #include #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_); } diff --git a/src/blureffect.h b/src/blureffect.h index 28ea685..61f0cd9 100644 --- a/src/blureffect.h +++ b/src/blureffect.h @@ -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_; diff --git a/src/dropshadoweffect.cpp b/src/dropshadoweffect.cpp index 0eac608..22be213 100644 --- a/src/dropshadoweffect.cpp +++ b/src/dropshadoweffect.cpp @@ -22,6 +22,7 @@ #include #include #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_); } diff --git a/src/dropshadoweffect.h b/src/dropshadoweffect.h index 864d585..56971db 100644 --- a/src/dropshadoweffect.h +++ b/src/dropshadoweffect.h @@ -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_; diff --git a/src/effect.h b/src/effect.h index 929680f..f06b424 100644 --- a/src/effect.h +++ b/src/effect.h @@ -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); diff --git a/src/flickereffect.cpp b/src/flickereffect.cpp index 16d535d..ebca5af 100644 --- a/src/flickereffect.cpp +++ b/src/flickereffect.cpp @@ -22,6 +22,7 @@ #include #include #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()); } } diff --git a/src/flickereffect.h b/src/flickereffect.h index f258058..e0cf8a0 100644 --- a/src/flickereffect.h +++ b/src/flickereffect.h @@ -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 diff --git a/src/graphicselement.cpp b/src/graphicselement.cpp index fba0e95..0442b3a 100644 --- a/src/graphicselement.cpp +++ b/src/graphicselement.cpp @@ -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_; +} diff --git a/src/graphicselement.h b/src/graphicselement.h index ecba5ae..3bc9756 100644 --- a/src/graphicselement.h +++ b/src/graphicselement.h @@ -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 loadedFonts_; VisibleWhen visibleWhen_; + bool canBeVisible_; }; #endif diff --git a/src/opacityeffect.cpp b/src/opacityeffect.cpp index 2b1ea09..d43a8cf 100644 --- a/src/opacityeffect.cpp +++ b/src/opacityeffect.cpp @@ -21,6 +21,7 @@ #include #include #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_); } diff --git a/src/opacityeffect.h b/src/opacityeffect.h index e85a5ae..d02507f 100644 --- a/src/opacityeffect.h +++ b/src/opacityeffect.h @@ -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_; diff --git a/src/poiascreader.cpp b/src/poiascreader.cpp index 68bb048..2d01f6f 100644 --- a/src/poiascreader.cpp +++ b/src/poiascreader.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include "poiascreader.h" @@ -39,22 +40,20 @@ bool PoiAscReader::read(QList& 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& 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); diff --git a/src/unitselector.cpp b/src/unitselector.cpp index 742a705..e4b0e16 100644 --- a/src/unitselector.cpp +++ b/src/unitselector.cpp @@ -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); -- 1.7.9.5