Rev 4198 | Rev 4284 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
181 | Franz | 1 | /*************************************************************************** |
2 | guidemanager.cpp |
||
3 | ------------------- |
||
4 | begin : Fri Jan 30 2004 |
||
5 | copyright : (C) 2004 by Alessandro Rimoldi |
||
6 | copyright : (C) by Franz Schmid |
||
7 | e-mail : http://www.ideale.ch/contact |
||
8 | ***************************************************************************/ |
||
9 | |||
10 | /*************************************************************************** |
||
11 | * * |
||
12 | * This program is free software; you can redistribute it and/or modify * |
||
13 | * it under the terms of the GNU General Public License as published by * |
||
14 | * the Free Software Foundation; either version 2 of the License, or * |
||
15 | * (at your option) any later version. * |
||
16 | * * |
||
17 | ***************************************************************************/ |
||
18 | |||
2164 | subik | 19 | #include "scribus.h" |
3934 | cbradney | 20 | #include "selection.h" |
3 | paul | 21 | #include "guidemanager.h" |
22 | #include "guidemanager.moc" |
||
3670 | cbradney | 23 | #include "page.h" |
1843 | cbradney | 24 | #include "units.h" |
4185 | subik | 25 | #include "commonstrings.h" |
26 | #include "pagestructs.h" |
||
27 | |||
2200 | subik | 28 | #include <qradiobutton.h> |
2215 | subik | 29 | #include <qlayout.h> |
2237 | subik | 30 | #include <qcursor.h> |
4185 | subik | 31 | #include <qlistview.h> |
32 | #include <qdialog.h> |
||
33 | #include <qvaluelist.h> |
||
34 | #include <qgroupbox.h> |
||
35 | #include <qlabel.h> |
||
36 | #include <qlistview.h> |
||
37 | #include <qpushbutton.h> |
||
38 | #include <qcheckbox.h> |
||
39 | #include <qtooltip.h> |
||
40 | #include <qhbuttongroup.h> |
||
1843 | cbradney | 41 | |
2164 | subik | 42 | |
3 | paul | 43 | extern QPixmap loadIcon(QString nam); |
181 | Franz | 44 | |
4185 | subik | 45 | |
4215 | subik | 46 | int GuideListItem::compare(QListViewItem *i, int col, bool asc) const |
47 | { |
||
48 | if (col == 0) |
||
49 | { |
||
50 | double d; |
||
51 | d = text(col).toDouble() - i->text(col).toDouble(); |
||
52 | if (d > 0.0) |
||
53 | return 1; |
||
54 | return -1; |
||
55 | } |
||
56 | else |
||
57 | return QListViewItem::compare(i, col, asc); |
||
58 | } |
||
59 | |||
60 | |||
2164 | subik | 61 | GuideManager::GuideManager(QWidget* parent) : QDialog(parent, "GuideManager", true, 0) |
3 | paul | 62 | { |
2397 | cbradney | 63 | setCaption( tr("Manage Guides")); |
240 | Franz | 64 | setIcon(loadIcon("AppIcon.png")); |
2143 | subik | 65 | |
240 | Franz | 66 | /* Initialise the global variables */ |
4185 | subik | 67 | resetMarginsForPage(); |
4026 | craig | 68 | docUnitIndex = ScMW->doc->unitIndex(); |
4185 | subik | 69 | docUnitPrecision = unitGetPrecisionFromIndex(docUnitIndex); |
1917 | cbradney | 70 | docUnitRatio = unitGetRatioFromIndex(docUnitIndex); |
4185 | subik | 71 | docUnitDecimals = unitGetDecimalsFromIndex(docUnitIndex); |
72 | suffix = unitGetSuffixFromIndex(docUnitIndex); |
||
2143 | subik | 73 | |
240 | Franz | 74 | /* Create the dialog elements */ |
4215 | subik | 75 | QHBoxLayout *guideManagerLayout = new QHBoxLayout(this, 11, 6, "guideManagerLayout"); |
76 | QVBoxLayout *mainWidgetsLayout = new QVBoxLayout(0, 11, 6, "mainWidgetsLayout"); |
||
2143 | subik | 77 | |
2215 | subik | 78 | QHBoxLayout *Layout6 = new QHBoxLayout(0, 0, 6, "Layout6"); |
2143 | subik | 79 | |
4185 | subik | 80 | QGroupBox *horGroup = new QGroupBox(this, "horGroup"); |
81 | horGroup->setTitle( tr("Horizontal Guides")); |
||
82 | horGroup->setColumnLayout(0, Qt::Vertical); |
||
83 | horGroup->layout()->setSpacing(6); |
||
84 | horGroup->layout()->setMargin(11); |
||
85 | QVBoxLayout *horGroupLayout = new QVBoxLayout(horGroup->layout()); |
||
86 | horGroupLayout->setAlignment(Qt::AlignTop); |
||
2143 | subik | 87 | |
4185 | subik | 88 | horList = new QListView(horGroup, "horList"); |
89 | horList->addColumn(tr("Guide")); |
||
90 | horList->addColumn(tr("Unit")); |
||
91 | horList->setMinimumSize(QSize(0, 150)); |
||
92 | horList->setSelectionMode(QListView::Extended); |
||
93 | horList->setAllColumnsShowFocus(true); |
||
94 | horList->setSorting(0); |
||
95 | horGroupLayout->addWidget(horList); |
||
2143 | subik | 96 | |
2215 | subik | 97 | QHBoxLayout *Layout4 = new QHBoxLayout(0, 0, 6, "Layout4"); |
2143 | subik | 98 | |
4185 | subik | 99 | TextLabel2 = new QLabel( tr("&Y-Pos:"), horGroup, "TextLabel2"); |
240 | Franz | 100 | Layout4->addWidget(TextLabel2); |
2143 | subik | 101 | |
4185 | subik | 102 | horSpin = new MSpinBox(0, locPageHeight, horGroup, 4); |
103 | TextLabel2->setBuddy(horSpin); |
||
104 | Layout4->addWidget(horSpin); |
||
2143 | subik | 105 | |
4185 | subik | 106 | horGroupLayout->addLayout(Layout4); |
2143 | subik | 107 | |
2215 | subik | 108 | QHBoxLayout *Layout3 = new QHBoxLayout(0, 0, 6, "Layout3"); |
2143 | subik | 109 | |
4185 | subik | 110 | horSet = new QPushButton( tr( "&Add" ), horGroup, "horSet"); |
111 | horSet->setAutoDefault(false); |
||
112 | Layout3->addWidget(horSet); |
||
2143 | subik | 113 | |
4185 | subik | 114 | horDel = new QPushButton( tr( "D&elete" ), horGroup, "horDel"); |
115 | horDel->setAutoDefault(false); |
||
116 | Layout3->addWidget(horDel); |
||
2143 | subik | 117 | |
4185 | subik | 118 | horGroupLayout->addLayout(Layout3); |
2143 | subik | 119 | |
4185 | subik | 120 | Layout6->addWidget(horGroup); |
2143 | subik | 121 | |
4185 | subik | 122 | verGroup = new QGroupBox(this, "verGroup"); |
123 | verGroup->setTitle( tr("Vertical Guides")); |
||
124 | verGroup->setColumnLayout(0, Qt::Vertical); |
||
125 | verGroup->layout()->setSpacing(6); |
||
126 | verGroup->layout()->setMargin(11); |
||
127 | QVBoxLayout *verGroupLayout = new QVBoxLayout(verGroup->layout()); |
||
128 | verGroupLayout->setAlignment(Qt::AlignTop); |
||
2143 | subik | 129 | |
4185 | subik | 130 | verList = new QListView(verGroup, "verList"); |
131 | verList->addColumn(tr("Guide")); |
||
132 | verList->addColumn(tr("Unit")); |
||
133 | verList->setMinimumSize(QSize(0, 150)); |
||
134 | verList->setSorting(0); |
||
135 | verList->setSelectionMode(QListView::Extended); |
||
136 | verList->setAllColumnsShowFocus(true); |
||
137 | verGroupLayout->addWidget(verList); |
||
2143 | subik | 138 | |
2215 | subik | 139 | QHBoxLayout *Layout2 = new QHBoxLayout(0, 0, 6, "Layout2"); |
2143 | subik | 140 | |
4185 | subik | 141 | TextLabel1 = new QLabel( tr("&X-Pos:"), verGroup, "TextLabel1"); |
240 | Franz | 142 | Layout2->addWidget(TextLabel1); |
2143 | subik | 143 | |
4185 | subik | 144 | verSpin = new MSpinBox(0, locPageWidth, verGroup, 4); |
145 | TextLabel1->setBuddy(verSpin); |
||
146 | Layout2->addWidget(verSpin); |
||
2143 | subik | 147 | |
4185 | subik | 148 | verGroupLayout->addLayout(Layout2); |
2143 | subik | 149 | |
2215 | subik | 150 | QHBoxLayout *Layout1 = new QHBoxLayout(0, 0, 6, "Layout1"); |
2143 | subik | 151 | |
4185 | subik | 152 | verSet = new QPushButton( tr( "A&dd" ), verGroup, "verSet"); |
153 | verSet->setAutoDefault(false); |
||
154 | Layout1->addWidget(verSet); |
||
2143 | subik | 155 | |
4185 | subik | 156 | verDel = new QPushButton( tr( "De&lete" ), verGroup, "verDel"); |
157 | verDel->setAutoDefault(false); |
||
158 | Layout1->addWidget(verDel); |
||
2143 | subik | 159 | |
4185 | subik | 160 | verGroupLayout->addLayout(Layout1); |
2143 | subik | 161 | |
4185 | subik | 162 | Layout6->addWidget(verGroup); |
2143 | subik | 163 | |
4215 | subik | 164 | mainWidgetsLayout->addLayout(Layout6); |
2143 | subik | 165 | |
2215 | subik | 166 | QHBoxLayout *Layout7 = new QHBoxLayout(0, 0, 6, "Layout7"); |
2143 | subik | 167 | |
2200 | subik | 168 | // auto guides |
4185 | subik | 169 | QGroupBox *horGroup2 = new QGroupBox(this, "horGroup"); |
170 | horGroup2->setTitle( tr("Rows and Columns - Automatic Guides")); |
||
171 | horGroup2->setColumnLayout(0, Qt::Vertical); |
||
172 | horGroup2->layout()->setSpacing(6); |
||
173 | horGroup2->layout()->setMargin(11); |
||
174 | QVBoxLayout *horGroupLayout2 = new QVBoxLayout(horGroup2->layout()); |
||
175 | horGroupLayout2->setAlignment(Qt::AlignTop); |
||
2143 | subik | 176 | |
2215 | subik | 177 | // auto guides basic |
4185 | subik | 178 | QLabel *TextLabel8 = new QLabel( tr("&Rows:"), horGroup2, "TextLabel8"); |
179 | rowSpin = new QSpinBox(1, 100, 1, horGroup2, "rowSpin"); |
||
180 | TextLabel8->setBuddy(rowSpin); |
||
2143 | subik | 181 | |
4185 | subik | 182 | QLabel *TextLabel9 = new QLabel( tr("C&olumns:"), horGroup2, "TextLabel9"); |
183 | colSpin = new QSpinBox(1, 100, 1, horGroup2, "colSpin"); |
||
184 | TextLabel9->setBuddy(colSpin); |
||
2143 | subik | 185 | |
2215 | subik | 186 | QVBoxLayout *rcLayout = new QVBoxLayout(0, 0, 6, "rcLayout"); |
187 | rcLayout->addWidget(TextLabel8); |
||
4185 | subik | 188 | rcLayout->addWidget(rowSpin); |
2215 | subik | 189 | rcLayout->addWidget(TextLabel9); |
4185 | subik | 190 | rcLayout->addWidget(colSpin); |
2215 | subik | 191 | |
192 | // auto guides gaps |
||
4185 | subik | 193 | useRowGap = new QCheckBox( tr("Row &Gap"), horGroup2, "useRowGap"); |
2215 | subik | 194 | useRowGap->setChecked(false); |
4185 | subik | 195 | rowGap = new MSpinBox(0, 100, horGroup2, 4); |
2215 | subik | 196 | rowGap->setValue(0); |
197 | rowGap->setEnabled(false); |
||
198 | |||
4185 | subik | 199 | useColGap = new QCheckBox( tr("Colum&n Gap"), horGroup2, "useColGap"); |
2200 | subik | 200 | useColGap->setChecked(false); |
4185 | subik | 201 | colGap = new MSpinBox(0, 100, horGroup2, 4); |
2215 | subik | 202 | colGap->setValue(0); |
2200 | subik | 203 | colGap->setEnabled(false); |
204 | |||
2215 | subik | 205 | QVBoxLayout *rcGapLayout = new QVBoxLayout(0, 0, 6, "rcGapLayout"); |
206 | rcGapLayout->addWidget(useRowGap); |
||
207 | rcGapLayout->addWidget(rowGap); |
||
208 | rcGapLayout->addWidget(useColGap); |
||
209 | rcGapLayout->addWidget(colGap); |
||
2143 | subik | 210 | |
2215 | subik | 211 | // auto guides formating |
212 | QHBoxLayout *autoGuidesLayout = new QHBoxLayout(0, 0, 6, "autoGuidesLayout"); |
||
213 | autoGuidesLayout->addLayout(rcLayout); |
||
214 | autoGuidesLayout->addLayout(rcGapLayout); |
||
215 | |||
216 | QHBoxLayout *Layout10 = new QHBoxLayout(0, 0, 6, "Layout10"); |
||
4185 | subik | 217 | bGroup = new QHButtonGroup(horGroup2, "bGroup"); |
218 | bGroup->setFrameStyle(QFrame::NoFrame); |
||
219 | QLabel *TextLabel10 = new QLabel( tr("Refer to:"), horGroup2, "TextLabel10"); |
||
2164 | subik | 220 | Layout10->addWidget(TextLabel10); |
4185 | subik | 221 | QRadioButton *fPage = new QRadioButton( tr( "&Page" ), bGroup, "fpage"); |
2164 | subik | 222 | fPage->setChecked(true); |
4185 | subik | 223 | (void) new QRadioButton( tr( "&Margins" ), bGroup, "fmargin"); |
224 | QRadioButton *fSelect = new QRadioButton( tr( "&Selection" ), bGroup, "fselect"); |
||
2164 | subik | 225 | fSelect->setEnabled(selected); |
4185 | subik | 226 | Layout10->addWidget(bGroup); |
2143 | subik | 227 | |
228 | QSpacerItem* spacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); |
||
229 | Layout10->addItem(spacer2); |
||
230 | |||
4185 | subik | 231 | Layout7->addWidget(horGroup2); |
232 | horGroupLayout2->addLayout(autoGuidesLayout); |
||
233 | horGroupLayout2->addLayout(Layout10); |
||
2143 | subik | 234 | |
4215 | subik | 235 | mainWidgetsLayout->addLayout(Layout7); |
2143 | subik | 236 | |
2215 | subik | 237 | QHBoxLayout *Layout5 = new QHBoxLayout(0, 0, 6, "Layout5"); |
4185 | subik | 238 | lockedCheckBox = new QCheckBox( tr( "&Lock Guides" ), this, "lockedCheckBox"); |
239 | lockedCheckBox->setChecked(ScMW->doc->GuideLock); |
||
240 | Layout5->addWidget(lockedCheckBox); |
||
2143 | subik | 241 | |
3816 | subik | 242 | allPages = new QCheckBox(tr("&Apply to All Pages"), this, "allPages"); |
243 | allPages->setChecked(false); |
||
244 | Layout5->addWidget(allPages); |
||
245 | |||
246 | QHBoxLayout *buttonLayout = new QHBoxLayout(0, 0, 6, "buttonLayout"); |
||
2215 | subik | 247 | QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); |
3816 | subik | 248 | buttonLayout->addItem(spacer); |
2143 | subik | 249 | |
2952 | cbradney | 250 | okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton"); |
2215 | subik | 251 | okButton->setAutoDefault(false); |
2237 | subik | 252 | cancelButton = new QPushButton( tr( "&Close" ), this, "cancelButton"); |
253 | cancelButton->setAutoDefault(false); |
||
254 | cancelButton->setAccel(QKeySequence("Esc")); |
||
2397 | cbradney | 255 | setButton = new QPushButton( tr("&Update"), this, "setButton"); |
2237 | subik | 256 | setButton->setAutoDefault(false); |
3816 | subik | 257 | buttonLayout->addWidget(setButton); |
258 | buttonLayout->addWidget(okButton); |
||
259 | buttonLayout->addWidget(cancelButton); |
||
2143 | subik | 260 | |
4215 | subik | 261 | mainWidgetsLayout->addLayout(Layout5); |
262 | mainWidgetsLayout->addLayout(buttonLayout); |
||
263 | |||
264 | // preview pixmap |
||
265 | // prevMainLayout is here due the aligning with the others widgets |
||
266 | QHBoxLayout *prevMainLayout = new QHBoxLayout(0, 11, 6, "prevMainLayout"); |
||
267 | QGroupBox *previewGBox = new QGroupBox(this, "previewGBox"); |
||
268 | previewGBox->setTitle(tr("Preview")); |
||
269 | previewGBox->setColumnLayout(0, Qt::Vertical); |
||
270 | previewGBox->layout()->setSpacing(6); |
||
271 | previewGBox->layout()->setMargin(11); |
||
272 | QVBoxLayout *previewGBoxLayout = new QVBoxLayout(previewGBox->layout()); |
||
273 | previewGBoxLayout->setAlignment(Qt::AlignTop); |
||
274 | previewLabel = new QLabel(previewGBox, "previewLabel"); |
||
275 | previewGBoxLayout->addWidget(previewLabel); |
||
276 | prevMainLayout->addWidget(previewGBox); |
||
277 | |||
278 | guideManagerLayout->addLayout(mainWidgetsLayout); |
||
279 | guideManagerLayout->addLayout(prevMainLayout); |
||
2143 | subik | 280 | |
4185 | subik | 281 | // set current guides |
282 | setGuidesFromList(horList, ScMW->doc->currentPage->YGuides); |
||
283 | setGuidesFromList(verList, ScMW->doc->currentPage->XGuides); |
||
2215 | subik | 284 | unitChange(); |
4215 | subik | 285 | slotDrawPreview(); |
2143 | subik | 286 | |
2237 | subik | 287 | //tooltips |
288 | QToolTip::add( setButton, "<qt>" + tr("Set the guides in document. Guide manager is still opened but the changes are persistant", "guide manager") + "</qt>"); |
||
289 | |||
240 | Franz | 290 | // Create signals and slots connections |
2237 | subik | 291 | connect(okButton, SIGNAL(clicked()), this, SLOT(commitChanges())); |
292 | connect(setButton, SIGNAL(clicked()), this, SLOT(commitEditChanges())); |
||
293 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
||
4185 | subik | 294 | connect(horSet, SIGNAL(clicked()), this, SLOT(AddHorVal())); |
295 | connect(horDel, SIGNAL(clicked()), this, SLOT(DelHorVal())); |
||
296 | connect(horSpin, SIGNAL(valueChanged(int)), this, SLOT(ChangeHorVal())); |
||
297 | connect(horList, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(horList_currentChanged(QListViewItem*))); |
||
298 | connect(verSet, SIGNAL(clicked()), this, SLOT(AddVerVal())); |
||
299 | connect(verDel, SIGNAL(clicked()), this, SLOT(DelVerVal())); |
||
300 | connect(verSpin, SIGNAL(valueChanged(int)), this, SLOT(ChangeVerVal())); |
||
301 | connect(verList, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(verList_currentChanged(QListViewItem*))); |
||
2200 | subik | 302 | connect(useRowGap, SIGNAL(toggled(bool)), this, SLOT(useRowGap_clicked(bool))); |
303 | connect(useColGap, SIGNAL(toggled(bool)), this, SLOT(useColGap_clicked(bool))); |
||
4215 | subik | 304 | connect(this, SIGNAL(guidesChanged()), this, SLOT(slotDrawPreview())); |
305 | connect(rowSpin, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview())); |
||
306 | connect(colSpin, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview())); |
||
307 | connect(rowGap, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview())); |
||
308 | connect(colGap, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview())); |
||
309 | connect(bGroup, SIGNAL(clicked(int)), this, SLOT(slotDrawPreview())); |
||
4185 | subik | 310 | } |
2143 | subik | 311 | |
4198 | subik | 312 | GuideManager::~GuideManager() |
313 | { |
||
314 | ScMW->mainWindowStatusLabel->setText(QString::null); |
||
315 | } |
||
316 | |||
4215 | subik | 317 | bool GuideManager::deleteValueFormList(QListView *list) |
4185 | subik | 318 | { |
319 | /* previous item pointer to ensure that ++it |
||
320 | runs before item goes deleted */ |
||
321 | QListViewItem *itemToDelete; |
||
4215 | subik | 322 | QListViewItemIterator it(list, QListViewItemIterator::Selected); |
4185 | subik | 323 | while (it.current()) |
264 | Franz | 324 | { |
4185 | subik | 325 | itemToDelete = it.current(); |
326 | ++it; |
||
327 | if (itemToDelete) |
||
328 | { |
||
4215 | subik | 329 | list->takeItem(itemToDelete); |
4185 | subik | 330 | delete itemToDelete; |
331 | } |
||
264 | Franz | 332 | } |
4215 | subik | 333 | emit guidesChanged(); |
334 | return true; |
||
4185 | subik | 335 | } |
336 | |||
4215 | subik | 337 | void GuideManager::DelHorVal() |
338 | { |
||
339 | deleteValueFormList(horList); |
||
340 | } |
||
341 | |||
4185 | subik | 342 | void GuideManager::DelVerVal() |
343 | { |
||
4215 | subik | 344 | deleteValueFormList(verList); |
2143 | subik | 345 | } |
2237 | subik | 346 | |
4198 | subik | 347 | bool GuideManager::addValueToList(QListView *list, MSpinBox *spin) |
3 | paul | 348 | { |
4185 | subik | 349 | QString tmp; |
350 | tmp = tmp.setNum(0.0, 'f', docUnitPrecision); |
||
4198 | subik | 351 | // no duplications |
352 | if (list->findItem(tmp, 0) != 0) |
||
353 | { |
||
354 | ScMW->mainWindowStatusLabel->setText(tr("There is empty (0.0) guide already")); |
||
355 | return false; |
||
356 | } |
||
4215 | subik | 357 | QListViewItem *item = new GuideListItem(list, tmp, suffix); |
4198 | subik | 358 | list->insertItem(item); |
359 | list->setCurrentItem(item); |
||
360 | list->clearSelection(); |
||
361 | list->setSelected(item, true); |
||
362 | spin->setFocus(); |
||
363 | spin->selectAll(); |
||
4215 | subik | 364 | emit guidesChanged(); |
4198 | subik | 365 | return true; |
3 | paul | 366 | } |
2143 | subik | 367 | |
4198 | subik | 368 | void GuideManager::AddHorVal() |
369 | { |
||
370 | addValueToList(horList, horSpin); |
||
4215 | subik | 371 | |
4198 | subik | 372 | } |
373 | |||
4185 | subik | 374 | void GuideManager::AddVerVal() |
3 | paul | 375 | { |
4198 | subik | 376 | addValueToList(verList, verSpin); |
3 | paul | 377 | } |
2143 | subik | 378 | |
4185 | subik | 379 | void GuideManager::resetMarginsForPage() |
3 | paul | 380 | { |
4185 | subik | 381 | locPageWidth = ScMW->doc->currentPage->width(); |
382 | locPageHeight = ScMW->doc->currentPage->height(); |
||
383 | // whatif selection settings |
||
384 | FPoint selectionTopLeft = FPoint(0, 0); |
||
385 | FPoint selectionBottomRight = FPoint(0, 0); |
||
2143 | subik | 386 | |
4185 | subik | 387 | int docSelectionCount = ScMW->doc->selection->count(); |
388 | // multiselection |
||
389 | if (docSelectionCount > 1) |
||
390 | { |
||
391 | selectionTopLeft.setXY(ScMW->view->GroupX - ScMW->doc->currentPage->xOffset(), |
||
392 | ScMW->view->GroupY - ScMW->doc->currentPage->yOffset()); |
||
393 | selectionBottomRight.setXY(ScMW->view->GroupW, |
||
394 | ScMW->view->GroupH); |
||
395 | } |
||
396 | // only one item selected |
||
397 | else if (docSelectionCount == 1) |
||
398 | { |
||
399 | PageItem *currItem = ScMW->doc->selection->itemAt(0); |
||
400 | selectionTopLeft.setXY(currItem->xPos() - ScMW->doc->currentPage->xOffset(), |
||
401 | currItem->yPos() - ScMW->doc->currentPage->yOffset()); |
||
402 | selectionBottomRight.setXY(currItem->width(), currItem->height()); |
||
403 | } |
||
2143 | subik | 404 | |
4185 | subik | 405 | selected = true; |
406 | if (selectionBottomRight != FPoint(0, 0)) |
||
407 | { |
||
408 | gy = selectionTopLeft.y(); |
||
409 | gx = selectionTopLeft.x(); |
||
410 | gw = selectionBottomRight.x(); |
||
411 | gh = selectionBottomRight.y(); |
||
412 | } |
||
413 | else selected = false; |
||
414 | |||
415 | locTop = ScMW->doc->pageMargins.Top; |
||
416 | locBottom = ScMW->doc->pageMargins.Bottom; |
||
417 | |||
418 | PageLocation pageLocation = ScMW->doc->locationOfPage(ScMW->doc->currentPageNumber()); |
||
419 | switch (pageLocation) |
||
420 | { |
||
421 | case MiddlePage : |
||
422 | locLeft = ScMW->doc->pageMargins.Left; |
||
423 | locRight = ScMW->doc->pageMargins.Left; |
||
424 | break; |
||
425 | case LeftPage: |
||
426 | locLeft = ScMW->doc->pageMargins.Right; |
||
427 | locRight = ScMW->doc->pageMargins.Left; |
||
428 | break; |
||
429 | case RightPage: |
||
430 | locRight = ScMW->doc->pageMargins.Right; |
||
431 | locLeft = ScMW->doc->pageMargins.Left; |
||
432 | break; |
||
433 | default: |
||
434 | locRight = 0; |
||
435 | locLeft = 0; |
||
436 | } |
||
3 | paul | 437 | } |
2143 | subik | 438 | |
4185 | subik | 439 | void GuideManager::addRows() |
2200 | subik | 440 | { |
4215 | subik | 441 | if (allPages->isChecked() && rowSpin->value() > 0) |
442 | horList->clear(); |
||
443 | setGuidesFromList(horList, getAutoRows()); |
||
444 | } |
||
445 | |||
446 | QValueList<double> GuideManager::getAutoRows() |
||
447 | { |
||
4185 | subik | 448 | resetMarginsForPage(); |
449 | int n = QString(rowSpin->text()).toInt(); |
||
2143 | subik | 450 | double offset = 0; |
3620 | subik | 451 | double newPageHeight = locPageHeight; |
2143 | subik | 452 | |
4185 | subik | 453 | if (bGroup->selectedId() == 1) |
2143 | subik | 454 | { |
3620 | subik | 455 | newPageHeight = locPageHeight - locTop - locBottom; |
456 | offset = locTop; |
||
2143 | subik | 457 | } |
4185 | subik | 458 | else if (bGroup->selectedId() == 2) |
2164 | subik | 459 | { |
2200 | subik | 460 | offset = gy; |
3620 | subik | 461 | newPageHeight = gh; |
2164 | subik | 462 | } |
2143 | subik | 463 | |
3620 | subik | 464 | double spacing = newPageHeight / n; |
2215 | subik | 465 | QValueList<double> values; |
2200 | subik | 466 | for (int i = 1; i < n; ++i) |
2143 | subik | 467 | { |
2200 | subik | 468 | if (useRowGap->isChecked()) |
2143 | subik | 469 | { |
4026 | craig | 470 | double gapValue = value2pts(rowGap->value(), ScMW->doc->unitIndex()); |
3943 | subik | 471 | values.append(offset + (spacing * i) + (gapValue / 2.0)); |
472 | values.append(offset + (spacing * i) - (gapValue / 2.0)); |
||
2143 | subik | 473 | } |
474 | else |
||
3620 | subik | 475 | values.append(offset + (spacing * i)); |
2143 | subik | 476 | } |
4215 | subik | 477 | return values; |
2143 | subik | 478 | } |
479 | |||
4185 | subik | 480 | void GuideManager::addCols() |
2200 | subik | 481 | { |
4215 | subik | 482 | if (allPages->isChecked() && colSpin->value() > 0) |
483 | verList->clear(); |
||
484 | setGuidesFromList(verList, getAutoCols()); |
||
485 | } |
||
486 | |||
487 | QValueList<double> GuideManager::getAutoCols() |
||
488 | { |
||
4185 | subik | 489 | resetMarginsForPage(); |
490 | int n = QString(colSpin->text()).toInt(); |
||
2143 | subik | 491 | double offset = 0; |
3620 | subik | 492 | double newPageWidth = locPageWidth; |
2143 | subik | 493 | |
4185 | subik | 494 | if (bGroup->selectedId() == 1) |
2143 | subik | 495 | { |
3620 | subik | 496 | newPageWidth = locPageWidth - locLeft - locRight; |
497 | offset = locLeft; |
||
2143 | subik | 498 | } |
4185 | subik | 499 | else if (bGroup->selectedId() == 2) |
2164 | subik | 500 | { |
501 | offset = gx; |
||
3620 | subik | 502 | newPageWidth = gw; |
2164 | subik | 503 | } |
2143 | subik | 504 | |
3620 | subik | 505 | double spacing = newPageWidth / n; |
2215 | subik | 506 | QValueList<double> values; |
2200 | subik | 507 | for (int i = 1; i < n; ++i) |
2143 | subik | 508 | { |
2200 | subik | 509 | if (useColGap->isChecked()) |
2143 | subik | 510 | { |
4026 | craig | 511 | double gapValue = value2pts(colGap->value(), ScMW->doc->unitIndex()); |
3943 | subik | 512 | values.append(offset + spacing * i + (gapValue / 2.0)); |
513 | values.append(offset + spacing * i - (gapValue / 2.0)); |
||
2143 | subik | 514 | } |
515 | else |
||
2215 | subik | 516 | values.append(offset + spacing * i); |
2143 | subik | 517 | } |
4215 | subik | 518 | return values; |
2215 | subik | 519 | } |
520 | |||
181 | Franz | 521 | void GuideManager::ChangeHorVal() |
3 | paul | 522 | { |
4185 | subik | 523 | QListViewItem *item = horList->currentItem(); |
524 | if (item == 0) |
||
525 | return; |
||
526 | QString tmp; |
||
527 | tmp = tmp.setNum(horSpin->value(), 'f', docUnitPrecision); |
||
528 | item->setText(0, tmp); |
||
4215 | subik | 529 | emit guidesChanged(); |
3 | paul | 530 | } |
2143 | subik | 531 | |
181 | Franz | 532 | void GuideManager::ChangeVerVal() |
3 | paul | 533 | { |
4185 | subik | 534 | QListViewItem *item = verList->currentItem(); |
535 | if (item == 0) |
||
536 | return; |
||
537 | QString tmp; |
||
538 | tmp = tmp.setNum(verSpin->value(), 'f', docUnitPrecision); |
||
539 | item->setText(0, tmp); |
||
4215 | subik | 540 | emit guidesChanged(); |
3 | paul | 541 | } |
2143 | subik | 542 | |
2215 | subik | 543 | void GuideManager::unitChange() |
3 | paul | 544 | { |
4185 | subik | 545 | horSpin->setSuffix(suffix); |
546 | verSpin->setSuffix(suffix); |
||
547 | rowGap->setSuffix(suffix); |
||
548 | colGap->setSuffix(suffix); |
||
549 | horSpin->setDecimals(docUnitDecimals); |
||
550 | verSpin->setDecimals(docUnitDecimals); |
||
551 | rowGap->setDecimals(docUnitDecimals); |
||
552 | colGap->setDecimals(docUnitDecimals); |
||
3 | paul | 553 | } |
2143 | subik | 554 | |
2164 | subik | 555 | void GuideManager::refreshDoc() |
556 | { |
||
4185 | subik | 557 | if (rowSpin->value() > 1) |
558 | addRows(); |
||
559 | if (colSpin->value() > 1) |
||
560 | addCols(); |
||
561 | QValueList<double> tmp = getValuesFromList(verList); |
||
562 | ScMW->doc->currentPage->addXGuides(tmp); |
||
563 | tmp = getValuesFromList(horList); |
||
564 | ScMW->doc->currentPage->addYGuides(tmp); |
||
565 | ScMW->doc->lockGuides(lockedCheckBox->isChecked()); |
||
4026 | craig | 566 | ScMW->view->DrawNew(); |
2164 | subik | 567 | } |
2200 | subik | 568 | |
3816 | subik | 569 | void GuideManager::refreshWholeDoc() |
570 | { |
||
4026 | craig | 571 | int origPage = ScMW->doc->currentPage->pageNr(); |
3816 | subik | 572 | |
4136 | cbradney | 573 | for (uint i = 0; i < ScMW->doc->Pages->count(); ++i) |
3816 | subik | 574 | { |
4026 | craig | 575 | ScMW->view->GotoPage(i); |
4185 | subik | 576 | refreshDoc(); |
3816 | subik | 577 | } |
4026 | craig | 578 | ScMW->view->GotoPage(origPage); |
579 | ScMW->view->DrawNew(); |
||
3816 | subik | 580 | } |
581 | |||
2200 | subik | 582 | void GuideManager::useRowGap_clicked(bool state) |
583 | { |
||
584 | rowGap->setEnabled(state); |
||
4198 | subik | 585 | if (state) |
586 | rowGap->setFocus(); |
||
2200 | subik | 587 | } |
588 | |||
589 | void GuideManager::useColGap_clicked(bool state) |
||
590 | { |
||
591 | colGap->setEnabled(state); |
||
4198 | subik | 592 | if (state) |
593 | colGap->setFocus(); |
||
2200 | subik | 594 | } |
2237 | subik | 595 | |
596 | void GuideManager::commitChanges() |
||
597 | { |
||
598 | commitEditChanges(); |
||
599 | return accept(); |
||
600 | } |
||
601 | |||
602 | void GuideManager::commitEditChanges() |
||
603 | { |
||
604 | qApp->setOverrideCursor(QCursor(waitCursor), true); |
||
3816 | subik | 605 | if (allPages->isChecked()) |
606 | refreshWholeDoc(); |
||
607 | else |
||
608 | refreshDoc(); |
||
2237 | subik | 609 | QApplication::restoreOverrideCursor(); |
610 | } |
||
4185 | subik | 611 | |
612 | void GuideManager::setGuidesFromList(QListView *w, QValueList<double> guides) |
||
613 | { |
||
614 | QValueList<double>::iterator it; |
||
615 | QString tmp; |
||
616 | |||
617 | for (it = guides.begin(); it != guides.end(); ++it) |
||
618 | { |
||
619 | tmp = tmp.setNum((*it) * docUnitRatio , 'f', docUnitPrecision); |
||
4215 | subik | 620 | // no insert for duplicates |
621 | if (w->findItem(tmp, 0) != 0) |
||
622 | continue; |
||
623 | QListViewItem *item = new GuideListItem(w, tmp, suffix); |
||
4185 | subik | 624 | w->insertItem(item); |
625 | } |
||
626 | w->setCurrentItem(w->firstChild()); |
||
627 | w->setSelected(w->firstChild(), true); |
||
4215 | subik | 628 | emit guidesChanged(); |
4185 | subik | 629 | } |
630 | |||
631 | QValueList<double> GuideManager::getValuesFromList(QListView *w) |
||
632 | { |
||
633 | QValueList<double> ret; |
||
634 | QListViewItemIterator it(w); |
||
635 | |||
636 | while (it.current()) |
||
637 | { |
||
638 | ret.append(it.current()->text(0).toDouble() / docUnitRatio); |
||
639 | ++it; |
||
640 | } |
||
641 | return ret; |
||
642 | } |
||
643 | |||
644 | void GuideManager::verList_currentChanged(QListViewItem *item) |
||
645 | { |
||
646 | double val; |
||
647 | if (!item) |
||
648 | val = 0.0; |
||
649 | else |
||
650 | val = item->text(0).toDouble(); |
||
651 | verSpin->setValue(val); |
||
4215 | subik | 652 | emit guidesChanged(); |
4185 | subik | 653 | } |
654 | |||
655 | void GuideManager::horList_currentChanged(QListViewItem *item) |
||
656 | { |
||
657 | double val; |
||
658 | if (!item) |
||
659 | val = 0.0; |
||
660 | else |
||
661 | val = item->text(0).toDouble(); |
||
662 | horSpin->setValue(val); |
||
4215 | subik | 663 | emit guidesChanged(); |
4185 | subik | 664 | } |
4215 | subik | 665 | |
666 | void GuideManager::slotDrawPreview() |
||
667 | { |
||
668 | int size = 400; // height of the preview pixmap |
||
669 | int x, y; // helper values. original guide size to smaller one |
||
670 | double val; // position of the current guide (red one) |
||
671 | QPixmap pm; // paint device for preview |
||
672 | QPainter *p = new QPainter(); |
||
673 | QValueList<double> vg = getValuesFromList(verList); // vert. g. |
||
674 | QValueList<double> hg = getValuesFromList(horList); // hor. g. |
||
675 | QValueList<double>::iterator it; // iterator for guides lists |
||
676 | |||
677 | vg += getAutoCols(); |
||
678 | hg += getAutoRows(); |
||
679 | //! \note Sorting is a must here for GUI |
||
680 | horList->sort(); |
||
681 | verList->sort(); |
||
682 | |||
683 | // load the page only at the first time |
||
684 | if (previewPixmap.isNull()) |
||
685 | previewPixmap = ScMW->view->PageToPixmap(ScMW->doc->currentPageNumber(), size); |
||
686 | |||
687 | pm = previewPixmap; |
||
688 | p->begin(&pm); |
||
689 | p->setPen(QPen(ScMW->doc->guidesSettings.guideColor, 1, Qt::SolidLine)); |
||
690 | // all guides - paint it standard |
||
691 | for (it = vg.begin(); it != vg.end(); ++it) |
||
692 | { |
||
693 | x = (int)(pm.width() * (*it) / ScMW->doc->currentPage->width()); |
||
694 | p->drawLine(x, 0, x, pm.height()); |
||
695 | } |
||
696 | for (it = hg.begin(); it != hg.end(); ++it) |
||
697 | { |
||
698 | y = (int)(pm.height() * (*it) / ScMW->doc->currentPage->height()); |
||
699 | p->drawLine(0, y, pm.width(), y); |
||
700 | } |
||
701 | // current guide - paint it bold and red... |
||
702 | p->setPen(QPen(QColor(200, 0, 0), 3, Qt::SolidLine)); |
||
703 | val = verSpin->value(); |
||
704 | if (val > 0.0) |
||
705 | { |
||
706 | x = (int)(pm.width() * val / ScMW->doc->currentPage->width()); |
||
707 | p->drawLine(x, 0, x, pm.height()); |
||
708 | } |
||
709 | val = horSpin->value(); |
||
710 | if (val > 0.0) |
||
711 | { |
||
712 | y = (int)(pm.height() * val / ScMW->doc->currentPage->height()); |
||
713 | p->drawLine(0, y, pm.width(), y); |
||
714 | } |
||
715 | p->end(); |
||
716 | previewLabel->setPixmap(pm); |
||
717 | delete p; |
||
718 | } |