~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to libs/odf/KoShadowStyle.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-08-08 11:05:31 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120808110531-43wco1j5sdm8n47s
Tags: 1:2.5.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    return !operator==(other);
87
87
}
88
88
 
 
89
// load value string as specified by CSS2 §7.16.5 "text-shadow"
89
90
bool KoShadowStyle::loadOdf (const QString &data)
90
91
{
91
 
    if (data == "none")
 
92
    if (data == QLatin1String("none"))
92
93
        return true;
 
94
 
93
95
    QList<KoShadowStyle::ShadowData> shadow_datas;
94
96
 
95
 
    QStringList sub_shadows = data.split(',');
96
 
    foreach (QString shadow, sub_shadows) {
97
 
        QStringList words = shadow.split(' ', QString::SkipEmptyParts);
98
 
        if (words.length() == 0)
 
97
    const QStringList sub_shadows = data.split(QLatin1Char(','));
 
98
    foreach (const QString &shadow, sub_shadows) {
 
99
        QStringList words = shadow.split(QLatin1Char(' '), QString::SkipEmptyParts);
 
100
        if (words.isEmpty())
99
101
            return false;
100
102
 
101
103
        KoShadowStyle::ShadowData currentData;
102
 
        QColor shadowColor(words[0]);
 
104
 
 
105
        // look for color at begin
 
106
        QColor shadowColor(words.first());
103
107
        if (shadowColor.isValid()) {
104
108
            currentData.color = shadowColor;
105
109
            words.removeFirst();
106
 
        } else {
107
 
            // We keep an invalid color.
 
110
        } else if (words.length() > 2) {
 
111
            // look for color at end, if there could be one
 
112
            shadowColor = QColor(words.last());
 
113
            if (shadowColor.isValid()) {
 
114
                currentData.color = shadowColor;
 
115
                words.removeLast();
 
116
            }
108
117
        }
 
118
        // We keep an invalid color.if none was found
109
119
 
110
 
        if (words.length() > 0) {
 
120
        // "Each shadow effect must specify a shadow offset and may optionally
 
121
        // specify a blur radius and a shadow color.", from CSS2 §7.16.5 "text-shadow"
 
122
        // But for some reason also no offset has been accepted before. TODO: which?
 
123
        if (! words.isEmpty()) {
111
124
            if ((words.length() < 2) || (words.length() > 3))
112
125
                return false;
113
126
 
114
 
            // Parse the 2/3 lengths
115
 
            currentData.offset.setX(KoUnit::parseValue(words[0], 0.0));
116
 
            currentData.offset.setY(KoUnit::parseValue(words[1], 0.0));
 
127
            // Parse offset
 
128
            currentData.offset.setX(KoUnit::parseValue(words.at(0), 0.0));
 
129
            currentData.offset.setY(KoUnit::parseValue(words.at(1), 0.0));
 
130
            // Parse blur radius if present
117
131
            if (words.length() == 3)
118
 
                currentData.radius = KoUnit::parseValue(words[2], 0.0);
 
132
                currentData.radius = KoUnit::parseValue(words.at(2), 0.0);
119
133
        }
120
134
        d->shadows << currentData;
121
135
    }
129
143
 
130
144
QString KoShadowStyle::saveOdf() const
131
145
{
 
146
    if (d->shadows.isEmpty())
 
147
        return QLatin1String("none");
 
148
 
132
149
    QStringList parts;
133
 
    foreach (ShadowData data, d->shadows) {
134
 
        QString part = QString("%1 %2pt %3pt %4pt").arg(data.color.name()).arg(data.offset.x()).arg(data.offset.y()).arg(data.radius);
135
 
        parts << part;
 
150
    const QString pt = QLatin1String("%1pt");
 
151
    foreach (const ShadowData &data, d->shadows) {
 
152
        QStringList elements;
 
153
        if (data.color.isValid()) {
 
154
            elements << data.color.name();
 
155
        }
 
156
        elements << pt.arg(data.offset.x()) << pt.arg(data.offset.y());
 
157
        if (data.radius != 0)
 
158
            elements << pt.arg(data.radius);
 
159
 
 
160
        parts << elements.join(QLatin1String(" "));
136
161
    }
137
 
    if (parts.isEmpty())
138
 
        return "none";
139
 
    return parts.join(",");
 
162
    return parts.join(QLatin1String(","));
140
163
}
141
164