Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pagelayout.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 "pagelayout.h"
00008 #include "pagelayout.moc"
00009 
00010 #include <qvariant.h>
00011 #include <qgroupbox.h>
00012 #include <qiconview.h>
00013 #include <qlabel.h>
00014 #include <qspinbox.h>
00015 #include <qlayout.h>
00016 #include <qtooltip.h>
00017 #include <qwhatsthis.h>
00018 #include <qpixmap.h>
00019 
00020 #include "sccombobox.h"
00021 #include "commonstrings.h"
00022 
00023 extern QPixmap loadIcon(QString nam);
00024 
00025 PageLayouts::PageLayouts( QWidget* parent, QValueList<PageSet> pSets, bool mode )  : QGroupBox( parent )
00026 {
00027        pageSets = pSets;
00028        modus = mode;
00029        setColumnLayout(0, Qt::Vertical );
00030        layout()->setSpacing( 5 );
00031        layout()->setMargin( 10 );
00032        layoutGroupLayout = new QVBoxLayout( layout() );
00033        layoutGroupLayout->setAlignment( Qt::AlignTop );
00034        if (modus)
00035        {
00036               layoutsView = new QIconView( this, "layoutsView" );
00037               layoutsView->setHScrollBarMode( QIconView::AlwaysOff );
00038               layoutsView->setVScrollBarMode( QIconView::Auto );
00039               layoutsView->setArrangement(QIconView::LeftToRight);
00040               layoutsView->setItemsMovable(false);
00041               layoutsView->setAutoArrange( false );
00042               layoutsView->setSorting( false );
00043               layoutsView->setFocusPolicy(QWidget::NoFocus);
00044               layoutsView->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Ignored, 0, 0, layoutsView->sizePolicy().hasHeightForWidth() ) );
00045               layoutsView->setSelectionMode(QIconView::Single);
00046               layoutGroupLayout->addWidget( layoutsView );
00047        }
00048        else
00049        {
00050               layoutsCombo = new ScComboBox( false, this, "layoutsCombo" );
00051               layoutGroupLayout->addWidget( layoutsCombo );
00052        }
00053        layoutLabel1 = new QLabel( this, "layoutLabel1" );
00054        layoutGroupLayout->addWidget( layoutLabel1 );
00055        firstPage = new ScComboBox( false, this, "firstPage" );
00056        layoutGroupLayout->addWidget( firstPage );
00057        languageChange();
00058        setMaximumWidth(minimumSizeHint().width());
00059        clearWState( WState_Polished );
00060        if (modus)
00061               connect(layoutsView, SIGNAL(clicked(QIconViewItem *)), this, SLOT(itemSelected(QIconViewItem* )));
00062        else
00063               connect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
00064        connect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00065 }
00066 
00067 void PageLayouts::updateLayoutSelector(QValueList<PageSet> pSets)
00068 {
00069        disconnect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
00070        pageSets = pSets;
00071        layoutsCombo->clear();
00072        for (uint pg = 0; pg < pageSets.count(); ++pg)
00073        {
00074               QString psname=CommonStrings::translatePageSetString(pageSets[pg].Name);
00075               if (pg == 0)
00076                      layoutsCombo->insertItem(loadIcon("16/page-simple.png"), psname);
00077               else if (pg == 1)
00078                      layoutsCombo->insertItem(loadIcon("16/page-doublesided.png"), psname);
00079               else if (pg == 2)
00080                      layoutsCombo->insertItem(loadIcon("16/page-3fold.png"), psname);
00081               else if (pg == 3)
00082                      layoutsCombo->insertItem(loadIcon("16/page-4fold.png"), psname);
00083               else
00084                      layoutsCombo->insertItem(loadIcon("16/page-simple.png"), psname);
00085        }
00086        connect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
00087 }
00088 
00089 void PageLayouts::selectFirstP(int nr)
00090 {
00091        disconnect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00092        firstPage->setCurrentItem(nr);
00093        connect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00094 }
00095 
00096 void PageLayouts::selectItem(uint nr)
00097 {
00098        QIconViewItem* ic=0;
00099        uint cce;
00100        if (modus)
00101        {
00102               disconnect(layoutsView, SIGNAL(clicked(QIconViewItem *)), this, SLOT(itemSelected(QIconViewItem* )));
00103               ic = layoutsView->firstItem();
00104               cce = layoutsView->count();
00105        }
00106        else
00107        {
00108               disconnect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
00109               cce = layoutsCombo->count();
00110        }
00111        disconnect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00112        for (uint cc = 0; cc < cce; ++cc)
00113        {
00114               if (cc == nr)
00115               {
00116                      if (cc > 0)
00117                      {
00118                             firstPage->setEnabled(true);
00119                             firstPage->clear();
00120                             QStringList::Iterator pNames;
00121                             for(pNames = pageSets[cc].pageNames.begin(); pNames != pageSets[cc].pageNames.end(); ++pNames )
00122                             {
00123                                    firstPage->insertItem(CommonStrings::translatePageSetLocString((*pNames)));
00124                             }
00125                      }
00126                      else
00127                      {
00128                             firstPage->clear();
00129                             firstPage->insertItem(" ");
00130                             firstPage->setEnabled(false);
00131                      }
00132                      if (modus)
00133                      {
00134                             layoutsView->setSelected(ic, true);
00135                             layoutsView->ensureVisible(0, ic->y(), 5, 5);
00136                      }
00137                      else
00138                             layoutsCombo->setCurrentItem(cc);
00139                      break;
00140               }
00141               if (modus)
00142                      ic = ic->nextItem();
00143        }
00144        if (modus)
00145               connect(layoutsView, SIGNAL(clicked(QIconViewItem *)), this, SLOT(itemSelected(QIconViewItem* )));
00146        else
00147               connect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
00148        connect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00149 }
00150 
00151 void PageLayouts::itemSelectedPost(int choosen)
00152 {
00153        disconnect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00154        if (choosen > 0)
00155        {
00156               firstPage->setEnabled(true);
00157               firstPage->clear();
00158               QStringList::Iterator pNames;
00159               for(pNames = pageSets[choosen].pageNames.begin(); pNames != pageSets[choosen].pageNames.end(); ++pNames )
00160               {
00161                      firstPage->insertItem(CommonStrings::translatePageSetLocString((*pNames)));
00162               }
00163        }
00164        else
00165        {
00166               firstPage->clear();
00167               firstPage->insertItem(" ");
00168               firstPage->setEnabled(false);
00169        }
00170        connect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00171 }
00172 
00173 void PageLayouts::itemSelected(int ic)
00174 {
00175        itemSelectedPost(ic);
00176        emit selectedLayout(ic);
00177 }
00178 
00179 void PageLayouts::itemSelected(QIconViewItem* ic)
00180 {
00181        if (ic == 0)
00182               return;
00183        itemSelectedPost(layoutsView->index(ic));
00184        emit selectedLayout(layoutsView->index(ic));
00185 }
00186 
00187 void PageLayouts::languageChange()
00188 {
00189        setTitle( tr( "Document Layout" ) );
00190        if (modus)
00191        {
00192               layoutsView->clear();
00193               for (uint pg = 0; pg < pageSets.count(); ++pg)
00194               {
00195                      QString psname=CommonStrings::translatePageSetString(pageSets[pg].Name);
00196                      if (pg == 0)
00197                             (void) new QIconViewItem( layoutsView, psname, loadIcon("32/page-simple.png") );
00198                      else if (pg == 1)
00199                             (void) new QIconViewItem( layoutsView, psname, loadIcon("32/page-doublesided.png") );
00200                      else if (pg == 2)
00201                             (void) new QIconViewItem( layoutsView, psname, loadIcon("32/page-3fold.png") );
00202                      else if (pg == 3)
00203                             (void) new QIconViewItem( layoutsView, psname, loadIcon("32/page-4fold.png") );
00204                      else
00205                             (void) new QIconViewItem( layoutsView, psname, loadIcon("32/page-simple.png") );
00206               }
00207               int maxWidth = 0;
00208               QIconViewItem* ic = layoutsView->firstItem();
00209               int startY = 5;
00210               for (uint cc = 0; cc < layoutsView->count(); ++cc)
00211               {
00212                      int w = ic->width();
00213                      maxWidth = QMAX(w, maxWidth);
00214                      ic = ic->nextItem();
00215               }
00216               ic = layoutsView->firstItem();
00217               layoutsView->setAutoArrange( false );
00218               layoutsView->setResizeMode(QIconView::Fixed);
00219               for (uint cc = 0; cc < layoutsView->count(); ++cc)
00220               {
00221                      int w = ic->width();
00222                      int moveW = (maxWidth - w) / 2;
00223                      ic->move(moveW, startY);
00224                      startY += ic->height()+5;
00225                      ic = ic->nextItem();
00226               }
00227        }
00228        else
00229        {
00230               disconnect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
00231               int currIndex=layoutsCombo->currentItem();
00232               layoutsCombo->clear();
00233               for (uint pg = 0; pg < pageSets.count(); ++pg)
00234               {
00235                      QString psname=CommonStrings::translatePageSetString(pageSets[pg].Name);
00236                      if (pg == 0)
00237                             layoutsCombo->insertItem(loadIcon("16/page-simple.png"), psname);
00238                      else if (pg == 1)
00239                             layoutsCombo->insertItem(loadIcon("16/page-doublesided.png"), psname);
00240                      else if (pg == 2)
00241                             layoutsCombo->insertItem(loadIcon("16/page-3fold.png"), psname);
00242                      else if (pg == 3)
00243                             layoutsCombo->insertItem(loadIcon("16/page-4fold.png"), psname);
00244                      else
00245                             layoutsCombo->insertItem(loadIcon("16/page-simple.png"), psname);
00246               }
00247               layoutsCombo->setCurrentItem(currIndex);
00248               connect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
00249               
00250               disconnect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00251               int currFirstPageIndex=firstPage->currentItem();
00252               firstPage->clear();
00253               for(QStringList::Iterator pNames = pageSets[currIndex].pageNames.begin(); pNames != pageSets[currIndex].pageNames.end(); ++pNames )
00254               {
00255                      firstPage->insertItem(CommonStrings::translatePageSetLocString((*pNames)));
00256               }
00257               firstPage->setCurrentItem(currFirstPageIndex);
00258               connect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
00259        }
00260        layoutLabel1->setText( tr( "First Page is:" ) );
00261        
00262 
00263 }