9#include <QGraphicsPixmapItem>
10#include <QGraphicsScene>
31 : QGraphicsView(parent),
51 setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
52 setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
138 int checkerSize = 12;
141 int numCheckersV = std::ceil(
m_image->
height() / (
float)checkerSize);
142 int numCheckersH = std::ceil(
m_image->
width() / (
float)checkerSize);
146 bool altColor =
true;
147 for (
int y = 0; y < numCheckersV; y++) {
148 for (
int x = 0; x < numCheckersH; x++) {
149 altColor = !altColor;
153 painter.
fill(x * checkerSize, y * checkerSize, checkerSize, checkerSize, checker1);
157 if (numCheckersH % 2 == 0) {
158 altColor = !altColor;
194 const int grayStrips = 20;
195 const float sectionPercent = 1.0f / grayStrips;
199 for (
int i = 0; i < grayStrips; i++) {
201 fillColor.
fromQColor((i % 2) ? QColor(80, 80, 80) : QColor(140, 140, 140));
203 const QRect fillRect(imageWidth * sectionPercent * i,
205 imageWidth * (sectionPercent * i + sectionPercent),
224 const QColor backgroundColor = palette().color(QPalette::Window);
249 const QColor textColor = palette().color(QPalette::Text);
263 font.setPixelSize(14);
266 m_noPreviewText = this->scene()->addText(i18n(
"No Preview for this engine"),font);
311 qreal previewSize = qBound(3.0,
m_currentPreset->settings()->paintOpSize(), 25.0 );
321 settings->setPaintOpSize(previewSize);
327 int maxTextureSize = 200;
328 int textureOffsetX = settings->getInt(
"Texture/Pattern/MaximumOffsetX")*2;
329 int textureOffsetY = settings->getInt(
"Texture/Pattern/MaximumOffsetY")*2;
330 double textureScale = settings->getDouble(
"Texture/Pattern/Scale");
331 if ( textureOffsetX*textureScale> maxTextureSize || textureOffsetY*textureScale > maxTextureSize) {
332 int maxSize = qMax(textureOffsetX, textureOffsetY);
333 double result = qreal(maxTextureSize) / maxSize;
334 settings->setProperty(
"Texture/Pattern/Scale", result);
336 if (proxy_preset->paintOp().id() ==
"spraybrush") {
340 QString brushDefinition = settings->getString(
"brush_definition");
341 if (!brushDefinition.isEmpty()) {
342 d.setContent(brushDefinition);
343 element = d.firstChildElement(
"Brush");
347 qreal width = brush->image().width();
348 qreal scale = brush->scale();
349 qreal diameterToBrushRatio = 1.0;
350 qreal diameter = settings->getInt(
"Spray/diameter");
352 if (brush->filename().endsWith(
".svg", Qt::CaseInsensitive)) {
353 diameterToBrushRatio = diameter/(1000.0*scale);
354 scale = 25.0 / 1000.0;
356 if (width * scale > 25.0) {
357 diameterToBrushRatio = diameter / (width * scale);
358 scale = 25.0 / width;
360 if (!settings->getBool(
"SprayShape/proportional")) {
361 settings->setProperty(
"SprayShape/width", qRound(scale * settings->getInt(
"SprayShape/width")));
362 settings->setProperty(
"SprayShape/height", qRound(scale * settings->getInt(
"SprayShape/height")));
366 settings->setProperty(
"Spray/diameter",
int(25.0 * diameterToBrushRatio));
368 brush->setScale(scale);
370 element = d.createElement(
"Brush");
371 brush->toXML(d, element);
372 d.appendChild(element);
373 settings->setProperty(
"brush_definition", d.toString());
377 proxy_preset->setSettings(settings);
384 resources->
setOpacity(settings->paintOpOpacity());
401 if (proxy_preset->paintOp().id() ==
"mypaintbrush") {
408 if (proxy_preset->paintOp().id() ==
"sketchbrush"
409 || proxy_preset->paintOp().id() ==
"curvebrush"
410 || proxy_preset->paintOp().id() ==
"particlebrush") {
416 pointOne.
setPos(QPointF(startX, middle));
419 pointTwo.
setPos(QPointF(startX, middle));
422 for (
int i = 0; i < repeats; i++) {
427 qreal xPos = ((1.0/repeats) * (i+1) * (endX-startX) )+startX;
428 pointTwo.
setPos(QPointF(xPos, middle));
430 qreal offset = (this->height()/(repeats*1.5))*(i+1);
431 qreal handleY = middle + offset;
433 handleY = middle - offset;
439 QPointF(pointOne.
pos().x(),
441 QPointF(pointTwo.
pos().x(),
490 QWidget::changeEvent(event);
498#include "kis_preset_live_preview_view.moc"
const quint8 OPACITY_OPAQUE_U8
const QString COMPOSITE_OVER
const QString COMPOSITE_ERASE
static bool needsStripedBackground(const QString &paintOpId)
True if paint engine needs striped background (colorsmudge, deform, filter).
static bool isNoPreviewEngine(const QString &paintOpId)
True if paint engine has no preview support.
static KisBrushSP fromXML(const QDomElement &element, KisResourcesInterfaceSP resourcesInterface)
static KisResourcesInterfaceSP instance()
const KoColorSpace * colorSpace() const
void addJob(KisStrokeId id, KisStrokeJobData *data) override
KisStrokeId startStroke(KisStrokeStrategy *strokeStrategy) override
QRect bounds() const override
void endStroke(KisStrokeId id) override
void fill(const QRect &rc, const KoColor &color)
const KoColorSpace * colorSpace() const
QImage convertToQImage(const KoColorProfile *dstProfile, qint32 x, qint32 y, qint32 w, qint32 h, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags()) const
void fill(qint32 x, qint32 y, qint32 width, qint32 height, const KoColor &color)
void bitBlt(qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
void setCompositeOpId(const KoCompositeOp *op)
KisPaintOpPresetSP m_currentPreset
int m_previewPresetId
presetId (resource id) associated with the in-flight preview generation.
QGraphicsScene * m_brushPreviewScene
the scene that can add items like text and the brush stroke image
void sigPreviewImageReady(int presetId, QImage previewImage)
Emitted when a preview image is generated.
const KoColorSpace * m_colorSpace
internally sets the color space for brush preview
~KisPresetLivePreviewView()
void changeEvent(QEvent *) override
KisPresetLivePreviewView(QWidget *parent)
void setupAndPaintStroke()
creates and performs the actual stroke that goes on top of the background this is internally and shou...
KoCanvasResourceProvider * m_resourceManager
internally sets the Resource Provider for brush preview (allowing gradients in preview)
void setCurrentPreset(KisPaintOpPresetSP preset)
set the current preset from resource manager for the live preview to use. Good to call this every str...
QGraphicsTextItem * m_noPreviewText
holds the 'no preview available' text object
KisImageSP m_image
internally sets the image area for brush preview
void setCachePreviewMode(bool enabled)
void paintBackground(bool cacheMode)
works as both clearing the previous stroke, providing striped backgrounds for smudging brushes,...
QGraphicsPixmapItem * m_sceneImageItem
holds the preview brush stroke data
QImage m_lastPreviewImage
Last preview image.
void requestUpdateStroke()
KisLayerSP m_layer
internally sets the layer area for brush preview
KisSignalCompressor m_updateCompressor
void setup(KoCanvasResourceProvider *resourceManager)
one time setup for initialization of many variables. This live preview might be in a UI file,...
KisPaintInformation m_curvePointPI1
KoCanvasResourceProvider * resourceManager() const
bool m_previewGenerationInProgress
QPointF m_canvasCenterPoint
KoColor m_paintColor
the color which is used for rendering the stroke
void requestUpdateStrokeImmediate()
void slotPreviewGenerationCompleted()
void paintStripedBackground()
Paint alternating gray stripes on the paint device.
KisPaintInformation m_curvePointPI2
The KisResourcesSnapshot class takes a snapshot of the various resources like colors and settings use...
void setFGColorOverride(const KoColor &color)
void setMirroring(bool horizontal, bool vertical)
void setOpacity(qreal opacity)
void setCompositeOpId(const QString &compositeOpId)
Override the composite op for the snapshot.
void enableJob(JobType type, bool enable=true, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
void setClearsRedoOnStart(bool value)
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
void initStrokeCallback() override
void cancelStrokeCallback() override
KUndo2MagicString kundo2_noi18n(const QString &text)
virtual KisPaintDeviceSP paintDevice() const =0
static KoColorSpaceRegistry * instance()
const KoColorSpace * rgb8(const QString &profileName=QString())