Couple of more options added to text element.
authoreshe <jessehakanen@gmail.com>
Mon, 19 Jul 2010 20:07:26 +0000 (21:07 +0100)
committereshe <jessehakanen@gmail.com>
Mon, 19 Jul 2010 20:07:26 +0000 (21:07 +0100)
src/resources/themes/default/theme.xml
src/textelement.cpp
src/textelement.h

index 066d2b5..d9becb0 100644 (file)
@@ -47,6 +47,7 @@
                <size>24</size>
                <color>#fff</color>
                <bold>true</bold>
+               <uppercase>true</uppercase>
                <effect name="dropshadow">
                        <xoffset>0</xoffset>
                        <yoffset>0</yoffset>
                         <color>#a5efff</color>
                 </effect>
        </text>
+       <text>
+                <data>{SPEEDUNIT}</data>
+                <xpos>330</xpos>
+                <ypos>522</ypos>
+                <font>Nokia Sans Bold</font>
+                <size>22</size>
+                <color>#fff</color>
+                <bold>true</bold>
+                <uppercase>true</uppercase>
+                <effect name="dropshadow">
+                        <xoffset>0</xoffset>
+                        <yoffset>0</yoffset>
+                        <radius>35</radius>
+                        <color>#a5efff</color>
+                </effect>
+        </text>
 </orientation>
 </theme>
index 1c49b7c..bf79a68 100644 (file)
@@ -40,7 +40,9 @@ namespace
      {"size", true},
      {"font", false},
      {"bold", false},
-     {"italic", false}
+     {"italic", false},
+     {"uppercase", false},
+     {"letterspacing", true}
     };
 
     const QString FIELDS[TextElement::FIELD_COUNT] =  {"TRIP", "TOTAL", "SPEED",
@@ -49,7 +51,8 @@ namespace
 }
 
 TextElement::TextElement(Reader* reader): GraphicsElement(reader),
-data_(""), format_(""), align_("left"), fontSize_(16), bold_(false), italic_(false)
+data_(""), format_(""), align_("left"), fontSize_(16), bold_(false), italic_(false),
+uppercase_(false), letterSpacing_(0)
 {
     element_ = new QGraphicsTextItem();
 }
@@ -110,6 +113,16 @@ bool TextElement::setAttribute(QString const& name, QString const& value)
                 fontChanged = true;
             }
             break;
+        case UPPERCASE:
+            if(value != "false" && value != "0")
+            {
+                uppercase_ = true;
+            }
+            break;
+        case LETTERSPACING:
+            letterSpacing_ = intVal;
+            fontChanged = true;
+            break;
         default:
             qDebug() << "Unknown attribute: " << attr;
             return false;
@@ -117,45 +130,7 @@ bool TextElement::setAttribute(QString const& name, QString const& value)
 
         if(fontChanged)
         {
-            if(!fontFile_.isEmpty())
-            {
-                QFont font;
-
-                if(getFont(fontFile_, font))
-                {
-                    font.setPointSize(fontSize_);
-
-                    if(bold_)
-                    {
-                        font.setBold(true);
-                    }
-                    if(italic_)
-                    {
-                        font.setItalic(true);
-                    }
-                    element_->setFont(font);
-                }
-                else
-                {
-                    return false;
-                }
-            }
-            else
-            {
-                QFont font("Default");
-
-                if(bold_)
-                {
-                    font.setBold(true);
-                }
-                if(italic_)
-                {
-                    font.setItalic(true);
-                }
-
-                font.setPointSize(fontSize_);
-                element_->setFont(font);
-            }
+            return applyFont();
         }
 
         return true;
@@ -167,6 +142,40 @@ bool TextElement::setAttribute(QString const& name, QString const& value)
     }
 }
 
+bool TextElement::applyFont()
+{
+    QFont font;
+
+    if(!fontFile_.isEmpty())
+    {
+        if(!getFont(fontFile_, font))
+        {
+            return false;
+        }
+    }
+
+    font.setPointSize(fontSize_);
+
+    if(bold_)
+    {
+        font.setBold(true);
+    }
+
+    if(italic_)
+    {
+        font.setItalic(true);
+    }
+
+    if(letterSpacing_)
+    {
+        font.setLetterSpacing(QFont::PercentageSpacing, letterSpacing_);
+    }
+
+    element_->setFont(font);
+
+    return true;
+}
+
 void TextElement::addToScene(GraphicsScene* scene)
 {
     specialFields_.clear();
@@ -200,8 +209,13 @@ void TextElement::update()
     updateHtml(replaced);
 }
 
-void TextElement::updateHtml(QString const& data)
+void TextElement::updateHtml(QString data)
 {
+    if(uppercase_)
+    {
+        data = data.toUpper();
+    }
+
     element_->setHtml("<div align='"+align_+"'>"+data+"</div>");
 }
 
index ddd289c..b531580 100644 (file)
@@ -30,7 +30,7 @@ class GraphicsScene;
 class TextElement : public GraphicsElement
 {
 public:
-    enum Attribute {XPOS, YPOS, DATA, FORMAT, WIDTH, ALIGN, COLOR, SIZE, FONT, BOLD, ITALIC, ATTRIBUTE_COUNT};
+    enum Attribute {XPOS, YPOS, DATA, FORMAT, WIDTH, ALIGN, COLOR, SIZE, FONT, BOLD, ITALIC, UPPERCASE, LETTERSPACING, ATTRIBUTE_COUNT};
     enum Field {TRIP, TOTAL, SPEED, MAXSPEED, AVGSPEED, UNIT, SPEEDUNIT, TIME, FIELD_COUNT};
     TextElement(Reader* reader);
     virtual bool setAttribute(QString const& name, QString const& value);
@@ -39,9 +39,10 @@ public:
     virtual QGraphicsItem* getElement() const;
 
 private:
-    void updateHtml(QString const& data);
+    void updateHtml(QString data);
     void replaceSpecialFields(QString& value);
     void replaceValue(QString& value, Field field, QString const& replace);
+    bool applyFont();
     QString formatString(double val);
     QGraphicsTextItem* element_;
     QString data_;
@@ -50,6 +51,8 @@ private:
     int fontSize_;
     bool bold_;
     bool italic_;
+    bool uppercase_;
+    int letterSpacing_;
     QString fontFile_;
     QList<Field> specialFields_;
 };