Commit c7db28cc authored by Scott Petrovic's avatar Scott Petrovic

Add create new preset option on brush editor as well as trashcan to blacklist the selected preset

T7380: Ability to Create New Presets from Brush Engines that have no presets
D9465: Add ability to create a brush preset from scratch as wellas delete/blacklist preset
parent 3035b737
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1134</width>
<width>1197</width>
<height>431</height>
</rect>
</property>
......@@ -395,22 +395,7 @@
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<layout class="QVBoxLayout" name="paintEngineOpContainer">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
......@@ -535,23 +520,65 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="bnDefaultPreset">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Engine Default Preset</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QToolButton" name="newPresetEngineButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="bnBlacklistPreset">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="presetsSpacer">
......
......@@ -454,6 +454,8 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
connect(m_presetsPopup , SIGNAL(eraserBrushSizeToggled(bool)) , SLOT(slotEraserBrushSizeToggled(bool)));
connect(m_presetsPopup , SIGNAL(eraserBrushOpacityToggled(bool)) , SLOT(slotEraserBrushOpacityToggled(bool)));
connect(m_presetsPopup, SIGNAL(createPresetFromScratch(QString)), this, SLOT(slotCreatePresetFromScratch(QString)));
connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)) , SLOT(resourceSelected(KoResource*)));
connect(m_presetsChooserPopup, SIGNAL(resourceClicked(KoResource*)) , SLOT(resourceSelected(KoResource*)));
......@@ -546,6 +548,8 @@ void KisPaintopBox::newOptionWidgets(const QList<QPointer<QWidget> > &optionWidg
void KisPaintopBox::resourceSelected(KoResource* resource)
{
m_presetsPopup->setCreatingBrushFromScratch(false); // show normal UI elements when we are not creating
KisPaintOpPreset* preset = dynamic_cast<KisPaintOpPreset*>(resource);
if (preset && preset != m_resourceProvider->currentPreset()) {
if (!preset->settings()->isLoadable())
......@@ -563,6 +567,8 @@ void KisPaintopBox::resourceSelected(KoResource* resource)
m_presetsPopup->setPresetImage(preset->image());
m_presetsPopup->resourceSelected(resource);
}
}
void KisPaintopBox::setCurrentPaintop(const KoID& paintop)
......@@ -795,6 +801,15 @@ void KisPaintopBox::slotInputDeviceChanged(const KoInputDevice& inputDevice)
}
}
void KisPaintopBox::slotCreatePresetFromScratch(QString paintop)
{
slotSetPaintop(paintop); // change the paintop settings area and update the UI
m_presetsPopup->setCreatingBrushFromScratch(true); // disable UI elements while creating from scratch
KisPaintOpPresetSP preset = m_resourceProvider->currentPreset();
m_presetsPopup->resourceSelected(preset.data()); // this helps update the UI on the brush editor
}
void KisPaintopBox::slotCanvasResourceChanged(int key, const QVariant &value)
{
if (m_viewManager) {
......@@ -843,7 +858,6 @@ void KisPaintopBox::slotCanvasResourceChanged(int key, const QVariant &value)
}
}
void KisPaintopBox::slotUpdatePreset()
{
if (!m_resourceProvider->currentPreset()) return;
......
......@@ -122,6 +122,11 @@ public Q_SLOTS:
void slotCanvasResourceChanged(int key, const QVariant& v);
void resourceSelected(KoResource* resource);
/// This should take care of creating a new brush preset from scratch
/// It will either load the default brush preset for the engine,
/// or create a new empty preset if a default preset does not exist
void slotCreatePresetFromScratch(QString paintop);
private:
void setCurrentPaintop(const KoID& paintop);
......
......@@ -76,6 +76,7 @@ public:
bool detached;
bool ignoreHideEvents;
bool isCreatingBrushFromScratch = false;
QSize minimumSettingsWidgetSize;
QRect detachedGeometry;
......@@ -126,6 +127,11 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
m_d->uiWdgPaintOpPresetSettings.renameBrushPresetButton->setToolTip(i18n("Rename the brush preset"));
// creating a new preset from scratch. Part of the brush presets area
// the menu options will get filled up later when we are generating all available paintops
// in the filter drop-down
newPresetBrushEnginesMenu = new QMenu();
// overwrite existing preset and saving a new preset use the same dialog
saveDialog = savePresetWidget;
saveDialog->scratchPadSetup(resourceProvider);
......@@ -180,6 +186,11 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
m_d->uiWdgPaintOpPresetSettings.presetChangeViewToolButton->setPopupMode(QToolButton::InstantPopup);
// loading preset from scratch option
m_d->uiWdgPaintOpPresetSettings.newPresetEngineButton->setPopupMode(QToolButton::InstantPopup);
m_d->uiWdgPaintOpPresetSettings.newPresetEngineButton->setIcon(KisIconUtils::loadIcon("addlayer"));
m_d->uiWdgPaintOpPresetSettings.bnBlacklistPreset->setIcon(KisIconUtils::loadIcon("deletelayer"));
// show/hide buttons
KisConfig cfg;
......@@ -254,9 +265,6 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
connect(m_d->uiWdgPaintOpPresetSettings.reloadPresetButton, SIGNAL(clicked()),
this, SIGNAL(reloadPresetClicked()));
connect(m_d->uiWdgPaintOpPresetSettings.bnDefaultPreset, SIGNAL(clicked()),
this, SIGNAL(defaultPresetClicked()));
connect(m_d->uiWdgPaintOpPresetSettings.dirtyPresetCheckBox, SIGNAL(toggled(bool)),
this, SIGNAL(dirtyPresetToggled(bool)));
......@@ -304,11 +312,25 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
connect(m_d->uiWdgPaintOpPresetSettings.brushEgineComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatePaintOpFilter()));
connect(m_d->uiWdgPaintOpPresetSettings.bnBlacklistPreset, SIGNAL(clicked()), this, SLOT(slotBlackListCurrentPreset()));
// setup things like the scene construct images, layers, etc that is a one-time thing
m_d->uiWdgPaintOpPresetSettings.liveBrushPreviewView->setup();
}
void KisPaintOpPresetsPopup::slotBlackListCurrentPreset()
{
KisPaintOpPresetResourceServer * rServer = KisResourceServerProvider::instance()->paintOpPresetServer();
KisPaintOpPresetSP curPreset = m_d->resourceProvider->currentPreset();
if (rServer->resourceByName(curPreset->name())) {
rServer->removeResourceAndBlacklist(curPreset);
}
}
void KisPaintOpPresetsPopup::slotRenameBrushActivated()
{
......@@ -341,10 +363,10 @@ void KisPaintOpPresetsPopup::toggleBrushRenameUIActive(bool isRenaming)
// what happens if you try to change presets. maybe we should auto-hide (or disable)
// the presets area in this case
if (m_d->uiWdgPaintOpPresetSettings.presetWidget->isVisible()) {
m_d->uiWdgPaintOpPresetSettings.bnDefaultPreset->setVisible(!isRenaming);
m_d->uiWdgPaintOpPresetSettings.newPresetEngineButton->setVisible(!isRenaming);
m_d->uiWdgPaintOpPresetSettings.bnBlacklistPreset->setVisible(!isRenaming);
}
}
void KisPaintOpPresetsPopup::slotSaveRenameCurrentBrush()
......@@ -396,7 +418,6 @@ void KisPaintOpPresetsPopup::slotSaveRenameCurrentBrush()
slotUpdatePresetSettings(); // update visibility of dirty preset and icon
}
void KisPaintOpPresetsPopup::slotResourceChanged(int key, const QVariant &value)
{
if (key == KisCanvasResourceProvider::LodAvailability) {
......@@ -418,6 +439,7 @@ KisPaintOpPresetsPopup::~KisPaintOpPresetsPopup()
m_d->settingsWidget = 0;
}
delete m_d;
delete newPresetBrushEnginesMenu;
}
void KisPaintOpPresetsPopup::setPaintOpSettingsWidget(QWidget * widget)
......@@ -515,6 +537,12 @@ void KisPaintOpPresetsPopup::switchDetached(bool show)
}
}
void KisPaintOpPresetsPopup::setCreatingBrushFromScratch(bool enabled)
{
m_d->isCreatingBrushFromScratch = enabled;
}
void KisPaintOpPresetsPopup::resourceSelected(KoResource* resource)
{
// this gets called every time the brush editor window is opened
......@@ -587,9 +615,24 @@ void KisPaintOpPresetsPopup::setPaintOpList(const QList< KisPaintOpFactory* >& l
// add an "All" option at the front to show all presets
QPixmap emptyPixmap = QPixmap(22,22);
emptyPixmap.fill(palette().color(QPalette::Background));
sortedBrushEnginesList.push_front(KisPaintOpInfo(QString("all_options"), i18n("All"), QString(""), emptyPixmap, 0 ));
// if we create a new brush from scratch, we need a full list of paintops to choose from
// we don't want "All", so populate the list before that is added
newPresetBrushEnginesMenu->actions().clear(); // clean out list in case we run this again
newBrushEngineOptions.clear();
for (int j = 0; j < sortedBrushEnginesList.length(); j++) {
KisAction * newEngineAction = static_cast<KisAction*>( newPresetBrushEnginesMenu->addAction(sortedBrushEnginesList[j].name));
newEngineAction->setObjectName(sortedBrushEnginesList[j].id); // we need the ID for changing the paintop when action triggered
newBrushEngineOptions.append(newEngineAction);
connect(newEngineAction, SIGNAL(triggered()), this, SLOT(slotCreateNewBrushPresetEngine()));
}
m_d->uiWdgPaintOpPresetSettings.newPresetEngineButton->setMenu(newPresetBrushEnginesMenu);
// fill the list into the brush combo box
sortedBrushEnginesList.push_front(KisPaintOpInfo(QString("all_options"), i18n("All"), QString(""), emptyPixmap, 0 ));
for (int m = 0; m < sortedBrushEnginesList.length(); m++) {
m_d->uiWdgPaintOpPresetSettings.brushEgineComboBox->addItem(sortedBrushEnginesList[m].icon, sortedBrushEnginesList[m].name, QVariant(sortedBrushEnginesList[m].id));
}
......@@ -679,8 +722,9 @@ void KisPaintOpPresetsPopup::slotSwitchShowPresets(bool visible) {
m_d->uiWdgPaintOpPresetSettings.presetChangeViewToolButton->setVisible(visible);
m_d->uiWdgPaintOpPresetSettings.brushEgineComboBox->setVisible(visible);
m_d->uiWdgPaintOpPresetSettings.engineFilterLabel->setVisible(visible);
m_d->uiWdgPaintOpPresetSettings.bnDefaultPreset->setVisible(visible);
m_d->uiWdgPaintOpPresetSettings.presetsSidebarLabel->setVisible(visible);
m_d->uiWdgPaintOpPresetSettings.newPresetEngineButton->setVisible(visible);
m_d->uiWdgPaintOpPresetSettings.bnBlacklistPreset->setVisible(visible);
// we only want a spacer to work when the toggle icon is present. Otherwise the list of presets will shrink
......@@ -725,6 +769,14 @@ void KisPaintOpPresetsPopup::slotSaveNewBrushPreset() {
saveDialog->showDialog();
}
void KisPaintOpPresetsPopup::slotCreateNewBrushPresetEngine()
{
KisAction *actionThatWasSent = static_cast<KisAction*>(sender());// sender() gets what menu item was called
emit createPresetFromScratch(actionThatWasSent->objectName());
actionThatWasSent->deleteLater();
}
void KisPaintOpPresetsPopup::updateViewSettings()
{
m_d->uiWdgPaintOpPresetSettings.presetWidget->smallPresetChooser->updateViewSettings();
......@@ -746,6 +798,8 @@ void KisPaintOpPresetsPopup::updateThemedIcons()
m_d->uiWdgPaintOpPresetSettings.fillSolid->setIcon(KisIconUtils::loadIcon("krita_tool_color_fill"));
m_d->uiWdgPaintOpPresetSettings.eraseScratchPad->setIcon(KisIconUtils::loadIcon("edit-delete"));
m_d->uiWdgPaintOpPresetSettings.presetChangeViewToolButton->setIcon(KisIconUtils::loadIcon("view-choose"));
m_d->uiWdgPaintOpPresetSettings.newPresetEngineButton->setIcon(KisIconUtils::loadIcon("addlayer"));
m_d->uiWdgPaintOpPresetSettings.bnBlacklistPreset->setIcon(KisIconUtils::loadIcon("deletelayer"));
}
void KisPaintOpPresetsPopup::slotUpdatePresetSettings()
......@@ -757,13 +811,21 @@ void KisPaintOpPresetsPopup::slotUpdatePresetSettings()
return;
}
bool isPresetDirty = m_d->resourceProvider->currentPreset()->isPresetDirty();
// don't need to reload or overwrite a clean preset
m_d->uiWdgPaintOpPresetSettings.dirtyPresetIndicatorButton->setVisible(isPresetDirty);
m_d->uiWdgPaintOpPresetSettings.reloadPresetButton->setVisible(isPresetDirty);
m_d->uiWdgPaintOpPresetSettings.saveBrushPresetButton->setEnabled(isPresetDirty);
// hide options on UI if we are creating a brush preset from scratch to prevent confusion
if (m_d->isCreatingBrushFromScratch) {
m_d->uiWdgPaintOpPresetSettings.dirtyPresetIndicatorButton->setVisible(false);
m_d->uiWdgPaintOpPresetSettings.reloadPresetButton->setVisible(false);
m_d->uiWdgPaintOpPresetSettings.saveBrushPresetButton->setVisible(false);
m_d->uiWdgPaintOpPresetSettings.renameBrushPresetButton->setVisible(false);
} else {
bool isPresetDirty = m_d->resourceProvider->currentPreset()->isPresetDirty();
// don't need to reload or overwrite a clean preset
m_d->uiWdgPaintOpPresetSettings.dirtyPresetIndicatorButton->setVisible(isPresetDirty);
m_d->uiWdgPaintOpPresetSettings.reloadPresetButton->setVisible(isPresetDirty);
m_d->uiWdgPaintOpPresetSettings.saveBrushPresetButton->setEnabled(isPresetDirty);
m_d->uiWdgPaintOpPresetSettings.renameBrushPresetButton->setVisible(true);
}
// update live preview area in here...
// don't update the live preview if the widget is not visible.
......
......@@ -27,6 +27,7 @@
#include <kis_types.h>
#include <brushengine/kis_paintop_factory.h>
#include "../kis_paint_ops_model.h"
#include <kis_action.h>
#include <widgets/kis_paintop_presets_save.h>
#include "widgets/kis_paintop_presets_popup.h"
#include "kis_favorite_resource_manager.h"
......@@ -80,6 +81,9 @@ public:
KisPresetSaveWidget * saveDialog;
// toggle the state when we are creating a brush from scratch
void setCreatingBrushFromScratch(bool enable);
protected:
void contextMenuEvent(QContextMenuEvent *) override;
void hideEvent(QHideEvent *) override;
......@@ -96,6 +100,7 @@ public Q_SLOTS:
void slotRenameBrushActivated();
void slotRenameBrushDeactivated();
void slotSaveRenameCurrentBrush();
void slotCreateNewBrushPresetEngine();
Q_SIGNALS:
void savePresetClicked();
......@@ -109,6 +114,7 @@ Q_SIGNALS:
void eraserBrushOpacityToggled(bool value);
void sizeChanged();
void brushEditorShown();
void createPresetFromScratch(const QString& paintOpName);
private Q_SLOTS:
void slotSwitchScratchpad(bool visible);
......@@ -120,7 +126,8 @@ private Q_SLOTS:
void slotSaveBrushPreset();
void slotSaveNewBrushPreset();
/// we do not delete brushe presets, but blacklist them so they disappear from the interface
void slotBlackListCurrentPreset();
private:
......@@ -128,6 +135,12 @@ private:
Private * const m_d;
QString current_paintOpId;
QList<KisPaintOpInfo> sortedBrushEnginesList;
QMenu * newPresetBrushEnginesMenu;
QList<KisAction*> newBrushEngineOptions;
void toggleBrushRenameUIActive(bool isRenaming);
};
......
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