~ubuntu-branches/debian/sid/scribus/sid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "pageselector.h"

#include <QEvent>
#include <QLineEdit>
#if OPTION_USE_QTOOLBUTTON
    #include <QToolButton>
#else
    #include <QPushButton>
#endif
#include <QLabel>
#include <QToolTip>
#include <QRegExp>
#include <QPixmap>
#include <QHBoxLayout>
#include <QValidator>
#include "sccombobox.h"
#include "util_icon.h"
#include "util.h"

// QIntValidator does it better for us... PV
// class PageValidator : public QValidator
// {
// public:
// 	PageValidator(int min, int max, QObject * parent);
// 	void fixup(QString & input) const;
// 	State validate(QString & input, int & pos) const;
// private:
// 	QRegExp rx;
// 	QRegExp rx2;
// 	PageSelector * pageSelector;
// };
// 
// PageValidator::PageValidator(int /* min */, int /* max */, QObject * parent) : QValidator
// (parent), rx("^([0-9]+).*"), rx2("^[0-9]+$") 
// {
// 	pageSelector = static_cast<PageSelector*>(parent);
// }
// 
// QValidator::State PageValidator::validate(QString & input, int & /* pos */) const
// {
// 	if (rx2.indexIn(input) == 0 && pageSelector->PageCombo->itemText(input.toInt()-1) == input)
// 		return Acceptable;
// 	else
// 		return Intermediate;
// }
// 
// void PageValidator::fixup(QString & input) const
// {
// 	if (rx.indexIn(input) == 0)
// 		input = const_cast<QRegExp &>(rx).cap(1);
// }
// 	

PageSelector::PageSelector( QWidget* parent, int maxPg ) : QWidget( parent, 0 )
{
	PageCountString = "%1" ;
	LastPG = maxPg;
	APage = 1;
	PageSelectorLayout = new QHBoxLayout( this );
	PageSelectorLayout->setMargin(0);
	PageSelectorLayout->setSpacing(1);

#if OPTION_USE_QTOOLBUTTON
	Start = new QToolButton( this );
	Start->setAutoRaise(OPTION_FLAT_BUTTON);
	Back = new QToolButton( this );
	Back->setAutoRaise(OPTION_FLAT_BUTTON);
	Forward = new QToolButton( this );
	Forward->setAutoRaise(OPTION_FLAT_BUTTON);
	Last = new QToolButton( this );
	Last->setAutoRaise(OPTION_FLAT_BUTTON);
#else
	Start = new QPushButton( this );
	Start->setDefault( false );
	Start->setAutoDefault( false );
	Start->setFlat(OPTION_FLAT_BUTTON);
	Back = new QPushButton( this );
	Back->setDefault( false );
	Back->setAutoDefault( false );
	Back->setFlat(OPTION_FLAT_BUTTON);
	Forward = new QPushButton( this );
	Forward->setDefault( false );
	Forward->setAutoDefault( false );
	Forward->setFlat(OPTION_FLAT_BUTTON);
	Last = new QPushButton( this );
	Last->setDefault( false );
	Last->setAutoDefault( false );
	Last->setFlat(OPTION_FLAT_BUTTON);
#endif
	Start->setIcon(QIcon(loadIcon("16/go-first.png")));
	Start->setFocusPolicy(Qt::NoFocus);
	PageSelectorLayout->addWidget( Start );

	Back->setIcon(QIcon(loadIcon("16/go-previous.png")));
	Back->setFocusPolicy(Qt::NoFocus);
	Back->setAutoRepeat(true);
	PageSelectorLayout->addWidget( Back );

// 	v = new PageValidator(1, LastPG, this);
	m_validator = new QIntValidator(1, LastPG, this);
	PageCombo = new ScComboBox( this );
	PageCombo->setEditable(true);
	PageCombo->setDuplicatesEnabled( false );
	PageCombo->setInsertPolicy(QComboBox::NoInsert);
	PageCombo->lineEdit()->setAlignment(Qt::AlignHCenter);
	for (int a = 0; a < LastPG; ++a)
	{
		PageCombo->addItem(QString::number(a+1));
	}
	PageCombo->setValidator(m_validator);
	PageCombo->setMinimumSize(fontMetrics().width( "999" )+20, 20);
	PageCombo->setFocusPolicy(Qt::ClickFocus);
	PageSelectorLayout->addWidget( PageCombo );
	
	PageCount = new QLabel(PageCountString.arg(LastPG), this);
	PageSelectorLayout->addWidget(PageCount);
			
	Forward->setIcon(QIcon(loadIcon("16/go-next.png")));
	Forward->setFocusPolicy(Qt::NoFocus);
	Forward->setAutoRepeat(true);
	PageSelectorLayout->addWidget( Forward );

	Last->setIcon(QIcon(loadIcon("16/go-last.png")));
	Last->setFocusPolicy(Qt::NoFocus);
	PageSelectorLayout->addWidget( Last );
	Forward->setEnabled(true);
	Last->setEnabled(true);
	Back->setEnabled(false);
	Start->setEnabled(false);
	if (APage == LastPG)
	{
		Forward->setEnabled(false);
		Last->setEnabled(false);
	}

	languageChange();
	// signals and slots connections
	connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
	connect( Back, SIGNAL( clicked() ), this, SLOT( goBk() ) );
	connect( Start, SIGNAL( clicked() ), this, SLOT( ToStart() ) );
	connect( Forward, SIGNAL( clicked() ), this, SLOT( goFw() ) );
	connect( Last, SIGNAL( clicked() ), this, SLOT( ToEnd() ) );
}

bool PageSelector::hasFocus()
{
	return PageCombo->hasFocus();
}


void PageSelector::focusPolicy(Qt::FocusPolicy policy)
{
	PageCombo->setFocusPolicy(policy);
}

void PageSelector::setFont ( const QFont &fo )
{
	PageCount->setFont(fo);
	QWidget::setFont(fo);
}

void PageSelector::GotoPgE(int a)
{
	clearFocus();
	GotoPg(a);
	emit GotoPage(a+1);
}


void PageSelector::GotoPage()
{
	static QRegExp rx("^([0-9])+.*");
	int p = rx.cap(1).toInt();
	if (p < 1)
		p=1;
	if (p > LastPG)
		p = LastPG;
	GotoPg(p-1);
	emit GotoPage(p);
}


void PageSelector::GotoPg(int a)
{
	disconnect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
	PageCombo->setCurrentIndex(a);
	setCurrentComboItem(PageCombo, QString::number(a+1));
	APage = a+1;
	Back->setEnabled(true);
	Start->setEnabled(true);
	Forward->setEnabled(true);
	Last->setEnabled(true);
	if (a == 0)
	{
		Back->setEnabled(false);
		Start->setEnabled(false);
	}
	if (a == LastPG-1)
	{
		Forward->setEnabled(false);
		Last->setEnabled(false);
	}
	connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
}

void PageSelector::setMaximum(int a)
{
	disconnect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
	PageCombo->clear();
	LastPG = a;
//	v->setTop(LastPG);
	m_validator->setRange(1, LastPG);
	for (int b = 0; b < LastPG; ++b)
	{
		PageCombo->addItem(QString::number(b+1));
	}
	setCurrentComboItem(PageCombo, QString::number(APage));
	PageCount->setText(PageCountString.arg(LastPG));
	connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
}

void PageSelector::ToStart()
{
	if (APage == 1)
		return;
	GotoPgE(0);
}

void PageSelector::ToEnd()
{
	if (APage == LastPG)
		return;
	GotoPgE(LastPG-1);
}

void PageSelector::goBk()
{
	APage--;
	if (APage < 1)
		APage = 1;
	GotoPgE(APage-1);
}

void PageSelector::goFw()
{
	APage++;
	if (APage > LastPG)
		APage = LastPG;
	GotoPgE(APage-1);
}

void PageSelector::changeEvent(QEvent *e)
{
	if (e->type() == QEvent::LanguageChange)
		languageChange();
	else
		QWidget::changeEvent(e);
}

void PageSelector::languageChange()
{
	Start->setToolTip( tr("Go to the first page") );
	Back->setToolTip( tr("Go to the previous page") );
	Forward->setToolTip( tr("Go to the next page") );
	Last->setToolTip( tr("Go to the last page") );
	PageCombo->setToolTip( tr("Select the current page") );
	PageCountString =  tr(" of %1", "number of pages in document");
	PageCount->setText(PageCountString.arg(LastPG));
	disconnect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
	setCurrentComboItem(PageCombo, QString::number(APage));
	connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
}

void PageSelector::clearFocus()
{
	PageCombo->clearFocus();	
}