Subversion Repositories Scribus

Rev

Rev 5087 | Rev 5785 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 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
*/
2777 fschmid 7
#include <qdialog.h>
8
#include <qlayout.h>
9
#include <qpushbutton.h>
2872 fschmid 10
#include <qgroupbox.h>
11
#include <qlabel.h>
2880 fschmid 12
#include <qcombobox.h>
13
#include <qcheckbox.h>
2777 fschmid 14
 
15
#include "margindialog.h"
16
#include "margindialog.moc"
17
#include "marginWidget.h"
4122 cbradney 18
#include "pagestructs.h"
2777 fschmid 19
#include "page.h"
20
#include "scribusdoc.h"
21
#include "units.h"
2872 fschmid 22
#include "mspinbox.h"
2880 fschmid 23
#include "pagesize.h"
2952 cbradney 24
#include "commonstrings.h"
2777 fschmid 25
 
26
extern QPixmap loadIcon(QString nam);
27
 
28
MarginDialog::MarginDialog( QWidget* parent, ScribusDoc* doc ) : QDialog( parent, "MarginDialog", true, 0 )
29
{
2872 fschmid 30
        setCaption( tr( "Manage Page Properties" ) );
2777 fschmid 31
        setIcon(loadIcon("AppIcon.png"));
2965 cbradney 32
        unitRatio = doc->unitRatio();
2777 fschmid 33
        dialogLayout = new QVBoxLayout( this, 10, 5);
2872 fschmid 34
 
35
        dsGroupBox7 = new QGroupBox( this, "GroupBox7" );
36
        dsGroupBox7->setTitle( tr( "Page Size" ) );
37
        dsGroupBox7->setColumnLayout(0, Qt::Vertical );
38
        dsGroupBox7->layout()->setSpacing( 0 );
39
        dsGroupBox7->layout()->setMargin( 0 );
40
        dsGroupBox7Layout = new QGridLayout( dsGroupBox7->layout() );
41
        dsGroupBox7Layout->setAlignment( Qt::AlignTop );
42
        dsGroupBox7Layout->setSpacing( 5 );
43
        dsGroupBox7Layout->setMargin( 10 );
2880 fschmid 44
        TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7, "TextLabel1" );
45
        dsGroupBox7Layout->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 );
5087 subik 46
        PageSize *ps=new PageSize(doc->currentPage()->PageSize);
2880 fschmid 47
        sizeQComboBox = new QComboBox( true, dsGroupBox7, "ComboBox1" );
48
        sizeQComboBox->setEditable(false);
49
        QStringList pageSizes=ps->getPageSizeList();
50
        sizeQComboBox->insertStringList(ps->getTrPageSizeList());
51
        sizeQComboBox->insertItem( tr( "Custom" ) );
52
        prefsPageSizeName=ps->getPageName();
53
        int sizeIndex = pageSizes.findIndex(ps->getPageText());
54
        if (sizeIndex != -1)
55
                sizeQComboBox->setCurrentItem(sizeIndex);
56
        else
57
                sizeQComboBox->setCurrentItem(sizeQComboBox->count()-1);
58
        TextLabel1->setBuddy(sizeQComboBox);
59
        dsGroupBox7Layout->addMultiCellWidget(sizeQComboBox, 0, 0, 2, 3);
60
        TextLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7, "TextLabel2" );
61
        dsGroupBox7Layout->addMultiCellWidget( TextLabel2, 1, 1, 0, 1 );
62
        orientationQComboBox = new QComboBox( true, dsGroupBox7, "ComboBox2" );
63
        orientationQComboBox->insertItem( tr( "Portrait" ) );
64
        orientationQComboBox->insertItem( tr( "Landscape" ) );
65
        orientationQComboBox->setEditable(false);
5087 subik 66
        orientationQComboBox->setCurrentItem(doc->currentPage()->PageOri );
67
        oldOri = doc->currentPage()->PageOri;
2880 fschmid 68
        TextLabel2->setBuddy(orientationQComboBox);
69
        dsGroupBox7Layout->addMultiCellWidget( orientationQComboBox, 1, 1, 2, 3 );
2965 cbradney 70
        widthMSpinBox = new MSpinBox( 1, 100000, dsGroupBox7, unitGetDecimalsFromIndex(doc->unitIndex()) );
2872 fschmid 71
        widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7, "widthLabel" );
2965 cbradney 72
        widthMSpinBox->setSuffix(unitGetSuffixFromIndex(doc->unitIndex()));
5087 subik 73
        widthMSpinBox->setValue(doc->currentPage()->width() * doc->unitRatio());
2872 fschmid 74
        widthQLabel->setBuddy(widthMSpinBox);
2880 fschmid 75
        dsGroupBox7Layout->addWidget( widthQLabel, 2, 0 );
76
        dsGroupBox7Layout->addWidget( widthMSpinBox, 2, 1 );
2965 cbradney 77
        heightMSpinBox = new MSpinBox( 1, 100000, dsGroupBox7, unitGetDecimalsFromIndex(doc->unitIndex()) );
78
        heightMSpinBox->setSuffix(unitGetSuffixFromIndex(doc->unitIndex()));
5087 subik 79
        heightMSpinBox->setValue(doc->currentPage()->height() * doc->unitRatio());
2872 fschmid 80
        heightQLabel = new QLabel(heightMSpinBox,  tr( "&Height:" ), dsGroupBox7, "heightLabel" );
2880 fschmid 81
        dsGroupBox7Layout->addWidget( heightQLabel, 2, 2 );
82
        dsGroupBox7Layout->addWidget( heightMSpinBox, 2, 3 );
83
        moveObjects = new QCheckBox( dsGroupBox7, "moveObjects" );
84
        moveObjects->setText( tr( "Move Objects with their Page" ) );
85
        moveObjects->setChecked( true );
86
        dsGroupBox7Layout->addMultiCellWidget( moveObjects, 3, 3, 0, 3 );
4840 cbradney 87
        Links=0;
3724 cbradney 88
        if ((doc->currentPageLayout != singlePage) && (doc->masterPageMode()))
3035 fschmid 89
        {
90
                TextLabel3 = new QLabel( tr( "Type:" ), dsGroupBox7, "TextLabel3" );
91
                dsGroupBox7Layout->addMultiCellWidget( TextLabel3, 4, 4, 0, 1 );
92
                Links = new QComboBox( true, dsGroupBox7, "links" );
93
                QStringList::Iterator pNames;
94
                for(pNames = doc->pageSets[doc->currentPageLayout].pageNames.begin(); pNames != doc->pageSets[doc->currentPageLayout].pageNames.end(); ++pNames )
95
                {
4984 cbradney 96
                        //Links->insertItem((*pNames));
97
                        Links->insertItem(CommonStrings::translatePageSetLocString((*pNames)));
3035 fschmid 98
                }
99
                Links->setEditable(false);
100
                dsGroupBox7Layout->addMultiCellWidget( Links, 4, 4, 2, 3 );
5087 subik 101
                if (doc->currentPage()->LeftPg == 0)
3035 fschmid 102
                        Links->setCurrentItem(Links->count()-1);
5087 subik 103
                else if (doc->currentPage()->LeftPg == 1)
3035 fschmid 104
                        Links->setCurrentItem(0);
105
                else
5087 subik 106
                        Links->setCurrentItem(doc->currentPage()->LeftPg-1);
3035 fschmid 107
        }
2872 fschmid 108
        dialogLayout->addWidget( dsGroupBox7 );
109
 
4853 cbradney 110
        //GroupRand = new MarginWidget(this,  tr( "Margin Guides" ), &doc->currentPage->initialMargins, doc->unitIndex());
5087 subik 111
        GroupRand = new MarginWidget(this,  tr( "Margin Guides" ), &doc->currentPage()->Margins, doc->unitIndex());
112
        GroupRand->setPageWidthHeight(doc->currentPage()->width(), doc->currentPage()->height());
3032 fschmid 113
        GroupRand->setFacingPages(!(doc->currentPageLayout == singlePage));
2777 fschmid 114
        dialogLayout->addWidget( GroupRand );
115
 
116
        okCancelLayout = new QHBoxLayout;
117
        okCancelLayout->setSpacing( 6 );
118
        okCancelLayout->setMargin( 0 );
119
        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
120
        okCancelLayout->addItem( spacer );
2952 cbradney 121
        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
2777 fschmid 122
        okButton->setDefault( true );
123
        okCancelLayout->addWidget(okButton);
2952 cbradney 124
        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
2777 fschmid 125
        cancelButton->setDefault( false );
126
        okCancelLayout->addWidget(cancelButton);
127
        dialogLayout->addLayout( okCancelLayout );
128
        setMaximumSize(sizeHint());
2880 fschmid 129
        pageWidth = widthMSpinBox->value() / unitRatio;
130
        pageHeight = heightMSpinBox->value() / unitRatio;
131
        if (sizeQComboBox->currentText() == tr("Custom"))
132
        {
133
                heightMSpinBox->setEnabled( true );
134
                widthMSpinBox->setEnabled( true );
135
        }
136
        else
137
        {
138
                heightMSpinBox->setEnabled( false );
139
                widthMSpinBox->setEnabled( false );
140
        }
141
        delete ps;
2777 fschmid 142
        // signals and slots connections
143
        connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
144
        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
2880 fschmid 145
        connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
2923 fschmid 146
        connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
2880 fschmid 147
        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
148
        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
5363 cbradney 149
 
150
        setPageSize();
2880 fschmid 151
        setMinimumSize(minimumSizeHint());
152
        setMaximumSize(minimumSizeHint());
153
        resize(minimumSizeHint());
2777 fschmid 154
}
2880 fschmid 155
 
156
void MarginDialog::setPageWidth(int)
157
{
158
        pageWidth = widthMSpinBox->value() / unitRatio;
159
        GroupRand->setPageWidth(pageWidth);
160
}
161
 
162
void MarginDialog::setPageHeight(int)
163
{
164
        pageHeight = heightMSpinBox->value() / unitRatio;
165
        GroupRand->setPageHeight(pageHeight);
166
}
167
 
2923 fschmid 168
void MarginDialog::setPageSize()
169
{
170
        setOrien(orientationQComboBox->currentItem());
171
}
172
 
2880 fschmid 173
void MarginDialog::setSize(const QString & gr)
174
{
175
        pageWidth = widthMSpinBox->value() / unitRatio;
176
        pageHeight = heightMSpinBox->value() / unitRatio;
177
        widthMSpinBox->setEnabled(false);
178
        heightMSpinBox->setEnabled(false);
179
        PageSize *ps2 = new PageSize(gr);
180
        prefsPageSizeName = ps2->getPageName();
181
        if (gr == tr("Custom"))
182
        {
183
                widthMSpinBox->setEnabled(true);
184
                heightMSpinBox->setEnabled(true);
185
        }
186
        else
187
        {
188
                pageWidth = ps2->getPageWidth();
189
                pageHeight = ps2->getPageHeight();
190
        }
191
        disconnect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
192
        disconnect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
193
        widthMSpinBox->setValue(pageWidth * unitRatio);
194
        heightMSpinBox->setValue(pageHeight * unitRatio);
195
        GroupRand->setPageHeight(pageHeight);
196
        GroupRand->setPageWidth(pageWidth);
5363 cbradney 197
        GroupRand->setPageSize(gr);
2880 fschmid 198
        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
199
        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
200
        delete ps2;
201
}
202
 
203
void MarginDialog::setOrien(int ori)
204
{
205
        double br;
206
        setSize(sizeQComboBox->currentText());
207
        disconnect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
208
        disconnect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
2966 fschmid 209
        if ((sizeQComboBox->currentText() == tr("Custom")) && (ori != oldOri))
2880 fschmid 210
        {
2966 fschmid 211
                br = widthMSpinBox->value();
212
                widthMSpinBox->setValue(heightMSpinBox->value());
213
                heightMSpinBox->setValue(br);
214
        }
215
        else
216
        {
217
                if (ori != 0)
2880 fschmid 218
                {
219
                        br = widthMSpinBox->value();
220
                        widthMSpinBox->setValue(heightMSpinBox->value());
221
                        heightMSpinBox->setValue(br);
222
                }
223
        }
2966 fschmid 224
        oldOri = ori;
2880 fschmid 225
        pageWidth = widthMSpinBox->value() / unitRatio;
226
        pageHeight = heightMSpinBox->value() / unitRatio;
227
        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
228
        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
229
}
4638 subik 230
 
231
int MarginDialog::pageOrder()
232
{
4840 cbradney 233
        int lp=0;
234
        if (Links!=0)
235
                lp = Links->currentItem();
4638 subik 236
        if (lp == 0)
237
                lp = 1;
238
        else if (lp == static_cast<int>(Links->count()-1))
239
                lp = 0;
240
        else
241
                lp++;
242
        return lp;
243
}
244
 
245
double MarginDialog::getPageWidth()
246
{
247
        return pageWidth;
248
}
249
 
250
double MarginDialog::getPageHeight()
251
{
252
        return pageHeight;
253
}
254
 
255
int MarginDialog::getPageOrientation()
256
{
257
        return orientationQComboBox->currentItem();
258
}
259
 
260
QString MarginDialog::getpPrefsPageSizeName()
261
{
262
        return prefsPageSizeName;
263
}
264
 
265
bool MarginDialog::getMoveObjects()
266
{
267
        return moveObjects->isChecked();
268
}
269
 
270
double MarginDialog::top()
271
{
272
        return GroupRand->top();
273
}
274
 
275
double MarginDialog::bottom()
276
{
277
        return GroupRand->bottom();
278
}
279
 
280
double MarginDialog::left()
281
{
282
        return GroupRand->left();
283
}
284
 
285
double MarginDialog::right()
286
{
287
        return GroupRand->right();
288
}