summaryrefslogtreecommitdiffstats
path: root/kbarcode/measurements.h
blob: a95e66659354d71e56002d3e72e832d853930e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************************
                          measurements.h  -  description
                             -------------------
    begin                : Mit Dec 24 2003
    copyright            : (C) 2003 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MEASUREMENTS_H
#define MEASUREMENTS_H

#include <klocale.h>

class QPaintDevice;

/**
  * This class keeps all measurements required to correctly draw a label.
  * The measurements are available in pixels, milimeter and inch.
  * This class allows also for transformations from inch to mm or pixels
  * (and the other way round). Internally, everything is handled in mm.
  *
  * @author Dominik Seichter
  */
class Measurements {
    public:
        enum {
            DpiX,
            DpiY
        };

        enum {
            Metric = KLocale::Metric,
            Imperial = KLocale::Imperial,
            None
        };

        Measurements();
        Measurements( const Measurements & rhs );
        ~Measurements();

        int numH() const { return num_h; }
        int numV() const { return num_v; }

        double gapLeftMM() const { return gap_left; }
        double gapTopMM() const { return gap_top; }
        double gapVMM() const { return gap_v; }
        double gapHMM() const { return gap_h; }
        double widthMM() const { return m_width; }
        double heightMM() const { return m_height; }

        // return inch or milimeters according to the
        // users preferrences
        double gapLeft() const;
        double gapTop() const;
        double gapV() const;
        double gapH() const;
        double width() const;
        double height() const;

        double gapLeft( const QPaintDevice* device ) const;
        double gapTop( const QPaintDevice* device ) const;
        double gapV( const QPaintDevice* device ) const;
        double gapH( const QPaintDevice* device ) const;
        double width( const QPaintDevice* device ) const;
        double height( const QPaintDevice* device ) const;

        void setNumH( int n ) { num_h = n; }
        void setNumV( int n ) { num_v = n; }

        // use milimeters for all of the setter methods
        void setGapLeftMM( double d ) { gap_left = d; }
        void setGapTopMM( double d ) { gap_top = d; }
        void setGapVMM( double d ) { gap_v = d; }
        void setGapHMM( double d ) { gap_h = d; }
        void setWidthMM( double d ) { m_width = d; }
        void setHeightMM( double d ) { m_height = d; }

        // inch or milimeters are taken as input
        // according to the users preferrences
        void setGapLeft( double d );
        void setGapTop( double d );
        void setGapV( double d );
        void setGapH( double d );
        void setWidth( double d );
        void setHeight( double d );

        void operator=(const Measurements & rhs );

        /** return the localized string that should be appended
          * to a measurement number visible to the user. I.e.
          * "mm" or "in".
          */
        static const QString & system() { Measurements::init(); return m_string; }

        /** return the measurements system to be used.
          */
        static int measurementSystem() { Measurements::init(); return m_system; }

    private:
        /** initialize measurements with the correctly
          * measurements system to be used from KDE.
          */
        static void init();

        void defaultMeasurements();

        double mmToPixel( double mm, const QPaintDevice* device, int mode = DpiX ) const;

        /** Measurement system to use:
          * milimeters or inch
          */
        static int m_system;
        static QString m_string;

        int num_h;
        int num_v;
        double gap_left;
        double gap_top;
        double gap_v;
        double gap_h;
        double m_width;
        double m_height;
};

#endif