diff --git a/libs/libkis/Krita.cpp b/libs/libkis/Krita.cpp --- a/libs/libkis/Krita.cpp +++ b/libs/libkis/Krita.cpp @@ -320,7 +320,7 @@ qc.setAlpha(0); KoColor bgColor(qc, cs); - if (!document->newImage(name, width, height, cs, bgColor, true, 1, "", double(resolution / 72) )) { + if (!document->newImage(name, width, height, cs, bgColor, KisConfig::RASTER_LAYER, 1, "", double(resolution / 72) )) { return 0; } diff --git a/libs/libqml/DocumentManager.cpp b/libs/libqml/DocumentManager.cpp --- a/libs/libqml/DocumentManager.cpp +++ b/libs/libqml/DocumentManager.cpp @@ -124,7 +124,7 @@ qc.setAlpha(0); KoColor bgColor(qc, cs); - d->document->newImage("New Image", d->newDocWidth, d->newDocHeight, KoColorSpaceRegistry::instance()->rgb8(), bgColor, true, 2, "", d->newDocResolution); + d->document->newImage("New Image", d->newDocWidth, d->newDocHeight, KoColorSpaceRegistry::instance()->rgb8(), bgColor, KisConfig::RASTER_LAYER, 2, "", d->newDocResolution); d->document->resetURL(); } else if (d->newDocOptions.contains("template")) { @@ -167,7 +167,7 @@ background.setAlphaF(d->newDocOptions.value("backgroundOpacity", 1.0f).toFloat()); KoColor bg(background, cs); - d->document->newImage(name, width, height, cs, bg, true, 1, "", res); + d->document->newImage(name, width, height, cs, bg, KisConfig::RASTER_LAYER, 1, "", res); d->document->resetURL(); } diff --git a/libs/ui/KisApplicationArguments.cpp b/libs/ui/KisApplicationArguments.cpp --- a/libs/ui/KisApplicationArguments.cpp +++ b/libs/ui/KisApplicationArguments.cpp @@ -331,6 +331,6 @@ return 0; } - doc->newImage(i18n("Unnamed"), d->width, d->height, cs, KoColor(QColor(Qt::white), cs), false, 1, "", 100.0); + doc->newImage(i18n("Unnamed"), d->width, d->height, cs, KoColor(QColor(Qt::white), cs), KisConfig::CANVAS_COLOR, 1, "", 100.0); return doc; } diff --git a/libs/ui/KisDocument.h b/libs/ui/KisDocument.h --- a/libs/ui/KisDocument.h +++ b/libs/ui/KisDocument.h @@ -40,6 +40,7 @@ #include #include #include +#include #include "kritaui_export.h" @@ -531,7 +532,7 @@ * Create a new image that has this document as a parent and * replace the current image with this image. */ - bool newImage(const QString& name, qint32 width, qint32 height, const KoColorSpace * cs, const KoColor &bgColor, bool backgroundAsLayer, + bool newImage(const QString& name, qint32 width, qint32 height, const KoColorSpace * cs, const KoColor &bgColor, KisConfig::BackgroundStyle bgStyle, int numberOfLayers, const QString &imageDescription, const double imageResolution); bool isSaving() const; diff --git a/libs/ui/KisDocument.cpp b/libs/ui/KisDocument.cpp --- a/libs/ui/KisDocument.cpp +++ b/libs/ui/KisDocument.cpp @@ -49,6 +49,8 @@ #include #include +#include +#include #include #include #include @@ -1632,14 +1634,13 @@ bool KisDocument::newImage(const QString& name, qint32 width, qint32 height, const KoColorSpace* cs, - const KoColor &bgColor, bool backgroundAsLayer, + const KoColor &bgColor, KisConfig::BackgroundStyle bgStyle, int numberOfLayers, const QString &description, const double imageResolution) { Q_ASSERT(cs); KisImageSP image; - KisPaintLayerSP layer; if (!cs) return false; @@ -1656,26 +1657,36 @@ documentInfo()->setAboutInfo("title", name); documentInfo()->setAboutInfo("abstract", description); - layer = new KisPaintLayer(image.data(), image->nextLayerName(), OPACITY_OPAQUE_U8, cs); - Q_CHECK_PTR(layer); + KisLayerSP layer; + if (bgStyle == KisConfig::RASTER_LAYER || bgStyle == KisConfig::FILL_LAYER) { + KoColor strippedAlpha = bgColor; + strippedAlpha.setOpacity(OPACITY_OPAQUE_U8); + + if (bgStyle == KisConfig::RASTER_LAYER) { + layer = new KisPaintLayer(image.data(), "Background", OPACITY_OPAQUE_U8, cs);; + layer->paintDevice()->setDefaultPixel(strippedAlpha); + } else if (bgStyle == KisConfig::FILL_LAYER) { + KisFilterConfigurationSP filter_config = KisGeneratorRegistry::instance()->get("color")->defaultConfiguration(); + filter_config->setProperty("color", strippedAlpha.toQColor()); + layer = new KisGeneratorLayer(image.data(), "Background Fill", filter_config, image->globalSelection()); + } - if (backgroundAsLayer) { - image->setDefaultProjectionColor(KoColor(cs)); + layer->setOpacity(bgColor.opacityU8()); - if (bgColor.opacityU8() == OPACITY_OPAQUE_U8) { - layer->paintDevice()->setDefaultPixel(bgColor); - } else { - // Hack: with a semi-transparent background color, the projection isn't composited right if we just set the default pixel - KisFillPainter painter; - painter.begin(layer->paintDevice()); - painter.fillRect(0, 0, width, height, bgColor, bgColor.opacityU8()); + if (numberOfLayers > 1) { + //Lock bg layer if others are present. + layer->setUserLocked(true); } - } else { + } + else { // KisConfig::CANVAS_COLOR (needs an unlocked starting layer). image->setDefaultProjectionColor(bgColor); + layer = new KisPaintLayer(image.data(), image->nextLayerName(), OPACITY_OPAQUE_U8, cs); } - layer->setDirty(QRect(0, 0, width, height)); + Q_CHECK_PTR(layer); image->addNode(layer.data(), image->rootLayer().data()); + layer->setDirty(QRect(0, 0, width, height)); + setCurrentImage(image); for(int i = 1; i < numberOfLayers; ++i) { diff --git a/libs/ui/forms/wdgnewimage.ui b/libs/ui/forms/wdgnewimage.ui --- a/libs/ui/forms/wdgnewimage.ui +++ b/libs/ui/forms/wdgnewimage.ui @@ -7,7 +7,7 @@ 0 0 600 - 462 + 491 @@ -41,7 +41,7 @@ - 0 + 1 @@ -383,7 +383,7 @@ - Ima&ge Background Opacity: + Background Opacity: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -401,6 +401,9 @@ 0 + + Number of layers that the image will start with, including optional background layer. + 1 @@ -415,7 +418,7 @@ - Image Bac&kground Color: + Bac&kground Color: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -467,19 +470,35 @@ - + + + Use background color and opacity to create a background raster layer. + - As fi&rst layer + As &raster layer + + Use background color and opacity as the base canvas color. This can be reconfigured in `Image > Properties.` + As can&vas color + + + + Use background color and opacity to create a background fill layer. The color for this layer can be reconfigured in the layer's properties. + + + As &fill layer + + + @@ -497,7 +516,7 @@ - Reset the image background color in the Image Properties dialog + @@ -556,6 +575,9 @@ + + + untitled-1 @@ -654,7 +676,7 @@ bnPortrait intNumLayers cmbColor - radioBackgroundAsLayer + radioBackgroundAsRaster radioBackgroundAsProjection txtDescription diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.h --- a/libs/ui/kis_config.h +++ b/libs/ui/kis_config.h @@ -435,8 +435,9 @@ void setDefaultBackgroundColor(QColor value); enum BackgroundStyle { - LAYER = 0, - PROJECTION = 1 + RASTER_LAYER = 0, + CANVAS_COLOR = 1, + FILL_LAYER = 2 }; BackgroundStyle defaultBackgroundStyle(bool defaultValue = false) const; diff --git a/libs/ui/kis_config.cc b/libs/ui/kis_config.cc --- a/libs/ui/kis_config.cc +++ b/libs/ui/kis_config.cc @@ -1555,7 +1555,7 @@ KisConfig::BackgroundStyle KisConfig::defaultBackgroundStyle(bool defaultValue) const { - return (KisConfig::BackgroundStyle)(defaultValue ? LAYER : m_cfg.readEntry("BackgroundStyleForNewImage", (int)LAYER)); + return (KisConfig::BackgroundStyle)(defaultValue ? RASTER_LAYER : m_cfg.readEntry("BackgroundStyleForNewImage", (int)RASTER_LAYER)); } void KisConfig::setDefaultBackgroundStyle(KisConfig::BackgroundStyle value) diff --git a/libs/ui/tests/kis_shape_selection_test.cpp b/libs/ui/tests/kis_shape_selection_test.cpp --- a/libs/ui/tests/kis_shape_selection_test.cpp +++ b/libs/ui/tests/kis_shape_selection_test.cpp @@ -42,7 +42,7 @@ QColor qc(Qt::white); qc.setAlpha(0); KoColor bgColor(qc, cs); - doc->newImage("test", 300, 300, cs, bgColor, true, 1, "test", 100); + doc->newImage("test", 300, 300, cs, bgColor, KisConfig::CANVAS_COLOR, 1, "test", 100); KisImageSP image = doc->image(); KisSelectionSP selection = new KisSelection(); diff --git a/libs/ui/widgets/kis_custom_image_widget.cc b/libs/ui/widgets/kis_custom_image_widget.cc --- a/libs/ui/widgets/kis_custom_image_widget.cc +++ b/libs/ui/widgets/kis_custom_image_widget.cc @@ -151,8 +151,10 @@ KisConfig::BackgroundStyle bgStyle = cfg.defaultBackgroundStyle(); - if (bgStyle == KisConfig::LAYER) { - radioBackgroundAsLayer->setChecked(true); + if (bgStyle == KisConfig::RASTER_LAYER) { + radioBackgroundAsRaster->setChecked(true); + } else if (bgStyle == KisConfig::FILL_LAYER) { + radioBackgroundAsFill->setChecked(true); } else { radioBackgroundAsProjection->setChecked(true); } @@ -258,7 +260,6 @@ KisDocument* KisCustomImageWidget::createNewImage() { - const KoColorSpace * cs = colorSpaceSelector->currentColorSpace(); if (cs->colorModelId() == RGBAColorModelID && @@ -303,15 +304,20 @@ qc.setAlpha(backgroundOpacity()); KoColor bgColor(qc, cs); - bool backgroundAsLayer = radioBackgroundAsLayer->isChecked(); + KisConfig::BackgroundStyle bgStyle = KisConfig::CANVAS_COLOR; + if( radioBackgroundAsRaster->isChecked() ){ + bgStyle = KisConfig::RASTER_LAYER; + } else if( radioBackgroundAsFill->isChecked() ){ + bgStyle = KisConfig::FILL_LAYER; + } - doc->newImage(txtName->text(), width, height, cs, bgColor, backgroundAsLayer, intNumLayers->value(), txtDescription->toPlainText(), resolution); + doc->newImage(txtName->text(), width, height, cs, bgColor, bgStyle, intNumLayers->value(), txtDescription->toPlainText(), resolution); KisConfig cfg(true); cfg.setNumDefaultLayers(intNumLayers->value()); cfg.setDefaultBackgroundOpacity(backgroundOpacity()); cfg.setDefaultBackgroundColor(cmbColor->color().toQColor()); - cfg.setDefaultBackgroundStyle(backgroundAsLayer ? KisConfig::LAYER : KisConfig::PROJECTION); + cfg.setDefaultBackgroundStyle(bgStyle); return doc; }