...
 
Commits (3)
......@@ -20,7 +20,8 @@ for which a new license (GPL+exception) is in place.
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 @@ PicSearch::PicSearch(QWidget* parent, const QString & fileName, const QStringLis
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 @@ void PicSearch::previewCheckBox_clicked()
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;
......
......@@ -24,7 +24,7 @@ for which a new license (GPL+exception) is in place.
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 @@ public:
\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:
/*!
......@@ -48,6 +50,11 @@ private slots:
*/
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.
\param c QListBoxItem
......@@ -63,8 +70,9 @@ signals:
//! \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
This diff is collapsed.
......@@ -89,7 +89,7 @@ void PicSearchOptions::slotChangeSearchDir()
#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;
......
......@@ -36,8 +36,6 @@ for which a new license (GPL+exception) is in place.
#include <QScopedPointer>
#include <QToolButton>
#include <cstdio>
#include "commonstrings.h"
#include "effectsdialog.h"
#include "extimageprops.h"
......@@ -201,14 +199,13 @@ void PicStatus::fillTable()
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::sortByName()
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 @@ void PicStatus::SelectPic()
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 @@ void PicStatus::SearchPic()
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 @@ void PicStatus::doImageEffects()
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 @@ void PicStatus::doImageExtProp()
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 @@ void PicStatus::doEditImage()
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));
}
}
......@@ -11,6 +11,8 @@ for which a new license (GPL+exception) is in place.
#include "ui_picstatus.h"
#include <QListWidgetItem>
class QFileInfo;
class ScribusDoc;
class PageItem;
......@@ -82,6 +84,11 @@ private slots:
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 @@ protected:
/*! \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;
......