Back to index

scribus-ng  1.3.4.dfsg+svn20071115
colorm.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 "colorm.h"
00008 #include "colorm.moc"
00009 #include <qmessagebox.h>
00010 #include <qpixmap.h>
00011 #include <qbitmap.h>
00012 #include <qdom.h>
00013 #include <cstdlib>
00014 
00015 #include "scconfig.h"
00016 #include "commonstrings.h"
00017 #include "customfdialog.h"
00018 #include "dcolor.h"
00019 #include "fileloader.h"
00020 #include "cmykfw.h"
00021 #include "scribusdoc.h"
00022 #include "prefsmanager.h"
00023 #include "prefsfile.h"
00024 #include "scpaths.h"
00025 #include "colorlistbox.h"
00026 
00027 #include "util.h"
00028 #include "dynamictip.h"
00029 #include "sccolorengine.h"
00030 
00031 ColorManager::ColorManager(QWidget* parent, ColorList doco, ScribusDoc* doc, QString docColSet, QStringList custColSet)
00032               : QDialog( parent, "ColorManager", true, 0 ), EditColors(doc, true), UsedC(doc, true)
00033 {
00034        setName( "ColorManager" );
00035        m_Doc=doc;
00036        customColSet = custColSet;
00037        setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, sizePolicy().hasHeightForWidth() ) );
00038        setSizeGripEnabled(true);
00039        setCaption( tr( "Colors" ) );
00040        setIcon(loadIcon("AppIcon.png"));
00041        Layout2 = new QVBoxLayout( this );
00042        Layout2->setSpacing( 6 );
00043        Layout2->setMargin( 11 );
00044 
00045        layout5 = new QHBoxLayout( 0, 0, 6, "layout5");
00046        layout3 = new QVBoxLayout( 0, 0, 6, "layout3");
00047        colorListBox = new ColorListBox( this, "colorListBox" );
00048        colorListBox->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, colorListBox->sizePolicy().hasHeightForWidth() ) );
00049        colorListBox->setMinimumSize( QSize( 164, 228 ) );
00050        colorListBox->setColumnMode( QListBox::FixedNumber );
00051        layout5->addWidget( colorListBox );
00052 
00053        ColorsGroup = new QGroupBox( this, "ColorsGroup" );
00054        ColorsGroup->setColumnLayout(0, Qt::Vertical );
00055        ColorsGroup->layout()->setSpacing( 6 );
00056        ColorsGroup->layout()->setMargin( 11 );
00057        Layout1 = new QVBoxLayout( ColorsGroup->layout() );
00058        Layout1->setAlignment( Qt::AlignTop );
00059        importColorsButton = new QPushButton( tr( "&Import" ), ColorsGroup, "importColorsButton" );
00060        Layout1->addWidget( importColorsButton );
00061        newColorButton = new QPushButton( tr( "&New" ), ColorsGroup, "newColorButton" );
00062        Layout1->addWidget( newColorButton );
00063        editColorButton = new QPushButton( tr( "&Edit" ), ColorsGroup, "editColorButton" );
00064        editColorButton->setEnabled( false );
00065        editColorButton->setDefault( true );
00066        Layout1->addWidget( editColorButton );
00067        duplicateColorButton = new QPushButton( tr( "D&uplicate" ), ColorsGroup, "duplicateColorButton" );
00068        duplicateColorButton->setEnabled( false );
00069        Layout1->addWidget( duplicateColorButton );
00070        deleteColorButton = new QPushButton( tr( "&Delete" ), ColorsGroup, "deleteColorButton" );
00071        deleteColorButton->setEnabled( false );
00072        Layout1->addWidget( deleteColorButton );
00073        if (m_Doc!=0)
00074        {
00075               deleteUnusedButton = new QPushButton( tr( "&Remove Unused" ), ColorsGroup, "deleteUnusedButton" );
00076               Layout1->addWidget( deleteUnusedButton );
00077        }
00078        layout3->addWidget( ColorsGroup );
00079        if (m_Doc==0)
00080        {
00081               ColsSetGroup = new QGroupBox( this, "ColsSetGroup" );
00082               ColsSetGroup->setTitle( tr( "Color Sets" ) );
00083               ColsSetGroup->setColumnLayout(0, Qt::Vertical );
00084               ColsSetGroup->layout()->setSpacing( 6 );
00085               ColsSetGroup->layout()->setMargin( 11 );
00086               ColsSetGroupLayout = new QVBoxLayout( ColsSetGroup->layout() );
00087               ColsSetGroupLayout->setAlignment( Qt::AlignTop );
00088               textLabel1 = new QLabel( ColsSetGroup, "textLabel1" );
00089               textLabel1->setText( tr( "Current Color Set:" ) );
00090               ColsSetGroupLayout->addWidget( textLabel1 );
00091               CSets = new QPopupMenu();
00092               CSets->insertItem("Scribus Small");
00093 /*
00094               CSets->insertItem("X11 RGB-Set");
00095               CSets->insertItem("X11 Grey-Set");
00096               CSets->insertItem("Gnome-Set");
00097               CSets->insertItem("SVG-Set");
00098               CSets->insertItem("OpenOffice.org-Set");
00099 */
00100               csm.findPaletteLocations();
00101               csm.findPalettes();
00102               QStringList allSets(csm.paletteNames());
00103               for ( QStringList::Iterator it = allSets.begin(); it != allSets.end(); ++it )
00104               {
00105                      CSets->insertItem((*it));
00106               }
00107               customSetStartIndex=CSets->count();
00108               if (custColSet.count() != 0)
00109               {
00110                      QStringList realEx;
00111                      realEx.clear();
00112                      for (uint m = 0; m < custColSet.count(); ++m)
00113                      {
00114                             QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir() + custColSet[m]);
00115                             QFileInfo cfi(Cpfad);
00116                             if (cfi.exists())
00117                             {
00118                                    CSets->insertItem(custColSet[m]);
00119                                    realEx.append(custColSet[m]);
00120                             }
00121                      }
00122                      customColSet = realEx;
00123               }
00124               LoadColSet = new QToolButton( ColsSetGroup, "LoadColSet" );
00125               LoadColSet->setPopup(CSets);
00126               LoadColSet->setPopupDelay(0);
00127               LoadColSet->setText(docColSet);
00128               ColsSetGroupLayout->addWidget( LoadColSet );
00129               SaveColSet = new QPushButton( tr( "&Save Color Set" ), ColsSetGroup, "SaveColSet" );
00130               ColsSetGroupLayout->addWidget( SaveColSet );
00131               layout3->addWidget( ColsSetGroup );
00132        }
00133        saveButton = new QPushButton( CommonStrings::tr_OK, this, "saveButton" );
00134        layout3->addWidget( saveButton );
00135        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
00136        cancelButton->setDefault( true );
00137        layout3->addWidget( cancelButton );
00138        layout5->addLayout( layout3 );
00139        Layout2->addLayout( layout5 );
00140        replaceMap.clear();
00141        EditColors = doco;
00142        dynTip = new DynamicTip(colorListBox, &EditColors);
00143        updateCList();
00144        // signals and slots connections
00145        if (m_Doc==0)
00146        {
00147               connect(CSets, SIGNAL(activated(int)), this, SLOT(loadDefaults(int)));
00148               connect(SaveColSet, SIGNAL( clicked() ), this, SLOT( saveDefaults() ) );
00149               QToolTip::add( LoadColSet, "<qt>" + tr( "Choose a color set to load" ) + "</qt>");
00150               QToolTip::add( SaveColSet, "<qt>" + tr( "Save the current color set" ) + "</qt>");
00151        }
00152        else
00153        {
00154               connect(deleteUnusedButton, SIGNAL( clicked() ), this, SLOT( deleteUnusedColors() ) );
00155               QToolTip::add( deleteUnusedButton, "<qt>" + tr( "Remove unused colors from current document's color set" ) + "</qt>");
00156        }
00157        QToolTip::add( importColorsButton, "<qt>" + tr( "Import colors to the current set from an existing document" ) + "</qt>");
00158        QToolTip::add( newColorButton, "<qt>" + tr( "Create a new color within the current set" ) + "</qt>");
00159        QToolTip::add( editColorButton, "<qt>" + tr( "Edit the currently selected color" ) + "</qt>");
00160        QToolTip::add( duplicateColorButton, "<qt>" + tr( "Make a copy of the currently selected color" ) + "</qt>");
00161        QToolTip::add( deleteColorButton, "<qt>" + tr( "Delete the currently selected color" ) + "</qt>");
00162        QToolTip::add( saveButton, "<qt>" + tr( "Make the current colorset the default color set" ) + "</qt>");
00163         QToolTip::add( colorListBox, "<qt>" + tr( "If color management is enabled, a triangle warning indicator is a warning the the color maybe outside of the color gamut of the current printer profile selected.What this means is the color may not print exactly as indicated on screen. Spot colors are indicated by a red circle. Registration colors will have a registration mark next to the color. More hints about gamut warnings are in the online help under Color Management." ) + "</qt>");
00164        connect( saveButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00165        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00166        connect( newColorButton, SIGNAL( clicked() ), this, SLOT( newColor() ) );
00167        connect( editColorButton, SIGNAL( clicked() ), this, SLOT( editColor() ) );
00168        connect( duplicateColorButton, SIGNAL( clicked() ), this, SLOT( duplicateColor() ) );
00169        connect( deleteColorButton, SIGNAL( clicked() ), this, SLOT( deleteColor() ) );
00170        connect( importColorsButton, SIGNAL( clicked() ), this, SLOT( importColors() ) );
00171        connect( colorListBox, SIGNAL( highlighted(QListBoxItem*) ), this, SLOT( selColor(QListBoxItem*) ) );
00172        connect( colorListBox, SIGNAL( selected(QListBoxItem*) ), this, SLOT( selEditColor(QListBoxItem*) ) );
00173 }
00174 
00175 void ColorManager::saveDefaults()
00176 {
00177        QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir());
00178        QString Name = LoadColSet->text();
00179        Query* dia = new Query(this, "Name", 1, 0, tr("&Name:"), tr("Choose a Name"));
00180        if ((Name == "Scribus Small") || (Name == "X11 RGB-Set") || (Name == "OpenOffice.org-Set")
00181                || (Name == "X11 Grey-Set") || (Name == "Gnome-Set") || (Name == "SVG-Set"))
00182               dia->setEditText("", false);
00183        else
00184               dia->setEditText(Name, false);
00185        if (dia->exec())
00186        {
00187               QString Fname = Cpfad+dia->getEditText();
00188               LoadColSet->setText(dia->getEditText());
00189               QFile fx(Fname);
00190               if (fx.open(IO_WriteOnly))
00191               {
00192                      QDomDocument docu("scribus");
00193                      QString st="<SCRIBUSCOLORS></SCRIBUSCOLORS>";
00194                      docu.setContent(st);
00195                      QDomElement elem = docu.documentElement();
00196                      elem.setAttribute("Name", dia->getEditText());
00197                      ColorList::Iterator itc;
00198                      for (itc = EditColors.begin(); itc != EditColors.end(); ++itc)
00199                      {
00200                             QDomElement co = docu.createElement("COLOR");
00201                             co.setAttribute("NAME",itc.key());
00202                             if (EditColors[itc.key()].getColorModel() == colorModelRGB)
00203                                    co.setAttribute("RGB",EditColors[itc.key()].nameRGB());
00204                             else
00205                                    co.setAttribute("CMYK",EditColors[itc.key()].nameCMYK());
00206                             co.setAttribute("Spot",static_cast<int>(EditColors[itc.key()].isSpotColor()));
00207                             co.setAttribute("Register",static_cast<int>(EditColors[itc.key()].isRegistrationColor()));
00208                             elem.appendChild(co);
00209                      }
00210                      static const char* xmlpi = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00211                      QCString cs = docu.toCString();
00212                      QTextStream s(&fx);
00213                      s.writeRawBytes(xmlpi, strlen(xmlpi));
00214                      s.writeRawBytes(cs, cs.length());
00215 /*                   CMYKColor cmyk;
00216                      QTextStream tsx(&fx);
00217                      QString tmp;
00218                      ColorList::Iterator itc;
00219                      tsx << "Color Set:"+dia->getEditText()+"\n";
00220                      int cp, mp, yp, kp;
00221                      for (itc = EditColors.begin(); itc != EditColors.end(); ++itc)
00222                      {
00223                             ScColorEngine::getCMYKValues(itc.data(), m_Doc, cmyk);
00224                             cmyk.getValues(cp, mp, yp, kp);
00225                             tsx << tmp.setNum(cp) << "\t" ;
00226                             tsx << tmp.setNum(mp) << "\t" ;
00227                             tsx << tmp.setNum(yp) << "\t" ;
00228                             tsx << tmp.setNum(kp) << "\t" ;
00229                             tsx << itc.key() << "\n" ;
00230                      } */
00231                      fx.close();
00232                      if (dia->getEditText() != Name)
00233                      {
00234                             customColSet.append(dia->getEditText());
00235                             CSets->insertItem(dia->getEditText());
00236                      }
00237               }
00238        }
00239        delete dia;
00240 }
00241 
00242 void ColorManager::loadDefaults(int id)
00243 {
00244        int c = CSets->indexOf(id);
00245        bool cus = false;
00246        LoadColSet->setText(CSets->text(id));
00247        EditColors.clear();
00248        QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir()+CSets->text(id));
00249        QString pfadC = ScPaths::instance().libDir()+"swatches/";
00250        QString pfadC2 = pfadC + "Scribus_X11.txt";
00251        switch (c)
00252        {
00253        case 0:
00254               LoadColSet->setText("Scribus Small");
00255               EditColors.insert("White", ScColor(0, 0, 0, 0));
00256               EditColors.insert("Black", ScColor(0, 0, 0, 255));
00257               EditColors.insert("Blue", ScColor(255, 255, 0, 0));
00258               EditColors.insert("Cyan", ScColor(255, 0, 0, 0));
00259               EditColors.insert("Green", ScColor(255, 0, 255, 0));
00260               EditColors.insert("Red", ScColor(0, 255, 255, 0));
00261               EditColors.insert("Yellow", ScColor(0, 0, 255, 0));
00262               EditColors.insert("Magenta", ScColor(0, 255, 0, 0));
00263               break;
00264               /*
00265        case 1:
00266               pfadC2 = pfadC + "Scribus_X11.txt";
00267               break;
00268        case 2:
00269               pfadC2 = pfadC + "Scribus_X11Grey.txt";
00270               break;
00271        case 3:
00272               pfadC2 = pfadC + "Scribus_Gnome.txt";
00273               break;
00274        case 4:
00275               pfadC2 = pfadC + "Scribus_SVG.txt";
00276               break;
00277        case 5:
00278               pfadC2 = pfadC + "Scribus_OpenOffice.txt";
00279               cus = true;
00280               break;*/
00281        default:
00282               if (c<customSetStartIndex)
00283               {
00284                      QString listText=CSets->text(id);
00285                      if (listText=="Scribus OpenOffice")
00286                             cus=true;
00287                      pfadC2 = csm.paletteFileFromName(listText);
00288               }
00289               else
00290               {
00291                      pfadC2 = Cpfad;
00292                      cus = true;
00293               }
00294               break;
00295        }
00296        if (c != 0)
00297        {
00298               QFile fiC(pfadC2);
00299               if (fiC.open(IO_ReadOnly))
00300               {
00301                      QString ColorEn, Cname;
00302                      int Rval, Gval, Bval, Kval;
00303                      QTextStream tsC(&fiC);
00304                      ColorEn = tsC.readLine();
00305                      if (ColorEn.startsWith("<?xml version="))
00306                      {
00307                             QCString docBytes("");
00308                             loadRawText(pfadC2, docBytes);
00309                             QString docText("");
00310                             docText = QString::fromUtf8(docBytes);
00311                             QDomDocument docu("scridoc");
00312                             docu.setContent(docText);
00313                             ScColor lf = ScColor();
00314                             QDomElement elem = docu.documentElement();
00315                             QDomNode PAGE = elem.firstChild();
00316                             while(!PAGE.isNull())
00317                             {
00318                                    QDomElement pg = PAGE.toElement();
00319                                    if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
00320                                    {
00321                                           if (pg.hasAttribute("CMYK"))
00322                                                  lf.setNamedColor(pg.attribute("CMYK"));
00323                                           else
00324                                                  lf.fromQColor(QColor(pg.attribute("RGB")));
00325                                           if (pg.hasAttribute("Spot"))
00326                                                  lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
00327                                           else
00328                                                  lf.setSpotColor(false);
00329                                           if (pg.hasAttribute("Register"))
00330                                                  lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
00331                                           else
00332                                                  lf.setRegistrationColor(false);
00333                                           EditColors.insert(pg.attribute("NAME"), lf);
00334                                    }
00335                                    PAGE=PAGE.nextSibling();
00336                             }
00337                      }
00338                      else
00339                      {
00340                             while (!tsC.atEnd())
00341                             {
00342                                    ScColor tmp;
00343                                    ColorEn = tsC.readLine().stripWhiteSpace();
00344                                    if (ColorEn.length()>0 && ColorEn[0]==QChar('#'))
00345                                           continue;
00346                                    
00347                                    if (ColorEn[0].isNumber()) {
00348                                           QTextStream CoE(&ColorEn, IO_ReadOnly);
00349                                           CoE >> Rval;
00350                                           CoE >> Gval;
00351                                           CoE >> Bval;
00352                                           if (cus)
00353                                           {
00354                                                  CoE >> Kval;
00355                                                  Cname = CoE.read().stripWhiteSpace();
00356                                                  tmp.setColor(Rval, Gval, Bval, Kval);
00357                                           }
00358                                           else
00359                                           {
00360                                                  Cname = CoE.read().stripWhiteSpace();
00361                                                  tmp.setColorRGB(Rval, Gval, Bval);
00362                                           }
00363                                    }
00364                                    else
00365                                    {
00366                                           QStringList fields = QStringList::split(QChar(9), ColorEn);
00367                                           if (fields.count() != 5)
00368                                                  continue;
00369                                           Cname = fields[0];
00370                                           Rval = fields[1].toInt();
00371                                           Gval = fields[2].toInt();
00372                                           Bval = fields[3].toInt();
00373                                           Kval = fields[4].toInt();
00374                                           tmp.setColor(Rval, Gval, Bval, Kval);
00375                                    }
00376                                    if ((c<customSetStartIndex) && (Cname.length()==0))
00377                                    {
00378                                           if (!cus)
00379                                                  Cname=QString("#%1%2%3").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).upper();
00380                                           else
00381                                                  Cname=QString("#%1%2%3%4").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).arg(Kval,2,16).upper();
00382                                           Cname.replace(" ","0");
00383                                    }
00384                                    if (EditColors.contains(Cname))
00385                                    {
00386                                           if (tmp==EditColors[Cname])
00387                                                  continue;
00388                                           Cname=QString("%1%2").arg(Cname).arg(EditColors.count());
00389                                    }
00390                                    EditColors.insert(Cname, tmp);
00391                             }
00392                      }
00393                      fiC.close();
00394               }
00395               else
00396               {
00397                      LoadColSet->setText("Scribus Small");
00398                      EditColors.insert("White", ScColor(0, 0, 0, 0));
00399                      EditColors.insert("Black", ScColor(0, 0, 0, 255));
00400                      EditColors.insert("Blue", ScColor(255, 255, 0, 0));
00401                      EditColors.insert("Cyan", ScColor(255, 0, 0, 0));
00402                      EditColors.insert("Green", ScColor(255, 0, 255, 0));
00403                      EditColors.insert("Red", ScColor(0, 255, 255, 0));
00404                      EditColors.insert("Yellow", ScColor(0, 0, 255, 0));
00405                      EditColors.insert("Magenta", ScColor(0, 255, 0, 0));
00406               }
00407        }
00408        updateCList();
00409 }
00410 
00411 void ColorManager::importColors()
00412 {
00413        QString fileName;
00414        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00415        QString wdir = dirs->get("colors", ".");
00416        CustomFDialog dia(this, wdir, tr("Import"), tr("Documents (*.sla *.sla.gz *.scd *.scd.gz);;Other Files (*.eps *.epsi *.ps *.ai);;All Files (*)"));
00417        if (dia.exec() == QDialog::Accepted)
00418               fileName = dia.selectedFile();
00419        else
00420               return;
00421        if (!fileName.isEmpty())
00422        {
00423               uint oldCount = EditColors.count();
00424               dirs->set("colors", fileName.left(fileName.findRev("/")));
00425               QFileInfo fi = QFileInfo(fileName);
00426               QString ext = fi.extension(false).lower();
00427               if ((ext == "ps") || (ext == "eps") || (ext == "epsi") || (ext == "ai"))
00428               {
00429                      QString tmp, tmp2, FarNam;
00430                      double c, m, y, k;
00431                      ScColor cc;
00432                      QFile f(fileName);
00433                      if (f.open(IO_ReadOnly))
00434                      {
00435                             QTextStream ts(&f);
00436                             while (!ts.atEnd())
00437                             {
00438                                    tmp = ts.readLine();
00439                                    if ((tmp.startsWith("%%CMYKCustomColor")) || (tmp.startsWith("%%CMYKProcessColor")))
00440                                    {
00441                                           if (tmp.startsWith("%%CMYKCustomColor"))
00442                                                  tmp = tmp.remove(0,18);
00443                                           else if (tmp.startsWith("%%CMYKProcessColor"))
00444                                                  tmp = tmp.remove(0,19);
00445                                           QTextStream ts2(&tmp, IO_ReadOnly);
00446                                           ts2 >> c >> m >> y >> k;
00447                                           FarNam = ts2.read();
00448                                           FarNam = FarNam.stripWhiteSpace();
00449                                           FarNam = FarNam.remove(0,1);
00450                                           FarNam = FarNam.remove(FarNam.length()-1,1);
00451                                           FarNam = FarNam.simplifyWhiteSpace();
00452                                           cc = ScColor(static_cast<int>(255 * c), static_cast<int>(255 * m), static_cast<int>(255 * y), static_cast<int>(255 * k));
00453                                           cc.setSpotColor(true);
00454                                           if (!EditColors.contains(FarNam))
00455                                                  EditColors.insert(FarNam, cc);
00456                                           while (!ts.atEnd())
00457                                           {
00458                                                  uint oldPos = ts.device()->at();
00459                                                  tmp = ts.readLine();
00460                                                  if (!tmp.startsWith("%%+"))
00461                                                  {
00462                                                         ts.device()->at(oldPos);
00463                                                         break;
00464                                                  }
00465                                                  tmp = tmp.remove(0,3);
00466                                                  QTextStream ts2(&tmp, IO_ReadOnly);
00467                                                  ts2 >> c >> m >> y >> k;
00468                                                  FarNam = ts2.read();
00469                                                  FarNam = FarNam.stripWhiteSpace();
00470                                                  FarNam = FarNam.remove(0,1);
00471                                                  FarNam = FarNam.remove(FarNam.length()-1,1);
00472                                                  FarNam = FarNam.simplifyWhiteSpace();
00473                                                  cc = ScColor(static_cast<int>(255 * c), static_cast<int>(255 * m), static_cast<int>(255 * y), static_cast<int>(255 * k));
00474                                                  cc.setSpotColor(true);
00475                                                  if (!EditColors.contains(FarNam))
00476                                                         EditColors.insert(FarNam, cc);
00477                                           }
00478                                    }
00479                                    if (tmp.startsWith("%%EndComments"))
00480                                    {
00481                                           if (ext == "ai")
00482                                           {
00483                                                  while (!ts.atEnd())
00484                                                  {
00485                                                         tmp = ts.readLine();
00486                                                         if ((tmp.endsWith("Xa") || tmp.endsWith(" k")) && (tmp.length() > 4))
00487                                                         {
00488                                                                QTextStream ts2(&tmp, IO_ReadOnly);
00489                                                                ts2 >> c >> m >> y >> k;
00490                                                                tmp = ts.readLine();
00491                                                                if (tmp.endsWith("Pc"))
00492                                                                {
00493                                                                       tmp = tmp.stripWhiteSpace();
00494                                                                       tmp = tmp.remove(0,1);
00495                                                                       int en = tmp.find(")");
00496                                                                       FarNam = tmp.mid(0, en);
00497                                                                       FarNam = FarNam.simplifyWhiteSpace();
00498                                                                       cc = ScColor(static_cast<int>(255 * c), static_cast<int>(255 * m), static_cast<int>(255 * y), static_cast<int>(255 * k));
00499                                                                       cc.setSpotColor(true);
00500                                                                       if (!EditColors.contains(FarNam))
00501                                                                              EditColors.insert(FarNam, cc);
00502                                                                }
00503                                                         }
00504                                                  }
00505                                           }
00506                                           break;
00507                                    }
00508                             }
00509                             f.close();
00510                             updateCList();
00511                      }
00512               }
00513               else
00514               {
00515                      FileLoader fl(fileName);
00516                      if (fl.TestFile() == -1)
00517                      //TODO put in nice user warning
00518                             return;
00519                      ColorList LColors;
00520                      if (fl.ReadColors(fileName, LColors))
00521                      {
00522                             ColorList::Iterator it;
00523                             for (it = LColors.begin(); it != LColors.end(); ++it)
00524                             {
00525                                    if (!EditColors.contains(it.key()))
00526                                           EditColors.insert(it.key(), it.data());
00527                             }
00528                             updateCList();
00529                      }
00530               }
00531               if (EditColors.count() == oldCount)
00532                      QMessageBox::information(this, tr("Information"), "<qt>" + tr("The file %1 does not contain colors which can be imported.\nIf the file was a PostScript-based, try to import it with File -&gt; Import. \nNot all files have DSC conformant comments where the color descriptions are located.\n This prevents importing colors from some files.\nSee the Edit Colors section of the documentation for more details.").arg(fileName) + "</qt>", 1, 0, 0);
00533               
00534        }
00535 }
00536 
00537 void ColorManager::deleteUnusedColors()
00538 {
00539        m_Doc->getUsedColors(UsedC);
00540        EditColors = UsedC;
00541        EditColors.ensureBlackAndWhite();
00542        updateCList();
00543 }
00544 
00545 void ColorManager::duplicateColor()
00546 {
00547        QString nam = tr("Copy of %1").arg(sColor);
00548        EditColors.insert(nam, EditColors[sColor]);
00549        sColor = nam;
00550        editColor();
00551        updateCList();
00552 }
00553 
00554 void ColorManager::newColor()
00555 {
00556        ScColor tmpColor = ScColor(0, 0, 0, 0);
00557        CMYKChoose* dia = new CMYKChoose(this, m_Doc, tmpColor, tr("New Color"), &EditColors, customColSet, true);
00558        int newItemIndex=0;
00559        int colCount=0;
00560        if (dia->exec())
00561        {
00562               dia->Farbe.setSpotColor(dia->Separations->isChecked());
00563               ColorList::Iterator itnew=EditColors.insert(dia->Farbname->text(), dia->Farbe);
00564               bool regChecked=dia->Regist->isChecked();
00565               ColorList::Iterator it;
00566               for (it = EditColors.begin(); it != EditColors.end(); ++it)
00567               {
00568                      if (regChecked)
00569                             it.data().setRegistrationColor(false);
00570                      if (it==itnew)
00571                             newItemIndex=colCount;
00572                      ++colCount;
00573               }
00574               EditColors[dia->Farbname->text()].setRegistrationColor(dia->Regist->isChecked());
00575               updateCList();
00576        }
00577        delete dia;
00578        colorListBox->setSelected(newItemIndex, true);
00579        colorListBox->setTopItem(newItemIndex);
00580 }
00581 
00582 void ColorManager::editColor()
00583 {
00584        int selectedIndex=colorListBox->currentItem();
00585        int topIndex=colorListBox->topItem();
00586        ScColor tmpColor = EditColors[sColor];
00587        CMYKChoose* dia = new CMYKChoose(this, m_Doc, tmpColor, sColor, &EditColors, customColSet, false);
00588        if (dia->exec())
00589        {
00590               dia->Farbe.setSpotColor(dia->Separations->isChecked());
00591               EditColors[dia->Farbname->text()] = dia->Farbe;
00592               if (dia->Regist->isChecked())
00593               {
00594                      ColorList::Iterator it;
00595                      for (it = EditColors.begin(); it != EditColors.end(); ++it)
00596                             it.data().setRegistrationColor(false);
00597               }
00598               EditColors[dia->Farbname->text()].setRegistrationColor(dia->Regist->isChecked());
00599               if (sColor != dia->Farbname->text())
00600               {
00601                      replaceMap.insert(sColor, dia->Farbname->text());
00602                      EditColors.remove(sColor);
00603               }
00604               updateCList();
00605        }
00606        delete dia;
00607        colorListBox->setSelected(selectedIndex, true);
00608        colorListBox->setTopItem(topIndex);
00609 }
00610 
00611 void ColorManager::deleteColor()
00612 {
00613        int selectedIndex=colorListBox->currentItem();
00614        int topIndex=colorListBox->topItem();
00615        DelColor *dia = new DelColor(this, EditColors, sColor, (m_Doc!=0));
00616        if (dia->exec())
00617        {
00618               QString replacementColor(dia->getReplacementColor());
00619               if (replacementColor == CommonStrings::tr_NoneColor)
00620                      replacementColor = CommonStrings::None;
00621               if (replaceMap.values().contains(sColor))
00622               {
00623                      QMap<QString,QString>::Iterator it;
00624                      for (it = replaceMap.begin(); it != replaceMap.end(); ++it)
00625                      {
00626                             if (it.data() == sColor)
00627                                    it.data() = replacementColor;
00628                      }
00629               }
00630               replaceMap.insert(sColor, replacementColor);
00631               EditColors.remove(sColor);
00632               updateCList();
00633        }
00634        delete dia;
00635        int listBoxCount=colorListBox->count();
00636        if (listBoxCount>selectedIndex)
00637               colorListBox->setSelected(selectedIndex, true);
00638        if (listBoxCount>topIndex)
00639               colorListBox->setTopItem(topIndex);
00640 }
00641 
00642 void ColorManager::selColor(QListBoxItem *c)
00643 {
00644        sColor = c->text();
00645        bool enableEdit = (sColor != "Black" && sColor != "White");
00646        bool enableDel  = (sColor != "Black" && sColor != "White") && (EditColors.count() > 1);
00647        editColorButton->setEnabled(enableEdit);
00648        duplicateColorButton->setEnabled(true);
00649        deleteColorButton->setEnabled(enableDel);
00650 }
00651 
00652 void ColorManager::selEditColor(QListBoxItem *c)
00653 {
00654        sColor = c->text();
00655        bool enableEdit = (sColor != "Black" && sColor != "White");
00656        bool enableDel  = (sColor != "Black" && sColor != "White") && (EditColors.count() > 1);
00657        editColorButton->setEnabled(enableEdit);
00658        duplicateColorButton->setEnabled(true);
00659        deleteColorButton->setEnabled(enableDel);
00660        if(enableEdit)
00661               editColor();
00662 }
00663 
00664 void ColorManager::updateCList()
00665 {
00666        ColorList::Iterator it;
00667        ScribusDoc* doc = EditColors.document();
00668        colorListBox->clear();
00669        for (it = EditColors.begin(); it != EditColors.end(); ++it)
00670        {
00671               if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
00672                      continue;
00673               colorListBox->insertItem( new ColorFancyPixmapItem(it.data(), doc, it.key()) );
00674        }
00675        colorListBox->setSelected(colorListBox->currentItem(), false);
00676        QString curCol = colorListBox->currentText();
00677        bool enableDel = (curCol != "Black" && curCol != "White") && (EditColors.count() > 1);
00678        deleteColorButton->setEnabled(enableDel);
00679        if (colorListBox->currentItem() < 0)
00680        {
00681               duplicateColorButton->setEnabled(false);
00682               editColorButton->setEnabled(false);
00683               deleteColorButton->setEnabled(false);
00684        }
00685 }
00686 
00687 QString ColorManager::getColorSetName()
00688 {
00689        return LoadColSet->text();
00690 }