[krita/krita/3.2] plugins/dockers/imagedocker: FEATURE: save lastly visited directory in the Reference Images docker

Dmitry Kazakov null at kde.org
Thu Aug 3 17:21:34 UTC 2017


Git commit 3b6d3646bc54d46616c145b9d75b2491fef5476e by Dmitry Kazakov.
Committed on 03/08/2017 at 17:04.
Pushed by dkazakov into branch 'krita/3.2'.

FEATURE: save lastly visited directory in the Reference Images docker

Now the docker saves/restores the lastly visited reference folder
over Krita restart.

** A question to painters **

Do you also need to restore the open reference images?

Please take into account that at the moment the list of reference
images is not per-painting, it is global, that is shared between all
open images in Krita.

CC:kimageshop at kde.org

M  +31   -2    plugins/dockers/imagedocker/imagedocker_dock.cpp
M  +4    -0    plugins/dockers/imagedocker/imagedocker_dock.h

https://commits.kde.org/krita/3b6d3646bc54d46616c145b9d75b2491fef5476e

diff --git a/plugins/dockers/imagedocker/imagedocker_dock.cpp b/plugins/dockers/imagedocker/imagedocker_dock.cpp
index eebaceebf98..fd846ff51a8 100644
--- a/plugins/dockers/imagedocker/imagedocker_dock.cpp
+++ b/plugins/dockers/imagedocker/imagedocker_dock.cpp
@@ -15,6 +15,10 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include <kconfig.h>
+#include <kconfiggroup.h>
+#include <ksharedconfig.h>
+
 #include "imagedocker_dock.h"
 #include "image_strip_scene.h"
 #include "image_view.h"
@@ -224,8 +228,7 @@ ImageDockerDock::ImageDockerDock():
 
     connect(m_ui->cmbPath, SIGNAL(activated(const QString&)), SLOT(slotChangeRoot(const QString&)));
 
-    m_model->setRootPath(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
-    m_ui->treeView->setRootIndex(m_proxyModel->mapFromSource(m_model->index(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation))));
+    loadConfigState();
 
     connect(m_ui->treeView           , SIGNAL(doubleClicked(const QModelIndex&))      , SLOT(slotItemDoubleClicked(const QModelIndex&)));
     connect(m_ui->bnBack             , SIGNAL(clicked(bool))                          , SLOT(slotBackButtonClicked()));
@@ -249,6 +252,8 @@ ImageDockerDock::ImageDockerDock():
 
 ImageDockerDock::~ImageDockerDock()
 {
+    saveConfigState();
+
     delete m_proxyModel;
     delete m_model;
     delete m_imageStripScene;
@@ -374,6 +379,30 @@ void ImageDockerDock::setZoom(const ImageInfo& info)
     m_popupUi->zoomSlider->blockSignals(false);
 }
 
+void ImageDockerDock::saveConfigState()
+{
+    const QString lastUsedDirectory = m_model->filePath(m_proxyModel->mapToSource(m_ui->treeView->rootIndex()));
+
+    KConfigGroup cfg =  KSharedConfig::openConfig()->group("referenceImageDocker");
+    cfg.writeEntry("lastUsedDirectory", lastUsedDirectory);
+}
+
+void ImageDockerDock::loadConfigState()
+{
+    const QString defaultLocation = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
+
+    KConfigGroup cfg =  KSharedConfig::openConfig()->group("referenceImageDocker");
+    QString lastUsedDirectory = cfg.readEntry("lastUsedDirectory", defaultLocation);
+
+    if (!QFileInfo(lastUsedDirectory).exists()) {
+        lastUsedDirectory = defaultLocation;
+    }
+
+    m_model->setRootPath(lastUsedDirectory);
+    m_ui->treeView->setRootIndex(m_proxyModel->mapFromSource(m_model->index(lastUsedDirectory)));
+    updatePath(lastUsedDirectory);
+}
+
 
 // ------------ slots ------------------------------------------------- //
 
diff --git a/plugins/dockers/imagedocker/imagedocker_dock.h b/plugins/dockers/imagedocker/imagedocker_dock.h
index 2db6614f920..52449126a8f 100644
--- a/plugins/dockers/imagedocker/imagedocker_dock.h
+++ b/plugins/dockers/imagedocker/imagedocker_dock.h
@@ -91,6 +91,10 @@ private:
     bool isImageLoaded() const { return m_currImageID != -1; }
     void setZoom(const ImageInfo& info);
     
+    void saveConfigState();
+    void loadConfigState();
+
+
 private:
     QFileSystemModel*      m_model;
     QButtonGroup*          m_zoomButtons;



More information about the kimageshop mailing list