r23372 by craig - #9154: Apply patch to apply new base directory to missing images (ale)

scribus-commit scribus-commit at lists.scribus.net
Sat Nov 23 21:57:42 UTC 2019


Author: craig
Date: Sat Nov 23 21:57:42 2019
New Revision: 23372

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23372
Log:
#9154: Apply patch to apply new base directory to missing images (ale)

Modified:
    trunk/Scribus/scribus/ui/picsearch.cpp
    trunk/Scribus/scribus/ui/picsearch.h
    trunk/Scribus/scribus/ui/picsearch.ui
    trunk/Scribus/scribus/ui/picsearchoptions.cpp
    trunk/Scribus/scribus/ui/picstatus.cpp
    trunk/Scribus/scribus/ui/picstatus.h

Modified: trunk/Scribus/scribus/ui/picsearch.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23372&path=/trunk/Scribus/scribus/ui/picsearch.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/picsearch.cpp	(original)
+++ trunk/Scribus/scribus/ui/picsearch.cpp	Sat Nov 23 21:57:42 2019
@@ -20,7 +20,8 @@
 
 
 
-PicSearch::PicSearch(QWidget* parent, const QString & fileName, const QStringList & avalableFiles) : QDialog(parent), currentImage(QString())
+PicSearch::PicSearch(QWidget* parent, const QString & fileName, const QStringList & avalableFiles, bool brokenLinksOnly) :
+	QDialog(parent), brokenLinksOnly{brokenLinksOnly}
 {
 	setupUi(this);
 	setModal(true);
@@ -28,13 +29,18 @@
 	previewLabel->hide();
 	fileNameLabel->setText(fileName);
 
-	for (int i = 0; i < avalableFiles.count(); ++i)
-		foundFilesBox->addItem( QDir::toNativeSeparators(avalableFiles[i]) );
+	for (const auto& file: avalableFiles)
+		foundFilesBox->addItem(QDir::toNativeSeparators(file));
+
+	foundFilesBox->setCurrentRow(0);
+
+	matchWarningLabel->setVisible(false);
 
 	// signals and slots connections
 	connect(cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
 	connect(useButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
 	connect(previewCheckBox, SIGNAL( clicked() ), this, SLOT( previewCheckBox_clicked() ) );
+	connect(matchCheckBox, SIGNAL( clicked() ), this, SLOT( matchCheckBox_clicked() ) );
 	connect(foundFilesBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(foundFilesBox_clicked(QListWidgetItem*)));
 }
 
@@ -43,25 +49,28 @@
 	if (previewCheckBox->isChecked())
 	{
 		previewLabel->show();
-		if (!currentImage.isEmpty())
-			createPreview();
+		createPreview();
 	}
 	else
 		previewLabel->hide();
+}
+
+void PicSearch::matchCheckBox_clicked()
+{
+	matchWarningLabel->setVisible(brokenLinksOnly && matchCheckBox->isChecked());
 }
 
 void PicSearch::foundFilesBox_clicked(QListWidgetItem *c)
 {
 	if (c == nullptr)
 		return;
-	currentImage = QDir::fromNativeSeparators(c->text());
 	if (previewCheckBox->isChecked())
 		createPreview();
-	useButton->setEnabled(true);
 }
 
 void PicSearch::createPreview()
 {
+	const auto currentImage = foundFilesBox->currentItem()->text();
 	QPixmap pm(200, 200);
 	QFileInfo fi = QFileInfo(currentImage);
 	int w = 200;

Modified: trunk/Scribus/scribus/ui/picsearch.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23372&path=/trunk/Scribus/scribus/ui/picsearch.h
==============================================================================
--- trunk/Scribus/scribus/ui/picsearch.h	(original)
+++ trunk/Scribus/scribus/ui/picsearch.h	Sat Nov 23 21:57:42 2019
@@ -24,7 +24,7 @@
 It's called after image search Extras/Manage Pictures/ Click [Search] button for chosen
 image frame item. */
 class SCRIBUS_API PicSearch : public QDialog, Ui::PicSearch
-{ 
+{
 	Q_OBJECT
 
 public:
@@ -35,11 +35,13 @@
 	\param fileName QString name of image
 	\param avalableFiles QStringList List of Paths where an Image with the given Name is present
 	*/
-	PicSearch( QWidget* parent, const QString & fileName, const QStringList & avalableFiles);
+	PicSearch( QWidget* parent, const QString & fileName, const QStringList & avalableFiles, bool brokenLinksOnly);
 	~PicSearch() {};
 
-	//! \brief Currently selected image with its full path
-	QString currentImage;
+	//! \brief Selected image with its full path
+	QString getSelectedImage() { return foundFilesBox->currentItem()->text(); }
+	//! \brief Matching images should also be replaced?
+	bool isApplyToMatchingImages() { return matchCheckBox->isChecked(); }
 
 private slots:
 	/*!
@@ -47,6 +49,11 @@
 	\brief If preview is desired (checked) then the image preview is shown and generated, otherwise hidden.
 	*/
 	void previewCheckBox_clicked();
+	/*!
+	\author Ale Rimoldi
+	\brief If matching is desired (checked) then show a warning when only broken linked images are matched.
+	*/
+	void matchCheckBox_clicked();
 	/*!
 	\author Franz Schmid
 	\brief When image is selected from the ListBox then the image preview may be shown and the Use button is enabled.
@@ -63,8 +70,9 @@
 	//! \brief Emitted when the pic for a row is replaced. Arg is row index.
 	void rowPicChanged(unsigned int);
 
-protected:
+private:
 	QSize minS;
+	bool brokenLinksOnly;
 };
 
 #endif // PICSEARCH_H

Modified: trunk/Scribus/scribus/ui/picsearch.ui
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23372&path=/trunk/Scribus/scribus/ui/picsearch.ui
==============================================================================
--- trunk/Scribus/scribus/ui/picsearch.ui	(original)
+++ trunk/Scribus/scribus/ui/picsearch.ui	Sat Nov 23 21:57:42 2019
@@ -1,60 +1,77 @@
-<ui version="4.0" >
- <author>Petr Vanek <petr at scribus.info></author>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <author>Petr Vanek <petr at scribus.info></author>
  <class>PicSearch</class>
- <widget class="QDialog" name="PicSearch" >
-  <property name="geometry" >
+ <widget class="QDialog" name="PicSearch">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>499</width>
-    <height>263</height>
+    <width>516</width>
+    <height>292</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Result</string>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
-    <number>10</number>
-   </property>
-   <property name="spacing" >
+  <layout class="QVBoxLayout">
+   <property name="spacing">
     <number>5</number>
    </property>
-   <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <property name="spacing" >
+   <property name="leftMargin">
+    <number>10</number>
+   </property>
+   <property name="topMargin">
+    <number>10</number>
+   </property>
+   <property name="rightMargin">
+    <number>10</number>
+   </property>
+   <property name="bottomMargin">
+    <number>10</number>
+   </property>
+   <item>
+    <layout class="QHBoxLayout">
+     <property name="spacing">
       <number>5</number>
      </property>
-     <item>
-      <widget class="QLabel" name="textLabel1" >
-       <property name="text" >
+     <property name="leftMargin">
+      <number>0</number>
+     </property>
+     <property name="topMargin">
+      <number>0</number>
+     </property>
+     <property name="rightMargin">
+      <number>0</number>
+     </property>
+     <property name="bottomMargin">
+      <number>0</number>
+     </property>
+     <item>
+      <widget class="QLabel" name="textLabel1">
+       <property name="text">
         <string>Search Results for: </string>
        </property>
-       <property name="wordWrap" >
+       <property name="wordWrap">
         <bool>false</bool>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QLabel" name="fileNameLabel" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>7</hsizetype>
-         <vsizetype>5</vsizetype>
+      <widget class="QLabel" name="fileNameLabel">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="frameShape" >
+       <property name="frameShape">
         <enum>QFrame::Box</enum>
        </property>
-       <property name="text" >
+       <property name="text">
         <string/>
        </property>
-       <property name="wordWrap" >
+       <property name="wordWrap">
         <bool>false</bool>
        </property>
       </widget>
@@ -62,43 +79,61 @@
     </layout>
    </item>
    <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <property name="spacing" >
+    <layout class="QHBoxLayout">
+     <property name="spacing">
       <number>5</number>
      </property>
-     <item>
-      <widget class="QListWidget" name="foundFilesBox" />
-     </item>
-     <item>
-      <layout class="QVBoxLayout" >
-       <property name="margin" >
-        <number>0</number>
-       </property>
-       <property name="spacing" >
+     <property name="leftMargin">
+      <number>0</number>
+     </property>
+     <property name="topMargin">
+      <number>0</number>
+     </property>
+     <property name="rightMargin">
+      <number>0</number>
+     </property>
+     <property name="bottomMargin">
+      <number>0</number>
+     </property>
+     <item>
+      <widget class="QListWidget" name="foundFilesBox"/>
+     </item>
+     <item>
+      <layout class="QVBoxLayout">
+       <property name="spacing">
         <number>5</number>
        </property>
-       <item>
-        <widget class="QCheckBox" name="previewCheckBox" >
-         <property name="text" >
+       <property name="leftMargin">
+        <number>0</number>
+       </property>
+       <property name="topMargin">
+        <number>0</number>
+       </property>
+       <property name="rightMargin">
+        <number>0</number>
+       </property>
+       <property name="bottomMargin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="QCheckBox" name="previewCheckBox">
+         <property name="text">
           <string>&Preview</string>
          </property>
-         <property name="shortcut" >
+         <property name="shortcut">
           <string>Alt+P</string>
          </property>
         </widget>
        </item>
        <item>
         <spacer>
-         <property name="orientation" >
+         <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
-         <property name="sizeType" >
+         <property name="sizeType">
           <enum>QSizePolicy::Expanding</enum>
          </property>
-         <property name="sizeHint" >
+         <property name="sizeHint" stdset="0">
           <size>
            <width>21</width>
            <height>81</height>
@@ -106,73 +141,59 @@
          </property>
         </spacer>
        </item>
-       <item>
-        <widget class="QPushButton" name="useButton" >
-         <property name="enabled" >
-          <bool>false</bool>
-         </property>
-         <property name="text" >
-          <string>&Select</string>
-         </property>
-         <property name="shortcut" >
-          <string>Alt+S</string>
-         </property>
-         <property name="default" >
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QPushButton" name="cancelButton" >
-         <property name="text" >
-          <string>Cancel</string>
-         </property>
-        </widget>
-       </item>
       </layout>
      </item>
      <item>
-      <layout class="QVBoxLayout" >
-       <property name="margin" >
-        <number>0</number>
-       </property>
-       <property name="spacing" >
+      <layout class="QVBoxLayout">
+       <property name="spacing">
         <number>5</number>
        </property>
-       <item>
-        <widget class="QLabel" name="previewLabel" >
-         <property name="minimumSize" >
+       <property name="leftMargin">
+        <number>0</number>
+       </property>
+       <property name="topMargin">
+        <number>0</number>
+       </property>
+       <property name="rightMargin">
+        <number>0</number>
+       </property>
+       <property name="bottomMargin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="QLabel" name="previewLabel">
+         <property name="minimumSize">
           <size>
            <width>210</width>
            <height>210</height>
           </size>
          </property>
-         <property name="maximumSize" >
+         <property name="maximumSize">
           <size>
            <width>210</width>
            <height>210</height>
           </size>
          </property>
-         <property name="frameShape" >
+         <property name="frameShape">
           <enum>QFrame::Box</enum>
          </property>
-         <property name="alignment" >
+         <property name="alignment">
           <set>Qt::AlignCenter</set>
          </property>
-         <property name="wordWrap" >
+         <property name="wordWrap">
           <bool>false</bool>
          </property>
         </widget>
        </item>
        <item>
         <spacer>
-         <property name="orientation" >
+         <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
-         <property name="sizeType" >
+         <property name="sizeType">
           <enum>QSizePolicy::Expanding</enum>
          </property>
-         <property name="sizeHint" >
+         <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
            <height>40</height>
@@ -184,9 +205,78 @@
      </item>
     </layout>
    </item>
+   <item>
+    <widget class="QCheckBox" name="matchCheckBox">
+     <property name="text">
+      <string>Apply to all &matching images</string>
+     </property>
+     <property name="shortcut">
+      <string>Alt+M</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="matchWarningLabel">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string>Since you selected an image with a broken link, only image frames with invalid links will be modified.</string>
+     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="useButton">
+       <property name="enabled">
+        <bool>true</bool>
+       </property>
+       <property name="text">
+        <string>&Select</string>
+       </property>
+       <property name="shortcut">
+        <string>Alt+S</string>
+       </property>
+       <property name="default">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="cancelButton">
+       <property name="text">
+        <string>Cancel</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
   </layout>
  </widget>
- <layoutdefault spacing="6" margin="11" />
+ <layoutdefault spacing="6" margin="11"/>
  <resources/>
  <connections/>
 </ui>

Modified: trunk/Scribus/scribus/ui/picsearchoptions.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23372&path=/trunk/Scribus/scribus/ui/picsearchoptions.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/picsearchoptions.cpp	(original)
+++ trunk/Scribus/scribus/ui/picsearchoptions.cpp	Sat Nov 23 21:57:42 2019
@@ -89,7 +89,7 @@
 #else 
 	// TODO: and on _WIN32 workDir is ... ?
 #endif
-	QString searchBase = QFileDialog::getExistingDirectory(this, tr("Select a base directory for search"), workDir);
+	QString searchBase = QFileDialog::getExistingDirectory(this, tr("Select a base directory to search for ") + fileEdit->text(), workDir);
 	if (searchBase.isEmpty() || !QDir().exists(searchBase))
 		return;
 	m_strLastDirSearched = searchBase;

Modified: trunk/Scribus/scribus/ui/picstatus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23372&path=/trunk/Scribus/scribus/ui/picstatus.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/picstatus.cpp	(original)
+++ trunk/Scribus/scribus/ui/picstatus.cpp	Sat Nov 23 21:57:42 2019
@@ -35,8 +35,6 @@
 #include <QPushButton>
 #include <QScopedPointer>
 #include <QToolButton>
-
-#include <cstdio>
 
 #include "commonstrings.h"
 #include "effectsdialog.h"
@@ -201,14 +199,13 @@
 
 void PicStatus::sortByName()
 {
-	QListWidgetItem *firstItem = nullptr;
 	QMap<QString, PicItem*> sorted;
 
 	int num = imageViewArea->count();
 	if (num == 0)
 		return;
 
-	firstItem = imageViewArea->currentItem();
+	auto firstItem = imageViewArea->currentItem();
 	for (int a = num-1; a > -1; --a)
 	{
 		QListWidgetItem *ite = imageViewArea->takeItem(a);
@@ -233,14 +230,13 @@
 
 void PicStatus::sortByPage()
 {
-	QListWidgetItem *firstItem = nullptr;
 	QMap<int, PicItem*> sorted;
 
 	int num = imageViewArea->count();
 	if (num == 0)
 		return;
 
-	firstItem = imageViewArea->currentItem();
+	auto firstItem = imageViewArea->currentItem();
 	for (int a = num-1; a > -1; --a)
 	{
 		QListWidgetItem *ite = imageViewArea->takeItem(a);
@@ -446,18 +442,18 @@
 	emit selectElementByItem(currItem, true, 1);
 }
 
-bool PicStatus::loadPict(const QString & newFilePath)
+bool PicStatus::loadPict(PageItem* item, const QString & newFilePath)
 {
 	// Hack to fool the LoadPict function
-	currItem->Pfile = newFilePath;
-	bool masterPageMode = !currItem->OnMasterPage.isEmpty();
+	item->Pfile = newFilePath;
+	bool masterPageMode = !item->OnMasterPage.isEmpty();
 	bool oldMasterPageMode = m_Doc->masterPageMode();
 	if (masterPageMode != oldMasterPageMode)
 		m_Doc->setMasterPageMode(masterPageMode);
-	m_Doc->loadPict(newFilePath, currItem, true);
+	m_Doc->loadPict(newFilePath, item, true);
 	if (masterPageMode != oldMasterPageMode)
 		m_Doc->setMasterPageMode(oldMasterPageMode);
-	return currItem->imageIsAvailable;
+	return item->imageIsAvailable;
 }
 
 void PicStatus::SearchPic()
@@ -483,16 +479,24 @@
 		return;
 	}
 
-	QScopedPointer<PicSearch> dia2(new PicSearch(this, dia->getFileName(), dia->getMatches()));
+	auto item = static_cast<PicItem*>(imageViewArea->currentItem());
+	bool brokenLink = !(item->PageItemObject->imageIsAvailable);
+
+	QScopedPointer<PicSearch> dia2(new PicSearch(this, dia->getFileName(), dia->getMatches(), brokenLink));
 	if (dia2->exec() != QDialog::Accepted)
 		return;
-	Q_ASSERT(!dia2->currentImage.isEmpty());
-	loadPict(dia2->currentImage);
+
+	auto source = QFileInfo(currItem->Pfile);
+
+	loadPict(currItem, dia2->getSelectedImage());
 	refreshItem(currItem);
-	QFileInfo fi = QFileInfo(currItem->Pfile);
-	imageViewArea->currentItem()->setText(fi.fileName());
-	imageViewArea->currentItem()->setIcon(createImgIcon(currItem));
+	auto target = QFileInfo(currItem->Pfile);
+	item->setText(target.fileName());
+	item->setIcon(createImgIcon(currItem));
 	imageSelected(imageViewArea->currentItem());
+
+	if (dia2->isApplyToMatchingImages())
+		relinkMatchingImages(source, target, brokenLink);
 }
 
 void PicStatus::FileManager()
@@ -515,7 +519,7 @@
 	if (dia->exec())
 	{
 		currItem->effectsInUse = dia->effectsList;
-		loadPict(currItem->Pfile);
+		loadPict(currItem, currItem->Pfile);
 		refreshItem(currItem);
 		imageViewArea->currentItem()->setIcon(createImgIcon(currItem));
 	}
@@ -530,7 +534,7 @@
 	ExtImageProps dia(this, &currItem->pixm.imgInfo, currItem, m_Doc->view());
 	if (dia.exec())
 	{
-		loadPict(currItem->Pfile);
+		loadPict(currItem, currItem->Pfile);
 		refreshItem(currItem);
 		imageViewArea->currentItem()->setIcon(createImgIcon(currItem));
 	}
@@ -543,3 +547,31 @@
 	SelectPic();
 	ScCore->primaryMainWindow()->callImageEditor();
 }
+
+/**
+ * Relink all matching images.
+ * Images match if they have the same path as the pattern.
+ * If the "pattern" was a broken link, only images with broken links will match.
+ */
+void PicStatus::relinkMatchingImages(const QFileInfo& source, const QFileInfo& target, bool brokenLink)
+{
+	for (int i = 0; i < imageViewArea->count(); i++)
+	{
+		auto item = static_cast<PicItem*>(imageViewArea->item(i));
+
+		if (brokenLink && item->PageItemObject->imageIsAvailable)
+			continue;
+
+		auto fi = QFileInfo(item->PageItemObject->Pfile);
+
+		if (fi.path() != source.path())
+			continue;
+		if (fi.fileName() == target.fileName())
+			continue;
+
+		loadPict(item->PageItemObject, QDir(target.path()).filePath(fi.fileName()));
+		refreshItem(item->PageItemObject);
+		item->setText(fi.fileName());
+		item->setIcon(createImgIcon(item->PageItemObject));
+	}
+}

Modified: trunk/Scribus/scribus/ui/picstatus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23372&path=/trunk/Scribus/scribus/ui/picstatus.h
==============================================================================
--- trunk/Scribus/scribus/ui/picstatus.h	(original)
+++ trunk/Scribus/scribus/ui/picstatus.h	Sat Nov 23 21:57:42 2019
@@ -10,6 +10,8 @@
 #include "scribusapi.h"
 #include "ui_picstatus.h"
 #include <QListWidgetItem>
+
+class QFileInfo;
 
 class ScribusDoc;
 class PageItem;
@@ -82,6 +84,11 @@
 	void FileManager();
 	void doImageEffects();
 	void doImageExtProp();
+	/*!
+	\author Ale Rimoldi
+	\brief Relink all images matching pattern.
+	*/
+	void relinkMatchingImages(const QFileInfo& source, const QFileInfo& target, bool brokenLink);
 	void doEditImage();
 
 signals:
@@ -96,7 +103,7 @@
 
 	/*! \brief Load the image specified into the PageItem
 	\param newFilePath a file path */
-	bool loadPict(const QString & newFilePath);
+	bool loadPict(PageItem* item, const QString & newFilePath);
 
 private:
 	ScribusDoc *m_Doc;




More information about the scribus-commit mailing list