Rev 11832 | 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 | */ |
||
181 | Franz | 7 | /*************************************************************************** |
8 | guidemanager.cpp |
||
9 | ------------------- |
||
10 | begin : Fri Jan 30 2004 |
||
11 | copyright : (C) 2004 by Alessandro Rimoldi |
||
12 | copyright : (C) by Franz Schmid |
||
13 | e-mail : http://www.ideale.ch/contact |
||
14 | ***************************************************************************/ |
||
15 | |||
16 | /*************************************************************************** |
||
17 | * * |
||
18 | * This program is free software; you can redistribute it and/or modify * |
||
19 | * it under the terms of the GNU General Public License as published by * |
||
20 | * the Free Software Foundation; either version 2 of the License, or * |
||
21 | * (at your option) any later version. * |
||
22 | * * |
||
23 | ***************************************************************************/ |
||
24 | |||
5901 | subik | 25 | #include "guidemanager.h" |
10181 | cbradney | 26 | #include "commonstrings.h" |
27 | #include "page.h" |
||
28 | #include "scinputdialog.h" |
||
5901 | subik | 29 | #include "scribuscore.h" |
30 | #include "scribusdoc.h" |
||
10181 | cbradney | 31 | #include "selection.h" |
32 | #include "undomanager.h" |
||
5901 | subik | 33 | #include "units.h" |
34 | #include "util.h" |
||
10205 | subik | 35 | #include "guidesmodel.h" |
36 | #include "guidesdelegate.h" |
||
2164 | subik | 37 | |
181 | Franz | 38 | |
5087 | subik | 39 | GuideManager::GuideManager(QWidget* parent) : |
8524 | subik | 40 | ScrPaletteBase(parent, "GuideManager"), |
5909 | subik | 41 | m_Doc(0), |
6747 | subik | 42 | currentPage(0), |
9069 | subik | 43 | m_drawGuides(true) |
3 | paul | 44 | { |
8524 | subik | 45 | setupUi(this); |
6001 | subik | 46 | tabWidget->setEnabled(false); |
8664 | subik | 47 | horizontalAutoGapSpin->setMinimum(0.0); |
48 | horizontalAutoGapSpin->setMaximum(100.0); |
||
49 | verticalAutoGapSpin->setMinimum(0.0); |
||
50 | verticalAutoGapSpin->setMaximum(100.0); |
||
2143 | subik | 51 | |
10205 | subik | 52 | // MVC |
53 | horizontalModel = new GuidesModel(this); |
||
54 | verticalModel = new GuidesModel(this); |
||
55 | GuidesDelegate * delegate = new GuidesDelegate(); |
||
56 | horizontalView->setItemDelegateForColumn(0, delegate); |
||
57 | verticalView->setItemDelegateForColumn(0, delegate); |
||
58 | horizontalView->setModel(horizontalModel); |
||
59 | verticalView->setModel(verticalModel); |
||
60 | |||
61 | connect(addHorButton, SIGNAL(clicked()), this, SLOT(addHorButton_clicked())); |
||
62 | connect(delHorButton, SIGNAL(clicked()), this, SLOT(delHorButton_clicked())); |
||
63 | connect(addVerButton, SIGNAL(clicked()), this, SLOT(addVerButton_clicked())); |
||
64 | connect(delVerButton, SIGNAL(clicked()), this, SLOT(delVerButton_clicked())); |
||
65 | connect(applyToAllStdButton, SIGNAL(clicked()), |
||
66 | this, SLOT(applyToAllStdButton_clicked())); |
||
67 | connect(horizontalAutoCountSpin, SIGNAL(valueChanged(int)), |
||
68 | this, SLOT(horizontalAutoCountSpin_valueChanged(int))); |
||
69 | connect(verticalAutoCountSpin, SIGNAL(valueChanged(int)), |
||
70 | this, SLOT(verticalAutoCountSpin_valueChanged(int))); |
||
71 | connect(horizontalAutoGapCheck, SIGNAL(stateChanged(int)), |
||
72 | this, SLOT(horizontalAutoGapCheck_stateChanged(int))); |
||
73 | connect(verticalAutoGapCheck, SIGNAL(stateChanged(int)), |
||
74 | this, SLOT(verticalAutoGapCheck_stateChanged(int))); |
||
75 | connect(horizontalAutoGapSpin, SIGNAL(valueChanged(double)), |
||
76 | this, SLOT(horizontalAutoGapSpin_valueChanged(double))); |
||
77 | connect(verticalAutoGapSpin, SIGNAL(valueChanged(double)), |
||
78 | this, SLOT(verticalAutoGapSpin_valueChanged(double))); |
||
10224 | subik | 79 | |
80 | connect(horizontalPageAutoButton, SIGNAL(toggled(bool)), |
||
81 | this, SLOT(horizontalPageAutoButton_toggled(bool))); |
||
82 | connect(horizontalMarginsAutoButton, SIGNAL(toggled(bool)), |
||
83 | this, SLOT(horizontalMarginsAutoButton_toggled(bool))); |
||
84 | connect(horizontalSelectionAutoButton, SIGNAL(toggled(bool)), |
||
85 | this, SLOT(horizontalSelectionAutoButton_toggled(bool))); |
||
86 | connect(verticalPageAutoButton, SIGNAL(toggled(bool)), |
||
87 | this, SLOT(verticalPageAutoButton_toggled(bool))); |
||
88 | connect(verticalMarginsAutoButton, SIGNAL(toggled(bool)), |
||
89 | this, SLOT(verticalMarginsAutoButton_toggled(bool))); |
||
90 | connect(verticalSelectionAutoButton, SIGNAL(toggled(bool)), |
||
91 | this, SLOT(verticalSelectionAutoButton_toggled(bool))); |
||
92 | |||
10205 | subik | 93 | connect(applyToAllAutoButton, SIGNAL(clicked()), |
94 | this, SLOT(applyToAllAutoButton_clicked())); |
||
95 | connect(deletePageButton, SIGNAL(clicked()), |
||
96 | this, SLOT(deletePageButton_clicked())); |
||
97 | connect(deleteAllGuides, SIGNAL(clicked()), |
||
98 | this, SLOT(deleteAllGuides_clicked())); |
||
99 | |||
10206 | subik | 100 | connect(horizontalModel, SIGNAL(valueChanged()), this, SLOT(horizontalModel_valueChanged())); |
101 | connect(verticalModel, SIGNAL(valueChanged()), this, SLOT(verticalModel_valueChanged())); |
||
5087 | subik | 102 | } |
103 | |||
5781 | cbradney | 104 | void GuideManager::setDoc(ScribusDoc* doc) |
105 | { |
||
106 | m_Doc=doc; |
||
11836 | subik | 107 | qobject_cast<GuidesDelegate*>(horizontalView->itemDelegateForColumn(0))->setDoc(doc); |
6270 | tsoots | 108 | if (!m_Doc) |
109 | currentPage = 0; |
||
6001 | subik | 110 | tabWidget->setEnabled(doc ? true : false); |
5781 | cbradney | 111 | } |
112 | |||
5087 | subik | 113 | void GuideManager::setupPage() |
114 | { |
||
5781 | cbradney | 115 | if (!m_Doc) |
116 | return; |
||
6203 | subik | 117 | m_drawGuides = false; |
5087 | subik | 118 | setEnabled(true); |
5996 | subik | 119 | // store old values for current page (=page to leave) |
10685 | subik | 120 | if (currentPage) |
121 | storePageValues(currentPage); |
||
122 | |||
5781 | cbradney | 123 | currentPage = m_Doc->currentPage(); |
5087 | subik | 124 | unitChange(); |
9069 | subik | 125 | setupGui(); |
126 | } |
||
6203 | subik | 127 | |
9069 | subik | 128 | void GuideManager::setupGui() |
129 | { |
||
10685 | subik | 130 | disconnect(horizontalAutoGapCheck, SIGNAL(stateChanged(int)), |
131 | this, SLOT(horizontalAutoGapCheck_stateChanged(int))); |
||
132 | disconnect(verticalAutoGapCheck, SIGNAL(stateChanged(int)), |
||
133 | this, SLOT(verticalAutoGapCheck_stateChanged(int))); |
||
134 | |||
5909 | subik | 135 | // restore values from new page |
5341 | subik | 136 | clearRestoreHorizontalList(); |
137 | clearRestoreVerticalList(); |
||
5909 | subik | 138 | // restore: brand "auto guides into GUI restore algorithm" |
139 | bool enable = currentPage->guides.horizontalAutoGap() > 0.0 ? true : false; |
||
140 | horizontalAutoGapCheck->setChecked(enable); |
||
141 | horizontalAutoGapSpin->setEnabled(enable); |
||
5996 | subik | 142 | horizontalAutoGapSpin->setValue(pts2value(currentPage->guides.horizontalAutoGap(), docUnitIndex)); |
5909 | subik | 143 | horizontalAutoCountSpin->setValue(currentPage->guides.horizontalAutoCount()); |
5972 | subik | 144 | if (horizontalAutoCountSpin->value()==0) |
145 | { |
||
146 | horizontalAutoGapSpin->setEnabled(false); |
||
147 | horizontalAutoGapCheck->setEnabled(false); |
||
148 | } |
||
10224 | subik | 149 | setHorizontalRefer(currentPage->guides.horizontalAutoRefer()); |
6747 | subik | 150 | // allow the selection radio button? |
7715 | subik | 151 | horizontalSelectionAutoButton->setEnabled(!m_Doc->m_Selection->isEmpty()); |
6212 | subik | 152 | |
5909 | subik | 153 | // verticals |
154 | enable = currentPage->guides.verticalAutoGap() > 0.0 ? true : false; |
||
155 | verticalAutoGapCheck->setChecked(enable); |
||
156 | verticalAutoGapSpin->setEnabled(enable); |
||
5996 | subik | 157 | verticalAutoGapSpin->setValue(pts2value(currentPage->guides.verticalAutoGap(), docUnitIndex)); |
5909 | subik | 158 | verticalAutoCountSpin->setValue(currentPage->guides.verticalAutoCount()); |
5972 | subik | 159 | if (verticalAutoCountSpin->value()==0) |
160 | { |
||
161 | verticalAutoGapSpin->setEnabled(false); |
||
162 | verticalAutoGapCheck->setEnabled(false); |
||
163 | } |
||
10224 | subik | 164 | setVerticalRefer(currentPage->guides.verticalAutoRefer()); |
6203 | subik | 165 | // allow the selection radio button? |
7715 | subik | 166 | verticalSelectionAutoButton->setEnabled(!m_Doc->m_Selection->isEmpty()); |
6747 | subik | 167 | |
10685 | subik | 168 | connect(horizontalAutoGapCheck, SIGNAL(stateChanged(int)), |
169 | this, SLOT(horizontalAutoGapCheck_stateChanged(int))); |
||
170 | connect(verticalAutoGapCheck, SIGNAL(stateChanged(int)), |
||
171 | this, SLOT(verticalAutoGapCheck_stateChanged(int))); |
||
172 | |||
6203 | subik | 173 | m_drawGuides = true; |
174 | drawGuides(); |
||
5087 | subik | 175 | } |
176 | |||
5996 | subik | 177 | void GuideManager::storePageValues(Page *page) |
5909 | subik | 178 | { |
5996 | subik | 179 | if (!page || !m_Doc) |
5909 | subik | 180 | return; |
181 | |||
182 | double gapValue = 0.0; |
||
183 | if (horizontalAutoGapCheck->isChecked()) |
||
5996 | subik | 184 | gapValue = value2pts(horizontalAutoGapSpin->value(), docUnitIndex); |
8856 | subik | 185 | page->guides.setHorizontalAutoGap(gapValue); |
5996 | subik | 186 | page->guides.setHorizontalAutoCount(horizontalAutoCountSpin->value()); |
10224 | subik | 187 | page->guides.setHorizontalAutoRefer(horizontalRefer()); |
7713 | subik | 188 | page->guides.addHorizontals(getAutoHorizontals(), GuideManagerCore::Auto); |
5909 | subik | 189 | |
190 | gapValue = 0.0; |
||
191 | if (verticalAutoGapCheck->isChecked()) |
||
5996 | subik | 192 | gapValue = value2pts(verticalAutoGapSpin->value(), docUnitIndex); |
8856 | subik | 193 | page->guides.setVerticalAutoGap(gapValue); |
5996 | subik | 194 | page->guides.setVerticalAutoCount(verticalAutoCountSpin->value()); |
10224 | subik | 195 | page->guides.setVerticalAutoRefer(verticalRefer()); |
7713 | subik | 196 | page->guides.addVerticals(getAutoVerticals(), GuideManagerCore::Auto); |
5909 | subik | 197 | } |
198 | |||
10903 | cbradney | 199 | void GuideManager::changeEvent(QEvent *e) |
200 | { |
||
201 | if (e->type() == QEvent::LanguageChange) |
||
202 | { |
||
203 | languageChange(); |
||
204 | } |
||
205 | else |
||
206 | QWidget::changeEvent(e); |
||
207 | } |
||
208 | |||
209 | void GuideManager::languageChange() |
||
210 | { |
||
211 | setWindowTitle( tr("Guide Manager") ); |
||
212 | tabWidget->setTabText(0, tr( "&Single") ); |
||
213 | tabWidget->setTabText(1, tr( "&Column/Row") ); |
||
214 | tabWidget->setTabText(2, tr( "&Misc") ); |
||
215 | horizontalGroupBox->setTitle( tr("Horizontals") ); |
||
216 | verticalGroupBox->setTitle( tr("Verticals") ); |
||
217 | addHorButton->setText( tr("&Add") ); |
||
218 | delHorButton->setText( tr("D&elete") ); |
||
219 | addVerButton->setText( tr("A&dd") ); |
||
220 | delVerButton->setText( tr("De&lete") ); |
||
221 | lockCheck->setText( tr("&Lock Guides") ); |
||
222 | applyToAllStdButton->setText( tr("Appl&y to All Pages") ); |
||
223 | horizontalAutoGroup->setTitle( tr("Horizontals") ); |
||
224 | verticalAutoGroup->setTitle( tr("Verticals") ); |
||
225 | textLabel1->setText( tr("&Number:") ); |
||
226 | textLabel1_2->setText( tr("Nu&mber:") ); |
||
227 | horizontalAutoGapCheck->setText( tr("U&se Gap:") ); |
||
228 | verticalAutoGapCheck->setText( tr("Use &Gap:") ); |
||
229 | groupBox->setTitle( tr("Refer To") ); |
||
230 | groupBox_2->setTitle( tr("Refer To") ); |
||
231 | horizontalPageAutoButton->setText( tr("&Page") ); |
||
232 | horizontalMarginsAutoButton->setText( tr("M&argins") ); |
||
233 | horizontalSelectionAutoButton->setText( tr("S&election") ); |
||
234 | verticalPageAutoButton->setText( tr("&Page") ); |
||
235 | verticalMarginsAutoButton->setText( tr("M&argins") ); |
||
236 | verticalSelectionAutoButton->setText( tr("S&election") ); |
||
237 | applyToAllAutoButton->setText( tr("Appl&y to All Pages") ); |
||
238 | deletePageButton->setText( tr("Delete Guides from Current &Page") ); |
||
239 | deleteAllGuides->setText( tr("Delete Guides from &All Pages") ); |
||
240 | } |
||
241 | |||
5087 | subik | 242 | void GuideManager::unitChange() |
243 | { |
||
5781 | cbradney | 244 | if (!m_Doc) |
245 | return; |
||
6219 | subik | 246 | // a little bit magic to get Verticals (unit) into group boxes |
10394 | cbradney | 247 | horizontalGroupBox->setTitle(horizontalGroupBox->title().remove(" ("+suffix.trimmed()+")")); |
248 | verticalGroupBox->setTitle(verticalGroupBox->title().remove(" ("+suffix.trimmed()+")")); |
||
5781 | cbradney | 249 | docUnitIndex = m_Doc->unitIndex(); |
10229 | subik | 250 | int docUnitDecimals = unitGetPrecisionFromIndex(docUnitIndex); |
5087 | subik | 251 | |
4185 | subik | 252 | suffix = unitGetSuffixFromIndex(docUnitIndex); |
5087 | subik | 253 | horizontalAutoGapSpin->setSuffix(suffix); |
254 | verticalAutoGapSpin->setSuffix(suffix); |
||
5901 | subik | 255 | horizontalAutoGapSpin->setDecimals(docUnitDecimals); |
256 | verticalAutoGapSpin->setDecimals(docUnitDecimals); |
||
10394 | cbradney | 257 | horizontalGroupBox->setTitle(horizontalGroupBox->title() + " ("+suffix.trimmed()+")"); |
258 | verticalGroupBox->setTitle(verticalGroupBox->title() + " ("+suffix.trimmed()+")"); |
||
10229 | subik | 259 | // models display |
260 | horizontalModel->unitChange(docUnitIndex, docUnitDecimals); |
||
261 | verticalModel->unitChange(docUnitIndex, docUnitDecimals); |
||
11836 | subik | 262 | qobject_cast<GuidesDelegate*>(horizontalView->itemDelegateForColumn(0))->setDoc(m_Doc); |
4185 | subik | 263 | } |
2143 | subik | 264 | |
5087 | subik | 265 | void GuideManager::delHorButton_clicked() |
4215 | subik | 266 | { |
10205 | subik | 267 | horizontalModel->removeRows(horizontalView->currentIndex().row(), 1); |
268 | currentPage->guides.clearHorizontals(GuideManagerCore::Standard); |
||
269 | currentPage->guides.addHorizontals(horizontalModel->values(), GuideManagerCore::Standard); |
||
10206 | subik | 270 | drawGuides(); |
4215 | subik | 271 | } |
272 | |||
5087 | subik | 273 | void GuideManager::delVerButton_clicked() |
4185 | subik | 274 | { |
10205 | subik | 275 | verticalModel->removeRows(verticalView->currentIndex().row(), 1); |
276 | currentPage->guides.clearVerticals(GuideManagerCore::Standard); |
||
277 | currentPage->guides.addVerticals(verticalModel->values(), GuideManagerCore::Standard); |
||
10206 | subik | 278 | drawGuides(); |
2143 | subik | 279 | } |
2237 | subik | 280 | |
5087 | subik | 281 | void GuideManager::addHorButton_clicked() |
4198 | subik | 282 | { |
10205 | subik | 283 | horizontalModel->insertRow(); |
4198 | subik | 284 | } |
285 | |||
5087 | subik | 286 | void GuideManager::addVerButton_clicked() |
3 | paul | 287 | { |
10205 | subik | 288 | verticalModel->insertRow(); |
3 | paul | 289 | } |
2143 | subik | 290 | |
5087 | subik | 291 | void GuideManager::lockCheck_stateChanged( int ) |
4215 | subik | 292 | { |
5781 | cbradney | 293 | m_Doc->lockGuides(lockCheck->isChecked()); |
5087 | subik | 294 | } |
295 | |||
296 | void GuideManager::copyGuidesToAllPages(GuideManagerCore::GuideType t) |
||
297 | { |
||
10013 | cbradney | 298 | QListIterator<Page*> it(*m_Doc->Pages); |
5087 | subik | 299 | Page *tmpPage; |
10013 | cbradney | 300 | while (it.hasNext()) |
5087 | subik | 301 | { |
10013 | cbradney | 302 | tmpPage=it.next(); |
5087 | subik | 303 | if (tmpPage->pageNr() == currentPage->pageNr()) |
304 | continue; |
||
305 | tmpPage->guides.clearHorizontals(t); |
||
306 | tmpPage->guides.clearVerticals(t); |
||
307 | currentPage->guides.copy(&tmpPage->guides, t); |
||
5996 | subik | 308 | if (t == GuideManagerCore::Auto) |
309 | storePageValues(tmpPage); |
||
5087 | subik | 310 | } |
311 | drawGuides(); |
||
312 | } |
||
313 | |||
314 | void GuideManager::applyToAllStdButton_clicked() |
||
315 | { |
||
316 | copyGuidesToAllPages(GuideManagerCore::Standard); |
||
317 | } |
||
318 | |||
319 | void GuideManager::applyToAllAutoButton_clicked() |
||
320 | { |
||
321 | copyGuidesToAllPages(GuideManagerCore::Auto); |
||
322 | } |
||
323 | |||
5902 | subik | 324 | void GuideManager::horizontalAutoCountSpin_valueChanged(int val) |
5087 | subik | 325 | { |
5972 | subik | 326 | bool enable = (val == 0) ? false : true; |
5902 | subik | 327 | horizontalAutoGapCheck->setEnabled(enable); |
328 | if (enable && horizontalAutoGapCheck->isChecked()) |
||
329 | horizontalAutoGapSpin->setEnabled(true); |
||
330 | else |
||
331 | horizontalAutoGapSpin->setEnabled(false); |
||
6203 | subik | 332 | currentPage->guides.setHorizontalAutoCount(val); |
333 | drawGuides(); |
||
5087 | subik | 334 | } |
335 | |||
8687 | cbradney | 336 | void GuideManager::horizontalAutoGapSpin_valueChanged(double) |
5087 | subik | 337 | { |
6203 | subik | 338 | currentPage->guides.setHorizontalAutoGap(value2pts(horizontalAutoGapSpin->value(), docUnitIndex)); |
339 | drawGuides(); |
||
5087 | subik | 340 | } |
341 | |||
342 | void GuideManager::horizontalAutoGapCheck_stateChanged( int ) |
||
343 | { |
||
344 | horizontalAutoGapSpin->setEnabled(horizontalAutoGapCheck->isChecked()); |
||
6203 | subik | 345 | if (horizontalAutoGapCheck->isChecked()) |
346 | currentPage->guides.setHorizontalAutoGap(value2pts(horizontalAutoGapSpin->value(), docUnitIndex)); |
||
347 | else |
||
348 | currentPage->guides.setHorizontalAutoGap(value2pts(0.0, docUnitIndex)); |
||
349 | drawGuides(); |
||
5087 | subik | 350 | } |
351 | |||
5902 | subik | 352 | void GuideManager::verticalAutoCountSpin_valueChanged(int val) |
5087 | subik | 353 | { |
5972 | subik | 354 | bool enable = (val == 0) ? false : true; |
5902 | subik | 355 | verticalAutoGapCheck->setEnabled(enable); |
356 | if (enable && verticalAutoGapCheck->isChecked()) |
||
357 | verticalAutoGapSpin->setEnabled(true); |
||
358 | else |
||
359 | verticalAutoGapSpin->setEnabled(false); |
||
6203 | subik | 360 | currentPage->guides.setVerticalAutoCount(val); |
361 | drawGuides(); |
||
5087 | subik | 362 | } |
363 | |||
8687 | cbradney | 364 | void GuideManager::verticalAutoGapSpin_valueChanged(double) |
5087 | subik | 365 | { |
6203 | subik | 366 | currentPage->guides.setVerticalAutoGap(value2pts(verticalAutoGapSpin->value(), docUnitIndex)); |
367 | drawGuides(); |
||
5087 | subik | 368 | } |
369 | |||
370 | void GuideManager::verticalAutoGapCheck_stateChanged( int ) |
||
371 | { |
||
372 | verticalAutoGapSpin->setEnabled(verticalAutoGapCheck->isChecked()); |
||
6203 | subik | 373 | if (verticalAutoGapCheck->isChecked()) |
374 | currentPage->guides.setVerticalAutoGap(value2pts(verticalAutoGapSpin->value(), docUnitIndex)); |
||
5078 | subik | 375 | else |
6203 | subik | 376 | currentPage->guides.setVerticalAutoGap(value2pts(0.0, docUnitIndex)); |
5087 | subik | 377 | drawGuides(); |
2143 | subik | 378 | } |
379 | |||
7715 | subik | 380 | void GuideManager::tabWidget_currentChanged(QWidget *) |
3 | paul | 381 | { |
5087 | subik | 382 | drawGuides(); |
10394 | cbradney | 383 | if (tabWidget->currentIndex() == 1) |
5340 | subik | 384 | { |
385 | horizontalAutoGapSpin->setEnabled(horizontalAutoGapCheck->isChecked()); |
||
386 | verticalAutoGapSpin->setEnabled(verticalAutoGapCheck->isChecked()); |
||
387 | } |
||
3 | paul | 388 | } |
2143 | subik | 389 | |
5087 | subik | 390 | Guides GuideManager::selectedHorizontals() |
2200 | subik | 391 | { |
10206 | subik | 392 | QModelIndex i; |
393 | QModelIndexList selectedIndexes = horizontalView->selectionModel()->selectedIndexes(); |
||
394 | Guides ret; |
||
395 | Guides curr = horizontalModel->values(); |
||
396 | foreach (i , selectedIndexes) |
||
4185 | subik | 397 | { |
10206 | subik | 398 | ret.append(curr.at(i.row())); |
399 | } |
||
400 | return ret; |
||
4185 | subik | 401 | } |
402 | |||
5087 | subik | 403 | Guides GuideManager::selectedVerticals() |
4185 | subik | 404 | { |
10206 | subik | 405 | QModelIndex i; |
406 | QModelIndexList selectedIndexes = verticalView->selectionModel()->selectedIndexes(); |
||
407 | Guides ret; |
||
408 | Guides curr = verticalModel->values(); |
||
409 | foreach (i , selectedIndexes) |
||
410 | { |
||
411 | ret.append(curr.at(i.row())); |
||
412 | } |
||
413 | return ret; |
||
4185 | subik | 414 | } |
415 | |||
5087 | subik | 416 | void GuideManager::drawGuides() |
4215 | subik | 417 | { |
6203 | subik | 418 | if (!m_Doc || !m_drawGuides) |
6000 | subik | 419 | return; |
7713 | subik | 420 | |
421 | currentPage->guides.addHorizontals(getAutoHorizontals(), GuideManagerCore::Auto); |
||
422 | currentPage->guides.addVerticals(getAutoVerticals(), GuideManagerCore::Auto); |
||
5781 | cbradney | 423 | ScCore->primaryMainWindow()->view->DrawNew(); |
4215 | subik | 424 | } |
5339 | subik | 425 | |
426 | void GuideManager::clearRestoreHorizontalList() |
||
427 | { |
||
10205 | subik | 428 | horizontalModel->setValues(currentPage->guides.horizontals(GuideManagerCore::Standard)); |
10206 | subik | 429 | drawGuides(); |
5339 | subik | 430 | } |
431 | |||
432 | void GuideManager::clearRestoreVerticalList() |
||
433 | { |
||
10205 | subik | 434 | verticalModel->setValues(currentPage->guides.verticals(GuideManagerCore::Standard)); |
10206 | subik | 435 | drawGuides(); |
5339 | subik | 436 | } |
6212 | subik | 437 | |
438 | void GuideManager::deletePageButton_clicked() |
||
439 | { |
||
11576 | avox | 440 | UndoTransaction trans(UndoManager::instance()->beginTransaction(currentPage->getUName(), |
441 | currentPage->getUPixmap(), |
||
442 | Um::RemoveAllPageGuides, "", |
||
443 | Um::IGuides)); |
||
6212 | subik | 444 | currentPage->guides.clearHorizontals(GuideManagerCore::Standard); |
445 | currentPage->guides.clearVerticals(GuideManagerCore::Standard); |
||
7713 | subik | 446 | currentPage->guides.clearHorizontals(GuideManagerCore::Auto); |
447 | currentPage->guides.clearVerticals(GuideManagerCore::Auto); |
||
6219 | subik | 448 | clearRestoreHorizontalList(); |
449 | clearRestoreVerticalList(); |
||
450 | |||
6212 | subik | 451 | currentPage->guides.setHorizontalAutoCount(0); |
452 | currentPage->guides.setVerticalAutoCount(0); |
||
453 | currentPage->guides.setHorizontalAutoGap(0.0); |
||
454 | currentPage->guides.setVerticalAutoGap(0.0); |
||
6747 | subik | 455 | currentPage->guides.setHorizontalAutoRefer(0); |
456 | currentPage->guides.setVerticalAutoRefer(0); |
||
6212 | subik | 457 | horizontalAutoCountSpin->setValue(0); |
458 | verticalAutoCountSpin->setValue(0); |
||
11576 | avox | 459 | trans.commit(); |
6219 | subik | 460 | |
6212 | subik | 461 | drawGuides(); |
462 | } |
||
463 | |||
464 | void GuideManager::deleteAllGuides_clicked() |
||
465 | { |
||
11576 | avox | 466 | UndoTransaction trans(UndoManager::instance()->beginTransaction(m_Doc->getUName(), |
467 | m_Doc->getUPixmap(), |
||
468 | Um::RemoveAllGuides, "", |
||
469 | Um::IGuides)); |
||
6212 | subik | 470 | m_drawGuides = false; |
471 | deletePageButton_clicked(); |
||
472 | copyGuidesToAllPages(GuideManagerCore::Standard); |
||
473 | copyGuidesToAllPages(GuideManagerCore::Auto); |
||
474 | m_drawGuides = true; |
||
11576 | avox | 475 | trans.commit(); |
6212 | subik | 476 | drawGuides(); |
477 | } |
||
7710 | subik | 478 | |
479 | void GuideManager::windowActivationChange(bool oldActive) |
||
480 | { |
||
7713 | subik | 481 | if (m_Doc) |
482 | { |
||
483 | bool enable = !m_Doc->m_Selection->isEmpty(); |
||
484 | horizontalSelectionAutoButton->setEnabled(enable); |
||
485 | verticalSelectionAutoButton->setEnabled(enable); |
||
486 | } |
||
7710 | subik | 487 | QDialog::windowActivationChange( oldActive ); |
488 | } |
||
7713 | subik | 489 | |
490 | Guides GuideManager::getAutoVerticals() |
||
491 | { |
||
492 | Guides retval; |
||
493 | double columnSize; |
||
494 | int value = verticalAutoCountSpin->value(); |
||
7715 | subik | 495 | double offset = 0.0; |
496 | double newPageWidth = currentPage->width(); |
||
7713 | subik | 497 | |
498 | if (value == 0) |
||
499 | return retval; |
||
500 | ++value; |
||
501 | |||
10224 | subik | 502 | if (verticalRefer() == 1) |
7713 | subik | 503 | { |
7715 | subik | 504 | newPageWidth = newPageWidth - currentPage->Margins.Left - currentPage->Margins.Right; |
7713 | subik | 505 | offset = currentPage->Margins.Left; |
506 | } |
||
11832 | fschmid | 507 | else if (verticalRefer() == 2) |
7713 | subik | 508 | { |
11832 | fschmid | 509 | if (qRound(currentPage->guides.gx) != 0) |
510 | { |
||
511 | offset = currentPage->guides.gx; |
||
512 | newPageWidth = currentPage->guides.gw; |
||
513 | } |
||
7713 | subik | 514 | } |
515 | |||
10551 | jghali | 516 | if (verticalAutoGapSpin->value() > 0.0 && verticalAutoGapCheck->isChecked()) |
7713 | subik | 517 | columnSize = (newPageWidth - (value - 1) * verticalAutoGapSpin->value()) / value; |
518 | else |
||
519 | columnSize = newPageWidth / value; |
||
520 | |||
521 | for (int i = 1, gapCount = 0; i < value; ++i) |
||
522 | { |
||
10551 | jghali | 523 | if (verticalAutoGapSpin->value() > 0.0 && verticalAutoGapCheck->isChecked()) |
7713 | subik | 524 | { |
525 | retval.append(offset + i * columnSize + gapCount * verticalAutoGapSpin->value()); |
||
526 | ++gapCount; |
||
527 | retval.append(offset + i * columnSize + gapCount * verticalAutoGapSpin->value()); |
||
528 | } |
||
529 | else |
||
530 | retval.append(offset + columnSize * i); |
||
531 | } |
||
532 | return retval; |
||
533 | } |
||
534 | |||
535 | Guides GuideManager::getAutoHorizontals() |
||
536 | { |
||
537 | Guides retval; |
||
538 | double rowSize; |
||
539 | int value = horizontalAutoCountSpin->value(); |
||
7715 | subik | 540 | double offset = 0.0; |
541 | double newPageHeight = currentPage->height(); |
||
7713 | subik | 542 | |
543 | if (value == 0) |
||
544 | return retval; |
||
545 | ++value; |
||
546 | |||
10224 | subik | 547 | if (horizontalRefer() == 1) |
7713 | subik | 548 | { |
7715 | subik | 549 | newPageHeight = newPageHeight - currentPage->Margins.Top - currentPage->Margins.Bottom; |
7713 | subik | 550 | offset = currentPage->Margins.Top; |
551 | } |
||
11832 | fschmid | 552 | else if (horizontalRefer() == 2) |
7713 | subik | 553 | { |
11832 | fschmid | 554 | if (qRound(currentPage->guides.gy) != 0.0) |
555 | { |
||
556 | offset = currentPage->guides.gy; |
||
557 | newPageHeight = currentPage->guides.gh; |
||
558 | } |
||
7713 | subik | 559 | } |
560 | |||
10551 | jghali | 561 | if (horizontalAutoGapSpin->value() > 0.0 && horizontalAutoGapCheck->isChecked()) |
7713 | subik | 562 | rowSize = (newPageHeight - (value - 1) * horizontalAutoGapSpin->value()) / value; |
563 | else |
||
564 | rowSize = newPageHeight / value; |
||
565 | |||
566 | for (int i = 1, gapCount = 0; i < value; ++i) |
||
567 | { |
||
10551 | jghali | 568 | if (horizontalAutoGapSpin->value() > 0.0&& horizontalAutoGapCheck->isChecked()) |
7713 | subik | 569 | { |
570 | retval.append(offset + i * rowSize + gapCount * horizontalAutoGapSpin->value()); |
||
571 | ++gapCount; |
||
572 | retval.append(offset + i * rowSize + gapCount * horizontalAutoGapSpin->value()); |
||
573 | } |
||
574 | else |
||
575 | retval.append(offset + rowSize * i); |
||
576 | } |
||
577 | return retval; |
||
578 | } |
||
579 | |||
7715 | subik | 580 | void GuideManager::resetSelectionForPage() |
7713 | subik | 581 | { |
582 | int docSelectionCount = currentPage->doc()->m_Selection->count(); |
||
583 | |||
7715 | subik | 584 | currentPage->guides.gx = currentPage->guides.gy = currentPage->guides.gw = currentPage->guides.gh = 0.0; |
7713 | subik | 585 | |
586 | // multiselection |
||
587 | if (docSelectionCount > 1) |
||
588 | { |
||
589 | double x, y; |
||
7715 | subik | 590 | m_Doc->m_Selection->getGroupRect(&x, &y, ¤tPage->guides.gw, ¤tPage->guides.gh); |
591 | currentPage->guides.gx = x - currentPage->xOffset(); |
||
592 | currentPage->guides.gy = y - currentPage->yOffset(); |
||
7713 | subik | 593 | } |
594 | // only one item selected |
||
595 | else if (docSelectionCount == 1) |
||
596 | { |
||
597 | PageItem *currItem = m_Doc->m_Selection->itemAt(0); |
||
7715 | subik | 598 | currentPage->guides.gx = currItem->xPos() - currentPage->xOffset(); |
599 | currentPage->guides.gy = currItem->yPos() - currentPage->yOffset(); |
||
600 | currentPage->guides.gw = currItem->width(); |
||
601 | currentPage->guides.gh = currItem->height(); |
||
7713 | subik | 602 | } |
603 | } |
||
10206 | subik | 604 | |
605 | void GuideManager::verticalModel_valueChanged() |
||
606 | { |
||
607 | currentPage->guides.clearVerticals(GuideManagerCore::Standard); |
||
608 | currentPage->guides.addVerticals(verticalModel->values(), GuideManagerCore::Standard); |
||
609 | drawGuides(); |
||
610 | } |
||
611 | |||
612 | void GuideManager::horizontalModel_valueChanged() |
||
613 | { |
||
614 | currentPage->guides.clearHorizontals(GuideManagerCore::Standard); |
||
615 | currentPage->guides.addHorizontals(horizontalModel->values(), GuideManagerCore::Standard); |
||
616 | drawGuides(); |
||
617 | } |
||
10224 | subik | 618 | |
619 | void GuideManager::setHorizontalRefer(int button) |
||
620 | { |
||
621 | switch (button) |
||
622 | { |
||
623 | case 0 : |
||
624 | horizontalPageAutoButton->setChecked(true); |
||
625 | break; |
||
626 | case 1 : |
||
627 | horizontalMarginsAutoButton->setChecked(true); |
||
628 | break; |
||
629 | case 2 : |
||
630 | horizontalSelectionAutoButton->setChecked(true); |
||
631 | } |
||
632 | } |
||
633 | |||
634 | int GuideManager::horizontalRefer() |
||
635 | { |
||
636 | if (horizontalPageAutoButton->isChecked()) |
||
637 | return 0; |
||
638 | if (horizontalMarginsAutoButton->isChecked()) |
||
639 | return 1; |
||
640 | if (horizontalSelectionAutoButton->isChecked()) |
||
641 | return 2; |
||
642 | return 0; |
||
643 | } |
||
644 | |||
645 | void GuideManager::setVerticalRefer(int button) |
||
646 | { |
||
647 | switch (button) |
||
648 | { |
||
649 | case 0 : |
||
650 | verticalPageAutoButton->setChecked(true); |
||
651 | break; |
||
652 | case 1 : |
||
653 | verticalMarginsAutoButton->setChecked(true); |
||
654 | break; |
||
655 | case 2 : |
||
656 | verticalSelectionAutoButton->setChecked(true); |
||
657 | } |
||
658 | } |
||
659 | |||
660 | int GuideManager::verticalRefer() |
||
661 | { |
||
662 | if (verticalPageAutoButton->isChecked()) |
||
663 | return 0; |
||
664 | if (verticalMarginsAutoButton->isChecked()) |
||
665 | return 1; |
||
666 | if (verticalSelectionAutoButton->isChecked()) |
||
667 | return 2; |
||
668 | return 0; |
||
669 | } |
||
670 | |||
671 | void GuideManager::horizontalPageAutoButton_toggled(bool state) |
||
672 | { |
||
673 | if (!state) |
||
674 | return; |
||
675 | currentPage->guides.setHorizontalAutoRefer(0); |
||
676 | drawGuides(); |
||
677 | } |
||
678 | |||
679 | void GuideManager::horizontalMarginsAutoButton_toggled(bool state) |
||
680 | { |
||
681 | if (!state) |
||
682 | return; |
||
683 | currentPage->guides.setHorizontalAutoRefer(1); |
||
684 | drawGuides(); |
||
685 | } |
||
686 | |||
687 | void GuideManager::horizontalSelectionAutoButton_toggled(bool state) |
||
688 | { |
||
689 | if (!state) |
||
690 | return; |
||
691 | currentPage->guides.setHorizontalAutoRefer(2); |
||
692 | if (horizontalSelectionAutoButton->isEnabled()) |
||
693 | resetSelectionForPage(); |
||
694 | drawGuides(); |
||
695 | } |
||
696 | |||
697 | void GuideManager::verticalPageAutoButton_toggled(bool state) |
||
698 | { |
||
699 | if (!state) |
||
700 | return; |
||
701 | currentPage->guides.setVerticalAutoRefer(0); |
||
702 | drawGuides(); |
||
703 | } |
||
704 | |||
705 | void GuideManager::verticalMarginsAutoButton_toggled(bool state) |
||
706 | { |
||
707 | if (!state) |
||
708 | return; |
||
709 | currentPage->guides.setVerticalAutoRefer(1); |
||
710 | drawGuides(); |
||
711 | } |
||
712 | |||
713 | void GuideManager::verticalSelectionAutoButton_toggled(bool state) |
||
714 | { |
||
715 | if (!state) |
||
716 | return; |
||
717 | currentPage->guides.setVerticalAutoRefer(2); |
||
718 | if (verticalSelectionAutoButton->isEnabled()) |
||
719 | resetSelectionForPage(); |
||
720 | drawGuides(); |
||
721 | } |