34 const int nBorderWidth = 10;
35 const int nInterBarGap = 10;
37 const int nTopLableStartX = nBorderWidth + nInterBarGap/2;
38 const int nTopLabelStartY = 15;
39 const int nTopLabelWidth = 15;
40 const int nTopLabelHeight = 25;
42 const int nBarStartX = nTopLableStartX;
43 const int nBarStartY = nTopLabelStartY + nTopLabelHeight + 10;
44 const int nBarWidth = nTopLabelWidth;
45 const int nBarHeight = 450;
47 const int nDownLabelStartX = nBarStartX;
48 const int nDownLabelStartY = nBarStartY + nBarHeight + 5;
49 const int nDownLabelWidth = nBarWidth;
50 const int nDownLabelHeight = nTopLabelHeight;
52 const int nTotalWindowHeight = nDownLabelStartY + nDownLabelHeight + nTopLabelStartY;
53 const int nUnitBarWidth = nInterBarGap + nTopLabelWidth;
56 QVUMeter::QVUMeter(QStringList strBarLables, QWidget *parent) : QWidget(parent)
58 colBack = QColor(60, 60, 60);
60 m_nBars = strBarLables.length();
62 for(
int i=0 ; i < m_nBars; ++i)
63 m_Bars.push_back(
new QVUBar(
this, strBarLables[i]));
65 m_nTotalWindowWidth = nUnitBarWidth * m_nBars + 2 * nBorderWidth;
69 QVUMeter::QVUMeter(QWidget *parent) : QWidget(parent)
71 colBack = QColor(60, 60, 60);
75 for(
int i=0 ; i < m_nBars; ++i)
76 m_Bars.push_back(
new QVUBar(
this));
78 m_nTotalWindowWidth = nUnitBarWidth * m_nBars + 2 * nBorderWidth;
86 m_nBars = strBarLables.length();
88 for(
int i=0 ; i < m_nBars; ++i)
89 m_Bars.push_back(
new QVUBar(
this, strBarLables[i], min, max));
91 m_nTotalWindowWidth = nUnitBarWidth * m_nBars + 2 * nBorderWidth;
98 while(m_Bars.size() > nCount)
101 for(
int i=0, nMax = m_Bars.size(); i < nMax; ++i)
102 m_Bars.at(i)->setMinMaxValues(min, max);
104 while(m_Bars.size() < nCount)
105 m_Bars.push_back(
new QVUBar(
this,
"", min, max));
107 m_nTotalWindowWidth = nUnitBarWidth * m_nBars + 2 * nBorderWidth;
112 void QVUMeter::paintEvent(QPaintEvent *)
120 void QVUMeter::paintBorder()
122 int nTotalWidth = m_nTotalWindowWidth;
123 int nTotalHeight = nTotalWindowHeight;
125 QPainter painter(
this);
126 painter.setWindow(0, 0, nTotalWidth, nTotalHeight);
127 painter.setRenderHint(QPainter::Antialiasing);
128 QColor light = Qt::white;
129 QColor dark = colBack.darker(140);
131 painter.setPen(QPen(colBack, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
132 QLinearGradient linGrad(5, nTotalHeight/2, 10, nTotalHeight/2);
133 linGrad.setColorAt(0, light);
134 linGrad.setColorAt(1, colBack);
135 linGrad.setSpread(QGradient::PadSpread);
136 painter.setBrush(linGrad);
137 QRectF border(5, 5, nTotalWidth - 10, nTotalHeight - 10);
138 painter.drawRoundRect(border, 30, 5);
139 QLinearGradient linGrad1(nTotalWidth - nBorderWidth, nTotalHeight/2, nTotalWidth - 5, nTotalHeight/2);
140 linGrad1.setColorAt(0, colBack);
141 linGrad1.setColorAt(1, dark);
142 linGrad1.setSpread(QGradient::PadSpread);
143 painter.setBrush(linGrad1);
144 QRectF border1(nBorderWidth, 5, nTotalWidth - nBorderWidth - 5, nTotalHeight - 10);
145 painter.drawRoundRect(border1, 30, 5);
148 QFont valFont(
"Arial", 9, QFont::Bold);
149 painter.setFont(valFont);
151 for(
int i=0; i < m_nBars; ++i)
153 painter.setPen(QPen(m_Bars[i]->colText, 2));
155 int nStartX = nDownLabelStartX + i * nUnitBarWidth;
156 int nStartY = nDownLabelStartY;
157 QRectF Left(nStartX, nStartY, nDownLabelWidth, nDownLabelHeight);
158 painter.drawText(Left, Qt::AlignCenter, m_Bars[i]->lable());
162 void QVUMeter::paintBar()
164 int nTotalWidth = m_nTotalWindowWidth;
165 int nTotalHeight = nTotalWindowHeight;
167 QPainter painter(
this);
168 painter.setWindow(0, 0, nTotalWidth, nTotalHeight);
169 painter.setRenderHint(QPainter::Antialiasing);
174 for(
int i=0; i < m_nBars; ++i)
176 const QVUBar& bar = *m_Bars[i];
178 int nStartX = nBarStartX + i * nUnitBarWidth;
179 int nStartY = nBarStartY;
181 QLinearGradient linGrad(nStartX, 0, nStartX, 500);
182 linGrad.setColorAt(0, bar.colHigh);
183 linGrad.setColorAt(1, bar.colLow);
184 linGrad.setSpread(QGradient::PadSpread);
185 painter.setBrush(linGrad);
187 painter.drawRect(nStartX, nStartY, nBarWidth, nBarHeight);
190 painter.setBrush(QColor(40, 40, 40));
192 double length = nBarHeight;
193 double leftBar = abs(length * (bar.Value - bar.min)/(bar.max-bar.min));
195 painter.drawRect(nStartX, nStartY, nBarWidth, nBarHeight-leftBar);
197 painter.setPen(QPen(Qt::black, 2));
199 for (
int i = 0; i <=60; i++)
201 painter.drawLine(nStartX + 1, 500-nBarHeight*i/60, nStartX + nBarWidth - 1, 500-nBarHeight*i/60);
207 void QVUMeter::paintValue()
209 int nTotalWidth = m_nTotalWindowWidth;
210 int nTotalHeight = nTotalWindowHeight;
212 QPainter painter(
this);
213 painter.setWindow(0, 0, nTotalWidth, nTotalHeight);
214 painter.setRenderHint(QPainter::Antialiasing);
216 QFont valFont(
"Arial", 9, QFont::Bold);
217 painter.setFont(valFont);
219 for(
int i=0; i < m_nBars; ++i)
221 const QVUBar& bar = *m_Bars[i];
223 int nStartX = nTopLableStartX + i * nUnitBarWidth;
224 int nStartY = nTopLabelStartY;
226 painter.setPen(QPen(Qt::black, 2));
227 painter.setBrush(Qt::black);
228 painter.drawRect(nStartX, nStartY, nTopLabelWidth, nTopLabelHeight);
230 painter.setPen(Qt::gray);
231 painter.drawLine(nStartX, nStartY + nTopLabelHeight, nStartX + nTopLabelWidth, nStartY + nTopLabelHeight);
233 painter.setPen(QPen(bar.colText, 1));
235 QRectF leftR(nStartX, nStartY, nTopLabelWidth, nTopLabelHeight);
236 QString lVal = QString(
"%1").arg(bar.Value, 0,
'f', 0);
237 painter.drawText(leftR, Qt::AlignCenter, lVal);
244 QVUBar::QVUBar(QObject* pParent, QString strLable,
double _min,
double _max) : QObject(pParent)
256 void QVUBar::setValueDim(
int dim)
259 ((QWidget *)parent())->update();
262 void QVUMeter::setColorBg(QColor color)
265 ((QWidget *)parent())->update();
268 void QVUBar::setColorOfText(QColor color)
271 ((QWidget *)parent())->update();
274 void QVUBar::setColorHigh(QColor color)
277 ((QWidget *)parent())->update();
281 void QVUBar::setColorLow(QColor color)
284 ((QWidget *)parent())->update();
287 void QVUBar::setValue(
double leftValue)
293 else if (leftValue < min)
301 ((QWidget *)parent())->update();
305 void QVUBar::setMinValue(
double minValue)
316 ((QWidget *)parent())->update();
319 void QVUBar::setMaxValue(
double maxValue)
330 ((QWidget *)parent())->update();
333 void QVUBar::setMinMaxValues(
double minValue,
double maxValue)
335 if(minValue > maxValue)
345 ((QWidget *)parent())->update();
348 void QVUBar::setLable(QString strLable)
351 ((QWidget *)parent())->update();
354 QSize QVUMeter::minimumSizeHint()
const
356 return QSize(m_nTotalWindowWidth / 5, nTotalWindowHeight / 10);
359 QSize QVUMeter::sizeHint()
const
361 return QSize(m_nTotalWindowWidth, nTotalWindowHeight);
365 QVUBar* QVUMeter::GetBar(
int nIndex)
const
367 if(nIndex >= 0 && nIndex < m_Bars.size())
368 return m_Bars.at(nIndex);
373 void QVUMeter::SetMinMaxValues(
double nMin,
double nMax)
375 for(
int i=0, nMax = m_Bars.size(); i < nMax; ++i)
376 m_Bars.at(i)->setMinMaxValues(nMin, nMax);
379 int QVUMeter::GetBarCount()
const
381 return m_Bars.size();
void SetBars(QStringList strBarLables, double min=0, double max=100)
void SetBarCount(int nCount, double min=0.0, double max=100.0)