audio_widget.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "audio_widget.h"
  2. #include <QLayout>
  3. #include <qglobal.h>
  4. AudioWidget::AudioWidget(QWidget* parent)
  5. : QWidget(parent)
  6. {
  7. _CreateUi();
  8. _CreateConnect();
  9. _mutebox->setChecked(true);
  10. // setMinimumHeight(10);
  11. // setMaximumHeight(24);
  12. }
  13. void AudioWidget::_CreateUi()
  14. {
  15. // auto hLayout = new QHBoxLayout;
  16. // hLayout->setContentsMargins(0, 0, 0, 0);
  17. // hLayout->setSpacing(2);
  18. // _nameLabel = new QLabel;
  19. // QFont smallFont = _nameLabel->font();
  20. // smallFont.setPointSize(smallFont.pointSize() - 1);
  21. // _nameLabel->setFont(smallFont);
  22. // _mutebox = new QCheckBox("静音");
  23. // _mutebox->setFont(smallFont);
  24. // _render = new AudioRender;
  25. // _render->setMaximumHeight(14); // 更小的高度
  26. // _volumeBox = new QDoubleSpinBox;
  27. // _volumeBox->setMinimum(0);
  28. // _volumeBox->setValue(1);
  29. // _volumeBox->setFont(smallFont);
  30. // _volumeBox->setFixedHeight(18);
  31. // hLayout->addWidget(_nameLabel);
  32. // hLayout->addWidget(_mutebox);
  33. // auto scaleLayout = new QHBoxLayout;
  34. // scaleLayout->setContentsMargins(0, 0, 0, 0);
  35. // scaleLayout->setSpacing(2);
  36. // QLabel* scaleLabel = new QLabel("调幅:");
  37. // scaleLabel->setFont(smallFont);
  38. // scaleLayout->addWidget(scaleLabel);
  39. // scaleLayout->addWidget(_volumeBox);
  40. // hLayout->addLayout(scaleLayout);
  41. // auto vLayout = new QVBoxLayout;
  42. // vLayout->setContentsMargins(0, 0, 0, 0);
  43. // vLayout->setSpacing(2);
  44. // vLayout->addLayout(hLayout);
  45. // vLayout->addWidget(_render);
  46. // setLayout(vLayout);
  47. // setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
  48. auto hLayout = new QHBoxLayout;
  49. hLayout->setContentsMargins(0, 0, 0, 0);
  50. hLayout->setSpacing(6);
  51. _nameLabel = new QLabel;
  52. _render = new AudioRender;
  53. _render->setMaximumHeight(14);
  54. _render->setMinimumWidth(60);
  55. _render->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  56. _mutebox = new QCheckBox("静音");
  57. _volumeBox = new QDoubleSpinBox;
  58. _volumeBox->setMinimum(0);
  59. _volumeBox->setValue(1);
  60. _volumeBox->setFixedHeight(18);
  61. _volumeBox->setMaximumWidth(48);
  62. QLabel* scaleLabel = new QLabel("调幅:");
  63. hLayout->addWidget(_nameLabel);
  64. hLayout->addWidget(_render, 1); // 音量条居中拉伸
  65. hLayout->addWidget(_mutebox);
  66. hLayout->addWidget(scaleLabel);
  67. hLayout->addWidget(_volumeBox);
  68. setLayout(hLayout);
  69. setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
  70. }
  71. void AudioWidget::_CreateConnect()
  72. {
  73. connect(_mutebox, &QCheckBox::stateChanged, this, [this](int) {
  74. if (_mutebox->isChecked()) {
  75. emit SetVolumeScale(0);
  76. _volumeBox->setEnabled(false);
  77. } else {
  78. _volumeBox->setEnabled(true);
  79. emit SetVolumeScale(_volumeBox->value());
  80. }
  81. });
  82. connect(_volumeBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, [this] {
  83. emit SetVolumeScale(_volumeBox->value());
  84. });
  85. }