context-bar-controls.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. 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. options |= QColorDialog::ShowAlphaChannel;
  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. // Use "color1" if it's a freetype source and "color" elsewise
  490. unsigned int val = (unsigned int)obs_data_get_int(
  491. settings,
  492. (strncmp(obs_source_get_id(source), "text_ft2_source", 15) == 0)
  493. ? "color1"
  494. : "color");
  495. color = color_from_int(val);
  496. const char *text = obs_data_get_string(settings, "text");
  497. bool single_line = !read_from_file &&
  498. (!text || (strchr(text, '\n') == nullptr));
  499. ui->emptySpace->setVisible(!single_line);
  500. ui->text->setVisible(single_line);
  501. if (single_line)
  502. ui->text->setText(text);
  503. obs_data_release(settings);
  504. }
  505. TextSourceToolbar::~TextSourceToolbar()
  506. {
  507. delete ui;
  508. }
  509. void TextSourceToolbar::on_selectFont_clicked()
  510. {
  511. OBSSource source = GetSource();
  512. if (!source) {
  513. return;
  514. }
  515. QFontDialog::FontDialogOptions options;
  516. uint32_t flags;
  517. bool success;
  518. #ifndef _WIN32
  519. options = QFontDialog::DontUseNativeDialog;
  520. #endif
  521. font = QFontDialog::getFont(&success, font, this, "Pick a Font",
  522. options);
  523. if (!success) {
  524. return;
  525. }
  526. obs_data_t *font_obj = obs_data_create();
  527. obs_data_set_string(font_obj, "face", QT_TO_UTF8(font.family()));
  528. obs_data_set_string(font_obj, "style", QT_TO_UTF8(font.styleName()));
  529. obs_data_set_int(font_obj, "size", font.pointSize());
  530. flags = font.bold() ? OBS_FONT_BOLD : 0;
  531. flags |= font.italic() ? OBS_FONT_ITALIC : 0;
  532. flags |= font.underline() ? OBS_FONT_UNDERLINE : 0;
  533. flags |= font.strikeOut() ? OBS_FONT_STRIKEOUT : 0;
  534. obs_data_set_int(font_obj, "flags", flags);
  535. SaveOldProperties(source);
  536. obs_data_t *settings = obs_data_create();
  537. obs_data_set_obj(settings, "font", font_obj);
  538. obs_data_release(font_obj);
  539. obs_source_update(source, settings);
  540. obs_data_release(settings);
  541. SetUndoProperties(source);
  542. }
  543. void TextSourceToolbar::on_selectColor_clicked()
  544. {
  545. OBSSource source = GetSource();
  546. if (!source) {
  547. return;
  548. }
  549. bool freetype =
  550. strncmp(obs_source_get_id(source), "text_ft2_source", 15) == 0;
  551. obs_property_t *p =
  552. obs_properties_get(props.get(), freetype ? "color1" : "color");
  553. const char *desc = obs_property_description(p);
  554. QColorDialog::ColorDialogOptions options;
  555. options |= QColorDialog::ShowAlphaChannel;
  556. #ifndef _WIN32
  557. options |= QColorDialog::DontUseNativeDialog;
  558. #endif
  559. QColor newColor = QColorDialog::getColor(color, this, desc, options);
  560. if (!newColor.isValid()) {
  561. return;
  562. }
  563. color = newColor;
  564. SaveOldProperties(source);
  565. obs_data_t *settings = obs_data_create();
  566. if (freetype) {
  567. obs_data_set_int(settings, "color1", color_to_int(color));
  568. obs_data_set_int(settings, "color2", color_to_int(color));
  569. } else {
  570. obs_data_set_int(settings, "color", color_to_int(color));
  571. }
  572. obs_source_update(source, settings);
  573. obs_data_release(settings);
  574. SetUndoProperties(source);
  575. }
  576. void TextSourceToolbar::on_text_textChanged()
  577. {
  578. OBSSource source = GetSource();
  579. if (!source) {
  580. return;
  581. }
  582. obs_data_t *settings = obs_data_create();
  583. obs_data_set_string(settings, "text", QT_TO_UTF8(ui->text->text()));
  584. obs_source_update(source, settings);
  585. obs_data_release(settings);
  586. }