Commit db965fac authored by Boudewijn Rempt's avatar Boudewijn Rempt

FEATURE: Implement a global alpha lock "Preserve Layer Alpha"

BUG: 687451

This works by overriding the channel flags set in the KisResourcesSnapshot.
parent 83c7a7fd
......@@ -407,11 +407,21 @@ void KisCanvasResourceProvider::setOpacity(qreal opacity)
m_resourceManager->setResource(Opacity, opacity);
}
qreal KisCanvasResourceProvider::opacity()
qreal KisCanvasResourceProvider::opacity() const
{
return m_resourceManager->resource(Opacity).toDouble();
}
void KisCanvasResourceProvider::setGlobalAlphaLock(bool lock)
{
m_resourceManager->setResource(GlobalAlphaLock, lock);
}
bool KisCanvasResourceProvider::globalAlphaLock() const
{
return m_resourceManager->resource(GlobalAlphaLock).toBool();
}
void KisCanvasResourceProvider::notifyLoadingWorkspace(KisWorkspaceResource* workspace)
{
emit sigLoadingWorkspace(workspace);
......
......@@ -64,7 +64,8 @@ public:
MirrorVertical,
MirrorAxisCenter,
Opacity,
HdrGamma
HdrGamma,
GlobalAlphaLock
};
......@@ -118,7 +119,10 @@ public:
bool mirrorVertical() const;
void setOpacity(qreal opacity);
qreal opacity();
qreal opacity() const;
void setGlobalAlphaLock(bool lock);
bool globalAlphaLock() const;
void setPaintOpPreset(const KisPaintOpPresetSP preset);
......
......@@ -115,6 +115,15 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
m_eraseModeButton->setDefaultAction(eraseAction);
m_view->actionCollection()->addAction("erase_action", eraseAction);
m_alphaLockButton = new QToolButton(this);
m_alphaLockButton->setFixedSize(32, 32);
m_alphaLockButton->setCheckable(true);
KAction* alphaLockAction = new KAction(i18n("Preserve Alpha"), m_alphaLockButton);
alphaLockAction->setIcon(koIcon("transparency-unlocked"));
alphaLockAction->setCheckable(true);
m_alphaLockButton->setDefaultAction(alphaLockAction);
m_view->actionCollection()->addAction("preserve_alpha", alphaLockAction);
QToolButton* hMirrorButton = new QToolButton(this);
hMirrorButton->setFixedSize(32, 32);
hMirrorButton->setCheckable(true);
......@@ -191,6 +200,7 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
compositeLayout->addWidget(labelMode);
compositeLayout->addWidget(m_cmbCompositeOp);
compositeLayout->addWidget(m_eraseModeButton);
compositeLayout->addWidget(m_alphaLockButton);
compositeLayout->setContentsMargins(0, 0, 0, 0);
action = new KAction(i18n("Brush composite"), this);
view->actionCollection()->addAction("composite_actions", action);
......@@ -263,6 +273,7 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
connect(m_paletteButton , SIGNAL(clicked()) , SLOT(slotSaveToFavouriteBrushes()));
connect(m_cmbCompositeOp , SIGNAL(activated(int)) , SLOT(slotSetCompositeMode(int)));
connect(eraseAction , SIGNAL(triggered(bool)) , SLOT(slotToggleEraseMode(bool)));
connect(alphaLockAction , SIGNAL(triggered(bool)) , SLOT(slotToggleAlphaLockMode(bool)));
connect(hMirrorAction , SIGNAL(triggered(bool)) , SLOT(slotHorizontalMirrorChanged(bool)));
connect(vMirrorAction , SIGNAL(triggered(bool)) , SLOT(slotVerticalMirrorChanged(bool)));
......@@ -807,3 +818,14 @@ void KisPaintopBox::slotUnsetEraseMode()
updateCompositeOp(m_prevCompositeOpID);
}
}
void KisPaintopBox::slotToggleAlphaLockMode(bool checked)
{
if (checked) {
m_alphaLockButton->actions()[0]->setIcon(koIcon("transparency-locked"));
}
else {
m_alphaLockButton->actions()[0]->setIcon(koIcon("transparency-unlocked"));
}
m_resourceProvider->setGlobalAlphaLock(checked);
}
......@@ -127,6 +127,8 @@ private slots:
void slotNextFavoritePreset();
void slotSwitchToPreviousPreset();
void slotUnsetEraseMode();
void slotToggleAlphaLockMode(bool);
private:
KisCanvasResourceProvider* m_resourceProvider;
QHBoxLayout* m_layout;
......@@ -137,6 +139,7 @@ private:
KisPopupButton* m_brushChooser;
KisCompositeOpComboBox* m_cmbCompositeOp;
QToolButton* m_eraseModeButton;
QToolButton* m_alphaLockButton;
KisPaintOpPresetsPopup* m_presetsPopup;
KisPaintOpPresetsChooserPopup* m_presetsChooserPopup;
KisView2* m_view;
......
......@@ -32,8 +32,11 @@
#include "kis_default_bounds.h"
struct KisResourcesSnapshot::Private {
Private() : currentPattern(0), currentGradient(0),
currentGenerator(0), compositeOp(0)
Private()
: currentPattern(0)
, currentGradient(0)
, currentGenerator(0)
, compositeOp(0)
{
}
......@@ -59,6 +62,8 @@ struct KisResourcesSnapshot::Private {
KisPainter::StrokeStyle strokeStyle;
KisPainter::FillStyle fillStyle;
bool globalAlphaLock;
};
KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager, KisDefaultBoundsBaseSP bounds)
......@@ -70,6 +75,7 @@ KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUn
}
m_d->bounds = bounds;
m_d->undoAdapter = undoAdapter;
m_d->currentFgColor = resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value<KoColor>();
m_d->currentBgColor = resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value<KoColor>();
m_d->currentPattern = static_cast<KisPattern*>(resourceManager->resource(KisCanvasResourceProvider::CurrentPattern).value<void*>());
......@@ -102,6 +108,8 @@ KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUn
*/
m_d->strokeStyle = KisPainter::StrokeStyleBrush;
m_d->fillStyle = KisPainter::FillStyleNone;
m_d->globalAlphaLock = resourceManager->resource(KisCanvasResourceProvider::GlobalAlphaLock).toBool();
}
KisResourcesSnapshot::~KisResourcesSnapshot()
......@@ -118,9 +126,9 @@ void KisResourcesSnapshot::setupPainter(KisPainter* painter)
painter->setPattern(m_d->currentPattern);
painter->setGradient(m_d->currentGradient);
KisPaintLayer *paintLayer;
if ((paintLayer = dynamic_cast<KisPaintLayer*>(m_d->currentNode.data()))) {
painter->setChannelFlags(paintLayer->channelLockFlags());
QBitArray lockflags = channelLockFlags();
if (lockflags.size() > 0) {
painter->setChannelFlags(lockflags);
}
painter->setOpacity(m_d->opacity);
......@@ -232,3 +240,24 @@ KoColor KisResourcesSnapshot::currentBgColor() const
{
return m_d->currentBgColor;
}
QBitArray KisResourcesSnapshot::channelLockFlags() const
{
QBitArray channelFlags;
KisPaintLayer *paintLayer;
if ((paintLayer = dynamic_cast<KisPaintLayer*>(m_d->currentNode.data()))) {
channelFlags = paintLayer->channelLockFlags();
if (channelFlags.isEmpty()) {
channelFlags = paintLayer->colorSpace()->channelFlags(true, true);
}
if (m_d->globalAlphaLock) {
channelFlags &= paintLayer->colorSpace()->channelFlags(true, false);
}
else {
channelFlags |= paintLayer->colorSpace()->channelFlags(false, true);
}
}
return channelFlags;
}
......@@ -62,6 +62,9 @@ public:
KoColor currentFgColor() const;
KoColor currentBgColor() const;
/// @return the channel lock flags of the current node with the global override applied
QBitArray channelLockFlags() const;
private:
struct Private;
Private * const m_d;
......
......@@ -126,9 +126,9 @@ void KisPainterBasedStrokeStrategy::initStrokeCallback()
indirect->setTemporaryCompositeOp(m_resources->compositeOp());
indirect->setTemporaryOpacity(m_resources->opacity());
KisPaintLayer *paintLayer = dynamic_cast<KisPaintLayer*>(node.data());
if(paintLayer) {
indirect->setTemporaryChannelFlags(paintLayer->channelLockFlags());
QBitArray channelLockFlags = m_resources->channelLockFlags();
if (channelLockFlags.size() > 0) {
indirect->setTemporaryChannelFlags(channelLockFlags);
}
}
else {
......
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