Rev 7374 | Rev 8495 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6658 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | #include "createrange.h" |
||
8 | #include "createrange.moc" |
||
9 | |||
10 | #include <qbuttongroup.h> |
||
11 | #include <qlabel.h> |
||
12 | #include <qlistbox.h> |
||
13 | #include <qpushbutton.h> |
||
14 | #include <qradiobutton.h> |
||
15 | #include <qspinbox.h> |
||
16 | #include <qstring.h> |
||
17 | #include <qtabwidget.h> |
||
18 | |||
6775 | cbradney | 19 | CreateRange::CreateRange(QString currText, int pageCount, QWidget* parent, const char* name, WFlags fl ) |
6658 | cbradney | 20 | : CreateRangeBase(parent, name, fl), |
21 | m_PageCount(pageCount), |
||
22 | m_RangeType(0), |
||
23 | m_BasicRangeType(0) |
||
24 | { |
||
25 | pageCountValueLabel->setText(QString("%1").arg(pageCount)); |
||
26 | basicConsecutiveFromSpinBox->setMinValue(1); |
||
27 | basicConsecutiveToSpinBox->setMinValue(1); |
||
28 | basicConsecutiveFromSpinBox->setMaxValue(pageCount); |
||
29 | basicConsecutiveToSpinBox->setMaxValue(pageCount); |
||
30 | basicSelectRangeType(m_BasicRangeType); |
||
31 | advPageGroupSizeSpinBox->setMaxValue(pageCount); |
||
6775 | cbradney | 32 | if (m_PageCount==1) |
33 | basicEvenRadioButton->setShown(false); |
||
34 | if (currText.length()>0) |
||
35 | basicRangeListBox->insertItem(currText); |
||
6658 | cbradney | 36 | // signals and slots connections |
37 | connect(tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selectRangeType(QWidget*))); |
||
38 | connect(basicRangeAddButton, SIGNAL(clicked()), this, SLOT(basicAddToRange())); |
||
39 | connect(basicRangeDelButton, SIGNAL(clicked()), this, SLOT(basicDelFromRange())); |
||
40 | connect(basicConsecutiveRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeConsec())); |
||
41 | connect(basicCommaSepRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeComma())); |
||
6667 | cbradney | 42 | connect(basicEvenRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeEven())); |
43 | connect(basicOddRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeOdd())); |
||
6658 | cbradney | 44 | connect(basicRangeUpButton, SIGNAL(clicked()), this, SLOT(basicMoveUp())); |
45 | connect(basicRangeDownButton, SIGNAL(clicked()), this, SLOT(basicMoveDown())); |
||
46 | connect(advPageGroupSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(advSpinChange(int))); |
||
47 | connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); |
||
48 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
||
49 | advPageGroupSizeSpinBox->setValue(4); |
||
50 | } |
||
51 | |||
52 | CreateRange::~CreateRange() |
||
53 | { |
||
54 | } |
||
55 | |||
56 | void CreateRange::getCreateRangeData(CreateRangeData& crData) |
||
57 | { |
||
58 | crData.pageRange=""; |
||
6821 | cbradney | 59 | //First tab selected |
6658 | cbradney | 60 | if (m_RangeType==0) |
61 | { |
||
7973 | cbradney | 62 | uint c=basicRangeListBox->count(); |
6821 | cbradney | 63 | if (c==0) |
6658 | cbradney | 64 | { |
6821 | cbradney | 65 | basicAddToRange(); |
66 | c=basicRangeListBox->count(); |
||
67 | } |
||
68 | for (uint i=0;i<c;++i) |
||
69 | { |
||
70 | if (i!=0 && i<c) |
||
6658 | cbradney | 71 | crData.pageRange+=","; |
72 | crData.pageRange+=basicRangeListBox->text(i); |
||
73 | } |
||
74 | } |
||
75 | else |
||
76 | crData.pageRange=m_PageString; |
||
77 | } |
||
78 | |||
79 | void CreateRange::basicAddToRange( ) |
||
80 | { |
||
6775 | cbradney | 81 | QString newEntry; |
6667 | cbradney | 82 | switch (m_BasicRangeType) |
83 | { |
||
84 | case 0: |
||
85 | { |
||
86 | int from=basicConsecutiveFromSpinBox->value(); |
||
87 | int to=basicConsecutiveToSpinBox->value(); |
||
88 | if (from==to) |
||
6775 | cbradney | 89 | newEntry=QString("%1").arg(from); |
6667 | cbradney | 90 | else |
6775 | cbradney | 91 | newEntry=QString("%1-%2").arg(from).arg(to); |
6667 | cbradney | 92 | } |
93 | break; |
||
94 | case 1: |
||
6775 | cbradney | 95 | newEntry=basicCommaSepLineEdit->text(); |
6667 | cbradney | 96 | break; |
97 | case 2: |
||
98 | { |
||
99 | QString numbers; |
||
100 | for (int i=2; i<=m_PageCount; i+=2) |
||
101 | { |
||
102 | if (i!=2) |
||
103 | numbers+=","; |
||
104 | numbers+=QString("%1").arg(i); |
||
105 | } |
||
6775 | cbradney | 106 | newEntry=numbers; |
6667 | cbradney | 107 | } |
108 | break; |
||
109 | case 3: |
||
110 | { |
||
111 | QString numbers; |
||
112 | for (int i=1; i<=m_PageCount; i+=2) |
||
113 | { |
||
114 | if (i!=1) |
||
115 | numbers+=","; |
||
116 | numbers+=QString("%1").arg(i); |
||
117 | } |
||
6775 | cbradney | 118 | newEntry=numbers; |
6667 | cbradney | 119 | } |
120 | break; |
||
121 | } |
||
6775 | cbradney | 122 | if (newEntry.length()!=0) |
123 | basicRangeListBox->insertItem(newEntry); |
||
6658 | cbradney | 124 | } |
125 | |||
126 | void CreateRange::basicDelFromRange() |
||
127 | { |
||
128 | basicRangeListBox->removeItem(basicRangeListBox->currentItem()); |
||
129 | } |
||
130 | |||
131 | void CreateRange::basicSelectRangeTypeConsec() |
||
132 | { |
||
133 | basicSelectRangeType(0); |
||
134 | } |
||
135 | |||
136 | void CreateRange::basicSelectRangeTypeComma() |
||
137 | { |
||
138 | basicSelectRangeType(1); |
||
139 | } |
||
140 | |||
6667 | cbradney | 141 | void CreateRange::basicSelectRangeTypeEven() |
142 | { |
||
143 | basicSelectRangeType(2); |
||
144 | } |
||
145 | |||
146 | void CreateRange::basicSelectRangeTypeOdd() |
||
147 | { |
||
148 | basicSelectRangeType(3); |
||
149 | } |
||
150 | |||
6658 | cbradney | 151 | void CreateRange::basicSelectRangeType(int i) |
152 | { |
||
153 | m_BasicRangeType=i; |
||
154 | bool basicRangeTypeIsConsecutive=(i==0); |
||
155 | basicConsecutiveFromLabel->setEnabled(basicRangeTypeIsConsecutive); |
||
156 | basicConsecutiveFromSpinBox->setEnabled(basicRangeTypeIsConsecutive); |
||
157 | basicConsecutiveToLabel->setEnabled(basicRangeTypeIsConsecutive); |
||
158 | basicConsecutiveToSpinBox->setEnabled(basicRangeTypeIsConsecutive); |
||
159 | basicCommaSepLineEdit->setEnabled(!basicRangeTypeIsConsecutive); |
||
160 | } |
||
161 | |||
162 | void CreateRange::selectRangeType(QWidget *) |
||
163 | { |
||
164 | m_RangeType=tabWidget->currentPageIndex(); |
||
165 | } |
||
166 | |||
167 | |||
168 | void CreateRange::basicMoveUp() |
||
169 | { |
||
170 | int index=basicRangeListBox->currentItem(); |
||
7374 | cbradney | 171 | if (index==-1 || index==0) |
6658 | cbradney | 172 | return; |
173 | basicRangeListBox->clearSelection(); |
||
174 | QListBoxItem* clbi=basicRangeListBox->item(index); |
||
175 | basicRangeListBox->takeItem(clbi); |
||
176 | basicRangeListBox->insertItem(clbi, QMAX(0, index-1)); |
||
177 | basicRangeListBox->setCurrentItem(clbi); |
||
178 | } |
||
179 | |||
180 | void CreateRange::basicMoveDown() |
||
181 | { |
||
182 | int index=basicRangeListBox->currentItem(); |
||
7374 | cbradney | 183 | if (index==-1 || index==static_cast<int>(basicRangeListBox->count())-1) |
6658 | cbradney | 184 | return; |
185 | basicRangeListBox->clearSelection(); |
||
186 | QListBoxItem* clbi=basicRangeListBox->item(index); |
||
187 | basicRangeListBox->takeItem(clbi); |
||
188 | basicRangeListBox->insertItem(clbi, index+1); |
||
189 | basicRangeListBox->setCurrentItem(clbi); |
||
190 | } |
||
191 | |||
192 | |||
193 | void CreateRange::advSpinChange(int /*v*/) |
||
194 | { |
||
195 | m_PageString=""; |
||
196 | int mp1=m_PageCount+1; |
||
197 | //locked at 4 for now. |
||
198 | if (m_PageCount % 4 == 0) |
||
199 | { |
||
200 | //28,1,2,27, 26,3,4,25 |
||
201 | for (int i=m_PageCount;i>m_PageCount/2;i-=2) |
||
202 | { |
||
203 | if (i!=m_PageCount) |
||
204 | m_PageString+=","; |
||
205 | m_PageString+=QString("%1").arg(i); |
||
206 | m_PageString+=QString(",%1").arg(mp1-i); |
||
207 | m_PageString+=QString(",%1").arg(mp1-i+1); |
||
208 | m_PageString+=QString(",%1").arg(i-1); |
||
209 | } |
||
210 | } |
||
211 | QString tmp(m_PageString); |
||
212 | tmp.truncate(20); |
||
213 | advSampleOrderExampleLabel->setText(tmp+"..."); |
||
214 | } |