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
284
285
286
|
/*
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.
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "applytemplatedialog.h"
#include <QCheckBox>
#include <QComboBox>
#include <QEvent>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QSpacerItem>
#include <QSpinBox>
#include <QToolTip>
#include <QVBoxLayout>
#include "commonstrings.h"
#include "scribusdoc.h"
#include "page.h"
#include "util_icon.h"
enum {
CurrentPage,
EvenPages,
OddPages,
AllPages
};
/*
* Constructs a ApplyMasterPageDialog as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
ApplyMasterPageDialog::ApplyMasterPageDialog( QWidget* parent ) : QDialog( parent )
{
setModal(true);
setWindowTitle( tr( "Possible Hyphenation" ));
setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
ApplyMasterPageDialogLayout = new QVBoxLayout(this);
ApplyMasterPageDialogLayout->setMargin(10);
ApplyMasterPageDialogLayout->setSpacing(5);
templateNameLayout = new QHBoxLayout;
templateNameLayout->setMargin(0);
templateNameLayout->setSpacing(5);
masterPageLabel = new QLabel( this );
templateNameLayout->addWidget( masterPageLabel );
spacer2 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
templateNameLayout->addItem( spacer2 );
masterPageComboBox = new QComboBox(this);
masterPageComboBox->setEditable(false);
templateNameLayout->addWidget( masterPageComboBox );
ApplyMasterPageDialogLayout->addLayout( templateNameLayout );
applyToPageButtonGroup = new QGroupBox(this);
applyToPageButtonGroup->setMinimumSize( QSize( 250, 0 ) );
applyToPageButtonGroupLayout = new QVBoxLayout(applyToPageButtonGroup);
applyToPageButtonGroupLayout->setSpacing( 5 );
applyToPageButtonGroupLayout->setMargin( 10 );
currentPageRadioButton = new QRadioButton( applyToPageButtonGroup );
currentPageRadioButton->setChecked( true );
applyToPageButtonGroupLayout->addWidget( currentPageRadioButton );
evenPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
applyToPageButtonGroupLayout->addWidget( evenPagesRadioButton );
oddPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
applyToPageButtonGroupLayout->addWidget( oddPagesRadioButton );
allPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
applyToPageButtonGroupLayout->addWidget( allPagesRadioButton );
rangeLayout = new QHBoxLayout;
rangeLayout->setSpacing( 5 );
rangeLayout->setMargin( 0 );
useRangeCheckBox = new QCheckBox( applyToPageButtonGroup );
useRangeCheckBox->setEnabled( false );
rangeLayout->addWidget( useRangeCheckBox );
fromPageSpinBox = new QSpinBox( applyToPageButtonGroup );
fromPageSpinBox->setEnabled( false );
fromPageSpinBox->setMinimum( 1 );
rangeLayout->addWidget( fromPageSpinBox );
toPageLabel = new QLabel( applyToPageButtonGroup );
rangeLayout->addWidget( toPageLabel );
toPageSpinBox = new QSpinBox( applyToPageButtonGroup );
toPageSpinBox->setEnabled( false );
toPageSpinBox->setMinimum( 1 );
rangeLayout->addWidget( toPageSpinBox );
spacer3 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
rangeLayout->addItem( spacer3 );
applyToPageButtonGroupLayout->addLayout( rangeLayout );
ApplyMasterPageDialogLayout->addWidget( applyToPageButtonGroup );
layout8 = new QHBoxLayout;
layout8->setSpacing( 5 );
layout8->setMargin( 0 );
spacer1 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
layout8->addItem( spacer1 );
okButton = new QPushButton( this );
layout8->addWidget( okButton );
cancelButton = new QPushButton( this );
layout8->addWidget( cancelButton );
ApplyMasterPageDialogLayout->addLayout( layout8 );
languageChange();
resize( QSize(272, 230).expandedTo(minimumSizeHint()) );
// signals and slots connections
connect( useRangeCheckBox, SIGNAL( toggled(bool) ), this, SLOT( enableRange(bool) ) );
connect( currentPageRadioButton, SIGNAL( clicked() ), this, SLOT( singleSelectable() ) );
connect( evenPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
connect( oddPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
connect( allPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
connect( fromPageSpinBox, SIGNAL( valueChanged(const QString&) ), this, SLOT( checkRangeFrom() ) );
connect( toPageSpinBox, SIGNAL( valueChanged(int) ), this, SLOT( checkRangeTo() ) );
connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
// buddies
masterPageLabel->setBuddy( masterPageComboBox );
}
/*
* Destroys the object and frees any allocated resources
*/
ApplyMasterPageDialog::~ApplyMasterPageDialog()
{
// no need to delete child widgets, Qt does it all for us
}
void ApplyMasterPageDialog::setup(ScribusDoc *view, QString Nam)
{
QString na = Nam == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : Nam, in;
int cc = 0;
for (QMap<QString,int>::Iterator it = view->MasterNames.begin(); it != view->MasterNames.end(); ++it)
{
in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key();
masterPageComboBox->addItem(in);
if (in == na)
masterPageComboBox->setCurrentIndex(cc);
++cc;
}
const unsigned int docPagesCount = view->Pages->count();
if (docPagesCount < 2)
evenPagesRadioButton->setEnabled(false);
fromPageSpinBox->setMaximum(docPagesCount);
fromPageSpinBox->setValue(view->currentPage()->pageNr()+1);
toPageSpinBox->setMaximum(docPagesCount);
toPageSpinBox->setValue(docPagesCount);
}
QString ApplyMasterPageDialog::getMasterPageName()
{
return masterPageComboBox->currentText();
}
int ApplyMasterPageDialog::getPageSelection()
{
if (currentPageRadioButton->isChecked())
return CurrentPage;
else if (evenPagesRadioButton->isChecked())
return EvenPages;
else if (oddPagesRadioButton->isChecked())
return OddPages;
else
return AllPages;
}
void ApplyMasterPageDialog::checkRangeFrom()
{
disconnect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
disconnect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
if (fromPageSpinBox->value() > toPageSpinBox->value())
toPageSpinBox->setValue(fromPageSpinBox->value());
connect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
connect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
}
void ApplyMasterPageDialog::checkRangeTo()
{
disconnect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
disconnect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
if (toPageSpinBox->value() < fromPageSpinBox->value())
fromPageSpinBox->setValue(toPageSpinBox->value());
connect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
connect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
}
void ApplyMasterPageDialog::enableRange( bool enabled )
{
fromPageSpinBox->setEnabled(enabled);
toPageSpinBox->setEnabled(enabled);
}
void ApplyMasterPageDialog::rangeSelectable()
{
useRangeCheckBox->setEnabled(true);
enableRange(useRangeCheckBox->isChecked());
}
void ApplyMasterPageDialog::singleSelectable()
{
useRangeCheckBox->setEnabled(false);
fromPageSpinBox->setEnabled(false);
toPageSpinBox->setEnabled(false);
}
bool ApplyMasterPageDialog::usingRange()
{
return useRangeCheckBox->isChecked();
}
int ApplyMasterPageDialog::getFromPage()
{
if (useRangeCheckBox->isChecked())
return fromPageSpinBox->value();
return -1;
}
int ApplyMasterPageDialog::getToPage()
{
if (useRangeCheckBox->isChecked())
return toPageSpinBox->value();
return -1;
}
void ApplyMasterPageDialog::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange)
{
languageChange();
}
else
QWidget::changeEvent(e);
}
void ApplyMasterPageDialog::languageChange()
{
setWindowTitle( tr( "Apply Master Page" ) );
masterPageLabel->setText( tr( "&Master Page:" ) );
applyToPageButtonGroup->setTitle( tr( "Apply to" ) );
currentPageRadioButton->setText( tr( "Current &Page" ) );
currentPageRadioButton->setShortcut( QKeySequence( tr( "Alt+P" ) ) );
evenPagesRadioButton->setText( tr( "&Even Pages" ) );
evenPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+E" ) ) );
oddPagesRadioButton->setText( tr( "O&dd Pages" ) );
oddPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+D" ) ) );
allPagesRadioButton->setText( tr( "&All Pages" ) );
allPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+A" ) ) );
useRangeCheckBox->setText( tr( "&Within Range" ) );
useRangeCheckBox->setShortcut( QKeySequence( tr( "Alt+W" ) ) );
useRangeCheckBox->setToolTip( "<qt>" + tr( "Apply the selected master page to even, odd or all pages within the following range") + "</qt>" );
toPageLabel->setText( tr( "to" ) );
okButton->setText( CommonStrings::tr_OK );
okButton->setShortcut( QKeySequence( tr( "Alt+O" ) ) );
cancelButton->setText( CommonStrings::tr_Cancel );
cancelButton->setShortcut( QKeySequence( tr( "Alt+C" ) ) );
}
|