context-bar-controls.cpp 18 KB

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