Rev 6658 | Rev 6775 | 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 | |||
19 | CreateRange::CreateRange( int pageCount, QWidget* parent, const char* name, WFlags fl ) |
||
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); |
||
32 | // signals and slots connections |
||
33 | connect(tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selectRangeType(QWidget*))); |
||
34 | connect(basicRangeAddButton, SIGNAL(clicked()), this, SLOT(basicAddToRange())); |
||
35 | connect(basicRangeDelButton, SIGNAL(clicked()), this, SLOT(basicDelFromRange())); |
||
36 | connect(basicConsecutiveRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeConsec())); |
||
37 | connect(basicCommaSepRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeComma())); |
||
6667 | cbradney | 38 | connect(basicEvenRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeEven())); |
39 | connect(basicOddRadioButton, SIGNAL(clicked()), this, SLOT(basicSelectRangeTypeOdd())); |
||
6658 | cbradney | 40 | connect(basicRangeUpButton, SIGNAL(clicked()), this, SLOT(basicMoveUp())); |
41 | connect(basicRangeDownButton, SIGNAL(clicked()), this, SLOT(basicMoveDown())); |
||
42 | connect(advPageGroupSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(advSpinChange(int))); |
||
43 | connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); |
||
44 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
||
45 | advPageGroupSizeSpinBox->setValue(4); |
||
46 | } |
||
47 | |||
48 | CreateRange::~CreateRange() |
||
49 | { |
||
50 | } |
||
51 | |||
52 | void CreateRange::getCreateRangeData(CreateRangeData& crData) |
||
53 | { |
||
54 | crData.pageRange=""; |
||
55 | if (m_RangeType==0) |
||
56 | { |
||
57 | for (uint i=0;i<basicRangeListBox->count();++i) |
||
58 | { |
||
59 | if (i!=0 && i<basicRangeListBox->count()) |
||
60 | crData.pageRange+=","; |
||
61 | crData.pageRange+=basicRangeListBox->text(i); |
||
62 | } |
||
63 | } |
||
64 | else |
||
65 | crData.pageRange=m_PageString; |
||
66 | } |
||
67 | |||
68 | void CreateRange::basicAddToRange( ) |
||
69 | { |
||
6667 | cbradney | 70 | switch (m_BasicRangeType) |
71 | { |
||
72 | case 0: |
||
73 | { |
||
74 | int from=basicConsecutiveFromSpinBox->value(); |
||
75 | int to=basicConsecutiveToSpinBox->value(); |
||
76 | if (from==to) |
||
77 | basicRangeListBox->insertItem(QString("%1").arg(from)); |
||
78 | else |
||
79 | basicRangeListBox->insertItem(QString("%1-%2").arg(from).arg(to)); |
||
80 | } |
||
81 | break; |
||
82 | case 1: |
||
83 | basicRangeListBox->insertItem(basicCommaSepLineEdit->text()); |
||
84 | break; |
||
85 | case 2: |
||
86 | { |
||
87 | QString numbers; |
||
88 | for (int i=2; i<=m_PageCount; i+=2) |
||
89 | { |
||
90 | if (i!=2) |
||
91 | numbers+=","; |
||
92 | numbers+=QString("%1").arg(i); |
||
93 | } |
||
94 | basicRangeListBox->insertItem(numbers); |
||
95 | } |
||
96 | break; |
||
97 | case 3: |
||
98 | { |
||
99 | QString numbers; |
||
100 | for (int i=1; i<=m_PageCount; i+=2) |
||
101 | { |
||
102 | if (i!=1) |
||
103 | numbers+=","; |
||
104 | numbers+=QString("%1").arg(i); |
||
105 | } |
||
106 | basicRangeListBox->insertItem(numbers); |
||
107 | } |
||
108 | break; |
||
109 | } |
||
6658 | cbradney | 110 | } |
111 | |||
112 | void CreateRange::basicDelFromRange() |
||
113 | { |
||
114 | basicRangeListBox->removeItem(basicRangeListBox->currentItem()); |
||
115 | } |
||
116 | |||
117 | void CreateRange::basicSelectRangeTypeConsec() |
||
118 | { |
||
119 | basicSelectRangeType(0); |
||
120 | } |
||
121 | |||
122 | void CreateRange::basicSelectRangeTypeComma() |
||
123 | { |
||
124 | basicSelectRangeType(1); |
||
125 | } |
||
126 | |||
6667 | cbradney | 127 | void CreateRange::basicSelectRangeTypeEven() |
128 | { |
||
129 | basicSelectRangeType(2); |
||
130 | } |
||
131 | |||
132 | void CreateRange::basicSelectRangeTypeOdd() |
||
133 | { |
||
134 | basicSelectRangeType(3); |
||
135 | } |
||
136 | |||
6658 | cbradney | 137 | void CreateRange::basicSelectRangeType(int i) |
138 | { |
||
139 | m_BasicRangeType=i; |
||
140 | bool basicRangeTypeIsConsecutive=(i==0); |
||
141 | basicConsecutiveFromLabel->setEnabled(basicRangeTypeIsConsecutive); |
||
142 | basicConsecutiveFromSpinBox->setEnabled(basicRangeTypeIsConsecutive); |
||
143 | basicConsecutiveToLabel->setEnabled(basicRangeTypeIsConsecutive); |
||
144 | basicConsecutiveToSpinBox->setEnabled(basicRangeTypeIsConsecutive); |
||
145 | basicCommaSepLineEdit->setEnabled(!basicRangeTypeIsConsecutive); |
||
146 | } |
||
147 | |||
148 | void CreateRange::selectRangeType(QWidget *) |
||
149 | { |
||
150 | m_RangeType=tabWidget->currentPageIndex(); |
||
151 | } |
||
152 | |||
153 | |||
154 | void CreateRange::basicMoveUp() |
||
155 | { |
||
156 | int index=basicRangeListBox->currentItem(); |
||
157 | if (index==0) |
||
158 | return; |
||
159 | basicRangeListBox->clearSelection(); |
||
160 | QListBoxItem* clbi=basicRangeListBox->item(index); |
||
161 | basicRangeListBox->takeItem(clbi); |
||
162 | basicRangeListBox->insertItem(clbi, QMAX(0, index-1)); |
||
163 | basicRangeListBox->setCurrentItem(clbi); |
||
164 | } |
||
165 | |||
166 | void CreateRange::basicMoveDown() |
||
167 | { |
||
168 | int index=basicRangeListBox->currentItem(); |
||
169 | if (index==static_cast<int>(basicRangeListBox->count())-1) |
||
170 | return; |
||
171 | basicRangeListBox->clearSelection(); |
||
172 | QListBoxItem* clbi=basicRangeListBox->item(index); |
||
173 | basicRangeListBox->takeItem(clbi); |
||
174 | basicRangeListBox->insertItem(clbi, index+1); |
||
175 | basicRangeListBox->setCurrentItem(clbi); |
||
176 | } |
||
177 | |||
178 | |||
179 | void CreateRange::advSpinChange(int /*v*/) |
||
180 | { |
||
181 | m_PageString=""; |
||
182 | int mp1=m_PageCount+1; |
||
183 | //locked at 4 for now. |
||
184 | if (m_PageCount % 4 == 0) |
||
185 | { |
||
186 | //28,1,2,27, 26,3,4,25 |
||
187 | for (int i=m_PageCount;i>m_PageCount/2;i-=2) |
||
188 | { |
||
189 | if (i!=m_PageCount) |
||
190 | m_PageString+=","; |
||
191 | m_PageString+=QString("%1").arg(i); |
||
192 | m_PageString+=QString(",%1").arg(mp1-i); |
||
193 | m_PageString+=QString(",%1").arg(mp1-i+1); |
||
194 | m_PageString+=QString(",%1").arg(i-1); |
||
195 | } |
||
196 | } |
||
197 | QString tmp(m_PageString); |
||
198 | tmp.truncate(20); |
||
199 | advSampleOrderExampleLabel->setText(tmp+"..."); |
||
200 | } |