Commit 91bdcfe3 authored by Timothée Giet's avatar Timothée Giet

new Eraser Switch Opacity feature

add a new Eraser Switch Opacity feature, similar to the Eraser Switch Size one
Completes task 3546
parent 9ad6d6f7
...@@ -284,6 +284,27 @@ void KisPaintOpSettings::setSavedBrushSize(qreal value) ...@@ -284,6 +284,27 @@ void KisPaintOpSettings::setSavedBrushSize(qreal value)
setPropertyNotSaved("SavedBrushSize"); setPropertyNotSaved("SavedBrushSize");
} }
qreal KisPaintOpSettings::savedEraserOpacity() const
{
return getDouble("SavedEraserOpacity", 0.0);
}
void KisPaintOpSettings::setSavedEraserOpacity(qreal value)
{
setProperty("SavedEraserOpacity", value);
setPropertyNotSaved("SavedEraserOpacity");
}
qreal KisPaintOpSettings::savedBrushOpacity() const
{
return getDouble("SavedBrushOpacity", 0.0);
}
void KisPaintOpSettings::setSavedBrushOpacity(qreal value)
{
setProperty("SavedBrushOpacity", value);
setPropertyNotSaved("SavedBrushOpacity");
}
QString KisPaintOpSettings::modelName() const QString KisPaintOpSettings::modelName() const
{ {
......
...@@ -208,6 +208,11 @@ public: ...@@ -208,6 +208,11 @@ public:
qreal savedBrushSize() const; qreal savedBrushSize() const;
void setSavedBrushSize(qreal value); void setSavedBrushSize(qreal value);
qreal savedEraserOpacity() const;
void setSavedEraserOpacity(qreal value);
qreal savedBrushOpacity() const;
void setSavedBrushOpacity(qreal value);
QString effectivePaintOpCompositeOp() const; QString effectivePaintOpCompositeOp() const;
void setPreset(KisPaintOpPresetWSP preset); void setPreset(KisPaintOpPresetWSP preset);
......
...@@ -275,6 +275,25 @@ ...@@ -275,6 +275,25 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="eraserBrushOpacityCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Erase mode will use a separate brush opacity</string>
</property>
<property name="text">
<string>Eraser switch opacity</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="KisLodAvailabilityWidget" name="wdgLodAvailability" native="true"> <widget class="KisLodAvailabilityWidget" name="wdgLodAvailability" native="true">
<property name="minimumSize"> <property name="minimumSize">
......
...@@ -357,6 +357,18 @@ void KisConfig::setUseEraserBrushSize(bool value) ...@@ -357,6 +357,18 @@ void KisConfig::setUseEraserBrushSize(bool value)
KisConfigNotifier::instance()->notifyConfigChanged(); KisConfigNotifier::instance()->notifyConfigChanged();
} }
bool KisConfig::useEraserBrushOpacity(bool defaultValue) const
{
return (defaultValue ? false : m_cfg.readEntry("useEraserBrushOpacity",false));
}
void KisConfig::setUseEraserBrushOpacity(bool value)
{
m_cfg.writeEntry("useEraserBrushOpacity",value);
KisConfigNotifier::instance()->notifyConfigChanged();
}
QColor KisConfig::getMDIBackgroundColor(bool defaultValue) const QColor KisConfig::getMDIBackgroundColor(bool defaultValue) const
{ {
QColor col(77, 77, 77); QColor col(77, 77, 77);
......
...@@ -436,6 +436,9 @@ public: ...@@ -436,6 +436,9 @@ public:
bool useEraserBrushSize(bool defaultValue = false) const; bool useEraserBrushSize(bool defaultValue = false) const;
void setUseEraserBrushSize(bool value); void setUseEraserBrushSize(bool value);
bool useEraserBrushOpacity(bool defaultValue = false) const;
void setUseEraserBrushOpacity(bool value);
QColor getMDIBackgroundColor(bool defaultValue = false) const; QColor getMDIBackgroundColor(bool defaultValue = false) const;
void setMDIBackgroundColor(const QColor & v) const; void setMDIBackgroundColor(const QColor & v) const;
......
...@@ -101,6 +101,7 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char * ...@@ -101,6 +101,7 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
, m_blockUpdate(false) , m_blockUpdate(false)
, m_dirtyPresetsEnabled(false) , m_dirtyPresetsEnabled(false)
, m_eraserBrushSizeEnabled(false) , m_eraserBrushSizeEnabled(false)
, m_eraserBrushOpacityEnabled(false)
, m_presetUpdateCompressor(200, KisSignalCompressor::FIRST_ACTIVE) , m_presetUpdateCompressor(200, KisSignalCompressor::FIRST_ACTIVE)
{ {
Q_ASSERT(view != 0); Q_ASSERT(view != 0);
...@@ -110,6 +111,7 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char * ...@@ -110,6 +111,7 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
KisConfig cfg; KisConfig cfg;
m_dirtyPresetsEnabled = cfg.useDirtyPresets(); m_dirtyPresetsEnabled = cfg.useDirtyPresets();
m_eraserBrushSizeEnabled = cfg.useEraserBrushSize(); m_eraserBrushSizeEnabled = cfg.useEraserBrushSize();
m_eraserBrushOpacityEnabled = cfg.useEraserBrushOpacity();
KAcceleratorManager::setNoAccel(this); KAcceleratorManager::setNoAccel(this);
...@@ -456,6 +458,7 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char * ...@@ -456,6 +458,7 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
connect(m_presetsPopup , SIGNAL(reloadPresetClicked()) , SLOT(slotReloadPreset())); connect(m_presetsPopup , SIGNAL(reloadPresetClicked()) , SLOT(slotReloadPreset()));
connect(m_presetsPopup , SIGNAL(dirtyPresetToggled(bool)) , SLOT(slotDirtyPresetToggled(bool))); connect(m_presetsPopup , SIGNAL(dirtyPresetToggled(bool)) , SLOT(slotDirtyPresetToggled(bool)));
connect(m_presetsPopup , SIGNAL(eraserBrushSizeToggled(bool)) , SLOT(slotEraserBrushSizeToggled(bool))); connect(m_presetsPopup , SIGNAL(eraserBrushSizeToggled(bool)) , SLOT(slotEraserBrushSizeToggled(bool)));
connect(m_presetsPopup , SIGNAL(eraserBrushOpacityToggled(bool)) , SLOT(slotEraserBrushOpacityToggled(bool)));
connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)) , SLOT(resourceSelected(KoResource*))); connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)) , SLOT(resourceSelected(KoResource*)));
connect(m_resourceProvider , SIGNAL(sigNodeChanged(const KisNodeSP)) , SLOT(slotNodeChanged(const KisNodeSP))); connect(m_resourceProvider , SIGNAL(sigNodeChanged(const KisNodeSP)) , SLOT(slotNodeChanged(const KisNodeSP)));
...@@ -936,6 +939,28 @@ void KisPaintopBox::slotToggleEraseMode(bool checked) ...@@ -936,6 +939,28 @@ void KisPaintopBox::slotToggleEraseMode(bool checked)
qreal newSize = checked ? settings->savedEraserSize() : settings->savedBrushSize(); qreal newSize = checked ? settings->savedEraserSize() : settings->savedBrushSize();
m_resourceProvider->setSize(newSize); m_resourceProvider->setSize(newSize);
} }
if (m_eraserBrushOpacityEnabled) {
const qreal currentOpacity = m_resourceProvider->opacity();
KisPaintOpSettingsSP settings = m_resourceProvider->currentPreset()->settings();
// remember brush opacity. set the eraser opacity to the normal brush size if not set
if (checked) {
settings->setSavedBrushOpacity(currentOpacity);
if (qFuzzyIsNull(settings->savedEraserOpacity())) {
settings->setSavedEraserOpacity(currentOpacity);
}
} else {
settings->setSavedEraserOpacity(currentOpacity);
if (qFuzzyIsNull(settings->savedBrushOpacity())) {
settings->setSavedBrushOpacity(currentOpacity);
}
}
//update value in UI (this is the main place the value is 'stored' in memory)
qreal newOpacity = checked ? settings->savedEraserOpacity() : settings->savedBrushOpacity();
m_resourceProvider->setOpacity(newOpacity);
}
} }
void KisPaintopBox::slotSetCompositeMode(int index) void KisPaintopBox::slotSetCompositeMode(int index)
...@@ -1184,6 +1209,13 @@ void KisPaintopBox::slotEraserBrushSizeToggled(bool value) ...@@ -1184,6 +1209,13 @@ void KisPaintopBox::slotEraserBrushSizeToggled(bool value)
cfg.setUseEraserBrushSize(m_eraserBrushSizeEnabled); cfg.setUseEraserBrushSize(m_eraserBrushSizeEnabled);
} }
void KisPaintopBox::slotEraserBrushOpacityToggled(bool value)
{
m_eraserBrushOpacityEnabled = value;
KisConfig cfg;
cfg.setUseEraserBrushOpacity(m_eraserBrushOpacityEnabled);
}
void KisPaintopBox::slotUpdateSelectionIcon() void KisPaintopBox::slotUpdateSelectionIcon()
{ {
m_hMirrorAction->setIcon(KisIconUtils::loadIcon("symmetry-horizontal")); m_hMirrorAction->setIcon(KisIconUtils::loadIcon("symmetry-horizontal"));
......
...@@ -161,6 +161,7 @@ private Q_SLOTS: ...@@ -161,6 +161,7 @@ private Q_SLOTS:
void slotDropLockedOption(KisPropertiesConfiguration* p); void slotDropLockedOption(KisPropertiesConfiguration* p);
void slotDirtyPresetToggled(bool); void slotDirtyPresetToggled(bool);
void slotEraserBrushSizeToggled(bool); void slotEraserBrushSizeToggled(bool);
void slotEraserBrushOpacityToggled(bool);
void slotUpdateSelectionIcon(); void slotUpdateSelectionIcon();
void slotLockXMirrorToggle(bool); void slotLockXMirrorToggle(bool);
...@@ -244,7 +245,8 @@ private: ...@@ -244,7 +245,8 @@ private:
bool m_blockUpdate; bool m_blockUpdate;
bool m_dirtyPresetsEnabled; bool m_dirtyPresetsEnabled;
bool m_eraserBrushSizeEnabled; bool m_eraserBrushSizeEnabled;
bool m_eraserBrushOpacityEnabled;
KisSignalAutoConnectionsStore m_presetConnections; KisSignalAutoConnectionsStore m_presetConnections;
KisSignalCompressor m_presetUpdateCompressor; KisSignalCompressor m_presetUpdateCompressor;
}; };
......
...@@ -129,6 +129,9 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou ...@@ -129,6 +129,9 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
connect(m_d->uiWdgPaintOpPresetSettings.eraserBrushSizeCheckBox, SIGNAL(toggled(bool)), connect(m_d->uiWdgPaintOpPresetSettings.eraserBrushSizeCheckBox, SIGNAL(toggled(bool)),
this, SIGNAL(eraserBrushSizeToggled(bool))); this, SIGNAL(eraserBrushSizeToggled(bool)));
connect(m_d->uiWdgPaintOpPresetSettings.eraserBrushOpacityCheckBox, SIGNAL(toggled(bool)),
this, SIGNAL(eraserBrushOpacityToggled(bool)));
connect(m_d->uiWdgPaintOpPresetSettings.bnDefaultPreset, SIGNAL(clicked()), connect(m_d->uiWdgPaintOpPresetSettings.bnDefaultPreset, SIGNAL(clicked()),
m_d->uiWdgPaintOpPresetSettings.txtPreset, SLOT(clear())); m_d->uiWdgPaintOpPresetSettings.txtPreset, SLOT(clear()));
...@@ -156,6 +159,7 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou ...@@ -156,6 +159,7 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
m_d->detachedGeometry = QRect(100, 100, 0, 0); m_d->detachedGeometry = QRect(100, 100, 0, 0);
m_d->uiWdgPaintOpPresetSettings.dirtyPresetCheckBox->setChecked(cfg.useDirtyPresets()); m_d->uiWdgPaintOpPresetSettings.dirtyPresetCheckBox->setChecked(cfg.useDirtyPresets());
m_d->uiWdgPaintOpPresetSettings.eraserBrushSizeCheckBox->setChecked(cfg.useEraserBrushSize()); m_d->uiWdgPaintOpPresetSettings.eraserBrushSizeCheckBox->setChecked(cfg.useEraserBrushSize());
m_d->uiWdgPaintOpPresetSettings.eraserBrushOpacityCheckBox->setChecked(cfg.useEraserBrushOpacity());
m_d->uiWdgPaintOpPresetSettings.wdgLodAvailability->setCanvasResourceManager(resourceProvider->resourceManager()); m_d->uiWdgPaintOpPresetSettings.wdgLodAvailability->setCanvasResourceManager(resourceProvider->resourceManager());
} }
......
...@@ -94,6 +94,7 @@ Q_SIGNALS: ...@@ -94,6 +94,7 @@ Q_SIGNALS:
void reloadPresetClicked(); void reloadPresetClicked();
void dirtyPresetToggled(bool value); void dirtyPresetToggled(bool value);
void eraserBrushSizeToggled(bool value); void eraserBrushSizeToggled(bool value);
void eraserBrushOpacityToggled(bool value);
void sizeChanged(); void sizeChanged();
......
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