OSDN Git Service

optimize QBrush::isOpaque()
authorIvailo Monev <xakepa10@laimg.moc>
Thu, 9 Jul 2020 12:11:07 +0000 (12:11 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Thu, 9 Jul 2020 12:11:07 +0000 (12:11 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
src/gui/painting/qbrush.cpp

index d050f83..8f487b2 100644 (file)
@@ -758,23 +758,6 @@ const QGradient *QBrush::gradient() const
     return 0;
 }
 
-static bool qt_isExtendedRadialGradient(const QBrush &brush)
-{
-    if (brush.style() == Qt::RadialGradientPattern) {
-        const QGradient *g = brush.gradient();
-        const QRadialGradient *rg = static_cast<const QRadialGradient *>(g);
-
-        if (!qFuzzyIsNull(rg->focalRadius()))
-            return true;
-
-        QPointF delta = rg->focalPoint() - rg->center();
-        if (delta.x() * delta.x() + delta.y() * delta.y() > rg->radius() * rg->radius())
-            return true;
-    }
-
-    return false;
-}
-
 /*!
     Returns true if the brush is fully opaque otherwise false. A brush
     is considered opaque if:
@@ -789,22 +772,27 @@ static bool qt_isExtendedRadialGradient(const QBrush &brush)
 
 bool QBrush::isOpaque() const
 {
-    bool opaqueColor = d->color.alpha() == 255;
+    // Test awfully simple case first, opaque color
+    if (d->style == Qt::SolidPattern) {
+        return (d->color.alpha() == 255);
+    } else if (d->style == Qt::RadialGradientPattern) {
+        const QRadialGradient *rg = static_cast<const QRadialGradient *>(gradient());
 
-    // Test awfully simple case first
-    if (d->style == Qt::SolidPattern)
-        return opaqueColor;
+        if (!qFuzzyIsNull(rg->focalRadius()))
+            return false;
 
-    if (qt_isExtendedRadialGradient(*this))
-        return false;
+        QPointF delta = rg->focalPoint() - rg->center();
+        if (delta.x() * delta.x() + delta.y() * delta.y() > rg->radius() * rg->radius())
+            return false;
+    }
 
     if (d->style == Qt::LinearGradientPattern
         || d->style == Qt::RadialGradientPattern
         || d->style == Qt::ConicalGradientPattern) {
-        QGradientStops stops = gradient()->stops();
-        for (int i=0; i<stops.size(); ++i)
-            if (stops.at(i).second.alpha() != 255)
+        foreach (const QGradientStop &stop, gradient()->stops()) {
+            if (stop.second.alpha() != 255)
                 return false;
+        }
         return true;
     } else if (d->style == Qt::TexturePattern) {
         return qHasPixmapTexture(*this)