Back to index

scribus-ng  1.3.4.dfsg+svn20071115
aligndistribute.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        begin                : June 2005
00009        copyright            : (C) 2005 by Craig Bradney
00010        email                : cbradney@zip.com.au
00011 ***************************************************************************/
00012 
00013 /***************************************************************************
00014 *                                                                         *
00015 *   ScMW program is free software; you can redistribute it and/or modify  *
00016 *   it under the terms of the GNU General Public License as published by  *
00017 *   the Free Software Foundation; either version 2 of the License, or     *
00018 *   (at your option) any later version.                                   *
00019 *                                                                         *
00020 ***************************************************************************/
00021 
00022 #include "aligndistribute.h"
00023 #include "aligndistribute.moc"
00024 
00025 #include <qvariant.h>
00026 #include <qpushbutton.h>
00027 #include <qlabel.h>
00028 #include <qcombobox.h>
00029 #include <qtoolbutton.h>
00030 #include <qlayout.h>
00031 #include <qtooltip.h>
00032 #include <qwhatsthis.h>
00033 #include <qimage.h>
00034 #include <qpixmap.h>
00035 #include <qlineedit.h>
00036 #include <qtabwidget.h>
00037 
00038 #include "page.h"
00039 #include "scmessagebox.h"
00040 #include "scribusdoc.h"
00041 #include "selection.h"
00042 #include "undomanager.h"
00043 #include "mspinbox.h"
00044 #include "units.h"
00045 #include "commonstrings.h"
00046 
00047 extern QPixmap loadIcon(QString nam);
00048 
00049 //TODO Distribute with 
00050 
00051 AlignDistributePalette::AlignDistributePalette( QWidget* parent, const char* name, bool /*modal*/, WFlags /*fl*/ )
00052        : AlignDistributeBase( parent, name )
00053 {
00054        if ( !name )
00055               setName( "AlignDistributePalette" );
00056        currDoc=NULL;
00057        
00058        //hide spare controls 
00059        toolButtonDummy1->hide();
00060        toolButtonDummy2->hide();
00061 
00062        //set up mspinboxes
00063        distributeDistMSpinBox->setValues(-1000.0, 1000.0, 100, 0.0);
00064 
00065        // buddies
00066        alignRelativeToLabel->setBuddy( alignRelativeToCombo );
00067        alignGuideLabel->setBuddy( alignGuideLineEdit );
00068        distributeDistLabel->setBuddy( distributeDistMSpinBox );
00069        
00070        resize( QSize(100, 100).expandedTo(minimumSizeHint()) );
00071        clearWState( WState_Polished );
00072        
00073        init();
00074        languageChange();
00075        setDoc(NULL);
00076 }
00077 
00078 AlignDistributePalette::~AlignDistributePalette()
00079 {
00080 }
00081 
00082 void AlignDistributePalette::languageChange()
00083 {
00084        setCaption( tr( "Align and Distribute" ) );
00085        tabWidget->changeTab(tabWidget->page(0), tr( "Align"));
00086        tabWidget->changeTab(tabWidget->page(1), tr( "Distribute"));
00087        alignRelativeToLabel->setText( tr( "&Relative to:" ) );
00088        int alignComboValue=alignRelativeToCombo->currentItem();
00089        alignRelativeToCombo->clear();
00090        alignRelativeToCombo->insertItem( tr( "First Selected" ) );
00091        alignRelativeToCombo->insertItem( tr( "Last Selected" ) );
00092        alignRelativeToCombo->insertItem( tr( "Page" ) );
00093        alignRelativeToCombo->insertItem( tr( "Margins" ) );
00094        alignRelativeToCombo->insertItem( tr( "Guide" ) );             
00095        alignRelativeToCombo->insertItem( tr( "Selection" ) );
00096        alignRelativeToCombo->setCurrentItem(alignComboValue);
00097        alignToChanged(alignComboValue);
00098        alignLeftOutToolButton->setText( QString::null );
00099        QToolTip::add( alignLeftOutToolButton, tr( "Align right sides of items to left side of anchor" ) );
00100        alignRightOutToolButton->setText( QString::null );
00101        QToolTip::add( alignRightOutToolButton, tr( "Align left sides of items to right side of anchor" ) );
00102        alignBottomInToolButton->setText( QString::null );
00103        QToolTip::add( alignBottomInToolButton, tr( "Align bottoms" ) );
00104        alignRightInToolButton->setText( QString::null );
00105        QToolTip::add( alignRightInToolButton, tr( "Align right sides" ) );
00106        alignBottomOutToolButton->setText( QString::null );
00107        QToolTip::add( alignBottomOutToolButton, tr( "Align tops of items to bottom of anchor" ) );
00108        alignCenterHorToolButton->setText( QString::null );
00109        QToolTip::add( alignCenterHorToolButton, tr( "Center on vertical axis" ) );
00110        alignLeftInToolButton->setText( QString::null );
00111        QToolTip::add( alignLeftInToolButton, tr( "Align left sides" ) );
00112        alignCenterVerToolButton->setText( QString::null );
00113        QToolTip::add( alignCenterVerToolButton, tr( "Center on horizontal axis" ) );
00114        alignTopOutToolButton->setText( QString::null );
00115        QToolTip::add( alignTopOutToolButton, tr( "Align bottoms of items to top of anchor" ) );
00116        alignTopInToolButton->setText( QString::null );
00117        QToolTip::add( alignTopInToolButton, tr( "Align tops" ) );
00118        
00119        alignGuideLabel->setText( tr( "&Selected Guide:" ) );
00120        
00121        distributeDistHToolButton->setText( QString::null );
00122        QToolTip::add( distributeDistHToolButton, tr( "Make horizontal gaps between items equal" ) );
00123        distributeDistValueHToolButton->setText( QString::null );
00124        QToolTip::add( distributeDistValueHToolButton, tr( "Make horizontal gaps between items equal to the value specified" ) );
00125        
00126        distributeRightToolButton->setText( QString::null );
00127        distributeRightToolButton->setTextLabel( tr( "Distribute right sides equidistantly" ) );
00128        distributeBottomToolButton->setText( QString::null );
00129        QToolTip::add( distributeBottomToolButton, tr( "Distribute bottoms equidistantly" ) );
00130        distributeCenterHToolButton->setText( QString::null );
00131        QToolTip::add( distributeCenterHToolButton, tr( "Distribute centers equidistantly horizontally" ) );
00132        distributeDistVToolButton->setText( QString::null );
00133        QToolTip::add( distributeDistVToolButton, tr( "Make vertical gaps between items equal" ) );
00134        distributeDistValueVToolButton->setText( QString::null );
00135        QToolTip::add( distributeDistValueVToolButton, tr( "Make vertical gaps between items equal to the value specified" ) );
00136        distributeLeftToolButton->setText( QString::null );
00137        QToolTip::add( distributeLeftToolButton, tr( "Distribute left sides equidistantly" ) );
00138        distributeCenterVToolButton->setText( QString::null );
00139        QToolTip::add( distributeCenterVToolButton, tr( "Distribute centers equidistantly vertically" ) );
00140        distributeTopToolButton->setText( QString::null );
00141        QToolTip::add( distributeTopToolButton, tr( "Distribute tops equidistantly" ) );
00142        distributeAcrossPageToolButton->setText( QString::null );
00143        QToolTip::add( distributeAcrossPageToolButton, tr( "Make horizontal gaps between items and sides of page equal" ) );
00144        distributeDownPageToolButton->setText( QString::null );
00145        QToolTip::add( distributeDownPageToolButton, tr( "Make vertical gaps between items and the top and bottom of page equal" ) );
00146        distributeAcrossMarginsToolButton->setText( QString::null );
00147        QToolTip::add( distributeAcrossMarginsToolButton, tr( "Make horizontal gaps between items and sides of page margins equal" ) );
00148        distributeDownMarginsToolButton->setText( QString::null );
00149        QToolTip::add( distributeDownMarginsToolButton, tr( "Make vertical gaps between items and the top and bottom of page margins equal" ) );
00150 
00151        distributeDistLabel->setText( tr( "&Distance:" ) );
00152        QToolTip::add( distributeDistMSpinBox, tr( "Distribute the items with the distance specified" ) );
00153        
00154        guideInfoTextNone = tr("None Selected");
00155 }
00156 
00157 void AlignDistributePalette::init()
00158 {
00159        undoManager = UndoManager::instance();
00160 
00161        alignLeftOutToolButton->setIconSet(QIconSet(loadIcon("22/align-horizontal-left-out.png"), QIconSet::Small));
00162        alignLeftInToolButton->setIconSet(QIconSet(loadIcon("22/align-horizontal-left.png"), QIconSet::Small));
00163        alignCenterHorToolButton->setIconSet(QIconSet(loadIcon("22/align-horizontal-center.png"), QIconSet::Small));
00164        alignRightInToolButton->setIconSet(QIconSet(loadIcon("22/align-horizontal-right.png"), QIconSet::Small));
00165        alignRightOutToolButton->setIconSet(QIconSet(loadIcon("22/align-horizontal-right-out.png"), QIconSet::Small));
00166        
00167        alignTopOutToolButton->setIconSet(QIconSet(loadIcon("22/align-vertical-top-out.png"), QIconSet::Small));
00168        alignTopInToolButton->setIconSet(QIconSet(loadIcon("22/align-vertical-top.png"), QIconSet::Small));
00169        alignCenterVerToolButton->setIconSet(QIconSet(loadIcon("22/align-vertical-center.png"), QIconSet::Small));
00170        alignBottomInToolButton->setIconSet(QIconSet(loadIcon("22/align-vertical-bottom.png"), QIconSet::Small));
00171        alignBottomOutToolButton->setIconSet(QIconSet(loadIcon("22/align-vertical-bottom-out.png"), QIconSet::Small));
00172        
00173        distributeLeftToolButton->setIconSet(QIconSet(loadIcon("22/distribute-horizontal-left.png"), QIconSet::Small));
00174        distributeCenterHToolButton->setIconSet(QIconSet(loadIcon("22/distribute-horizontal-center.png"), QIconSet::Small));
00175        distributeRightToolButton->setIconSet(QIconSet(loadIcon("22/distribute-horizontal-right.png"), QIconSet::Small));
00176        distributeDistHToolButton->setIconSet(QIconSet(loadIcon("22/distribute-horizontal-equal.png"), QIconSet::Small));
00177        
00178        distributeBottomToolButton->setIconSet(QIconSet(loadIcon("22/distribute-vertical-bottom.png"), QIconSet::Small));
00179        distributeCenterVToolButton->setIconSet(QIconSet(loadIcon("22/distribute-vertical-center.png"), QIconSet::Small));
00180        distributeTopToolButton->setIconSet(QIconSet(loadIcon("22/distribute-vertical-top.png"), QIconSet::Small));
00181        distributeDistVToolButton->setIconSet(QIconSet(loadIcon("22/distribute-vertical-equal.png"), QIconSet::Small));
00182        
00183        distributeAcrossPageToolButton->setIconSet(QIconSet(loadIcon("22/distribute-horizontal-page.png"), QIconSet::Small));
00184        distributeDownPageToolButton->setIconSet(QIconSet(loadIcon("22/distribute-vertical-page.png"), QIconSet::Small));
00185        distributeAcrossMarginsToolButton->setIconSet(QIconSet(loadIcon("22/distribute-horizontal-margin.png"), QIconSet::Small));
00186        distributeDownMarginsToolButton->setIconSet(QIconSet(loadIcon("22/distribute-vertical-margin.png"), QIconSet::Small));
00187        distributeDistValueHToolButton->setIconSet(QIconSet(loadIcon("22/distribute-horizontal-x.png"), QIconSet::Small));
00188        distributeDistValueVToolButton->setIconSet(QIconSet(loadIcon("22/distribute-vertical-y.png"), QIconSet::Small));
00189        
00190        connect(alignLeftOutToolButton, SIGNAL(clicked()), this, SLOT(alignLeftOut()));
00191        connect(alignRightOutToolButton, SIGNAL(clicked()), this, SLOT(alignRightOut()));
00192        connect(alignBottomInToolButton, SIGNAL(clicked()), this, SLOT(alignBottomIn()));
00193        connect(alignRightInToolButton, SIGNAL(clicked()), this, SLOT(alignRightIn()));
00194        connect(alignBottomOutToolButton, SIGNAL(clicked()), this, SLOT(alignBottomOut()));
00195        connect(alignCenterHorToolButton, SIGNAL(clicked()), this, SLOT(alignCenterHor()));
00196        connect(alignLeftInToolButton, SIGNAL(clicked()), this, SLOT(alignLeftIn()));
00197        connect(alignCenterVerToolButton, SIGNAL(clicked()), this, SLOT(alignCenterVer()));
00198        connect(alignTopOutToolButton, SIGNAL(clicked()), this, SLOT(alignTopOut()));
00199        connect(alignTopInToolButton, SIGNAL(clicked()), this, SLOT(alignTopIn()));
00200        connect(distributeDistHToolButton, SIGNAL(clicked()), this, SLOT(distributeDistH()));
00201        connect(distributeDistValueHToolButton, SIGNAL(clicked()), this, SLOT(distributeDistValH()));
00202        connect(distributeRightToolButton, SIGNAL(clicked()), this, SLOT(distributeRight()));
00203        connect(distributeBottomToolButton, SIGNAL(clicked()), this, SLOT(distributeBottom()));
00204        connect(distributeCenterHToolButton, SIGNAL(clicked()), this, SLOT(distributeCenterH()));
00205        connect(distributeDistVToolButton, SIGNAL(clicked()), this, SLOT(distributeDistV()));
00206        connect(distributeDistValueVToolButton, SIGNAL(clicked()), this, SLOT(distributeDistValV()));
00207        connect(distributeLeftToolButton, SIGNAL(clicked()), this, SLOT(distributeLeft()));
00208        connect(distributeCenterVToolButton, SIGNAL(clicked()), this, SLOT(distributeCenterV()));
00209        connect(distributeTopToolButton, SIGNAL(clicked()), this, SLOT(distributeTop()));
00210        connect(distributeAcrossPageToolButton, SIGNAL(clicked()), this, SLOT(distributeDistAcrossPage()));
00211        connect(distributeDownPageToolButton, SIGNAL(clicked()), this, SLOT(distributeDistDownPage()));
00212        connect(distributeAcrossMarginsToolButton, SIGNAL(clicked()), this, SLOT(distributeDistAcrossMargins()));
00213        connect(distributeDownMarginsToolButton, SIGNAL(clicked()), this, SLOT(distributeDistDownMargins()));
00214        
00215        connect(alignRelativeToCombo, SIGNAL(activated(int)), this, SLOT(alignToChanged(int)));
00216        
00217        unitRatio=1.0;
00218        guideDirection=-1;
00219        
00220        guideInfoText = guideInfoTextNone;
00221        alignGuideLineEdit->setText(guideInfoTextNone);
00222 }
00223 
00224 void AlignDistributePalette::unitChange()
00225 {
00226        if (currDoc!=NULL)
00227        {
00228               double oldValue=distributeDistMSpinBox->value();
00229               double oldRatio=unitRatio;
00230               distributeDistMSpinBox->setDecimals(unitGetDecimalsFromIndex(currDoc->unitIndex()));
00231               distributeDistMSpinBox->setSuffix(unitGetSuffixFromIndex(currDoc->unitIndex()));
00232               unitRatio=unitGetRatioFromIndex(currDoc->unitIndex());
00233               double ratioDivisor =  unitRatio / oldRatio;
00234               distributeDistMSpinBox->setValue(oldValue*ratioDivisor);
00235               enableGuideButtons();
00236        }
00237 }
00238 
00239 void AlignDistributePalette::setDoc( ScribusDoc* newDoc )
00240 {
00241        currDoc=newDoc;
00242        if (currDoc!=NULL)
00243               alignObjects=&(currDoc->AObjects);
00244        else
00245               alignObjects=NULL;
00246        unitChange();
00247 }
00248 
00249 void AlignDistributePalette::alignLeftOut()
00250 {
00251        if (currDoc!=NULL)
00252               currDoc->itemSelection_AlignLeftOut(currAlignTo, guidePosition);
00253 }
00254 
00255 void AlignDistributePalette::alignLeftIn()
00256 {
00257        if (currDoc!=NULL)
00258               currDoc->itemSelection_AlignLeftIn(currAlignTo, guidePosition);
00259 }
00260 
00261 void AlignDistributePalette::alignCenterHor()
00262 {
00263        if (currDoc!=NULL)
00264               currDoc->itemSelection_AlignCenterHor(currAlignTo, guidePosition);
00265 }
00266 
00267 void AlignDistributePalette::alignRightIn()
00268 {
00269        if (currDoc!=NULL)
00270               currDoc->itemSelection_AlignRightIn(currAlignTo, guidePosition);
00271 }
00272 
00273 void AlignDistributePalette::alignRightOut()
00274 {
00275        if (currDoc!=NULL)
00276               currDoc->itemSelection_AlignRightOut(currAlignTo, guidePosition);
00277 }
00278 
00279 void AlignDistributePalette::alignTopOut()
00280 {
00281        if (currDoc!=NULL)
00282               currDoc->itemSelection_AlignTopOut(currAlignTo, guidePosition);
00283 }
00284 
00285 void AlignDistributePalette::alignTopIn()
00286 {
00287        if (currDoc!=NULL)
00288               currDoc->itemSelection_AlignTopIn(currAlignTo, guidePosition);
00289 }
00290 
00291 
00292 void AlignDistributePalette::alignCenterVer()
00293 {
00294        if (currDoc!=NULL)
00295               currDoc->itemSelection_AlignCenterVer(currAlignTo, guidePosition);
00296 }
00297 
00298 
00299 void AlignDistributePalette::alignBottomIn()
00300 {
00301        if (currDoc!=NULL)
00302               currDoc->itemSelection_AlignBottomIn(currAlignTo, guidePosition);
00303 }
00304 
00305 void AlignDistributePalette::alignBottomOut()
00306 {
00307        if (currDoc!=NULL)
00308               currDoc->itemSelection_AlignBottomOut(currAlignTo, guidePosition);
00309 }
00310 
00311 void AlignDistributePalette::distributeLeft()
00312 {
00313        if (currDoc!=NULL)
00314               currDoc->itemSelection_DistributeLeft();
00315 }
00316 
00317 void AlignDistributePalette::distributeCenterH()
00318 {
00319        if (currDoc!=NULL)
00320               currDoc->itemSelection_DistributeCenterH();
00321 }
00322 
00323 void AlignDistributePalette::distributeRight()
00324 {
00325        if (currDoc!=NULL)
00326               currDoc->itemSelection_DistributeRight();
00327 }
00328 
00329 void AlignDistributePalette::distributeDistH(bool usingDistance)
00330 {
00331        if (currDoc!=NULL)
00332               currDoc->itemSelection_DistributeDistH(usingDistance, distributeDistMSpinBox->value());
00333 }
00334 
00335 void AlignDistributePalette::distributeDistValH()
00336 {
00337        if (currDoc!=NULL)
00338               distributeDistH(true);
00339 }
00340 
00341 void AlignDistributePalette::distributeDistAcrossPage()
00342 {
00343        if (currDoc!=NULL)
00344               currDoc->itemSelection_DistributeAcrossPage();
00345 }
00346 
00347 void AlignDistributePalette::distributeDistDownPage()
00348 {
00349        if (currDoc!=NULL)
00350               currDoc->itemSelection_DistributeDownPage();
00351 }
00352 
00353 void AlignDistributePalette::distributeDistAcrossMargins()
00354 {
00355        if (currDoc!=NULL)
00356               currDoc->itemSelection_DistributeAcrossPage(true);
00357 }
00358 
00359 void AlignDistributePalette::distributeDistDownMargins()
00360 {
00361        if (currDoc!=NULL)
00362               currDoc->itemSelection_DistributeDownPage(true);
00363 }
00364 
00365 
00366 void AlignDistributePalette::distributeBottom()
00367 {
00368        if (currDoc!=NULL)
00369               currDoc->itemSelection_DistributeBottom();
00370 }
00371 
00372 void AlignDistributePalette::distributeCenterV()
00373 {
00374        if (currDoc!=NULL)
00375               currDoc->itemSelection_DistributeCenterV();
00376 }
00377 
00378 void AlignDistributePalette::distributeTop()
00379 {
00380        if (currDoc!=NULL)
00381               currDoc->itemSelection_DistributeTop();
00382 }
00383 
00384 void AlignDistributePalette::distributeDistV(bool usingDistance)
00385 {
00386        if (currDoc!=NULL)
00387               currDoc->itemSelection_DistributeDistV(usingDistance, distributeDistMSpinBox->value());
00388 }
00389 
00390 void AlignDistributePalette::distributeDistValV()
00391 {
00392        if (currDoc!=NULL)
00393               distributeDistV(true);
00394 }
00395 
00396 void AlignDistributePalette::alignToChanged(int newAlignTo)
00397 {
00398        currAlignTo=(ScribusDoc::AlignTo)newAlignTo;
00399        enableGuideButtons();
00400 }
00401 
00402 void AlignDistributePalette::setGuide(int direction, double position)
00403 {
00404        //direction 0=H, 1=V
00405        guideDirection=direction;
00406        guidePosition=position;
00407        enableGuideButtons();
00408 }
00409 
00410 void AlignDistributePalette::enableGuideButtons()
00411 {
00412        QString suffix="";
00413        double unitRatio=1.0;
00414        int precision=1;
00415        if (currDoc!=NULL)
00416        {
00417               suffix=unitGetSuffixFromIndex(currDoc->unitIndex());
00418               unitRatio=unitGetRatioFromIndex(currDoc->unitIndex());
00419               precision=unitGetPrecisionFromIndex(currDoc->unitIndex());
00420        }
00421        bool setterH=true, setterV=true;
00422        switch(guideDirection)
00423        {
00424               case -1:
00425                      guideInfoText = guideInfoTextNone;
00426                      if (currAlignTo==ScribusDoc::alignGuide)
00427                             setterH=setterV=false;
00428                      break;
00429               case 0:
00430                      guideInfoText = tr("Y: %1%2").arg(guidePosition * unitRatio, 0, 'f', precision).arg(suffix);
00431                      if (currAlignTo==ScribusDoc::alignGuide)
00432                      {
00433                             setterV=false;
00434                             setterH=true;
00435                      }
00436                      break;
00437               case 1:
00438                      guideInfoText = tr("X: %1%2").arg(guidePosition * unitRatio, 0, 'f', precision).arg(suffix);
00439                      if (currAlignTo==ScribusDoc::alignGuide)
00440                      {
00441                             setterV=true;
00442                             setterH=false;
00443                      }
00444                      break;
00445        }
00446        bool setterO=true;
00447        if (currAlignTo==ScribusDoc::alignGuide)
00448               setterO=false;
00449               
00450        alignLeftInToolButton->setEnabled(setterV);
00451        alignLeftOutToolButton->setEnabled(setterO);
00452        alignRightInToolButton->setEnabled(setterV);
00453        alignRightOutToolButton->setEnabled(setterO);    
00454        alignCenterHorToolButton->setEnabled(setterV);
00455 
00456        alignTopInToolButton->setEnabled(setterH);
00457        alignTopOutToolButton->setEnabled(setterO);
00458        alignBottomInToolButton->setEnabled(setterH);
00459        alignBottomOutToolButton->setEnabled(setterO);
00460        alignCenterVerToolButton->setEnabled(setterH);
00461        
00462        alignGuideLineEdit->setText(guideInfoText);
00463 }