2 * Parameter SpinBox, a custom Qt4 widget
3 * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "paramspinbox.hpp"
20 #include <QtGui/QMouseEvent>
22 ParamProgressBar::ParamProgressBar(QWidget
* parent
)
23 : QProgressBar(parent
)
25 m_leftClickDown
= false;
39 void ParamProgressBar::set_minimum(float value
)
44 void ParamProgressBar::set_maximum(float value
)
49 void ParamProgressBar::set_value(float value
)
52 float vper
= (value
- m_minimum
) / (m_maximum
- m_minimum
);
53 setValue(vper
* 1000);
56 void ParamProgressBar::set_label(QString label
)
60 if (m_label
== "(coef)")
67 void ParamProgressBar::set_text_call(TextCallback
* textCall
)
69 m_textCall
= textCall
;
72 void ParamProgressBar::handleMouseEventPos(const QPoint
& pos
)
74 float xper
= float(pos
.x()) / width();
75 float value
= xper
* (m_maximum
- m_minimum
) + m_minimum
;
77 if (value
< m_minimum
)
79 else if (value
> m_maximum
)
82 emit
valueChangedFromBar(value
);
85 void ParamProgressBar::mousePressEvent(QMouseEvent
* event
)
87 if (event
->button() == Qt::LeftButton
)
89 handleMouseEventPos(event
->pos());
90 m_leftClickDown
= true;
93 m_leftClickDown
= false;
94 QProgressBar::mousePressEvent(event
);
97 void ParamProgressBar::mouseMoveEvent(QMouseEvent
* event
)
100 handleMouseEventPos(event
->pos());
101 QProgressBar::mouseMoveEvent(event
);
104 void ParamProgressBar::mouseReleaseEvent(QMouseEvent
* event
)
106 m_leftClickDown
= false;
107 QProgressBar::mouseReleaseEvent(event
);
110 void ParamProgressBar::paintEvent(QPaintEvent
* event
)
113 setFormat(QString("%1 %2 %3").arg(m_preLabel
).arg(m_textCall
->textCallBack()).arg(m_label
));
115 setFormat(QString("%1 %2 %3").arg(m_preLabel
).arg(m_rvalue
).arg(m_label
));
117 QProgressBar::paintEvent(event
);