[PATCH 4/9] Overwrite an existing PaintOp preset instead of creating a new one with the same name.

Silvio Heinrich plassy at web.de
Sun Dec 26 01:40:31 CET 2010


Additionally if a name is entered in the LineEdit field of the PaintOpPreset popup that exists already
then the LineEdit field is highlighted and the save button text is changed to "Overwrite Preset"
---
 krita/ui/kis_paintop_box.cc                    |   43 +++++++++++++++---------
 krita/ui/kis_paintop_box.h                     |    2 +-
 krita/ui/widgets/kis_paintop_presets_popup.cpp |   22 ++++++++++--
 krita/ui/widgets/kis_paintop_presets_popup.h   |    8 ++++
 4 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/krita/ui/kis_paintop_box.cc b/krita/ui/kis_paintop_box.cc
index a200ef0..4e60f69 100644
--- a/krita/ui/kis_paintop_box.cc
+++ b/krita/ui/kis_paintop_box.cc
@@ -171,15 +171,18 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
     connect(m_presetsPopup, SIGNAL(savePresetClicked()), this, SLOT(slotSaveActivePreset()));
 
     connect(m_presetsPopup, SIGNAL(defaultPresetClicked()), this, SLOT(slotSetupDefaultPreset()));
+    
+    connect(m_presetsPopup, SIGNAL(presetNameLineEditChanged(QString)),
+            this, SLOT(slotWatchPresetNameLineEdit(QString)));
 
     connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)),
             this, SLOT(resourceSelected(KoResource*)));
 
     connect(m_resourceProvider, SIGNAL(sigNodeChanged(const KisNodeSP)),
             this, SLOT(nodeChanged(const KisNodeSP)));
-	
-	connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)),
-			m_presetsPopup, SLOT(resourceSelected(KoResource*)));
+    
+    connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)),
+            m_presetsPopup, SLOT(resourceSelected(KoResource*)));
 
     //Needed to connect canvas to favoriate resource manager
     m_view->canvasBase()->createFavoriteResourceManager(this);
@@ -411,27 +414,28 @@ KisPaintOpPresetSP KisPaintopBox::activePreset(const KoID & paintop, const KoInp
 
 void KisPaintopBox::slotSaveActivePreset()
 {
-    KisPaintOpPresetSP preset = m_resourceProvider->currentPreset();
-    if (!preset)
+    KisPaintOpPresetSP curPreset = m_resourceProvider->currentPreset();
+    
+    if (!curPreset)
         return;
 
-    KisPaintOpPreset* newPreset = preset->clone();
-    newPreset->setImage(m_presetsPopup->cutOutOverlay());
-
+    KisPaintOpPreset* newPreset = curPreset->clone();
     KoResourceServer<KisPaintOpPreset>* rServer = KisResourceServerProvider::instance()->paintOpPresetServer();
     QString saveLocation = rServer->saveLocation();
-
     QString name = m_presetsPopup->getPresetName();
+    QFileInfo fileInfo(saveLocation + name + newPreset->defaultFileExtension());
 
-    QFileInfo fileInfo;
-    fileInfo.setFile(saveLocation + name + newPreset->defaultFileExtension());
-
-    int i = 1;
-    while (fileInfo.exists()) {
-        fileInfo.setFile(saveLocation + name + QString("%1").arg(i) + newPreset->defaultFileExtension());
-        i++;
+    if (fileInfo.exists()) {
+        rServer->removeResource(rServer->getResourceByFilename(fileInfo.fileName()));
     }
+    
+//     int i = 1;
+//     while (fileInfo.exists()) {
+//         fileInfo.setFile(saveLocation + name + QString("%1").arg(i) + newPreset->defaultFileExtension());
+//         i++;
+//     }
 
+    newPreset->setImage(m_presetsPopup->cutOutOverlay());
     newPreset->setFilename(fileInfo.filePath());
     newPreset->setName(name);
 
@@ -581,4 +585,11 @@ void KisPaintopBox::slotSaveToFavouriteBrushes()
     }
 }
 
+void KisPaintopBox::slotWatchPresetNameLineEdit(const QString& text)
+{
+    KoResourceServer<KisPaintOpPreset>* rServer = KisResourceServerProvider::instance()->paintOpPresetServer();
+    m_presetsPopup->changeSavePresetButtonText(rServer->getResourceByName(text) != 0);
+}
+
+
 #include "kis_paintop_box.moc"
diff --git a/krita/ui/kis_paintop_box.h b/krita/ui/kis_paintop_box.h
index 85f4db2..6d17b83 100644
--- a/krita/ui/kis_paintop_box.h
+++ b/krita/ui/kis_paintop_box.h
@@ -105,7 +105,6 @@ private:
     void setEnabledInternal(bool value);
 
 private slots:
-
     void updatePaintops();
     void nodeChanged(const KisNodeSP node);
     void eraseModeToggled(bool checked);
@@ -113,6 +112,7 @@ private slots:
     void slotSetCompositeMode(const QString& compositeOp);
     void slotSetPaintop(const QString& paintOpId);
     void slotSaveToFavouriteBrushes();
+    void slotWatchPresetNameLineEdit(const QString& text);
 
 private:
 
diff --git a/krita/ui/widgets/kis_paintop_presets_popup.cpp b/krita/ui/widgets/kis_paintop_presets_popup.cpp
index 4d71b39..3c42640 100644
--- a/krita/ui/widgets/kis_paintop_presets_popup.cpp
+++ b/krita/ui/widgets/kis_paintop_presets_popup.cpp
@@ -112,6 +112,9 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
             
     connect(m_d->uiWdgPaintOpPresetSettings.bnDefaultPreset, SIGNAL(clicked()),
             this, SIGNAL(defaultPresetClicked()));
+    
+    connect(m_d->uiWdgPaintOpPresetSettings.txtPreset, SIGNAL(textChanged(QString)),
+            this, SIGNAL(presetNameLineEditChanged(QString)));
             
     KisConfig cfg;
     m_d->detached = !cfg.paintopPopupDetached();
@@ -161,9 +164,6 @@ void KisPaintOpPresetsPopup::setPaintOpSettingsWidget(QWidget * widget)
     }
 
     if (widget) {
-
-        
-        
         widget->setFont(m_d->smallFont);
 
         m_d->settingsWidget->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
@@ -174,6 +174,22 @@ void KisPaintOpPresetsPopup::setPaintOpSettingsWidget(QWidget * widget)
     }
 }
 
+void KisPaintOpPresetsPopup::changeSavePresetButtonText(bool change)
+{
+    QPalette palette;
+    
+    if (change) {
+        palette.setColor(QPalette::Base, QColor(255,180,180));
+        m_d->uiWdgPaintOpPresetSettings.bnSave->setText("Overwrite Preset");
+        m_d->uiWdgPaintOpPresetSettings.txtPreset->setPalette(palette);
+    }
+    else {
+        m_d->uiWdgPaintOpPresetSettings.bnSave->setText("Save to Presets");
+        m_d->uiWdgPaintOpPresetSettings.txtPreset->setPalette(palette);
+    }
+}
+
+
 QString KisPaintOpPresetsPopup::getPresetName() const
 {
     return m_d->uiWdgPaintOpPresetSettings.txtPreset->text();
diff --git a/krita/ui/widgets/kis_paintop_presets_popup.h b/krita/ui/widgets/kis_paintop_presets_popup.h
index 49a242e..9379ba1 100644
--- a/krita/ui/widgets/kis_paintop_presets_popup.h
+++ b/krita/ui/widgets/kis_paintop_presets_popup.h
@@ -45,6 +45,12 @@ public:
     ~KisPaintOpPresetsPopup();
 
     void setPaintOpSettingsWidget(QWidget * widget);
+    
+    /**
+     * changes the "save to preset" button text to "override preset"
+     * and highlites the preset name lineedit
+     */
+    void changeSavePresetButtonText(bool change);
 
     /**
      * @return the name entered in the preset name lineedit
@@ -71,12 +77,14 @@ public slots:
 signals:
     void savePresetClicked();
     void defaultPresetClicked();
+    void presetNameLineEditChanged(const QString& presetName);
 
 private slots:
     void fillScratchPadGradient();
     void fillScratchPadSolid();
     void fillScratchPadLayer();
     void slotCheckPresetValidity();
+    
 
 private:
 
-- 
1.7.1




More information about the kimageshop mailing list