Skip to content

Commit

Permalink
Add actions to reset all slots and all brushes
Browse files Browse the repository at this point in the history
Rather than making you go through every one of those individually and
resetting each in turn.
  • Loading branch information
askmeaboutlo0m committed Oct 1, 2024
1 parent 9b41a7e commit 82f1819
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 43 deletions.
14 changes: 14 additions & 0 deletions src/desktop/docks/brushpalettedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct BrushPalette::Private {
QAction *overwriteBrushAction;
QAction *editBrushAction;
QAction *resetBrushAction;
QAction *resetAllAction;
QAction *deleteBrushAction;
QMenu *iconSizeMenu;
QMenu *tagMenu;
Expand Down Expand Up @@ -129,6 +130,7 @@ BrushPalette::BrushPalette(QWidget *parent)
d->tagMenu->addAction(QIcon::fromTheme("configure"), tr("&Edit Brush"));
d->resetBrushAction = d->tagMenu->addAction(
QIcon::fromTheme("view-refresh"), tr("&Reset Brush"));
d->resetAllAction = d->tagMenu->addAction(tr("Reset All &Brushes"));
d->tagMenu->addSeparator();
d->newBrushAction =
d->tagMenu->addAction(QIcon::fromTheme("list-add"), tr("&New Brush"));
Expand All @@ -153,6 +155,7 @@ BrushPalette::BrushPalette(QWidget *parent)
d->brushMenu = new QMenu(this);
d->brushMenu->addAction(d->editBrushAction);
d->brushMenu->addAction(d->resetBrushAction);
d->brushMenu->addAction(d->resetAllAction);
d->brushMenu->addSeparator();
d->brushMenu->addAction(d->newBrushAction);
d->brushMenu->addAction(d->overwriteBrushAction);
Expand Down Expand Up @@ -240,6 +243,9 @@ BrushPalette::BrushPalette(QWidget *parent)
connect(
d->resetBrushAction, &QAction::triggered, this,
&BrushPalette::resetCurrentPreset);
connect(
d->resetAllAction, &QAction::triggered, this,
&BrushPalette::resetAllPresets);
connect(
d->deleteBrushAction, &QAction::triggered, this,
&BrushPalette::deleteCurrentPreset);
Expand Down Expand Up @@ -401,6 +407,14 @@ void BrushPalette::overwriteCurrentPreset(QWidget *parent)
box->show();
}

void BrushPalette::resetAllPresets()
{
d->presetModel->resetAllPresetChanges();
if(d->brushSettings) {
d->brushSettings->resetPresetsInAllSlots();
}
}

void BrushPalette::importBrushes()
{
FileWrangler(this).openBrushPack(
Expand Down
1 change: 1 addition & 0 deletions src/desktop/docks/brushpalettedock.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BrushPalette final : public DockBase {
void overwriteCurrentPreset(QWidget *parent);

public slots:
void resetAllPresets();
void importBrushes();
void exportBrushes();

Expand Down
19 changes: 18 additions & 1 deletion src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5126,6 +5126,12 @@ void MainWindow::setupActions()
QAction *smallerbrush = makeAction("ensmallenbrush", tr("&Decrease Brush Size")).shortcut(Qt::Key_BracketLeft).autoRepeat();
QAction *biggerbrush = makeAction("embiggenbrush", tr("&Increase Brush Size")).shortcut(Qt::Key_BracketRight).autoRepeat();
QAction *reloadPreset = makeAction("reloadpreset", tr("&Reset Brush")).icon("view-refresh").shortcut("Shift+P");
QAction *reloadPresetSlots =
makeAction("reloadpresetslots", tr("Reset All Brush &Slots"))
.noDefaultShortcut();
QAction *reloadAllPresets =
makeAction("reloadallpresets", tr("Reset All &Brushes"))
.shortcut("Shift+Alt+P");

smallerbrush->setAutoRepeat(true);
biggerbrush->setAutoRepeat(true);
Expand All @@ -5140,6 +5146,14 @@ void MainWindow::setupActions()
connect(smallerbrush, &QAction::triggered, this, [this]() { m_dockToolSettings->stepAdjustCurrent1(false); });
connect(biggerbrush, &QAction::triggered, this, [this]() { m_dockToolSettings->stepAdjustCurrent1(true); });
connect(reloadPreset, &QAction::triggered, m_dockToolSettings->brushSettings(), &tools::BrushSettings::resetPreset);
connect(
reloadPresetSlots, &QAction::triggered,
m_dockToolSettings->brushSettings(),
&tools::BrushSettings::resetPresetsInAllSlots);
connect(
reloadAllPresets, &QAction::triggered,
m_dockBrushPalette,
&docks::BrushPalette::resetAllPresets);

toolshortcuts->addAction(currentEraseMode);
toolshortcuts->addAction(currentRecolorMode);
Expand All @@ -5150,6 +5164,8 @@ void MainWindow::setupActions()
toolshortcuts->addAction(smallerbrush);
toolshortcuts->addAction(biggerbrush);
toolshortcuts->addAction(reloadPreset);
toolshortcuts->addAction(reloadPresetSlots);
toolshortcuts->addAction(reloadAllPresets);

m_toolBarDraw = new QToolBar(tr("Drawing tools"));
m_toolBarDraw->setObjectName("drawtoolsbar");
Expand Down Expand Up @@ -5183,7 +5199,8 @@ void MainWindow::setupActions()
}
}

m_dockToolSettings->brushSettings()->setActions(reloadPreset);
m_dockToolSettings->brushSettings()->setActions(
reloadPreset, reloadPresetSlots, reloadAllPresets);

m_smallScreenSpacer = new QWidget;
m_smallScreenSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
Expand Down
117 changes: 79 additions & 38 deletions src/desktop/toolwidgets/brushsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ struct BrushSettings::Private {

QAction *editBrushAction;
QAction *resetBrushAction;
QAction *resetSlotPresetsAction;
QAction *resetAllPresetsAction;
QAction *newBrushAction;
QAction *overwriteBrushAction;
QAction *deleteBrushAction;
Expand Down Expand Up @@ -243,9 +245,20 @@ BrushSettings::~BrushSettings()
delete d;
}

void BrushSettings::setActions(QAction *reloadPreset)
void BrushSettings::setActions(
QAction *reloadPreset, QAction *reloadPresetSlots,
QAction *reloadAllPresets)
{
d->ui.reloadButton->setDefaultAction(reloadPreset);
connect(
d->resetBrushAction, &QAction::triggered, reloadPreset,
&QAction::trigger);
connect(
d->resetSlotPresetsAction, &QAction::triggered, reloadPresetSlots,
&QAction::trigger);
connect(
d->resetAllPresetsAction, &QAction::triggered, reloadAllPresets,
&QAction::trigger);
}

void BrushSettings::connectBrushPresets(brushes::BrushPresetModel *brushPresets)
Expand Down Expand Up @@ -314,9 +327,8 @@ QWidget *BrushSettings::createUiWidget(QWidget *parent)

d->resetBrushAction =
menu->addAction(QIcon::fromTheme("view-refresh"), tr("&Reset Brush"));
connect(
d->resetBrushAction, &QAction::triggered, this,
&BrushSettings::resetPreset);
d->resetSlotPresetsAction = menu->addAction(tr("Reset All Brush &Slots"));
d->resetAllPresetsAction = menu->addAction(tr("Reset All &Brushes"));

menu->addSeparator();

Expand Down Expand Up @@ -691,7 +703,7 @@ void BrushSettings::setBrushPresetsAttach(bool brushPresetsAttach)
if(preset.attached) {
d->ui.preview->setPreset(
preset.effectiveThumbnail(), preset.hasChanges());
updateChangesInBrushPresets();
updateChangesInCurrentBrushPreset();
}
}
} else if(d->current == i) {
Expand Down Expand Up @@ -720,40 +732,52 @@ void BrushSettings::setBrushPresetsAttach(bool brushPresetsAttach)

void BrushSettings::setCurrentBrushDetached(const brushes::ActiveBrush &brush)
{
brushes::Preset p;
p.originalBrush = brush;
setCurrentBrushPreset(p);
setBrushDetachedInSlot(brush, d->current);
}

void BrushSettings::setCurrentBrushPreset(const brushes::Preset &p)
{
brushes::ActiveBrush brush = changeCurrentBrushInternal(p.effectiveBrush());
Preset &preset = d->currentPreset();
if(p.id <= 0) {
preset = Preset::makeDetached(brush);
emit presetIdChanged(0);
} else if(d->presetsAttach) {
preset = Preset::makeAttached(p);
preset.changeBrush(brush, isCurrentEraserSlot());
emit presetIdChanged(p.id);
} else {
preset = Preset::makeDetached(p.originalBrush, true, p.id);
}
updateMenuActions();
updateUi();
updateChangesInBrushPresets();
setBrushPresetInSlot(p, d->current);
}

void BrushSettings::setBrushDetachedInSlot(
const brushes::ActiveBrush &brush, int i)
{
brushes::Preset p;
p.originalBrush = brush;
setBrushPresetInSlot(p, i);
}

void BrushSettings::changeCurrentBrush(const brushes::ActiveBrush &brush)
{
changePresetBrush(changeCurrentBrushInternal(brush));
changePresetBrush(changeBrushInSlot(brush, d->current));
updateUi();
}

brushes::ActiveBrush
BrushSettings::changeCurrentBrushInternal(const brushes::ActiveBrush &brush)
void BrushSettings::setBrushPresetInSlot(const brushes::Preset &p, int i)
{
return changeBrushInSlot(brush, d->current);
brushes::ActiveBrush brush = changeBrushInSlot(p.effectiveBrush(), i);
Preset &preset = d->presetAt(i);
bool isCurrent = i == d->current;
if(p.id <= 0) {
preset = Preset::makeDetached(brush);
if(isCurrent) {
emit presetIdChanged(0);
}
} else if(d->presetsAttach) {
preset = Preset::makeAttached(p);
preset.changeBrush(brush, i == ERASER_SLOT_INDEX);
if(isCurrent) {
emit presetIdChanged(p.id);
}
} else {
preset = Preset::makeDetached(p.originalBrush, true, p.id);
}
if(isCurrent) {
updateMenuActions();
updateUi();
}
updateChangesInBrushPresetInSlot(i);
}

brushes::ActiveBrush
Expand Down Expand Up @@ -847,7 +871,7 @@ void BrushSettings::selectBrushSlot(int i)
const Preset &preset = d->currentPreset();
updateMenuActions();
emit presetIdChanged(preset.effectiveId());
updateChangesInBrushPresets();
updateChangesInCurrentBrushPreset();
}

void BrushSettings::toggleEraserMode()
Expand Down Expand Up @@ -886,16 +910,28 @@ void BrushSettings::toggleRecolorMode()

void BrushSettings::resetPreset()
{
Preset &preset = d->currentPreset();
resetBrushInSlot(d->current);
}

void BrushSettings::resetPresetsInAllSlots()
{
for(int i = 0; i < TOTAL_SLOT_COUNT; ++i) {
resetBrushInSlot(i);
}
}

void BrushSettings::resetBrushInSlot(int i)
{
Preset &preset = d->presetAt(i);
if(preset.valid) {
if(preset.attached) {
preset.changedName = {};
preset.changedDescription = {};
preset.changedThumbnail = {};
preset.changedBrush = {};
setCurrentBrushPreset(preset);
setBrushPresetInSlot(preset, i);
} else {
setCurrentBrushDetached(preset.originalBrush);
setBrushDetachedInSlot(preset.originalBrush, i);
}
}
}
Expand All @@ -905,7 +941,7 @@ void BrushSettings::changeCurrentPresetName(const QString &name)
Preset &preset = d->currentPreset();
if(preset.changeName(name)) {
d->ui.preview->setPresetChanged(preset.hasChanges());
updateChangesInBrushPresets();
updateChangesInCurrentBrushPreset();
}
}

Expand All @@ -914,7 +950,7 @@ void BrushSettings::changeCurrentPresetDescription(const QString &description)
Preset &preset = d->currentPreset();
if(preset.changeDescription(description)) {
d->ui.preview->setPresetChanged(preset.hasChanges());
updateChangesInBrushPresets();
updateChangesInCurrentBrushPreset();
}
}

Expand All @@ -924,7 +960,7 @@ void BrushSettings::changeCurrentPresetThumbnail(const QPixmap &thumbnail)
if(preset.changeThumbnail(thumbnail)) {
d->ui.preview->setPresetThumbnail(thumbnail);
d->ui.preview->setPresetChanged(preset.hasChanges());
updateChangesInBrushPresets();
updateChangesInCurrentBrushPreset();
}
}

Expand Down Expand Up @@ -1360,17 +1396,22 @@ void BrushSettings::changePresetBrush(const brushes::ActiveBrush &brush)
if(preset.isAttached()) {
d->ui.preview->setPresetChanged(preset.hasChanges());
}
updateChangesInBrushPresets();
updateChangesInCurrentBrushPreset();
}

void BrushSettings::updateChangesInBrushPresets()
void BrushSettings::updateChangesInCurrentBrushPreset()
{
const Preset &preset = d->currentPreset();
updateChangesInBrushPresetInSlot(d->current);
}

void BrushSettings::updateChangesInBrushPresetInSlot(int i)
{
const Preset &preset = d->presetAt(i);
if(d->brushPresets && preset.isAttached()) {
d->brushPresets->changePreset(
preset.id, preset.changedName, preset.changedDescription,
preset.changedThumbnail, preset.changedBrush,
isCurrentEraserSlot());
i == ERASER_SLOT_INDEX);
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/desktop/toolwidgets/brushsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class BrushSettings final : public ToolSettings {
BrushSettings(ToolController *ctrl, QObject *parent = nullptr);
~BrushSettings() override;

void setActions(QAction *reloadPreset);
void setActions(
QAction *reloadPreset, QAction *reloadPresetSlots,
QAction *reloadAllPresets);
void connectBrushPresets(brushes::BrushPresetModel *brushPresets);

QString toolType() const override { return QStringLiteral("brush"); }
Expand Down Expand Up @@ -56,6 +58,8 @@ class BrushSettings final : public ToolSettings {
void setCurrentBrushDetached(const brushes::ActiveBrush &brush);
void setCurrentBrushPreset(const brushes::Preset &p);
void changeCurrentBrush(const brushes::ActiveBrush &brush);
void setBrushDetachedInSlot(const brushes::ActiveBrush &brush, int i);
void setBrushPresetInSlot(const brushes::Preset &p, int i);
brushes::ActiveBrush currentBrush() const;
int currentPresetId() const;
const QString &currentPresetName() const;
Expand Down Expand Up @@ -88,6 +92,7 @@ public slots:
void toggleRecolorMode() override;
void setEraserMode(bool erase);
void resetPreset();
void resetPresetsInAllSlots();

void changeCurrentPresetName(const QString &name);
void changeCurrentPresetDescription(const QString &description);
Expand Down Expand Up @@ -129,10 +134,10 @@ private slots:
enum class Lock { None, MyPaintPermission, MyPaintCompat, IndirectCompat };

void changePresetBrush(const brushes::ActiveBrush &brush);
void updateChangesInBrushPresets();
void updateChangesInCurrentBrushPreset();
void updateChangesInBrushPresetInSlot(int i);

brushes::ActiveBrush
changeCurrentBrushInternal(const brushes::ActiveBrush &brush);
void resetBrushInSlot(int i);
brushes::ActiveBrush changeBrushInSlot(brushes::ActiveBrush brush, int i);

void updateMenuActions();
Expand Down
Loading

0 comments on commit 82f1819

Please sign in to comment.