Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

paramspinbox.cpp 2.8KB

12 years ago
12 years ago
12 years ago
12 years ago
11 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Parameter SpinBox, a custom Qt4 widget
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  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.
  9. *
  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.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "paramspinbox.hpp"
  18. #include <QtGui/QMouseEvent>
  19. ParamProgressBar::ParamProgressBar(QWidget* parent)
  20. : QProgressBar(parent)
  21. {
  22. m_leftClickDown = false;
  23. m_minimum = 0.0f;
  24. m_maximum = 1.0f;
  25. m_rvalue = 0.0f;
  26. m_textCall = nullptr;
  27. setMinimum(0);
  28. setMaximum(1000);
  29. setValue(0);
  30. setFormat("(none)");
  31. }
  32. void ParamProgressBar::set_minimum(float value)
  33. {
  34. m_minimum = value;
  35. }
  36. void ParamProgressBar::set_maximum(float value)
  37. {
  38. m_maximum = value;
  39. }
  40. void ParamProgressBar::set_value(float value)
  41. {
  42. m_rvalue = value;
  43. float vper = (value - m_minimum) / (m_maximum - m_minimum);
  44. setValue(vper * 1000);
  45. }
  46. void ParamProgressBar::set_label(QString label)
  47. {
  48. m_label = label;
  49. if (m_label == "(coef)")
  50. {
  51. m_label = "";
  52. m_preLabel = "*";
  53. }
  54. }
  55. void ParamProgressBar::set_text_call(TextCallback* textCall)
  56. {
  57. m_textCall = textCall;
  58. }
  59. void ParamProgressBar::handleMouseEventPos(const QPoint& pos)
  60. {
  61. float xper = float(pos.x()) / width();
  62. float value = xper * (m_maximum - m_minimum) + m_minimum;
  63. if (value < m_minimum)
  64. value = m_minimum;
  65. else if (value > m_maximum)
  66. value = m_maximum;
  67. emit valueChangedFromBar(value);
  68. }
  69. void ParamProgressBar::mousePressEvent(QMouseEvent* event)
  70. {
  71. if (event->button() == Qt::LeftButton)
  72. {
  73. handleMouseEventPos(event->pos());
  74. m_leftClickDown = true;
  75. }
  76. else
  77. m_leftClickDown = false;
  78. QProgressBar::mousePressEvent(event);
  79. }
  80. void ParamProgressBar::mouseMoveEvent(QMouseEvent* event)
  81. {
  82. if (m_leftClickDown)
  83. handleMouseEventPos(event->pos());
  84. QProgressBar::mouseMoveEvent(event);
  85. }
  86. void ParamProgressBar::mouseReleaseEvent(QMouseEvent* event)
  87. {
  88. m_leftClickDown = false;
  89. QProgressBar::mouseReleaseEvent(event);
  90. }
  91. void ParamProgressBar::paintEvent(QPaintEvent* event)
  92. {
  93. if (m_textCall)
  94. setFormat(QString("%1 %2 %3").arg(m_preLabel).arg(m_textCall->textCallBack()).arg(m_label));
  95. else
  96. setFormat(QString("%1 %2 %3").arg(m_preLabel).arg(m_rvalue).arg(m_label));
  97. QProgressBar::paintEvent(event);
  98. }