Back to index

scribus-ng  1.3.4.dfsg+svn20071115
createrange.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 "createrange.h"
00008 #include "createrange.moc"
00009 
00010 #include <qbuttongroup.h>
00011 #include <qlabel.h>
00012 #include <qlistbox.h>
00013 #include <qpushbutton.h>
00014 #include <qradiobutton.h>
00015 #include <qspinbox.h>
00016 #include <qstring.h>
00017 #include <qtabwidget.h>
00018 
00019 CreateRange::CreateRange(QString currText, int pageCount, QWidget* parent, const char* name, WFlags fl )
00020        : CreateRangeBase(parent, name, fl),
00021        m_PageCount(pageCount),
00022        m_RangeType(0),
00023        m_BasicRangeType(0)
00024 {
00025        pageCountValueLabel->setText(QString("%1").arg(pageCount));
00026        basicConsecutiveFromSpinBox->setMinValue(1);
00027        basicConsecutiveToSpinBox->setMinValue(1);
00028        basicConsecutiveFromSpinBox->setMaxValue(pageCount);
00029        basicConsecutiveToSpinBox->setMaxValue(pageCount);
00030        basicSelectRangeType(m_BasicRangeType);
00031        advPageGroupSizeSpinBox->setMaxValue(pageCount);
00032        if (m_PageCount==1)
00033           basicEvenRadioButton->setShown(false);
00034        if (currText.length()>0)
00035               basicRangeListBox->insertItem(currText);
00036        // signals and slots connections
00037        connect(tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selectRangeType(QWidget*)));
00038        connect(basicRangeAddButton, SIGNAL(clicked()), this, SLOT(basicAddToRange()));
00039        connect(basicRangeDelButton, SIGNAL(clicked()), this, SLOT(basicDelFromRange()));
00040        connect(basicConsecutiveRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeConsec()));
00041        connect(basicCommaSepRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeComma()));
00042        connect(basicEvenRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeEven()));
00043        connect(basicOddRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeOdd()));
00044        connect(basicRangeUpButton, SIGNAL(clicked()), this, SLOT(basicMoveUp()));
00045        connect(basicRangeDownButton, SIGNAL(clicked()), this, SLOT(basicMoveDown()));
00046        connect(advPageGroupSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(advSpinChange(int)));
00047        connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
00048        connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
00049        advPageGroupSizeSpinBox->setValue(4);
00050 }
00051 
00052 CreateRange::~CreateRange()
00053 {
00054 }
00055 
00056 void CreateRange::getCreateRangeData(CreateRangeData& crData)
00057 {
00058        crData.pageRange="";
00059        //First tab selected
00060        if (m_RangeType==0)
00061        {
00062               uint c=basicRangeListBox->count();
00063               if (c==0)
00064               {
00065                      basicAddToRange();
00066                      c=basicRangeListBox->count();
00067               }
00068               for (uint i=0;i<c;++i)
00069               {
00070                      if (i!=0 && i<c)
00071                             crData.pageRange+=",";
00072                      crData.pageRange+=basicRangeListBox->text(i);
00073               }
00074        }
00075        else
00076               crData.pageRange=m_PageString;
00077 }
00078 
00079 void CreateRange::basicAddToRange( )
00080 {
00081        QString newEntry;
00082        switch (m_BasicRangeType)
00083        {
00084               case 0:
00085                      {
00086                             int from=basicConsecutiveFromSpinBox->value();
00087                             int to=basicConsecutiveToSpinBox->value();
00088                             if (from==to)
00089                                    newEntry=QString("%1").arg(from);
00090                             else
00091                                    newEntry=QString("%1-%2").arg(from).arg(to);
00092                      }
00093                      break;
00094               case 1:
00095                      newEntry=basicCommaSepLineEdit->text();
00096                      break;
00097               case 2:
00098                      {
00099                             QString numbers;
00100                             for (int i=2; i<=m_PageCount; i+=2)
00101                             {
00102                                    if (i!=2)
00103                                           numbers+=",";
00104                                    numbers+=QString("%1").arg(i);
00105                             }
00106                             newEntry=numbers;
00107                      }
00108                      break;
00109               case 3:
00110                      {
00111                             QString numbers;
00112                             for (int i=1; i<=m_PageCount; i+=2)
00113                             {
00114                                    if (i!=1)
00115                                           numbers+=",";
00116                                    numbers+=QString("%1").arg(i);
00117                             }
00118                             newEntry=numbers;
00119                      }
00120                      break;
00121        }
00122        if (newEntry.length()!=0)
00123               basicRangeListBox->insertItem(newEntry);
00124 }
00125 
00126 void CreateRange::basicDelFromRange()
00127 {
00128        basicRangeListBox->removeItem(basicRangeListBox->currentItem());
00129 }
00130 
00131 void CreateRange::basicSelectRangeTypeConsec()
00132 {
00133        basicSelectRangeType(0);
00134 }
00135 
00136 void CreateRange::basicSelectRangeTypeComma()
00137 {
00138        basicSelectRangeType(1);
00139 }
00140 
00141 void CreateRange::basicSelectRangeTypeEven()
00142 {
00143        basicSelectRangeType(2);
00144 }
00145 
00146 void CreateRange::basicSelectRangeTypeOdd()
00147 {
00148        basicSelectRangeType(3);
00149 }
00150 
00151 void CreateRange::basicSelectRangeType(int i)
00152 {
00153        m_BasicRangeType=i;
00154        bool basicRangeTypeIsConsecutive=(i==0);
00155        basicConsecutiveFromLabel->setEnabled(basicRangeTypeIsConsecutive);
00156        basicConsecutiveFromSpinBox->setEnabled(basicRangeTypeIsConsecutive);
00157        basicConsecutiveToLabel->setEnabled(basicRangeTypeIsConsecutive);
00158        basicConsecutiveToSpinBox->setEnabled(basicRangeTypeIsConsecutive);
00159        basicCommaSepLineEdit->setEnabled(!basicRangeTypeIsConsecutive);
00160 }
00161 
00162 void CreateRange::selectRangeType(QWidget *)
00163 {
00164        m_RangeType=tabWidget->currentPageIndex();
00165 }
00166 
00167 
00168 void CreateRange::basicMoveUp()
00169 {
00170        int index=basicRangeListBox->currentItem();
00171        if (index==-1 || index==0)
00172               return;
00173        basicRangeListBox->clearSelection();
00174        QListBoxItem* clbi=basicRangeListBox->item(index);
00175        basicRangeListBox->takeItem(clbi);
00176        basicRangeListBox->insertItem(clbi, QMAX(0, index-1));
00177        basicRangeListBox->setCurrentItem(clbi);
00178 }
00179 
00180 void CreateRange::basicMoveDown()
00181 {
00182        int index=basicRangeListBox->currentItem();
00183        if (index==-1 || index==static_cast<int>(basicRangeListBox->count())-1)
00184               return;
00185        basicRangeListBox->clearSelection();
00186        QListBoxItem* clbi=basicRangeListBox->item(index);
00187        basicRangeListBox->takeItem(clbi);
00188        basicRangeListBox->insertItem(clbi, index+1);
00189        basicRangeListBox->setCurrentItem(clbi);
00190 }
00191 
00192 
00193 void CreateRange::advSpinChange(int /*v*/)
00194 {
00195        m_PageString="";
00196        int mp1=m_PageCount+1;
00197        //locked at 4 for now.
00198        if (m_PageCount % 4 == 0)
00199        {
00200        //28,1,2,27, 26,3,4,25
00201               for (int i=m_PageCount;i>m_PageCount/2;i-=2)
00202               {
00203                      if (i!=m_PageCount)
00204                             m_PageString+=",";
00205                      m_PageString+=QString("%1").arg(i);
00206                      m_PageString+=QString(",%1").arg(mp1-i);
00207                      m_PageString+=QString(",%1").arg(mp1-i+1);
00208                      m_PageString+=QString(",%1").arg(i-1);
00209               }
00210        }
00211        QString tmp(m_PageString);
00212        tmp.truncate(20);
00213        advSampleOrderExampleLabel->setText(tmp+"...");
00214 }