window-basic-settings.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Philippe Groarke <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #pragma once
  16. #include <util/util.hpp>
  17. #include <QDialog>
  18. #include <memory>
  19. #include <string>
  20. #include <libff/ff-util.h>
  21. #include <obs.h>
  22. class OBSBasic;
  23. class QAbstractButton;
  24. class QComboBox;
  25. class OBSPropertiesView;
  26. class OBSHotkeyWidget;
  27. #include "ui_OBSBasicSettings.h"
  28. class SilentUpdateCheckBox : public QCheckBox {
  29. Q_OBJECT
  30. public slots:
  31. void setCheckedSilently(bool checked)
  32. {
  33. bool blocked = blockSignals(true);
  34. setChecked(checked);
  35. blockSignals(blocked);
  36. }
  37. };
  38. class SilentUpdateSpinBox : public QSpinBox {
  39. Q_OBJECT
  40. public slots:
  41. void setValueSilently(int val)
  42. {
  43. bool blocked = blockSignals(true);
  44. setValue(val);
  45. blockSignals(blocked);
  46. }
  47. };
  48. class OBSFFDeleter
  49. {
  50. public:
  51. void operator()(const ff_format_desc *format)
  52. {
  53. ff_format_desc_free(format);
  54. }
  55. void operator()(const ff_codec_desc *codec)
  56. {
  57. ff_codec_desc_free(codec);
  58. }
  59. };
  60. using OBSFFCodecDesc = std::unique_ptr<const ff_codec_desc,
  61. OBSFFDeleter>;
  62. using OBSFFFormatDesc = std::unique_ptr<const ff_format_desc,
  63. OBSFFDeleter>;
  64. class OBSBasicSettings : public QDialog {
  65. Q_OBJECT
  66. private:
  67. OBSBasic *main;
  68. std::unique_ptr<Ui::OBSBasicSettings> ui;
  69. bool generalChanged = false;
  70. bool stream1Changed = false;
  71. bool outputsChanged = false;
  72. bool audioChanged = false;
  73. bool videoChanged = false;
  74. bool hotkeysChanged = false;
  75. bool advancedChanged = false;
  76. int pageIndex = 0;
  77. bool loading = true;
  78. std::string savedTheme;
  79. OBSFFFormatDesc formats;
  80. OBSPropertiesView *streamProperties = nullptr;
  81. OBSPropertiesView *streamEncoderProps = nullptr;
  82. OBSPropertiesView *recordEncoderProps = nullptr;
  83. using AudioSource_t =
  84. std::tuple<OBSWeakSource,
  85. QPointer<QCheckBox>, QPointer<QSpinBox>,
  86. QPointer<QCheckBox>, QPointer<QSpinBox>>;
  87. std::vector<AudioSource_t> audioSources;
  88. std::vector<OBSSignal> audioSourceSignals;
  89. OBSSignal sourceCreated;
  90. OBSSignal channelChanged;
  91. std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
  92. OBSSignal hotkeyRegistered;
  93. OBSSignal hotkeyUnregistered;
  94. void SaveCombo(QComboBox *widget, const char *section,
  95. const char *value);
  96. void SaveComboData(QComboBox *widget, const char *section,
  97. const char *value);
  98. void SaveCheckBox(QAbstractButton *widget, const char *section,
  99. const char *value, bool invert = false);
  100. void SaveEdit(QLineEdit *widget, const char *section,
  101. const char *value);
  102. void SaveSpinBox(QSpinBox *widget, const char *section,
  103. const char *value);
  104. void SaveFormat(QComboBox *combo);
  105. void SaveEncoder(QComboBox *combo, const char *section,
  106. const char *value);
  107. inline bool Changed() const
  108. {
  109. return generalChanged || outputsChanged || stream1Changed ||
  110. audioChanged || videoChanged || advancedChanged ||
  111. hotkeysChanged;
  112. }
  113. inline void EnableApplyButton(bool en)
  114. {
  115. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  116. }
  117. inline void ClearChanged()
  118. {
  119. generalChanged = false;
  120. stream1Changed = false;
  121. outputsChanged = false;
  122. audioChanged = false;
  123. videoChanged = false;
  124. hotkeysChanged = false;
  125. advancedChanged= false;
  126. EnableApplyButton(false);
  127. }
  128. void HookWidget(QWidget *widget, const char *signal, const char *slot);
  129. bool QueryChanges();
  130. void LoadServiceTypes();
  131. void LoadEncoderTypes();
  132. void LoadColorRanges();
  133. void LoadFormats();
  134. void ReloadCodecs(const ff_format_desc *formatDesc);
  135. void LoadGeneralSettings();
  136. void LoadStream1Settings();
  137. void LoadOutputSettings();
  138. void LoadAudioSettings();
  139. void LoadVideoSettings();
  140. void LoadHotkeySettings(obs_hotkey_id ignoreKey=OBS_INVALID_HOTKEY_ID);
  141. void LoadAdvancedSettings();
  142. void LoadSettings(bool changedOnly);
  143. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  144. const char *path, bool changed = false);
  145. /* general */
  146. void LoadLanguageList();
  147. void LoadThemeList();
  148. /* output */
  149. void LoadSimpleOutputSettings();
  150. void LoadAdvOutputStreamingSettings();
  151. void LoadAdvOutputStreamingEncoderProperties();
  152. void LoadAdvOutputRecordingSettings();
  153. void LoadAdvOutputRecordingEncoderProperties();
  154. void LoadAdvOutputFFmpegSettings();
  155. void LoadAdvOutputAudioSettings();
  156. void SetAdvOutputFFmpegEnablement(
  157. ff_codec_type encoderType, bool enabled,
  158. bool enableEncode = false);
  159. /* audio */
  160. void LoadListValues(QComboBox *widget, obs_property_t *prop,
  161. const char *configName);
  162. void LoadAudioDevices();
  163. void LoadAudioSources();
  164. /* video */
  165. void LoadRendererList();
  166. void ResetDownscales(uint32_t cx, uint32_t cy,
  167. uint32_t out_cx, uint32_t out_cy);
  168. void LoadDownscaleFilters();
  169. void LoadResolutionLists();
  170. void LoadFPSData();
  171. void SaveGeneralSettings();
  172. void SaveStream1Settings();
  173. void SaveOutputSettings();
  174. void SaveAudioSettings();
  175. void SaveVideoSettings();
  176. void SaveHotkeySettings();
  177. void SaveAdvancedSettings();
  178. void SaveSettings();
  179. private slots:
  180. void on_theme_activated(int idx);
  181. void on_simpleOutUseBufsize_toggled(bool checked);
  182. void on_simpleOutputVBitrate_valueChanged(int val);
  183. void on_listWidget_itemSelectionChanged();
  184. void on_buttonBox_clicked(QAbstractButton *button);
  185. void on_streamType_currentIndexChanged(int idx);
  186. void on_simpleOutputBrowse_clicked();
  187. void on_advOutRecPathBrowse_clicked();
  188. void on_advOutFFPathBrowse_clicked();
  189. void on_advOutEncoder_currentIndexChanged(int idx);
  190. void on_advOutRecEncoder_currentIndexChanged(int idx);
  191. void on_advOutFFFormat_currentIndexChanged(int idx);
  192. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  193. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  194. void on_colorFormat_currentIndexChanged(const QString &text);
  195. void on_baseResolution_editTextChanged(const QString &text);
  196. void GeneralChanged();
  197. void AudioChanged();
  198. void AudioChangedRestart();
  199. void ReloadAudioSources();
  200. void OutputsChanged();
  201. void Stream1Changed();
  202. void VideoChanged();
  203. void VideoChangedResolution();
  204. void VideoChangedRestart();
  205. void HotkeysChanged();
  206. void ReloadHotkeys(obs_hotkey_id ignoreKey=OBS_INVALID_HOTKEY_ID);
  207. void AdvancedChanged();
  208. void AdvancedChangedRestart();
  209. protected:
  210. virtual void closeEvent(QCloseEvent *event);
  211. public:
  212. OBSBasicSettings(QWidget *parent);
  213. };