Subversion Repositories Scribus

Rev

Rev 7855 | 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
*/
879 fschmid 7
#include "tabguides.h"
8
#include "tabguides.moc"
9
#include <qlayout.h>
10
#include <qgroupbox.h>
1187 fschmid 11
#include <qbuttongroup.h>
12
#include <qradiobutton.h>
879 fschmid 13
#include <qlabel.h>
14
#include <qtooltip.h>
15
#include <qspinbox.h>
16
#include <qcolor.h>
17
#include <qcolordialog.h>
18
#include <qcheckbox.h>
19
#include <qpushbutton.h>
20
#include <qpixmap.h>
21
#include "mspinbox.h"
2834 cbradney 22
#include "prefsstructs.h"
879 fschmid 23
#include "scribusstructs.h"
1790 cbradney 24
#include "units.h"
879 fschmid 25
 
1790 cbradney 26
TabGuides::TabGuides( QWidget* parent, struct guidesPrefs *prefsData, struct typoPrefs *prefsData2, int unitIndex) : QWidget( parent, "tabguide", 0 )
879 fschmid 27
{
5851 subik 28
        double unitRatio = unitGetRatioFromIndex(unitIndex);
29
        QString unit = unitGetSuffixFromIndex(unitIndex);
30
        int precision = unitGetPrecisionFromIndex(unitIndex);
31
 
1877 cbradney 32
        tabGuidesLayout = new QVBoxLayout( this, 0, 5, "tabViewLayout");
1195 fschmid 33
 
34
        commonBox = new QGroupBox( this, "commonBox" );
35
        commonBox->setTitle( tr( "Common Settings" ) );
36
        commonBox->setColumnLayout(0, Qt::Vertical );
37
        commonBox->layout()->setSpacing( 5 );
38
        commonBox->layout()->setMargin( 10 );
39
        commonBoxLayout = new QHBoxLayout( commonBox->layout() );
40
 
41
        buttonGroup1 = new QButtonGroup( commonBox, "buttonGroup1" );
42
        buttonGroup1->setExclusive( true );
43
        buttonGroup1->setColumnLayout(0, Qt::Horizontal );
44
        buttonGroup1->layout()->setSpacing( 5 );
45
        buttonGroup1->layout()->setMargin( 10 );
46
        buttonGroup1->setTitle( tr( "Placing in Documents" ) );
47
        buttonGroup1Layout = new QVBoxLayout( buttonGroup1->layout() );
48
        buttonGroup1Layout->setAlignment( Qt::AlignTop );
49
        inBackground = new QRadioButton( buttonGroup1, "inBackground" );
50
        inBackground->setText( tr( "In the Background" ) );
51
        buttonGroup1Layout->addWidget( inBackground );
52
        inForeground = new QRadioButton( buttonGroup1, "inForeground" );
53
        inForeground->setText( tr( "In the Foreground" ) );
54
        buttonGroup1Layout->addWidget( inForeground );
55
        commonBoxLayout->addWidget( buttonGroup1 );
56
 
57
        snapBox = new QGroupBox( commonBox, "snapBox" );
58
        snapBox->setTitle( tr( "Snapping" ) );
59
        snapBox->setColumnLayout(0, Qt::Vertical );
60
        snapBox->layout()->setSpacing( 5 );
61
        snapBox->layout()->setMargin( 10 );
62
        snapBoxLayout = new QGridLayout( snapBox->layout() );
63
        textLabel8 = new QLabel( snapBox, "textLabel8" );
64
        textLabel8->setText( tr( "Snap Distance:" ) );
65
        snapBoxLayout->addWidget( textLabel8, 0, 0 );
7855 fschmid 66
        snapDistance = new QSpinBox( snapBox, "snapDistance" );
67
        snapDistance->setMaxValue( 1000 );
68
        snapDistance->setMinValue( 1 );
69
        snapDistance->setLineStep( 1 );
1195 fschmid 70
        snapBoxLayout->addWidget( snapDistance, 0, 1 );
71
        textLabel82 = new QLabel( snapBox, "textLabel8" );
72
        textLabel82->setText( tr( "Grab Radius:" ) );
73
        snapBoxLayout->addWidget( textLabel82, 1, 0 );
74
        grabDistance = new QSpinBox( snapBox, "grabDistance" );
75
        grabDistance->setMaxValue( 1000 );
76
        grabDistance->setMinValue( 1 );
77
        grabDistance->setLineStep( 1 );
78
        snapBoxLayout->addWidget( grabDistance, 1, 1 );
79
        commonBoxLayout->addWidget( snapBox );
80
        tabGuidesLayout->addWidget( commonBox );
81
        layout9 = new QHBoxLayout( 0, 0, 5, "layout9");
82
        guideBox = new QGroupBox( this, "guideBox" );
1834 fschmid 83
        guideBox->setTitle( tr( "Show Guides" ) );
84
        guideBox->setCheckable( true );
1195 fschmid 85
        guideBox->setColumnLayout(0, Qt::Vertical );
86
        guideBox->layout()->setSpacing( 5 );
87
        guideBox->layout()->setMargin( 10 );
88
        guideBoxLayout = new QHBoxLayout( guideBox->layout() );
1834 fschmid 89
        checkGuides = new QLabel( guideBox, "checkGuides" );
90
        checkGuides->setText( tr( "Color:" ) );
1195 fschmid 91
        guideBoxLayout->addWidget( checkGuides );
92
        guideColor = new QPushButton( guideBox, "guideColor" );
93
        guideColor->setMinimumSize( QSize( 60, 20 ) );
94
        guideColor->setMaximumSize( QSize( 60, 20 ) );
95
        guideColor->setFlat( false );
96
        guideColor->setAutoDefault( false );
97
        guideColor->setText( QString::null );
98
        guideBoxLayout->addWidget( guideColor );
99
        layout9->addWidget( guideBox );
100
        marginBox = new QGroupBox( this, "guideBox" );
1834 fschmid 101
        marginBox->setCheckable( true );
102
        marginBox->setTitle( tr( "Show Margins" ) );
1195 fschmid 103
        marginBox->setColumnLayout(0, Qt::Vertical );
104
        marginBox->layout()->setSpacing( 5 );
105
        marginBox->layout()->setMargin( 10 );
106
        marginBoxLayout = new QHBoxLayout( marginBox->layout() );
1834 fschmid 107
        checkMargin = new QLabel( marginBox, "checkMargin" );
108
        checkMargin->setText( tr( "Color:" ) );
1195 fschmid 109
        marginBoxLayout->addWidget( checkMargin );
110
        marginColor = new QPushButton( marginBox, "marginColor" );
111
        marginColor->setMinimumSize( QSize( 60, 20 ) );
112
        marginColor->setMaximumSize( QSize( 60, 20 ) );
113
        marginColor->setAutoDefault( false );
114
        marginColor->setFlat( false );
115
        marginColor->setText( QString::null );
116
        marginBoxLayout->addWidget( marginColor );
117
        layout9->addWidget( marginBox );
118
        tabGuidesLayout->addLayout( layout9 );
119
 
879 fschmid 120
        checkGrid = new QGroupBox( this, "checkGrid" );
1195 fschmid 121
        checkGrid->setTitle( tr( "Show Page Grid" ) );
879 fschmid 122
        checkGrid->setCheckable( true );
123
        checkGrid->setColumnLayout(0, Qt::Vertical );
124
        checkGrid->layout()->setSpacing( 5 );
125
        checkGrid->layout()->setMargin( 10 );
126
        checkGridLayout = new QGridLayout( checkGrid->layout() );
127
        checkGridLayout->setAlignment( Qt::AlignTop );
128
        groupBox1 = new QGroupBox( checkGrid, "groupBox1" );
129
        groupBox1->setColumnLayout(0, Qt::Vertical );
130
        groupBox1->layout()->setSpacing( 5 );
131
        groupBox1->layout()->setMargin( 10 );
132
        groupBox1->setTitle( tr( "Major Grid" ) );
133
        groupBox1Layout = new QGridLayout( groupBox1->layout() );
134
        groupBox1Layout->setAlignment( Qt::AlignTop );
135
        majorGridColor = new QPushButton( groupBox1, "majorGridColor" );
136
        majorGridColor->setMinimumSize( QSize( 60, 20 ) );
137
        majorGridColor->setMaximumSize( QSize( 60, 20 ) );
138
        majorGridColor->setFlat( false );
139
        majorGridColor->setAutoDefault( false );
140
        majorGridColor->setText( QString::null );
141
        groupBox1Layout->addWidget( majorGridColor, 1, 1 );
142
        textLabel4 = new QLabel( groupBox1, "textLabel4" );
143
        textLabel4->setText( tr( "Color:" ) );
144
        groupBox1Layout->addWidget( textLabel4, 1, 0 );
145
        textLabel6 = new QLabel( groupBox1, "textLabel6" );
146
        textLabel6->setText( tr( "Spacing:" ) );
147
        groupBox1Layout->addWidget( textLabel6, 0, 0 );
1790 cbradney 148
        majorSpace = new MSpinBox( 10 * unitRatio, 1000 * unitRatio, groupBox1, precision );
879 fschmid 149
        groupBox1Layout->addWidget( majorSpace, 0, 1 );
150
        checkGridLayout->addWidget( groupBox1, 0, 0 );
151
        groupBox2 = new QGroupBox( checkGrid, "groupBox2" );
152
        groupBox2->setColumnLayout(0, Qt::Vertical );
153
        groupBox2->layout()->setSpacing( 5 );
154
        groupBox2->layout()->setMargin( 10 );
155
        groupBox2->setTitle( tr( "Minor Grid" ) );
156
        groupBox2Layout = new QGridLayout( groupBox2->layout() );
157
        groupBox2Layout->setAlignment( Qt::AlignTop );
158
        textLabel5 = new QLabel( groupBox2, "textLabel5" );
159
        textLabel5->setText( tr( "Color:" ) );
160
        groupBox2Layout->addWidget( textLabel5, 1, 0 );
161
        minorGridColor = new QPushButton( groupBox2, "minorGridColor" );
162
        minorGridColor->setMinimumSize( QSize( 60, 20 ) );
163
        minorGridColor->setMaximumSize( QSize( 60, 20 ) );
164
        minorGridColor->setFlat( false );
165
        minorGridColor->setAutoDefault( false );
166
        minorGridColor->setText( QString::null );
167
        groupBox2Layout->addWidget( minorGridColor, 1, 1 );
168
        textLabel7 = new QLabel( groupBox2, "textLabel7" );
169
        textLabel7->setText( tr( "Spacing:" ) );
170
        groupBox2Layout->addWidget( textLabel7, 0, 0 );
1790 cbradney 171
        minorSpace = new MSpinBox( unitRatio, 1000 * unitRatio, groupBox2, precision );
879 fschmid 172
        groupBox2Layout->addWidget( minorSpace, 0, 1 );
173
        checkGridLayout->addWidget( groupBox2, 0, 1 );
174
        tabGuidesLayout->addWidget( checkGrid );
175
 
1834 fschmid 176
        layout9a = new QHBoxLayout( 0, 0, 5, "layout9");
1195 fschmid 177
        baselineBox = new QGroupBox( this, "baselineBox" );
1834 fschmid 178
        baselineBox->setTitle( tr( "Show Baseline Grid" ) );
179
        baselineBox->setCheckable( true );
1195 fschmid 180
        baselineBox->setColumnLayout(0, Qt::Vertical );
181
        baselineBox->layout()->setSpacing( 5 );
182
        baselineBox->layout()->setMargin( 10 );
183
        baselineBoxLayout = new QGridLayout( baselineBox->layout() );
184
        baselineBoxLayout->setAlignment( Qt::AlignTop );
1834 fschmid 185
        checkBaseline = new QLabel( baselineBox, "checkBaseline" );
1877 cbradney 186
        checkBaseline->setText( tr( "Color:" ) );
1195 fschmid 187
        baselineBoxLayout->addWidget( checkBaseline, 0, 0 );
188
        baselineColor = new QPushButton( baselineBox, "baselineColor" );
879 fschmid 189
        baselineColor->setMinimumSize( QSize( 60, 20 ) );
190
        baselineColor->setMaximumSize( QSize( 60, 20 ) );
191
        baselineColor->setFlat( false );
192
        baselineColor->setAutoDefault( false );
193
        baselineColor->setText( QString::null );
1195 fschmid 194
        baselineBoxLayout->addWidget( baselineColor, 0, 1 );
1834 fschmid 195
        layout9a->addWidget( baselineBox );
196
 
197
        baseGridBox = new QGroupBox( this, "baseGridBox" );
198
        baseGridBox->setTitle( tr( "Baseline Settings" ) );
199
        baseGridBox->setColumnLayout(0, Qt::Vertical );
200
        baseGridBox->layout()->setSpacing( 5 );
201
        baseGridBox->layout()->setMargin( 10 );
202
        baseGridBoxLayout = new QGridLayout( baseGridBox->layout() );
203
        baseGridBoxLayout->setAlignment( Qt::AlignTop );
2150 cbradney 204
        baseGrid = new MSpinBox( baseGridBox, precision );
205
        baseGrid->setMaxValue(1000);
206
        baseGrid->setMinValue(pts2value(1.0, unitIndex));
1834 fschmid 207
        baseGridBoxLayout->addWidget( baseGrid, 0, 1 );
208
        textLabel6a = new QLabel(baseGrid, tr( "Baseline &Grid:" ), baseGridBox, "textLabel6a" );
209
        baseGridBoxLayout->addWidget( textLabel6a, 0, 0 );
210
        baseOffset = new MSpinBox( 0, 1000, baseGridBox, precision );
211
        baseGridBoxLayout->addWidget( baseOffset, 1, 1 );
212
        textLabel7a = new QLabel(baseOffset, tr( "Baseline &Offset:" ), baseGridBox, "textLabel7a" );
213
        baseGridBoxLayout->addWidget( textLabel7a, 1, 0 );
214
        layout9a->addWidget( baseGridBox );
215
        tabGuidesLayout->addLayout( layout9a );
1195 fschmid 216
 
5763 subik 217
        // switched off as it's called in main prefs classes - PV
218
        //restoreDefaults(prefsData, prefsData2, unitIndex);
5711 subik 219
 
879 fschmid 220
        connect(majorGridColor, SIGNAL(clicked()), this, SLOT(changeMajorColor()));
221
        connect(minorGridColor, SIGNAL(clicked()), this, SLOT(changeMinorColor()));
222
        connect(baselineColor, SIGNAL(clicked()), this, SLOT(changeBaselineColor()));
223
        connect(guideColor, SIGNAL(clicked()), this, SLOT(changeGuideColor()));
224
        connect(marginColor, SIGNAL(clicked()), this, SLOT(changeMarginColor()));
2598 cbradney 225
        QToolTip::add( inBackground, tr( "Guides are not visible through objects on the page" ) );
226
        QToolTip::add( inForeground, tr( "Guides are visible above all objects on the page" ) );
879 fschmid 227
        QToolTip::add( minorSpace, tr( "Distance between the minor grid lines" ) );
228
        QToolTip::add( majorSpace, tr( "Distance between the major grid lines" ) );
229
        QToolTip::add( snapDistance, tr( "Distance within which an object will snap to your placed guides" ) );
230
        QToolTip::add( grabDistance, tr( "Radius of the area where Scribus will allow you to grab an objects handles" ) );
231
        QToolTip::add( minorGridColor, tr( "Color of the minor grid lines" ) );
232
        QToolTip::add( majorGridColor, tr( "Color of the major grid lines" ) );
233
        QToolTip::add( guideColor, tr( "Color of the guide lines you insert" ) );
234
        QToolTip::add( marginColor, tr( "Color for the margin lines" ) );
1877 cbradney 235
        QToolTip::add( baselineColor, tr( "Color for the baseline grid" ) );
1834 fschmid 236
        QToolTip::add( baselineBox, tr("Turns the basegrid on or off"));
2598 cbradney 237
        QToolTip::add( baseGrid, tr("Distance between the lines of the baseline grid"));
238
        QToolTip::add( baseOffset, tr("Distance from the top of the page for the first baseline"));
879 fschmid 239
        QToolTip::add( checkGrid, tr("Turns the gridlines on or off"));
1834 fschmid 240
        QToolTip::add( guideBox, tr("Turns the guides on or off"));
241
        QToolTip::add( marginBox, tr("Turns the margins on or off"));
879 fschmid 242
}
243
 
1833 fschmid 244
void TabGuides::restoreDefaults(struct guidesPrefs *prefsData, struct typoPrefs *prefsData2, int unitIndex)
1828 fschmid 245
{
5851 subik 246
        QString unit = unitGetSuffixFromIndex(unitIndex);
247
        double unitRatio = unitGetRatioFromIndex(unitIndex);
248
 
3333 avox 249
        QPixmap pm3(54, 14);
1833 fschmid 250
        pm3.fill(prefsData->guideColor);
251
        colorGuides = prefsData->guideColor;
252
        guideColor->setPixmap(pm3);
3333 avox 253
        QPixmap pm6(54, 14);
1833 fschmid 254
        pm6.fill(prefsData->margColor);
255
        colorMargin = prefsData->margColor;
256
        marginColor->setPixmap(pm6);
3333 avox 257
        QPixmap pm1(54, 14);
1833 fschmid 258
        pm1.fill(prefsData->majorColor);
259
        colorMajorGrid = prefsData->majorColor;
260
        majorGridColor->setPixmap(pm1);
3333 avox 261
        QPixmap pm(54, 14);
1833 fschmid 262
        pm.fill(prefsData->minorColor);
263
        colorMinorGrid = prefsData->minorColor;
264
        minorGridColor->setPixmap(pm);
3333 avox 265
        QPixmap pm4(54, 14);
1833 fschmid 266
        pm4.fill(prefsData->baseColor);
267
        colorBaselineGrid = prefsData->baseColor;
268
        baselineColor->setPixmap(pm4);
269
        minorSpace->setValue(prefsData->minorGrid  * unitRatio);
5711 subik 270
        minorSpace->setSuffix( unit );
1833 fschmid 271
        majorSpace->setValue(prefsData->majorGrid * unitRatio);
5711 subik 272
        majorSpace->setSuffix( unit );
7978 fschmid 273
        snapDistance->setValue(qRound(prefsData->guideRad));
7855 fschmid 274
        snapDistance->setSuffix( " " + tr( "px" ) );
1833 fschmid 275
        grabDistance->setValue(prefsData->grabRad);
7855 fschmid 276
        grabDistance->setSuffix( " " + tr( " px" ) );
1833 fschmid 277
        baseGrid->setValue(prefsData2->valueBaseGrid * unitRatio);
5711 subik 278
        baseGrid->setSuffix( unit );
1833 fschmid 279
        baseOffset->setValue(prefsData2->offsetBaseGrid * unitRatio);
5711 subik 280
        baseOffset->setSuffix( unit );
1833 fschmid 281
        inBackground->setChecked( prefsData->before );
282
        inForeground->setChecked( !prefsData->before );
1834 fschmid 283
        baselineBox->setChecked(prefsData->baseShown);
1833 fschmid 284
        checkGrid->setChecked(prefsData->gridShown);
1834 fschmid 285
        marginBox->setChecked(prefsData->marginsShown);
286
        guideBox->setChecked(prefsData->guidesShown);
1828 fschmid 287
}
288
 
879 fschmid 289
void TabGuides::changeMajorColor()
290
{
291
        QColor neu = QColor();
292
        neu = QColorDialog::getColor(colorMajorGrid, this);
293
        if (neu.isValid())
294
        {
3333 avox 295
                QPixmap pm(54, 14);
879 fschmid 296
                pm.fill(neu);
297
                colorMajorGrid = neu;
298
                majorGridColor->setPixmap(pm);
299
        }
300
}
301
 
302
void TabGuides::changeMinorColor()
303
{
304
        QColor neu = QColor();
305
        neu = QColorDialog::getColor(colorMinorGrid, this);
306
        if (neu.isValid())
307
        {
3333 avox 308
                QPixmap pm(54, 14);
879 fschmid 309
                pm.fill(neu);
310
                colorMinorGrid = neu;
311
                minorGridColor->setPixmap(pm);
312
        }
313
}
314
 
315
void TabGuides::changeBaselineColor()
316
{
317
        QColor neu = QColor();
318
        neu = QColorDialog::getColor(colorBaselineGrid, this);
319
        if (neu.isValid())
320
        {
3333 avox 321
                QPixmap pm(54, 14);
879 fschmid 322
                pm.fill(neu);
323
                colorBaselineGrid = neu;
324
                baselineColor->setPixmap(pm);
325
        }
326
}
327
 
328
void TabGuides::changeGuideColor()
329
{
330
        QColor neu = QColor();
331
        neu = QColorDialog::getColor(colorGuides, this);
332
        if (neu.isValid())
333
        {
3333 avox 334
                QPixmap pm(54, 14);
879 fschmid 335
                pm.fill(neu);
336
                colorGuides = neu;
337
                guideColor->setPixmap(pm);
338
        }
339
}
340
 
341
void TabGuides::changeMarginColor()
342
{
343
        QColor neu = QColor();
344
        neu = QColorDialog::getColor(colorMargin, this);
345
        if (neu.isValid())
346
        {
3333 avox 347
                QPixmap pm(54, 14);
879 fschmid 348
                pm.fill(neu);
349
                colorMargin = neu;
350
                marginColor->setPixmap(pm);
351
        }
352
}
5851 subik 353
 
354
void TabGuides::unitChange(QString unit, int docUnitIndex, int decimals, double invUnitConversion)
355
{
356
        double oldMin, oldMax, val;
357
        int decimalsOld;
358
 
359
        minorSpace->setSuffix(unit);
360
        majorSpace->setSuffix(unit);
361
        baseGrid->setSuffix(unit);
362
        baseOffset->setSuffix(unit);
363
 
364
        minorSpace->getValues(&oldMin, &oldMax, &decimalsOld, &val);
365
        minorSpace->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
366
        majorSpace->getValues(&oldMin, &oldMax, &decimalsOld, &val);
367
        majorSpace->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
368
        baseGrid->getValues(&oldMin, &oldMax, &decimalsOld, &val);
369
        baseGrid->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
370
        baseOffset->getValues(&oldMin, &oldMax, &decimalsOld, &val);
371
        baseOffset->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
372
}