context-bar-controls.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. const char *device_str =
  189. get_os_text(mod, "Device", "CoreAudio.Device", "Device");
  190. ui->deviceLabel->setText(device_str);
  191. prop_name = "device_id";
  192. ComboSelectToolbar::Init();
  193. }
  194. WindowCaptureToolbar::WindowCaptureToolbar(QWidget *parent, OBSSource source)
  195. : ComboSelectToolbar(parent, source)
  196. {
  197. }
  198. void WindowCaptureToolbar::Init()
  199. {
  200. delete ui->activateButton;
  201. ui->activateButton = nullptr;
  202. obs_module_t *mod =
  203. get_os_module("win-capture", "mac-capture", "linux-capture");
  204. if (!mod)
  205. return;
  206. const char *device_str = get_os_text(mod, "WindowCapture.Window",
  207. "WindowUtils.Window", "Window");
  208. ui->deviceLabel->setText(device_str);
  209. #if !defined(_WIN32) && !defined(__APPLE__) //linux
  210. prop_name = "capture_window";
  211. #else
  212. prop_name = "window";
  213. #endif
  214. #ifdef __APPLE__
  215. is_int = true;
  216. #endif
  217. ComboSelectToolbar::Init();
  218. }
  219. DisplayCaptureToolbar::DisplayCaptureToolbar(QWidget *parent, OBSSource source)
  220. : ComboSelectToolbar(parent, source)
  221. {
  222. }
  223. void DisplayCaptureToolbar::Init()
  224. {
  225. delete ui->activateButton;
  226. ui->activateButton = nullptr;
  227. obs_module_t *mod =
  228. get_os_module("win-capture", "mac-capture", "linux-capture");
  229. if (!mod)
  230. return;
  231. const char *device_str =
  232. get_os_text(mod, "Monitor", "DisplayCapture.Display", "Screen");
  233. ui->deviceLabel->setText(device_str);
  234. is_int = true;
  235. #ifdef _WIN32
  236. prop_name = "monitor";
  237. #elif __APPLE__
  238. prop_name = "display";
  239. #else
  240. prop_name = "screen";
  241. #endif
  242. ComboSelectToolbar::Init();
  243. }
  244. /* ========================================================================= */
  245. DeviceCaptureToolbar::DeviceCaptureToolbar(QWidget *parent, OBSSource source)
  246. : QWidget(parent),
  247. weakSource(OBSGetWeakRef(source)),
  248. ui(new Ui_DeviceSelectToolbar)
  249. {
  250. ui->setupUi(this);
  251. delete ui->deviceLabel;
  252. delete ui->device;
  253. ui->deviceLabel = nullptr;
  254. ui->device = nullptr;
  255. OBSDataAutoRelease settings = obs_source_get_settings(source);
  256. active = obs_data_get_bool(settings, "active");
  257. obs_module_t *mod = obs_get_module("win-dshow");
  258. if (!mod)
  259. return;
  260. activateText = obs_module_get_locale_text(mod, "Activate");
  261. deactivateText = obs_module_get_locale_text(mod, "Deactivate");
  262. ui->activateButton->setText(active ? deactivateText : activateText);
  263. }
  264. DeviceCaptureToolbar::~DeviceCaptureToolbar() {}
  265. void DeviceCaptureToolbar::on_activateButton_clicked()
  266. {
  267. OBSSource source = OBSGetStrongRef(weakSource);
  268. if (!source) {
  269. return;
  270. }
  271. OBSDataAutoRelease settings = obs_source_get_settings(source);
  272. bool now_active = obs_data_get_bool(settings, "active");
  273. bool desyncedSetting = now_active != active;
  274. active = !active;
  275. const char *text = active ? deactivateText : activateText;
  276. ui->activateButton->setText(text);
  277. if (desyncedSetting) {
  278. return;
  279. }
  280. calldata_t cd = {};
  281. calldata_set_bool(&cd, "active", active);
  282. proc_handler_t *ph = obs_source_get_proc_handler(source);
  283. proc_handler_call(ph, "activate", &cd);
  284. calldata_free(&cd);
  285. }
  286. /* ========================================================================= */
  287. GameCaptureToolbar::GameCaptureToolbar(QWidget *parent, OBSSource source)
  288. : SourceToolbar(parent, source), ui(new Ui_GameCaptureToolbar)
  289. {
  290. obs_property_t *p;
  291. int cur_idx;
  292. ui->setupUi(this);
  293. obs_module_t *mod = obs_get_module("win-capture");
  294. if (!mod)
  295. return;
  296. ui->modeLabel->setText(obs_module_get_locale_text(mod, "Mode"));
  297. ui->windowLabel->setText(
  298. obs_module_get_locale_text(mod, "WindowCapture.Window"));
  299. OBSDataAutoRelease settings = obs_source_get_settings(source);
  300. std::string cur_mode = obs_data_get_string(settings, "capture_mode");
  301. std::string cur_window = obs_data_get_string(settings, "window");
  302. ui->mode->blockSignals(true);
  303. p = obs_properties_get(props.get(), "capture_mode");
  304. cur_idx = FillPropertyCombo(ui->mode, p, cur_mode);
  305. ui->mode->setCurrentIndex(cur_idx);
  306. ui->mode->blockSignals(false);
  307. ui->window->blockSignals(true);
  308. p = obs_properties_get(props.get(), "window");
  309. cur_idx = FillPropertyCombo(ui->window, p, cur_window);
  310. ui->window->setCurrentIndex(cur_idx);
  311. ui->window->blockSignals(false);
  312. if (cur_idx != -1 && obs_property_list_item_disabled(p, cur_idx)) {
  313. SetComboItemEnabled(ui->window, cur_idx, false);
  314. }
  315. UpdateWindowVisibility();
  316. }
  317. GameCaptureToolbar::~GameCaptureToolbar() {}
  318. void GameCaptureToolbar::UpdateWindowVisibility()
  319. {
  320. QString mode = ui->mode->currentData().toString();
  321. bool is_window = (mode == "window");
  322. ui->windowLabel->setVisible(is_window);
  323. ui->window->setVisible(is_window);
  324. }
  325. void GameCaptureToolbar::on_mode_currentIndexChanged(int idx)
  326. {
  327. OBSSource source = GetSource();
  328. if (idx == -1 || !source) {
  329. return;
  330. }
  331. QString id = ui->mode->itemData(idx).toString();
  332. SaveOldProperties(source);
  333. OBSDataAutoRelease settings = obs_data_create();
  334. obs_data_set_string(settings, "capture_mode", QT_TO_UTF8(id));
  335. obs_source_update(source, settings);
  336. SetUndoProperties(source);
  337. UpdateWindowVisibility();
  338. }
  339. void GameCaptureToolbar::on_window_currentIndexChanged(int idx)
  340. {
  341. OBSSource source = GetSource();
  342. if (idx == -1 || !source) {
  343. return;
  344. }
  345. QString id = ui->window->itemData(idx).toString();
  346. SaveOldProperties(source);
  347. OBSDataAutoRelease settings = obs_data_create();
  348. obs_data_set_string(settings, "window", QT_TO_UTF8(id));
  349. obs_source_update(source, settings);
  350. SetUndoProperties(source);
  351. }
  352. /* ========================================================================= */
  353. ImageSourceToolbar::ImageSourceToolbar(QWidget *parent, OBSSource source)
  354. : SourceToolbar(parent, source), ui(new Ui_ImageSourceToolbar)
  355. {
  356. ui->setupUi(this);
  357. obs_module_t *mod = obs_get_module("image-source");
  358. ui->pathLabel->setText(obs_module_get_locale_text(mod, "File"));
  359. OBSDataAutoRelease settings = obs_source_get_settings(source);
  360. std::string file = obs_data_get_string(settings, "file");
  361. ui->path->setText(file.c_str());
  362. }
  363. ImageSourceToolbar::~ImageSourceToolbar() {}
  364. void ImageSourceToolbar::on_browse_clicked()
  365. {
  366. OBSSource source = GetSource();
  367. if (!source) {
  368. return;
  369. }
  370. obs_property_t *p = obs_properties_get(props.get(), "file");
  371. const char *desc = obs_property_description(p);
  372. const char *filter = obs_property_path_filter(p);
  373. const char *default_path = obs_property_path_default_path(p);
  374. QString path = OpenFile(this, desc, default_path, filter);
  375. if (path.isEmpty()) {
  376. return;
  377. }
  378. ui->path->setText(path);
  379. SaveOldProperties(source);
  380. OBSDataAutoRelease settings = obs_data_create();
  381. obs_data_set_string(settings, "file", QT_TO_UTF8(path));
  382. obs_source_update(source, settings);
  383. SetUndoProperties(source);
  384. }
  385. /* ========================================================================= */
  386. static inline QColor color_from_int(long long val)
  387. {
  388. return QColor(val & 0xff, (val >> 8) & 0xff, (val >> 16) & 0xff,
  389. (val >> 24) & 0xff);
  390. }
  391. static inline long long color_to_int(QColor color)
  392. {
  393. auto shift = [&](unsigned val, int shift) {
  394. return ((val & 0xff) << shift);
  395. };
  396. return shift(color.red(), 0) | shift(color.green(), 8) |
  397. shift(color.blue(), 16) | shift(color.alpha(), 24);
  398. }
  399. ColorSourceToolbar::ColorSourceToolbar(QWidget *parent, OBSSource source)
  400. : SourceToolbar(parent, source), ui(new Ui_ColorSourceToolbar)
  401. {
  402. ui->setupUi(this);
  403. OBSDataAutoRelease settings = obs_source_get_settings(source);
  404. unsigned int val = (unsigned int)obs_data_get_int(settings, "color");
  405. color = color_from_int(val);
  406. UpdateColor();
  407. }
  408. ColorSourceToolbar::~ColorSourceToolbar() {}
  409. void ColorSourceToolbar::UpdateColor()
  410. {
  411. QPalette palette = QPalette(color);
  412. ui->color->setFrameStyle(QFrame::Sunken | QFrame::Panel);
  413. ui->color->setText(color.name(QColor::HexRgb));
  414. ui->color->setPalette(palette);
  415. ui->color->setStyleSheet(
  416. QString("background-color :%1; color: %2;")
  417. .arg(palette.color(QPalette::Window)
  418. .name(QColor::HexRgb))
  419. .arg(palette.color(QPalette::WindowText)
  420. .name(QColor::HexRgb)));
  421. ui->color->setAutoFillBackground(true);
  422. ui->color->setAlignment(Qt::AlignCenter);
  423. }
  424. void ColorSourceToolbar::on_choose_clicked()
  425. {
  426. OBSSource source = GetSource();
  427. if (!source) {
  428. return;
  429. }
  430. obs_property_t *p = obs_properties_get(props.get(), "color");
  431. const char *desc = obs_property_description(p);
  432. QColorDialog::ColorDialogOptions options;
  433. options |= QColorDialog::ShowAlphaChannel;
  434. #ifndef _WIN32
  435. options |= QColorDialog::DontUseNativeDialog;
  436. #endif
  437. QColor newColor = QColorDialog::getColor(color, this, desc, options);
  438. if (!newColor.isValid()) {
  439. return;
  440. }
  441. color = newColor;
  442. UpdateColor();
  443. SaveOldProperties(source);
  444. OBSDataAutoRelease settings = obs_data_create();
  445. obs_data_set_int(settings, "color", color_to_int(color));
  446. obs_source_update(source, settings);
  447. SetUndoProperties(source);
  448. }
  449. /* ========================================================================= */
  450. extern void MakeQFont(obs_data_t *font_obj, QFont &font, bool limit = false);
  451. TextSourceToolbar::TextSourceToolbar(QWidget *parent, OBSSource source)
  452. : SourceToolbar(parent, source), ui(new Ui_TextSourceToolbar)
  453. {
  454. ui->setupUi(this);
  455. OBSDataAutoRelease settings = obs_source_get_settings(source);
  456. const char *id = obs_source_get_unversioned_id(source);
  457. bool ft2 = strcmp(id, "text_ft2_source") == 0;
  458. bool read_from_file = obs_data_get_bool(
  459. settings, ft2 ? "from_file" : "read_from_file");
  460. OBSDataAutoRelease font_obj = obs_data_get_obj(settings, "font");
  461. MakeQFont(font_obj, font);
  462. // Use "color1" if it's a freetype source and "color" elsewise
  463. unsigned int val = (unsigned int)obs_data_get_int(
  464. settings,
  465. (strncmp(obs_source_get_id(source), "text_ft2_source", 15) == 0)
  466. ? "color1"
  467. : "color");
  468. color = color_from_int(val);
  469. const char *text = obs_data_get_string(settings, "text");
  470. bool single_line = !read_from_file &&
  471. (!text || (strchr(text, '\n') == nullptr));
  472. ui->emptySpace->setVisible(!single_line);
  473. ui->text->setVisible(single_line);
  474. if (single_line)
  475. ui->text->setText(text);
  476. }
  477. TextSourceToolbar::~TextSourceToolbar() {}
  478. void TextSourceToolbar::on_selectFont_clicked()
  479. {
  480. OBSSource source = GetSource();
  481. if (!source) {
  482. return;
  483. }
  484. QFontDialog::FontDialogOptions options;
  485. uint32_t flags;
  486. bool success;
  487. #ifndef _WIN32
  488. options = QFontDialog::DontUseNativeDialog;
  489. #endif
  490. font = QFontDialog::getFont(&success, font, this, "Pick a Font",
  491. options);
  492. if (!success) {
  493. return;
  494. }
  495. OBSDataAutoRelease font_obj = obs_data_create();
  496. obs_data_set_string(font_obj, "face", QT_TO_UTF8(font.family()));
  497. obs_data_set_string(font_obj, "style", QT_TO_UTF8(font.styleName()));
  498. obs_data_set_int(font_obj, "size", font.pointSize());
  499. flags = font.bold() ? OBS_FONT_BOLD : 0;
  500. flags |= font.italic() ? OBS_FONT_ITALIC : 0;
  501. flags |= font.underline() ? OBS_FONT_UNDERLINE : 0;
  502. flags |= font.strikeOut() ? OBS_FONT_STRIKEOUT : 0;
  503. obs_data_set_int(font_obj, "flags", flags);
  504. SaveOldProperties(source);
  505. OBSDataAutoRelease settings = obs_data_create();
  506. obs_data_set_obj(settings, "font", font_obj);
  507. obs_source_update(source, settings);
  508. SetUndoProperties(source);
  509. }
  510. void TextSourceToolbar::on_selectColor_clicked()
  511. {
  512. OBSSource source = GetSource();
  513. if (!source) {
  514. return;
  515. }
  516. bool freetype =
  517. strncmp(obs_source_get_id(source), "text_ft2_source", 15) == 0;
  518. obs_property_t *p =
  519. obs_properties_get(props.get(), freetype ? "color1" : "color");
  520. const char *desc = obs_property_description(p);
  521. QColorDialog::ColorDialogOptions options;
  522. options |= QColorDialog::ShowAlphaChannel;
  523. #ifndef _WIN32
  524. options |= QColorDialog::DontUseNativeDialog;
  525. #endif
  526. QColor newColor = QColorDialog::getColor(color, this, desc, options);
  527. if (!newColor.isValid()) {
  528. return;
  529. }
  530. color = newColor;
  531. SaveOldProperties(source);
  532. OBSDataAutoRelease settings = obs_data_create();
  533. if (freetype) {
  534. obs_data_set_int(settings, "color1", color_to_int(color));
  535. obs_data_set_int(settings, "color2", color_to_int(color));
  536. } else {
  537. obs_data_set_int(settings, "color", color_to_int(color));
  538. }
  539. obs_source_update(source, settings);
  540. SetUndoProperties(source);
  541. }
  542. void TextSourceToolbar::on_text_textChanged()
  543. {
  544. OBSSource source = GetSource();
  545. if (!source) {
  546. return;
  547. }
  548. SaveOldProperties(source);
  549. OBSDataAutoRelease settings = obs_data_create();
  550. obs_data_set_string(settings, "text", QT_TO_UTF8(ui->text->text()));
  551. obs_source_update(source, settings);
  552. SetUndoProperties(source, true);
  553. }