Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2a18026d authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Add pattern transform options to fill tool.

parent 9853d845
......@@ -251,7 +251,7 @@ void KisFillPainter::fillColor(int startX, int startY, KisPaintDeviceSP sourceDe
}
}
void KisFillPainter::fillPattern(int startX, int startY, KisPaintDeviceSP sourceDevice)
void KisFillPainter::fillPattern(int startX, int startY, KisPaintDeviceSP sourceDevice, QTransform patternTransform)
{
genericFillStart(startX, startY, sourceDevice);
......@@ -259,7 +259,7 @@ void KisFillPainter::fillPattern(int startX, int startY, KisPaintDeviceSP source
KisPaintDeviceSP filled = device()->createCompositionSourceDevice();
Q_CHECK_PTR(filled);
KisFillPainter painter(filled);
painter.fillRect(QRect(0, 0, m_width, m_height), pattern(), QTransform());
painter.fillRect(QRect(0, 0, m_width, m_height), pattern(), patternTransform);
painter.end();
genericFillEnd(filled);
......
......@@ -165,8 +165,9 @@ public:
* @param startY the Y position where the floodfill starts
* @param sourceDevice the sourceDevice that determines the area that
* is floodfilled if sampleMerged is on
* @param patternTransform transform applied to the pattern;
*/
void fillPattern(int startX, int startY, KisPaintDeviceSP sourceDevice);
void fillPattern(int startX, int startY, KisPaintDeviceSP sourceDevice, QTransform patternTransform = QTransform());
/**
* Returns a selection mask for the floodfill starting at the specified position.
......
......@@ -82,7 +82,7 @@ void FillProcessingVisitor::fillPaintDevice(KisPaintDeviceSP device, KisUndoAdap
fillPainter.setProgress(helper.updater());
if (m_usePattern) {
fillPainter.fillRect(fillRect, m_resources->currentPattern(), QTransform());
fillPainter.fillRect(fillRect, m_resources->currentPattern(), m_resources->fillTransform());
} else if (m_useBgColor) {
fillPainter.fillRect(fillRect,
m_resources->currentBgColor(),
......@@ -130,7 +130,7 @@ void FillProcessingVisitor::fillPaintDevice(KisPaintDeviceSP device, KisUndoAdap
KisPaintDeviceSP sourceDevice = m_unmerged ? device : m_refPaintDevice;
if (m_usePattern) {
fillPainter.fillPattern(startPoint.x(), startPoint.y(), sourceDevice);
fillPainter.fillPattern(startPoint.x(), startPoint.y(), sourceDevice, m_resources->fillTransform());
} else {
fillPainter.fillColor(startPoint.x(), startPoint.y(), sourceDevice);
}
......
......@@ -381,6 +381,11 @@ KisPaintOpPresetSP KisResourcesSnapshot::currentPaintOpPreset() const
return m_d->currentPaintOpPreset;
}
QTransform KisResourcesSnapshot::fillTransform() const
{
return m_d->fillTransform;
}
QBitArray KisResourcesSnapshot::channelLockFlags() const
{
......
......@@ -84,6 +84,8 @@ public:
KoColor currentBgColor() const;
KisPaintOpPresetSP currentPaintOpPreset() const;
QTransform fillTransform() const;
/// @return the channel lock flags of the current node with the global override applied
QBitArray channelLockFlags() const;
......
......@@ -29,6 +29,7 @@
#include <QLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QGroupBox>
#include <QVector>
#include <QRect>
#include <QColor>
......@@ -195,6 +196,12 @@ void KisToolFill::endPrimaryAction(KoPointerEvent *event)
KIS_ASSERT(refPaintDevice);
QTransform transform;
transform.rotate(m_patternRotation);
transform.scale(m_patternScale, m_patternScale);
resources->setFillTransform(transform);
KisProcessingVisitorSP visitor =
new FillProcessingVisitor(refPaintDevice,
m_startPos,
......@@ -255,6 +262,20 @@ QWidget* KisToolFill::createOptionWidget()
m_checkUsePattern = new QCheckBox(QString(), widget);
m_checkUsePattern->setToolTip(i18n("When checked do not use the foreground color, but the pattern selected to fill with"));
QLabel *lbl_patternRotation = new QLabel(i18n("Rotate:"), widget);
m_sldPatternRotate = new KisDoubleSliderSpinBox(widget);
m_sldPatternRotate->setObjectName("patternrotate");
m_sldPatternRotate->setRange(0, 360, 2);
m_sldPatternRotate->setSingleStep(1.0);
m_sldPatternRotate->setSuffix(QChar(Qt::Key_degree));
QLabel *lbl_patternScale = new QLabel(i18n("Scale:"), widget);
m_sldPatternScale = new KisDoubleSliderSpinBox(widget);
m_sldPatternScale->setObjectName("patternscale");
m_sldPatternScale->setRange(0, 500, 2);
m_sldPatternScale->setSingleStep(1.0);
m_sldPatternScale->setSuffix(QChar(Qt::Key_Percent));
QLabel *lbl_sampleLayers = new QLabel(i18nc("This is a label before a combobox with different choices regarding which layers "
"to take into considerationg when calculating the area to fill. "
"Options together with the label are: /Sample current layer/ /Sample all layers/ "
......@@ -283,6 +304,8 @@ QWidget* KisToolFill::createOptionWidget()
connect (m_checkFillSelection, SIGNAL(toggled(bool)) , this, SLOT(slotSetFillSelection(bool)));
connect (m_cmbSampleLayersMode , SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetSampleLayers(int)));
connect (m_cmbSelectedLabels , SIGNAL(selectedColorsChanged()), this, SLOT(slotSetSelectedColorLabels()));
connect (m_sldPatternRotate , SIGNAL(valueChanged(qreal)), this, SLOT(slotSetPatternRotation(qreal)));
connect (m_sldPatternScale , SIGNAL(valueChanged(qreal)), this, SLOT(slotSetPatternScale(qreal)));
addOptionWidgetOption(m_useFastMode, lbl_fastMode);
addOptionWidgetOption(m_slThreshold, lbl_threshold);
......@@ -294,6 +317,9 @@ QWidget* KisToolFill::createOptionWidget()
addOptionWidgetOption(m_cmbSelectedLabels, lbl_cmbLabel);
addOptionWidgetOption(m_checkUsePattern, lbl_usePattern);
addOptionWidgetOption(m_sldPatternRotate, lbl_patternRotation);
addOptionWidgetOption(m_sldPatternScale, lbl_patternScale);
updateGUI();
widget->setFixedHeight(widget->sizeHint().height());
......@@ -317,6 +343,9 @@ QWidget* KisToolFill::createOptionWidget()
}
m_checkFillSelection->setChecked(m_configGroup.readEntry("fillSelection", false));
m_sldPatternRotate->setValue(m_configGroup.readEntry("patternRotate", 0.0));
m_sldPatternScale->setValue(m_configGroup.readEntry("patternScale", 100.0));
activateConnectionsToImage();
m_widgetsInitialized = true;
......@@ -334,6 +363,8 @@ void KisToolFill::updateGUI()
m_sizemodWidget->setEnabled(!selectionOnly && useAdvancedMode);
m_featherWidget->setEnabled(!selectionOnly && useAdvancedMode);
m_checkUsePattern->setEnabled(useAdvancedMode);
m_sldPatternRotate->setEnabled((m_checkUsePattern->isChecked() && useAdvancedMode));
m_sldPatternScale->setEnabled((m_checkUsePattern->isChecked() && useAdvancedMode));
m_cmbSampleLayersMode->setEnabled(!selectionOnly && useAdvancedMode);
......@@ -409,6 +440,8 @@ void KisToolFill::slotSetThreshold(int threshold)
void KisToolFill::slotSetUsePattern(bool state)
{
m_usePattern = state;
m_sldPatternScale->setEnabled(state);
m_sldPatternRotate->setEnabled(state);
m_configGroup.writeEntry("usePattern", state);
}
......@@ -425,6 +458,18 @@ void KisToolFill::slotSetSelectedColorLabels()
m_selectedColors = m_cmbSelectedLabels->selectedColors();
}
void KisToolFill::slotSetPatternScale(qreal scale)
{
m_patternScale = scale*0.01;
m_configGroup.writeEntry("patternScale", scale);
}
void KisToolFill::slotSetPatternRotation(qreal rotate)
{
m_patternRotation = rotate;
m_configGroup.writeEntry("patternRotate", rotate);
}
void KisToolFill::slotSetFillSelection(bool state)
{
m_fillOnlySelection = state;
......
......@@ -36,6 +36,7 @@
class QWidget;
class QCheckBox;
class KisSliderSpinBox;
class KisDoubleSliderSpinBox;
class KoCanvasBase;
class KisColorFilterCombo;
class KisDummiesFacadeBase;
......@@ -66,6 +67,8 @@ public Q_SLOTS:
void slotSetFeather(int);
void slotSetSampleLayers(int index);
void slotSetSelectedColorLabels();
void slotSetPatternScale(qreal scale);
void slotSetPatternRotation(qreal rotate);
protected Q_SLOTS:
void resetCursorStyle() override;
......@@ -99,6 +102,8 @@ private:
bool m_fillOnlySelection;
QString m_sampleLayersMode;
QList<int> m_selectedColors;
qreal m_patternRotation;
qreal m_patternScale;
bool m_widgetsInitialized {false};
......@@ -106,6 +111,8 @@ private:
KisSliderSpinBox *m_slThreshold;
KisSliderSpinBox *m_sizemodWidget;
KisSliderSpinBox *m_featherWidget;
KisDoubleSliderSpinBox *m_sldPatternRotate;
KisDoubleSliderSpinBox *m_sldPatternScale;
QCheckBox *m_checkUsePattern;
QCheckBox *m_checkFillSelection;
QComboBox *m_cmbSampleLayersMode;
......
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