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 135 136 137 138 139 140 141 142 143
|
/***************************************************************************
ScaleWidget.h - widget for drawing a scale under an image
-------------------
begin : Sep 18 2001
copyright : (C) 2001 by Thomas Eschenbacher
email : Thomas Eschenbacher <thomas.eschenbacher@gmx.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 SCALE_WIDGET_H
#define SCALE_WIDGET_H
#include "config.h"
#include "libkwavegui_export.h"
#include <QtGlobal>
#include <QString>
#include <QWidget>
class QPaintEvent;
class QPainter;
class QSize;
namespace Kwave
{
class LIBKWAVEGUI_EXPORT ScaleWidget: public QWidget
{
public:
/**
* Primitve constructor for usage in a Qt designer's dialog
* @param parent the widget's parent widget
*/
explicit ScaleWidget(QWidget *parent);
/**
* Constructor with initialization.
* @param parent the widget's parent widget
* @param low left/lower border value
* @param high right/upper border value
* @param unit text of the units to show
*/
ScaleWidget(QWidget *parent, int low, int high, const QString &unit);
/** Destructor */
~ScaleWidget() override;
/**
* Sets the border values.
* @param min left/lower border value
* @param max right/upper border value
*/
void setMinMax(int min, int max);
/**
* Set the text of the units.
* @param text the units to show
*/
void setUnit(const QString &text);
/**
* Sets logarithmic or linear mode.
* @param log if true, set logarithmic mode, if not select
* linear mode
*/
void setLogMode(bool log);
/** minimum size of the widtget, @see QWidget::minimumSize() */
virtual QSize minimumSize() const;
/** optimal size for the widget, @see QWidget::sizeHint() */
QSize sizeHint() const override;
protected:
/**
* Draws the widget.
* @see QWidget::paintEvent
*/
void paintEvent(QPaintEvent *) override;
/**
* Draws a linear scale
* @param p reference to the painter
* @param w width of the drawing area in pixels
* @param h height of the drawing area in pixels
* @param inverse of true, the coordinate system is rotated
* to be upside-down and the scale has to be drawn
* mirrored in x and y axis.
*/
void drawLinear(QPainter &p, int w, int h, bool inverse);
/**
* @todo implementation of logarithmic scale
*/
void drawLog(QPainter &p, int w, int h, bool inverse);
/**
* Painting routine for own small font with fixed size
* There are Problems with smaller displays using QFont,
* sizes are not correct.
* @param p reference to the painter
* @param x coordinate of the left edge of the first character
* @param y coordinate of the lower edge of the first character
* @param reverse if true, print reverse: x is right edge of
* the text, like "align right".
* @param text the text to be printed. Must only contain known
* characters that are present in the font bitmap, like
* numbers, letters and some special chars like "%",
* space, dot and comma.
*/
void paintText(QPainter &p, int x, int y,
bool reverse, const QString &text);
private:
/** Lower boundary value */
int m_low;
/** Upper boundary value */
int m_high;
/** If true, logarithmic mode, linear mode if false */
bool m_logmode;
/** String containing the name of the unit */
QString m_unittext;
};
}
#endif // SCALE_WIDGET_H
//***************************************************************************
//***************************************************************************
|