GradientResourceServer(const QString& type, const QString& extensions) : KoResourceServer<KoAbstractGradient>(type, extensions) { const KoColorSpace* cs = KoColorSpaceRegistry::instance()->rgb8(); KoStopGradient* gradient = new KoStopGradient(""); gradient->setType(QGradient::LinearGradient); gradient->setName("Foreground to Background"); QList<KoGradientStop> stops; stops << KoGradientStop(0.0, KoColor(Qt::black, cs)) << KoGradientStop(1.0, KoColor(Qt::white, cs)); gradient->setStops(stops); gradient->setValid(true); addResource(gradient, false); gradient = new KoStopGradient(""); gradient->setType(QGradient::LinearGradient); gradient->setName("Foreground to Transparent"); stops.clear(); stops << KoGradientStop(0.0, KoColor(Qt::black, cs)) << KoGradientStop(1.0, KoColor(QColor(0, 0, 0, 0), cs)); gradient->setStops(stops); gradient->setValid(true); addResource(gradient, false); }
KoStopGradient * KoStopGradient::fromQGradient(QGradient * gradient) { if (! gradient) return 0; KoStopGradient * newGradient = new KoStopGradient(""); newGradient->setType(gradient->type()); newGradient->setSpread(gradient->spread()); switch (gradient->type()) { case QGradient::LinearGradient: { QLinearGradient * g = static_cast<QLinearGradient*>(gradient); newGradient->m_start = g->start(); newGradient->m_stop = g->finalStop(); newGradient->m_focalPoint = g->start(); break; } case QGradient::RadialGradient: { QRadialGradient * g = static_cast<QRadialGradient*>(gradient); newGradient->m_start = g->center(); newGradient->m_stop = g->center() + QPointF(g->radius(), 0); newGradient->m_focalPoint = g->focalPoint(); break; } case QGradient::ConicalGradient: { QConicalGradient * g = static_cast<QConicalGradient*>(gradient); qreal radian = g->angle() * M_PI / 180.0; newGradient->m_start = g->center(); newGradient->m_stop = QPointF(100.0 * cos(radian), 100.0 * sin(radian)); newGradient->m_focalPoint = g->center(); break; } default: delete newGradient; return 0; } Q_FOREACH (const QGradientStop & stop, gradient->stops()) { KoColor color(newGradient->colorSpace()); color.fromQColor(stop.second); newGradient->m_stops.append(KoGradientStop(stop.first, color)); } return newGradient; }