Back to index

scribus-ng  1.3.4.dfsg+svn20071115
tabdisplay.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 #include <qpushbutton.h>
00008 #include <qcheckbox.h>
00009 #include <qlabel.h>
00010 #include <qslider.h>
00011 #include <qtooltip.h>
00012 #include <qgroupbox.h>
00013 #include <qcolordialog.h>
00014 #include <qpainter.h>
00015 
00016 #include "tabdisplay.h"
00017 #include "tabdisplay.moc"
00018 #include "mspinbox.h"
00019 #include "prefsmanager.h"
00020 #include "units.h"
00021 
00022 
00023 TabDisplay::TabDisplay(QWidget* parent, const char* name)
00024        : TabDisplayBase(parent, name, 0)
00025 {
00026        QToolTip::add( backColor, "<qt>" + tr( "Color for paper" ) + "</qt>");
00027        QToolTip::add( checkUnprintable, "<qt>" + tr( "Mask the area outside the margins in the margin color" ) + "</qt>" );
00028        QToolTip::add( checkLink, "<qt>" + tr("Enable or disable  the display of linked frames.") + "</qt>");
00029        QToolTip::add( checkControl, "<qt>" + tr("Display non-printing characters such as paragraph markers in text frames") + "</qt>");
00030        QToolTip::add( checkFrame, "<qt>" + tr("Turns the display of frames on or off") + "</qt>");
00031        QToolTip::add( checkLayerM, "<qt>" + tr("Turns the display of layer indicators on or off") + "</qt>");
00032        QToolTip::add( checkPictures, "<qt>" + tr("Turns the display of pictures on or off") + "</qt>");
00033        QToolTip::add( leftScratch, "<qt>" + tr( "Defines amount of space left of the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00034        QToolTip::add( rightScratch, "<qt>" + tr( "Defines amount of space right of the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00035        QToolTip::add( topScratch, "<qt>" + tr( "Defines amount of space above the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00036        QToolTip::add( bottomScratch, "<qt>" + tr( "Defines amount of space below the document canvas available as a pasteboard for creating and modifying elements and dragging them onto the active page" ) + "</qt>" );
00037        QToolTip::add( CaliText, "<qt>" + tr( "Set the default zoom level" )  + "</qt>");
00038        QToolTip::add( CaliGroup, "<qt>" + tr( "Place a ruler against your screen and drag the slider to set the zoom level so Scribus will display your pages and objects on them at the correct size" ) + "</qt>" );
00039 
00040        connect(backColor, SIGNAL(clicked()), this, SLOT(changePaperColor()));
00041        connect(buttonFrameSelected, SIGNAL(clicked()), this, SLOT(changeFrameColor()));
00042        connect(buttonFrameNormal, SIGNAL(clicked()), this, SLOT(changeNormFrameColor()));
00043        connect(buttonFrameGrouped, SIGNAL(clicked()), this, SLOT(changeGroupFrameColor()));
00044        connect(buttonFrameLinked, SIGNAL(clicked()), this, SLOT(changeChainFrameColor()));
00045        connect(buttonFrameLocked, SIGNAL(clicked()), this, SLOT(changeLockFrameColor()));
00046        connect(buttonFrameAnnotation, SIGNAL(clicked()), this, SLOT(changeAnnotFrameColor()));
00047        connect(buttonSelectedPage, SIGNAL(clicked()), this, SLOT(changePageBorderColor()));
00048        connect(buttonControlChars, SIGNAL(clicked()), this, SLOT(changeControlCharsColor()));
00049 
00050        connect(CaliSlider, SIGNAL(valueChanged(int)), this, SLOT(setDisScale()));
00051 }
00052 
00053 void TabDisplay::restoreDefaults(struct ApplicationPrefs *prefsData, struct guidesPrefs &guidesSettings, QValueList<PageSet> &pageSets, int pageLayout, MarginStruct &scratch)
00054 {
00055        docUnitIndex = prefsData->docUnitIndex;
00056        double unitRatio = unitGetRatioFromIndex(docUnitIndex);
00057 
00058        DisScale = prefsData->DisScale;
00059        int decimals = unitGetDecimalsFromIndex(docUnitIndex);
00060        QString unitSuffix = unitGetSuffixFromIndex(docUnitIndex);
00061        QPixmap pm(54, 14);
00062        pm.fill(prefsData->DpapColor);
00063        colorPaper = prefsData->DpapColor;
00064        backColor->setPixmap(pm);
00065        backColor->setText( QString::null );
00066        pm.fill(prefsData->DFrameColor);
00067        colorFrame = prefsData->DFrameColor;
00068        buttonFrameSelected->setText( QString::null );
00069        buttonFrameSelected->setPixmap(pm);
00070        pm.fill(prefsData->DFrameNormColor);
00071        colorFrameNorm = prefsData->DFrameNormColor;
00072        buttonFrameNormal->setText( QString::null );
00073        buttonFrameNormal->setPixmap(pm);
00074        pm.fill(prefsData->DFrameGroupColor);
00075        colorFrameGroup = prefsData->DFrameGroupColor;
00076        buttonFrameGrouped->setText( QString::null );
00077        buttonFrameGrouped->setPixmap(pm);
00078        pm.fill(prefsData->DFrameLinkColor);
00079        colorFrameLinked = prefsData->DFrameLinkColor;
00080        buttonFrameLinked->setText( QString::null );
00081        buttonFrameLinked->setPixmap(pm);
00082        pm.fill(prefsData->DFrameLockColor);
00083        colorFrameLocked = prefsData->DFrameLockColor;
00084        buttonFrameLocked->setText( QString::null );
00085        buttonFrameLocked->setPixmap(pm);
00086        pm.fill(prefsData->DFrameAnnotationColor);
00087        colorFrameAnnotation = prefsData->DFrameAnnotationColor;
00088        buttonFrameAnnotation->setText( QString::null );
00089        buttonFrameAnnotation->setPixmap(pm);
00090        pm.fill(prefsData->DPageBorderColor);
00091        colorPageBorder = prefsData->DPageBorderColor;
00092        buttonSelectedPage->setText( QString::null );
00093        buttonSelectedPage->setPixmap(pm);
00094        pm.fill(prefsData->DControlCharColor);
00095        colorControlChars = prefsData->DControlCharColor;
00096        buttonControlChars->setText( QString::null );
00097        buttonControlChars->setPixmap(pm);
00098 
00099        checkUnprintable->setChecked( prefsData->marginColored );
00100        checkPictures->setChecked(guidesSettings.showPic);
00101        checkLink->setChecked(guidesSettings.linkShown);
00102        checkControl->setChecked(guidesSettings.showControls);
00103        checkFrame->setChecked(guidesSettings.framesShown);
00104        checkLayerM->setChecked(guidesSettings.layerMarkersShown);
00105        checkRuler->setChecked(guidesSettings.rulerMode);
00106        checkBleed->setChecked(guidesSettings.showBleed);
00107        topScratch->setDecimals( decimals );
00108        topScratch->setMaxValue(1000);
00109        topScratch->setValue(scratch.Top * unitRatio);
00110        leftScratch->setDecimals( decimals );
00111        leftScratch->setMaxValue(1000);
00112        leftScratch->setValue(scratch.Left * unitRatio);
00113        bottomScratch->setDecimals( decimals );
00114        bottomScratch->setMaxValue(10000);
00115        bottomScratch->setValue(scratch.Bottom * unitRatio);
00116        rightScratch->setDecimals( decimals );
00117        rightScratch->setMaxValue(1000);
00118        rightScratch->setValue(scratch.Right * unitRatio);
00119        topScratch->setSuffix(unitSuffix);
00120        bottomScratch->setSuffix(unitSuffix);
00121        leftScratch->setSuffix(unitSuffix);
00122        rightScratch->setSuffix(unitSuffix);
00123        gapHorizontal->setSuffix( unitSuffix );
00124        gapHorizontal->setDecimals( decimals );
00125        gapHorizontal->setMaxValue(1000);
00126        gapHorizontal->setValue(pageSets[pageLayout].GapHorizontal * unitRatio);
00127        gapVertical->setSuffix( unitSuffix );
00128        gapVertical->setDecimals( decimals );
00129        gapVertical->setMaxValue(1000);
00130        gapVertical->setValue(pageSets[pageLayout].GapBelow * unitRatio);
00131        drawRuler();
00132        CaliSlider->setValue(qRound(100 * DisScale) - 150);
00133        CaliAnz->setText(QString::number(DisScale*100, 'f', 2)+" %");
00134 }
00135 
00136 void TabDisplay::unitChange(QString unit, int docUnitIx, int decimals, double invUnitConversion)
00137 {
00138        double oldMin, oldMax, val;
00139        int decimalsOld;
00140        docUnitIndex = docUnitIx;
00141 
00142        topScratch->setSuffix(unit);
00143        bottomScratch->setSuffix(unit);
00144        leftScratch->setSuffix(unit);
00145        rightScratch->setSuffix(unit);
00146        gapVertical->setSuffix( unit );
00147        gapHorizontal->setSuffix( unit );
00148 
00149        topScratch->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00150        topScratch->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00151        bottomScratch->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00152        bottomScratch->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00153        leftScratch->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00154        leftScratch->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00155        rightScratch->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00156        rightScratch->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00157        gapVertical->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00158        gapVertical->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00159        gapHorizontal->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00160        gapHorizontal->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00161        drawRuler();
00162 }
00163 
00164 void TabDisplay::changePaperColor()
00165 {
00166        QColor neu = QColor();
00167        neu = QColorDialog::getColor(colorPaper, this);
00168        if (neu.isValid())
00169        {
00170               QPixmap pm(54, 14);
00171               pm.fill(neu);
00172               colorPaper = neu;
00173               backColor->setPixmap(pm);
00174        }
00175 }
00176 
00177 void TabDisplay::setPaperColor(QColor neu)
00178 {
00179        if (neu.isValid())
00180        {
00181               QPixmap pm(54, 14);
00182               pm.fill(neu);
00183               colorPaper = neu;
00184               backColor->setPixmap(pm);
00185        }
00186 }
00187 
00188 void TabDisplay::setDisScale()
00189 {
00190        DisScale = QMAX((150.0 + CaliSlider->value()) / 100.0, 0.01);
00191        drawRuler();
00192        CaliAnz->setText(QString::number(DisScale*100, 'f', 2)+" %");
00193 }
00194 
00195 void TabDisplay::drawRuler()
00196 {
00197        double xl, iter, iter2, maxi;
00198        switch (docUnitIndex)
00199        {
00200               case 0:
00201                      iter = 10.0;
00202                      iter2 = iter * 10.0;
00203                      maxi = 200.0;
00204                      break;
00205               case 1:
00206                      iter = (10.0 / 25.4) * 72.0;
00207                      iter2 = iter * 10.0;
00208                      maxi = iter2;
00209                      break;
00210               case 2:
00211                      iter = 18.0;
00212                      iter2 = 72.0;
00213                      maxi = 2 * iter2;
00214                      break;
00215               case 3:
00216                      iter = 12.0;
00217                      iter2 = 120.0;
00218                      maxi = 240.0;
00219                      break;
00220               case 4:
00221                      iter = 12.0;
00222                      iter2 = 120.0;
00223                      maxi = 240.0;
00224                      break;
00225               default:
00226                      iter = 10.0;
00227                      iter2 = iter * 10.0;
00228                      maxi = 200.0;
00229                      break;
00230        }
00231 
00232        QPixmap pm(qRound(maxi*DisScale+30), 21);
00233        pm.fill();
00234        QPainter p;
00235        p.begin(&pm);
00236        p.drawLine(0, 19, width(), 19);
00237        p.setBrush(black);
00238        p.setPen(black);
00239        p.scale(DisScale, 1.0);
00240        for (xl = 0; xl < maxi; xl += iter)
00241               p.drawLine(static_cast<int>(xl), 13, static_cast<int>(xl), 19);
00242        for (xl = 0; xl < maxi+10; xl += iter2)
00243        {
00244               p.drawLine(static_cast<int>(xl), 6, static_cast<int>(xl), 19);
00245               p.save();
00246               p.scale(1.0 / DisScale, 1.0);
00247               switch (docUnitIndex)
00248               {
00249                      case 2:
00250                             p.drawText(static_cast<int>((xl+qRound(2/DisScale)) * DisScale), 12,
00251                                              QString::number(xl / iter2));
00252                             break;
00253                      case 3:
00254                             p.drawText(static_cast<int>((xl+qRound(2/DisScale)) * DisScale), 12,
00255                                              QString::number(xl / iter));
00256                             break;
00257                      default:
00258                             p.drawText(static_cast<int>((xl+qRound(2/DisScale)) * DisScale), 12,
00259                                              QString::number(xl / iter * 10));
00260                             break;
00261               }
00262               p.restore();
00263        }
00264        p.end();
00265        CaliRuler->setPixmap(pm);
00266 }
00267 
00268 void TabDisplay::setDocSetupMode()
00269 {
00270        CaliGroup->hide();
00271        selectedPageBorderLabel->hide();
00272        buttonSelectedPage->hide();
00273        groupObjFrame->hide();
00274        textColorGroup->hide();
00275 }
00276 
00277 void TabDisplay::changeFrameColor()
00278 {
00279        QColor neu = QColor();
00280        neu = QColorDialog::getColor(colorFrame, this);
00281        if (neu.isValid())
00282        {
00283               QPixmap pm(54, 14);
00284               pm.fill(neu);
00285               colorFrame = neu;
00286               buttonFrameSelected->setPixmap(pm);
00287        }
00288 }
00289 
00290 void TabDisplay::changeNormFrameColor()
00291 {
00292        QColor neu = QColor();
00293        neu = QColorDialog::getColor(colorFrameNorm, this);
00294        if (neu.isValid())
00295        {
00296               QPixmap pm(54, 14);
00297               pm.fill(neu);
00298               colorFrameNorm = neu;
00299               buttonFrameNormal->setPixmap(pm);
00300        }
00301 }
00302 
00303 void TabDisplay::changeGroupFrameColor()
00304 {
00305        QColor neu = QColor();
00306        neu = QColorDialog::getColor(colorFrameGroup, this);
00307        if (neu.isValid())
00308        {
00309               QPixmap pm(54, 14);
00310               pm.fill(neu);
00311               colorFrameGroup = neu;
00312               buttonFrameGrouped->setPixmap(pm);
00313        }
00314 }
00315 
00316 void TabDisplay::changeChainFrameColor()
00317 {
00318        QColor neu = QColor();
00319        neu = QColorDialog::getColor(colorFrameLinked, this);
00320        if (neu.isValid())
00321        {
00322               QPixmap pm(54, 14);
00323               pm.fill(neu);
00324               colorFrameLinked = neu;
00325               buttonFrameLinked->setPixmap(pm);
00326        }
00327 }
00328 
00329 void TabDisplay::changeLockFrameColor()
00330 {
00331        QColor neu = QColor();
00332        neu = QColorDialog::getColor(colorFrameLocked, this);
00333        if (neu.isValid())
00334        {
00335               QPixmap pm(54, 14);
00336               pm.fill(neu);
00337               colorFrameLocked = neu;
00338               buttonFrameLocked->setPixmap(pm);
00339        }
00340 }
00341 
00342 void TabDisplay::changeAnnotFrameColor()
00343 {
00344        QColor neu = QColor();
00345        neu = QColorDialog::getColor(colorFrameAnnotation, this);
00346        if (neu.isValid())
00347        {
00348               QPixmap pm(54, 14);
00349               pm.fill(neu);
00350               colorFrameAnnotation = neu;
00351               buttonFrameAnnotation->setPixmap(pm);
00352        }
00353 }
00354 
00355 void TabDisplay::changePageBorderColor()
00356 {
00357        QColor neu = QColor();
00358        neu = QColorDialog::getColor(colorPageBorder, this);
00359        if (neu.isValid())
00360        {
00361               QPixmap pm(54, 14);
00362               pm.fill(neu);
00363               colorPageBorder = neu;
00364               buttonSelectedPage->setPixmap(pm);
00365        }
00366 }
00367 
00368 void TabDisplay::changeControlCharsColor()
00369 {
00370        QColor neu = QColor();
00371        neu = QColorDialog::getColor(colorControlChars, this);
00372        if (neu.isValid())
00373        {
00374               QPixmap pm(54, 14);
00375               pm.fill(neu);
00376               colorControlChars = neu;
00377               buttonControlChars->setPixmap(pm);
00378        }
00379 }