Back to index

scribus-ng  1.3.4.dfsg+svn20071115
tabguides.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 "tabguides.h"
00008 #include "tabguides.moc"
00009 #include <qlayout.h>
00010 #include <qgroupbox.h>
00011 #include <qbuttongroup.h>
00012 #include <qradiobutton.h>
00013 #include <qlabel.h>
00014 #include <qtooltip.h>
00015 #include <qspinbox.h>
00016 #include <qcolor.h>
00017 #include <qcolordialog.h>
00018 #include <qcheckbox.h>
00019 #include <qpushbutton.h>
00020 #include <qpixmap.h>
00021 #include "mspinbox.h"
00022 #include "prefsstructs.h"
00023 #include "scribusstructs.h"
00024 #include "units.h"
00025 
00026 TabGuides::TabGuides( QWidget* parent, struct guidesPrefs *prefsData, struct typoPrefs *prefsData2, int unitIndex) : QWidget( parent, "tabguide", 0 )
00027 {
00028        double unitRatio = unitGetRatioFromIndex(unitIndex);
00029        QString unit = unitGetSuffixFromIndex(unitIndex);
00030        int precision = unitGetPrecisionFromIndex(unitIndex);
00031 
00032        tabGuidesLayout = new QVBoxLayout( this, 0, 5, "tabViewLayout");
00033 
00034        commonBox = new QGroupBox( this, "commonBox" );
00035        commonBox->setTitle( tr( "Common Settings" ) );
00036        commonBox->setColumnLayout(0, Qt::Vertical );
00037        commonBox->layout()->setSpacing( 5 );
00038        commonBox->layout()->setMargin( 10 );
00039        commonBoxLayout = new QHBoxLayout( commonBox->layout() );
00040 
00041        buttonGroup1 = new QButtonGroup( commonBox, "buttonGroup1" );
00042        buttonGroup1->setExclusive( true );
00043        buttonGroup1->setColumnLayout(0, Qt::Horizontal );
00044        buttonGroup1->layout()->setSpacing( 5 );
00045        buttonGroup1->layout()->setMargin( 10 );
00046        buttonGroup1->setTitle( tr( "Placing in Documents" ) );
00047        buttonGroup1Layout = new QVBoxLayout( buttonGroup1->layout() );
00048        buttonGroup1Layout->setAlignment( Qt::AlignTop );
00049        inBackground = new QRadioButton( buttonGroup1, "inBackground" );
00050        inBackground->setText( tr( "In the Background" ) );
00051        buttonGroup1Layout->addWidget( inBackground );
00052        inForeground = new QRadioButton( buttonGroup1, "inForeground" );
00053        inForeground->setText( tr( "In the Foreground" ) );
00054        buttonGroup1Layout->addWidget( inForeground );
00055        commonBoxLayout->addWidget( buttonGroup1 );
00056 
00057        snapBox = new QGroupBox( commonBox, "snapBox" );
00058        snapBox->setTitle( tr( "Snapping" ) );
00059        snapBox->setColumnLayout(0, Qt::Vertical );
00060        snapBox->layout()->setSpacing( 5 );
00061        snapBox->layout()->setMargin( 10 );
00062        snapBoxLayout = new QGridLayout( snapBox->layout() );
00063        textLabel8 = new QLabel( snapBox, "textLabel8" );
00064        textLabel8->setText( tr( "Snap Distance:" ) );
00065        snapBoxLayout->addWidget( textLabel8, 0, 0 );
00066        snapDistance = new QSpinBox( snapBox, "snapDistance" );
00067        snapDistance->setMaxValue( 1000 );
00068        snapDistance->setMinValue( 1 );
00069        snapDistance->setLineStep( 1 );
00070        snapBoxLayout->addWidget( snapDistance, 0, 1 );
00071        textLabel82 = new QLabel( snapBox, "textLabel8" );
00072        textLabel82->setText( tr( "Grab Radius:" ) );
00073        snapBoxLayout->addWidget( textLabel82, 1, 0 );
00074        grabDistance = new QSpinBox( snapBox, "grabDistance" );
00075        grabDistance->setMaxValue( 1000 );
00076        grabDistance->setMinValue( 1 );
00077        grabDistance->setLineStep( 1 );
00078        snapBoxLayout->addWidget( grabDistance, 1, 1 );
00079        commonBoxLayout->addWidget( snapBox );
00080        tabGuidesLayout->addWidget( commonBox );
00081        layout9 = new QHBoxLayout( 0, 0, 5, "layout9");
00082        guideBox = new QGroupBox( this, "guideBox" );
00083        guideBox->setTitle( tr( "Show Guides" ) );
00084        guideBox->setCheckable( true );
00085        guideBox->setColumnLayout(0, Qt::Vertical );
00086        guideBox->layout()->setSpacing( 5 );
00087        guideBox->layout()->setMargin( 10 );
00088        guideBoxLayout = new QHBoxLayout( guideBox->layout() );
00089        checkGuides = new QLabel( guideBox, "checkGuides" );
00090        checkGuides->setText( tr( "Color:" ) );
00091        guideBoxLayout->addWidget( checkGuides );
00092        guideColor = new QPushButton( guideBox, "guideColor" );
00093        guideColor->setMinimumSize( QSize( 60, 20 ) );
00094        guideColor->setMaximumSize( QSize( 60, 20 ) );
00095        guideColor->setFlat( false );
00096        guideColor->setAutoDefault( false );
00097        guideColor->setText( QString::null );
00098        guideBoxLayout->addWidget( guideColor );
00099        layout9->addWidget( guideBox );
00100        marginBox = new QGroupBox( this, "guideBox" );
00101        marginBox->setCheckable( true );
00102        marginBox->setTitle( tr( "Show Margins" ) );
00103        marginBox->setColumnLayout(0, Qt::Vertical );
00104        marginBox->layout()->setSpacing( 5 );
00105        marginBox->layout()->setMargin( 10 );
00106        marginBoxLayout = new QHBoxLayout( marginBox->layout() );
00107        checkMargin = new QLabel( marginBox, "checkMargin" );
00108        checkMargin->setText( tr( "Color:" ) );
00109        marginBoxLayout->addWidget( checkMargin );
00110        marginColor = new QPushButton( marginBox, "marginColor" );
00111        marginColor->setMinimumSize( QSize( 60, 20 ) );
00112        marginColor->setMaximumSize( QSize( 60, 20 ) );
00113        marginColor->setAutoDefault( false );
00114        marginColor->setFlat( false );
00115        marginColor->setText( QString::null );
00116        marginBoxLayout->addWidget( marginColor );
00117        layout9->addWidget( marginBox );
00118        tabGuidesLayout->addLayout( layout9 );
00119 
00120        checkGrid = new QGroupBox( this, "checkGrid" );
00121        checkGrid->setTitle( tr( "Show Page Grid" ) );
00122        checkGrid->setCheckable( true );
00123        checkGrid->setColumnLayout(0, Qt::Vertical );
00124        checkGrid->layout()->setSpacing( 5 );
00125        checkGrid->layout()->setMargin( 10 );
00126        checkGridLayout = new QGridLayout( checkGrid->layout() );
00127        checkGridLayout->setAlignment( Qt::AlignTop );
00128        groupBox1 = new QGroupBox( checkGrid, "groupBox1" );
00129        groupBox1->setColumnLayout(0, Qt::Vertical );
00130        groupBox1->layout()->setSpacing( 5 );
00131        groupBox1->layout()->setMargin( 10 );
00132        groupBox1->setTitle( tr( "Major Grid" ) );
00133        groupBox1Layout = new QGridLayout( groupBox1->layout() );
00134        groupBox1Layout->setAlignment( Qt::AlignTop );
00135        majorGridColor = new QPushButton( groupBox1, "majorGridColor" );
00136        majorGridColor->setMinimumSize( QSize( 60, 20 ) );
00137        majorGridColor->setMaximumSize( QSize( 60, 20 ) );
00138        majorGridColor->setFlat( false );
00139        majorGridColor->setAutoDefault( false );
00140        majorGridColor->setText( QString::null );
00141        groupBox1Layout->addWidget( majorGridColor, 1, 1 );
00142        textLabel4 = new QLabel( groupBox1, "textLabel4" );
00143        textLabel4->setText( tr( "Color:" ) );
00144        groupBox1Layout->addWidget( textLabel4, 1, 0 );
00145        textLabel6 = new QLabel( groupBox1, "textLabel6" );
00146        textLabel6->setText( tr( "Spacing:" ) );
00147        groupBox1Layout->addWidget( textLabel6, 0, 0 );
00148        majorSpace = new MSpinBox( 10 * unitRatio, 1000 * unitRatio, groupBox1, precision );
00149        groupBox1Layout->addWidget( majorSpace, 0, 1 );
00150        checkGridLayout->addWidget( groupBox1, 0, 0 );
00151        groupBox2 = new QGroupBox( checkGrid, "groupBox2" );
00152        groupBox2->setColumnLayout(0, Qt::Vertical );
00153        groupBox2->layout()->setSpacing( 5 );
00154        groupBox2->layout()->setMargin( 10 );
00155        groupBox2->setTitle( tr( "Minor Grid" ) );
00156        groupBox2Layout = new QGridLayout( groupBox2->layout() );
00157        groupBox2Layout->setAlignment( Qt::AlignTop );
00158        textLabel5 = new QLabel( groupBox2, "textLabel5" );
00159        textLabel5->setText( tr( "Color:" ) );
00160        groupBox2Layout->addWidget( textLabel5, 1, 0 );
00161        minorGridColor = new QPushButton( groupBox2, "minorGridColor" );
00162        minorGridColor->setMinimumSize( QSize( 60, 20 ) );
00163        minorGridColor->setMaximumSize( QSize( 60, 20 ) );
00164        minorGridColor->setFlat( false );
00165        minorGridColor->setAutoDefault( false );
00166        minorGridColor->setText( QString::null );
00167        groupBox2Layout->addWidget( minorGridColor, 1, 1 );
00168        textLabel7 = new QLabel( groupBox2, "textLabel7" );
00169        textLabel7->setText( tr( "Spacing:" ) );
00170        groupBox2Layout->addWidget( textLabel7, 0, 0 );
00171        minorSpace = new MSpinBox( unitRatio, 1000 * unitRatio, groupBox2, precision );
00172        groupBox2Layout->addWidget( minorSpace, 0, 1 );
00173        checkGridLayout->addWidget( groupBox2, 0, 1 );
00174        tabGuidesLayout->addWidget( checkGrid );
00175 
00176        layout9a = new QHBoxLayout( 0, 0, 5, "layout9");
00177        baselineBox = new QGroupBox( this, "baselineBox" );
00178        baselineBox->setTitle( tr( "Show Baseline Grid" ) );
00179        baselineBox->setCheckable( true );
00180        baselineBox->setColumnLayout(0, Qt::Vertical );
00181        baselineBox->layout()->setSpacing( 5 );
00182        baselineBox->layout()->setMargin( 10 );
00183        baselineBoxLayout = new QGridLayout( baselineBox->layout() );
00184        baselineBoxLayout->setAlignment( Qt::AlignTop );
00185        checkBaseline = new QLabel( baselineBox, "checkBaseline" );
00186        checkBaseline->setText( tr( "Color:" ) );
00187        baselineBoxLayout->addWidget( checkBaseline, 0, 0 );
00188        baselineColor = new QPushButton( baselineBox, "baselineColor" );
00189        baselineColor->setMinimumSize( QSize( 60, 20 ) );
00190        baselineColor->setMaximumSize( QSize( 60, 20 ) );
00191        baselineColor->setFlat( false );
00192        baselineColor->setAutoDefault( false );
00193        baselineColor->setText( QString::null );
00194        baselineBoxLayout->addWidget( baselineColor, 0, 1 );
00195        layout9a->addWidget( baselineBox );
00196 
00197        baseGridBox = new QGroupBox( this, "baseGridBox" );
00198        baseGridBox->setTitle( tr( "Baseline Settings" ) );
00199        baseGridBox->setColumnLayout(0, Qt::Vertical );
00200        baseGridBox->layout()->setSpacing( 5 );
00201        baseGridBox->layout()->setMargin( 10 );
00202        baseGridBoxLayout = new QGridLayout( baseGridBox->layout() );
00203        baseGridBoxLayout->setAlignment( Qt::AlignTop );
00204        baseGrid = new MSpinBox( baseGridBox, precision );
00205        baseGrid->setMaxValue(1000);
00206        baseGrid->setMinValue(pts2value(1.0, unitIndex));
00207        baseGridBoxLayout->addWidget( baseGrid, 0, 1 );
00208        textLabel6a = new QLabel(baseGrid, tr( "Baseline &Grid:" ), baseGridBox, "textLabel6a" );
00209        baseGridBoxLayout->addWidget( textLabel6a, 0, 0 );
00210        baseOffset = new MSpinBox( 0, 1000, baseGridBox, precision );
00211        baseGridBoxLayout->addWidget( baseOffset, 1, 1 );
00212        textLabel7a = new QLabel(baseOffset, tr( "Baseline &Offset:" ), baseGridBox, "textLabel7a" );
00213        baseGridBoxLayout->addWidget( textLabel7a, 1, 0 );
00214        layout9a->addWidget( baseGridBox );
00215        tabGuidesLayout->addLayout( layout9a );
00216 
00217        // switched off as it's called in main prefs classes - PV
00218        //restoreDefaults(prefsData, prefsData2, unitIndex);
00219 
00220        connect(majorGridColor, SIGNAL(clicked()), this, SLOT(changeMajorColor()));
00221        connect(minorGridColor, SIGNAL(clicked()), this, SLOT(changeMinorColor()));
00222        connect(baselineColor, SIGNAL(clicked()), this, SLOT(changeBaselineColor()));
00223        connect(guideColor, SIGNAL(clicked()), this, SLOT(changeGuideColor()));
00224        connect(marginColor, SIGNAL(clicked()), this, SLOT(changeMarginColor()));
00225        QToolTip::add( inBackground, tr( "Guides are not visible through objects on the page" ) );
00226        QToolTip::add( inForeground, tr( "Guides are visible above all objects on the page" ) );
00227        QToolTip::add( minorSpace, tr( "Distance between the minor grid lines" ) );
00228        QToolTip::add( majorSpace, tr( "Distance between the major grid lines" ) );
00229        QToolTip::add( snapDistance, tr( "Distance within which an object will snap to your placed guides" ) );
00230        QToolTip::add( grabDistance, tr( "Radius of the area where Scribus will allow you to grab an objects handles" ) );
00231        QToolTip::add( minorGridColor, tr( "Color of the minor grid lines" ) );
00232        QToolTip::add( majorGridColor, tr( "Color of the major grid lines" ) );
00233        QToolTip::add( guideColor, tr( "Color of the guide lines you insert" ) );
00234        QToolTip::add( marginColor, tr( "Color for the margin lines" ) );
00235        QToolTip::add( baselineColor, tr( "Color for the baseline grid" ) );
00236        QToolTip::add( baselineBox, tr("Turns the basegrid on or off"));
00237        QToolTip::add( baseGrid, tr("Distance between the lines of the baseline grid"));
00238        QToolTip::add( baseOffset, tr("Distance from the top of the page for the first baseline"));
00239        QToolTip::add( checkGrid, tr("Turns the gridlines on or off"));
00240        QToolTip::add( guideBox, tr("Turns the guides on or off"));
00241        QToolTip::add( marginBox, tr("Turns the margins on or off"));
00242 }
00243 
00244 void TabGuides::restoreDefaults(struct guidesPrefs *prefsData, struct typoPrefs *prefsData2, int unitIndex)
00245 {
00246        QString unit = unitGetSuffixFromIndex(unitIndex);
00247        double unitRatio = unitGetRatioFromIndex(unitIndex);
00248 
00249        QPixmap pm3(54, 14);
00250        pm3.fill(prefsData->guideColor);
00251        colorGuides = prefsData->guideColor;
00252        guideColor->setPixmap(pm3);
00253        QPixmap pm6(54, 14);
00254        pm6.fill(prefsData->margColor);
00255        colorMargin = prefsData->margColor;
00256        marginColor->setPixmap(pm6);
00257        QPixmap pm1(54, 14);
00258        pm1.fill(prefsData->majorColor);
00259        colorMajorGrid = prefsData->majorColor;
00260        majorGridColor->setPixmap(pm1);
00261        QPixmap pm(54, 14);
00262        pm.fill(prefsData->minorColor);
00263        colorMinorGrid = prefsData->minorColor;
00264        minorGridColor->setPixmap(pm);
00265        QPixmap pm4(54, 14);
00266        pm4.fill(prefsData->baseColor);
00267        colorBaselineGrid = prefsData->baseColor;
00268        baselineColor->setPixmap(pm4);
00269        minorSpace->setValue(prefsData->minorGrid  * unitRatio);
00270        minorSpace->setSuffix( unit );
00271        majorSpace->setValue(prefsData->majorGrid * unitRatio);
00272        majorSpace->setSuffix( unit );
00273        snapDistance->setValue(qRound(prefsData->guideRad));
00274        snapDistance->setSuffix( " " + tr( "px" ) );
00275        grabDistance->setValue(prefsData->grabRad);
00276        grabDistance->setSuffix( " " + tr( " px" ) );
00277        baseGrid->setValue(prefsData2->valueBaseGrid * unitRatio);
00278        baseGrid->setSuffix( unit );
00279        baseOffset->setValue(prefsData2->offsetBaseGrid * unitRatio);
00280        baseOffset->setSuffix( unit );
00281        inBackground->setChecked( prefsData->before );
00282        inForeground->setChecked( !prefsData->before );
00283        baselineBox->setChecked(prefsData->baseShown);
00284        checkGrid->setChecked(prefsData->gridShown);
00285        marginBox->setChecked(prefsData->marginsShown);
00286        guideBox->setChecked(prefsData->guidesShown);
00287 }
00288 
00289 void TabGuides::changeMajorColor()
00290 {
00291        QColor neu = QColor();
00292        neu = QColorDialog::getColor(colorMajorGrid, this);
00293        if (neu.isValid())
00294        {
00295               QPixmap pm(54, 14);
00296               pm.fill(neu);
00297               colorMajorGrid = neu;
00298               majorGridColor->setPixmap(pm);
00299        }
00300 }
00301 
00302 void TabGuides::changeMinorColor()
00303 {
00304        QColor neu = QColor();
00305        neu = QColorDialog::getColor(colorMinorGrid, this);
00306        if (neu.isValid())
00307        {
00308               QPixmap pm(54, 14);
00309               pm.fill(neu);
00310               colorMinorGrid = neu;
00311               minorGridColor->setPixmap(pm);
00312        }
00313 }
00314 
00315 void TabGuides::changeBaselineColor()
00316 {
00317        QColor neu = QColor();
00318        neu = QColorDialog::getColor(colorBaselineGrid, this);
00319        if (neu.isValid())
00320        {
00321               QPixmap pm(54, 14);
00322               pm.fill(neu);
00323               colorBaselineGrid = neu;
00324               baselineColor->setPixmap(pm);
00325        }
00326 }
00327 
00328 void TabGuides::changeGuideColor()
00329 {
00330        QColor neu = QColor();
00331        neu = QColorDialog::getColor(colorGuides, this);
00332        if (neu.isValid())
00333        {
00334               QPixmap pm(54, 14);
00335               pm.fill(neu);
00336               colorGuides = neu;
00337               guideColor->setPixmap(pm);
00338        }
00339 }
00340 
00341 void TabGuides::changeMarginColor()
00342 {
00343        QColor neu = QColor();
00344        neu = QColorDialog::getColor(colorMargin, this);
00345        if (neu.isValid())
00346        {
00347               QPixmap pm(54, 14);
00348               pm.fill(neu);
00349               colorMargin = neu;
00350               marginColor->setPixmap(pm);
00351        }
00352 }
00353 
00354 void TabGuides::unitChange(QString unit, int docUnitIndex, int decimals, double invUnitConversion)
00355 {
00356        double oldMin, oldMax, val;
00357        int decimalsOld;
00358 
00359        minorSpace->setSuffix(unit);
00360        majorSpace->setSuffix(unit);
00361        baseGrid->setSuffix(unit);
00362        baseOffset->setSuffix(unit);
00363        
00364        minorSpace->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00365        minorSpace->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00366        majorSpace->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00367        majorSpace->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00368        baseGrid->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00369        baseGrid->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00370        baseOffset->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00371        baseOffset->setValues(oldMin * invUnitConversion, oldMax * invUnitConversion, decimals, val * invUnitConversion);
00372 }