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