soundspane.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "soundspane.h"
  2. void SoundsPane::setPaneContents() {
  3. mContentsWidget = new QWidget();
  4. QVBoxLayout* contentsLayout = new QVBoxLayout(mContentsWidget);
  5. mContentsWidget->setObjectName("innerPane");
  6. // Adding widgets
  7. QLabel* logInSoundLabel = new QLabel(tr("Log In Sound"));
  8. logInSoundLabel->setFont(mTitleFont);
  9. contentsLayout->addWidget(logInSoundLabel);
  10. QHBoxLayout* logInSoundLayout = new QHBoxLayout();
  11. logInSoundLayout->setContentsMargins(10, 1, 1, 1);
  12. QLineEdit* logInSoundPathLineEdit = new QLineEdit();
  13. logInSoundPathLineEdit->setFont(mFont);
  14. logInSoundPathLineEdit->setPlaceholderText(tr("Type path here..."));
  15. logInSoundPathLineEdit->setClearButtonEnabled(true);
  16. logInSoundLayout->addWidget(logInSoundPathLineEdit);
  17. QPushButton* logInSoundChooseButton = new QPushButton("...");
  18. logInSoundLayout->addWidget(logInSoundChooseButton);
  19. contentsLayout->addLayout(logInSoundLayout);
  20. QLabel* logOutSoundLabel = new QLabel(tr("Log Out Sound"));
  21. logOutSoundLabel->setFont(mTitleFont);
  22. contentsLayout->addWidget(logOutSoundLabel);
  23. QHBoxLayout* logOutSoundLayout = new QHBoxLayout();
  24. logOutSoundLayout->setContentsMargins(10, 1, 1, 1);
  25. QLineEdit* logOutSoundPathLineEdit = new QLineEdit();
  26. logOutSoundPathLineEdit->setFont(mFont);
  27. logOutSoundPathLineEdit->setPlaceholderText(tr("Type path here..."));
  28. logOutSoundPathLineEdit->setClearButtonEnabled(true);
  29. logOutSoundLayout->addWidget(logOutSoundPathLineEdit);
  30. QPushButton* logOutSoundChooseButton = new QPushButton("...");
  31. logOutSoundLayout->addWidget(logOutSoundChooseButton);
  32. contentsLayout->addLayout(logOutSoundLayout);
  33. contentsLayout->addSpacerItem(new QSpacerItem(0, 0,
  34. QSizePolicy::Ignored,
  35. QSizePolicy::MinimumExpanding));
  36. QPushButton* saveButton = new QPushButton(tr("Save settings"));
  37. saveButton->setFont(mFont);
  38. contentsLayout->addWidget(saveButton);
  39. saveButton->setVisible(false);
  40. // Setting current settings
  41. logInSoundPathLineEdit->setText(getConfigValue("logInSound").toString());
  42. logOutSoundPathLineEdit->setText(getConfigValue("logOutSound").toString());
  43. // Making connections
  44. connect(logInSoundPathLineEdit, &QLineEdit::textChanged, this, [saveButton]() {
  45. saveButton->setVisible(true);
  46. });
  47. connect(logOutSoundPathLineEdit, &QLineEdit::textChanged, this, [saveButton]() {
  48. saveButton->setVisible(true);
  49. });
  50. connect(saveButton, &QPushButton::clicked, this, [this,
  51. logInSoundPathLineEdit,
  52. logOutSoundPathLineEdit,
  53. saveButton]() {
  54. prepareToSave(logInSoundPathLineEdit,
  55. logOutSoundPathLineEdit);
  56. saveConfig();
  57. saveButton->setVisible(false);
  58. });
  59. connect(logInSoundChooseButton,
  60. &QPushButton::clicked, this, [this, logInSoundPathLineEdit]() {
  61. QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
  62. QDir::homePath(),
  63. "Audio Files (*.mp3 *.wav *.m4a *.ogg *.opus)");
  64. if (!fileName.isEmpty()) {
  65. logInSoundPathLineEdit->setText(fileName);
  66. }
  67. });
  68. connect(logOutSoundChooseButton,
  69. &QPushButton::clicked, this, [this, logOutSoundPathLineEdit]() {
  70. QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
  71. QDir::homePath(),
  72. "Audio Files (*.mp3 *.wav *.m4a *.ogg *.opus)");
  73. if (!fileName.isEmpty()) {
  74. logOutSoundPathLineEdit->setText(fileName);
  75. }
  76. });
  77. finalizeUI();
  78. }
  79. void SoundsPane::prepareToSave(QLineEdit* logInSoundLineEdit,
  80. QLineEdit* logOutSoundLineEdit) {
  81. setEntry("logInSound", QJsonValue(logInSoundLineEdit->text()));
  82. setEntry("logOutSound", QJsonValue(logOutSoundLineEdit->text()));
  83. }
  84. SoundsPane::SoundsPane(QJsonObject* cfgObj) : Pane(nullptr,
  85. cfgObj,
  86. tr("Sounds"),
  87. "preferences-system-sound") {
  88. }