00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "applytemplatedialog.h"
00016
00017 #include <QCheckBox>
00018 #include <QComboBox>
00019 #include <QEvent>
00020 #include <QGroupBox>
00021 #include <QHBoxLayout>
00022 #include <QLabel>
00023 #include <QPushButton>
00024 #include <QRadioButton>
00025 #include <QSpacerItem>
00026 #include <QSpinBox>
00027 #include <QToolTip>
00028 #include <QVBoxLayout>
00029
00030 #include "commonstrings.h"
00031 #include "scribusdoc.h"
00032 #include "page.h"
00033 #include "util_icon.h"
00034
00035 enum {
00036 CurrentPage,
00037 EvenPages,
00038 OddPages,
00039 AllPages
00040 };
00041
00042
00043
00044
00045
00046
00047
00048
00049 ApplyMasterPageDialog::ApplyMasterPageDialog( QWidget* parent ) : QDialog( parent )
00050 {
00051 setModal(true);
00052 setWindowTitle( tr( "Possible Hyphenation" ));
00053 setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
00054 ApplyMasterPageDialogLayout = new QVBoxLayout(this);
00055 ApplyMasterPageDialogLayout->setMargin(10);
00056 ApplyMasterPageDialogLayout->setSpacing(5);
00057
00058 templateNameLayout = new QHBoxLayout;
00059 templateNameLayout->setMargin(0);
00060 templateNameLayout->setSpacing(5);
00061
00062 masterPageLabel = new QLabel( this );
00063 templateNameLayout->addWidget( masterPageLabel );
00064 spacer2 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
00065 templateNameLayout->addItem( spacer2 );
00066
00067 masterPageComboBox = new QComboBox(this);
00068 masterPageComboBox->setEditable(false);
00069 templateNameLayout->addWidget( masterPageComboBox );
00070 ApplyMasterPageDialogLayout->addLayout( templateNameLayout );
00071
00072 applyToPageButtonGroup = new QGroupBox(this);
00073 applyToPageButtonGroup->setMinimumSize( QSize( 250, 0 ) );
00074 applyToPageButtonGroupLayout = new QVBoxLayout(applyToPageButtonGroup);
00075 applyToPageButtonGroupLayout->setSpacing( 5 );
00076 applyToPageButtonGroupLayout->setMargin( 10 );
00077
00078 currentPageRadioButton = new QRadioButton( applyToPageButtonGroup );
00079 currentPageRadioButton->setChecked( true );
00080 applyToPageButtonGroupLayout->addWidget( currentPageRadioButton );
00081
00082 evenPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
00083 applyToPageButtonGroupLayout->addWidget( evenPagesRadioButton );
00084
00085 oddPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
00086 applyToPageButtonGroupLayout->addWidget( oddPagesRadioButton );
00087
00088 allPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
00089 applyToPageButtonGroupLayout->addWidget( allPagesRadioButton );
00090
00091 rangeLayout = new QHBoxLayout;
00092 rangeLayout->setSpacing( 5 );
00093 rangeLayout->setMargin( 0 );
00094
00095 useRangeCheckBox = new QCheckBox( applyToPageButtonGroup );
00096 useRangeCheckBox->setEnabled( false );
00097 rangeLayout->addWidget( useRangeCheckBox );
00098
00099 fromPageSpinBox = new QSpinBox( applyToPageButtonGroup );
00100 fromPageSpinBox->setEnabled( false );
00101 fromPageSpinBox->setMinimum( 1 );
00102 rangeLayout->addWidget( fromPageSpinBox );
00103
00104 toPageLabel = new QLabel( applyToPageButtonGroup );
00105 rangeLayout->addWidget( toPageLabel );
00106
00107 toPageSpinBox = new QSpinBox( applyToPageButtonGroup );
00108 toPageSpinBox->setEnabled( false );
00109 toPageSpinBox->setMinimum( 1 );
00110 rangeLayout->addWidget( toPageSpinBox );
00111 spacer3 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
00112 rangeLayout->addItem( spacer3 );
00113 applyToPageButtonGroupLayout->addLayout( rangeLayout );
00114 ApplyMasterPageDialogLayout->addWidget( applyToPageButtonGroup );
00115
00116 layout8 = new QHBoxLayout;
00117 layout8->setSpacing( 5 );
00118 layout8->setMargin( 0 );
00119 spacer1 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
00120 layout8->addItem( spacer1 );
00121
00122 okButton = new QPushButton( this );
00123 layout8->addWidget( okButton );
00124
00125 cancelButton = new QPushButton( this );
00126 layout8->addWidget( cancelButton );
00127 ApplyMasterPageDialogLayout->addLayout( layout8 );
00128 languageChange();
00129 resize( QSize(272, 230).expandedTo(minimumSizeHint()) );
00130
00131
00132 connect( useRangeCheckBox, SIGNAL( toggled(bool) ), this, SLOT( enableRange(bool) ) );
00133 connect( currentPageRadioButton, SIGNAL( clicked() ), this, SLOT( singleSelectable() ) );
00134 connect( evenPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
00135 connect( oddPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
00136 connect( allPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
00137 connect( fromPageSpinBox, SIGNAL( valueChanged(const QString&) ), this, SLOT( checkRangeFrom() ) );
00138 connect( toPageSpinBox, SIGNAL( valueChanged(int) ), this, SLOT( checkRangeTo() ) );
00139 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00140 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00141
00142
00143 masterPageLabel->setBuddy( masterPageComboBox );
00144 }
00145
00146
00147
00148
00149 ApplyMasterPageDialog::~ApplyMasterPageDialog()
00150 {
00151
00152 }
00153
00154 void ApplyMasterPageDialog::setup(ScribusDoc *view, QString Nam)
00155 {
00156 QString na = Nam == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : Nam, in;
00157 int cc = 0;
00158 for (QMap<QString,int>::Iterator it = view->MasterNames.begin(); it != view->MasterNames.end(); ++it)
00159 {
00160 in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key();
00161 masterPageComboBox->addItem(in);
00162 if (in == na)
00163 masterPageComboBox->setCurrentIndex(cc);
00164 ++cc;
00165 }
00166 const unsigned int docPagesCount = view->Pages->count();
00167 if (docPagesCount < 2)
00168 evenPagesRadioButton->setEnabled(false);
00169 fromPageSpinBox->setMaximum(docPagesCount);
00170 fromPageSpinBox->setValue(view->currentPage()->pageNr()+1);
00171 toPageSpinBox->setMaximum(docPagesCount);
00172 toPageSpinBox->setValue(docPagesCount);
00173 }
00174
00175
00176 QString ApplyMasterPageDialog::getMasterPageName()
00177 {
00178 return masterPageComboBox->currentText();
00179 }
00180
00181
00182 int ApplyMasterPageDialog::getPageSelection()
00183 {
00184 if (currentPageRadioButton->isChecked())
00185 return CurrentPage;
00186 else if (evenPagesRadioButton->isChecked())
00187 return EvenPages;
00188 else if (oddPagesRadioButton->isChecked())
00189 return OddPages;
00190 else
00191 return AllPages;
00192 }
00193
00194 void ApplyMasterPageDialog::checkRangeFrom()
00195 {
00196 disconnect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00197 disconnect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00198 if (fromPageSpinBox->value() > toPageSpinBox->value())
00199 toPageSpinBox->setValue(fromPageSpinBox->value());
00200 connect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00201 connect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00202 }
00203
00204 void ApplyMasterPageDialog::checkRangeTo()
00205 {
00206 disconnect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00207 disconnect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00208 if (toPageSpinBox->value() < fromPageSpinBox->value())
00209 fromPageSpinBox->setValue(toPageSpinBox->value());
00210 connect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00211 connect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00212 }
00213
00214 void ApplyMasterPageDialog::enableRange( bool enabled )
00215 {
00216 fromPageSpinBox->setEnabled(enabled);
00217 toPageSpinBox->setEnabled(enabled);
00218 }
00219
00220 void ApplyMasterPageDialog::rangeSelectable()
00221 {
00222 useRangeCheckBox->setEnabled(true);
00223 enableRange(useRangeCheckBox->isChecked());
00224 }
00225
00226 void ApplyMasterPageDialog::singleSelectable()
00227 {
00228 useRangeCheckBox->setEnabled(false);
00229 fromPageSpinBox->setEnabled(false);
00230 toPageSpinBox->setEnabled(false);
00231 }
00232
00233
00234 bool ApplyMasterPageDialog::usingRange()
00235 {
00236 return useRangeCheckBox->isChecked();
00237 }
00238
00239
00240 int ApplyMasterPageDialog::getFromPage()
00241 {
00242 if (useRangeCheckBox->isChecked())
00243 return fromPageSpinBox->value();
00244 return -1;
00245 }
00246
00247
00248 int ApplyMasterPageDialog::getToPage()
00249 {
00250 if (useRangeCheckBox->isChecked())
00251 return toPageSpinBox->value();
00252 return -1;
00253 }
00254
00255 void ApplyMasterPageDialog::changeEvent(QEvent *e)
00256 {
00257 if (e->type() == QEvent::LanguageChange)
00258 {
00259 languageChange();
00260 }
00261 else
00262 QWidget::changeEvent(e);
00263 }
00264
00265 void ApplyMasterPageDialog::languageChange()
00266 {
00267 setWindowTitle( tr( "Apply Master Page" ) );
00268 masterPageLabel->setText( tr( "&Master Page:" ) );
00269 applyToPageButtonGroup->setTitle( tr( "Apply To" ) );
00270 currentPageRadioButton->setText( tr( "Current &page" ) );
00271 currentPageRadioButton->setShortcut( QKeySequence( tr( "Alt+P" ) ) );
00272 evenPagesRadioButton->setText( tr( "&Even pages" ) );
00273 evenPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+E" ) ) );
00274 oddPagesRadioButton->setText( tr( "O&dd pages" ) );
00275 oddPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+D" ) ) );
00276 allPagesRadioButton->setText( tr( "&All pages" ) );
00277 allPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+A" ) ) );
00278 useRangeCheckBox->setText( tr( "&Within range" ) );
00279 useRangeCheckBox->setShortcut( QKeySequence( tr( "Alt+W" ) ) );
00280 useRangeCheckBox->setToolTip( "<qt>" + tr( "Apply the selected master page to even, odd or all pages within the following range") + "</qt>" );
00281 toPageLabel->setText( tr( "to" ) );
00282 okButton->setText( CommonStrings::tr_OK );
00283 okButton->setShortcut( QKeySequence( tr( "Alt+O" ) ) );
00284 cancelButton->setText( CommonStrings::tr_Cancel );
00285 cancelButton->setShortcut( QKeySequence( tr( "Alt+C" ) ) );
00286 }