Commit 68a16b92 authored by Scott Petrovic's avatar Scott Petrovic

move the saving brush preset code to the save widget.

parent 47c16742
......@@ -117,6 +117,9 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
setWindowTitle(i18n("Painter's Toolchest"));
m_favoriteResourceManager = new KisFavoriteResourceManager(this);
KConfigGroup grp = KSharedConfig::openConfig()->group("krita").group("Toolbar BrushesAndStuff");
int iconsize = grp.readEntry("IconSize", 32);
......@@ -429,10 +432,12 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
m_toolOptionsPopup->switchDetached(false);
}
m_presetsPopup = new KisPaintOpPresetsPopup(m_resourceProvider);
m_presetsPopup = new KisPaintOpPresetsPopup(m_resourceProvider, m_favoriteResourceManager);
m_brushEditorPopupButton->setPopupWidget(m_presetsPopup);
m_presetsPopup->parentWidget()->setWindowTitle(i18n("Brush Editor"));
connect(m_presetsPopup, SIGNAL(brushEditorShown()), SLOT(slotUpdateOptionsWidgetPopup()));
connect(m_viewManager->mainWindow(), SIGNAL(themeChanged()), m_presetsPopup, SLOT(updateThemedIcons()));
......@@ -488,7 +493,7 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
//Needed to connect canvas to favorite resource manager
connect(m_viewManager->resourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), SLOT(slotUnsetEraseMode()));
m_favoriteResourceManager = new KisFavoriteResourceManager(this);
connect(m_resourceProvider, SIGNAL(sigFGColorUsed(KoColor)), m_favoriteResourceManager, SLOT(slotAddRecentColor(KoColor)));
connect(m_resourceProvider, SIGNAL(sigFGColorChanged(KoColor)), m_favoriteResourceManager, SLOT(slotChangeFGColorSelector(KoColor)));
......@@ -532,6 +537,7 @@ KisPaintopBox::~KisPaintopBox()
void KisPaintopBox::restoreResource(KoResource* resource)
{
KisPaintOpPreset* preset = dynamic_cast<KisPaintOpPreset*>(resource);
//qDebug() << "restoreResource" << resource << preset;
if (preset) {
......@@ -850,6 +856,7 @@ void KisPaintopBox::slotCanvasResourceChanged(int key, const QVariant &value)
void KisPaintopBox::slotSaveActivePreset()
{
KisPaintOpPresetSP curPreset = m_resourceProvider->currentPreset();
if (!curPreset)
return;
......@@ -910,6 +917,7 @@ void KisPaintopBox::slotSaveActivePreset()
restoreResource(curPreset.data());
m_favoriteResourceManager->setBlockUpdates(false);
}
void KisPaintopBox::slotUpdatePreset()
......
......@@ -72,6 +72,7 @@ public:
KisPaintOpConfigWidget *settingsWidget;
QFont smallFont;
KisCanvasResourceProvider *resourceProvider;
bool detached;
bool ignoreHideEvents;
QSize minimumSettingsWidgetSize;
......@@ -80,7 +81,9 @@ public:
KisSignalAutoConnectionsStore widgetConnections;
};
KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resourceProvider, QWidget * parent)
KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resourceProvider,
KisFavoriteResourceManager* favoriteResourceManager,
QWidget * parent)
: QWidget(parent)
, m_d(new Private())
{
......@@ -110,6 +113,7 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
// overwrite existing preset and saving a new preset use the same dialog
saveDialog = new KisPresetSaveWidget(this->parentWidget());
saveDialog->scratchPadSetup(resourceProvider);
saveDialog->setFavoriteResourceManager(favoriteResourceManager); // this is needed when saving the preset
saveDialog->hide();
......
......@@ -28,6 +28,7 @@
#include <brushengine/kis_paintop_factory.h>
#include "../kis_paint_ops_model.h"
#include <widgets/kis_paintop_presets_save.h>
#include "kis_favorite_resource_manager.h"
class QString;
class KisCanvasResourceProvider;
......@@ -43,7 +44,9 @@ class KisPaintOpPresetsPopup : public QWidget
public:
KisPaintOpPresetsPopup(KisCanvasResourceProvider * resourceProvider, QWidget * parent = 0);
KisPaintOpPresetsPopup(KisCanvasResourceProvider * resourceProvider,
KisFavoriteResourceManager* favoriteResourceManager,
QWidget * parent = 0);
~KisPaintOpPresetsPopup() override;
......@@ -126,7 +129,6 @@ private:
QString current_paintOpId;
QList<KisPaintOpInfo> sortedBrushEnginesList;
};
#endif
......@@ -19,10 +19,15 @@
#include "widgets/kis_paintop_presets_save.h"
#include <QDebug>
#include <QDate>
#include <QTime>
#include <KoFileDialog.h>
#include "KisImportExportManager.h"
#include "QDesktopServices"
#include "kis_resource_server_provider.h"
KisPresetSaveWidget::KisPresetSaveWidget(QWidget * parent)
: KisPaintOpPresetSaveDialog(parent)
......@@ -132,13 +137,86 @@ void KisPresetSaveWidget::loadImageFromFile()
}
void KisPresetSaveWidget::setFavoriteResourceManager(KisFavoriteResourceManager * favManager)
{
m_favoriteResourceManager = favManager;
}
void KisPresetSaveWidget::savePreset()
{
KisPaintOpPresetSP curPreset = m_resourceProvider->currentPreset();
if (!curPreset)
return;
m_favoriteResourceManager->setBlockUpdates(true);
KisPaintOpPresetSP oldPreset = curPreset->clone();
oldPreset->load();
KisPaintOpPresetResourceServer * rServer = KisResourceServerProvider::instance()->paintOpPresetServer();
QString saveLocation = rServer->saveLocation();
// if we are saving a new brush, use what we type in for the input
QString presetName = m_isSavingNewBrush ? newBrushNameTexField->text() : curPreset->name();
QString currentPresetFileName = saveLocation + presetName + curPreset->defaultFileExtension();
if (rServer->resourceByName(presetName)) {
QString currentDate = QDate::currentDate().toString(Qt::ISODate);
QString currentTime = QTime::currentTime().toString(Qt::ISODate);
QString presetFilename = saveLocation + presetName + "_backup_" + currentDate + "-" + currentTime + oldPreset->defaultFileExtension();
oldPreset->setFilename(presetFilename);
oldPreset->setName(presetName);
oldPreset->setPresetDirty(false);
oldPreset->setValid(true);
rServer->addResource(oldPreset);
QStringList tags;
tags = rServer->assignedTagsList(curPreset.data());
rServer->removeResourceAndBlacklist(oldPreset.data());
Q_FOREACH (const QString & tag, tags) {
rServer->addTag(oldPreset.data(), tag);
}
}
if (m_isSavingNewBrush) {
qDebug() << "save the brush as a new preset";
KisPaintOpPresetSP newPreset = curPreset->clone();
newPreset->setFilename(currentPresetFileName);
newPreset->setName(presetName);
newPreset->setImage(brushPresetThumbnailWidget->cutoutOverlay());
newPreset->setPresetDirty(false);
newPreset->setValid(true);
rServer->addResource(newPreset);
curPreset = newPreset; //to load the new preset
} else {
qDebug() << "save over the existing brush (and create a backup)";
if (curPreset->filename().contains(saveLocation)==false || curPreset->filename().contains(presetName)==false) {
rServer->removeResourceAndBlacklist(curPreset.data());
curPreset->setFilename(currentPresetFileName);
curPreset->setName(presetName);
}
if (!rServer->resourceByFilename(curPreset->filename())){
//this is necessary so that we can get the preset afterwards.
rServer->addResource(curPreset, false, false);
rServer->removeFromBlacklist(curPreset.data());
}
curPreset->setImage(brushPresetThumbnailWidget->cutoutOverlay());
curPreset->save();
curPreset->load();
}
// HACK ALERT! the server does not notify the observers
// automatically, so we need to call theupdate manually!
rServer->tagCategoryMembersChanged();
m_favoriteResourceManager->setBlockUpdates(false);
close(); // we are done... so close the save brush dialog
}
void KisPresetSaveWidget::isSavingNewBrush(bool newBrush)
......
......@@ -24,6 +24,7 @@
#include "ui_wdgsavebrushpreset.h"
#include "kis_canvas_resource_provider.h"
#include "kis_favorite_resource_manager.h"
class KisPaintOpPresetSaveDialog : public QDialog , public Ui::WdgSaveBrushPreset
{
......@@ -53,6 +54,9 @@ public:
void scratchPadSetup(KisCanvasResourceProvider* resourceProvider);
KisCanvasResourceProvider* m_resourceProvider;
void setFavoriteResourceManager(KisFavoriteResourceManager * favManager);
public Q_SLOTS:
void usePreviousThumbnail(bool usePrevious);
void loadImageFromFile();
......@@ -62,7 +66,7 @@ public Q_SLOTS:
private:
bool m_isSavingNewBrush;
KisFavoriteResourceManager * m_favoriteResourceManager;
};
......
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