context-bar-controls.cpp 18 KB

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