Back to index

scribus-ng  1.3.4.dfsg+svn20071115
measurements.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 "measurements.h"
00008 #include "measurements.moc"
00009 
00010 #include <qvariant.h>
00011 #include <qlabel.h>
00012 #include <qlayout.h>
00013 #include <qtooltip.h>
00014 #include <qwhatsthis.h>
00015 #include <qpixmap.h>
00016 #include <cmath>
00017 #include "units.h"
00018 
00019 using namespace std;
00020 
00021 
00022 Measurements::Measurements( QWidget* parent ) : ScrPaletteBase( parent, "MeasurementsPalette", false, 0 )
00023 {
00024        measurementsLayout = new QGridLayout( this, 1, 1, 10, 6, "measurementsLayout");
00025        x1Label = new QLabel( this, "x1Label" );
00026        y1Label = new QLabel( this, "y1Label" );
00027        x2Label = new QLabel( this, "x2Label" );
00028        y2Label = new QLabel( this, "y2Label" );
00029        dxLabel = new QLabel( this, "dxLabel" );
00030        dyLabel = new QLabel( this, "dyLabel" );
00031        angleLabel = new QLabel( this, "dxLabel" );
00032        lengthLabel = new QLabel( this, "dyLabel" );
00033        measurementsLayout->addWidget( x1Label, 0, 0 );
00034        measurementsLayout->addWidget( y1Label, 1, 0 );
00035        measurementsLayout->addWidget( x2Label, 2, 0 );
00036        measurementsLayout->addWidget( y2Label, 3, 0 );
00037        measurementsLayout->addWidget( dxLabel, 4, 0 );
00038        measurementsLayout->addWidget( dyLabel, 5, 0 );
00039        measurementsLayout->addWidget( angleLabel, 6, 0 );
00040        measurementsLayout->addWidget( lengthLabel, 7, 0 );
00041 
00042        x1Data = new QLabel( "", this, "x1Data" );
00043        y1Data = new QLabel( "", this, "y1Data" );
00044        x2Data = new QLabel( "", this, "x2Data" );
00045        y2Data = new QLabel( "", this, "y2Data" );
00046        dXData = new QLabel( "", this, "dxData" );
00047        dYData = new QLabel( "", this, "dyData" );
00048        angleData = new QLabel( "", this, "angleData" );
00049        lengthData = new QLabel( "", this, "lengthData" );
00050        
00051        const QString widthString="10000.00 " + tr( "pt" );
00052        int textWidth=fontMetrics().width(widthString);
00053        x1Data->setMinimumSize(textWidth, 12);
00054        y1Data->setMinimumSize(textWidth, 12);
00055        x2Data->setMinimumSize(textWidth, 12);
00056        y2Data->setMinimumSize(textWidth, 12);
00057        dXData->setMinimumSize(textWidth, 12);
00058        dYData->setMinimumSize(textWidth, 12);
00059        angleData->setMinimumSize(textWidth, 12);
00060        lengthData->setMinimumSize(textWidth, 12);
00061 
00062        int labelAlignment=int( QLabel::AlignVCenter | QLabel::AlignRight );
00063        x1Data->setAlignment( labelAlignment );
00064        y1Data->setAlignment( labelAlignment );
00065        x2Data->setAlignment( labelAlignment );
00066        y2Data->setAlignment( labelAlignment );
00067        dXData->setAlignment( labelAlignment );
00068        dYData->setAlignment( labelAlignment );
00069        angleData->setAlignment( labelAlignment );
00070        lengthData->setAlignment( labelAlignment );
00071 
00072        measurementsLayout->addWidget( x1Data, 0, 1 );
00073        measurementsLayout->addWidget( y1Data, 1, 1 );
00074        measurementsLayout->addWidget( x2Data, 2, 1 );
00075        measurementsLayout->addWidget( y2Data, 3, 1 );
00076        measurementsLayout->addWidget( dXData, 4, 1 );
00077        measurementsLayout->addWidget( dYData, 5, 1 );
00078        measurementsLayout->addWidget( angleData, 6, 1 );
00079        measurementsLayout->addWidget( lengthData, 7, 1 );
00080 
00081        languageChange();
00082 
00083 }
00084 /*
00085 void Measurements::closeEvent(QCloseEvent *ce)
00086 {
00087        emit Schliessen(false);
00088        ce->accept();
00089 }
00090 */
00091 void Measurements::setValues(double x1, double y1, double x2, double y2, double angle, double len, int unitIndex)
00092 {
00093        QString tmp;
00094        QString unitSuffix = unitGetSuffixFromIndex(unitIndex);
00095        int multiplier = unitGetDecimalsFromIndex(unitIndex);
00096        double divisor = static_cast<double>(multiplier);
00097        int precision = unitGetPrecisionFromIndex(unitIndex);
00098 
00099        double rr = angle;
00100        if (angle < 0)
00101               rr = rr + 360;
00102 
00103        double uXm =  unitGetRatioFromIndex(unitIndex) * multiplier;
00104 
00105        x1Data->setText(tmp.setNum(qRound(x1*uXm) / divisor, 'f', precision)+unitSuffix);
00106        y1Data->setText(tmp.setNum(qRound(y1*uXm) / divisor, 'f', precision)+unitSuffix);
00107        x2Data->setText(tmp.setNum(qRound(x2*uXm) / divisor, 'f', precision)+unitSuffix);
00108        y2Data->setText(tmp.setNum(qRound(y2*uXm) / divisor, 'f', precision)+unitSuffix);
00109        dXData->setText(tmp.setNum(qRound((x2-x1)*uXm) / divisor, 'f', precision)+unitSuffix);
00110        dYData->setText(tmp.setNum(qRound((y2-y1)*uXm) / divisor, 'f', precision)+unitSuffix);
00111        angleData->setText(tmp.setNum(fabs(rr), 'f', precision)+ tr(QString::fromUtf8(" °")));
00112        lengthData->setText(tmp.setNum(qRound(len*uXm) / divisor, 'f', precision)+unitSuffix);
00113 }
00114 
00115 void Measurements::languageChange()
00116 {
00117        setCaption( tr( "Distances" ) );
00118        
00119        x1Label->setText( tr( "X1:" ) );
00120        y1Label->setText( tr( "Y1:" ) );
00121        x2Label->setText( tr( "X2:" ) );
00122        y2Label->setText( tr( "Y2:" ) );
00123        dxLabel->setText( tr( "DX:" ) );
00124        dyLabel->setText( tr( "DY:" ) );
00125        angleLabel->setText( tr( "Angle:" ) );
00126        lengthLabel->setText( tr( "Length:" ) );
00127 
00128        resize(minimumSizeHint());
00129 }
00130