Commit 24f97f7d authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add Document::setBackgroundColor API

This can be used like this:

from krita import Krita
from PyQt5.QtGui import QColor

kt = Krita.instance()
doc = kt.activeDocument()

test_color = QColor(128, 128, 128, 255)  # change as needed

old_background = doc.backGroundColor()
print("Old background: {}".format(old_background.getRgb()))


new_background = doc.backGroundColor()
print("New background {}".format(new_background.getRgb()))

Patch by Jeroen Hoolmans, thanks!
fferential Revision:
parent 4cbc15c8
......@@ -52,8 +52,10 @@
#include <kis_filter_strategy.h>
#include <kis_guides_config.h>
#include <kis_coordinates_converter.h>
#include <kis_layer_utils.h>
#include <KisMimeDatabase.h>
#include <KoColor.h>
#include <KoColorSpace.h>
#include <KoColorProfile.h>
#include <KoColorSpaceRegistry.h>
......@@ -197,6 +199,28 @@ bool Document::setColorSpace(const QString &colorModel, const QString &colorDept
return true;
QColor Document::backGroundColor()
if (!d->document) return QColor();
if (!d->document->image()) return QColor();
const KoColor color = d->document->image()->defaultProjectionColor();
return color.toQColor();
bool Document::setBackGroundColor(const QColor &color)
if (!d->document) return false;
if (!d->document->image()) return false;
KoColor background = KoColor(color, d->document->image()->colorSpace());
return true;
QString Document::documentInfo() const
......@@ -190,6 +190,22 @@ public Q_SLOTS:
bool setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile);
* @brief backgroundColor returns the current background color of the document. The color will
* also include the opacity.
* @return QColor
QColor backGroundColor();
* @brief setBackGroundColor sets the background color of the document. It will trigger a projection
* update.
* @param color A QColor. The color will be converted from sRGB.
* @return bool
bool setBackGroundColor(const QColor &color);
* @brief documentInfo creates and XML document representing document and author information.
......@@ -26,6 +26,8 @@ public Q_SLOTS:
QString colorProfile() const;
bool setColorProfile(const QString &colorProfile);
bool setColorSpace(const QString &value, const QString &colorDepth, const QString &colorProfile);
QColor backGroundColor();
bool setBackGroundColor(const QColor &color);
QString documentInfo() const;
void setDocumentInfo(const QString &document);
QString fileName() const;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment