context-bar-controls.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. }
  339. void GameCaptureToolbar::on_mode_currentIndexChanged(int idx)
  340. {
  341. OBSSource source = GetSource();
  342. if (idx == -1 || !source) {
  343. return;
  344. }
  345. QString id = ui->mode->itemData(idx).toString();
  346. SaveOldProperties(source);
  347. obs_data_t *settings = obs_data_create();
  348. obs_data_set_string(settings, "capture_mode", QT_TO_UTF8(id));
  349. obs_source_update(source, settings);
  350. obs_data_release(settings);
  351. SetUndoProperties(source);
  352. UpdateWindowVisibility();
  353. }
  354. void GameCaptureToolbar::on_window_currentIndexChanged(int idx)
  355. {
  356. OBSSource source = GetSource();
  357. if (idx == -1 || !source) {
  358. return;
  359. }
  360. QString id = ui->window->itemData(idx).toString();
  361. SaveOldProperties(source);
  362. obs_data_t *settings = obs_data_create();
  363. obs_data_set_string(settings, "window", QT_TO_UTF8(id));
  364. obs_source_update(source, settings);
  365. obs_data_release(settings);
  366. SetUndoProperties(source);
  367. }
  368. /* ========================================================================= */
  369. ImageSourceToolbar::ImageSourceToolbar(QWidget *parent, OBSSource source)
  370. : SourceToolbar(parent, source), ui(new Ui_ImageSourceToolbar)
  371. {
  372. ui->setupUi(this);
  373. obs_module_t *mod = obs_get_module("image-source");
  374. ui->pathLabel->setText(obs_module_get_locale_text(mod, "File"));
  375. obs_data_t *settings = obs_source_get_settings(source);
  376. std::string file = obs_data_get_string(settings, "file");
  377. obs_data_release(settings);
  378. ui->path->setText(file.c_str());
  379. }
  380. ImageSourceToolbar::~ImageSourceToolbar()
  381. {
  382. delete ui;
  383. }
  384. void ImageSourceToolbar::on_browse_clicked()
  385. {
  386. OBSSource source = GetSource();
  387. if (!source) {
  388. return;
  389. }
  390. obs_property_t *p = obs_properties_get(props.get(), "file");
  391. const char *desc = obs_property_description(p);
  392. const char *filter = obs_property_path_filter(p);
  393. const char *default_path = obs_property_path_default_path(p);
  394. QString path = OpenFile(this, desc, default_path, filter);
  395. if (path.isEmpty()) {
  396. return;
  397. }
  398. ui->path->setText(path);
  399. SaveOldProperties(source);
  400. obs_data_t *settings = obs_data_create();
  401. obs_data_set_string(settings, "file", QT_TO_UTF8(path));
  402. obs_source_update(source, settings);
  403. obs_data_release(settings);
  404. SetUndoProperties(source);
  405. }
  406. /* ========================================================================= */
  407. static inline QColor color_from_int(long long val)
  408. {
  409. return QColor(val & 0xff, (val >> 8) & 0xff, (val >> 16) & 0xff,
  410. (val >> 24) & 0xff);
  411. }
  412. static inline long long color_to_int(QColor color)
  413. {
  414. auto shift = [&](unsigned val, int shift) {
  415. return ((val & 0xff) << shift);
  416. };
  417. return shift(color.red(), 0) | shift(color.green(), 8) |
  418. shift(color.blue(), 16) | shift(color.alpha(), 24);
  419. }
  420. ColorSourceToolbar::ColorSourceToolbar(QWidget *parent, OBSSource source)
  421. : SourceToolbar(parent, source), ui(new Ui_ColorSourceToolbar)
  422. {
  423. ui->setupUi(this);
  424. obs_data_t *settings = obs_source_get_settings(source);
  425. unsigned int val = (unsigned int)obs_data_get_int(settings, "color");
  426. obs_data_release(settings);
  427. color = color_from_int(val);
  428. UpdateColor();
  429. }
  430. ColorSourceToolbar::~ColorSourceToolbar()
  431. {
  432. delete ui;
  433. }
  434. void ColorSourceToolbar::UpdateColor()
  435. {
  436. color.setAlpha(255);
  437. QPalette palette = QPalette(color);
  438. ui->color->setFrameStyle(QFrame::Sunken | QFrame::Panel);
  439. ui->color->setText(color.name(QColor::HexRgb));
  440. ui->color->setPalette(palette);
  441. ui->color->setStyleSheet(
  442. QString("background-color :%1; color: %2;")
  443. .arg(palette.color(QPalette::Window)
  444. .name(QColor::HexRgb))
  445. .arg(palette.color(QPalette::WindowText)
  446. .name(QColor::HexRgb)));
  447. ui->color->setAutoFillBackground(true);
  448. ui->color->setAlignment(Qt::AlignCenter);
  449. }
  450. void ColorSourceToolbar::on_choose_clicked()
  451. {
  452. OBSSource source = GetSource();
  453. if (!source) {
  454. return;
  455. }
  456. obs_property_t *p = obs_properties_get(props.get(), "color");
  457. const char *desc = obs_property_description(p);
  458. QColorDialog::ColorDialogOptions options;
  459. #ifndef _WIN32
  460. options |= QColorDialog::DontUseNativeDialog;
  461. #endif
  462. QColor newColor = QColorDialog::getColor(color, this, desc, options);
  463. if (!newColor.isValid()) {
  464. return;
  465. }
  466. color = newColor;
  467. UpdateColor();
  468. SaveOldProperties(source);
  469. obs_data_t *settings = obs_data_create();
  470. obs_data_set_int(settings, "color", color_to_int(color));
  471. obs_source_update(source, settings);
  472. obs_data_release(settings);
  473. SetUndoProperties(source);
  474. }
  475. /* ========================================================================= */
  476. extern void MakeQFont(obs_data_t *font_obj, QFont &font, bool limit = false);
  477. TextSourceToolbar::TextSourceToolbar(QWidget *parent, OBSSource source)
  478. : SourceToolbar(parent, source), ui(new Ui_TextSourceToolbar)
  479. {
  480. ui->setupUi(this);
  481. obs_data_t *settings = obs_source_get_settings(source);
  482. const char *id = obs_source_get_unversioned_id(source);
  483. bool ft2 = strcmp(id, "text_ft2_source") == 0;
  484. bool read_from_file = obs_data_get_bool(
  485. settings, ft2 ? "from_file" : "read_from_file");
  486. obs_data_t *font_obj = obs_data_get_obj(settings, "font");
  487. MakeQFont(font_obj, font);
  488. obs_data_release(font_obj);
  489. unsigned int val = (unsigned int)obs_data_get_int(settings, "color");
  490. color = color_from_int(val);
  491. const char *text = obs_data_get_string(settings, "text");
  492. bool single_line = !read_from_file &&
  493. (!text || (strchr(text, '\n') == nullptr));
  494. ui->emptySpace->setVisible(!single_line);
  495. ui->text->setVisible(single_line);
  496. if (single_line)
  497. ui->text->setText(text);
  498. obs_data_release(settings);
  499. }
  500. TextSourceToolbar::~TextSourceToolbar()
  501. {
  502. delete ui;
  503. }
  504. void TextSourceToolbar::on_selectFont_clicked()
  505. {
  506. OBSSource source = GetSource();
  507. if (!source) {
  508. return;
  509. }
  510. QFontDialog::FontDialogOptions options;
  511. uint32_t flags;
  512. bool success;
  513. #ifndef _WIN32
  514. options = QFontDialog::DontUseNativeDialog;
  515. #endif
  516. font = QFontDialog::getFont(&success, font, this, "Pick a Font",
  517. options);
  518. if (!success) {
  519. return;
  520. }
  521. obs_data_t *font_obj = obs_data_create();
  522. obs_data_set_string(font_obj, "face", QT_TO_UTF8(font.family()));
  523. obs_data_set_string(font_obj, "style", QT_TO_UTF8(font.styleName()));
  524. obs_data_set_int(font_obj, "size", font.pointSize());
  525. flags = font.bold() ? OBS_FONT_BOLD : 0;
  526. flags |= font.italic() ? OBS_FONT_ITALIC : 0;
  527. flags |= font.underline() ? OBS_FONT_UNDERLINE : 0;
  528. flags |= font.strikeOut() ? OBS_FONT_STRIKEOUT : 0;
  529. obs_data_set_int(font_obj, "flags", flags);
  530. SaveOldProperties(source);
  531. obs_data_t *settings = obs_data_create();
  532. obs_data_set_obj(settings, "font", font_obj);
  533. obs_data_release(font_obj);
  534. obs_source_update(source, settings);
  535. obs_data_release(settings);
  536. SetUndoProperties(source);
  537. }
  538. void TextSourceToolbar::on_selectColor_clicked()
  539. {
  540. OBSSource source = GetSource();
  541. if (!source) {
  542. return;
  543. }
  544. obs_property_t *p = obs_properties_get(props.get(), "color");
  545. const char *desc = obs_property_description(p);
  546. QColorDialog::ColorDialogOptions options;
  547. #ifndef _WIN32
  548. options |= QColorDialog::DontUseNativeDialog;
  549. #endif
  550. QColor newColor = QColorDialog::getColor(color, this, desc, options);
  551. if (!newColor.isValid()) {
  552. return;
  553. }
  554. color = newColor;
  555. SaveOldProperties(source);
  556. obs_data_t *settings = obs_data_create();
  557. if (!strncmp(obs_source_get_id(source), "text_ft2_source", 15)) {
  558. obs_data_set_int(settings, "color1", color_to_int(color));
  559. obs_data_set_int(settings, "color2", color_to_int(color));
  560. } else {
  561. obs_data_set_int(settings, "color", color_to_int(color));
  562. }
  563. obs_source_update(source, settings);
  564. obs_data_release(settings);
  565. SetUndoProperties(source);
  566. }
  567. void TextSourceToolbar::on_text_textChanged()
  568. {
  569. OBSSource source = GetSource();
  570. if (!source) {
  571. return;
  572. }
  573. obs_data_t *settings = obs_data_create();
  574. obs_data_set_string(settings, "text", QT_TO_UTF8(ui->text->text()));
  575. obs_source_update(source, settings);
  576. obs_data_release(settings);
  577. }