Subversion Repositories Scribus

Rev

Rev 20936 | Rev 22603 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
21212 jghali 7
 
8
#include <cmath>
9
 
284 Franz 10
#include "measurements.h"
21212 jghali 11
#include "scribusdoc.h"
12
#include "scribusview.h"
793 cbradney 13
#include "units.h"
284 Franz 14
 
504 cbradney 15
using namespace std;
16
 
284 Franz 17
 
1525 cbradney 18
Measurements::Measurements( QWidget* parent ) : ScrPaletteBase( parent, "MeasurementsPalette", false, 0 )
284 Franz 19
{
12438 fschmid 20
        setupUi(this);
20904 jghali 21
 
22
        mX1 = mY1 = 0;
23
        mX2 = mY2 = 0;
24
        mDX = mDY = 0;
25
        mLength = 0;
26
 
12438 fschmid 27
        const QString widthString="10000.0000";
9879 fschmid 28
        int textWidth = fontMetrics().width(widthString);
1525 cbradney 29
        x1Data->setMinimumSize(textWidth, 12);
30
        y1Data->setMinimumSize(textWidth, 12);
31
        x2Data->setMinimumSize(textWidth, 12);
32
        y2Data->setMinimumSize(textWidth, 12);
33
        dXData->setMinimumSize(textWidth, 12);
34
        dYData->setMinimumSize(textWidth, 12);
35
        angleData->setMinimumSize(textWidth, 12);
36
        lengthData->setMinimumSize(textWidth, 12);
12438 fschmid 37
        int maxUindex = unitGetMaxIndex() - 2;
38
        textWidth = fontMetrics().width("mmm")+12;
39
        for (int i = 0; i <= maxUindex; ++i)
12753 fschmid 40
                unitSwitch->addItem(unitGetStrFromIndex(i));
18015 jghali 41
        int minHeight = unitSwitch->minimumSizeHint().height();
42
        unitSwitch->setMinimumSize(textWidth, minHeight);
12438 fschmid 43
        resize(minimumSizeHint());
21212 jghali 44
 
45
        // Try to start with doc unit if possible
46
        ScribusView* view = qobject_cast<ScribusView*>(parent);
47
        if (view)
48
        {
49
                ScribusDoc* doc = view->Doc;
50
                if (doc)
51
                {
52
                        int unitIndex = doc->unitIndex();
53
                        unitSwitch->setCurrentIndex(unitIndex);
54
                }
55
        }
56
        setValues(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
57
 
12753 fschmid 58
        connect(unitSwitch, SIGNAL(currentIndexChanged(int)), this, SLOT(unitChanged()));
12438 fschmid 59
}
706 cbradney 60
 
12438 fschmid 61
void Measurements::setValues(double x1, double y1, double x2, double y2, double angle, double len)
310 Franz 62
{
12438 fschmid 63
        mX1 = x1;
64
        mY1 = y1;
65
        mX2 = x2;
66
        mY2 = y2;
67
        mDX = x2 - x1;
68
        mDY = y2 - y1;
69
        mLength = len;
706 cbradney 70
        QString tmp;
284 Franz 71
        double rr = angle;
72
        if (angle < 0)
73
                rr = rr + 360;
12438 fschmid 74
        angleData->setText(tmp.setNum(fabs(rr), 'f', 2)+ trUtf8(" °"));
75
        unitChanged();
284 Franz 76
}
706 cbradney 77
 
12438 fschmid 78
void Measurements::unitChanged()
10859 cbradney 79
{
12438 fschmid 80
        QString tmp;
12753 fschmid 81
        int uInd = unitSwitch->currentIndex();
20936 jghali 82
        int uDec = unitGetDecimalsFromIndex(uInd);
83
        if (uDec == 0)
84
                uDec = 1; // Unlikely but avoid division by 0 if unitGetDecimalsFromIndex() returns 0
85
        int uPrec = unitGetPrecisionFromIndex(uInd);
86
        double uRatio = unitGetRatioFromIndex(uInd);
87
        QString uStr  = unitGetStrFromIndex(uInd);
88
        x1Data->setText(tmp.setNum(qRound(mX1 * uRatio * uDec) / static_cast<double>(uDec), 'f', uPrec) + " " + uStr);
89
        y1Data->setText(tmp.setNum(qRound(mY1 * uRatio * uDec) / static_cast<double>(uDec), 'f', uPrec) + " " + uStr);
90
        x2Data->setText(tmp.setNum(qRound(mX2 * uRatio * uDec) / static_cast<double>(uDec), 'f', uPrec) + " " + uStr);
91
        y2Data->setText(tmp.setNum(qRound(mY2 * uRatio * uDec) / static_cast<double>(uDec), 'f', uPrec) + " " + uStr);
92
        dXData->setText(tmp.setNum(qRound(mDX * uRatio * uDec) / static_cast<double>(uDec), 'f', uPrec) + " " + uStr);
93
        dYData->setText(tmp.setNum(qRound(mDY * uRatio * uDec) / static_cast<double>(uDec), 'f', uPrec) + " " + uStr);
94
        lengthData->setText(tmp.setNum(qRound(mLength * uRatio * uDec) / static_cast<double>(uDec), 'f', uPrec) + " " + uStr);
10859 cbradney 95
}
12720 cbradney 96
 
97
void Measurements::changeEvent(QEvent *e)
98
{
99
        if (e->type() == QEvent::LanguageChange)
100
        {
101
                languageChange();
102
        }
103
        else
104
                QWidget::changeEvent(e);
105
}
106
 
107
void Measurements::languageChange()
108
{
109
        retranslateUi(this);
12736 fschmid 110
}