1 /***************************************************************************
2           ScaleWidget.h  -  widget for drawing a scale under an image
3 			     -------------------
4     begin                : Sep 18 2001
5     copyright            : (C) 2001 by Thomas Eschenbacher
6     email                : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef SCALE_WIDGET_H
19 #define SCALE_WIDGET_H
20 
21 #include "config.h"
22 
23 #include <QtGlobal>
24 #include <QString>
25 #include <QWidget>
26 
27 class QPaintEvent;
28 class QPainter;
29 class QSize;
30 
31 namespace Kwave
32 {
33     class Q_DECL_EXPORT ScaleWidget: public QWidget
34     {
35     public:
36 
37 	/**
38 	 * Primitve constructor for usage in a Qt designer's dialog
39 	 * @param parent the widget's parent widget
40 	 */
41 	explicit ScaleWidget(QWidget *parent);
42 
43 	/**
44 	 * Constructor with initialization.
45 	 * @param parent the widget's parent widget
46 	 * @param low left/lower border value
47 	 * @param high right/upper border value
48 	 * @param unit text of the units to show
49 	 */
50 	ScaleWidget(QWidget *parent, int low, int high, const QString &unit);
51 
52 	/** Destructor */
53         virtual ~ScaleWidget() Q_DECL_OVERRIDE;
54 
55 	/**
56 	 * Sets the border values.
57 	 * @param min left/lower border value
58 	 * @param max right/upper border value
59 	 */
60 	void setMinMax(int min, int max);
61 
62 	/**
63 	 * Set the text of the units.
64 	 * @param text the units to show
65 	 */
66 	void setUnit(const QString &text);
67 
68 	/**
69 	 * Sets logarithmic or linear mode.
70 	 * @param log if true, set logarithmic mode, if not select
71 	 *        linear mode
72 	 */
73 	void setLogMode(bool log);
74 
75 	/** minimum size of the widtget, @see QWidget::minimumSize() */
76 	virtual QSize minimumSize() const;
77 
78 	/** optimal size for the widget, @see QWidget::sizeHint() */
79         virtual QSize sizeHint() const Q_DECL_OVERRIDE;
80 
81     protected:
82 
83 	/**
84 	 * Draws the widget.
85 	 * @see QWidget::paintEvent
86 	 */
87         virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
88 
89 	/**
90 	 * Draws a linear scale
91 	 * @param p reference to the painter
92 	 * @param w width of the drawing area in pixels
93 	 * @param h height of the drawing area in pixels
94 	 * @param inverse of true, the coordinate system is rotated
95 	 *        to be upside-down and the scale has to be drawn
96 	 *        mirrored in x and y axis.
97 	 */
98 	void drawLinear(QPainter &p, int w, int h, bool inverse);
99 
100 	/**
101 	 * @todo implementation of logarithmic scale
102 	 */
103 	void drawLog(QPainter &p, int w, int h, bool inverse);
104 
105 	/**
106 	 * Painting routine for own small font with fixed size
107 	 * There are Problems with smaller displays using QFont,
108 	 * sizes are not correct.
109 	 * @param p reference to the painter
110 	 * @param x coordinate of the left edge of the first character
111 	 * @param y coordinate of the lower edge of the first character
112 	 * @param reverse if true, print reverse: x is right edge of
113 	 *        the text, like "align right".
114 	 * @param text the text to be printed. Must only contain known
115 	 *        characters that are present in the font bitmap, like
116 	 *        numbers, letters and some special chars like "%",
117 	 *        space, dot and comma.
118 	 */
119 	void paintText(QPainter &p, int x, int y,
120 	                bool reverse, const QString &text);
121 
122     private:
123 
124 	/** Lower boundary value */
125 	int m_low;
126 
127 	/** Upper boundary value */
128 	int m_high;
129 
130 	/** If true, logarithmic mode, linear mode if false */
131 	bool m_logmode;
132 
133 	/** String containing the name of the unit */
134 	QString m_unittext;
135 
136     };
137 }
138 
139 #endif // SCALE_WIDGET_H
140 
141 //***************************************************************************
142 //***************************************************************************
143