Add "Save Brush Here" option to brush slot popup

This commit is contained in:
David Capello 2015-12-15 17:58:55 -03:00
parent 2d64a1926e
commit 6ff62c899e
3 changed files with 21 additions and 0 deletions

View File

@ -77,6 +77,15 @@ BrushRef AppBrushes::getCustomBrush(slot_id slot) const
return BrushRef();
}
void AppBrushes::setCustomBrush(slot_id slot, const doc::BrushRef& brush)
{
--slot;
if (slot >= 0 && slot < (int)m_slots.size()) {
m_slots[slot].setBrush(brush);
ItemsChange();
}
}
Brushes AppBrushes::getCustomBrushes()
{
Brushes brushes;

View File

@ -32,6 +32,7 @@ namespace app {
bool hasCustomBrush(slot_id slot) const;
const doc::Brushes& getStandardBrushes() { return m_standard; }
doc::BrushRef getCustomBrush(slot_id slot) const;
void setCustomBrush(slot_id slot, const doc::BrushRef& brush);
doc::Brushes getCustomBrushes();
void lockCustomBrush(slot_id slot);

View File

@ -121,12 +121,16 @@ private:
void onClick() override {
Menu menu;
AppMenuItem save("Save Brush Here");
AppMenuItem lockItem(m_delegate->onIsBrushSlotLocked(m_slot) ? "Unlock Brush": "Lock Brush");
AppMenuItem deleteItem("Delete");
AppMenuItem deleteAllItem("Delete All");
save.Click.connect(&BrushOptionsItem::onSaveBrush, this);
lockItem.Click.connect(&BrushOptionsItem::onLockBrush, this);
deleteItem.Click.connect(&BrushOptionsItem::onDeleteBrush, this);
deleteAllItem.Click.connect(&BrushOptionsItem::onDeleteAllBrushes, this);
menu.addChild(&save);
menu.addChild(new MenuSeparator);
menu.addChild(&lockItem);
menu.addChild(&deleteItem);
menu.addChild(new MenuSeparator);
@ -142,6 +146,13 @@ private:
private:
void onSaveBrush() {
AppBrushes& brushes = App::instance()->brushes();
brushes.setCustomBrush(
m_slot, ContextBar::createBrushFromPreferences());
brushes.lockCustomBrush(m_slot);
}
void onLockBrush() {
if (m_delegate->onIsBrushSlotLocked(m_slot))
m_delegate->onUnlockBrushSlot(m_slot);