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 <QPen>
9 #include <QTabWidget>
10 
11 #include "guidemanagercore.h"
12 
13 #include "fpoint.h"
14 #include "scclocale.h"
15 #include "scpage.h"
16 #include "scpainter.h"
17 #include "scribuscore.h"
18 #include "scribusdoc.h"
19 #include "pagestructs.h"
20 #include "selection.h"
21 #include "undomanager.h"
22 #include "undostate.h"
23 #include "ui/guidemanager.h"
24 
GuideManagerCore()25 GuideManagerCore::GuideManagerCore():
26 	m_undoManager(UndoManager::instance())
27 {
28 }
29 
GuideManagerCore(ScPage * parentPage)30 GuideManagerCore::GuideManagerCore(ScPage *parentPage):
31 	m_undoManager(UndoManager::instance()),
32 	m_page(parentPage)
33 {
34 }
35 
setPage(ScPage * p)36 void GuideManagerCore::setPage(ScPage *p)
37 {
38 	m_page = p;
39 }
40 
addHorizontal(double value,GuideType type)41 void GuideManagerCore::addHorizontal(double value, GuideType type)
42 {
43 	switch (type)
44 	{
45 		case Standard:
46 			if (!m_horizontalStdG.contains(value))
47 			{
48 				m_horizontalStdG.append(value);
49 				if (UndoManager::undoEnabled())
50 				{
51 					SimpleState* ss = new SimpleState(Um::AddHGuide, nullptr, Um::IGuides);
52 					ss->set("ADD_H", value);
53 					m_undoManager->action(m_page, ss);
54 				}
55 			}
56 			break;
57 		case Auto:
58 			break;
59 	}
60 }
61 
addHorizontals(Guides values,GuideType type)62 void GuideManagerCore::addHorizontals(Guides values, GuideType type)
63 {
64 	Guides::iterator it;
65 	switch (type)
66 	{
67 		case Standard:
68 			for (it = values.begin(); it != values.end(); ++it)
69 			{
70 				if (!m_horizontalStdG.contains((*it)))
71 					m_horizontalStdG.append((*it));
72 			}
73 			break;
74 		case Auto:
75 			m_horizontalAutoG.clear();
76 			for (it = values.begin(); it != values.end(); ++it)
77 				m_horizontalAutoG.append((*it));
78 			break;
79 	}
80 }
81 
addVertical(double value,GuideType type)82 void GuideManagerCore::addVertical(double value, GuideType type)
83 {
84 	switch (type)
85 	{
86 		case Standard:
87 			if (!m_verticalStdG.contains(value))
88 			{
89 				m_verticalStdG.append(value);
90 				if (UndoManager::undoEnabled())
91 				{
92 					SimpleState* ss = new SimpleState(Um::AddVGuide, nullptr, Um::IGuides);
93 					ss->set("ADD_V", value);
94 					m_undoManager->action(m_page, ss);
95 				}
96 			}
97 			break;
98 		case Auto:
99 			break;
100 	}
101 }
102 
addVerticals(Guides values,GuideType type)103 void GuideManagerCore::addVerticals(Guides values, GuideType type)
104 {
105 	Guides::iterator it;
106 	switch (type)
107 	{
108 		case Standard:
109 			for (it = values.begin(); it != values.end(); ++it)
110 			{
111 				if (!m_verticalStdG.contains((*it)))
112 					m_verticalStdG.append((*it));
113 			}
114 			break;
115 		case Auto:
116 			m_verticalAutoG.clear();
117 			for (it = values.begin(); it != values.end(); ++it)
118 				m_verticalAutoG.append((*it));
119 			break;
120 	}
121 }
122 
deleteHorizontal(double value,GuideType type)123 void GuideManagerCore::deleteHorizontal(double value, GuideType type)
124 {
125 	switch (type)
126 	{
127 		case Standard:
128 			m_horizontalStdG.removeAt(m_horizontalStdG.indexOf(value));
129 			if (UndoManager::undoEnabled())
130 			{
131 				SimpleState* ss = new SimpleState(Um::DelHGuide, nullptr, Um::IGuides);
132 				ss->set("REMOVE_H", value);
133 				m_undoManager->action(m_page, ss);
134 			}
135 			break;
136 		case Auto:
137 			break;
138 	}
139 }
140 
deleteVertical(double value,GuideType type)141 void GuideManagerCore::deleteVertical(double value, GuideType type)
142 {
143 	switch (type)
144 	{
145 		case Standard:
146 			m_verticalStdG.removeAt(m_verticalStdG.indexOf(value));
147 			if (UndoManager::undoEnabled())
148 			{
149 				SimpleState* ss = new SimpleState(Um::DelVGuide, nullptr, Um::IGuides);
150 				ss->set("REMOVE_V", value);
151 				m_undoManager->action(m_page, ss);
152 			}
153 			break;
154 		case Auto:
155 			break;
156 	}
157 }
158 
horizontals(GuideType type)159 Guides GuideManagerCore::horizontals(GuideType type)
160 {
161 	switch (type)
162 	{
163 		case Standard:
164 			return m_horizontalStdG;
165 			break;
166 		case Auto:
167 			return m_horizontalAutoG;
168 			break;
169 	}
170 	// just to prevent the compiler warnings
171 	return m_horizontalStdG;
172 }
173 
verticals(GuideType type)174 Guides GuideManagerCore::verticals(GuideType type)
175 {
176 	switch (type)
177 	{
178 		case Standard:
179 			return m_verticalStdG;
180 			break;
181 		case Auto:
182 			return m_verticalAutoG;
183 			break;
184 	}
185 	return m_verticalStdG;
186 }
187 
horizontal(uint ix,GuideType type)188 double GuideManagerCore::horizontal(uint ix, GuideType type)
189 {
190 	switch (type)
191 	{
192 		case Standard:
193 			return m_horizontalStdG[ix];
194 			break;
195 		case Auto:
196 			break;
197 	}
198 	return -1.0; // just for compiler warning
199 }
200 
vertical(uint ix,GuideType type)201 double GuideManagerCore::vertical(uint ix, GuideType type)
202 {
203 	switch (type)
204 	{
205 		case Standard:
206 			return m_verticalStdG[ix];
207 			break;
208 		case Auto:
209 			break;
210 	}
211 	return -1.0; // just for compiler warning
212 }
213 
getAutoHorizontals(ScPage * page)214 Guides GuideManagerCore::getAutoHorizontals(ScPage* page)
215 {
216 	Guides guides;
217 	int value = m_horizontalAutoCount;
218 
219 	if (page == nullptr)
220 		page = m_page;
221 	if (page == nullptr)
222 		return guides;
223 	if (m_horizontalAutoCount == 0)
224 		return guides;
225 	++value;
226 	double newPageHeight = page->height();
227 	double offset = 0.0;
228 	if (m_horizontalAutoRefer == 1)
229 	{
230 		newPageHeight = newPageHeight - page->Margins.top() - page->Margins.bottom();
231 		offset = page->Margins.top();
232 	}
233 	else if (m_horizontalAutoRefer == 2)
234 	{
235 		if (qRound(page->guides.gy) != 0.0)
236 		{
237 			offset = page->guides.gy;
238 			newPageHeight = page->guides.gh;
239 		}
240 	}
241 	double rowSize;
242 	if (page->guides.horizontalAutoGap() > 0.0)
243 		rowSize = (newPageHeight - (value - 1) * page->guides.horizontalAutoGap()) / value;
244 	else
245 		rowSize = newPageHeight / value;
246 
247 	for (int i = 1, gapCount = 0; i < value; ++i)
248 	{
249 		if (page->guides.horizontalAutoGap() > 0.0)
250 		{
251 			guides.append(offset + i * rowSize + gapCount * page->guides.horizontalAutoGap());
252 			++gapCount;
253 			guides.append(offset + i * rowSize + gapCount * page->guides.horizontalAutoGap());
254 		}
255 		else
256 			guides.append(offset + rowSize * i);
257 	}
258 	return guides;
259 }
260 
getAutoVerticals(ScPage * page)261 Guides GuideManagerCore::getAutoVerticals(ScPage* page)
262 {
263 	Guides guides;
264 	int value = m_verticalAutoCount;
265 
266 	if (page == nullptr)
267 		page = m_page;
268 	if (page == nullptr)
269 		return guides;
270 	if (m_verticalAutoCount == 0)
271 		return guides;
272 	++value;
273 	double newPageWidth = page->width();
274 	double offset = 0.0;
275 	if (m_verticalAutoRefer == 1)
276 	{
277 		newPageWidth = newPageWidth - page->Margins.left() - page->Margins.right();
278 		offset = page->Margins.left();
279 	}
280 	else if (m_verticalAutoRefer == 2)
281 	{
282 		if (qRound(page->guides.gx) != 0)
283 		{
284 			offset = page->guides.gx;
285 			newPageWidth = page->guides.gw;
286 		}
287 	}
288 	double columnSize;
289 	if (page->guides.verticalAutoGap() > 0.0)
290 		columnSize = (newPageWidth - (value - 1) * page->guides.verticalAutoGap()) / value;
291 	else
292 		columnSize = newPageWidth / value;
293 
294 	for (int i = 1, gapCount = 0; i < value; ++i)
295 	{
296 		if (page->guides.verticalAutoGap() > 0.0)
297 		{
298 			guides.append(offset + i * columnSize + gapCount * page->guides.verticalAutoGap());
299 			++gapCount;
300 			guides.append(offset + i * columnSize + gapCount * page->guides.verticalAutoGap());
301 		}
302 		else
303 			guides.append(offset + columnSize * i);
304 	}
305 	return guides;
306 }
307 
clearHorizontals(GuideType type)308 void GuideManagerCore::clearHorizontals(GuideType type)
309 {
310 	switch (type)
311 	{
312 		case Standard:
313 			if (UndoManager::undoEnabled())
314 			{
315 				for (int i = 0; i < m_horizontalStdG.count(); ++i)
316 				{
317 					SimpleState* ss = new SimpleState(Um::DelHGuide, nullptr, Um::IGuides);
318 					ss->set("REMOVE_H", m_horizontalStdG[i]);
319 					m_undoManager->action(m_page, ss);
320 				}
321 			}
322 			m_horizontalStdG.clear();
323 			break;
324 		case Auto:
325 			if (UndoManager::undoEnabled())
326 			{
327 				SimpleState * ss = new SimpleState(Um::DelHAGuide, nullptr, Um::IGuides);
328 				ss->set("REMOVE_HA_GAP", m_horizontalAutoGap);
329 				ss->set("REMOVE_HA_COUNT", m_horizontalAutoCount);
330 				ss->set("REMOVE_HA_REFER", m_horizontalAutoRefer);
331 				m_undoManager->action(m_page, ss);
332 			}
333 
334 			m_horizontalAutoGap = 0.0;
335 			m_horizontalAutoCount= 0;
336 			m_horizontalAutoRefer = 0;
337 			m_horizontalAutoG.clear();
338 			break;
339 	}
340 }
341 
clearVerticals(GuideType type)342 void GuideManagerCore::clearVerticals(GuideType type)
343 {
344 	switch (type)
345 	{
346 		case Standard:
347 			if (UndoManager::undoEnabled())
348 			{
349 				for (int i = 0; i < m_verticalStdG.count(); ++i)
350 				{
351 					SimpleState* ss = new SimpleState(Um::DelVGuide, nullptr, Um::IGuides);
352 					ss->set("REMOVE_V", m_verticalStdG[i]);
353 					m_undoManager->action(m_page, ss);
354 				}
355 			}
356 			m_verticalStdG.clear();
357 			break;
358 		case Auto:
359 			if (UndoManager::undoEnabled())
360 			{
361 				SimpleState * ss = new SimpleState(Um::DelVAGuide, nullptr, Um::IGuides);
362 				ss->set("REMOVE_VA_GAP", m_verticalAutoGap);
363 				ss->set("REMOVE_VA_COUNT", m_verticalAutoCount);
364 				ss->set("REMOVE_VA_REFER", m_verticalAutoRefer);
365 				m_undoManager->action(m_page, ss);
366 			}
367 
368 			m_verticalAutoGap = 0.0;
369 			m_verticalAutoCount = 0;
370 			m_verticalAutoRefer = 0;
371 			m_verticalAutoG.clear();
372 			break;
373 	}
374 }
moveHorizontal(double from,double to,GuideType type)375 void GuideManagerCore::moveHorizontal(double from, double to, GuideType type)
376 {
377 	switch (type)
378 	{
379 		case Standard:
380 			m_horizontalStdG.removeAt(m_horizontalStdG.indexOf(from));
381 			m_horizontalStdG.append(to);
382 			if (UndoManager::undoEnabled())
383 			{
384 				SimpleState* ss = new SimpleState(Um::MoveHGuide, nullptr, Um::IGuides);
385 				ss->set("MOVE_H_FROM", from);
386 				ss->set("MOVE_H_TO", to);
387 				m_undoManager->action(m_page, ss);
388 			}
389 			break;
390 		case Auto:
391 			break;
392 	}
393 }
394 
moveVertical(double from,double to,GuideType type)395 void GuideManagerCore::moveVertical(double from, double to, GuideType type)
396 {
397 	switch (type)
398 	{
399 		case Standard:
400 			m_verticalStdG.removeAt(m_verticalStdG.indexOf(from));
401 			m_verticalStdG.append(to);
402 			if (UndoManager::undoEnabled())
403 			{
404 				SimpleState* ss = new SimpleState(Um::MoveVGuide, nullptr, Um::IGuides);
405 				ss->set("MOVE_V_FROM", from);
406 				ss->set("MOVE_V_TO", to);
407 				m_undoManager->action(m_page, ss);
408 			}
409 			break;
410 		case Auto:
411 			break;
412 	}
413 }
414 
copy(GuideManagerCore * target)415 void GuideManagerCore::copy(GuideManagerCore *target)
416 {
417 	copy(target, Standard);
418 	copy(target, Auto);
419 }
420 
copy(GuideManagerCore * target,GuideType type)421 void GuideManagerCore::copy(GuideManagerCore *target, GuideType type)
422 {
423 	switch (type)
424 	{
425 		case Standard:
426 			target->addHorizontals(m_horizontalStdG, Standard);
427 			target->addVerticals(m_verticalStdG, Standard);
428 			break;
429 		case Auto:
430 			target->setHorizontalAutoCount(m_horizontalAutoCount);
431 			target->setVerticalAutoCount(m_verticalAutoCount);
432 			target->setHorizontalAutoGap(m_horizontalAutoGap);
433 			target->setVerticalAutoGap(m_verticalAutoGap);
434 			target->setHorizontalAutoRefer(m_horizontalAutoRefer);
435 			target->setVerticalAutoRefer(m_verticalAutoRefer);
436 			target->addHorizontals(m_horizontalAutoG, Auto);
437 			target->addVerticals(m_verticalAutoG, Auto);
438 			target->gx = gx;
439 			target->gy = gy;
440 			target->gw = gw;
441 			target->gh = gh;
442 			break;
443 	}
444 }
445 
drawPage(ScPainter * p,ScribusDoc * doc,double lineWidth)446 void GuideManagerCore::drawPage(ScPainter *p, ScribusDoc *doc, double lineWidth)
447 {
448 	Guides::iterator it;
449 	const GuideManager* guideManager = ScCore->primaryMainWindow()->guidePalette;
450 	QColor color(doc->guidesPrefs().guideColor);
451 
452 	if (!m_page || guideManager->pageNr() < 0)
453 		return;
454 
455 	// real painting margins including bleeds
456 	double verticalFrom = 0.0 - doc->bleeds()->top();
457 	double verticalTo = m_page->height() + doc->bleeds()->bottom();
458 	double horizontalFrom = 0.0 - doc->bleeds()->left();
459 	double horizontalTo = m_page->width() + doc->bleeds()->right();
460 
461 	// all standard
462 	p->setPen(color, lineWidth, Qt::DashDotLine, Qt::FlatCap, Qt::MiterJoin);
463 	for (it = m_verticalStdG.begin(); it != m_verticalStdG.end(); ++it)
464 // 		if ((*it) >= 0 && (*it) <= m_page->width())
465 // 			p->drawLine(FPoint((*it), 0), FPoint((*it), m_page->height()));
466 		p->drawLine(FPoint((*it), verticalFrom), FPoint((*it), verticalTo));
467 	for (it = m_horizontalStdG.begin(); it != m_horizontalStdG.end(); ++it)
468 // 		if ((*it) >= 0 && (*it) <= m_page->height())
469 // 			p->drawLine(FPoint(0, (*it)), FPoint(m_page->width(), (*it)));
470 		p->drawLine(FPoint(horizontalFrom, (*it)), FPoint(horizontalTo, (*it)));
471 
472 	// highlight selected standards
473 	if (guideManager->currentIndex() == 0
474 		   && m_page->pageNr() == guideManager->pageNr())
475 	{
476 		p->setPen(Qt::red, lineWidth, Qt::DashDotLine, Qt::FlatCap, Qt::MiterJoin);
477 		Guides highlight = guideManager->selectedVerticals();
478 		for (it = highlight.begin(); it != highlight.end(); ++it)
479 // 			if ((*it) >= 0 && (*it) <= m_page->width())
480 // 				p->drawLine(FPoint((*it), 0), FPoint((*it), m_page->height()));
481 			p->drawLine(FPoint((*it), verticalFrom), FPoint((*it), verticalTo));
482 		highlight = guideManager->selectedHorizontals();
483 		for (it = highlight.begin(); it != highlight.end(); ++it)
484 // 			if ((*it) >= 0 && (*it) <= m_page->height())
485 // 				p->drawLine(FPoint(0, (*it)), FPoint(m_page->width(), (*it)));
486 			p->drawLine(FPoint(horizontalFrom, (*it)), FPoint(horizontalTo, (*it)));
487 	}
488 
489 	// all auto
490 	if (guideManager->currentIndex() == 1 && guideManager->isVisible())
491 		color = Qt::red;
492 	else
493 		color = doc->guidesPrefs().guideColor;
494 	p->setPen(color, lineWidth, Qt::DashDotLine, Qt::FlatCap, Qt::MiterJoin);
495 
496 	for (it = m_verticalAutoG.begin(); it != m_verticalAutoG.end(); ++it)
497 // 		if ((*it) >= 0 && (*it) <= m_page->width())
498 // 			p->drawLine(FPoint((*it), 0), FPoint((*it), m_page->height()));
499 		p->drawLine(FPoint((*it), verticalFrom), FPoint((*it), verticalTo));
500 	for (it = m_horizontalAutoG.begin(); it != m_horizontalAutoG.end(); ++it)
501 // 		if ((*it) >= 0 && (*it) <= m_page->height())
502 // 			p->drawLine(FPoint(0, (*it)), FPoint(m_page->width(), (*it)));
503 		p->drawLine(FPoint(horizontalFrom, (*it)), FPoint(horizontalTo, (*it)));
504 }
505 
isMouseOnHorizontal(double low,double high,GuideType type)506 int GuideManagerCore::isMouseOnHorizontal(double low, double high, GuideType type)
507 {
508 	Guides tmp;
509 	Guides::iterator it;
510 
511 	switch (type)
512 	{
513 		case Standard:
514 			tmp = m_horizontalStdG;
515 			break;
516 		case Auto:
517 			tmp = m_horizontalAutoG;
518 			break;
519 	}
520 	for (it = tmp.begin(); it != tmp.end(); ++it)
521 	{
522 		double guideOffset = (*it) + m_page->yOffset();
523 		if (guideOffset < low && guideOffset > high)
524 			return it - tmp.begin();
525 	}
526 	return -1;
527 }
528 
isMouseOnVertical(double low,double high,GuideType type)529 int GuideManagerCore::isMouseOnVertical(double low, double high, GuideType type)
530 {
531 	Guides tmp;
532 	Guides::iterator it;
533 
534 	switch (type)
535 	{
536 		case Standard:
537 			tmp = m_verticalStdG;
538 			break;
539 		case Auto:
540 			tmp = m_horizontalAutoG;
541 			break;
542 	}
543 	for (it = tmp.begin(); it != tmp.end(); ++it)
544 	{
545 		double guideOffset = (*it) + m_page->xOffset();
546 		if (guideOffset < low && guideOffset > high)
547 			return it - tmp.begin();
548 	}
549 	return -1;
550 }
551 
topLeft(double x,double y)552 QPair<double, double> GuideManagerCore::topLeft(double x, double y)// const
553 {
554 	return QPair<double, double>(closestVertLeft(x), closestHorAbove(y));
555 }
556 
topRight(double x,double y)557 QPair<double, double> GuideManagerCore::topRight(double x, double y)// const
558 {
559 	return QPair<double, double>(closestVertRight(x), closestHorAbove(y));
560 }
561 
bottomLeft(double x,double y)562 QPair<double, double> GuideManagerCore::bottomLeft(double x, double y)// const
563 {
564 	return QPair<double, double>(closestVertLeft(x), closestHorBelow(y));
565 }
566 
bottomRight(double x,double y)567 QPair<double, double> GuideManagerCore::bottomRight(double x, double y)// const
568 {
569 	return QPair<double, double>(closestVertRight(x), closestHorBelow(y));
570 }
571 
closestHorAbove(double y)572 double GuideManagerCore::closestHorAbove(double y)// const
573 {
574 	double closest = 0.0;
575 	for (int i = 0; i < m_horizontalStdG.size(); ++i)
576 	{
577 		if (m_horizontalStdG[i] < y && m_horizontalStdG[i] > closest)
578 			closest = m_horizontalStdG[i];
579 	}
580 
581 	for (int i = 0; i < m_horizontalAutoG.size(); ++i)
582 	{
583 		if (m_horizontalAutoG[i] < y && m_horizontalAutoG[i] > closest)
584 			closest = m_horizontalAutoG[i];
585 	}
586 
587 	if (m_page->Margins.top() < y && m_page->Margins.top() > closest)
588 		closest = m_page->Margins.top();
589 	if (m_page->height() - m_page->Margins.bottom() < y && m_page->height() - m_page->Margins.bottom() > closest)
590 		closest = m_page->height() - m_page->Margins.bottom();
591 
592 	return closest;
593 }
594 
closestHorBelow(double y)595 double GuideManagerCore::closestHorBelow(double y)// const
596 {
597 	double closest = m_page->height();
598 	for (int i = 0; i < m_horizontalStdG.size(); ++i)
599 	{
600 		if (m_horizontalStdG[i] > y && m_horizontalStdG[i] < closest)
601 			closest = m_horizontalStdG[i];
602 	}
603 
604 	for (int i = 0; i < m_horizontalAutoG.size(); ++i)
605 	{
606 		if (m_horizontalAutoG[i] > y && m_horizontalAutoG[i] < closest)
607 			closest = m_horizontalAutoG[i];
608 	}
609 
610 	if (m_page->Margins.top() > y && m_page->Margins.top() < closest)
611 		closest = m_page->Margins.top();
612 	if (m_page->height() - m_page->Margins.bottom() > y && m_page->height() - m_page->Margins.bottom() < closest)
613 		closest = m_page->height() - m_page->Margins.bottom();
614 
615 	return closest;
616 }
617 
closestVertLeft(double x)618 double GuideManagerCore::closestVertLeft(double x)// const
619 {
620 	double closest = 0.0;
621 	for (int i = 0; i < m_verticalStdG.size(); ++i)
622 	{
623 		if (m_verticalStdG[i] < x && m_verticalStdG[i] > closest)
624 			closest = m_verticalStdG[i];
625 	}
626 
627 	for (int i = 0; i < m_verticalAutoG.size(); ++i)
628 	{
629 		if (m_verticalAutoG[i] < x && m_verticalAutoG[i] > closest)
630 			closest = m_verticalAutoG[i];
631 	}
632 
633 	if (m_page->Margins.left() < x && m_page->Margins.left() > closest)
634 		closest = m_page->Margins.left();
635 	if (m_page->width() - m_page->Margins.right() < x && m_page->width() - m_page->Margins.right() > closest)
636 		closest = m_page->width() - m_page->Margins.right();
637 
638 	return closest;
639 }
640 
closestVertRight(double x)641 double GuideManagerCore::closestVertRight(double x)// const
642 {
643 	double closest = m_page->width();
644 	for (int i = 0; i < m_verticalStdG.size(); ++i)
645 	{
646 		if (m_verticalStdG[i] > x && m_verticalStdG[i] < closest)
647 			closest = m_verticalStdG[i];
648 	}
649 
650 	for (int i = 0; i < m_verticalAutoG.size(); ++i)
651 	{
652 		if (m_verticalAutoG[i] > x && m_verticalAutoG[i] < closest)
653 			closest = m_verticalAutoG[i];
654 	}
655 
656 	if (m_page->Margins.left() > x  && m_page->Margins.left() < closest)
657 		closest = m_page->Margins.left();
658 	if (m_page->width() - m_page->Margins.right() > x && m_page->width() - m_page->Margins.right() < closest)
659 		closest = m_page->width() - m_page->Margins.right();
660 
661 	return closest;
662 }
663 
664 
readVerticalGuides(const QString & guideString,ScPage * page,GuideManagerCore::GuideType type,bool useOldGuides)665 void GuideManagerIO::readVerticalGuides(const QString& guideString, ScPage *page, GuideManagerCore::GuideType type, bool useOldGuides)
666 {
667 	QStringList gVal(guideString.split(' ', Qt::SkipEmptyParts));
668 	for (QStringList::Iterator it = gVal.begin(); it != gVal.end(); ++it )
669 		useOldGuides ?
670 			page->guides.addHorizontal(ScCLocale::toDoubleC((*it)), type) :
671 			page->guides.addVertical(ScCLocale::toDoubleC((*it)), type);
672 }
673 
readHorizontalGuides(const QString & guideString,ScPage * page,GuideManagerCore::GuideType type,bool useOldGuides)674 void GuideManagerIO::readHorizontalGuides(const QString& guideString, ScPage *page, GuideManagerCore::GuideType type, bool useOldGuides)
675 {
676 	QStringList gVal(guideString.split(' ', Qt::SkipEmptyParts));
677 	for (QStringList::Iterator it = gVal.begin(); it != gVal.end(); ++it )
678 		useOldGuides ?
679 			page->guides.addVertical(ScCLocale::toDoubleC((*it)), type):
680 			page->guides.addHorizontal(ScCLocale::toDoubleC((*it)), type);
681 }
682 
writeHorizontalGuides(ScPage * page,GuideManagerCore::GuideType type)683 QString GuideManagerIO::writeHorizontalGuides(ScPage *page, GuideManagerCore::GuideType type)
684 {
685 	Guides::iterator it;
686 	QString retval;
687 	QString tmp;
688 	Guides tmpGuides = page->guides.horizontals(type);
689 	for (it = tmpGuides.begin(); it != tmpGuides.end(); ++it)
690 	{
691 		tmp = tmp.setNum((*it));
692 		retval += tmp + " ";
693 	}
694 	return retval;
695 }
696 
writeVerticalGuides(ScPage * page,GuideManagerCore::GuideType type)697 QString GuideManagerIO::writeVerticalGuides(ScPage *page, GuideManagerCore::GuideType type)
698 {
699 	Guides::iterator it;
700 	QString retval;
701 	QString tmp;
702 	Guides tmpGuides = page->guides.verticals(type);
703 	for (it = tmpGuides.begin(); it != tmpGuides.end(); ++it)
704 	{
705 		tmp = tmp.setNum((*it));
706 		retval += tmp + " ";
707 	}
708 	return retval;
709 }
710 
writeSelection(ScPage * page)711 QString GuideManagerIO::writeSelection(ScPage *page)
712 {
713 	return QString("%1 %2 %3 %4").arg(page->guides.gx).arg(page->guides.gy).arg(page->guides.gw).arg(page->guides.gh);
714 }
715 
readSelection(const QString & guideString,ScPage * page)716 void GuideManagerIO::readSelection(const QString& guideString, ScPage *page)
717 {
718 	if (guideString.isEmpty())
719 		return;
720 	QStringList gVal(guideString.split(' ', Qt::SkipEmptyParts));
721 	page->guides.gx = ScCLocale::toDoubleC(gVal[0]);
722 	page->guides.gy = ScCLocale::toDoubleC(gVal[1]);
723 	page->guides.gw = ScCLocale::toDoubleC(gVal[2]);
724 	page->guides.gh = ScCLocale::toDoubleC(gVal[3]);
725 }
726