Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

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