Back to index

scribus-ng  1.3.4.dfsg+svn20071115
satdialog.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Riku Leino, tsoots@gmail.com                                          *
00009  ***************************************************************************/
00010 #include "satdialog.h"
00011 #include "satdialog.moc"
00012 #include "scribusapi.h"
00013 #include "prefsmanager.h"
00014 #include <prefsfile.h>
00015 
00016 extern QPixmap SCRIBUS_API loadIcon(QString nam);
00017 
00018 satdialog::satdialog(QWidget* parent, QString tmplName, int pageW, int pageH) : QDialog(parent, "satdialog", true)
00019 {
00020        setCaption( tr("Save as Template"));
00021        setIcon(loadIcon("AppIcon.png"));
00022        readPrefs();
00023        
00024        QBoxLayout* blo = new QVBoxLayout(this,0,5,"blo");
00025        QWidget* top = new QWidget(this);
00026        top->setMaximumHeight(5);
00027        middle = new QWidget(this);
00028        middle->setMinimumWidth(250);
00029        QBoxLayout* middlelo = new QHBoxLayout(middle,0,5);
00030        QWidget* left = new QWidget(middle);
00031        center = new QWidget(middle);
00032        QWidget* right = new QWidget(middle);
00033        middlelo->addWidget(left);
00034        middlelo->addWidget(center);
00035        middlelo->addWidget(right);
00036        QWidget* bottom = new QWidget(this);
00037        bottom->setMinimumHeight(40);
00038        bottom->setMaximumHeight(40);
00039        blo->addWidget(top);
00040        blo->addWidget(middle);
00041        blo->addWidget(bottom);
00042        
00043        QBoxLayout* mlo = new QVBoxLayout(center,0,5);
00044        mlo->insertSpacing(0,5);
00045        nameLabel = new QLabel( tr("Name"),center);
00046        mlo->addWidget(nameLabel);
00047        nameEdit = new QLineEdit(center);
00048        nameEdit->setText(tmplName);
00049        mlo->addWidget(nameEdit);
00050        
00051        catsLabel = new QLabel( tr("Category"), center);
00052        mlo->addWidget(catsLabel);
00053        catsCombo = new QComboBox(center,"catsCombo");
00054        mlo->addWidget(catsCombo);
00055        setupCategories();
00056        
00057        psizeLabel = new QLabel( tr("Page Size"),center);
00058        mlo->addWidget(psizeLabel);
00059        psizeEdit = new QLineEdit(center);
00060        mlo->addWidget(psizeEdit);
00061        setupPageSize(pageW, pageH);
00062        
00063        colorsLabel = new QLabel( tr("Colors"),center);
00064        mlo->addWidget(colorsLabel);
00065        colorsEdit = new QLineEdit(center);
00066        mlo->addWidget(colorsEdit);
00067        
00068        descrLabel = new QLabel( tr("Description"),center);
00069        mlo->addWidget(descrLabel);
00070        descrEdit = new QTextEdit(center);
00071        mlo->addWidget(descrEdit);
00072        
00073        usageLabel = new QLabel( tr("Usage"),center);
00074        mlo->addWidget(usageLabel);
00075        usageEdit = new QTextEdit(center);
00076        mlo->addWidget(usageEdit);
00077        
00078        authorLabel = new QLabel( tr("Author"),center);
00079        mlo->addWidget(authorLabel);
00080        authorEdit = new QLineEdit(center);
00081        mlo->addWidget(authorEdit);
00082        authorEdit->setText(author);
00083        
00084        emailLabel = new QLabel( tr("Email"),center);
00085        mlo->addWidget(emailLabel);
00086        emailEdit = new QLineEdit(center);
00087        mlo->addWidget(emailEdit);
00088        emailEdit->setText(email);
00089        
00090        mlo->addStretch(10);
00091        mlo->insertSpacing(-1,5);
00092        QBoxLayout* tlo = new QHBoxLayout(bottom,0,5);
00093        detailButton = new QPushButton( tr("More Details"), bottom);
00094        tlo->addWidget(detailButton);
00095        tlo->addStretch(10);
00096        okButton = new QPushButton( tr("OK"),bottom);
00097        okButton->setDefault(true);
00098        tlo->addWidget(okButton);
00099        tlo->insertSpacing(0,5);
00100        tlo->insertSpacing(-1,5);
00101        
00102        if (isFullDetail) 
00103               fullDetail();
00104        else
00105               minimumDetail();
00106 
00107        // Slots and signals connections
00108        connect(detailButton, SIGNAL(clicked()), this, SLOT(detailClicked()));
00109        connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
00110        
00111 }
00112 
00113 void satdialog::detailClicked()
00114 {
00115        if (isFullDetail) {
00116               minimumDetail();
00117        } else {
00118               fullDetail();
00119        }
00120        isFullDetail = !isFullDetail;
00121 }
00122 
00123 void satdialog::fullDetail() 
00124 {
00125        detailButton->setText( tr("Less Details"));
00126        psizeLabel->setHidden(false);
00127        psizeLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00128        catsLabel->setHidden(false);
00129        catsLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00130        colorsLabel->setHidden(false);
00131        colorsLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00132        descrLabel->setHidden(false);
00133        descrLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00134        usageLabel->setHidden(false);
00135        usageLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00136        authorLabel->setHidden(false);
00137        authorLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00138        emailLabel->setHidden(false);
00139        emailLabel->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00140        psizeEdit->setHidden(false);
00141        psizeEdit->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00142        catsCombo->setHidden(false);
00143        catsCombo->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
00144        colorsEdit->setHidden(false);
00145        colorsEdit->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00146        descrEdit->setHidden(false);
00147        descrEdit->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00148        usageEdit->setHidden(false);
00149        usageEdit->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00150        authorEdit->setHidden(false);
00151        authorEdit->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00152        emailEdit->show();
00153        emailEdit->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
00154        layout()->activate();
00155 //     resize(minimumSizeHint());
00156        setFixedSize(minimumSizeHint());
00157 }
00158 
00159 void satdialog::minimumDetail()
00160 {
00161        detailButton->setText( tr("More Details"));
00162        catsLabel->hide();
00163        catsLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00164        psizeLabel->hide();
00165        psizeLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00166        colorsLabel->hide();
00167        colorsLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00168        descrLabel->hide();
00169        descrLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00170        usageLabel->hide();
00171        usageLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00172        authorLabel->hide();
00173        authorLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00174        emailLabel->hide();
00175        emailLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00176        catsCombo->hide();
00177        catsCombo->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00178        psizeEdit->hide();
00179        psizeEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00180        colorsEdit->hide();
00181        colorsEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00182        descrEdit->hide();
00183        descrEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00184        usageEdit->hide();
00185        usageEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00186        authorEdit->hide();
00187        authorEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00188        emailEdit->hide();
00189        emailEdit->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
00190 
00191        layout()->activate();
00192        setFixedSize(minimumSizeHint());
00193 
00194        adjustSize();  // TODO Get rid of this
00195 }
00196 
00197 void satdialog::readPrefs() 
00198 {
00199        prefs = PrefsManager::instance()->prefsFile->getPluginContext("satemplate");
00200        author = prefs->get("author", "");
00201        email = prefs->get("email", "");
00202        isFullDetail = prefs->getBool("isFullDetail", false);
00203 }
00204 
00205 void satdialog::writePrefs()
00206 {
00207        prefs->set("author", authorEdit->text());
00208        prefs->set("email", emailEdit->text());
00209        prefs->set("isFullDetail", isFullDetail);
00210 }
00211 
00212 void satdialog::setupCategories() 
00213 {
00214        // en will be used in template.xml and it will be then replaced with the lang when used for users
00215        // to get the categories in their language.
00216        QString* en = new QString("Newsletters"); QString* lang = new QString(QObject::tr("Newsletters"));
00217        cats.push_back(new Pair(en,lang));
00218        en = new QString("Brochures"); lang = new QString(QObject::tr("Brochures"));
00219        cats.push_back(new Pair(en,lang));
00220        en = new QString("Catalogs"); lang = new QString(QObject::tr("Catalogs"));
00221        cats.push_back(new Pair(en,lang));
00222        en = new QString("Flyers"); lang = new QString(QObject::tr("Flyers"));
00223        cats.push_back(new Pair(en,lang));
00224        en = new QString("Signs"); lang = new QString(QObject::tr("Signs"));
00225        cats.push_back(new Pair(en,lang));
00226        en = new QString("Cards"); lang = new QString(QObject::tr("Cards"));
00227        cats.push_back(new Pair(en,lang));
00228        en = new QString("Letterheads"); lang = new QString(QObject::tr("Letterheads"));
00229        cats.push_back(new Pair(en,lang));
00230        en = new QString("Envelopes"); lang = new QString(QObject::tr("Envelopes"));
00231        cats.push_back(new Pair(en,lang));
00232        en = new QString("Business Cards"); lang = new QString(QObject::tr("Business Cards"));
00233        cats.push_back(new Pair(en,lang));
00234        en = new QString("Calendars"); lang = new QString(QObject::tr("Calendars"));
00235        cats.push_back(new Pair(en,lang));
00236        en = new QString("Advertisements"); lang = new QString(QObject::tr("Advertisements"));
00237        cats.push_back(new Pair(en,lang));
00238        en = new QString("Labels"); lang = new QString(QObject::tr("Labels"));
00239        cats.push_back(new Pair(en,lang));
00240        en = new QString("Menus"); lang = new QString(QObject::tr("Menus"));
00241        cats.push_back(new Pair(en,lang));
00242        en = new QString("Programs"); lang = new QString(QObject::tr("Programs"));
00243        cats.push_back(new Pair(en,lang));
00244        en = new QString("PDF Forms"); lang = new QString(QObject::tr("PDF Forms"));
00245        cats.push_back(new Pair(en,lang));
00246        en = new QString("PDF Presentations"); lang = new QString(QObject::tr("PDF Presentations"));
00247        cats.push_back(new Pair(en,lang));
00248        en = new QString("Magazines"); lang = new QString(QObject::tr("Magazines"));
00249        cats.push_back(new Pair(en,lang));
00250        en = new QString("Posters"); lang = new QString(QObject::tr("Posters"));
00251        cats.push_back(new Pair(en,lang));
00252        en = new QString("Announcements"); lang = new QString(QObject::tr("Announcements"));
00253        cats.push_back(new Pair(en,lang));
00254        en = new QString("Text Documents"); lang = new QString(QObject::tr("Text Documents"));
00255        cats.push_back(new Pair(en,lang));
00256        en = new QString("Folds"); lang = new QString(QObject::tr("Folds"));
00257        cats.push_back(new Pair(en,lang));
00258        en = new QString("Media Cases"); lang = new QString(QObject::tr("Media Cases"));
00259        cats.push_back(new Pair(en,lang));
00260        en = new QString("Own Templates"); lang = new QString(QObject::tr("Own Templates"));
00261        cats.push_back(new Pair(en,lang));
00262        
00263        QStringList* list = new QStringList();
00264        for (uint i = 0; i < cats.size(); ++i)
00265               list->append(*cats[i]->second);
00266        list->sort();
00267        QStringList list2 = *list;
00268        catsCombo->insertStringList(list2);
00269        catsCombo->insertItem("",0);
00270        catsCombo->setEditable(true);
00271 }
00272 
00273 void satdialog::setupPageSize(int w, int h)
00274 {
00275        QString sizelist[] = 
00276               {"2380x3368", "1684x2380", "1190x1684", "842x1190", "595x842", "421x595", "297x421", "210x297", "148x210",
00277             "105x148", "2836x4008", "2004x2836", "1418x2004", "1002x1418", "709x1002", "501x709", "355x501", "250x355",
00278                "178x250", "125x178", "89x125", "462x649", "298x683", "312x624", "542x720", "595x935", "1224x792", "612x1008",
00279                "612x792", "792x1225"};
00280        QString namelist[] = 
00281               {"A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8",
00282                "A9", "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7",
00283                "B8", "B9", "B10", "C5E", "Comm10E", "DLE", "Executive", "Folio", "Ledger", tr("Legal"),
00284                tr("Letter"), tr("Tabloid")};
00285 
00286        QString orient, search, psize;
00287        QString wString = QString("%1").arg(w);
00288        QString hString = QString("%1").arg(h);
00289        if (w > h)
00290        {
00291               orient = ", "+ tr("landscape");
00292               search = hString+"x"+wString;
00293        }
00294        else if (w < h)
00295        {
00296               orient = ", "+ tr("portrait");
00297               search = wString+"x"+hString;
00298        }
00299        int index = -1;
00300        for (int i = 0; i < 30; ++i)
00301        {
00302               if (sizelist[i] == search)
00303               {
00304                      index = i;
00305                      psize = namelist[i];
00306                      break;
00307               }
00308        }
00309        
00310        if (index == -1)
00311        {
00312               psize = tr("custom")+", "+wString+"x"+hString;
00313               orient = "";
00314        }
00315 
00316        psizeEdit->setText(psize + orient);
00317 }
00318 
00319 satdialog::~satdialog()
00320 {
00321        writePrefs();
00322        for(uint i = 0; i < cats.size(); ++i)
00323               delete cats[i];
00324 
00325 }