void KisCanvasResourceProvider::slotCanvasResourceChanged(int key, const QVariant & res) { if(key == KoCanvasResourceManager::ForegroundColor || key == KoCanvasResourceManager::BackgroundColor) { KoAbstractGradient* resource = KoResourceServerProvider::instance()->gradientServer()->resources()[0]; KoStopGradient* stopGradient = dynamic_cast<KoStopGradient*>(resource); if(stopGradient) { QList<KoGradientStop> stops; stops << KoGradientStop(0.0, fgColor()) << KoGradientStop(1.0, bgColor()); stopGradient->setStops(stops); KoResourceServerProvider::instance()->gradientServer()->updateResource(resource); } resource = KoResourceServerProvider::instance()->gradientServer()->resources()[1]; stopGradient = dynamic_cast<KoStopGradient*>(resource); if(stopGradient) { QList<KoGradientStop> stops; stops << KoGradientStop(0.0, fgColor()) << KoGradientStop(1.0, KoColor(QColor(0, 0, 0, 0), fgColor().colorSpace())); stopGradient->setStops(stops); KoResourceServerProvider::instance()->gradientServer()->updateResource(resource); } } switch (key) { case(KoCanvasResourceManager::ForegroundColor): m_fGChanged = true; emit sigFGColorChanged(res.value<KoColor>()); break; case(KoCanvasResourceManager::BackgroundColor): emit sigBGColorChanged(res.value<KoColor>()); break; case(CurrentPattern): emit sigPatternChanged(static_cast<KisPattern *>(res.value<void *>())); break; case(CurrentGeneratorConfiguration): emit sigGeneratorConfigurationChanged(static_cast<KisFilterConfiguration*>(res.value<void*>())); case(CurrentGradient): emit sigGradientChanged(static_cast<KoAbstractGradient *>(res.value<void *>())); break; case(CurrentPaintOpPreset): emit sigPaintOpPresetChanged(currentPreset()); break; case(CurrentKritaNode) : emit sigNodeChanged(currentNode()); break; case(CurrentCompositeOp) : emit sigCompositeOpChanged(currentCompositeOp()); break; case (Opacity): { emit sigOpacityChanged(res.toDouble()); } default: ; // Do nothing }; }
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; }
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); }