[Merge] lp:~abreu-alexandre/webbrowser-app/text-color-for-theme-color-webapps into lp:webbrowser-app

Alexandre Abreu alexandre.abreu at canonical.com
Tue Apr 5 15:25:58 UTC 2016


Updates to address comments (see reply to the QColor one)

Diff comments:

> 
> === modified file 'src/app/webcontainer/webapp-container-helper.cpp'
> --- src/app/webcontainer/webapp-container-helper.cpp	2015-05-27 16:19:45 +0000
> +++ src/app/webcontainer/webapp-container-helper.cpp	2016-04-04 17:16:24 +0000
> @@ -38,15 +40,55 @@
>  
>  void WebappContainerHelper::browseToUrl(QObject* webview, const QUrl& url)
>  {
> -    if ( ! webview)
> +    if ( ! webview) {
>          return;
> +    }
>      const QMetaObject* metaobject = webview->metaObject();
>      int urlPropIdx = metaobject->indexOfProperty("url");
> -    if (urlPropIdx == -1)
> +    if (urlPropIdx == -1) {
>          return;
> +    }
>      metaobject->property(urlPropIdx).write(webview, QVariant(url));
>  }
>  
> -
> -
> -
> +QString WebappContainerHelper::rgbColorFromCSSColor(const QString& cssColor)
> +{
> +    QString color = cssColor.trimmed().toLower();
> +    if (color.isEmpty()) {
> +        return QString();
> +    }
> +    QString returnColorFormat = "%1,%2,%3";
> +    if (color.startsWith("rgb")) {
> +        QRegExp rgbColorRe("rgb\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)");
> +        if (rgbColorRe.exactMatch(color)) {
> +            return returnColorFormat
> +                    .arg(rgbColorRe.cap(1).toInt())
> +                    .arg(rgbColorRe.cap(2).toInt())
> +                    .arg(rgbColorRe.cap(3).toInt());
> +        }
> +        return QString();
> +    } else if (color.startsWith("#")) {

not really ... the QColor parsing is not flexible enough, things like "#36699" are "valid" (in a rather loose sense) colors found in some webpages, but not properly parsed by QColor, I tweaked the code though to delegate to QColor

> +        QString hexColor = color.mid(1);
> +        if (hexColor.size() != 6) {
> +            hexColor = QString(6 - hexColor.size(), '0') + hexColor;
> +        }
> +        QRegExp rgbColorRe("((\\d|[a-f])(\\d|[a-f]))((\\d|[a-f])(\\d|[a-f]))((\\d|[a-f])(\\d|[a-f]))");
> +        if (rgbColorRe.exactMatch(hexColor)) {
> +            bool status = false;
> +            return returnColorFormat
> +                    .arg(rgbColorRe.cap(1).toUInt(&status, 16))
> +                    .arg(rgbColorRe.cap(4).toUInt(&status, 16))
> +                    .arg(rgbColorRe.cap(7).toUInt(&status, 16));
> +        }
> +        return QString();
> +    } else {
> +        QColor returnColor(color);
> +        return returnColor.isValid()
> +                ? returnColorFormat
> +                        .arg(returnColor.red())
> +                        .arg(returnColor.green())
> +                        .arg(returnColor.blue())
> +                        .toLower()
> +                : QString();
> +    }
> +}


-- 
https://code.launchpad.net/~abreu-alexandre/webbrowser-app/text-color-for-theme-color-webapps/+merge/287058
Your team Ubuntu Phablet Team is subscribed to branch lp:webbrowser-app.



More information about the Ubuntu-reviews mailing list