diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
| commit | 7ed83b6c6666eb8b6b104c211ae7e52907350372 (patch) | |
| tree | 4430b556abac0ad660a0aacf1887d77f85d8be02 /scribus/picsearch.cpp | |
| download | scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.gz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.xz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.zip | |
Branch 1.3.5 tree to 1.4.x tree, goodbye 1.3.x
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17163 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/picsearch.cpp')
| -rw-r--r-- | scribus/picsearch.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/scribus/picsearch.cpp b/scribus/picsearch.cpp new file mode 100644 index 0000000..18c6d4c --- /dev/null +++ b/scribus/picsearch.cpp @@ -0,0 +1,120 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "picsearch.h" +#include <QPixmap> +#include <QPainter> + +#include "cmsettings.h" +#include "commonstrings.h" +#include "scimage.h" +#include "scpaths.h" +#include "scribusstructs.h" +#include "util.h" +#include "util_color.h" +#include "util_formats.h" +#include "util_icon.h" + + +PicSearch::PicSearch(QWidget* parent, const QString & fileName, const QStringList & avalableFiles) : QDialog(parent), currentImage(QString()) +{ + setupUi(this); + setModal(true); + cancelButton->setText(CommonStrings::tr_Cancel); + previewLabel->hide(); + fileNameLabel->setText(fileName); + + for (int i = 0; i < avalableFiles.count(); ++i) + foundFilesBox->addItem( QDir::toNativeSeparators(avalableFiles[i]) ); + + // 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(foundFilesBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(foundFilesBox_clicked(QListWidgetItem*))); +} + +void PicSearch::previewCheckBox_clicked() +{ + if (previewCheckBox->isChecked()) + { + previewLabel->show(); + if (!currentImage.isEmpty()) + createPreview(); + } + else + previewLabel->hide(); +} + +void PicSearch::foundFilesBox_clicked(QListWidgetItem *c) +{ + if (c == NULL) + return; + currentImage = QDir::fromNativeSeparators(c->text()); + if (previewCheckBox->isChecked()) + createPreview(); + useButton->setEnabled(true); +} + +void PicSearch::createPreview() +{ + QPixmap pm(200, 200); + QFileInfo fi = QFileInfo(currentImage); + int w = 200; + int h = 200; + bool mode = false; + QString ext = fi.suffix().toLower(); + if (ext.isEmpty()) + ext = getImageType(currentImage); + ScImage im; + //No doc to send data anyway, so no doc to get into scimage. + CMSettings cms(0, "", Intent_Perceptual); + if (im.LoadPicture(currentImage, 1, cms, false, false, ScImage::Thumbnail, 72, &mode)) + { + int ix,iy; + if ((im.imgInfo.exifDataValid) && (!im.imgInfo.exifInfo.thumbnail.isNull())) + { + ix = im.imgInfo.exifInfo.width; + iy = im.imgInfo.exifInfo.height; + } + else + { + ix = im.width(); + iy = im.height(); + } + int xres = im.imgInfo.xres; + int yres = im.imgInfo.yres; + QString tmp = ""; + QString tmp2 = ""; + QImage im2; + if ((ix > w-5) || (iy > h-44)) + { + double sx = im.width() / static_cast<double>(w-5); + double sy = im.height() / static_cast<double>(h-44); + im2 = sy < sx ? im.scaled(qRound(im.width() / sx), qRound(im.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) + : im.scaled(qRound(im.width() / sy), qRound(im.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } + else + im2 = im.qImage(); // no need to copy + QPainter p; + QBrush b(QColor(205,205,205), loadIcon("testfill.png")); + p.begin(&pm); + p.fillRect(0, 0, w, h-44, b); + p.fillRect(0, h-44, w, 44, QColor(255, 255, 255)); + p.drawImage((w - im2.width()) / 2, (h - 44 - im2.height()) / 2, im2); + p.drawText(2, h-29, tr("Size:")+" "+tmp.setNum(ix)+" x "+tmp2.setNum(iy)); + p.drawText(2, h-17, tr("Resolution:")+" "+tmp.setNum(xres)+" x "+tmp2.setNum(yres)+" "+ tr("DPI")); + QString cSpace; + if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (im.imgInfo.type != ImageType7)) + cSpace = tr("Unknown"); + else + cSpace=colorSpaceText(im.imgInfo.colorspace); + p.drawText(2, h-5, tr("Colorspace:")+" "+cSpace); + p.end(); + repaint(); + } + previewLabel->setPixmap(pm); +} |
