Back to index

scribus-ng  1.3.4.dfsg+svn20071115
picsearch.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "picsearch.h"
00008 #include "picsearch.moc"
00009 #include <qpixmap.h>
00010 #include <qpainter.h>
00011 #include "scribusstructs.h"
00012 #include "scimage.h"
00013 #include "commonstrings.h"
00014 #include "scpaths.h"
00015 #include "util.h"
00016 
00017 extern QPixmap loadIcon(QString nam);
00018 
00019 
00020 PicSearch::PicSearch(QWidget* parent, const QString & fileName, const QStringList & avalableFiles)
00021        : PicSearchBase( parent, "PicSearch", true, 0 ),
00022        currentImage(QString())
00023 {
00024        setIcon(loadIcon("AppIcon.png"));
00025        cancelButton->setText(CommonStrings::tr_Cancel);
00026        previewLabel->hide();
00027        fileNameLabel->setText(fileName);
00028 
00029        for (uint i = 0; i < avalableFiles.count(); ++i)
00030               foundFilesBox->insertItem( QDir::convertSeparators(avalableFiles[i]) );
00031 
00032        // signals and slots connections
00033        connect(cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00034        connect(useButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00035        connect(previewCheckBox, SIGNAL( clicked() ), this, SLOT( previewCheckBox_clicked() ) );
00036        connect(foundFilesBox, SIGNAL(clicked(QListBoxItem*)), this, SLOT(foundFilesBox_clicked(QListBoxItem*)));
00037 }
00038 
00039 void PicSearch::previewCheckBox_clicked()
00040 {
00041        if (previewCheckBox->isChecked())
00042        {
00043               previewLabel->show();
00044               if (!currentImage.isEmpty())
00045                      createPreview();
00046        }
00047        else
00048               previewLabel->hide();
00049 }
00050 
00051 void PicSearch::foundFilesBox_clicked(QListBoxItem *c)
00052 {
00053        if (c == NULL)
00054               return;
00055        currentImage = ScPaths::separatorsToSlashes(c->text());
00056        if (previewCheckBox->isChecked())
00057               createPreview();
00058        useButton->setEnabled(true);
00059 }
00060 
00061 void PicSearch::createPreview()
00062 {
00063        QPixmap pm(200, 200);
00064        QFileInfo fi = QFileInfo(currentImage);
00065        int w = 200;
00066        int h = 200;
00067        bool mode = false;
00068        QString ext = fi.extension(false).lower();
00069        if (ext.isEmpty())
00070               ext = getImageType(currentImage);
00071        ScImage im;
00072        //No doc to send data anyway, so no doc to get into scimage.
00073        CMSettings cms(0, "", 0);
00074        if (im.LoadPicture(currentImage, cms, false, false, ScImage::Thumbnail, 72, &mode))
00075        {
00076               int ix,iy;
00077               if ((im.imgInfo.exifDataValid) && (!im.imgInfo.exifInfo.thumbnail.isNull()))
00078               {
00079                      ix = im.imgInfo.exifInfo.width;
00080                      iy = im.imgInfo.exifInfo.height;
00081               }
00082               else
00083               {
00084                      ix = im.width();
00085                      iy = im.height();
00086               }
00087               int xres = im.imgInfo.xres;
00088               int yres = im.imgInfo.yres;
00089               QString tmp = "";
00090               QString tmp2 = "";
00091               QImage im2;
00092               if ((ix > w-5) || (iy > h-44))
00093               {
00094                      double sx = im.width() / static_cast<double>(w-5);
00095                      double sy = im.height() / static_cast<double>(h-44);
00096                      im2 = sy < sx ?  im.smoothScale(qRound(im.width() / sx), qRound(im.height() / sx)) :
00097                                                         im.smoothScale(qRound(im.width() / sy), qRound(im.height() / sy));
00098               }
00099               else
00100                      im2 = im.qImage(); // no need to copy
00101               QPainter p;
00102               QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
00103               p.begin(&pm);
00104               p.fillRect(0, 0, w, h-44, b);
00105               p.fillRect(0, h-44, w, 44, QColor(255, 255, 255));
00106               p.drawImage((w - im2.width()) / 2, (h - 44 - im2.height()) / 2, im2);
00107               p.drawText(2, h-29, tr("Size:")+" "+tmp.setNum(ix)+" x "+tmp2.setNum(iy));
00108               p.drawText(2, h-17, tr("Resolution:")+" "+tmp.setNum(xres)+" x "+tmp2.setNum(yres)+" "+ tr("DPI"));
00109               QString cSpace;
00110               if (((ext == "pdf") || (ext == "eps") || (ext == "epsi") || (ext == "ps")) && (im.imgInfo.type != 7))
00111                      cSpace = tr("Unknown");
00112               else
00113               {
00114                      switch (im.imgInfo.colorspace)
00115                      {
00116                             case 0:
00117                                    cSpace = tr("RGB");
00118                                    break;
00119                             case 1:
00120                                    cSpace = tr("CMYK");
00121                                    break;
00122                             case 2:
00123                                    cSpace = tr("Grayscale");
00124                                    break;
00125                             case 3:
00126                                    cSpace = tr("Duotone");
00127                                    break;
00128                      }
00129               }
00130               p.drawText(2, h-5, tr("Colorspace:")+" "+cSpace);
00131               p.end();
00132               repaint();
00133        }
00134        previewLabel->setPixmap(pm);
00135 }