Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes
BarcodeGenerator Class Reference

Active tasts for BC GUI. More...

#include <barcodegenerator.h>

List of all members.

Public Member Functions

 BarcodeGenerator (QWidget *parent=0, const char *name=0)
 Create modal BC dialog.
 ~BarcodeGenerator ()
 Erase the temporary files here.

Protected Slots

void bcComboChanged ()
void textCheck_changed ()
void guardCheck_changed ()
void includeCheck_stateChanged (int state)
void includeCheckInText_stateChanged (int state)
void bgColorButton_pressed ()
void lnColorButton_pressed ()
void txtColorButton_pressed ()
void codeEdit_textChanged (const QString &s)
void resetButton_clicked ()
void okButton_pressed ()
void cancelButton_pressed ()

Protected Member Functions

bool paintBarcode (QString fileName=0, int dpi=72)
 Create bitmap for current BC.
void paintColorSample (QLabel *l, QColor c)
 Create color preview.
bool codeEdit_check (const QString &s)
 Perform BarcodeCheckType checks here.

Protected Attributes

BarcodeMap map
 BC/BC type mapping. QMap keys are used as BC names.
QColor lnColor
 Color of the BC lines.
QColor txtColor
 Color of the BC font.
QColor bgColor
 Background color of the BC.
QString psCommand
 A PS command taken from barcode.ps with scribus related addons.
QString tmpFile
 A temporary png pixmap to store the preview image.
QString psFile
 A temporary PS file to store commants for Ghostscript.
bool useSamples
 Flag if user modified the codeEditor.
QColor guiColor

Detailed Description

Active tasts for BC GUI.

It's inherited from BarcodeGeneratorBase() class which is created by uic from designer. Don't change anything in BarcodeGeneratorBase manually! It will be overwritten automatically by uic.

Author:
Petr Vanek petr@.nosp@m.yarp.nosp@m.en.cz

Definition at line 60 of file barcodegenerator.h.


Constructor & Destructor Documentation

BarcodeGenerator::BarcodeGenerator ( QWidget *  parent = 0,
const char *  name = 0 
)

Create modal BC dialog.

Parameters:
parentParent of the dialog.
namename od the QObject to debug

Definition at line 43 of file barcodegenerator.cpp.

       : BarcodeGeneratorBase(parent, name, true)
{
       map["EAN-13"] = BarcodeType("ean13", "9781860742712", tr("12 or 13 digits"),
                                                        "[0-9]{12,13}");
       map["EAN-8"] = BarcodeType("ean8", "12345678", tr("8 digits"),
                                                    "[0-9]{8,8}");
       map["UPC-A"] = BarcodeType("upca", "78858101497", tr("11 or 12 digits"),
                                                    "[0-9]{11,12}");
       map["UPC-E"] = BarcodeType("upce", "0123456", tr("7 or 8 digits"),
                                                    "[0-9]{7,8}");
       map["EAN-5"] = BarcodeType("ean5", "90200", tr("5 digits"),
                                                    "[0-9]{5,5}");
       map["EAN-2"] = BarcodeType("ean2", "42", tr("2 digits"),
                                                    "[0-9]{2,2}");
       map["ISBN"] = BarcodeType("isbn", "1-58880-149",
                                                   tr("12 or 13 digits with dashes. The legacy ISBN-10 format accepts 9 or 10 digits with dashes, but this standard was depreciated for public use after 1st January 2007. (Note: To convert an old ISBN-10 to a new ISBN-13, prefix 978- to the first 9 digits, e.g. 1-56592-479-7 -> 978-1-56592-479. The final check-digit will be calculated automatically.)"),
                                                   "[0-9]*\\-[0-9]*\\-[0-9]*");
//    "Code-11"] = "code11"
       map["Code-39"] = BarcodeType("code39", "CODE-39",
                                                         tr("Variable number of characters, digits and any of the symbols -. *$/+%."),
                                                         "[0-9a-zA-Z\\-\\.\\ \\*\\$\\/\\+\\%]*",
                                                        true, true);
//    "Code-93"] = "code93"
       map["Code-128"] = BarcodeType("code128", "^104^102Count^0991234^101!",
                                                          tr("Variable number of ASCII characters and special function symbols, starting with the appropriate start character for the initial character set. UCC/EAN-128s must have a mandatory FNC 1 symbol immediately following the start character."),
                                                          "\\^[0-9a-zA-Z\\^\\!]*",
                                                          true, true);
       map["UCC/EAN-128"] = BarcodeType("code128", "^104^102Count^0991234^101!",
                                                                tr("Variable number of ASCII characters and special function symbols, starting with the appropriate start character for the initial character set. UCC/EAN-128s must have a mandatory FNC 1 symbol immediately following the start character."),
                                                                "\\^[0-9a-zA-Z\\^\\!]*");
       map["Rationalized Codabar"] = BarcodeType("rationalizedCodabar", "0123456789",
                                                                               tr("Variable number of digits and any of the symbols -$:/.+ABCD."),
                                                                               "[0-9A-D\\-\\$\\:\\/\\.\\+]*",
                                                                              true, true);
       map["Interleaved 2 of 5"] = BarcodeType("interleaved2of5", "05012345678900",
                                                                             tr("Variable number of digits"),
                                                                             "[0-9]*",
                                                                         true, true);
       map["ITF-14"] = BarcodeType("interleaved2of5", "05012345678900",
                                                        tr("Variable number of digits. An ITF-14 is 14 characters and does not have a check digit"),
                                                        "[0-9]*",
                                                    true, true);
       map["Code 2 of 5"] = BarcodeType("code2of5", "0123456789",
                                                                tr("Variable number of digits"),
                                                                "[0-9]*");
       map["Postnet"] = BarcodeType("postnet", "01234567",
                                                         tr("Variable number of digits"),
                                                         "[0-9]*",
                                                        false, true);
       map["Royal Mail"] = BarcodeType("royalmail", "LE28HS9Z",
                                                               tr("Variable number of digits and capital letters"),
                                                               "[0-9A-Z]*",
                                                               false, true);
//    "Auspost"] = "auspost"
       map["MSI"] = BarcodeType("msi", "0120823635162", tr("Variable number of digits"),
                                                  "[0-9]*",
                                                 true, true);
//    "KIX"] = "kix"
       map["Plessey"] = BarcodeType("plessey", "012345ABCDEF",
                                                         tr("Variable number of hexadecimal characters"),
                                                         "[0-9A-F]*",
                                                        false, true);
       //    "Symbol"] = "symbol"

       useSamples = true;
       guiColor = codeEdit->paletteBackgroundColor();
       bcCombo->insertStringList(map.keys());
       okButton->setText(CommonStrings::tr_OK);
       cancelButton->setText(CommonStrings::tr_Cancel);
       resetButton->setPixmap(loadIcon("u_undo16.png"));
       lnColor = Qt::black;
       txtColor = Qt::black;
       bgColor = Qt::white;
       paintColorSample(linesLabel, lnColor);
       paintColorSample(txtLabel, txtColor);
       paintColorSample(bgLabel, bgColor);

       tmpFile = QDir::convertSeparators(ScPaths::getTempFileDir() + "bcode.png");
       psFile = QDir::convertSeparators(ScPaths::getTempFileDir() + "bcode.ps");

       // PS engine
       psCommand.append("%!PS-Adobe-2.0 EPSF-2.0\n");
       QFile f( ScPaths::instance().shareDir() + QString("/plugins/barcode.ps") );
       f.open(IO_ReadOnly);
       QTextStream ts(&f);
       QString s = ts.read();
       int begin = s.find("% --BEGIN TEMPLATE--");
       int end = s.find("% --END TEMPLATE--");
       psCommand.append(s.mid(begin, end));
       f.close();
       psCommand.append("\n\n%command\n");
       bcComboChanged();
}

Here is the call graph for this function:

Erase the temporary files here.

Definition at line 138 of file barcodegenerator.cpp.

{
       QFile::remove(psFile);
       QFile::remove(tmpFile);
}

Member Function Documentation

void BarcodeGenerator::bcComboChanged ( ) [protected, slot]

Definition at line 144 of file barcodegenerator.cpp.

{
       QString s = bcCombo->currentText();
       commentEdit->setText(map[s].comment);
       if (useSamples)
       {
              disconnect(codeEdit, SIGNAL(textChanged(const QString&)), this, SLOT(codeEdit_textChanged(const QString&)));
              codeEdit->setText(map[s].example);
              connect(codeEdit, SIGNAL(textChanged(const QString&)), this, SLOT(codeEdit_textChanged(const QString&)));
       }

       includeCheck->setEnabled(map[s].includeCheck ? true : false);
       if (textCheck->isChecked())
              includeCheckInText->setEnabled(map[s].includeCheckInText ? true : false);
       else
              includeCheckInText->setEnabled(false);

       codeEdit_check(codeEdit->text());
       paintBarcode();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BarcodeGenerator::bgColorButton_pressed ( ) [protected, slot]

Definition at line 195 of file barcodegenerator.cpp.

{
       bgColor = QColorDialog::getColor(bgColor, this);
       if (bgColor.isValid())
       {
              paintColorSample(bgLabel, bgColor);
              paintBarcode();
       }
}

Here is the call graph for this function:

void BarcodeGenerator::cancelButton_pressed ( ) [protected, slot]

Definition at line 236 of file barcodegenerator.cpp.

{
       reject();
}
bool BarcodeGenerator::codeEdit_check ( const QString &  s) [protected]

Perform BarcodeCheckType checks here.

Parameters:
snew string

Definition at line 241 of file barcodegenerator.cpp.

{
       /* probably not needed as the backend do it for us (PV)
       QRegExp rx(map[bcCombo->currentText()].regularExp);
       if (!rx.exactMatch(s))
       {
              codeEdit->setPaletteBackgroundColor(QColor(255, 0, 0));
              sampleLabel->setText("<qt>" + tr("Barcode incomplete") + "</qt>");
              okButton->setEnabled(false);
              return false;
       }
       else
       {
              codeEdit->setPaletteBackgroundColor(guiColor);
              okButton->setEnabled(true);
              paintBarcode();
              return true;
       } */
       paintBarcode();
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BarcodeGenerator::codeEdit_textChanged ( const QString &  s) [protected, slot]

Definition at line 263 of file barcodegenerator.cpp.

{
       useSamples = false;
       codeEdit_check(s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BarcodeGenerator::guardCheck_changed ( ) [protected, slot]

Definition at line 173 of file barcodegenerator.cpp.

{
       paintBarcode();
}

Here is the call graph for this function:

void BarcodeGenerator::includeCheck_stateChanged ( int  state) [protected, slot]

Definition at line 178 of file barcodegenerator.cpp.

{
       paintBarcode();
}

Here is the call graph for this function:

void BarcodeGenerator::includeCheckInText_stateChanged ( int  state) [protected, slot]

Definition at line 183 of file barcodegenerator.cpp.

{
       paintBarcode();
}

Here is the call graph for this function:

void BarcodeGenerator::lnColorButton_pressed ( ) [protected, slot]

Definition at line 205 of file barcodegenerator.cpp.

{
       lnColor = QColorDialog::getColor(lnColor, this);
       if (lnColor.isValid())
       {
              paintColorSample(linesLabel, lnColor);
              paintBarcode();
       }
}

Here is the call graph for this function:

void BarcodeGenerator::okButton_pressed ( ) [protected, slot]

Definition at line 225 of file barcodegenerator.cpp.

{
       // no need to call paintBarcode(tmpFile, 300); because
       // it's created by previous run...
       hide();
       const FileFormat * fmt = LoadSavePlugin::getFormatById(FORMATID_PSIMPORT);
       if( fmt )
              fmt->loadFile(QString::fromUtf8(psFile), LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive);
       accept();
}
bool BarcodeGenerator::paintBarcode ( QString  fileName = 0,
int  dpi = 72 
) [protected]

Create bitmap for current BC.

When tt's called for preview, the 72dpi, small PNG image is created each time user change GUI. No need to call it for final rendering because we have PS file created from "preview" run.

Parameters:
fileNamea optional file name to store on user's filesyste,
dpioptional DPI value. Default is 72 for preview.
Return values:
booltrue on success.

Definition at line 269 of file barcodegenerator.cpp.

{
       if (fileName == QString::null)
              fileName = tmpFile;
       QString opts("barcolor=%1 showbackground backgroundcolor=%2 textcolor=%3");
       opts = opts.arg(lnColor.name().replace('#', "")) \
                     .arg(bgColor.name().replace('#', "")) \
                     .arg(txtColor.name().replace('#', ""));
       if (textCheck->isChecked())
              opts += " includetext";
       if (guardCheck->isChecked())
              opts += " guardwhitespace";
       if (includeCheckInText->isChecked() & includeCheckInText->isEnabled())
              opts += " includecheckintext";
       if (includeCheck->isChecked() & includeCheck->isEnabled())
              opts += " includecheck";
       QString comm("15 10 moveto (%1) (%2) %3 barcode");
       comm = comm.arg(codeEdit->text()).arg(opts).arg(map[bcCombo->currentText()].command);
       comm = psCommand + comm;
       QFile f(psFile);
       if (!f.open(IO_WriteOnly))
       {
              sampleLabel->setText("<qt>" + tr("Error opening file: %1").arg(psFile) + "</qt>");
              return false;
       }
       QTextStream ts(&f);
       ts << comm;
       f.close();

       QStringList gargs;
       // limit the area only for preview. EPS importer bounds the box itself.
       if (fileName == tmpFile)
       {
              gargs.append("-dDEVICEWIDTHPOINTS=200");
              gargs.append("-dDEVICEHEIGHTPOINTS=150");
       }
       gargs.append( QString("-r%1").arg(dpi) );
       gargs.append( QString("-sOutputFile=%1").arg(fileName) );
       gargs.append( psFile );
       int gs = callGS(gargs);
       bool retval = true;
       if (gs != 0)
              retval = false;
       // setup only preview
       if (fileName != tmpFile)
              return retval;
    if (gs == 0)
       {
              sampleLabel->setPixmap(QPixmap(fileName));
              okButton->setEnabled(true);
       }
       else
       {
              sampleLabel->setText("<qt>" + tr("Barcode incomplete") + "</qt>");
              okButton->setEnabled(false);
       }
       return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BarcodeGenerator::paintColorSample ( QLabel *  l,
QColor  c 
) [protected]

Create color preview.

Used for Color box feedback.

Parameters:
lA pointer to the sample QLabel
cA color to fill

Definition at line 188 of file barcodegenerator.cpp.

{
       QPixmap pm(1, 1);
       pm.fill(c);
       l->setPixmap(pm);
}

Here is the caller graph for this function:

void BarcodeGenerator::resetButton_clicked ( ) [protected, slot]

Definition at line 328 of file barcodegenerator.cpp.

{
       useSamples = true;
       bcComboChanged();
}

Here is the call graph for this function:

void BarcodeGenerator::textCheck_changed ( ) [protected, slot]

Definition at line 165 of file barcodegenerator.cpp.

{
       bool s = textCheck->state();
       txtColorButton->setEnabled(s);
       includeCheckInText->setEnabled(s);
       paintBarcode();
}

Here is the call graph for this function:

void BarcodeGenerator::txtColorButton_pressed ( ) [protected, slot]

Definition at line 215 of file barcodegenerator.cpp.

{
       txtColor = QColorDialog::getColor(txtColor, this);
       if (txtColor.isValid())
       {
              paintColorSample(txtLabel, txtColor);
              paintBarcode();
       }
}

Here is the call graph for this function:


Member Data Documentation

QColor BarcodeGenerator::bgColor [protected]

Background color of the BC.

Definition at line 80 of file barcodegenerator.h.

QColor BarcodeGenerator::guiColor [protected]

Definition at line 90 of file barcodegenerator.h.

QColor BarcodeGenerator::lnColor [protected]

Color of the BC lines.

Definition at line 76 of file barcodegenerator.h.

BC/BC type mapping. QMap keys are used as BC names.

Definition at line 74 of file barcodegenerator.h.

QString BarcodeGenerator::psCommand [protected]

A PS command taken from barcode.ps with scribus related addons.

Definition at line 82 of file barcodegenerator.h.

QString BarcodeGenerator::psFile [protected]

A temporary PS file to store commants for Ghostscript.

Definition at line 86 of file barcodegenerator.h.

QString BarcodeGenerator::tmpFile [protected]

A temporary png pixmap to store the preview image.

Definition at line 84 of file barcodegenerator.h.

QColor BarcodeGenerator::txtColor [protected]

Color of the BC font.

Definition at line 78 of file barcodegenerator.h.

Flag if user modified the codeEditor.

To stop replacing his code with samples.

Definition at line 89 of file barcodegenerator.h.


The documentation for this class was generated from the following files: