Rev 23268 | Rev 23642 | Go to most recent revision | 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 | */ |
||
3903 | cbradney | 7 | /*************************************************************************** |
8 | copyright : (C) 2005 by Craig Bradney |
||
9 | email : cbradney@zip.com.au |
||
10 | ***************************************************************************/ |
||
11 | |||
12 | /*************************************************************************** |
||
13 | * * |
||
14 | * This program is free software; you can redistribute it and/or modify * |
||
15 | * it under the terms of the GNU General Public License as published by * |
||
16 | * the Free Software Foundation; either version 2 of the License, or * |
||
17 | * (at your option) any later version. * |
||
18 | * * |
||
19 | ***************************************************************************/ |
||
20 | |||
15169 | jghali | 21 | #include "sclimits.h" |
4133 | cbradney | 22 | #include "scribusdoc.h" |
10223 | cbradney | 23 | #include "selection.h" |
13101 | jghali | 24 | #include <QDebug> |
3903 | cbradney | 25 | |
22832 | craig | 26 | Selection::Selection(QObject* parent) : |
27 | QObject(parent), |
||
11735 | jghali | 28 | m_isGUISelection(false), |
29 | m_delaySignals(0), |
||
23268 | jghali | 30 | m_sigSelectionChanged(false) |
4133 | cbradney | 31 | { |
20691 | craig | 32 | m_groupX = m_groupY = m_groupW = m_groupH = 0; |
33 | m_visualGX = m_visualGY = m_visualGW = m_visualGH = 0; |
||
4133 | cbradney | 34 | } |
3903 | cbradney | 35 | |
22832 | craig | 36 | Selection::Selection(QObject* parent, bool guiSelection) : |
37 | QObject(parent), |
||
11735 | jghali | 38 | m_isGUISelection(guiSelection), |
39 | m_delaySignals(0), |
||
23268 | jghali | 40 | m_sigSelectionChanged(false) |
3903 | cbradney | 41 | { |
20691 | craig | 42 | m_groupX = m_groupY = m_groupW = m_groupH = 0; |
43 | m_visualGX = m_visualGY = m_visualGW = m_visualGH = 0; |
||
3903 | cbradney | 44 | } |
45 | |||
4130 | cbradney | 46 | Selection::Selection(const Selection& other) : |
47 | QObject(other.parent()), |
||
4133 | cbradney | 48 | m_SelList(other.m_SelList), |
11736 | jghali | 49 | // We do not copy m_isGUISelection as : |
50 | // 1) copy ctor is used for temporary selections |
||
51 | // 2) having two GUI selections for same doc should really be avoided |
||
52 | m_isGUISelection(false), |
||
11735 | jghali | 53 | // We do not copy m_delaySignals as that can potentially |
54 | // cause much trouble balancing delaySignalOff/On right |
||
55 | m_delaySignals(0), |
||
23268 | jghali | 56 | m_sigSelectionChanged(other.m_sigSelectionChanged) |
4130 | cbradney | 57 | { |
4352 | cbradney | 58 | if (m_isGUISelection && !m_SelList.isEmpty()) |
59 | { |
||
60 | m_SelList[0]->connectToGUI(); |
||
61 | m_SelList[0]->emitAllToGUI(); |
||
62 | m_SelList[0]->setSelected(true); |
||
23268 | jghali | 63 | emit selectionChanged(); |
4352 | cbradney | 64 | } |
20691 | craig | 65 | m_groupX = other.m_groupX; |
66 | m_groupY = other.m_groupY; |
||
67 | m_groupW = other.m_groupW; |
||
68 | m_groupH = other.m_groupH; |
||
69 | m_visualGX = other.m_visualGX; |
||
70 | m_visualGY = other.m_visualGY; |
||
71 | m_visualGW = other.m_visualGW; |
||
72 | m_visualGH = other.m_visualGH; |
||
4130 | cbradney | 73 | } |
3903 | cbradney | 74 | |
22832 | craig | 75 | Selection& Selection::operator=(const Selection &other) |
4130 | cbradney | 76 | { |
22832 | craig | 77 | if (&other == this) |
4130 | cbradney | 78 | return *this; |
11729 | jghali | 79 | if (m_isGUISelection) |
80 | { |
||
81 | SelectionList::Iterator itend = m_SelList.end(); |
||
82 | for (SelectionList::Iterator it = m_SelList.begin(); it != itend; ++it) |
||
83 | (*it)->setSelected(false); |
||
84 | } |
||
23268 | jghali | 85 | m_SelList = other.m_SelList; |
11736 | jghali | 86 | // Do not copy m_isGUISelection for consistency with cpy ctor |
87 | /* m_isGUISelection = other.m_isGUISelection; */ |
||
11735 | jghali | 88 | // We do not copy m_delaySignals as that can potentially |
89 | // cause much trouble balancing delaySignalOff/On right |
||
90 | m_sigSelectionChanged = other.m_sigSelectionChanged; |
||
4352 | cbradney | 91 | if (m_isGUISelection && !m_SelList.isEmpty()) |
92 | { |
||
93 | m_SelList[0]->connectToGUI(); |
||
94 | m_SelList[0]->emitAllToGUI(); |
||
95 | m_SelList[0]->setSelected(true); |
||
23268 | jghali | 96 | emit selectionChanged(); |
4352 | cbradney | 97 | } |
4130 | cbradney | 98 | return *this; |
99 | } |
||
100 | |||
11729 | jghali | 101 | void Selection::copy(Selection& other, bool emptyOther) |
8735 | cbradney | 102 | { |
22832 | craig | 103 | if (&other == this) |
8735 | cbradney | 104 | return; |
11729 | jghali | 105 | if (m_isGUISelection) |
106 | { |
||
107 | SelectionList::Iterator itend = m_SelList.end(); |
||
108 | for (SelectionList::Iterator it = m_SelList.begin(); it != itend; ++it) |
||
109 | (*it)->setSelected(false); |
||
110 | } |
||
22832 | craig | 111 | m_SelList = other.m_SelList; |
23269 | jghali | 112 | if (m_isGUISelection) |
23268 | jghali | 113 | m_sigSelectionChanged = true; |
8735 | cbradney | 114 | if (emptyOther) |
115 | other.clear(); |
||
11729 | jghali | 116 | sendSignals(); |
8735 | cbradney | 117 | } |
118 | |||
3903 | cbradney | 119 | Selection::~Selection() |
120 | { |
||
121 | } |
||
122 | |||
4132 | cbradney | 123 | bool Selection::clear() |
3903 | cbradney | 124 | { |
4133 | cbradney | 125 | if (!m_SelList.isEmpty()) |
126 | { |
||
23268 | jghali | 127 | SelectionList::Iterator itend = m_SelList.end(); |
128 | SelectionList::Iterator it = m_SelList.begin(); |
||
129 | while (it != itend) |
||
3903 | cbradney | 130 | { |
4133 | cbradney | 131 | (*it)->isSingleSel=false; |
132 | if (m_isGUISelection) |
||
11729 | jghali | 133 | { |
134 | (*it)->setSelected(false); |
||
3903 | cbradney | 135 | (*it)->disconnectFromGUI(); |
11729 | jghali | 136 | } |
4133 | cbradney | 137 | ++it; |
3903 | cbradney | 138 | } |
4133 | cbradney | 139 | } |
140 | m_SelList.clear(); |
||
11729 | jghali | 141 | m_sigSelectionChanged = true; |
142 | sendSignals(); |
||
4133 | cbradney | 143 | return true; |
3903 | cbradney | 144 | } |
145 | |||
4132 | cbradney | 146 | bool Selection::connectItemToGUI() |
3903 | cbradney | 147 | { |
4133 | cbradney | 148 | if (!m_isGUISelection || m_SelList.isEmpty()) |
23269 | jghali | 149 | return false; |
150 | |||
151 | QPointer<PageItem> pi = m_SelList.first(); |
||
152 | //Quick check to see if the pointer is nullptr, if its nullptr, we should remove it from the list now |
||
153 | while (pi.isNull()) |
||
3903 | cbradney | 154 | { |
23269 | jghali | 155 | m_SelList.removeAll(pi); |
156 | if (m_SelList.isEmpty()) |
||
157 | break; |
||
158 | pi = m_SelList.first(); |
||
4132 | cbradney | 159 | } |
23269 | jghali | 160 | |
161 | if (pi.isNull()) |
||
162 | return false; |
||
163 | |||
164 | bool ret = pi->connectToGUI(); |
||
165 | pi->emitAllToGUI(); |
||
166 | m_sigSelectionChanged = true; |
||
167 | |||
12125 | jghali | 168 | sendSignals(false); |
6593 | fschmid | 169 | return ret; |
3903 | cbradney | 170 | } |
171 | |||
172 | bool Selection::disconnectAllItemsFromGUI() |
||
173 | { |
||
4133 | cbradney | 174 | if (!m_isGUISelection || m_SelList.isEmpty()) |
175 | return false; |
||
22832 | craig | 176 | SelectionList::Iterator it2end = m_SelList.end(); |
177 | SelectionList::Iterator it2 = m_SelList.begin(); |
||
178 | while (it2 != it2end) |
||
4132 | cbradney | 179 | { |
4133 | cbradney | 180 | (*it2)->disconnectFromGUI(); |
181 | ++it2; |
||
4132 | cbradney | 182 | } |
3903 | cbradney | 183 | return true; |
184 | } |
||
185 | |||
22271 | craig | 186 | bool Selection::addItem(PageItem *item, bool /*ignoreGUI*/) |
3903 | cbradney | 187 | { |
22832 | craig | 188 | if (item == nullptr) |
3903 | cbradney | 189 | return false; |
17388 | jghali | 190 | bool listWasEmpty = m_SelList.isEmpty(); |
4133 | cbradney | 191 | if (listWasEmpty || !m_SelList.contains(item)) |
3903 | cbradney | 192 | { |
4133 | cbradney | 193 | m_SelList.append(item); |
11729 | jghali | 194 | if (m_isGUISelection) |
5859 | tsoots | 195 | { |
11729 | jghali | 196 | item->setSelected(true); |
197 | m_sigSelectionChanged = true; |
||
5859 | tsoots | 198 | } |
11729 | jghali | 199 | sendSignals(); |
4132 | cbradney | 200 | return true; |
3903 | cbradney | 201 | } |
202 | return false; |
||
203 | } |
||
204 | |||
23254 | jghali | 205 | bool Selection::addItems(const QList<PageItem *> items) |
206 | { |
||
207 | if (items.isEmpty()) |
||
208 | return false; |
||
209 | |||
210 | QList< QPointer<PageItem> > toAdd; |
||
211 | toAdd.reserve(items.count()); |
||
212 | for (int i = 0; i < items.count(); ++i) |
||
213 | { |
||
214 | PageItem* item = items.at(i); |
||
215 | if (m_SelList.contains(item)) |
||
216 | continue; |
||
217 | toAdd.append(item); |
||
218 | item->setSelected(true); |
||
219 | } |
||
220 | |||
221 | if (toAdd.count() <= 0) |
||
222 | return false; |
||
223 | |||
224 | m_SelList.append(toAdd); |
||
225 | if (m_isGUISelection) |
||
226 | m_sigSelectionChanged = true; |
||
227 | sendSignals(); |
||
228 | return true; |
||
229 | } |
||
230 | |||
23269 | jghali | 231 | bool Selection::prependItem(PageItem *item) |
3903 | cbradney | 232 | { |
22832 | craig | 233 | if (item == nullptr) |
3934 | cbradney | 234 | return false; |
23269 | jghali | 235 | if (m_SelList.contains(item)) |
236 | return false; |
||
237 | |||
238 | if (m_isGUISelection && !m_SelList.isEmpty()) |
||
239 | m_SelList[0]->disconnectFromGUI(); |
||
240 | m_SelList.prepend(item); |
||
241 | if (m_isGUISelection) |
||
3934 | cbradney | 242 | { |
23269 | jghali | 243 | item->setSelected(true); |
244 | m_sigSelectionChanged = true; |
||
245 | } |
||
246 | sendSignals(); |
||
247 | return true; |
||
3903 | cbradney | 248 | } |
249 | |||
8266 | avox | 250 | PageItem *Selection::itemAt_(int index) |
3903 | cbradney | 251 | { |
23268 | jghali | 252 | if (!m_SelList.isEmpty() && index < m_SelList.count()) |
4132 | cbradney | 253 | { |
23249 | jghali | 254 | QPointer<PageItem> pi = m_SelList[index]; |
22518 | craig | 255 | //If not nullptr return it, otherwise remove from the list and return nullptr |
4132 | cbradney | 256 | if (!pi.isNull()) |
257 | return pi; |
||
9803 | fschmid | 258 | // SelectionList::Iterator it=m_SelList.at(index); |
259 | m_SelList.removeAt(index); |
||
4132 | cbradney | 260 | } |
22518 | craig | 261 | return nullptr; |
3903 | cbradney | 262 | } |
3934 | cbradney | 263 | |
18357 | jghali | 264 | QList<PageItem*> Selection::items() const |
265 | { |
||
266 | QList<PageItem*> selectedItems; |
||
267 | for (int i = 0; i < m_SelList.count(); ++i) |
||
268 | { |
||
269 | QPointer<PageItem> pi = m_SelList.at(i); |
||
270 | if (pi.isNull()) |
||
271 | continue; |
||
272 | selectedItems.append(pi.data()); |
||
273 | } |
||
274 | return selectedItems; |
||
275 | } |
||
276 | |||
4132 | cbradney | 277 | bool Selection::removeFirst() |
3934 | cbradney | 278 | { |
4133 | cbradney | 279 | if (!m_SelList.isEmpty()) |
3934 | cbradney | 280 | { |
11729 | jghali | 281 | if (m_isGUISelection && m_SelList.first()) |
282 | m_SelList.first()->setSelected(false); |
||
4133 | cbradney | 283 | removeItem(m_SelList.first()); |
284 | if (m_SelList.isEmpty()) |
||
3934 | cbradney | 285 | return true; |
4133 | cbradney | 286 | if (m_isGUISelection) |
11729 | jghali | 287 | m_sigSelectionChanged = true; |
288 | sendSignals(); |
||
3934 | cbradney | 289 | } |
290 | return false; |
||
291 | } |
||
292 | |||
4132 | cbradney | 293 | bool Selection::removeItem(PageItem *item) |
3934 | cbradney | 294 | { |
23175 | jghali | 295 | if (m_SelList.isEmpty() || !m_SelList.contains(item)) |
296 | return false; |
||
297 | |||
298 | bool removeOk = (m_SelList.removeAll(item) == 1); |
||
299 | if (removeOk) |
||
4132 | cbradney | 300 | { |
23175 | jghali | 301 | if (m_isGUISelection) |
3934 | cbradney | 302 | { |
23175 | jghali | 303 | item->setSelected(false); |
304 | item->disconnectFromGUI(); |
||
3934 | cbradney | 305 | } |
23175 | jghali | 306 | item->isSingleSel = false; |
307 | } |
||
13101 | jghali | 308 | |
23175 | jghali | 309 | if (m_isGUISelection) |
310 | { |
||
311 | m_sigSelectionChanged = true; |
||
312 | sendSignals(); |
||
313 | } |
||
314 | return removeOk; |
||
315 | } |
||
316 | |||
317 | bool Selection::removeItemsOfLayer(int layedID) |
||
318 | { |
||
319 | if (m_SelList.isEmpty()) |
||
320 | return false; |
||
321 | |||
322 | int oldSelCount = m_SelList.count(); |
||
323 | |||
324 | delaySignalsOn(); |
||
325 | |||
326 | int selIndex = 0; |
||
327 | while (selIndex < m_SelList.count()) |
||
328 | { |
||
329 | QPointer<PageItem> pi = m_SelList.at(selIndex); |
||
330 | if (pi.isNull()) |
||
5859 | tsoots | 331 | { |
23175 | jghali | 332 | removeItem(itemAt(selIndex)); |
333 | continue; |
||
5859 | tsoots | 334 | } |
23175 | jghali | 335 | |
336 | if (pi->m_layerID != layedID) |
||
337 | { |
||
338 | ++selIndex; |
||
339 | continue; |
||
340 | } |
||
341 | |||
342 | removeItem(itemAt(selIndex)); |
||
4132 | cbradney | 343 | } |
23175 | jghali | 344 | |
345 | delaySignalsOff(); |
||
346 | |||
347 | bool itemsRemoved = (oldSelCount != m_SelList.count()); |
||
348 | return itemsRemoved; |
||
3934 | cbradney | 349 | } |
350 | |||
23249 | jghali | 351 | void Selection::replaceItem(PageItem* oldItem, PageItem* newItem) |
352 | { |
||
353 | delaySignalsOn(); |
||
354 | |||
355 | int itemIndex = findItem(oldItem); |
||
356 | if (itemIndex >= 0) |
||
357 | m_SelList.replace(itemIndex, newItem); |
||
358 | |||
359 | delaySignalsOff(); |
||
360 | } |
||
361 | |||
8583 | cbradney | 362 | PageItem* Selection::takeItem(int itemIndex) |
3934 | cbradney | 363 | { |
23175 | jghali | 364 | if (m_SelList.isEmpty() || itemIndex >= m_SelList.count()) |
365 | return nullptr; |
||
366 | |||
367 | PageItem *item = m_SelList[itemIndex]; |
||
368 | bool removeOk = (m_SelList.removeAll(item) == 1); |
||
369 | if (removeOk) |
||
4132 | cbradney | 370 | { |
23175 | jghali | 371 | item->isSingleSel = false; |
372 | if (m_isGUISelection) |
||
3934 | cbradney | 373 | { |
23175 | jghali | 374 | item->setSelected(false); |
375 | m_sigSelectionChanged = true; |
||
376 | if (itemIndex == 0) |
||
377 | item->disconnectFromGUI(); |
||
3934 | cbradney | 378 | } |
23175 | jghali | 379 | sendSignals(); |
380 | return item; |
||
4132 | cbradney | 381 | } |
22518 | craig | 382 | return nullptr; |
3934 | cbradney | 383 | } |
384 | |||
8266 | avox | 385 | QStringList Selection::getSelectedItemsByName() const |
3934 | cbradney | 386 | { |
387 | QStringList names; |
||
8266 | avox | 388 | SelectionList::ConstIterator it=m_SelList.begin(); |
389 | SelectionList::ConstIterator itend=m_SelList.end(); |
||
3934 | cbradney | 390 | for ( ; it!=itend ; ++it) |
391 | names.append((*it)->itemName()); |
||
392 | return names; |
||
393 | } |
||
4049 | cbradney | 394 | |
8266 | avox | 395 | double Selection::width() const |
6442 | cbradney | 396 | { |
397 | if (m_SelList.isEmpty()) |
||
398 | return 0.0; |
||
15169 | jghali | 399 | double minX = std::numeric_limits<double>::max(); |
400 | double maxX = -std::numeric_limits<double>::max(); |
||
8266 | avox | 401 | SelectionList::ConstIterator it=m_SelList.begin(); |
402 | SelectionList::ConstIterator itend=m_SelList.end(); |
||
22832 | craig | 403 | double x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0; |
404 | for ( ; it != itend ; ++it) |
||
6442 | cbradney | 405 | { |
406 | (*it)->getBoundingRect(&x1, &y1, &x2, &y2); |
||
22832 | craig | 407 | if (x1 < minX) |
408 | minX = x1; |
||
409 | if (x2 > maxX) |
||
410 | maxX = x2; |
||
6442 | cbradney | 411 | } |
412 | return maxX-minX; |
||
413 | } |
||
414 | |||
8266 | avox | 415 | double Selection::height() const |
6442 | cbradney | 416 | { |
417 | if (m_SelList.isEmpty()) |
||
418 | return 0.0; |
||
15169 | jghali | 419 | double minY = std::numeric_limits<double>::max(); |
420 | double maxY = -std::numeric_limits<double>::max(); |
||
8266 | avox | 421 | SelectionList::ConstIterator it=m_SelList.begin(); |
422 | SelectionList::ConstIterator itend=m_SelList.end(); |
||
22832 | craig | 423 | double x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0; |
424 | for ( ; it != itend ; ++it) |
||
6442 | cbradney | 425 | { |
426 | (*it)->getBoundingRect(&x1, &y1, &x2, &y2); |
||
22832 | craig | 427 | if (y1 < minY) |
428 | minY = y1; |
||
429 | if (y2 > maxY) |
||
430 | maxY = y2; |
||
6442 | cbradney | 431 | } |
432 | return maxY-minY; |
||
433 | } |
||
7575 | cbradney | 434 | |
435 | void Selection::setGroupRect() |
||
436 | { |
||
437 | PageItem *currItem; |
||
22271 | craig | 438 | int selectedItemCount = count(); |
15169 | jghali | 439 | if (selectedItemCount == 0) |
440 | { |
||
20691 | craig | 441 | m_groupX = m_groupY = m_groupW = m_groupH = 0; |
442 | m_visualGX = m_visualGY = m_visualGW = m_visualGH = 0; |
||
15169 | jghali | 443 | return; |
444 | } |
||
445 | double minx = std::numeric_limits<double>::max(); |
||
446 | double miny = std::numeric_limits<double>::max(); |
||
447 | double maxx = -std::numeric_limits<double>::max(); |
||
448 | double maxy = -std::numeric_limits<double>::max(); |
||
449 | double vminx = std::numeric_limits<double>::max(); |
||
450 | double vminy = std::numeric_limits<double>::max(); |
||
451 | double vmaxx = -std::numeric_limits<double>::max(); |
||
452 | double vmaxy = -std::numeric_limits<double>::max(); |
||
453 | |||
22271 | craig | 454 | for (int i = 0; i < selectedItemCount; ++i) |
7575 | cbradney | 455 | { |
22271 | craig | 456 | currItem = itemAt(i); |
457 | if (currItem->rotation() != 0.0) |
||
7575 | cbradney | 458 | { |
21288 | jghali | 459 | QRectF itRect(currItem->getBoundingRect()); |
21293 | jghali | 460 | minx = qMin(minx, itRect.x()); |
461 | miny = qMin(miny, itRect.y()); |
||
462 | maxx = qMax(maxx, itRect.right()); |
||
463 | maxy = qMax(maxy, itRect.bottom()); |
||
12463 | pierre | 464 | |
465 | // Same for visual |
||
21288 | jghali | 466 | QRectF itVisualRect(currItem->getVisualBoundingRect()); |
467 | vminx = qMin(vminx, itVisualRect.x()); |
||
468 | vminy = qMin(vminy, itVisualRect.y()); |
||
469 | vmaxx = qMax(vmaxx, itVisualRect.right()); |
||
470 | vmaxy = qMax(vmaxy, itVisualRect.bottom()); |
||
7575 | cbradney | 471 | } |
472 | else |
||
473 | { |
||
8562 | jghali | 474 | minx = qMin(minx, currItem->xPos()); |
475 | miny = qMin(miny, currItem->yPos()); |
||
476 | maxx = qMax(maxx, currItem->xPos() + currItem->width()); |
||
477 | maxy = qMax(maxy, currItem->yPos() + currItem->height()); |
||
12463 | pierre | 478 | |
479 | vminx = qMin(vminx, currItem->visualXPos()); |
||
480 | vminy = qMin(vminy, currItem->visualYPos()); |
||
481 | vmaxx = qMax(vmaxx, currItem->visualXPos() + currItem->visualWidth()); |
||
482 | vmaxy = qMax(vmaxy, currItem->visualYPos() + currItem->visualHeight()); |
||
7575 | cbradney | 483 | } |
484 | } |
||
20691 | craig | 485 | m_groupX = minx; |
486 | m_groupY = miny; |
||
487 | m_groupW = maxx - minx; |
||
488 | m_groupH = maxy - miny; |
||
12463 | pierre | 489 | |
20691 | craig | 490 | m_visualGX = vminx; |
491 | m_visualGY = vminy; |
||
492 | m_visualGW = vmaxx - vminx; |
||
493 | m_visualGH = vmaxy - vminy; |
||
7575 | cbradney | 494 | } |
495 | |||
496 | void Selection::getGroupRect(double *x, double *y, double *w, double *h) |
||
497 | { |
||
13801 | pierre | 498 | setGroupRect(); |
20691 | craig | 499 | *x = m_groupX; |
500 | *y = m_groupY; |
||
501 | *w = m_groupW; |
||
502 | *h = m_groupH; |
||
7611 | cbradney | 503 | } |
7686 | cbradney | 504 | |
13801 | pierre | 505 | QRectF Selection::getGroupRect() |
506 | { |
||
507 | double x, y, w, h; |
||
508 | getGroupRect(&x, &y, &w, &h); |
||
509 | return QRectF(x,y,w,h); |
||
510 | } |
||
511 | |||
12463 | pierre | 512 | void Selection::getVisualGroupRect(double * x, double * y, double * w, double * h) |
513 | { |
||
13801 | pierre | 514 | setGroupRect(); |
20691 | craig | 515 | *x = m_visualGX; |
516 | *y = m_visualGY; |
||
517 | *w = m_visualGW; |
||
518 | *h = m_visualGH; |
||
12463 | pierre | 519 | } |
520 | |||
13801 | pierre | 521 | QRectF Selection::getVisualGroupRect() |
522 | { |
||
523 | double x, y, w, h; |
||
524 | getGroupRect(&x, &y, &w, &h); |
||
525 | return QRectF(x,y,w,h); |
||
526 | } |
||
527 | |||
22120 | jghali | 528 | bool Selection::containsItemType(PageItem::ItemType type) const |
529 | { |
||
530 | if (m_SelList.isEmpty()) |
||
531 | return false; |
||
532 | SelectionList::ConstIterator it = m_SelList.begin(); |
||
533 | SelectionList::ConstIterator itend = m_SelList.end(); |
||
534 | for (; it != itend; ++it) |
||
535 | { |
||
22121 | jghali | 536 | if ((*it)->itemType() == type) |
22120 | jghali | 537 | return true; |
538 | } |
||
539 | return false; |
||
540 | } |
||
541 | |||
8266 | avox | 542 | bool Selection::itemsAreSameType() const |
7686 | cbradney | 543 | { |
544 | //CB Putting count=1 before isempty test as its probably the most likely, given our view code. |
||
22832 | craig | 545 | if (m_SelList.count() == 1) |
7686 | cbradney | 546 | return true; |
547 | if (m_SelList.isEmpty()) |
||
548 | return false; |
||
22832 | craig | 549 | SelectionList::ConstIterator it = m_SelList.begin(); |
550 | SelectionList::ConstIterator itend = m_SelList.end(); |
||
8266 | avox | 551 | PageItem::ItemType itemType = (*it)->itemType(); |
7686 | cbradney | 552 | for ( ; it!=itend ; ++it) |
553 | { |
||
16105 | fschmid | 554 | if ((*it)->isGroup()) // ignore GroupControl items |
9057 | fschmid | 555 | continue; |
8266 | avox | 556 | if ((*it)->itemType() != itemType) |
7686 | cbradney | 557 | return false; |
558 | } |
||
559 | return true; |
||
560 | } |
||
11729 | jghali | 561 | |
23188 | jghali | 562 | bool Selection::itemsAreOnSamePage() const |
563 | { |
||
564 | //CB Putting count=1 before isempty test as its probably the most likely, given our view code. |
||
565 | if (m_SelList.count() == 1) |
||
566 | return true; |
||
567 | if (m_SelList.isEmpty()) |
||
568 | return false; |
||
569 | auto it = m_SelList.begin(); |
||
570 | auto itend = m_SelList.end(); |
||
571 | auto ownPage = (*it)->OwnPage; |
||
572 | for ( ; it!=itend ; ++it) |
||
573 | { |
||
574 | if ((*it)->OwnPage != ownPage) |
||
575 | return false; |
||
576 | } |
||
577 | return true; |
||
578 | } |
||
579 | |||
22598 | craig | 580 | int Selection::objectsLayer() const |
14296 | jghali | 581 | { |
582 | if (m_SelList.isEmpty()) |
||
583 | return -1; |
||
22832 | craig | 584 | int layerID = m_SelList.at(0)->m_layerID; |
14296 | jghali | 585 | for (int i = 1; i < m_SelList.count(); ++i) |
586 | { |
||
22832 | craig | 587 | if (m_SelList.at(i)->m_layerID != layerID) |
14296 | jghali | 588 | { |
589 | layerID = -1; |
||
590 | break; |
||
591 | } |
||
592 | } |
||
593 | return layerID; |
||
594 | } |
||
595 | |||
22598 | craig | 596 | bool Selection::objectsHaveSameParent() const |
17092 | jghali | 597 | { |
598 | int selectedItemCount = m_SelList.count(); |
||
599 | if (selectedItemCount <= 1) |
||
600 | return true; |
||
601 | |||
602 | bool haveSameParent = true; |
||
603 | const PageItem *firstItem = itemAt(0); |
||
604 | for (int a = 1; a < selectedItemCount; ++a) |
||
605 | { |
||
606 | if (itemAt(a)->Parent != firstItem->Parent) |
||
607 | { |
||
608 | haveSameParent = false; |
||
609 | break; |
||
610 | } |
||
611 | } |
||
612 | return haveSameParent; |
||
613 | } |
||
614 | |||
22598 | craig | 615 | bool Selection::signalsDelayed() |
11729 | jghali | 616 | { |
617 | return (m_isGUISelection && (m_delaySignals > 0)); |
||
618 | } |
||
619 | |||
22598 | craig | 620 | void Selection::delaySignalsOn() |
11729 | jghali | 621 | { |
622 | ++m_delaySignals; |
||
623 | } |
||
624 | |||
22598 | craig | 625 | void Selection::delaySignalsOff() |
11729 | jghali | 626 | { |
627 | --m_delaySignals; |
||
628 | if (m_delaySignals <= 0) |
||
629 | sendSignals(); |
||
630 | } |
||
631 | |||
12125 | jghali | 632 | void Selection::sendSignals(bool guiConnect) |
11729 | jghali | 633 | { |
634 | if (m_isGUISelection && (m_delaySignals <= 0)) |
||
635 | { |
||
15169 | jghali | 636 | setGroupRect(); |
15318 | jghali | 637 | // JG - We should probably add an m_sigSelectionChanged here |
638 | // to avoid multiple connectItemToGUI() if sendSignals() is called |
||
639 | // several times successively (but does that happen?) |
||
640 | if (guiConnect /*&& m_sigSelectionChanged*/) |
||
12125 | jghali | 641 | connectItemToGUI(); |
11729 | jghali | 642 | if (m_sigSelectionChanged) |
643 | emit selectionChanged(); |
||
644 | m_sigSelectionChanged = false; |
||
645 | } |
||
646 | } |
||
12463 | pierre | 647 | |
13101 | jghali | 648 |