Commit 1e81d724 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implemented a correct eraser mode for the paintop presets

Now the eraser mode is a part of the preset so it is saved on switching
between presets.

Ref T1597
parent dc0bb8c0
......@@ -613,6 +613,7 @@ void KisSketchView::centerDoc()
void KisSketchView::Private::imageUpdated(const QRect &updated)
{
Q_UNUSED(updated);
// QT5TODO
// if (q->scene()) {
// q->scene()->views().at(0)->update(updated);
......
......@@ -311,8 +311,6 @@ void KisView::setViewManager(KisViewManager *view)
{
d->viewManager = view;
connect(canvasController(), SIGNAL(toolOptionWidgetsChanged(QList<QPointer<QWidget> >)), d->viewManager->mainWindow(), SLOT(newOptionWidgets(QList<QPointer<QWidget> >)));
KoToolManager::instance()->addController(&d->canvasController);
KoToolManager::instance()->registerToolActions(d->actionCollection, &d->canvasController);
dynamic_cast<KisShapeController*>(d->document->shapeController())->setInitialShapeForCanvas(&d->canvas);
......
......@@ -349,6 +349,17 @@ QString KisCanvasResourceProvider::currentCompositeOp() const
return m_resourceManager->resource(CurrentCompositeOp).value<QString>();
}
bool KisCanvasResourceProvider::eraserMode() const
{
return m_resourceManager->resource(EraserMode).toBool();
}
void KisCanvasResourceProvider::setEraserMode(bool value)
{
m_resourceManager->setResource(EraserMode,
QVariant::fromValue(value));
}
void KisCanvasResourceProvider::slotPainting()
{
if (m_fGChanged && m_enablefGChange) {
......
......@@ -95,6 +95,9 @@ public:
float HDRGamma() const;
void setHDRGamma(float gamma);
bool eraserMode() const;
void setEraserMode(bool value);
KoPattern *currentPattern() const;
KoAbstractGradient *currentGradient() const;
......
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __KIS_HIGHLIGHTED_BUTTON_H
#define __KIS_HIGHLIGHTED_BUTTON_H
template <class BaseButton>
class HighlightedButtonBase : public BaseButton
{
public:
HighlightedButtonBase(QWidget *parent = 0) : BaseButton(parent) {}
protected:
void checkStateSet() {
BaseButton::checkStateSet();
updatePalette();
}
void nextCheckState() {
BaseButton::nextCheckState();
updatePalette();
}
private:
void updatePalette() {
QWidget *parent = this->parentWidget();
if (parent) {
QPalette p = parent->palette();
QColor color = p.color(this->isChecked() ? QPalette::Highlight : QPalette::Button);
p.setColor(QPalette::Button, color);
this->setPalette(p);
}
}
};
class QPushButton;
class QToolButton;
typedef HighlightedButtonBase<QPushButton> KisHighlightedButton;
typedef HighlightedButtonBase<QToolButton> KisHighlightedToolButton;
#endif /* __KIS_HIGHLIGHTED_BUTTON_H */
This diff is collapsed.
......@@ -66,7 +66,7 @@ class KisAction;
* To incorporate the dirty preset functionality and locked settings
* the following slots are added
* void slotReloadPreset();
void slotConfigurationItemChanged();
void slotGuiChangedCurrentPreset();
void slotSaveLockedOptionToPreset(KisPropertiesConfiguration* p);
void slotDropLockedOption(KisPropertiesConfiguration* p);
void slotDirtyPresetToggled(bool);
......@@ -109,6 +109,8 @@ public:
*/
void newOptionWidgets(const QList<QPointer<QWidget> > & optionWidgetList);
KisFavoriteResourceManager *favoriteResourcesManager() { return m_favoriteResourceManager; }
public Q_SLOTS:
void slotColorSpaceChanged(const KoColorSpace* colorSpace);
......@@ -116,20 +118,14 @@ public Q_SLOTS:
void slotCanvasResourceChanged(int key, const QVariant& v);
void resourceSelected(KoResource* resource);
KisFavoriteResourceManager *favoriteResourcesManager() { return m_favoriteResourceManager; }
private:
KoID currentPaintop();
void setCurrentPaintop(const KoID& paintop, KisPaintOpPresetSP preset = 0);
void setCurrentPaintopAndReload(const KoID& paintop, KisPaintOpPresetSP preset);
QPixmap paintopPixmap(const KoID& paintop);
KoID defaultPaintOp();
KisPaintOpPresetSP defaultPreset(const KoID& paintOp);
KisPaintOpPresetSP activePreset(const KoID& paintOp);
void updateCompositeOp(QString compositeOpID, bool localUpdate = false);
void updateCompositeOp(QString compositeOpID);
void setWidgetState(int flags);
void setSliderValue(const QString& sliderID, qreal value);
void sliderChanged(int n);
......@@ -156,10 +152,8 @@ private Q_SLOTS:
void slotUnsetEraseMode();
void slotToggleAlphaLockMode(bool);
void toggleHighlightedButton(QToolButton* m_tool);
void slotReloadPreset();
void slotConfigurationItemChanged();
void slotGuiChangedCurrentPreset();
void slotSaveLockedOptionToPreset(KisPropertiesConfiguration* p);
void slotDropLockedOption(KisPropertiesConfiguration* p);
void slotDirtyPresetToggled(bool);
......@@ -195,8 +189,8 @@ private:
QString m_currCompositeOpID;
KisNodeWSP m_previousNode;
qreal normalBrushSize; // when toggling between eraser mode
qreal eraserBrushSize;
qreal m_normalBrushSize; // when toggling between eraser mode
qreal m_eraserBrushSize;
KisAction* m_hMirrorAction;
KisAction* m_vMirrorAction;
......
......@@ -108,7 +108,7 @@ KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisNodeSP currentN
qreal normOpacity = resourceManager->resource(KisCanvasResourceProvider::Opacity).toDouble();
m_d->opacity = quint8(normOpacity * OPACITY_OPAQUE_U8);
m_d->compositeOpId = resourceManager->resource(KisCanvasResourceProvider::CurrentCompositeOp).toString();
m_d->compositeOpId = resourceManager->resource(KisCanvasResourceProvider::CurrentEffectiveCompositeOp).toString();
setCurrentNode(currentNode);
/**
......
......@@ -30,7 +30,8 @@
KisCompositeOpOption::KisCompositeOpOption(bool createConfigWidget):
KisPaintOpOption(KisPaintOpOption::GENERAL, true),
m_createConfigWidget(createConfigWidget)
m_createConfigWidget(createConfigWidget),
m_eraserMode(false)
{
m_checkable = false;
m_prevCompositeOpID = KoCompositeOpRegistry::instance().getDefaultCompositeOp().id();
......@@ -64,6 +65,7 @@ KisCompositeOpOption::~KisCompositeOpOption()
void KisCompositeOpOption::writeOptionSetting(KisPropertiesConfiguration* setting) const
{
setting->setProperty("CompositeOp", m_currCompositeOpID);
setting->setProperty("EraserMode", m_eraserMode);
}
void KisCompositeOpOption::readOptionSetting(const KisPropertiesConfiguration* setting)
......@@ -71,6 +73,9 @@ void KisCompositeOpOption::readOptionSetting(const KisPropertiesConfiguration* s
QString ompositeOpID = setting->getString("CompositeOp", KoCompositeOpRegistry::instance().getDefaultCompositeOp().id());
KoID compositeOp = KoCompositeOpRegistry::instance().getKoID(ompositeOpID);
changeCompositeOp(compositeOp);
const bool eraserMode = setting->getBool("EraserMode", false);;
slotEraserToggled(eraserMode);
}
void KisCompositeOpOption::changeCompositeOp(const KoID& compositeOp)
......@@ -83,9 +88,6 @@ void KisCompositeOpOption::changeCompositeOp(const KoID& compositeOp)
if (m_createConfigWidget) {
m_label->setText(compositeOp.name());
KisSignalsBlocker b(m_bnEraser);
m_bnEraser->setChecked(m_currCompositeOpID == "erase");
}
emitSettingChanged();
......@@ -102,8 +104,12 @@ void KisCompositeOpOption::slotCompositeOpChanged(const QModelIndex& index)
void KisCompositeOpOption::slotEraserToggled(bool toggled)
{
if (toggled)
changeCompositeOp(KoCompositeOpRegistry::instance().getKoID("erase"));
else
changeCompositeOp(KoCompositeOpRegistry::instance().getKoID(m_prevCompositeOpID));
if (m_bnEraser->isChecked() != toggled) {
KisSignalsBlocker b(m_bnEraser);
m_bnEraser->setChecked(toggled);
}
m_eraserMode = toggled;
emitSettingChanged();
}
......@@ -56,6 +56,7 @@ private:
QString m_prevCompositeOpID;
QString m_currCompositeOpID;
bool m_createConfigWidget;
bool m_eraserMode;
};
......
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