Rev 6667 | Go to most recent revision | Details | 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())); |
||
38 | connect(basicRangeUpButton, SIGNAL(clicked()), this, SLOT(basicMoveUp())); |
||
39 | connect(basicRangeDownButton, SIGNAL(clicked()), this, SLOT(basicMoveDown())); |
||
40 | connect(advPageGroupSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(advSpinChange(int))); |
||
41 | connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); |
||
42 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
||
43 | advPageGroupSizeSpinBox->setValue(4); |
||
44 | } |
||
45 | |||
46 | CreateRange::~CreateRange() |
||
47 | { |
||
48 | } |
||
49 | |||
50 | void CreateRange::getCreateRangeData(CreateRangeData& crData) |
||
51 | { |
||
52 | crData.pageRange=""; |
||
53 | if (m_RangeType==0) |
||
54 | { |
||
55 | for (uint i=0;i<basicRangeListBox->count();++i) |
||
56 | { |
||
57 | if (i!=0 && i<basicRangeListBox->count()) |
||
58 | crData.pageRange+=","; |
||
59 | crData.pageRange+=basicRangeListBox->text(i); |
||
60 | } |
||
61 | } |
||
62 | else |
||
63 | crData.pageRange=m_PageString; |
||
64 | } |
||
65 | |||
66 | void CreateRange::basicAddToRange( ) |
||
67 | { |
||
68 | if (m_BasicRangeType==0) |
||
69 | basicRangeListBox->insertItem(QString("%1-%2").arg(basicConsecutiveFromSpinBox->value()).arg(basicConsecutiveToSpinBox->value())); |
||
70 | else |
||
71 | basicRangeListBox->insertItem(basicCommaSepLineEdit->text()); |
||
72 | } |
||
73 | |||
74 | void CreateRange::basicDelFromRange() |
||
75 | { |
||
76 | basicRangeListBox->removeItem(basicRangeListBox->currentItem()); |
||
77 | } |
||
78 | |||
79 | void CreateRange::basicSelectRangeTypeConsec() |
||
80 | { |
||
81 | basicSelectRangeType(0); |
||
82 | } |
||
83 | |||
84 | void CreateRange::basicSelectRangeTypeComma() |
||
85 | { |
||
86 | basicSelectRangeType(1); |
||
87 | } |
||
88 | |||
89 | void CreateRange::basicSelectRangeType(int i) |
||
90 | { |
||
91 | m_BasicRangeType=i; |
||
92 | bool basicRangeTypeIsConsecutive=(i==0); |
||
93 | basicConsecutiveFromLabel->setEnabled(basicRangeTypeIsConsecutive); |
||
94 | basicConsecutiveFromSpinBox->setEnabled(basicRangeTypeIsConsecutive); |
||
95 | basicConsecutiveToLabel->setEnabled(basicRangeTypeIsConsecutive); |
||
96 | basicConsecutiveToSpinBox->setEnabled(basicRangeTypeIsConsecutive); |
||
97 | basicCommaSepLineEdit->setEnabled(!basicRangeTypeIsConsecutive); |
||
98 | } |
||
99 | |||
100 | void CreateRange::selectRangeType(QWidget *) |
||
101 | { |
||
102 | m_RangeType=tabWidget->currentPageIndex(); |
||
103 | } |
||
104 | |||
105 | |||
106 | void CreateRange::basicMoveUp() |
||
107 | { |
||
108 | int index=basicRangeListBox->currentItem(); |
||
109 | if (index==0) |
||
110 | return; |
||
111 | basicRangeListBox->clearSelection(); |
||
112 | QListBoxItem* clbi=basicRangeListBox->item(index); |
||
113 | basicRangeListBox->takeItem(clbi); |
||
114 | basicRangeListBox->insertItem(clbi, QMAX(0, index-1)); |
||
115 | basicRangeListBox->setCurrentItem(clbi); |
||
116 | } |
||
117 | |||
118 | void CreateRange::basicMoveDown() |
||
119 | { |
||
120 | int index=basicRangeListBox->currentItem(); |
||
121 | if (index==static_cast<int>(basicRangeListBox->count())-1) |
||
122 | return; |
||
123 | basicRangeListBox->clearSelection(); |
||
124 | QListBoxItem* clbi=basicRangeListBox->item(index); |
||
125 | basicRangeListBox->takeItem(clbi); |
||
126 | basicRangeListBox->insertItem(clbi, index+1); |
||
127 | basicRangeListBox->setCurrentItem(clbi); |
||
128 | } |
||
129 | |||
130 | |||
131 | void CreateRange::advSpinChange(int /*v*/) |
||
132 | { |
||
133 | m_PageString=""; |
||
134 | int mp1=m_PageCount+1; |
||
135 | //locked at 4 for now. |
||
136 | if (m_PageCount % 4 == 0) |
||
137 | { |
||
138 | //28,1,2,27, 26,3,4,25 |
||
139 | for (int i=m_PageCount;i>m_PageCount/2;i-=2) |
||
140 | { |
||
141 | if (i!=m_PageCount) |
||
142 | m_PageString+=","; |
||
143 | m_PageString+=QString("%1").arg(i); |
||
144 | m_PageString+=QString(",%1").arg(mp1-i); |
||
145 | m_PageString+=QString(",%1").arg(mp1-i+1); |
||
146 | m_PageString+=QString(",%1").arg(i-1); |
||
147 | } |
||
148 | } |
||
149 | QString tmp(m_PageString); |
||
150 | tmp.truncate(20); |
||
151 | advSampleOrderExampleLabel->setText(tmp+"..."); |
||
152 | } |