r22577 by jghali - #15349: Image Manager: show images in the file manager <ale> (+some refactoring)
scribus-commit
scribus-commit at lists.scribus.net
Wed Jun 6 10:27:16 UTC 2018
Author: jghali
Date: Wed Jun 6 10:27:16 2018
New Revision: 22577
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22577
Log:
#15349: Image Manager: show images in the file manager <ale> (+some refactoring)
Modified:
trunk/Scribus/scribus/ui/picstatus.cpp
trunk/Scribus/scribus/ui/picstatus.h
trunk/Scribus/scribus/ui/picstatus.ui
Modified: trunk/Scribus/scribus/ui/picstatus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22577&path=/trunk/Scribus/scribus/ui/picstatus.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/picstatus.cpp (original)
+++ trunk/Scribus/scribus/ui/picstatus.cpp Wed Jun 6 10:27:16 2018
@@ -22,17 +22,20 @@
***************************************************************************/
#include "picstatus.h"
+#include <QAction>
+#include <QCheckBox>
+#include <QDesktopServices>
+#include <QFileInfo>
+#include <QLabel>
#include <QListWidget>
+#include <QMenu>
+#include <QMessageBox>
+#include <QPainter>
+#include <QPixmap>
#include <QPushButton>
+#include <QScopedPointer>
#include <QToolButton>
-#include <QLabel>
-#include <QCheckBox>
-#include <QMessageBox>
-#include <QPixmap>
-#include <QFileInfo>
-#include <QPainter>
-#include <QAction>
-#include <QMenu>
+
#include <cstdio>
#include "commonstrings.h"
@@ -75,6 +78,7 @@
connect(goPageButton, SIGNAL(clicked()), this, SLOT(GotoPic()));
connect(selectButton, SIGNAL(clicked()), this, SLOT(SelectPic()));
connect(searchButton, SIGNAL(clicked()), this, SLOT(SearchPic()));
+ connect(fileManagerButton, SIGNAL(clicked()), this, SLOT(FileManager()));
connect(effectsButton, SIGNAL(clicked()), this, SLOT(doImageEffects()));
connect(buttonLayers, SIGNAL(clicked()), this, SLOT(doImageExtProp()));
connect(buttonEdit, SIGNAL(clicked()), this, SLOT(doEditImage()));
@@ -111,6 +115,19 @@
p.drawRect(12, 12, 104, 104);
p.end();
return pm;
+}
+
+void PicStatus::enableWidgets(bool enabled)
+{
+ isPrinting->setEnabled(enabled);
+ isVisibleCheck->setEnabled(enabled);
+ goPageButton->setEnabled(enabled);
+ selectButton->setEnabled(enabled);
+ searchButton->setEnabled(enabled);
+ fileManagerButton->setEnabled(enabled);
+ effectsButton->setEnabled(enabled);
+ buttonLayers->setEnabled(enabled);
+ buttonEdit->setEnabled(enabled);
}
void PicStatus::fillTable()
@@ -186,30 +203,32 @@
{
QListWidgetItem *firstItem = 0;
QMap<QString, PicItem*> sorted;
+
int num = imageViewArea->count();
- if (num != 0)
- {
- firstItem = imageViewArea->currentItem();
- for (int a = num-1; a > -1; --a)
- {
- QListWidgetItem *ite = imageViewArea->takeItem(a);
- PicItem *item = (PicItem*)ite;
- QFileInfo fi = QFileInfo(item->PageItemObject->Pfile);
- sorted.insertMulti(fi.fileName(), item);
- }
- int counter = 0;
- foreach (const QString& i, sorted.uniqueKeys())
- {
- foreach (PicItem* val, sorted.values(i))
- {
- imageViewArea->insertItem(counter, val);
- counter++;
- }
- }
- imageViewArea->setCurrentItem(firstItem);
- imageSelected(firstItem);
- sortOrder = 0;
- }
+ if (num == 0)
+ return;
+
+ firstItem = imageViewArea->currentItem();
+ for (int a = num-1; a > -1; --a)
+ {
+ QListWidgetItem *ite = imageViewArea->takeItem(a);
+ PicItem *item = (PicItem*)ite;
+ QFileInfo fi = QFileInfo(item->PageItemObject->Pfile);
+ sorted.insertMulti(fi.fileName(), item);
+ }
+
+ int counter = 0;
+ foreach (const QString& i, sorted.uniqueKeys())
+ {
+ foreach (PicItem* val, sorted.values(i))
+ {
+ imageViewArea->insertItem(counter, val);
+ counter++;
+ }
+ }
+ imageViewArea->setCurrentItem(firstItem);
+ imageSelected(firstItem);
+ sortOrder = 0;
}
void PicStatus::sortByPage()
@@ -267,114 +286,119 @@
void PicStatus::imageSelected(QListWidgetItem *ite)
{
- if (ite != nullptr)
- {
- PicItem *item = (PicItem*)ite;
- currItem = item->PageItemObject;
- if (!currItem->OnMasterPage.isEmpty())
- displayPage->setText(currItem->OnMasterPage);
+ if (ite == nullptr)
+ {
+ currItem = nullptr;
+ enableWidgets(false);
+ return;
+ }
+
+ enableWidgets(true);
+
+ PicItem *item = (PicItem*) ite;
+ currItem = item->PageItemObject;
+ if (!currItem->OnMasterPage.isEmpty())
+ displayPage->setText(currItem->OnMasterPage);
+ else
+ {
+ if (currItem->OwnPage == -1)
+ displayPage->setText( tr("Not on a Page"));
else
- {
- if (currItem->OwnPage == -1)
- displayPage->setText( tr("Not on a Page"));
- else
- displayPage->setText(QString::number(currItem->OwnPage + 1));
- }
- displayObjekt->setText(currItem->itemName());
- if (currItem->imageIsAvailable)
+ displayPage->setText(QString::number(currItem->OwnPage + 1));
+ }
+ displayObjekt->setText(currItem->itemName());
+ if (currItem->imageIsAvailable)
+ {
+ QFileInfo fi = QFileInfo(currItem->Pfile);
+ QString ext = fi.suffix().toLower();
+ if (currItem->isInlineImage)
+ {
+ displayName->setText( tr("Embedded Image"));
+ displayPath->setText("");
+ searchButton->setEnabled(false);
+ fileManagerButton->setEnabled(false);
+ }
+ else
+ {
+ displayName->setText(fi.fileName());
+ displayPath->setText(QDir::toNativeSeparators(fi.path()));
+ searchButton->setEnabled(true);
+ fileManagerButton->setEnabled(true);
+ }
+ QString format = "";
+ switch (currItem->pixm.imgInfo.type)
+ {
+ case 0:
+ format = tr("JPG");
+ break;
+ case 1:
+ format = tr("TIFF");
+ break;
+ case 2:
+ format = tr("PSD");
+ break;
+ case 3:
+ format = tr("EPS/PS");
+ break;
+ case 4:
+ format = tr("PDF");
+ break;
+ case 5:
+ format = tr("JPG2000");
+ break;
+ case 6:
+ format = ext.toUpper();
+ break;
+ case 7:
+ format = tr("emb. PSD");
+ break;
+ }
+ displayFormat->setText(format);
+ QString cSpace;
+ if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (currItem->pixm.imgInfo.type != ImageType7))
+ cSpace = tr("Unknown");
+ else
+ cSpace=colorSpaceText(currItem->pixm.imgInfo.colorspace);
+ displayColorspace->setText(cSpace);
+ displayDPI->setText(QString("%1 x %2").arg(currItem->pixm.imgInfo.xres).arg(currItem->pixm.imgInfo.yres));
+ displayEffDPI->setText(QString("%1 x %2").arg(qRound(72.0 / currItem->imageXScale())).arg(qRound(72.0 / currItem->imageYScale())));
+ displaySizePixel->setText(QString("%1 x %2").arg(currItem->OrigW).arg(currItem->OrigH));
+ displayScale->setText(QString("%1 x %2 %").arg(currItem->imageXScale() * 100 / 72.0 * currItem->pixm.imgInfo.xres, 5, 'f', 1).arg(currItem->imageYScale() * 100 / 72.0 * currItem->pixm.imgInfo.yres, 5, 'f', 1));
+ displayPrintSize->setText(QString("%1 x %2%3").arg(currItem->OrigW * currItem->imageXScale() * m_Doc->unitRatio(), 7, 'f', 2).arg(currItem->OrigH * currItem->imageXScale() * m_Doc->unitRatio(), 7, 'f', 2).arg(unitGetSuffixFromIndex(m_Doc->unitIndex())));
+ isPrinting->setChecked(currItem->printEnabled());
+ isVisibleCheck->setChecked(currItem->imageVisible());
+ buttonEdit->setEnabled(currItem->isRaster);
+ effectsButton->setEnabled(currItem->isRaster);
+ buttonLayers->setEnabled(currItem->pixm.imgInfo.valid);
+ }
+ else
+ {
+ QString trNA = tr("n/a");
+ if (!currItem->Pfile.isEmpty())
{
QFileInfo fi = QFileInfo(currItem->Pfile);
- QString ext = fi.suffix().toLower();
- if (currItem->isInlineImage)
- {
- displayName->setText( tr("Embedded Image"));
- displayPath->setText("");
- searchButton->setEnabled(false);
- }
- else
- {
- displayName->setText(fi.fileName());
- displayPath->setText(QDir::toNativeSeparators(fi.path()));
- searchButton->setEnabled(true);
- }
- QString format = "";
- switch (currItem->pixm.imgInfo.type)
- {
- case 0:
- format = tr("JPG");
- break;
- case 1:
- format = tr("TIFF");
- break;
- case 2:
- format = tr("PSD");
- break;
- case 3:
- format = tr("EPS/PS");
- break;
- case 4:
- format = tr("PDF");
- break;
- case 5:
- format = tr("JPG2000");
- break;
- case 6:
- format = ext.toUpper();
- break;
- case 7:
- format = tr("emb. PSD");
- break;
- }
- displayFormat->setText(format);
- QString cSpace;
- if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (currItem->pixm.imgInfo.type != ImageType7))
- cSpace = tr("Unknown");
- else
- cSpace=colorSpaceText(currItem->pixm.imgInfo.colorspace);
- displayColorspace->setText(cSpace);
- displayDPI->setText(QString("%1 x %2").arg(currItem->pixm.imgInfo.xres).arg(currItem->pixm.imgInfo.yres));
- displayEffDPI->setText(QString("%1 x %2").arg(qRound(72.0 / currItem->imageXScale())).arg(qRound(72.0 / currItem->imageYScale())));
- displaySizePixel->setText(QString("%1 x %2").arg(currItem->OrigW).arg(currItem->OrigH));
- displayScale->setText(QString("%1 x %2 %").arg(currItem->imageXScale() * 100 / 72.0 * currItem->pixm.imgInfo.xres, 5, 'f', 1).arg(currItem->imageYScale() * 100 / 72.0 * currItem->pixm.imgInfo.yres, 5, 'f', 1));
- displayPrintSize->setText(QString("%1 x %2%3").arg(currItem->OrigW * currItem->imageXScale() * m_Doc->unitRatio(), 7, 'f', 2).arg(currItem->OrigH * currItem->imageXScale() * m_Doc->unitRatio(), 7, 'f', 2).arg(unitGetSuffixFromIndex(m_Doc->unitIndex())));
- isPrinting->setChecked(currItem->printEnabled());
- isVisibleCheck->setChecked(currItem->imageVisible());
- buttonEdit->setEnabled(currItem->isRaster);
- effectsButton->setEnabled(currItem->isRaster);
- buttonLayers->setEnabled(currItem->pixm.imgInfo.valid);
+ displayName->setText(fi.fileName());
+ displayPath->setText(QDir::toNativeSeparators(fi.path()));
+ searchButton->setEnabled(true);
+ fileManagerButton->setEnabled(true);
}
else
{
- QString trNA = tr("n/a");
- if (!currItem->Pfile.isEmpty())
- {
- QFileInfo fi = QFileInfo(currItem->Pfile);
- displayName->setText(fi.fileName());
- displayPath->setText(QDir::toNativeSeparators(fi.path()));
- searchButton->setEnabled(true);
- }
- else
- {
- displayName->setText(trNA);
- displayPath->setText(trNA);
- searchButton->setEnabled(false);
- }
- displayFormat->setText(trNA);
- displayColorspace->setText(trNA);
- displayDPI->setText(trNA);
- displayEffDPI->setText(trNA);
- displaySizePixel->setText(trNA);
- displayScale->setText(trNA);
- displayPrintSize->setText(trNA);
- buttonEdit->setEnabled(false);
- effectsButton->setEnabled(false);
- buttonLayers->setEnabled(false);
- }
- }
- else
- {
- currItem = nullptr;
- imageViewArea->clearSelection();
+ displayName->setText(trNA);
+ displayPath->setText(trNA);
+ searchButton->setEnabled(false);
+ fileManagerButton->setEnabled(false);
+ }
+ displayFormat->setText(trNA);
+ displayColorspace->setText(trNA);
+ displayDPI->setText(trNA);
+ displayEffDPI->setText(trNA);
+ displaySizePixel->setText(trNA);
+ displayScale->setText(trNA);
+ displayPrintSize->setText(trNA);
+ buttonEdit->setEnabled(false);
+ effectsButton->setEnabled(false);
+ buttonLayers->setEnabled(false);
}
}
@@ -444,33 +468,41 @@
if (lastSearchPath.isEmpty())
lastSearchPath = displayPath->text();
- PicSearchOptions *dia = new PicSearchOptions(this, displayName->text(), lastSearchPath);
- if (dia->exec())
- {
- lastSearchPath = dia->getLastDirSearched();
- if (dia->getMatches().count() == 0)
- {
- ScMessageBox::information(this, tr("Scribus - Image Search"), tr("No images named \"%1\" were found.").arg(dia->getFileName()),
- QMessageBox::Ok|QMessageBox::Default|QMessageBox::Escape,
- QMessageBox::NoButton);
- }
- else
- {
- PicSearch *dia2 = new PicSearch(this, dia->getFileName(), dia->getMatches());
- if (dia2->exec())
- {
- Q_ASSERT(!dia2->currentImage.isEmpty());
- loadPict(dia2->currentImage);
- refreshItem(currItem);
- QFileInfo fi = QFileInfo(currItem->Pfile);
- imageViewArea->currentItem()->setText(fi.fileName());
- imageViewArea->currentItem()->setIcon(createImgIcon(currItem));
- imageSelected(imageViewArea->currentItem());
- }
- delete dia2;
- }
- }
- delete dia;
+
+ QScopedPointer<PicSearchOptions> dia(new PicSearchOptions(this, displayName->text(), lastSearchPath));
+ if (dia->exec() != QDialog::Accepted)
+ return;
+
+ lastSearchPath = dia->getLastDirSearched();
+ if (dia->getMatches().count() == 0)
+ {
+ ScMessageBox::information(this, tr("Scribus - Image Search"), tr("No images named \"%1\" were found.").arg(dia->getFileName()),
+ QMessageBox::Ok|QMessageBox::Default|QMessageBox::Escape,
+ QMessageBox::NoButton);
+ return;
+ }
+
+ QScopedPointer<PicSearch> dia2(new PicSearch(this, dia->getFileName(), dia->getMatches()));
+ if (dia2->exec() != QDialog::Accepted)
+ return;
+ Q_ASSERT(!dia2->currentImage.isEmpty());
+ loadPict(dia2->currentImage);
+ refreshItem(currItem);
+ QFileInfo fi = QFileInfo(currItem->Pfile);
+ imageViewArea->currentItem()->setText(fi.fileName());
+ imageViewArea->currentItem()->setIcon(createImgIcon(currItem));
+ imageSelected(imageViewArea->currentItem());
+}
+
+void PicStatus::FileManager()
+{
+ if (currItem == nullptr)
+ return;
+ QFileInfo fi = QFileInfo(currItem->Pfile);
+ QString path = fi.canonicalPath();
+ if (path.isEmpty())
+ return;
+ QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
void PicStatus::doImageEffects()
@@ -491,10 +523,12 @@
void PicStatus::doImageExtProp()
{
- if (currItem != nullptr)
- {
- ExtImageProps dia(this, &currItem->pixm.imgInfo, currItem, m_Doc->view());
- dia.exec();
+ if (currItem == nullptr)
+ return;
+
+ ExtImageProps dia(this, &currItem->pixm.imgInfo, currItem, m_Doc->view());
+ if (dia.exec())
+ {
loadPict(currItem->Pfile);
refreshItem(currItem);
imageViewArea->currentItem()->setIcon(createImgIcon(currItem));
Modified: trunk/Scribus/scribus/ui/picstatus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22577&path=/trunk/Scribus/scribus/ui/picstatus.h
==============================================================================
--- trunk/Scribus/scribus/ui/picstatus.h (original)
+++ trunk/Scribus/scribus/ui/picstatus.h Wed Jun 6 10:27:16 2018
@@ -79,6 +79,7 @@
\brief Searches for the given Picture. Displays a Dialog when more than one Picture is found.
*/
void SearchPic();
+ void FileManager();
void doImageEffects();
void doImageExtProp();
void doEditImage();
@@ -90,6 +91,9 @@
void refreshItem(PageItem*);
protected:
+ /*! \brief Enable widgets depending on currently selected item */
+ void enableWidgets(bool enabled);
+
/*! \brief Load the image specified into the PageItem
\param newFilePath a file path */
bool loadPict(const QString & newFilePath);
Modified: trunk/Scribus/scribus/ui/picstatus.ui
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22577&path=/trunk/Scribus/scribus/ui/picstatus.ui
==============================================================================
--- trunk/Scribus/scribus/ui/picstatus.ui (original)
+++ trunk/Scribus/scribus/ui/picstatus.ui Wed Jun 6 10:27:16 2018
@@ -189,6 +189,22 @@
</property>
<property name="text">
<string>Search...</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="fileManagerButton">
+ <property name="toolTip">
+ <string>Show Image in the File Manager</string>
+ </property>
+ <property name="text">
+ <string>Show directory...</string>
</property>
<property name="autoDefault">
<bool>false</bool>
More information about the scribus-commit
mailing list