Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
13761 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
*/
7
 
14030 cbradney 8
#include <QApplication>
9
#include <QColor>
10
#include <QColorDialog>
11
#include <QDesktopWidget>
12
#include <QPainter>
13
 
13761 cbradney 14
#include "prefs_display.h"
14023 cbradney 15
#include "prefsstructs.h"
16
#include "units.h"
14030 cbradney 17
#include "util_icon.h"
14023 cbradney 18
 
13761 cbradney 19
Prefs_Display::Prefs_Display(QWidget* parent)
14046 cbradney 20
        : Prefs_Pane(parent)
13761 cbradney 21
{
22
        setupUi(this);
14030 cbradney 23
        languageChange();
24
 
25
        buttonRestoreDPI->setIcon(QIcon(loadIcon("screen.png")));
26
 
27
        connect(pageFillColorButton, SIGNAL(clicked()), this, SLOT(changePaperColor()));
28
        connect(frameSelectedColorButton, SIGNAL(clicked()), this, SLOT(changeFrameColor()));
29
        connect(frameColorButton, SIGNAL(clicked()), this, SLOT(changeNormFrameColor()));
30
        connect(frameGroupedColorButton, SIGNAL(clicked()), this, SLOT(changeGroupFrameColor()));
31
        connect(frameLinkedColorButton, SIGNAL(clicked()), this, SLOT(changeChainFrameColor()));
32
        connect(frameLockedColorButton, SIGNAL(clicked()), this, SLOT(changeLockFrameColor()));
33
        connect(frameAnnotationColorButton, SIGNAL(clicked()), this, SLOT(changeAnnotFrameColor()));
34
        connect(selectedPageBorderButton, SIGNAL(clicked()), this, SLOT(changePageBorderColor()));
35
        connect(textControlCharsButton, SIGNAL(clicked()), this, SLOT(changeControlCharsColor()));
36
 
37
        connect(buttonRestoreDPI, SIGNAL(clicked()), this, SLOT(restoreDisScale()));
38
        connect(adjustDisplaySlider, SIGNAL(valueChanged(int)), this, SLOT(setDisScale()));
39
        connect(rulerUnitComboBox, SIGNAL(activated(int)), this, SLOT(drawRuler()));
13761 cbradney 40
}
41
 
42
Prefs_Display::~Prefs_Display()
43
{
44
}
45
 
14030 cbradney 46
void Prefs_Display::languageChange()
47
{
48
        pageFillColorButton->setToolTip( "<qt>" + tr( "Color for paper (onscreen)" ) + "</qt>");
49
        showUnprintableAreaInMarginColorCheckBox->setToolTip( "<qt>" + tr( "Mask the area outside the margins in the margin color" ) + "</qt>" );
50
        showTextChainsCheckBox->setToolTip( "<qt>" + tr("Enable or disable  the display of linked frames.") + "</qt>");
51
        showControlCharsCheckBox->setToolTip( "<qt>" + tr("Display non-printing characters such as paragraph markers in text frames") + "</qt>");
52
        showFramesCheckBox->setToolTip( "<qt>" + tr("Turns the display of frames on or off") + "</qt>");
53
        showLayerIndicatorsCheckBox->setToolTip( "<qt>" + tr("Turns the display of layer indicators on or off") + "</qt>");
54
        showImagesCheckBox->setToolTip( "<qt>" + tr("Turns the display of images on or off") + "</qt>");
55
        showPageShadowCheckBox->setToolTip( "<qt>" + tr("Turns the page shadow on or off") + "</qt>");
56
        scratchSpaceLeftSpinBox->setToolTip( "<qt>" + tr( "Defines amount of space left of the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
57
        scratchSpaceRightSpinBox->setToolTip( "<qt>" + tr( "Defines amount of space right of the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
58
        scratchSpaceTopSpinBox->setToolTip( "<qt>" + tr( "Defines amount of space above the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
59
        scratchSpaceBottomSpinBox->setToolTip( "<qt>" + tr( "Defines amount of space below the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
60
        buttonRestoreDPI->setToolTip( "<qt>" + tr( "Set the default zoom level" )  + "</qt>");
61
        adjustDisplaySlider->setToolTip( "<qt>" + tr( "Place a ruler against your screen and drag the slider to set the zoom level so Scribus will display your pages and objects on them at the correct size" ) + "</qt>" );
62
}
63
 
14023 cbradney 64
void Prefs_Display::restoreDefaults(struct ApplicationPrefs *prefsData)
65
{
66
        docUnitIndex = prefsData->docSetupPrefs.docUnitIndex;
67
        double unitRatio = unitGetRatioFromIndex(docUnitIndex);
14030 cbradney 68
//      int decimals = unitGetPrecisionFromIndex(docUnitIndex);
14023 cbradney 69
        QString unitSuffix = unitGetSuffixFromIndex(docUnitIndex);
70
 
71
        showImagesCheckBox->setChecked(prefsData->guidesPrefs.showPic);
72
        showControlCharsCheckBox->setChecked(prefsData->guidesPrefs.showControls);
73
        showRulersRelativeToPageCheckBox->setChecked(prefsData->guidesPrefs.rulerMode);
74
        showTextChainsCheckBox->setChecked(prefsData->guidesPrefs.linkShown);
75
        showFramesCheckBox->setChecked(prefsData->guidesPrefs.framesShown);
76
        showLayerIndicatorsCheckBox->setChecked(prefsData->guidesPrefs.layerMarkersShown);
77
        showUnprintableAreaInMarginColorCheckBox->setChecked(prefsData->displayPrefs.marginColored);
78
        showBleedAreaCheckBox->setChecked(prefsData->guidesPrefs.showBleed);
79
        showPageShadowCheckBox->setChecked(prefsData->displayPrefs.showPageShadow);
80
 
81
 
82
        scratchSpaceLeftSpinBox->setMaximum(1000);
83
        scratchSpaceRightSpinBox->setMaximum(1000);
84
        scratchSpaceTopSpinBox->setMaximum(1000);
85
        scratchSpaceBottomSpinBox->setMaximum(1000);
86
        pageGapHorizontalSpinBox->setMaximum(1000);
87
        pageGapVerticalSpinBox->setMaximum(1000);
88
        scratchSpaceLeftSpinBox->setNewUnit(docUnitIndex);
89
        scratchSpaceRightSpinBox->setNewUnit(docUnitIndex);
90
        scratchSpaceTopSpinBox->setNewUnit(docUnitIndex);
91
        scratchSpaceBottomSpinBox->setNewUnit(docUnitIndex);
92
        pageGapHorizontalSpinBox->setNewUnit(docUnitIndex);
93
        pageGapVerticalSpinBox->setNewUnit(docUnitIndex);
94
 
95
 
96
        scratchSpaceLeftSpinBox->setValue(prefsData->displayPrefs.scratch.Left * unitRatio);
97
        scratchSpaceRightSpinBox->setValue(prefsData->displayPrefs.scratch.Right * unitRatio);
98
        scratchSpaceTopSpinBox->setValue(prefsData->displayPrefs.scratch.Top * unitRatio);
99
        scratchSpaceBottomSpinBox->setValue(prefsData->displayPrefs.scratch.Bottom * unitRatio);
100
        pageGapHorizontalSpinBox->setValue(prefsData->displayPrefs.pageGapHorizontal);
101
        pageGapVerticalSpinBox->setValue(prefsData->displayPrefs.pageGapVertical);
102
 
14030 cbradney 103
        QPixmap pm(100, 30);
14023 cbradney 104
        pm.fill(prefsData->displayPrefs.paperColor);
105
        colorPaper = prefsData->displayPrefs.paperColor;
14030 cbradney 106
        pageFillColorButton->setText( QString::null );
107
        pageFillColorButton->setIcon(pm);
108
 
109
 
14023 cbradney 110
        pm.fill(prefsData->displayPrefs.frameColor);
111
        colorFrame = prefsData->displayPrefs.frameColor;
14030 cbradney 112
        frameSelectedColorButton->setText( QString::null );
113
        frameSelectedColorButton->setIcon(pm);
114
 
14023 cbradney 115
        pm.fill(prefsData->displayPrefs.frameNormColor);
116
        colorFrameNorm = prefsData->displayPrefs.frameNormColor;
14030 cbradney 117
        frameColorButton->setText( QString::null );
118
        frameColorButton->setIcon(pm);
119
 
14023 cbradney 120
        pm.fill(prefsData->displayPrefs.frameGroupColor);
121
        colorFrameGroup = prefsData->displayPrefs.frameGroupColor;
14030 cbradney 122
        frameGroupedColorButton->setText( QString::null );
123
        frameGroupedColorButton->setIcon(pm);
124
 
14023 cbradney 125
        pm.fill(prefsData->displayPrefs.frameLinkColor);
126
        colorFrameLinked = prefsData->displayPrefs.frameLinkColor;
14030 cbradney 127
        frameLinkedColorButton->setText( QString::null );
128
        frameLinkedColorButton->setIcon(pm);
129
 
14023 cbradney 130
        pm.fill(prefsData->displayPrefs.frameLockColor);
131
        colorFrameLocked = prefsData->displayPrefs.frameLockColor;
14030 cbradney 132
        frameLockedColorButton->setText( QString::null );
133
        frameLockedColorButton->setIcon(pm);
134
 
14023 cbradney 135
        pm.fill(prefsData->displayPrefs.frameAnnotationColor);
136
        colorFrameAnnotation = prefsData->displayPrefs.frameAnnotationColor;
14030 cbradney 137
        frameAnnotationColorButton->setText( QString::null );
138
        frameAnnotationColorButton->setIcon(pm);
139
 
14023 cbradney 140
        pm.fill(prefsData->displayPrefs.pageBorderColor);
141
        colorPageBorder = prefsData->displayPrefs.pageBorderColor;
14030 cbradney 142
        selectedPageBorderButton->setText( QString::null );
143
        selectedPageBorderButton->setIcon(pm);
144
 
14023 cbradney 145
        pm.fill(prefsData->displayPrefs.controlCharColor);
146
        colorControlChars = prefsData->displayPrefs.controlCharColor;
14030 cbradney 147
        textControlCharsButton->setText( QString::null );
148
        textControlCharsButton->setIcon(pm);
14023 cbradney 149
 
14030 cbradney 150
        displayScale=prefsData->displayPrefs.displayScale;
14023 cbradney 151
 
14030 cbradney 152
        adjustDisplaySlider->setValue(qRound(100 * displayScale) - 150);
153
        displayDPI->setText(QString::number(qRound(displayScale*72.0))+ tr(" dpi"));
154
        rulerUnitComboBox->clear();
155
        rulerUnitComboBox->addItems(unitGetTextUnitList());
156
        rulerUnitComboBox->setCurrentIndex(docUnitIndex);
14023 cbradney 157
        drawRuler();
14030 cbradney 158
 
14023 cbradney 159
}
160
 
14030 cbradney 161
void Prefs_Display::drawRuler()
162
{
163
        int index = rulerUnitComboBox->currentIndex();
164
        double iter = unitRulerGetIter1FromIndex(index);
165
        double iter2 = unitRulerGetIter2FromIndex(index);
166
        double maxi;
167
        switch (index)
168
        {
169
                case 0:
170
                        maxi = 200.0;
171
                        break;
172
                case 1:
173
                        maxi = iter2;
174
                        break;
175
                case 2:
176
                        maxi = 2 * iter2;
177
                        break;
178
                case 3:
179
                        maxi = 240.0;
180
                        break;
181
                case 4:
182
                        maxi = 240.0;
183
                        break;
184
                default:
185
                        iter = 10.0;
186
                        iter2 = iter * 10.0;
187
                        maxi = 200.0;
188
                        break;
189
        }
190
 
191
        QPixmap pm(qMin(qMax(displaySizeRuler->width(), qRound(maxi)+30), qRound(maxi*displayScale+30)), 21);
192
        pm.fill();
193
        QPainter p;
194
        p.begin(&pm);
195
        p.drawLine(0, 19, pm.width(), 19);
196
        p.setBrush(Qt::black);
197
        p.setPen(Qt::black);
198
        p.scale(displayScale, 1.0);
199
        double xl;
200
        for (xl = 0; xl < maxi; xl += iter)
201
                p.drawLine(QPointF(xl, 13.0), QPointF(xl, 19.0));
202
        for (xl = 0; xl < maxi+10; xl += iter2)
203
        {
204
                p.drawLine(QPointF(xl, 6.0), QPointF(xl, 19.0));
205
                p.save();
206
                p.scale(1.0 / displayScale, 1.0);
14046 cbradney 207
                double val;
14030 cbradney 208
                switch (index)
209
                {
210
                        case 2:
211
                        case 4:
14046 cbradney 212
                                val=xl/iter2;
14030 cbradney 213
                                break;
214
                        case 3:
215
                        case 5:
14046 cbradney 216
                                val=xl/iter;
14030 cbradney 217
                                break;
218
                        default:
14046 cbradney 219
                                val=xl/iter*10;
14030 cbradney 220
                                break;
221
                }
14046 cbradney 222
                p.drawText(static_cast<int>((xl+qRound(2/displayScale)) * displayScale), 12, QString::number(val));
14030 cbradney 223
                p.restore();
224
        }
225
        p.end();
226
        displaySizeRuler->setPixmap(pm);
227
}
228
 
229
void Prefs_Display::restoreDisScale()
230
{
231
        disconnect(adjustDisplaySlider, SIGNAL(valueChanged(int)), this, SLOT(setDisScale()));
232
        int dpi = qApp->desktop()->logicalDpiX();
233
        if ((dpi < 60) || (dpi > 250))
234
                dpi = 72;
235
        displayScale = dpi / 72.0;
236
        adjustDisplaySlider->setValue(qRound(100 * displayScale) - 150);
237
        drawRuler();
238
        displayDPI->setText(QString::number(qRound(displayScale*72.0))+ tr(" dpi"));
239
        connect(adjustDisplaySlider, SIGNAL(valueChanged(int)), this, SLOT(setDisScale()));
240
}
241
 
242
void Prefs_Display::setDisScale()
243
{
244
        displayScale = qMax((150.0 + adjustDisplaySlider->value()) / 100.0, 0.01);
245
        drawRuler();
246
        displayDPI->setText(QString::number(qRound(displayScale*72.0))+ tr(" dpi"));
247
}
248
 
249
void Prefs_Display::changePaperColor()
250
{
14060 cbradney 251
        QColor newColor(QColorDialog::getColor(colorPaper, this));
252
        if (newColor.isValid())
14030 cbradney 253
        {
14060 cbradney 254
                QPixmap pm(100, 30);
255
                pm.fill(newColor);
256
                colorPaper = newColor;
14030 cbradney 257
                pageFillColorButton->setIcon(pm);
258
        }
259
}
260
 
261
void Prefs_Display::changeFrameColor()
262
{
14060 cbradney 263
        QColor newColor(QColorDialog::getColor(colorFrame, this));
264
        if (newColor.isValid())
14030 cbradney 265
        {
14060 cbradney 266
                QPixmap pm(100, 30);
267
                pm.fill(newColor);
268
                colorFrame = newColor;
14030 cbradney 269
                frameSelectedColorButton->setIcon(pm);
270
        }
271
}
272
 
273
void Prefs_Display::changeNormFrameColor()
274
{
14060 cbradney 275
        QColor newColor(QColorDialog::getColor(colorFrameNorm, this));
276
        if (newColor.isValid())
14030 cbradney 277
        {
14060 cbradney 278
                QPixmap pm(100, 30);
279
                pm.fill(newColor);
280
                colorFrameNorm = newColor;
14030 cbradney 281
                frameColorButton->setIcon(pm);
282
        }
283
}
284
 
285
void Prefs_Display::changeGroupFrameColor()
286
{
14060 cbradney 287
        QColor newColor(QColorDialog::getColor(colorFrameGroup, this));
288
        if (newColor.isValid())
14030 cbradney 289
        {
14060 cbradney 290
                QPixmap pm(100, 30);
291
                pm.fill(newColor);
292
                colorFrameGroup = newColor;
14030 cbradney 293
                frameGroupedColorButton->setIcon(pm);
294
        }
295
}
296
 
297
void Prefs_Display::changeChainFrameColor()
298
{
14060 cbradney 299
        QColor newColor(QColorDialog::getColor(colorFrameLinked, this));
300
        if (newColor.isValid())
14030 cbradney 301
        {
14060 cbradney 302
                QPixmap pm(100, 30);
303
                pm.fill(newColor);
304
                colorFrameLinked = newColor;
14030 cbradney 305
                frameLinkedColorButton->setIcon(pm);
306
        }
307
}
308
 
309
void Prefs_Display::changeLockFrameColor()
310
{
14060 cbradney 311
        QColor newColor(QColorDialog::getColor(colorFrameLocked, this));
312
        if (newColor.isValid())
14030 cbradney 313
        {
14060 cbradney 314
                QPixmap pm(100, 30);
315
                pm.fill(newColor);
316
                colorFrameLocked = newColor;
14030 cbradney 317
                frameLockedColorButton->setIcon(pm);
318
        }
319
}
320
 
321
void Prefs_Display::changeAnnotFrameColor()
322
{
14060 cbradney 323
        QColor newColor(QColorDialog::getColor(colorFrameAnnotation, this));
324
        if (newColor.isValid())
14030 cbradney 325
        {
14060 cbradney 326
                QPixmap pm(100, 30);
327
                pm.fill(newColor);
328
                colorFrameAnnotation = newColor;
14030 cbradney 329
                frameAnnotationColorButton->setIcon(pm);
330
        }
331
}
332
 
333
void Prefs_Display::changePageBorderColor()
334
{
14060 cbradney 335
        QColor newColor(QColorDialog::getColor(colorPageBorder, this));
336
        if (newColor.isValid())
14030 cbradney 337
        {
14060 cbradney 338
                QPixmap pm(100, 30);
339
                pm.fill(newColor);
340
                colorPageBorder = newColor;
14030 cbradney 341
                selectedPageBorderButton->setIcon(pm);
342
        }
343
}
344
 
345
void Prefs_Display::changeControlCharsColor()
346
{
14060 cbradney 347
        QColor newColor(QColorDialog::getColor(colorControlChars, this));
348
        if (newColor.isValid())
14030 cbradney 349
        {
14060 cbradney 350
                QPixmap pm(100, 30);
351
                pm.fill(newColor);
352
                colorControlChars = newColor;
14030 cbradney 353
                textControlCharsButton->setIcon(pm);
354
        }
355
}
14046 cbradney 356
 
357
void Prefs_Display::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
358
{
359
        prefsData->guidesPrefs.showPic=showImagesCheckBox->isChecked();
360
        prefsData->guidesPrefs.showControls=showControlCharsCheckBox->isChecked();
361
        prefsData->guidesPrefs.rulerMode=showRulersRelativeToPageCheckBox->isChecked();
362
        prefsData->guidesPrefs.linkShown=showTextChainsCheckBox->isChecked();
363
        prefsData->guidesPrefs.framesShown=showFramesCheckBox->isChecked();
364
        prefsData->guidesPrefs.layerMarkersShown=showLayerIndicatorsCheckBox->isChecked();
365
        prefsData->displayPrefs.marginColored=showUnprintableAreaInMarginColorCheckBox->isChecked();
366
        prefsData->guidesPrefs.showBleed=showBleedAreaCheckBox->isChecked();
367
        prefsData->displayPrefs.showPageShadow=showPageShadowCheckBox->isChecked();
368
        double unitRatio = unitGetRatioFromIndex(docUnitIndex);
369
        prefsData->displayPrefs.scratch.Left=scratchSpaceLeftSpinBox->value()/unitRatio;
370
        prefsData->displayPrefs.scratch.Right=scratchSpaceRightSpinBox->value()/unitRatio;
371
        prefsData->displayPrefs.scratch.Top=scratchSpaceTopSpinBox->value()/unitRatio;
372
        prefsData->displayPrefs.scratch.Bottom=scratchSpaceBottomSpinBox->value()/unitRatio;
373
        prefsData->displayPrefs.pageGapHorizontal=pageGapHorizontalSpinBox->value();
374
        prefsData->displayPrefs.pageGapVertical=pageGapVerticalSpinBox->value();
375
 
376
        prefsData->displayPrefs.paperColor=colorPaper;
377
        prefsData->displayPrefs.frameColor=colorFrame;
378
        prefsData->displayPrefs.frameNormColor=colorFrameNorm;
379
        prefsData->displayPrefs.frameGroupColor=colorFrameGroup;
380
        prefsData->displayPrefs.frameLinkColor=colorFrameLinked;
381
        prefsData->displayPrefs.frameLockColor=colorFrameLocked;
382
        prefsData->displayPrefs.frameAnnotationColor=colorFrameAnnotation;
383
        prefsData->displayPrefs.pageBorderColor=colorPageBorder;
384
        prefsData->displayPrefs.controlCharColor=colorControlChars;
385
        prefsData->displayPrefs.displayScale=displayScale;
386
}