Cleanup
[carla.git] / source / frontend / widgets / paramspinbox.cpp
blob53020387b7f787d6c6be127ac2019f52107a6bf8
1 /*
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
8 * any later version.
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;
27 m_minimum = 0.0f;
28 m_maximum = 1.0f;
29 m_rvalue = 0.0f;
31 m_textCall = nullptr;
33 setMinimum(0);
34 setMaximum(1000);
35 setValue(0);
36 setFormat("(none)");
39 void ParamProgressBar::set_minimum(float value)
41 m_minimum = value;
44 void ParamProgressBar::set_maximum(float value)
46 m_maximum = value;
49 void ParamProgressBar::set_value(float value)
51 m_rvalue = value;
52 float vper = (value - m_minimum) / (m_maximum - m_minimum);
53 setValue(vper * 1000);
56 void ParamProgressBar::set_label(QString label)
58 m_label = label;
60 if (m_label == "(coef)")
62 m_label = "";
63 m_preLabel = "*";
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)
78 value = m_minimum;
79 else if (value > m_maximum)
80 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;
92 else
93 m_leftClickDown = false;
94 QProgressBar::mousePressEvent(event);
97 void ParamProgressBar::mouseMoveEvent(QMouseEvent* event)
99 if (m_leftClickDown)
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)
112 if (m_textCall)
113 setFormat(QString("%1 %2 %3").arg(m_preLabel).arg(m_textCall->textCallBack()).arg(m_label));
114 else
115 setFormat(QString("%1 %2 %3").arg(m_preLabel).arg(m_rvalue).arg(m_label));
117 QProgressBar::paintEvent(event);