Back to index

scribus-ng  1.3.4.dfsg+svn20071115
picstatus.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 /***************************************************************************
00008                           picstatus.cpp  -  description
00009                              -------------------
00010     begin                : Fri Nov 29 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 #include <qtable.h>
00024 #include <qfileinfo.h>
00025 #include <qmessagebox.h>
00026 #include <qtoolbutton.h>
00027 #include <qstringlist.h>
00028 #include <qtextstream.h>
00029 #include <qtooltip.h>
00030 #include <qcursor.h>
00031 #include <qpainter.h>
00032 #include <cstdio>
00033 
00034 #include "picstatus.h"
00035 #include "picstatus.moc"
00036 #include "picsearch.h"
00037 #include "picsearchoptions.h"
00038 #include "scribusdoc.h"
00039 #include "pageitem.h"
00040 #include "filesearch.h"
00041 #include "scribuscore.h"
00042 #include "commonstrings.h"
00043 #include "effectsdialog.h"
00044 #include "extimageprops.h"
00045 
00046 extern QPixmap loadIcon(QString nam);
00047 
00048 PicItem::PicItem(QIconView* parent, QString text, QPixmap pix, PageItem* pgItem) : QIconViewItem(parent, text, pix)
00049 {
00050        PageItemObject = pgItem;
00051 }
00052 
00053 PicStatus::PicStatus(QWidget* parent, ScribusDoc *docu) : PicStatusBase( parent, "PicStatus", true, 0 )
00054 {
00055        m_Doc = docu;
00056        currItem = NULL;
00057        setIcon(loadIcon("AppIcon.png"));
00058        fillTable();
00059        connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
00060        connect(imageViewArea, SIGNAL(currentChanged(QIconViewItem *)), this, SLOT(imageSelected(QIconViewItem *)));
00061        connect(imageViewArea, SIGNAL(clicked(QIconViewItem*)), this, SLOT(imageSelected(QIconViewItem*)));
00062        connect(isPrinting, SIGNAL(clicked()), this, SLOT(PrintPic()));
00063        connect(isVisible, SIGNAL(clicked()), this, SLOT(visiblePic()));
00064        connect(goPageButton, SIGNAL(clicked()), this, SLOT(GotoPic()));
00065        connect(selectButton, SIGNAL(clicked()), this, SLOT(SelectPic()));
00066        connect(searchButton, SIGNAL(clicked()), this, SLOT(SearchPic()));
00067        connect(effectsButton, SIGNAL(clicked()), this, SLOT(doImageEffects()));
00068        connect(buttonLayers, SIGNAL(clicked()), this, SLOT(doImageExtProp()));
00069        connect(buttonEdit, SIGNAL(clicked()), this, SLOT(doEditImage()));
00070 }
00071 
00072 QPixmap PicStatus::createImgIcon(PageItem* item)
00073 {
00074        QPainter p;
00075        QPixmap pm(128, 128);
00076        QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
00077        p.begin(&pm);
00078        p.fillRect(0, 0, 128, 128, imageViewArea->paletteBackgroundColor());
00079        p.setPen(QPen(black, 1, SolidLine, FlatCap, MiterJoin));
00080        p.setBrush(paletteBackgroundColor());
00081        p.drawRoundRect(0, 0, 128, 128, 10, 10);
00082        p.setPen(Qt::NoPen);
00083        p.setBrush(b);
00084        p.drawRect(12, 12, 104, 104);
00085        if (item->PicAvail)
00086        {
00087               QImage im2 = item->pixm.smoothScale(104, 104, QImage::ScaleMin);
00088               p.drawImage((104 - im2.width()) / 2 + 12, (104 - im2.height()) / 2 + 12, im2);
00089        }
00090        else
00091        {
00092               p.setBrush(Qt::NoBrush);
00093               p.setPen(QPen(red, 2, SolidLine, FlatCap, MiterJoin));
00094               p.drawLine(12, 12, 116, 116);
00095               p.drawLine(12, 116, 116, 12);
00096        }
00097        p.setPen(QPen(black, 1, SolidLine, FlatCap, MiterJoin));
00098        p.setBrush(Qt::NoBrush);
00099        p.drawRect(12, 12, 104, 104);
00100        p.end();
00101        return pm;
00102 }
00103 
00104 void PicStatus::fillTable()
00105 {
00106        PageItem *item;
00107        QPixmap pm(128, 128);
00108        QPainter p;
00109        imageViewArea->clear();
00110        for (item = m_Doc->MasterItems.first(); item; item = m_Doc->MasterItems.next())
00111        {
00112               QFileInfo fi = QFileInfo(item->Pfile);
00113               if (item->itemType() == PageItem::ImageFrame)
00114               {
00115                      PicItem *ite =  new PicItem(imageViewArea, fi.fileName(), createImgIcon(item), item);
00116                      ite->setDragEnabled(false);
00117               }
00118        }
00119        for (item = m_Doc->Items->first(); item; item = m_Doc->Items->next())
00120        {
00121               QFileInfo fi = QFileInfo(item->Pfile);
00122               if (item->itemType() == PageItem::ImageFrame)
00123               {
00124                      PicItem *ite =  new PicItem(imageViewArea, fi.fileName(), createImgIcon(item), item);
00125                      ite->setDragEnabled(false);
00126               }
00127        }
00128 }
00129 
00130 void PicStatus::imageSelected(QIconViewItem *ite)
00131 {
00132        if (ite != NULL)
00133        {
00134               PicItem *item = (PicItem*)ite;
00135               currItem = item->PageItemObject;
00136               if (!currItem->OnMasterPage.isEmpty())
00137                      displayPage->setText(currItem->OnMasterPage);
00138               else
00139               {
00140                      if (currItem->OwnPage == -1)
00141                             displayPage->setText(  tr("Not on a Page"));
00142                      else
00143                             displayPage->setText(QString::number(currItem->OwnPage + 1));
00144               }
00145               displayObjekt->setText(currItem->itemName());
00146               if (currItem->PicAvail)
00147               {
00148                      QFileInfo fi = QFileInfo(currItem->Pfile);
00149                      QString ext = fi.extension(false).lower();
00150                      displayName->setText(fi.fileName());
00151                      displayPath->setText(QDir::convertSeparators(fi.dirPath()));
00152                      QString format = "";
00153                      switch (currItem->pixm.imgInfo.type)
00154                      {
00155                             case 0:
00156                                    format = tr("JPG");
00157                                    break;
00158                             case 1:
00159                                    format = tr("TIFF");
00160                                    break;
00161                             case 2:
00162                                    format = tr("PSD");
00163                                    break;
00164                             case 3:
00165                                    format = tr("EPS/PS");
00166                                    break;
00167                             case 4:
00168                                    format = tr("PDF");
00169                                    break;
00170                             case 5:
00171                                    format = tr("JPG2000");
00172                                    break;
00173                             case 6:
00174                                    format = ext.upper();
00175                                    break;
00176                             case 7:
00177                                    format = tr("emb. PSD");
00178                                    break;
00179                      }
00180                      displayFormat->setText(format);
00181                      QString cSpace;
00182                      if (((ext == "pdf") || (ext == "eps") || (ext == "epsi") || (ext == "ps")) && (currItem->pixm.imgInfo.type != 7))
00183                             cSpace = tr("Unknown");
00184                      else
00185                      {
00186                             switch (currItem->pixm.imgInfo.colorspace)
00187                             {
00188                                    case 0:
00189                                           cSpace = tr("RGB");
00190                                           break;
00191                                    case 1:
00192                                           cSpace = tr("CMYK");
00193                                           break;
00194                                    case 2:
00195                                           cSpace = tr("Grayscale");
00196                                           break;
00197                                    case 3:
00198                                           cSpace = tr("Duotone");
00199                                           break;
00200                             }
00201                      }
00202                      displayColorspace->setText(cSpace);
00203                      displayDPI->setText(QString("%1 x %2").arg(qRound(currItem->pixm.imgInfo.xres)).arg(qRound(currItem->pixm.imgInfo.yres)));
00204                      displayEffDPI->setText(QString("%1 x %2").arg(qRound(72.0 / currItem->imageXScale())).arg(qRound(72.0 / currItem->imageYScale())));
00205                      displaySizePixel->setText(QString("%1 x %2").arg(currItem->OrigW).arg(currItem->OrigH));
00206                      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));
00207                      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())));
00208                      isPrinting->setChecked(currItem->printEnabled());
00209                      isVisible->setChecked(currItem->imageShown());
00210                      buttonEdit->setEnabled(true);
00211                      effectsButton->setEnabled(true);
00212                      buttonLayers->setEnabled(true);
00213               }
00214               else
00215               {
00216                      if (!currItem->Pfile.isEmpty())
00217                      {
00218                             QFileInfo fi = QFileInfo(currItem->Pfile);
00219                             displayName->setText(fi.fileName());
00220                             displayPath->setText(QDir::convertSeparators(fi.dirPath()));
00221                      }
00222                      else
00223                      {
00224                             displayName->setText( tr("n/a"));
00225                             displayPath->setText( tr("n/a"));
00226                      }
00227                      displayFormat->setText( tr("n/a"));
00228                      displayColorspace->setText( tr("n/a"));
00229                      displayDPI->setText( tr("n/a"));
00230                      displayEffDPI->setText( tr("n/a"));
00231                      displaySizePixel->setText( tr("n/a"));
00232                      displayScale->setText( tr("n/a"));
00233                      displayPrintSize->setText( tr("n/a"));
00234                      buttonEdit->setEnabled(false);
00235                      effectsButton->setEnabled(false);
00236                      buttonLayers->setEnabled(false);
00237               }
00238        }
00239        else
00240        {
00241               currItem = NULL;
00242               imageViewArea->clearSelection();
00243        }
00244 }
00245 
00246 void PicStatus::PrintPic()
00247 {
00248        if (currItem != NULL)
00249               currItem->setPrintEnabled(isPrinting->isChecked());
00250 }
00251 
00252 void PicStatus::visiblePic()
00253 {
00254        if (currItem != NULL)
00255        {
00256               currItem->setImageShown(isVisible->isChecked());
00257               emit refreshItem(currItem);
00258        }
00259 }
00260 
00261 void PicStatus::GotoPic()
00262 {
00263        if (currItem != NULL)
00264        {
00265               ScCore->primaryMainWindow()->closeActiveWindowMasterPageEditor();
00266               if (!currItem->OnMasterPage.isEmpty())
00267                      emit selectMasterPage(currItem->OnMasterPage);
00268               else
00269                      emit selectPage(currItem->OwnPage);
00270        }
00271 }
00272 
00273 void PicStatus::SelectPic()
00274 {
00275        if (currItem != NULL)
00276        {
00277               ScCore->primaryMainWindow()->closeActiveWindowMasterPageEditor();
00278               if (currItem->Groups.count() == 0)
00279                      emit selectElement(currItem->OwnPage, currItem->ItemNr, false);
00280               else
00281               {
00282                      if (currItem->isGroupControl)
00283                             emit selectElement(currItem->OwnPage, currItem->ItemNr, false);
00284                      else
00285                             emit selectElement(currItem->OwnPage, currItem->ItemNr, true);
00286               }
00287        }
00288 }
00289 
00290 bool PicStatus::loadPict(const QString & newFilePath)
00291 {
00292        // Hack to fool the LoadPict function
00293        currItem->Pfile = newFilePath;
00294        m_Doc->LoadPict(newFilePath, currItem->ItemNr, true);
00295        return currItem->PicAvail;
00296 }
00297 
00298 void PicStatus::SearchPic()
00299 {
00300        PicSearchOptions *dia = new PicSearchOptions(this, displayName->text(), displayPath->text());
00301        if (dia->exec())
00302        {
00303               if (dia->m_matches.count() == 0)
00304               {
00305                      QMessageBox::information(this, tr("Scribus - Image Search"), tr("No images named \"%1\" were found.").arg(dia->m_fileName),
00306                                    QMessageBox::Ok|QMessageBox::Default|QMessageBox::Escape,
00307                                    QMessageBox::NoButton);
00308               }
00309               else
00310               {
00311                      PicSearch *dia2 = new PicSearch(this, dia->m_fileName, dia->m_matches);
00312                      if (dia2->exec())
00313                      {
00314                             Q_ASSERT(!dia2->currentImage.isEmpty());
00315                             loadPict(dia2->currentImage);
00316                             refreshItem(currItem);
00317                             QFileInfo fi = QFileInfo(currItem->Pfile);
00318                             imageViewArea->currentItem()->setText(fi.fileName());
00319                             imageViewArea->currentItem()->setPixmap(createImgIcon(currItem));
00320                             imageSelected(imageViewArea->currentItem());
00321                      }
00322                      delete dia2;
00323               }
00324        }
00325        delete dia;
00326 }
00327 
00328 void PicStatus::doImageEffects()
00329 {
00330        if (currItem != NULL)
00331        {
00332               EffectsDialog* dia = new EffectsDialog(this, currItem, m_Doc);
00333               if (dia->exec())
00334               {
00335                      currItem->effectsInUse = dia->effectsList;
00336                      loadPict(currItem->Pfile);
00337                      refreshItem(currItem);
00338                      imageViewArea->currentItem()->setPixmap(createImgIcon(currItem));
00339               }
00340               delete dia;
00341        }
00342 }
00343 
00344 void PicStatus::doImageExtProp()
00345 {
00346        if (currItem != NULL)
00347        {
00348               ExtImageProps* dia = new ExtImageProps(this, &currItem->pixm.imgInfo, currItem, m_Doc->view());
00349               dia->exec();
00350               loadPict(currItem->Pfile);
00351               refreshItem(currItem);
00352               imageViewArea->currentItem()->setPixmap(createImgIcon(currItem));
00353               delete dia;
00354        }
00355 }
00356 
00357 void PicStatus::doEditImage()
00358 {
00359        if (currItem != NULL)
00360        {
00361               SelectPic();
00362               ScCore->primaryMainWindow()->callImageEditor();
00363        }
00364 }