Back to index

scribus-ng  1.3.4.dfsg+svn20071115
nftdialog.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 "nftdialog.h"
00011 #include "nftdialog.moc"
00012 #include "scconfig.h"
00013 #include "scribusapi.h"
00014 #include "commonstrings.h"
00015 
00016 extern QPixmap SCRIBUS_API loadIcon(QString nam);
00017 
00018 nftdialog::nftdialog(QWidget* parent, QString lang, QString templateDir) : QDialog(parent, "nftdialog", true)
00019 {
00020        settings = new nftsettings(lang, templateDir);
00021        
00022        setCaption( tr("New From Template"));
00023        setIcon(loadIcon("AppIcon.png"));
00024        
00025        QBoxLayout* blo = new QVBoxLayout(this,0,5,"blo");
00026        QWidget* top = new QWidget(this);
00027        top->setMaximumHeight(5);
00028        top->setMinimumHeight(5);
00029        QWidget* middle = new QWidget(this);
00030        middle->setMinimumHeight(370);
00031        QWidget* bottom = new QWidget(this);
00032        bottom->setMinimumHeight(40);
00033        bottom->setMaximumHeight(40);
00034        blo->addWidget(top);
00035        blo->addWidget(middle);
00036        blo->addWidget(bottom);
00037        QBoxLayout* bottomlo = new QHBoxLayout(bottom,0,5,"bottomlo");
00038 //     settingsButton = new QPushButton(tr("Settings"),bottom,"settingsButton");
00039 //     bottomlo->insertSpacing(0,5);
00040 //     bottomlo->addWidget(settingsButton);
00041        bottomlo->addStretch(10);
00042        okButton = new QPushButton( CommonStrings::tr_OK,bottom,"okButton");
00043        okButton->setEnabled(false);
00044        bottomlo->addWidget(okButton);
00045        cancelButton = new QPushButton( CommonStrings::tr_Cancel,bottom,"cancelButton");
00046        bottomlo->addWidget(cancelButton);
00047        bottomlo->insertSpacing(-1,5);
00048        cancelButton->setDefault(true);
00049        
00050        mainlo = new QHBoxLayout(middle,0,5,"mainlo");
00051        QSplitter* splitter = new QSplitter(middle);
00052        mainlo->addWidget(splitter);
00053        
00054        categoryList = new QListBox(splitter,"categoryList",0);
00055        categoryList->setMinimumWidth(130);
00056        categoryList->setMaximumWidth(200);
00057        
00058        tnailGrid = new QIconView(splitter,"tnailGrid",0);
00059        tnailGrid->setMinimumWidth(300);
00060        tnailGrid->setSpacing(5);
00061        tnailGrid->setItemsMovable(false);
00062        
00063        popUp = new QPopupMenu(tnailGrid, "popUp");
00064        popUp->insertItem( tr("&Remove"), this, SLOT(removeTemplate()));
00065        popUp->insertItem( tr("&Open"), this, SLOT(exitOK()));
00066        
00067        QWidget* dtTmp = new QWidget(splitter, "dtTmp", 0);
00068        dtTmp->setMinimumWidth(235);
00069        mainlo->insertSpacing(0,5);
00070        mainlo->insertSpacing(-1,5);
00071        
00072        detaillo = new QVBoxLayout(dtTmp,0,5);
00073        detailBar = new QFrame(dtTmp,"detailBar",0);
00074        detailBar->setMaximumHeight(32);
00075        detailBar->setMinimumHeight(32);
00076        detailBar->setMargin(5);
00077        detaillo->addWidget(detailBar);
00078        
00079        infoLabel = new QTextBrowser(dtTmp,"infoLabel");
00080        infoLabel->setFrameShape(QFrame::Panel);
00081        infoLabel->setFrameShadow(QFrame::Sunken);
00082        detaillo->addWidget(infoLabel);
00083 
00084        tmpSpacer = new QWidget(dtTmp,"tmpSpacer",0);
00085        detaillo->addWidget(tmpSpacer);
00086        tmpSpacer->setHidden(true);
00087        
00088        imgLabel = new QIconView(dtTmp,"imgLabel",0);
00089        imgLabel->setFrameShape(QFrame::Panel);
00090        imgLabel->setFrameShadow(QFrame::Sunken);
00091        imgLabel->setSelectionMode(QIconView::NoSelection);
00092        detaillo->addWidget(imgLabel);
00093        imgLabel->setHidden(true);
00094        
00095        aboutLabel = new QTextBrowser(dtTmp,"aboutLabel");
00096        aboutLabel->setFrameShape(QFrame::Panel);
00097        aboutLabel->setFrameShadow(QFrame::Sunken);
00098        detaillo->addWidget(aboutLabel);
00099        aboutLabel->setHidden(true);
00100        setupAbout();
00101        
00102        dtbarlo = new QHBoxLayout(detailBar,0,5);
00103        imgButton = new QToolButton(detailBar,"imgButton");
00104        QIconSet imgSet(loadIcon("16/image-x-generic.png"));
00105        imgButton->setIconSet(imgSet);
00106        imgButton->setToggleButton(true);
00107        imgButton->setMinimumWidth(30);
00108        imgButton->setMinimumHeight(30);
00109        imgButton->setMaximumWidth(30);
00110        imgButton->setMaximumHeight(30);
00111        dtbarlo->addWidget(imgButton);
00112        infoButton = new QToolButton(detailBar,"infoButton");
00113        QIconSet imgSet2(loadIcon("16/information.png"));
00114        infoButton->setIconSet(imgSet2);
00115        infoButton->setToggleButton(true);
00116        infoButton->setMinimumWidth(30);
00117        infoButton->setMinimumHeight(30);
00118        infoButton->setMaximumWidth(30);
00119        infoButton->setMaximumHeight(30);
00120        infoButton->toggle();
00121        dtbarlo->addWidget(infoButton);
00122        dtbarlo->addStretch(10);
00123        dtbarlo->insertSpacing(0,5);
00124        aboutButton = new QToolButton(detailBar,"aboutButton");
00125        QIconSet imgSet3(loadIcon("16/help-browser.png"));
00126        aboutButton->setIconSet(imgSet3);
00127        aboutButton->setToggleButton(true);
00128        aboutButton->setMinimumWidth(30);
00129        aboutButton->setMinimumHeight(30);
00130        aboutButton->setMaximumWidth(30);
00131        aboutButton->setMaximumHeight(30);
00132        dtbarlo->addWidget(aboutButton);
00133        
00134        // Signals and Slots Connections
00135        connect(categoryList, SIGNAL(selectionChanged()), this, SLOT(setTNails()));
00136        connect(infoButton, SIGNAL(toggled(bool)), this, SLOT(infoToggle()));
00137        connect(imgButton, SIGNAL(toggled(bool)), this, SLOT(imgToggle()));
00138        connect(aboutButton, SIGNAL(toggled(bool)), this, SLOT(aboutToggle()));
00139        connect(okButton, SIGNAL(clicked()), this, SLOT(exitOK()));
00140        connect(cancelButton, SIGNAL(clicked()), this, SLOT(exitCancel()));
00141        connect(tnailGrid, SIGNAL(selectionChanged(QIconViewItem*)),this,SLOT(setInfo(QIconViewItem*)));
00142        connect(tnailGrid, SIGNAL(doubleClicked(QIconViewItem*)),this,SLOT(exitOK()));
00143        connect(tnailGrid, SIGNAL(rightButtonPressed(QIconViewItem*, const QPoint&)), 
00144                this, SLOT(showPopup(QIconViewItem*, const QPoint&)));
00145        
00146        setupListItems();
00147        setupCategories();
00148 }
00149 
00150 void nftdialog::setupCategories() 
00151 {
00152        QString categories("");
00153        categoryList->clear();
00154        for (uint i = 0; i < settings->templates.size(); i++)
00155        {
00156               if ((categories.find(settings->templates[i]->templateCategory) == -1) &&
00157                   (!settings->templates[i]->isDeleted))
00158               {
00159                      categoryList->insertItem(settings->templates[i]->templateCategory);
00160                      categories += settings->templates[i]->templateCategory;
00161               }
00162        }
00163        categoryList->sort();
00164        categoryList->insertItem(QString( tr("All")), 0 );
00165        categoryList->setCurrentItem(0);
00166 }
00167 
00168 void nftdialog::setupListItems()
00169 {
00170        iconItems.clear();
00171        for (uint i = 0; i < settings->templates.size(); ++i)
00172        {
00173               if (!settings->templates[i]->isDeleted)
00174               {
00175                      ListItem* tmp = new ListItem(settings->templates[i], NULL);
00176                      iconItems.push_back(tmp);
00177               }
00178        }
00179 }
00180 
00181 void nftdialog::setTNails()
00182 {
00183        if (categoryList->currentItem() == 0)
00184        {
00185               tnailGrid->clear();
00186               for (uint i = 0; i < iconItems.size(); ++i) 
00187               {
00188                      QIconViewItem* tmpQIVI = new QIconViewItem(tnailGrid,
00189                                                                 iconItems[i]->first->name, 
00190                                                                 QPixmap(iconItems[i]->first->tnail));
00191                      iconItems[i]->second = tmpQIVI;
00192               }
00193               tnailGrid->sort();
00194               return;
00195        }
00196        
00197        QString curtype = categoryList->text(categoryList->currentItem());
00198        if (curtype != NULL)
00199        {
00200               tnailGrid->clear();
00201               for (uint i = 0; i < iconItems.size(); ++i)
00202               {
00203                      if (curtype.find(iconItems[i]->first->templateCategory) != -1)
00204                      {
00205                             QIconViewItem* tmpQIVI = new QIconViewItem(tnailGrid,
00206                                                                    iconItems[i]->first->name, 
00207                                                                    QPixmap(iconItems[i]->first->tnail));
00208                             iconItems[i]->second = tmpQIVI;
00209                      } 
00210                      else
00211                             iconItems[i]->second = NULL;
00212               }
00213               tnailGrid->sort();
00214        }
00215 }
00216 
00217 void nftdialog::setInfo(QIconViewItem* item) 
00218 {
00219        getCurrentDocumentTemplate(item);
00220        QString infoText = "<b>"+ tr("Name")+"</b><br>";
00221        infoText += currentDocumentTemplate->name + "<br>";
00222        infoText += "<b>"+ tr("Page Size")+"</b><br>";
00223        infoText += currentDocumentTemplate->psize + "<br>";
00224        infoText += "<b>"+ tr("Colors")+"</b><br>";
00225        infoText += currentDocumentTemplate->color + "<br>";
00226        infoText += "<b>"+ tr("Description")+"</b><br>";
00227        infoText += currentDocumentTemplate->descr + "<br>";
00228        infoText += "<b>"+ tr("Usage")+"</b><br>";
00229        infoText += currentDocumentTemplate->usage + "<br>";
00230        infoText += "<b>"+ tr("Created with")+"</b><br>";
00231        infoText += "Scribus " + currentDocumentTemplate->scribusVersion + "<br>";
00232        infoText += "<b>"+ tr("Date")+"</b><br>";
00233        infoText += currentDocumentTemplate->date + "<br>";
00234        infoText += "<b>"+ tr("Author")+"</b><br>";
00235        infoText += currentDocumentTemplate->author + "<br>";
00236        infoText += currentDocumentTemplate->email + "<br>";
00237        infoLabel->setText(infoText);
00238        imgLabel->clear();
00239        QPixmap tmplImg(currentDocumentTemplate->img);
00240        QIconViewItem* qvi = new QIconViewItem(imgLabel,currentDocumentTemplate->name,tmplImg);
00241        qvi->setRenameEnabled(false);
00242        qvi->setDragEnabled(false);
00243        qvi->setDropEnabled(false);
00244        
00245        if (!okButton->isEnabled())
00246        {
00247               okButton->setEnabled(true);
00248               okButton->setDefault(true);
00249        }
00250 
00251 }
00252 
00253 void nftdialog::infoToggle()
00254 {
00255        if (infoButton->state() == QButton::On)
00256        {
00257               tmpSpacer->setHidden(true);
00258               infoLabel->setHidden(false);
00259               if (imgButton->state() == QButton::On)
00260                      imgButton->toggle();
00261               if (aboutButton->state() == QButton::On)
00262                      aboutButton->toggle();
00263        } 
00264        else
00265        {
00266               if (imgButton->state() == QButton::Off)
00267                      tmpSpacer->setHidden(false);
00268               infoLabel->setHidden(true);
00269        }
00270        
00271 }
00272 
00273 void nftdialog::imgToggle() 
00274 {      
00275        if (imgButton->state() == QButton::On)
00276        {
00277               tmpSpacer->setHidden(true);
00278               imgLabel->setHidden(false);
00279               if (infoButton->state() == QButton::On) 
00280                      infoButton->toggle();
00281               if (aboutButton->state() == QButton::On) 
00282                      aboutButton->toggle();
00283        }
00284        else
00285        {
00286               if (infoButton->state() == QButton::Off)
00287                      tmpSpacer->setHidden(false);
00288               imgLabel->setHidden(true);
00289        }
00290 }
00291 
00292 void nftdialog::aboutToggle()
00293 {
00294        if (aboutButton->state() == QButton::On)
00295        {
00296               tmpSpacer->setHidden(true);
00297               aboutLabel->setHidden(false);
00298               if (imgButton->state() == QButton::On) 
00299                      imgButton->toggle();
00300               if (infoButton->state() == QButton::On)
00301                      infoButton->toggle();
00302        }
00303        else
00304        {
00305               if (aboutButton->state() == QButton::Off)
00306                      tmpSpacer->setHidden(false);
00307               aboutLabel->setHidden(true);
00308        }
00309 }
00310 
00311 void nftdialog::exitCancel() 
00312 {
00313        reject();
00314 }
00315 
00316 void nftdialog::exitOK() 
00317 {
00318        if (currentDocumentTemplate == NULL)
00319               reject();
00320        else
00321               accept();
00322 }
00323 
00324 void nftdialog::setupAbout() 
00325 {
00326        QString text = "New From Template - 0.0.7<br><br>";
00327        text += "<b>";
00328        text += tr("Downloading Templates");
00329        text += "</b><br>";
00330        text += tr("Document templates can be found at "
00331                   "http://www.scribus.net/ in the Downloads section.");
00332        text += "<br><br>";
00333        text += "<b>";
00334        text +=  tr("Installing Templates");
00335        text +=  "</b><br>";
00336        text += tr("Extract the package to the template directory " 
00337                   "~/.scribus/templates "
00338                   "for the current user or "
00339                   "PREFIX/share/scribus/templates "
00340                   "for all users in the system.");
00341        text +=  "<br><br>";
00342        text += "<b>";
00343        text +=  tr("Preparing a template");
00344        text +=  "</b><br>";
00345        text +=  tr("Make sure images and fonts you use can be used freely. If fonts cannot be shared do not collect them when saving as a template.");
00346        text += tr("The template creator should also make sure that the Installing Templates section above applies to their templates as well. This means a user should be able to download a template package and be able to extract them to the template directory and start using them.");
00347        text +=  "<br><br><b>";
00348        text +=  tr("Removing a template");
00349        text +=  "</b><br>";
00350        text += tr("Removing a template from the New From Template dialog will only remove the entry from the template.xml, it will not delete the document files. A popup menu with remove is only shown if you have write access to the template.xml file.");
00351        text +=  "<br><br>";
00352        text += "<b>";
00353        text +=  tr("Translating template.xml");
00354        text +=  "</b><br>";
00355        text += tr("Copy an existing template.xml to a file called template.lang_COUNTRY.xml (use the same lang code that is present in the qm file for your language), for example template.fi.xml for Finnish language template.xml. The copy must be located in the same directory as the original template.xml so Scribus can load it.");
00356        aboutLabel->setText(text);
00357 }
00358 
00359 void nftdialog::showPopup(QIconViewItem* item, const QPoint& point)
00360 {
00361        if (item != NULL) 
00362        {
00363               getCurrentDocumentTemplate(item);
00364               if (currentDocumentTemplate->canWrite())
00365                      popUp->popup(point);
00366        }
00367 }
00368 
00369 void nftdialog::removeTemplate()
00370 {
00371        currentDocumentTemplate->isDeleted = true;
00372        infoLabel->clear();
00373        imgLabel->clear();
00374        currentDocumentTemplate = NULL;
00375        okButton->setEnabled(false);
00376        setupListItems();
00377        setupCategories();
00378 }
00379 
00380 void nftdialog::getCurrentDocumentTemplate(QIconViewItem* item)
00381 {
00382        for (uint i = 0; i < iconItems.size(); ++i)
00383        {
00384               if (iconItems[i]->second == item)
00385               {
00386                      currentDocumentTemplate = iconItems[i]->first;
00387                      break;
00388               }
00389        }
00390 }
00391 
00392 nftdialog::~nftdialog()
00393 {
00394        // TODO Get the window size and position information and save with settings
00395        delete settings;
00396        for (uint i = 0; i < iconItems.size(); i++)
00397        {
00398               if (iconItems[i] != NULL)
00399                      delete iconItems[i];
00400        }
00401 }