Back to index

scribus-ng  1.3.4.dfsg+svn20071115
guidemanager.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                               guidemanager.cpp
00009                              -------------------
00010     begin                : Fri Jan 30 2004
00011     copyright            : (C) 2004 by Alessandro Rimoldi
00012     copyright            : (C) by Franz Schmid
00013     e-mail               : http://www.ideale.ch/contact
00014  ***************************************************************************/
00015 
00016 /***************************************************************************
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 #include <qradiobutton.h>
00026 #include <qlayout.h>
00027 #include <qcursor.h>
00028 #include <qlistview.h>
00029 #include <qdialog.h>
00030 #include <qvaluelist.h>
00031 #include <qgroupbox.h>
00032 #include <qlabel.h>
00033 #include <qlistview.h>
00034 #include <qpushbutton.h>
00035 #include <qcheckbox.h>
00036 #include <qtooltip.h>
00037 #include <qhbuttongroup.h>
00038 #include <qtabwidget.h>
00039 
00040 #include "guidemanager.h"
00041 #include "guidemanager.moc"
00042 #include "scribuscore.h"
00043 #include "scribusdoc.h"
00044 #include "page.h"
00045 #include "units.h"
00046 #include "util.h"
00047 #include "commonstrings.h"
00048 #include "scinputdialog.h"
00049 #include "selection.h"
00050 #include "undomanager.h"
00051 
00052 
00053 int GuideListItem::compare(QListViewItem *i, int col, bool asc) const
00054 {
00055        if (col == 0)
00056        {
00057               double d;
00058               d = text(col).toDouble() - i->text(col).toDouble();
00059               if (d > 0.0)
00060                      return 1;
00061               return -1;
00062        }
00063        else
00064               return QListViewItem::compare(i, col, asc);
00065 }
00066 
00067 
00068 GuideManager::GuideManager(QWidget* parent) :
00069               GuideManagerBase(parent, "GuideManager"),
00070               m_Doc(0),
00071               currentPage(0),
00072               m_drawGuides(true)
00073 {
00074        tabWidget->setEnabled(false);
00075        horizontalAutoGapSpin->setMinValue(0.0);
00076        horizontalAutoGapSpin->setMaxValue(100.0);
00077        verticalAutoGapSpin->setMinValue(0.0);
00078        verticalAutoGapSpin->setMaxValue(100.0);
00079 
00080        // signals that cannot be defined in designer (mspinbox related)
00081        connect(horizontalAutoGapSpin, SIGNAL(valueChanged(int)), this, SLOT(horizontalAutoGapSpin_valueChanged(int)));
00082        connect(verticalAutoGapSpin, SIGNAL(valueChanged(int)), this, SLOT(verticalAutoGapSpin_valueChanged(int)));
00083 }
00084 
00085 void GuideManager::setDoc(ScribusDoc* doc)
00086 {
00087        m_Doc=doc;
00088        if (!m_Doc)
00089               currentPage = 0;
00090        tabWidget->setEnabled(doc ? true : false);
00091 }
00092 
00093 void GuideManager::setupPage()
00094 {
00095        if (!m_Doc)
00096               return;
00097        m_drawGuides = false;
00098        setEnabled(true);
00099        // store old values for current page (=page to leave)
00100        storePageValues(currentPage);
00101        currentPage = m_Doc->currentPage();
00102        unitChange();
00103        setupGui();
00104 }
00105 
00106 void GuideManager::setupGui()
00107 {
00108        // restore values from new page
00109        clearRestoreHorizontalList();
00110        clearRestoreVerticalList();
00111        // restore: brand "auto guides into GUI restore algorithm"
00112        bool enable = currentPage->guides.horizontalAutoGap() > 0.0 ? true : false;
00113        horizontalAutoGapCheck->setChecked(enable);
00114        horizontalAutoGapSpin->setEnabled(enable);
00115        horizontalAutoGapSpin->setValue(pts2value(currentPage->guides.horizontalAutoGap(), docUnitIndex));
00116        horizontalAutoCountSpin->setValue(currentPage->guides.horizontalAutoCount());
00117        if (horizontalAutoCountSpin->value()==0)
00118        {
00119               horizontalAutoGapSpin->setEnabled(false);
00120               horizontalAutoGapCheck->setEnabled(false);
00121        }
00122        horizontalReferGroup->setButton(currentPage->guides.horizontalAutoRefer());
00123        // allow the selection radio button?
00124        horizontalSelectionAutoButton->setEnabled(!m_Doc->m_Selection->isEmpty());
00125 
00126        // verticals
00127        enable = currentPage->guides.verticalAutoGap() > 0.0 ? true : false;
00128        verticalAutoGapCheck->setChecked(enable);
00129        verticalAutoGapSpin->setEnabled(enable);
00130        verticalAutoGapSpin->setValue(pts2value(currentPage->guides.verticalAutoGap(), docUnitIndex));
00131        verticalAutoCountSpin->setValue(currentPage->guides.verticalAutoCount());
00132        if (verticalAutoCountSpin->value()==0)
00133        {
00134               verticalAutoGapSpin->setEnabled(false);
00135               verticalAutoGapCheck->setEnabled(false);
00136        }
00137        verticalReferGroup->setButton(currentPage->guides.verticalAutoRefer());
00138        // allow the selection radio button?
00139        verticalSelectionAutoButton->setEnabled(!m_Doc->m_Selection->isEmpty());
00140 
00141        m_drawGuides = true;
00142        drawGuides();
00143 }
00144 
00145 void GuideManager::storePageValues(Page *page)
00146 {
00147        if (!page || !m_Doc)
00148               return;
00149 
00150        double gapValue = 0.0;
00151        if (horizontalAutoGapCheck->isChecked())
00152               gapValue = value2pts(horizontalAutoGapSpin->value(), docUnitIndex);
00153        page->guides.setHorizontalAutoGap(gapValue);
00154        page->guides.setHorizontalAutoCount(horizontalAutoCountSpin->value());
00155        page->guides.setHorizontalAutoRefer(horizontalReferGroup->selectedId());
00156        page->guides.addHorizontals(getAutoHorizontals(), GuideManagerCore::Auto);
00157 
00158        gapValue = 0.0;
00159        if (verticalAutoGapCheck->isChecked())
00160               gapValue = value2pts(verticalAutoGapSpin->value(), docUnitIndex);
00161        page->guides.setVerticalAutoGap(gapValue);
00162        page->guides.setVerticalAutoCount(verticalAutoCountSpin->value());
00163        page->guides.setVerticalAutoRefer(verticalReferGroup->selectedId());
00164        page->guides.addVerticals(getAutoVerticals(), GuideManagerCore::Auto);
00165 }
00166 
00167 void GuideManager::unitChange()
00168 {
00169        if (!m_Doc)
00170               return;
00171        // a little bit magic to get Verticals (unit) into group boxes
00172        horizontalGroupBox->setTitle(horizontalGroupBox->title().remove(" ("+suffix.stripWhiteSpace()+")"));
00173        verticalGroupBox->setTitle(verticalGroupBox->title().remove(" ("+suffix.stripWhiteSpace()+")"));
00174        docUnitIndex = m_Doc->unitIndex();
00175        docUnitPrecision = unitGetPrecisionFromIndex(docUnitIndex);
00176        docUnitRatio = unitGetRatioFromIndex(docUnitIndex);
00177        docUnitDecimals = unitGetDecimalsFromIndex(docUnitIndex);
00178        
00179        suffix = unitGetSuffixFromIndex(docUnitIndex);
00180        horizontalAutoGapSpin->setSuffix(suffix);
00181        verticalAutoGapSpin->setSuffix(suffix);
00182        horizontalAutoGapSpin->setDecimals(docUnitDecimals);
00183        verticalAutoGapSpin->setDecimals(docUnitDecimals);
00184        horizontalGroupBox->setTitle(horizontalGroupBox->title() + " ("+suffix.stripWhiteSpace()+")");
00185        verticalGroupBox->setTitle(verticalGroupBox->title() + " ("+suffix.stripWhiteSpace()+")");
00186 }
00187 
00188 bool GuideManager::deleteValueFormList(QListView *list)
00189 {
00190        /* previous item pointer to ensure that ++it
00191        runs before item goes deleted */
00192        QListViewItem *itemToDelete;
00193        QListViewItemIterator it(list, QListViewItemIterator::Selected);
00194        QString value;
00195        while (it.current())
00196        {
00197               itemToDelete = it.current();
00198               value = itemToDelete->text(0);
00199               if (list == horizontalList)
00200                      currentPage->guides.deleteHorizontal(m_horMap[value], GuideManagerCore::Standard);
00201               else
00202                      currentPage->guides.deleteVertical(m_verMap[value], GuideManagerCore::Standard);
00203               ++it;
00204               if (itemToDelete)
00205               {
00206                      list->takeItem(itemToDelete);
00207                      delete itemToDelete;
00208               }
00209        }
00210        drawGuides();
00211        return true;
00212 }
00213 
00214 void GuideManager::delHorButton_clicked()
00215 {
00216        deleteValueFormList(horizontalList);
00217 }
00218 
00219 void GuideManager::delVerButton_clicked()
00220 {
00221        deleteValueFormList(verticalList);
00222 }
00223 
00224 bool GuideManager::editValueToList(QListView *list)
00225 {
00226        bool ok;
00227        QString original = list->currentItem()->text(0);
00228        double newGuide = ScInputDialog::getDouble( tr("Edit Guide"),
00229                                                                                tr("Enter a position:"),
00230                                                                                original.toDouble(),
00231                                                                                0, 1000, docUnitDecimals, suffix,
00232                                                                                &ok, this);
00233        if (!ok)
00234               return false;
00235 
00236        if (list == horizontalList)
00237        {
00238               currentPage->guides.moveHorizontal(m_horMap[original], value2pts(newGuide, docUnitIndex),
00239                                                                          GuideManagerCore::Standard);
00240               clearRestoreHorizontalList();
00241        }
00242        else
00243        {
00244               currentPage->guides.moveVertical(m_verMap[original], value2pts(newGuide, docUnitIndex),
00245                                                                        GuideManagerCore::Standard);
00246               clearRestoreVerticalList();
00247        }
00248        drawGuides();
00249        return true;
00250 }
00251 
00252 bool GuideManager::addValueToList(QListView *list)
00253 {
00254        bool ok;
00255        double newGuide = ScInputDialog::getDouble( tr("New Guide"),
00256                                                                        tr("Enter a position:"),
00257                                                                        0.0, 0, 1000, docUnitDecimals, suffix,
00258                                                                        &ok, this );
00259        if (!ok)
00260               return false;
00261 
00262        QString tmp;
00263        tmp = tmp.setNum(newGuide, 'f', docUnitPrecision);
00264        double ng = value2pts(newGuide, docUnitIndex);
00265        if (list == horizontalList)
00266        {
00267               Guides tmpGuides = currentPage->guides.horizontals(GuideManagerCore::Standard);
00268               if (tmpGuides.contains(ng))
00269                      return false;
00270               currentPage->guides.addHorizontal(ng, GuideManagerCore::Standard);
00271               m_horMap[tmp] = ng;
00272        }
00273        else
00274        {
00275               Guides tmpGuides = currentPage->guides.verticals(GuideManagerCore::Standard);
00276               if (tmpGuides.contains(ng))
00277                      return false;
00278               currentPage->guides.addVertical(ng, GuideManagerCore::Standard);
00279               m_verMap[tmp] = ng;
00280        }
00281 
00282        GuideListItem *item = new GuideListItem(list, tmp);
00283        item->setRenameEnabled(0, true);
00284        list->insertItem(item);
00285        list->setCurrentItem(item);
00286        list->clearSelection();
00287        list->setSelected(item, true);
00288        drawGuides();
00289        return true;
00290 }
00291 
00292 void GuideManager::addHorButton_clicked()
00293 {
00294        addValueToList(horizontalList);
00295 }
00296 
00297 void GuideManager::addVerButton_clicked()
00298 {
00299        addValueToList(verticalList);
00300 }
00301 
00302 void GuideManager::setGuidesFromList(QListView *w, GuideGUIMap *map, Guides guides)
00303 {
00304        QString tmp;
00305        //w->clear(); // clearing is moved into the setupPage()
00306        for (Guides::iterator it = guides.begin(); it != guides.end(); ++it)
00307        {
00308               tmp = tmp.setNum((*it) * docUnitRatio , 'f', docUnitPrecision);
00309               // no insert for duplicates
00310               if (w->findItem(tmp, 0) != 0)
00311                      continue;
00312               GuideListItem *item = new GuideListItem(w, tmp);
00313               w->insertItem(item);
00314               map->insert(tmp, (*it));
00315        }
00316 }
00317 
00318 void GuideManager::lockCheck_stateChanged( int )
00319 {
00320        m_Doc->lockGuides(lockCheck->isChecked());
00321 }
00322 
00323 void GuideManager::copyGuidesToAllPages(GuideManagerCore::GuideType t)
00324 {
00325        QPtrListIterator<Page> it(*m_Doc->Pages);
00326        Page *tmpPage;
00327        while ((tmpPage = it.current()) != 0 )
00328        {
00329               ++it;
00330               if (tmpPage->pageNr() == currentPage->pageNr())
00331                      continue;
00332               tmpPage->guides.clearHorizontals(t);
00333               tmpPage->guides.clearVerticals(t);
00334               currentPage->guides.copy(&tmpPage->guides, t);
00335               if (t == GuideManagerCore::Auto)
00336                      storePageValues(tmpPage);
00337        }
00338        drawGuides();
00339 }
00340 
00341 void GuideManager::applyToAllStdButton_clicked()
00342 {
00343        copyGuidesToAllPages(GuideManagerCore::Standard);
00344 }
00345 
00346 void GuideManager::applyToAllAutoButton_clicked()
00347 {
00348        copyGuidesToAllPages(GuideManagerCore::Auto);
00349 }
00350 
00351 void GuideManager::horizontalAutoCountSpin_valueChanged(int val)
00352 {
00353        bool enable = (val == 0) ? false : true;
00354        horizontalAutoGapCheck->setEnabled(enable);
00355        if (enable && horizontalAutoGapCheck->isChecked())
00356               horizontalAutoGapSpin->setEnabled(true);
00357        else
00358               horizontalAutoGapSpin->setEnabled(false);
00359        currentPage->guides.setHorizontalAutoCount(val);
00360        drawGuides();
00361 }
00362 
00363 void GuideManager::horizontalAutoGapSpin_valueChanged(int)
00364 {
00365        currentPage->guides.setHorizontalAutoGap(value2pts(horizontalAutoGapSpin->value(), docUnitIndex));
00366        drawGuides();
00367 }
00368 
00369 void GuideManager::horizontalAutoGapCheck_stateChanged( int )
00370 {
00371        horizontalAutoGapSpin->setEnabled(horizontalAutoGapCheck->isChecked());
00372        if (horizontalAutoGapCheck->isChecked())
00373               currentPage->guides.setHorizontalAutoGap(value2pts(horizontalAutoGapSpin->value(), docUnitIndex));
00374        else
00375               currentPage->guides.setHorizontalAutoGap(value2pts(0.0, docUnitIndex));
00376        drawGuides();
00377 }
00378 
00379 void GuideManager::verticalAutoCountSpin_valueChanged(int val)
00380 {
00381        bool enable = (val == 0) ? false : true;
00382        verticalAutoGapCheck->setEnabled(enable);
00383        if (enable && verticalAutoGapCheck->isChecked())
00384               verticalAutoGapSpin->setEnabled(true);
00385        else
00386               verticalAutoGapSpin->setEnabled(false);
00387        currentPage->guides.setVerticalAutoCount(val);
00388        drawGuides();
00389 }
00390 
00391 void GuideManager::verticalAutoGapSpin_valueChanged(int)
00392 {
00393        currentPage->guides.setVerticalAutoGap(value2pts(verticalAutoGapSpin->value(), docUnitIndex));
00394        drawGuides();
00395 }
00396 
00397 void GuideManager::verticalAutoGapCheck_stateChanged( int )
00398 {
00399        verticalAutoGapSpin->setEnabled(verticalAutoGapCheck->isChecked());
00400        if (verticalAutoGapCheck->isChecked())
00401               currentPage->guides.setVerticalAutoGap(value2pts(verticalAutoGapSpin->value(), docUnitIndex));
00402        else
00403               currentPage->guides.setVerticalAutoGap(value2pts(0.0, docUnitIndex));
00404        drawGuides();
00405 }
00406 
00407 void GuideManager::horizontalReferGroup_clicked(int val)
00408 {
00409        currentPage->guides.setHorizontalAutoRefer(val);
00410        if (val == 2 && horizontalSelectionAutoButton->isEnabled())
00411               resetSelectionForPage();
00412        drawGuides();
00413 }
00414 
00415 void GuideManager::verticalReferGroup_clicked(int val)
00416 {
00417        currentPage->guides.setVerticalAutoRefer(val);
00418        if (val == 2 && verticalSelectionAutoButton->isEnabled())
00419               resetSelectionForPage();
00420        drawGuides();
00421 }
00422 
00423 void GuideManager::tabWidget_currentChanged(QWidget *)
00424 {
00425        drawGuides();
00426        if (tabWidget->currentPageIndex() == 1)
00427        {
00428               horizontalAutoGapSpin->setEnabled(horizontalAutoGapCheck->isChecked());
00429               verticalAutoGapSpin->setEnabled(verticalAutoGapCheck->isChecked());
00430        }
00431 }
00432 
00433 void GuideManager::horizontalList_doubleClicked( QListViewItem * )
00434 {
00435        editValueToList(horizontalList);
00436 }
00437 
00438 void GuideManager::horizontalList_returnPressed( QListViewItem * )
00439 {
00440        editValueToList(horizontalList);
00441 }
00442 
00443 void GuideManager::verticalList_returnPressed( QListViewItem * )
00444 {
00445        editValueToList(verticalList);
00446 }
00447 
00448 void GuideManager::verticalList_doubleClicked( QListViewItem * )
00449 {
00450        editValueToList(verticalList);
00451 }
00452 
00453 Guides GuideManager::selectedHorizontals()
00454 {
00455        Guides retval;
00456        QListViewItemIterator it(horizontalList);
00457        while (it.current())
00458        {
00459               if (it.current()->isSelected())
00460                      retval.append(it.current()->text(0).toDouble() / docUnitRatio);
00461               ++it;
00462        }
00463        return retval;
00464 }
00465 
00466 Guides GuideManager::selectedVerticals()
00467 {
00468        Guides retval;
00469        QListViewItemIterator it(verticalList);
00470        while (it.current())
00471        {
00472               if (it.current()->isSelected())
00473                      retval.append(it.current()->text(0).toDouble() / docUnitRatio);
00474               ++it;
00475        }
00476        return retval;
00477 }
00478 
00479 void GuideManager::horizontalList_selectionChanged()
00480 {
00481        drawGuides();
00482 }
00483 
00484 void GuideManager::verticalList_selectionChanged()
00485 {
00486        drawGuides();
00487 }
00488 
00489 void GuideManager::drawGuides()
00490 {
00491        if (!m_Doc || !m_drawGuides)
00492               return;
00493 
00494        currentPage->guides.addHorizontals(getAutoHorizontals(), GuideManagerCore::Auto);
00495        currentPage->guides.addVerticals(getAutoVerticals(), GuideManagerCore::Auto);
00496        ScCore->primaryMainWindow()->view->DrawNew();
00497 }
00498 
00499 void GuideManager::clearRestoreHorizontalList()
00500 {
00501        m_horMap.clear();
00502        horizontalList->clear();
00503        setGuidesFromList(horizontalList, &m_horMap,
00504                                      currentPage->guides.horizontals(GuideManagerCore::Standard));
00505 }
00506 
00507 void GuideManager::clearRestoreVerticalList()
00508 {
00509        m_verMap.clear();
00510        verticalList->clear();
00511        setGuidesFromList(verticalList, &m_verMap,
00512                                      currentPage->guides.verticals(GuideManagerCore::Standard));
00513 }
00514 
00515 void GuideManager::deletePageButton_clicked()
00516 {
00517        UndoManager::instance()->beginTransaction(currentPage->getUName(),
00518                                      currentPage->getUPixmap(),
00519                                      Um::RemoveAllPageGuides, "",
00520                                      Um::IGuides);
00521        currentPage->guides.clearHorizontals(GuideManagerCore::Standard);
00522        currentPage->guides.clearVerticals(GuideManagerCore::Standard);
00523        currentPage->guides.clearHorizontals(GuideManagerCore::Auto);
00524        currentPage->guides.clearVerticals(GuideManagerCore::Auto);
00525        clearRestoreHorizontalList();
00526        clearRestoreVerticalList();
00527 
00528        currentPage->guides.setHorizontalAutoCount(0);
00529        currentPage->guides.setVerticalAutoCount(0);
00530        currentPage->guides.setHorizontalAutoGap(0.0);
00531        currentPage->guides.setVerticalAutoGap(0.0);
00532        currentPage->guides.setHorizontalAutoRefer(0);
00533        currentPage->guides.setVerticalAutoRefer(0);
00534        horizontalAutoCountSpin->setValue(0);
00535        verticalAutoCountSpin->setValue(0);
00536        UndoManager::instance()->commit();
00537 
00538        drawGuides();
00539 }
00540 
00541 void GuideManager::deleteAllGuides_clicked()
00542 {
00543        UndoManager::instance()->beginTransaction(m_Doc->getUName(),
00544                                      m_Doc->getUPixmap(),
00545                                      Um::RemoveAllGuides, "",
00546                                      Um::IGuides);
00547        m_drawGuides = false;
00548        deletePageButton_clicked();
00549        copyGuidesToAllPages(GuideManagerCore::Standard);
00550        copyGuidesToAllPages(GuideManagerCore::Auto);
00551        m_drawGuides = true;
00552        UndoManager::instance()->commit();
00553        drawGuides();
00554 }
00555 
00556 void GuideManager::windowActivationChange(bool oldActive)
00557 {
00558        if (m_Doc)
00559        {
00560               bool enable = !m_Doc->m_Selection->isEmpty();
00561               horizontalSelectionAutoButton->setEnabled(enable);
00562               verticalSelectionAutoButton->setEnabled(enable);
00563        }
00564        QDialog::windowActivationChange( oldActive );
00565 }
00566 
00567 Guides GuideManager::getAutoVerticals()
00568 {
00569        Guides retval;
00570        double columnSize;
00571        int value = verticalAutoCountSpin->value();
00572        double offset = 0.0;
00573        double newPageWidth = currentPage->width();
00574 
00575        if (value == 0)
00576               return retval;
00577        ++value;
00578 
00579        if (verticalReferGroup->selectedId() == 1)
00580        {
00581               newPageWidth = newPageWidth - currentPage->Margins.Left - currentPage->Margins.Right;
00582               offset = currentPage->Margins.Left;
00583        }
00584        else if (qRound(currentPage->guides.gx) != 0)
00585        {
00586               offset = currentPage->guides.gx;
00587               newPageWidth = currentPage->guides.gw;
00588        }
00589 
00590        if (verticalAutoGapSpin->value() > 0.0)
00591               columnSize = (newPageWidth - (value - 1) * verticalAutoGapSpin->value()) / value;
00592        else
00593               columnSize = newPageWidth / value;
00594 
00595        for (int i = 1, gapCount = 0; i < value; ++i)
00596        {
00597               if (verticalAutoGapSpin->value() > 0.0)
00598               {
00599                      retval.append(offset + i * columnSize + gapCount * verticalAutoGapSpin->value());
00600                      ++gapCount;
00601                      retval.append(offset + i * columnSize + gapCount * verticalAutoGapSpin->value());
00602               }
00603               else
00604                      retval.append(offset + columnSize * i);
00605        }
00606        return retval;
00607 }
00608 
00609 Guides GuideManager::getAutoHorizontals()
00610 {
00611        Guides retval;
00612        double rowSize;
00613        int value = horizontalAutoCountSpin->value();
00614        double offset = 0.0;
00615        double newPageHeight = currentPage->height();
00616 
00617        if (value == 0)
00618               return retval;
00619        ++value;
00620 
00621        if (horizontalReferGroup->selectedId() == 1)
00622        {
00623               newPageHeight = newPageHeight - currentPage->Margins.Top - currentPage->Margins.Bottom;
00624               offset = currentPage->Margins.Top;
00625        }
00626        else if (qRound(currentPage->guides.gy) != 0.0)
00627        {
00628               offset = currentPage->guides.gy;
00629               newPageHeight = currentPage->guides.gh;
00630        }
00631 
00632        if (horizontalAutoGapSpin->value() > 0.0)
00633               rowSize = (newPageHeight - (value - 1) * horizontalAutoGapSpin->value()) / value;
00634        else
00635               rowSize = newPageHeight / value;
00636 
00637        for (int i = 1, gapCount = 0; i < value; ++i)
00638        {
00639               if (horizontalAutoGapSpin->value() > 0.0)
00640               {
00641                      retval.append(offset + i * rowSize + gapCount * horizontalAutoGapSpin->value());
00642                      ++gapCount;
00643                      retval.append(offset + i * rowSize + gapCount * horizontalAutoGapSpin->value());
00644               }
00645               else
00646                      retval.append(offset + rowSize * i);
00647        }
00648        return retval;
00649 }
00650 
00651 void GuideManager::resetSelectionForPage()
00652 {
00653        int docSelectionCount = currentPage->doc()->m_Selection->count();
00654 
00655        currentPage->guides.gx = currentPage->guides.gy = currentPage->guides.gw = currentPage->guides.gh = 0.0;
00656 
00657        // multiselection
00658        if (docSelectionCount > 1)
00659        {
00660               double x, y;
00661               m_Doc->m_Selection->getGroupRect(&x, &y, &currentPage->guides.gw, &currentPage->guides.gh);
00662               currentPage->guides.gx = x - currentPage->xOffset();
00663               currentPage->guides.gy = y - currentPage->yOffset();
00664        }
00665        // only one item selected
00666        else if (docSelectionCount == 1)
00667        {
00668               PageItem *currItem = m_Doc->m_Selection->itemAt(0);
00669               currentPage->guides.gx = currItem->xPos() - currentPage->xOffset();
00670               currentPage->guides.gy = currItem->yPos() - currentPage->yOffset();
00671               currentPage->guides.gw = currItem->width();
00672               currentPage->guides.gh = currItem->height();
00673        }
00674 }