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
8 #include <QColorDialog>
9
10 #include "commonstrings.h"
11 #include "iconmanager.h"
12 #include "prefsstructs.h"
13 #include "scribusdoc.h"
14 #include "scrspinbox.h"
15 #include "ui/prefs_guides.h"
16 #include "units.h"
17
Prefs_Guides(QWidget * parent,ScribusDoc * doc)18 Prefs_Guides::Prefs_Guides(QWidget* parent, ScribusDoc* doc)
19 : Prefs_Pane(parent)
20 {
21 setupUi(this);
22 languageChange();
23
24 m_caption = tr("Guides");
25 m_icon = "16/edit-guides.png";
26
27 buttonUp->setIcon(IconManager::instance().loadIcon("16/go-up.png"));
28 buttonUp->setEnabled(false);
29 buttonDown->setIcon(IconManager::instance().loadIcon("16/go-down.png"));
30 buttonDown->setEnabled(false);
31
32 QString pxSuffix = QString(" %1").arg(CommonStrings::trStrPX);
33 guideSnapDistanceSpinBox->setSuffix(pxSuffix);
34 guideGrabRadiusSpinBox->setSuffix(pxSuffix);
35
36 guideSnapDistanceSpinBox->setDecimals(0);
37 guideGrabRadiusSpinBox->setDecimals(0);
38
39 connect(guideColorPushButton, SIGNAL(clicked()), this, SLOT(changeGuideColor()));
40 connect(marginColorPushButton, SIGNAL(clicked()), this, SLOT(changeMarginColor()));
41 connect(majorGridColorPushButton, SIGNAL(clicked()), this, SLOT(changeMajorColor()));
42 connect(minorGridColorPushButton, SIGNAL(clicked()), this, SLOT(changeMinorColor()));
43 connect(baselineGridColorPushButton, SIGNAL(clicked()), this, SLOT(changeBaselineColor()));
44 connect(buttonUp, SIGNAL(clicked()), this, SLOT(moveUp()));
45 connect(buttonDown, SIGNAL(clicked()), this, SLOT(moveDown()));
46 connect(guidePlacementListBox, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(select(QListWidgetItem*)));
47 connect(visibilityGridCheckBox, SIGNAL(clicked()), this, SLOT(gridClicked()));
48 }
49
50 Prefs_Guides::~Prefs_Guides() = default;
51
languageChange()52 void Prefs_Guides::languageChange()
53 {
54 guidePlacementListBox->clear();
55 int renderStackCount = renderStackOrder.count();
56 for (int r = renderStackCount - 1; r > -1; r--)
57 {
58 QListWidgetItem *item(nullptr);
59 int it = renderStackOrder[r];
60 if (it == 4)
61 item = new QListWidgetItem( tr("Content Objects"), guidePlacementListBox);
62 else if (it == 3)
63 item = new QListWidgetItem( tr("Guides"), guidePlacementListBox);
64 else if (it == 2)
65 item = new QListWidgetItem( tr("Grid"), guidePlacementListBox);
66 else if (it == 1)
67 item = new QListWidgetItem( tr("Baseline Grid"), guidePlacementListBox);
68 else if (it == 0)
69 item = new QListWidgetItem( tr("Margins"), guidePlacementListBox);
70 if (item)
71 {
72 item->setData(Qt::UserRole, it);
73 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
74 }
75 }
76 int grTy = gridTypeCombo->currentIndex();
77 gridTypeCombo->clear();
78 gridTypeCombo->addItem( tr("Lines"));
79 gridTypeCombo->addItem( tr("Crosses and Dots"));
80 gridTypeCombo->setCurrentIndex(grTy);
81
82 QString pxSuffix = QString(" %1").arg(CommonStrings::trStrPX);
83 guideSnapDistanceSpinBox->setSuffix(pxSuffix);
84 guideGrabRadiusSpinBox->setSuffix(pxSuffix);
85
86 guidePlacementListBox->setToolTip( tr( "Place guides in front of or behind objects on the page" ) );
87 minorGridSpacingSpinBox->setToolTip( tr( "Distance between the minor grid lines" ) );
88 majorGridSpacingSpinBox->setToolTip( tr( "Distance between the major grid lines" ) );
89 guideSnapDistanceSpinBox->setToolTip( "<qt>" + tr( "Distance within which an object will snap to your placed guides. After setting this you will need to restart Scribus to set this setting." ) + "</qt>");
90 guideGrabRadiusSpinBox->setToolTip( "<qt>" + tr( "Radius of the area where Scribus will allow you to grab an objects handles. After setting this you will need to restart Scribus to set this setting." ) + "</qt>");
91 minorGridColorPushButton->setToolTip( tr( "Color of the minor grid lines" ) );
92 majorGridColorPushButton->setToolTip( tr( "Color of the major grid lines" ) );
93 guideColorPushButton->setToolTip( tr( "Color of the guide lines you insert" ) );
94 marginColorPushButton->setToolTip( tr( "Color for the margin lines" ) );
95 baselineGridColorPushButton->setToolTip( tr( "Color for the baseline grid" ) );
96 visibilityBaselineGridCheckBox->setToolTip( tr("Turns the basegrid on or off"));
97 baselineGridSpacingSpinBox->setToolTip( tr("Distance between the lines of the baseline grid"));
98 baselineGridOffsetSpinBox->setToolTip( tr("Distance from the top of the page for the first baseline"));
99 visibilityGridCheckBox->setToolTip( tr("Turns the gridlines on or off"));
100 visibilityGuidesCheckBox->setToolTip( tr("Turns the guides on or off"));
101 visibilityMarginsCheckBox->setToolTip( tr("Turns the margins on or off"));
102 }
103
unitChange(int unitIndex)104 void Prefs_Guides::unitChange(int unitIndex)
105 {
106 double unitRatio = unitGetRatioFromIndex(unitIndex);
107 majorGridSpacingSpinBox->setNewUnit(unitIndex);
108 minorGridSpacingSpinBox->setNewUnit(unitIndex);
109
110 majorGridSpacingSpinBox->setMinimum(10 * unitRatio);
111 minorGridSpacingSpinBox->setMinimum(unitRatio);
112 majorGridSpacingSpinBox->setMaximum(1000 * unitRatio);
113 minorGridSpacingSpinBox->setMaximum(1000 * unitRatio);
114 }
115
restoreDefaults(struct ApplicationPrefs * prefsData)116 void Prefs_Guides::restoreDefaults(struct ApplicationPrefs *prefsData)
117 {
118 int docUnitIndex = prefsData->docSetupPrefs.docUnitIndex;
119 unitChange(docUnitIndex);
120 double unitRatio = unitGetRatioFromIndex(docUnitIndex);
121 renderStackOrder = prefsData->guidesPrefs.renderStackOrder;
122 guidePlacementListBox->clear();
123 int renderStackCount = renderStackOrder.count();
124 for (int r = renderStackCount - 1; r > -1; r--)
125 {
126 QListWidgetItem *item(nullptr);
127 int it = renderStackOrder[r];
128 if (it == 4)
129 item = new QListWidgetItem( tr("Content Objects"), guidePlacementListBox);
130 else if (it == 3)
131 item = new QListWidgetItem( tr("Guides"), guidePlacementListBox);
132 else if (it == 2)
133 item = new QListWidgetItem( tr("Grid"), guidePlacementListBox);
134 else if (it == 1)
135 item = new QListWidgetItem( tr("Baseline Grid"), guidePlacementListBox);
136 else if (it == 0)
137 item = new QListWidgetItem( tr("Margins"), guidePlacementListBox);
138 if (item)
139 {
140 item->setData(Qt::UserRole, it);
141 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
142 }
143 }
144 guideSnapDistanceSpinBox->setValue(prefsData->guidesPrefs.guideRad);
145 guideGrabRadiusSpinBox->setValue(prefsData->guidesPrefs.grabRadius);
146 visibilityGuidesCheckBox->setChecked(prefsData->guidesPrefs.guidesShown);
147 visibilityMarginsCheckBox->setChecked(prefsData->guidesPrefs.marginsShown);
148 visibilityGridCheckBox->setChecked(prefsData->guidesPrefs.gridShown);
149 visibilityBaselineGridCheckBox->setChecked(prefsData->guidesPrefs.baselineGridShown);
150
151 gridTypeCombo->setCurrentIndex(prefsData->guidesPrefs.gridType);
152 majorGridSpacingSpinBox->setValue(prefsData->guidesPrefs.majorGridSpacing * unitRatio);
153 minorGridSpacingSpinBox->setValue(prefsData->guidesPrefs.minorGridSpacing * unitRatio);
154 baselineGridSpacingSpinBox->setValue(prefsData->guidesPrefs.valueBaselineGrid);
155 baselineGridOffsetSpinBox->setValue(prefsData->guidesPrefs.offsetBaselineGrid);
156
157 QPixmap pm(100, 30);
158 pm.fill(prefsData->guidesPrefs.guideColor);
159 colorGuides = prefsData->guidesPrefs.guideColor;
160 guideColorPushButton->setText( QString() );
161 guideColorPushButton->setIcon(pm);
162
163
164 pm.fill(prefsData->guidesPrefs.marginColor);
165 colorMargin = prefsData->guidesPrefs.marginColor;
166 marginColorPushButton->setText( QString() );
167 marginColorPushButton->setIcon(pm);
168
169 pm.fill(prefsData->guidesPrefs.majorGridColor);
170 colorMajorGrid = prefsData->guidesPrefs.majorGridColor;
171 majorGridColorPushButton->setText( QString() );
172 majorGridColorPushButton->setIcon(pm);
173
174 pm.fill(prefsData->guidesPrefs.minorGridColor);
175 colorMinorGrid = prefsData->guidesPrefs.minorGridColor;
176 minorGridColorPushButton->setText( QString() );
177 minorGridColorPushButton->setIcon(pm);
178
179 pm.fill(prefsData->guidesPrefs.baselineGridColor);
180 colorBaselineGrid = prefsData->guidesPrefs.baselineGridColor;
181 baselineGridColorPushButton->setText( QString() );
182 baselineGridColorPushButton->setIcon(pm);
183 gridTypeCombo->setEnabled(visibilityGridCheckBox->isChecked());
184 }
185
saveGuiToPrefs(struct ApplicationPrefs * prefsData) const186 void Prefs_Guides::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
187 {
188 prefsData->guidesPrefs.renderStackOrder = renderStackOrder;
189 prefsData->guidesPrefs.guideRad = guideSnapDistanceSpinBox->value();
190 prefsData->guidesPrefs.grabRadius = guideGrabRadiusSpinBox->value();
191 prefsData->guidesPrefs.guidesShown = visibilityGuidesCheckBox->isChecked();
192 prefsData->guidesPrefs.marginsShown = visibilityMarginsCheckBox->isChecked();
193 prefsData->guidesPrefs.gridShown = visibilityGridCheckBox->isChecked();
194 prefsData->guidesPrefs.baselineGridShown = visibilityBaselineGridCheckBox->isChecked();
195 double unitRatio = unitGetRatioFromIndex(prefsData->docSetupPrefs.docUnitIndex);
196 prefsData->guidesPrefs.majorGridSpacing = majorGridSpacingSpinBox->value() / unitRatio;
197 prefsData->guidesPrefs.minorGridSpacing = minorGridSpacingSpinBox->value() / unitRatio;
198 prefsData->guidesPrefs.valueBaselineGrid = baselineGridSpacingSpinBox->value();
199 prefsData->guidesPrefs.offsetBaselineGrid = baselineGridOffsetSpinBox->value();
200 prefsData->guidesPrefs.guideColor = colorGuides;
201 prefsData->guidesPrefs.marginColor = colorMargin;
202 prefsData->guidesPrefs.majorGridColor = colorMajorGrid;
203 prefsData->guidesPrefs.minorGridColor = colorMinorGrid;
204 prefsData->guidesPrefs.baselineGridColor = colorBaselineGrid;
205 prefsData->guidesPrefs.gridType = gridTypeCombo->currentIndex();
206 }
207
changeMajorColor()208 void Prefs_Guides::changeMajorColor()
209 {
210 QColor newColor(QColorDialog::getColor(colorMajorGrid, this));
211 if (newColor.isValid())
212 {
213 QPixmap pm(54, 14);
214 pm.fill(newColor);
215 colorMajorGrid = newColor;
216 majorGridColorPushButton->setIcon(pm);
217 }
218 }
219
changeMinorColor()220 void Prefs_Guides::changeMinorColor()
221 {
222 QColor newColor(QColorDialog::getColor(colorMinorGrid, this));
223 if (newColor.isValid())
224 {
225 QPixmap pm(54, 14);
226 pm.fill(newColor);
227 colorMinorGrid = newColor;
228 minorGridColorPushButton->setIcon(pm);
229 }
230 }
231
changeBaselineColor()232 void Prefs_Guides::changeBaselineColor()
233 {
234 QColor newColor(QColorDialog::getColor(colorBaselineGrid, this));
235 if (newColor.isValid())
236 {
237 QPixmap pm(54, 14);
238 pm.fill(newColor);
239 colorBaselineGrid = newColor;
240 baselineGridColorPushButton->setIcon(pm);
241 }
242 }
243
changeGuideColor()244 void Prefs_Guides::changeGuideColor()
245 {
246 QColor newColor(QColorDialog::getColor(colorGuides, this));
247 if (newColor.isValid())
248 {
249 QPixmap pm(54, 14);
250 pm.fill(newColor);
251 colorGuides = newColor;
252 guideColorPushButton->setIcon(pm);
253 }
254 }
255
changeMarginColor()256 void Prefs_Guides::changeMarginColor()
257 {
258 QColor newColor(QColorDialog::getColor(colorMargin, this));
259 if (newColor.isValid())
260 {
261 QPixmap pm(54, 14);
262 pm.fill(newColor);
263 colorMargin = newColor;
264 marginColorPushButton->setIcon(pm);
265 }
266 }
267
changeRenderStack()268 void Prefs_Guides::changeRenderStack()
269 {
270 renderStackOrder.clear();
271 for (int i = 0; i < guidePlacementListBox->count(); i++)
272 {
273 renderStackOrder.prepend(guidePlacementListBox->item(i)->data(Qt::UserRole).toInt());
274 }
275 int curr = guidePlacementListBox->currentRow();
276 if (curr == 0)
277 {
278 buttonUp->setEnabled(false);
279 buttonDown->setEnabled(true);
280 }
281 else if (curr == guidePlacementListBox->count() - 1)
282 {
283 buttonUp->setEnabled(true);
284 buttonDown->setEnabled(false);
285 }
286 else
287 {
288 buttonUp->setEnabled(true);
289 buttonDown->setEnabled(true);
290 }
291 }
292
moveUp()293 void Prefs_Guides::moveUp()
294 {
295 int curr = guidePlacementListBox->currentRow();
296 if (curr == 0)
297 return;
298 QListWidgetItem *it = guidePlacementListBox->takeItem(curr);
299 guidePlacementListBox->insertItem(curr - 1, it);
300 guidePlacementListBox->setCurrentItem(it);
301 changeRenderStack();
302 }
303
moveDown()304 void Prefs_Guides::moveDown()
305 {
306 int curr = guidePlacementListBox->currentRow();
307 if (curr == static_cast<int>(guidePlacementListBox->count()) - 1)
308 return;
309 QListWidgetItem *it = guidePlacementListBox->takeItem(curr);
310 guidePlacementListBox->insertItem(curr + 1, it);
311 guidePlacementListBox->setCurrentItem(it);
312 changeRenderStack();
313 }
314
select(QListWidgetItem * item)315 void Prefs_Guides::select(QListWidgetItem* item)
316 {
317 guidePlacementListBox->setCurrentItem(item);
318 int curr = guidePlacementListBox->currentRow();
319 if (curr == 0)
320 {
321 buttonUp->setEnabled(false);
322 buttonDown->setEnabled(true);
323 }
324 else if (curr == guidePlacementListBox->count() - 1)
325 {
326 buttonUp->setEnabled(true);
327 buttonDown->setEnabled(false);
328 }
329 else
330 {
331 buttonUp->setEnabled(true);
332 buttonDown->setEnabled(true);
333 }
334 }
335
gridClicked()336 void Prefs_Guides::gridClicked()
337 {
338 gridTypeCombo->setEnabled(visibilityGridCheckBox->isChecked());
339 }
340