context-bar-controls.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. #include "window-basic-main.hpp"
  2. #include "context-bar-controls.hpp"
  3. #include "qt-wrappers.hpp"
  4. #include "obs-app.hpp"
  5. #include <QStandardItemModel>
  6. #include <QColorDialog>
  7. #include <QFontDialog>
  8. #include "ui_browser-source-toolbar.h"
  9. #include "ui_device-select-toolbar.h"
  10. #include "ui_game-capture-toolbar.h"
  11. #include "ui_image-source-toolbar.h"
  12. #include "ui_color-source-toolbar.h"
  13. #include "ui_text-source-toolbar.h"
  14. #ifdef _WIN32
  15. #define get_os_module(win, mac, linux) obs_get_module(win)
  16. #define get_os_text(mod, win, mac, linux) obs_module_get_locale_text(mod, win)
  17. #elif __APPLE__
  18. #define get_os_module(win, mac, linux) obs_get_module(mac)
  19. #define get_os_text(mod, win, mac, linux) obs_module_get_locale_text(mod, mac)
  20. #else
  21. #define get_os_module(win, mac, linux) obs_get_module(linux)
  22. #define get_os_text(mod, win, mac, linux) obs_module_get_locale_text(mod, linux)
  23. #endif
  24. /* ========================================================================= */
  25. SourceToolbar::SourceToolbar(QWidget *parent, OBSSource source)
  26. : QWidget(parent),
  27. weakSource(OBSGetWeakRef(source)),
  28. props(obs_source_properties(source), obs_properties_destroy)
  29. {
  30. }
  31. void SourceToolbar::SaveOldProperties(obs_source_t *source)
  32. {
  33. oldData = obs_data_create();
  34. OBSDataAutoRelease oldSettings = obs_source_get_settings(source);
  35. obs_data_apply(oldData, oldSettings);
  36. obs_data_set_string(oldData, "undo_sname", obs_source_get_name(source));
  37. }
  38. void SourceToolbar::SetUndoProperties(obs_source_t *source, bool repeatable)
  39. {
  40. if (!oldData) {
  41. blog(LOG_ERROR, "%s: somehow oldData was null.", __FUNCTION__);
  42. return;
  43. }
  44. OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
  45. OBSSource currentSceneSource = main->GetCurrentSceneSource();
  46. if (!currentSceneSource)
  47. return;
  48. std::string scene_name = obs_source_get_name(currentSceneSource);
  49. auto undo_redo = [scene_name,
  50. main = std::move(main)](const std::string &data) {
  51. OBSDataAutoRelease settings =
  52. obs_data_create_from_json(data.c_str());
  53. OBSSourceAutoRelease source = obs_get_source_by_name(
  54. obs_data_get_string(settings, "undo_sname"));
  55. obs_source_reset_settings(source, settings);
  56. OBSSourceAutoRelease scene_source =
  57. obs_get_source_by_name(scene_name.c_str());
  58. main->SetCurrentScene(scene_source.Get(), true);
  59. main->UpdateContextBar();
  60. };
  61. OBSDataAutoRelease new_settings = obs_data_create();
  62. OBSDataAutoRelease curr_settings = obs_source_get_settings(source);
  63. obs_data_apply(new_settings, curr_settings);
  64. obs_data_set_string(new_settings, "undo_sname",
  65. obs_source_get_name(source));
  66. std::string undo_data(obs_data_get_json(oldData));
  67. std::string redo_data(obs_data_get_json(new_settings));
  68. if (undo_data.compare(redo_data) != 0)
  69. main->undo_s.add_action(
  70. QTStr("Undo.Properties")
  71. .arg(obs_source_get_name(source)),
  72. undo_redo, undo_redo, undo_data, redo_data, repeatable);
  73. oldData = nullptr;
  74. }
  75. /* ========================================================================= */
  76. BrowserToolbar::BrowserToolbar(QWidget *parent, OBSSource source)
  77. : SourceToolbar(parent, source), ui(new Ui_BrowserSourceToolbar)
  78. {
  79. ui->setupUi(this);
  80. }
  81. BrowserToolbar::~BrowserToolbar() {}
  82. void BrowserToolbar::on_refresh_clicked()
  83. {
  84. OBSSource source = GetSource();
  85. if (!source) {
  86. return;
  87. }
  88. obs_property_t *p = obs_properties_get(props.get(), "refreshnocache");
  89. obs_property_button_clicked(p, source.Get());
  90. }
  91. /* ========================================================================= */
  92. ComboSelectToolbar::ComboSelectToolbar(QWidget *parent, OBSSource source)
  93. : SourceToolbar(parent, source), ui(new Ui_DeviceSelectToolbar)
  94. {
  95. ui->setupUi(this);
  96. }
  97. ComboSelectToolbar::~ComboSelectToolbar() {}
  98. static int FillPropertyCombo(QComboBox *c, obs_property_t *p,
  99. const std::string &cur_id, bool is_int = false)
  100. {
  101. size_t count = obs_property_list_item_count(p);
  102. int cur_idx = -1;
  103. for (size_t i = 0; i < count; i++) {
  104. const char *name = obs_property_list_item_name(p, i);
  105. std::string id;
  106. if (is_int) {
  107. id = std::to_string(obs_property_list_item_int(p, i));
  108. } else {
  109. const char *val = obs_property_list_item_string(p, i);
  110. id = val ? val : "";
  111. }
  112. if (cur_id == id)
  113. cur_idx = (int)i;
  114. c->addItem(name, id.c_str());
  115. }
  116. return cur_idx;
  117. }
  118. void UpdateSourceComboToolbarProperties(QComboBox *combo, OBSSource source,
  119. obs_properties_t *props,
  120. const char *prop_name, bool is_int)
  121. {
  122. std::string cur_id;
  123. OBSDataAutoRelease settings = obs_source_get_settings(source);
  124. if (is_int) {
  125. cur_id = std::to_string(obs_data_get_int(settings, prop_name));
  126. } else {
  127. cur_id = obs_data_get_string(settings, prop_name);
  128. }
  129. combo->blockSignals(true);
  130. obs_property_t *p = obs_properties_get(props, prop_name);
  131. int cur_idx = FillPropertyCombo(combo, p, cur_id, is_int);
  132. if (cur_idx == -1 || obs_property_list_item_disabled(p, cur_idx)) {
  133. if (cur_idx == -1) {
  134. combo->insertItem(
  135. 0,
  136. QTStr("Basic.Settings.Audio.UnknownAudioDevice"));
  137. cur_idx = 0;
  138. }
  139. SetComboItemEnabled(combo, cur_idx, false);
  140. }
  141. combo->setCurrentIndex(cur_idx);
  142. combo->blockSignals(false);
  143. }
  144. void ComboSelectToolbar::Init()
  145. {
  146. OBSSource source = GetSource();
  147. if (!source) {
  148. return;
  149. }
  150. UpdateSourceComboToolbarProperties(ui->device, source, props.get(),
  151. prop_name, is_int);
  152. }
  153. void UpdateSourceComboToolbarValue(QComboBox *combo, OBSSource source, int idx,
  154. const char *prop_name, bool is_int)
  155. {
  156. QString id = combo->itemData(idx).toString();
  157. OBSDataAutoRelease settings = obs_data_create();
  158. if (is_int) {
  159. obs_data_set_int(settings, prop_name, id.toInt());
  160. } else {
  161. obs_data_set_string(settings, prop_name, QT_TO_UTF8(id));
  162. }
  163. obs_source_update(source, settings);
  164. }
  165. void ComboSelectToolbar::on_device_currentIndexChanged(int idx)
  166. {
  167. OBSSource source = GetSource();
  168. if (idx == -1 || !source) {
  169. return;
  170. }
  171. SaveOldProperties(source);
  172. UpdateSourceComboToolbarValue(ui->device, source, idx, prop_name,
  173. is_int);
  174. SetUndoProperties(source);
  175. }
  176. AudioCaptureToolbar::AudioCaptureToolbar(QWidget *parent, OBSSource source)
  177. : ComboSelectToolbar(parent, source)
  178. {
  179. }
  180. void AudioCaptureToolbar::Init()
  181. {
  182. delete ui->activateButton;
  183. ui->activateButton = nullptr;
  184. obs_module_t *mod =
  185. get_os_module("win-wasapi", "mac-capture", "linux-pulseaudio");
  186. if (!mod) {
  187. return;
  188. }
  189. const char *device_str =
  190. get_os_text(mod, "Device", "CoreAudio.Device", "Device");
  191. ui->deviceLabel->setText(device_str);
  192. prop_name = "device_id";
  193. ComboSelectToolbar::Init();
  194. }
  195. WindowCaptureToolbar::WindowCaptureToolbar(QWidget *parent, OBSSource source)
  196. : ComboSelectToolbar(parent, source)
  197. {
  198. }
  199. void WindowCaptureToolbar::Init()
  200. {
  201. delete ui->activateButton;
  202. ui->activateButton = nullptr;
  203. obs_module_t *mod =
  204. get_os_module("win-capture", "mac-capture", "linux-capture");
  205. const char *device_str = get_os_text(mod, "WindowCapture.Window",
  206. "WindowUtils.Window", "Window");
  207. ui->deviceLabel->setText(device_str);
  208. #if !defined(_WIN32) && !defined(__APPLE__) //linux
  209. prop_name = "capture_window";
  210. #else
  211. prop_name = "window";
  212. #endif
  213. #ifdef __APPLE__
  214. is_int = true;
  215. #endif
  216. ComboSelectToolbar::Init();
  217. }
  218. DisplayCaptureToolbar::DisplayCaptureToolbar(QWidget *parent, OBSSource source)
  219. : ComboSelectToolbar(parent, source)
  220. {
  221. }
  222. void DisplayCaptureToolbar::Init()
  223. {
  224. delete ui->activateButton;
  225. ui->activateButton = nullptr;
  226. obs_module_t *mod =
  227. get_os_module("win-capture", "mac-capture", "linux-capture");
  228. const char *device_str =
  229. get_os_text(mod, "Monitor", "DisplayCapture.Display", "Screen");
  230. ui->deviceLabel->setText(device_str);
  231. is_int = true;
  232. #ifdef _WIN32
  233. prop_name = "monitor";
  234. #elif __APPLE__
  235. prop_name = "display";
  236. #else
  237. prop_name = "screen";
  238. #endif
  239. ComboSelectToolbar::Init();
  240. }
  241. /* ========================================================================= */
  242. DeviceCaptureToolbar::DeviceCaptureToolbar(QWidget *parent, OBSSource source)
  243. : QWidget(parent),
  244. weakSource(OBSGetWeakRef(source)),
  245. ui(new Ui_DeviceSelectToolbar)
  246. {
  247. ui->setupUi(this);
  248. delete ui->deviceLabel;
  249. delete ui->device;
  250. ui->deviceLabel = nullptr;
  251. ui->device = nullptr;
  252. OBSDataAutoRelease settings = obs_source_get_settings(source);
  253. active = obs_data_get_bool(settings, "active");
  254. obs_module_t *mod = obs_get_module("win-dshow");
  255. if (!mod)
  256. return;
  257. activateText = obs_module_get_locale_text(mod, "Activate");
  258. deactivateText = obs_module_get_locale_text(mod, "Deactivate");
  259. ui->activateButton->setText(active ? deactivateText : activateText);
  260. }
  261. DeviceCaptureToolbar::~DeviceCaptureToolbar() {}
  262. void DeviceCaptureToolbar::on_activateButton_clicked()
  263. {
  264. OBSSource source = OBSGetStrongRef(weakSource);
  265. if (!source) {
  266. return;
  267. }
  268. OBSDataAutoRelease settings = obs_source_get_settings(source);
  269. bool now_active = obs_data_get_bool(settings, "active");
  270. bool desyncedSetting = now_active != active;
  271. active = !active;
  272. const char *text = active ? deactivateText : activateText;
  273. ui->activateButton->setText(text);
  274. if (desyncedSetting) {
  275. return;
  276. }
  277. calldata_t cd = {};
  278. calldata_set_bool(&cd, "active", active);
  279. proc_handler_t *ph = obs_source_get_proc_handler(source);
  280. proc_handler_call(ph, "activate", &cd);
  281. calldata_free(&cd);
  282. }
  283. /* ========================================================================= */
  284. GameCaptureToolbar::GameCaptureToolbar(QWidget *parent, OBSSource source)
  285. : SourceToolbar(parent, source), ui(new Ui_GameCaptureToolbar)
  286. {
  287. obs_property_t *p;
  288. int cur_idx;
  289. ui->setupUi(this);
  290. obs_module_t *mod = obs_get_module("win-capture");
  291. if (!mod)
  292. return;
  293. ui->modeLabel->setText(obs_module_get_locale_text(mod, "Mode"));
  294. ui->windowLabel->setText(
  295. obs_module_get_locale_text(mod, "WindowCapture.Window"));
  296. OBSDataAutoRelease settings = obs_source_get_settings(source);
  297. std::string cur_mode = obs_data_get_string(settings, "capture_mode");
  298. std::string cur_window = obs_data_get_string(settings, "window");
  299. ui->mode->blockSignals(true);
  300. p = obs_properties_get(props.get(), "capture_mode");
  301. cur_idx = FillPropertyCombo(ui->mode, p, cur_mode);
  302. ui->mode->setCurrentIndex(cur_idx);
  303. ui->mode->blockSignals(false);
  304. ui->window->blockSignals(true);
  305. p = obs_properties_get(props.get(), "window");
  306. cur_idx = FillPropertyCombo(ui->window, p, cur_window);
  307. ui->window->setCurrentIndex(cur_idx);
  308. ui->window->blockSignals(false);
  309. if (cur_idx != -1 && obs_property_list_item_disabled(p, cur_idx)) {
  310. SetComboItemEnabled(ui->window, cur_idx, false);
  311. }
  312. UpdateWindowVisibility();
  313. }
  314. GameCaptureToolbar::~GameCaptureToolbar() {}
  315. void GameCaptureToolbar::UpdateWindowVisibility()
  316. {
  317. QString mode = ui->mode->currentData().toString();
  318. bool is_window = (mode == "window");
  319. ui->windowLabel->setVisible(is_window);
  320. ui->window->setVisible(is_window);
  321. }
  322. void GameCaptureToolbar::on_mode_currentIndexChanged(int idx)
  323. {
  324. OBSSource source = GetSource();
  325. if (idx == -1 || !source) {
  326. return;
  327. }
  328. QString id = ui->mode->itemData(idx).toString();
  329. SaveOldProperties(source);
  330. OBSDataAutoRelease settings = obs_data_create();
  331. obs_data_set_string(settings, "capture_mode", QT_TO_UTF8(id));
  332. obs_source_update(source, settings);
  333. SetUndoProperties(source);
  334. UpdateWindowVisibility();
  335. }
  336. void GameCaptureToolbar::on_window_currentIndexChanged(int idx)
  337. {
  338. OBSSource source = GetSource();
  339. if (idx == -1 || !source) {
  340. return;
  341. }
  342. QString id = ui->window->itemData(idx).toString();
  343. SaveOldProperties(source);
  344. OBSDataAutoRelease settings = obs_data_create();
  345. obs_data_set_string(settings, "window", QT_TO_UTF8(id));
  346. obs_source_update(source, settings);
  347. SetUndoProperties(source);
  348. }
  349. /* ========================================================================= */
  350. ImageSourceToolbar::ImageSourceToolbar(QWidget *parent, OBSSource source)
  351. : SourceToolbar(parent, source), ui(new Ui_ImageSourceToolbar)
  352. {
  353. ui->setupUi(this);
  354. obs_module_t *mod = obs_get_module("image-source");
  355. ui->pathLabel->setText(obs_module_get_locale_text(mod, "File"));
  356. OBSDataAutoRelease settings = obs_source_get_settings(source);
  357. std::string file = obs_data_get_string(settings, "file");
  358. ui->path->setText(file.c_str());
  359. }
  360. ImageSourceToolbar::~ImageSourceToolbar() {}
  361. void ImageSourceToolbar::on_browse_clicked()
  362. {
  363. OBSSource source = GetSource();
  364. if (!source) {
  365. return;
  366. }
  367. obs_property_t *p = obs_properties_get(props.get(), "file");
  368. const char *desc = obs_property_description(p);
  369. const char *filter = obs_property_path_filter(p);
  370. const char *default_path = obs_property_path_default_path(p);
  371. QString path = OpenFile(this, desc, default_path, filter);
  372. if (path.isEmpty()) {
  373. return;
  374. }
  375. ui->path->setText(path);
  376. SaveOldProperties(source);
  377. OBSDataAutoRelease settings = obs_data_create();
  378. obs_data_set_string(settings, "file", QT_TO_UTF8(path));
  379. obs_source_update(source, settings);
  380. SetUndoProperties(source);
  381. }
  382. /* ========================================================================= */
  383. static inline QColor color_from_int(long long val)
  384. {
  385. return QColor(val & 0xff, (val >> 8) & 0xff, (val >> 16) & 0xff,
  386. (val >> 24) & 0xff);
  387. }
  388. static inline long long color_to_int(QColor color)
  389. {
  390. auto shift = [&](unsigned val, int shift) {
  391. return ((val & 0xff) << shift);
  392. };
  393. return shift(color.red(), 0) | shift(color.green(), 8) |
  394. shift(color.blue(), 16) | shift(color.alpha(), 24);
  395. }
  396. ColorSourceToolbar::ColorSourceToolbar(QWidget *parent, OBSSource source)
  397. : SourceToolbar(parent, source), ui(new Ui_ColorSourceToolbar)
  398. {
  399. ui->setupUi(this);
  400. OBSDataAutoRelease settings = obs_source_get_settings(source);
  401. unsigned int val = (unsigned int)obs_data_get_int(settings, "color");
  402. color = color_from_int(val);
  403. UpdateColor();
  404. }
  405. ColorSourceToolbar::~ColorSourceToolbar() {}
  406. void ColorSourceToolbar::UpdateColor()
  407. {
  408. QPalette palette = QPalette(color);
  409. ui->color->setFrameStyle(QFrame::Sunken | QFrame::Panel);
  410. ui->color->setText(color.name(QColor::HexRgb));
  411. ui->color->setPalette(palette);
  412. ui->color->setStyleSheet(
  413. QString("background-color :%1; color: %2;")
  414. .arg(palette.color(QPalette::Window)
  415. .name(QColor::HexRgb))
  416. .arg(palette.color(QPalette::WindowText)
  417. .name(QColor::HexRgb)));
  418. ui->color->setAutoFillBackground(true);
  419. ui->color->setAlignment(Qt::AlignCenter);
  420. }
  421. void ColorSourceToolbar::on_choose_clicked()
  422. {
  423. OBSSource source = GetSource();
  424. if (!source) {
  425. return;
  426. }
  427. obs_property_t *p = obs_properties_get(props.get(), "color");
  428. const char *desc = obs_property_description(p);
  429. QColorDialog::ColorDialogOptions options;
  430. options |= QColorDialog::ShowAlphaChannel;
  431. #ifndef _WIN32
  432. options |= QColorDialog::DontUseNativeDialog;
  433. #endif
  434. QColor newColor = QColorDialog::getColor(color, this, desc, options);
  435. if (!newColor.isValid()) {
  436. return;
  437. }
  438. color = newColor;
  439. UpdateColor();
  440. SaveOldProperties(source);
  441. OBSDataAutoRelease settings = obs_data_create();
  442. obs_data_set_int(settings, "color", color_to_int(color));
  443. obs_source_update(source, settings);
  444. SetUndoProperties(source);
  445. }
  446. /* ========================================================================= */
  447. extern void MakeQFont(obs_data_t *font_obj, QFont &font, bool limit = false);
  448. TextSourceToolbar::TextSourceToolbar(QWidget *parent, OBSSource source)
  449. : SourceToolbar(parent, source), ui(new Ui_TextSourceToolbar)
  450. {
  451. ui->setupUi(this);
  452. OBSDataAutoRelease settings = obs_source_get_settings(source);
  453. const char *id = obs_source_get_unversioned_id(source);
  454. bool ft2 = strcmp(id, "text_ft2_source") == 0;
  455. bool read_from_file = obs_data_get_bool(
  456. settings, ft2 ? "from_file" : "read_from_file");
  457. OBSDataAutoRelease font_obj = obs_data_get_obj(settings, "font");
  458. MakeQFont(font_obj, font);
  459. // Use "color1" if it's a freetype source and "color" elsewise
  460. unsigned int val = (unsigned int)obs_data_get_int(
  461. settings,
  462. (strncmp(obs_source_get_id(source), "text_ft2_source", 15) == 0)
  463. ? "color1"
  464. : "color");
  465. color = color_from_int(val);
  466. const char *text = obs_data_get_string(settings, "text");
  467. bool single_line = !read_from_file &&
  468. (!text || (strchr(text, '\n') == nullptr));
  469. ui->emptySpace->setVisible(!single_line);
  470. ui->text->setVisible(single_line);
  471. if (single_line)
  472. ui->text->setText(text);
  473. }
  474. TextSourceToolbar::~TextSourceToolbar() {}
  475. void TextSourceToolbar::on_selectFont_clicked()
  476. {
  477. OBSSource source = GetSource();
  478. if (!source) {
  479. return;
  480. }
  481. QFontDialog::FontDialogOptions options;
  482. uint32_t flags;
  483. bool success;
  484. #ifndef _WIN32
  485. options = QFontDialog::DontUseNativeDialog;
  486. #endif
  487. font = QFontDialog::getFont(&success, font, this, "Pick a Font",
  488. options);
  489. if (!success) {
  490. return;
  491. }
  492. OBSDataAutoRelease font_obj = obs_data_create();
  493. obs_data_set_string(font_obj, "face", QT_TO_UTF8(font.family()));
  494. obs_data_set_string(font_obj, "style", QT_TO_UTF8(font.styleName()));
  495. obs_data_set_int(font_obj, "size", font.pointSize());
  496. flags = font.bold() ? OBS_FONT_BOLD : 0;
  497. flags |= font.italic() ? OBS_FONT_ITALIC : 0;
  498. flags |= font.underline() ? OBS_FONT_UNDERLINE : 0;
  499. flags |= font.strikeOut() ? OBS_FONT_STRIKEOUT : 0;
  500. obs_data_set_int(font_obj, "flags", flags);
  501. SaveOldProperties(source);
  502. OBSDataAutoRelease settings = obs_data_create();
  503. obs_data_set_obj(settings, "font", font_obj);
  504. obs_source_update(source, settings);
  505. SetUndoProperties(source);
  506. }
  507. void TextSourceToolbar::on_selectColor_clicked()
  508. {
  509. OBSSource source = GetSource();
  510. if (!source) {
  511. return;
  512. }
  513. bool freetype =
  514. strncmp(obs_source_get_id(source), "text_ft2_source", 15) == 0;
  515. obs_property_t *p =
  516. obs_properties_get(props.get(), freetype ? "color1" : "color");
  517. const char *desc = obs_property_description(p);
  518. QColorDialog::ColorDialogOptions options;
  519. options |= QColorDialog::ShowAlphaChannel;
  520. #ifndef _WIN32
  521. options |= QColorDialog::DontUseNativeDialog;
  522. #endif
  523. QColor newColor = QColorDialog::getColor(color, this, desc, options);
  524. if (!newColor.isValid()) {
  525. return;
  526. }
  527. color = newColor;
  528. SaveOldProperties(source);
  529. OBSDataAutoRelease settings = obs_data_create();
  530. if (freetype) {
  531. obs_data_set_int(settings, "color1", color_to_int(color));
  532. obs_data_set_int(settings, "color2", color_to_int(color));
  533. } else {
  534. obs_data_set_int(settings, "color", color_to_int(color));
  535. }
  536. obs_source_update(source, settings);
  537. SetUndoProperties(source);
  538. }
  539. void TextSourceToolbar::on_text_textChanged()
  540. {
  541. OBSSource source = GetSource();
  542. if (!source) {
  543. return;
  544. }
  545. SaveOldProperties(source);
  546. OBSDataAutoRelease settings = obs_data_create();
  547. obs_data_set_string(settings, "text", QT_TO_UTF8(ui->text->text()));
  548. obs_source_update(source, settings);
  549. SetUndoProperties(source, true);
  550. }