context-bar-controls.cpp 18 KB

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