Back to index

scribus-ng  1.3.4.dfsg+svn20071115
extimageprops.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 "extimageprops.h"
00008 #include "extimageprops.moc"
00009 #include <qvariant.h>
00010 #include <qpushbutton.h>
00011 #include <qtabwidget.h>
00012 #include <qwidget.h>
00013 #include <qlabel.h>
00014 #include <qcheckbox.h>
00015 #include <qspinbox.h>
00016 #include <qtable.h>
00017 #include <qlistbox.h>
00018 #include <qlayout.h>
00019 #include <qtooltip.h>
00020 #include <qwhatsthis.h>
00021 #include <qheader.h>
00022 #include <qpainter.h>
00023 
00024 #include "pageitem.h"
00025 #include "sccombobox.h"
00026 #include "scpainter.h"
00027 #include "scribusdoc.h"
00028 #include "scribusview.h"
00029 #include "util.h"
00030 
00031 ExtImageProps::ExtImageProps( QWidget* parent, ImageInfoRecord *info, PageItem *item, ScribusView *view )  : QDialog( parent, "ExtImageProps", true, 0 )
00032 {
00033        setIcon(loadIcon("AppIcon.png"));
00034        setCaption( tr( "Extended Image Properties" ) );
00035        ExtImagePropsLayout = new QVBoxLayout( this, 1, 2, "ExtImagePropsLayout");
00036        viewWidget = view;
00037        currentItem = item;
00038        currentLayer = 0;
00039        blendModes.clear();
00040        blendModes.insert("norm", tr("Normal"));
00041        blendModes.insert("dark", tr("Darken"));
00042        blendModes.insert("lite", tr("Lighten"));
00043        blendModes.insert("hue ", tr("Hue"));
00044        blendModes.insert("sat ", tr("Saturation"));
00045        blendModes.insert("colr", tr("Color"));
00046        blendModes.insert("lum ", tr("Luminosity"));
00047        blendModes.insert("mul ", tr("Multiply"));
00048        blendModes.insert("scrn", tr("Screen"));
00049        blendModes.insert("diss", tr("Dissolve"));
00050        blendModes.insert("over", tr("Overlay"));
00051        blendModes.insert("hLit", tr("Hard Light"));
00052        blendModes.insert("sLit", tr("Soft Light"));
00053        blendModes.insert("diff", tr("Difference"));
00054        blendModes.insert("smud", tr("Exclusion"));
00055        blendModes.insert("div ", tr("Color Dodge"));
00056        blendModes.insert("idiv", tr("Color Burn"));
00057        blendModesRev.clear();
00058        blendModesRev.insert( tr("Normal"), "norm");
00059        blendModesRev.insert( tr("Darken"), "dark");
00060        blendModesRev.insert( tr("Lighten"), "lite");
00061        blendModesRev.insert( tr("Hue"), "hue ");
00062        blendModesRev.insert( tr("Saturation"), "sat ");
00063        blendModesRev.insert( tr("Color"), "colr");
00064        blendModesRev.insert( tr("Luminosity"), "lum ");
00065        blendModesRev.insert( tr("Multiply"), "mul ");
00066        blendModesRev.insert( tr("Screen"), "scrn");
00067        blendModesRev.insert( tr("Dissolve"), "diss");
00068        blendModesRev.insert( tr("Overlay"), "over");
00069        blendModesRev.insert( tr("Hard Light"), "hLit");
00070        blendModesRev.insert( tr("Soft Light"), "sLit");
00071        blendModesRev.insert( tr("Difference"), "diff");
00072        blendModesRev.insert( tr("Exclusion"), "smud");
00073        blendModesRev.insert( tr("Color Dodge"), "div ");
00074        blendModesRev.insert( tr("Color Burn"), "idiv");
00075        propsTab = new QTabWidget( this, "propsTab" );
00076 
00077        if (info->layerInfo.count() != 0)
00078        {
00079               tab = new QWidget( propsTab, "tab" );
00080               tabLayout = new QVBoxLayout( tab, 4, 4, "tabLayout");
00081               layout1 = new QHBoxLayout( 0, 0, 4, "layout1");
00082               textLabel1 = new QLabel( tab, "textLabel1" );
00083               textLabel1->setText( tr( "Blend Mode:" ) );
00084               layout1->addWidget( textLabel1 );
00085               blendMode = new ScComboBox( false, tab, "blendMode" );
00086               blendMode->clear();
00087               blendMode->insertItem( tr("Normal"));
00088               blendMode->insertItem( tr("Darken"));
00089               blendMode->insertItem( tr("Lighten"));
00090               blendMode->insertItem( tr("Hue"));
00091               blendMode->insertItem( tr("Saturation"));
00092               blendMode->insertItem( tr("Color"));
00093               blendMode->insertItem( tr("Luminosity"));
00094               blendMode->insertItem( tr("Multiply"));
00095               blendMode->insertItem( tr("Screen"));
00096               blendMode->insertItem( tr("Dissolve"));
00097               blendMode->insertItem( tr("Overlay"));
00098               blendMode->insertItem( tr("Hard Light"));
00099               blendMode->insertItem( tr("Soft Light"));
00100               blendMode->insertItem( tr("Difference"));
00101               blendMode->insertItem( tr("Exclusion"));
00102               blendMode->insertItem( tr("Color Dodge"));
00103               blendMode->insertItem( tr("Color Burn"));
00104               layout1->addWidget( blendMode );
00105               textLabel2 = new QLabel( tab, "textLabel2" );
00106               textLabel2->setText( tr( "Opacity:" ) );
00107               layout1->addWidget( textLabel2 );
00108               opacitySpinBox = new QSpinBox( tab, "opacitySpinBox" );
00109               opacitySpinBox->setMinValue(0);
00110               opacitySpinBox->setMaxValue(100);
00111               opacitySpinBox->setLineStep(10);
00112               opacitySpinBox->setSuffix( tr(" %"));
00113               layout1->addWidget( opacitySpinBox );
00114               tabLayout->addLayout( layout1 );
00115               layerTable = new QTable( tab, "layerTable" );
00116               layerTable->setNumRows( 0 );
00117               layerTable->setNumCols( 3 );
00118               QHeader *header = layerTable->horizontalHeader();
00119               header->setLabel(0, loadIcon("16/show-object.png"), "");
00120               header->setLabel(1, "");
00121               header->setLabel(2, tr("Name"));
00122               layerTable->setColumnReadOnly(0, true);
00123               layerTable->setColumnReadOnly(1, true);
00124               layerTable->setColumnReadOnly(2, true);
00125               if (info->layerInfo.count() == 1)
00126               {
00127                      layerTable->setColumnWidth(1, 40);
00128                      layerTable->setColumnWidth(0, 24);
00129               }
00130               layerTable->setColumnStretchable(2, true);
00131               layerTable->setRowMovingEnabled(false);
00132               layerTable->setSorting(false);
00133               layerTable->setSelectionMode( QTable::SingleRow );
00134               layerTable->setFocusStyle( QTable::FollowStyle );
00135               QHeader *Header = layerTable->verticalHeader();
00136               Header->setMovingEnabled(false);
00137               Header->setResizeEnabled(false);
00138               layerTable->setLeftMargin(0);
00139               Header->hide();
00140               FlagsSicht.clear();
00141               if (info->layerInfo.count() != 0)
00142               {
00143                      if ((info->isRequest) && (info->RequestProps.contains(0)))
00144                      {
00145                             opacitySpinBox->setValue(qRound(info->RequestProps[0].opacity / 255.0 * 100));
00146                             blendMode->setCurrentText(blendModes[info->RequestProps[0].blend]);
00147                      }
00148                      else
00149                      {
00150                             opacitySpinBox->setValue(qRound(info->layerInfo[0].opacity / 255.0 * 100));
00151                             blendMode->setCurrentText(blendModes[info->layerInfo[0].blend]);
00152                      }
00153                      opacitySpinBox->setEnabled(true);
00154                      blendMode->setEnabled(true);
00155                      QString tmp;
00156                      QValueList<PSDLayer>::iterator it2;
00157                      layerTable->setNumRows(info->layerInfo.count());
00158                      uint counter = 0;
00159                      for (it2 = info->layerInfo.begin(); it2 != info->layerInfo.end(); ++it2)
00160                      {
00161                             QCheckBox *cp = new QCheckBox(this, (*it2).layerName);
00162                             cp->setPaletteBackgroundColor(white);
00163                             if ((info->isRequest) && (info->RequestProps.contains(counter)))
00164                                    cp->setChecked(info->RequestProps[counter].visible);
00165                             else
00166                                    cp->setChecked(!((*it2).flags & 2));
00167                             QPixmap pm;
00168                             pm.convertFromImage((*it2).thumb);
00169                             cp->setPixmap(pm);
00170                             FlagsSicht.append(cp);
00171                             connect(cp, SIGNAL(clicked()), this, SLOT(changedLayer()));
00172                             layerTable->setCellWidget(info->layerInfo.count()-counter-1, 0, cp);
00173                             if (!(*it2).thumb_mask.isNull())
00174                             {
00175                                    QCheckBox *cp2 = new QCheckBox(this, (*it2).layerName);
00176                                    cp2->setPaletteBackgroundColor(white);
00177                                    if ((info->isRequest) && (info->RequestProps.contains(counter)))
00178                                           cp2->setChecked(info->RequestProps[counter].useMask);
00179                                    else
00180                                           cp2->setChecked(true);
00181                                    QPixmap pm2;
00182                                    pm2.convertFromImage((*it2).thumb_mask);
00183                                    cp2->setPixmap(pm2);
00184                                    connect(cp2, SIGNAL(clicked()), this, SLOT(changedLayer()));
00185                                    layerTable->setCellWidget(info->layerInfo.count()-counter-1, 1, cp2);
00186                                    FlagsMask.append(cp2);
00187                             }
00188                             else
00189                                    FlagsMask.append(0);
00190                             layerTable->setText(info->layerInfo.count()-counter-1, 2, (*it2).layerName);
00191                             Header->setLabel(info->layerInfo.count()-counter-1, tmp.setNum(counter+1));
00192                             layerTable->setRowHeight(info->layerInfo.count()-counter-1, 40);
00193                             counter++;
00194                      }
00195                      layerTable->adjustColumn(0);
00196                      layerTable->adjustColumn(1);
00197               }
00198               tabLayout->addWidget( layerTable );
00199               blendMode->setCurrentItem(0);
00200               propsTab->insertTab( tab,  tr( "Layers" ) );
00201        }
00202        tab_2 = new QWidget( propsTab, "tab_2" );
00203        tabLayout_2 = new QVBoxLayout( tab_2, 4, 4, "tabLayout_2");
00204        pathList = new QListBox( tab_2, "pathList" );
00205        pathList->clear();
00206        QMap<QString, FPointArray>::Iterator it;
00207        if (info->PDSpathData.count() != 0)
00208        {
00209               for (it = info->PDSpathData.begin(); it != info->PDSpathData.end(); ++it)
00210               {
00211                      QPixmap pixm(40, 40);
00212                      ScPainter *p = new ScPainter(&pixm, 40, 40);
00213                      p->clear();
00214                      p->translate(3.0, 3.0);
00215                      if (it.key() == info->clipPath)
00216                      {
00217                             pixm.fill(green);
00218                             p->clear(green);
00219                      }
00220                      else
00221                             pixm.fill(white);
00222                      FPointArray Path;
00223                      Path.resize(0);
00224                      Path = info->PDSpathData[it.key()].copy();
00225                      FPoint min = getMinClipF(&Path);
00226                      Path.translate(-min.x(), -min.y());
00227                      FPoint max = Path.WidthHeight();
00228                      QWMatrix mm;
00229                      mm.scale(34.0 / QMAX(max.x(), max.y()), 34.0 / QMAX(max.x(), max.y()));
00230                      Path.map(mm);
00231                      p->setupPolygon(&Path);
00232                      p->setPen(black);
00233                      p->setBrush(white);
00234                      p->setFillMode(0);
00235                      p->setLineWidth(1.0);
00236                      p->strokePath();
00237                      p->end();
00238                      delete p;
00239                      pathList->insertItem(pixm, it.key());
00240                      if (it.key() == info->usedPath)
00241                             pathList->setSelected(pathList->count()-1, true);
00242               }
00243        }
00244        tabLayout_2->addWidget( pathList );
00245        resetPath = new QPushButton( tr("Don't use any Path"), tab_2, "reset");
00246        tabLayout_2->addWidget( resetPath );
00247        propsTab->insertTab( tab_2, tr( "Paths" ) );
00248        ExtImagePropsLayout->addWidget( propsTab );
00249        resize(330, 320);
00250        clearWState( WState_Polished );
00251        connect(pathList, SIGNAL( highlighted(QListBoxItem*) ), this, SLOT( selPath(QListBoxItem*) ) );
00252        connect(resetPath, SIGNAL(clicked()), this, SLOT(noPath()));
00253        if (info->layerInfo.count() != 0)
00254        {
00255               connect(layerTable, SIGNAL(currentChanged(int, int)), this, SLOT(selLayer(int)));
00256               connect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changedLayer()));
00257               connect(blendMode, SIGNAL(activated(int)), this, SLOT(changedLayer()));
00258        }
00259 }
00260 
00261 void ExtImageProps::changedLayer()
00262 {
00263        struct ImageLoadRequest loadingInfo;
00264        currentItem->pixm.imgInfo.isRequest = true;
00265        for (int r = 0; r < layerTable->numRows(); ++r)
00266        {
00267               if (currentLayer == layerTable->numRows() - r - 1)
00268               {
00269                      loadingInfo.blend = blendModesRev[blendMode->currentText()];
00270                      loadingInfo.opacity = qRound(opacitySpinBox->value() / 100.0 * 255);
00271               }
00272 /*            else if (currentItem->pixm.imgInfo.RequestProps.contains(layerTable->numRows() - r - 1))
00273               {
00274                      loadingInfo.blend = currentItem->pixm.imgInfo.RequestProps[layerTable->numRows() - r - 1].blend;
00275                      loadingInfo.opacity = currentItem->pixm.imgInfo.RequestProps[layerTable->numRows() - r - 1].opacity;
00276               } */
00277               else
00278               {
00279                      loadingInfo.blend = currentItem->pixm.imgInfo.layerInfo[layerTable->numRows() - r - 1].blend;
00280                      loadingInfo.opacity = currentItem->pixm.imgInfo.layerInfo[layerTable->numRows() - r - 1].opacity;
00281               }
00282               loadingInfo.visible = FlagsSicht.at(layerTable->numRows() - r - 1)->isChecked();
00283               if (FlagsMask.at(layerTable->numRows() - r - 1))
00284                      loadingInfo.useMask = FlagsMask.at(layerTable->numRows() - r - 1)->isChecked();
00285               else
00286                      loadingInfo.useMask = true;
00287               currentItem->pixm.imgInfo.RequestProps.insert(layerTable->numRows() - r - 1, loadingInfo);
00288        }
00289        viewWidget->Doc->LoadPict(currentItem->Pfile, currentItem->ItemNr, true);
00290        viewWidget->updateContents();
00291 }
00292 
00293 void ExtImageProps::selLayer(int layer)
00294 {
00295        disconnect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changedLayer()));
00296        disconnect(blendMode, SIGNAL(activated(int)), this, SLOT(changedLayer()));
00297        if ((currentItem->pixm.imgInfo.isRequest) && (currentItem->pixm.imgInfo.RequestProps.contains(layerTable->numRows() - layer - 1)))
00298        {
00299               opacitySpinBox->setValue(qRound(currentItem->pixm.imgInfo.RequestProps[layerTable->numRows() - layer - 1].opacity / 255.0 * 100));
00300               blendMode->setCurrentText(blendModes[currentItem->pixm.imgInfo.RequestProps[layerTable->numRows() - layer - 1].blend]);
00301        }
00302        else
00303        {
00304               opacitySpinBox->setValue(qRound(currentItem->pixm.imgInfo.layerInfo[layerTable->numRows() - layer - 1].opacity / 255.0 * 100));
00305               blendMode->setCurrentText(blendModes[currentItem->pixm.imgInfo.layerInfo[layerTable->numRows() - layer - 1].blend]);
00306        }
00307        opacitySpinBox->setEnabled(true);
00308        blendMode->setEnabled(true);
00309        currentLayer = layerTable->numRows() - layer - 1;
00310        connect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changedLayer()));
00311        connect(blendMode, SIGNAL(activated(int)), this, SLOT(changedLayer()));
00312 }
00313 
00314 void ExtImageProps::noPath()
00315 {
00316        disconnect(pathList, SIGNAL( highlighted(QListBoxItem*) ), this, SLOT( selPath(QListBoxItem*) ) );
00317        currentItem->imageClip.resize(0);
00318        currentItem->pixm.imgInfo.usedPath = "";
00319        pathList->clearSelection();
00320        viewWidget->updateContents();
00321        connect(pathList, SIGNAL( highlighted(QListBoxItem*) ), this, SLOT( selPath(QListBoxItem*) ) );
00322 }
00323 
00324 void ExtImageProps::selPath(QListBoxItem *c)
00325 {
00326        currentItem->imageClip = currentItem->pixm.imgInfo.PDSpathData[c->text()].copy();
00327        currentItem->pixm.imgInfo.usedPath = c->text();
00328        QWMatrix cl;
00329        cl.translate(currentItem->imageXOffset()*currentItem->imageXScale(), currentItem->imageYOffset()*currentItem->imageYScale());
00330        cl.scale(currentItem->imageXScale(), currentItem->imageYScale());
00331        currentItem->imageClip.map(cl);
00332        viewWidget->updateContents();
00333 }
00334