properties-view.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. #include <QFormLayout>
  2. #include <QLabel>
  3. #include <QCheckBox>
  4. #include <QFont>
  5. #include <QFontDialog>
  6. #include <QLineEdit>
  7. #include <QSpinBox>
  8. #include <QDoubleSpinBox>
  9. #include <QComboBox>
  10. #include <QPushButton>
  11. #include <QStandardItem>
  12. #include <QFileDialog>
  13. #include <QColorDialog>
  14. #include <QPlainTextEdit>
  15. #include "qt-wrappers.hpp"
  16. #include "properties-view.hpp"
  17. #include "obs-app.hpp"
  18. #include <string>
  19. using namespace std;
  20. static inline QColor color_from_int(long long val)
  21. {
  22. return QColor( val & 0xff,
  23. (val >> 8) & 0xff,
  24. (val >> 16) & 0xff,
  25. (val >> 24) & 0xff);
  26. }
  27. static inline long long color_to_int(QColor color)
  28. {
  29. auto shift = [&](unsigned val, int shift)
  30. {
  31. return ((val & 0xff) << shift);
  32. };
  33. return shift(color.red(), 0) |
  34. shift(color.green(), 8) |
  35. shift(color.blue(), 16) |
  36. shift(color.alpha(), 24);
  37. }
  38. void OBSPropertiesView::RefreshProperties()
  39. {
  40. children.clear();
  41. if (widget)
  42. widget->deleteLater();
  43. widget = new QWidget();
  44. QFormLayout *layout = new QFormLayout;
  45. layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
  46. widget->setLayout(layout);
  47. QSizePolicy mainPolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  48. QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  49. //widget->setSizePolicy(policy);
  50. layout->setSizeConstraint(QLayout::SetMaximumSize);
  51. layout->setLabelAlignment(Qt::AlignRight);
  52. obs_property_t *property = obs_properties_first(properties.get());
  53. while (property) {
  54. AddProperty(property, layout);
  55. obs_property_next(&property);
  56. }
  57. setWidgetResizable(true);
  58. setWidget(widget);
  59. setSizePolicy(mainPolicy);
  60. lastFocused.clear();
  61. if (lastWidget) {
  62. lastWidget->setFocus(Qt::OtherFocusReason);
  63. lastWidget = nullptr;
  64. }
  65. }
  66. OBSPropertiesView::OBSPropertiesView(OBSData settings_,
  67. obs_properties_t *properties_, void *obj_,
  68. PropertiesUpdateCallback callback_, int minSize_)
  69. : QScrollArea (nullptr),
  70. widget (nullptr),
  71. properties (properties_, obs_properties_destroy),
  72. settings (settings_),
  73. obj (obj_),
  74. callback (callback_),
  75. minSize (minSize_),
  76. lastWidget (nullptr)
  77. {
  78. setFrameShape(QFrame::NoFrame);
  79. RefreshProperties();
  80. }
  81. void OBSPropertiesView::resizeEvent(QResizeEvent *event)
  82. {
  83. emit PropertiesResized();
  84. UNUSED_PARAMETER(event);
  85. }
  86. QWidget *OBSPropertiesView::NewWidget(obs_property_t *prop, QWidget *widget,
  87. const char *signal)
  88. {
  89. WidgetInfo *info = new WidgetInfo(this, prop, widget);
  90. connect(widget, signal, info, SLOT(ControlChanged()));
  91. children.push_back(std::move(unique_ptr<WidgetInfo>(info)));
  92. return widget;
  93. }
  94. QWidget *OBSPropertiesView::AddCheckbox(obs_property_t *prop)
  95. {
  96. const char *name = obs_property_name(prop);
  97. const char *desc = obs_property_description(prop);
  98. bool val = obs_data_get_bool(settings, name);
  99. QCheckBox *checkbox = new QCheckBox(QT_UTF8(desc));
  100. checkbox->setCheckState(val ? Qt::Checked : Qt::Unchecked);
  101. return NewWidget(prop, checkbox, SIGNAL(stateChanged(int)));
  102. }
  103. QWidget *OBSPropertiesView::AddText(obs_property_t *prop)
  104. {
  105. const char *name = obs_property_name(prop);
  106. const char *val = obs_data_get_string(settings, name);
  107. obs_text_type type = obs_proprety_text_type(prop);
  108. if (type == OBS_TEXT_MULTILINE) {
  109. QPlainTextEdit *edit = new QPlainTextEdit(QT_UTF8(val));
  110. return NewWidget(prop, edit, SIGNAL(textChanged()));
  111. }
  112. QLineEdit *edit = new QLineEdit();
  113. if (type == OBS_TEXT_PASSWORD)
  114. edit->setEchoMode(QLineEdit::Password);
  115. edit->setText(QT_UTF8(val));
  116. return NewWidget(prop, edit, SIGNAL(textEdited(const QString &)));
  117. }
  118. void OBSPropertiesView::AddPath(obs_property_t *prop, QFormLayout *layout,
  119. QLabel **label)
  120. {
  121. const char *name = obs_property_name(prop);
  122. const char *val = obs_data_get_string(settings, name);
  123. QLayout *subLayout = new QHBoxLayout();
  124. QLineEdit *edit = new QLineEdit();
  125. QPushButton *button = new QPushButton(QTStr("Browse"));
  126. edit->setText(QT_UTF8(val));
  127. edit->setReadOnly(true);
  128. subLayout->addWidget(edit);
  129. subLayout->addWidget(button);
  130. WidgetInfo *info = new WidgetInfo(this, prop, edit);
  131. connect(button, SIGNAL(clicked()), info, SLOT(ControlChanged()));
  132. children.push_back(std::move(unique_ptr<WidgetInfo>(info)));
  133. *label = new QLabel(QT_UTF8(obs_property_description(prop)));
  134. layout->addRow(*label, subLayout);
  135. }
  136. QWidget *OBSPropertiesView::AddInt(obs_property_t *prop)
  137. {
  138. const char *name = obs_property_name(prop);
  139. int val = (int)obs_data_get_int(settings, name);
  140. QSpinBox *spin = new QSpinBox();
  141. spin->setMinimum(obs_property_int_min(prop));
  142. spin->setMaximum(obs_property_int_max(prop));
  143. spin->setSingleStep(obs_property_int_step(prop));
  144. spin->setValue(val);
  145. return NewWidget(prop, spin, SIGNAL(valueChanged(int)));
  146. }
  147. QWidget *OBSPropertiesView::AddFloat(obs_property_t *prop)
  148. {
  149. const char *name = obs_property_name(prop);
  150. double val = obs_data_get_double(settings, name);
  151. QDoubleSpinBox *spin = new QDoubleSpinBox();
  152. spin->setMinimum(obs_property_float_min(prop));
  153. spin->setMaximum(obs_property_float_max(prop));
  154. spin->setSingleStep(obs_property_float_step(prop));
  155. spin->setValue(val);
  156. return NewWidget(prop, spin, SIGNAL(valueChanged(double)));
  157. }
  158. static void AddComboItem(QComboBox *combo, obs_property_t *prop,
  159. obs_combo_format format, size_t idx)
  160. {
  161. const char *name = obs_property_list_item_name(prop, idx);
  162. QVariant var;
  163. if (format == OBS_COMBO_FORMAT_INT) {
  164. long long val = obs_property_list_item_int(prop, idx);
  165. var = QVariant::fromValue<long long>(val);
  166. } else if (format == OBS_COMBO_FORMAT_FLOAT) {
  167. double val = obs_property_list_item_float(prop, idx);
  168. var = QVariant::fromValue<double>(val);
  169. } else if (format == OBS_COMBO_FORMAT_STRING) {
  170. var = obs_property_list_item_string(prop, idx);
  171. }
  172. combo->addItem(QT_UTF8(name), var);
  173. if (!obs_property_list_item_disabled(prop, idx))
  174. return;
  175. int index = combo->findText(QT_UTF8(name));
  176. if (index < 0)
  177. return;
  178. QStandardItemModel *model =
  179. dynamic_cast<QStandardItemModel*>(combo->model());
  180. if (!model)
  181. return;
  182. QStandardItem *item = model->item(index);
  183. item->setFlags(Qt::NoItemFlags);
  184. }
  185. template <long long get_int(obs_data_t*, const char*),
  186. double get_double(obs_data_t*, const char*),
  187. const char *get_string(obs_data_t*, const char*)>
  188. static string from_obs_data(obs_data_t *data, const char *name,
  189. obs_combo_format format)
  190. {
  191. switch (format) {
  192. case OBS_COMBO_FORMAT_INT:
  193. return to_string(get_int(data, name));
  194. case OBS_COMBO_FORMAT_FLOAT:
  195. return to_string(get_double(data, name));
  196. case OBS_COMBO_FORMAT_STRING:
  197. return get_string(data, name);
  198. default:
  199. return "";
  200. }
  201. }
  202. static string from_obs_data(obs_data_t *data, const char *name,
  203. obs_combo_format format)
  204. {
  205. return from_obs_data<obs_data_get_int, obs_data_get_double,
  206. obs_data_get_string>(data, name, format);
  207. }
  208. static string from_obs_data_autoselect(obs_data_t *data, const char *name,
  209. obs_combo_format format)
  210. {
  211. return from_obs_data<obs_data_get_autoselect_int,
  212. obs_data_get_autoselect_double,
  213. obs_data_get_autoselect_string>(data, name, format);
  214. }
  215. QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning)
  216. {
  217. const char *name = obs_property_name(prop);
  218. QComboBox *combo = new QComboBox();
  219. obs_combo_type type = obs_property_list_type(prop);
  220. obs_combo_format format = obs_property_list_format(prop);
  221. size_t count = obs_property_list_item_count(prop);
  222. int idx = -1;
  223. for (size_t i = 0; i < count; i++)
  224. AddComboItem(combo, prop, format, i);
  225. if (type == OBS_COMBO_TYPE_EDITABLE)
  226. combo->setEditable(true);
  227. string value = from_obs_data(settings, name, format);
  228. if (format == OBS_COMBO_FORMAT_STRING &&
  229. type == OBS_COMBO_TYPE_EDITABLE)
  230. combo->lineEdit()->setText(QT_UTF8(value.c_str()));
  231. else
  232. idx = combo->findData(QT_UTF8(value.c_str()));
  233. if (type == OBS_COMBO_TYPE_EDITABLE)
  234. return NewWidget(prop, combo,
  235. SIGNAL(editTextChanged(const QString &)));
  236. if (idx != -1)
  237. combo->setCurrentIndex(idx);
  238. if (obs_data_has_autoselect_value(settings, name)) {
  239. string autoselect =
  240. from_obs_data_autoselect(settings, name, format);
  241. int id = combo->findData(QT_UTF8(autoselect.c_str()));
  242. if (id != -1 && id != idx) {
  243. QString actual = combo->itemText(id);
  244. QString selected = combo->itemText(idx);
  245. QString combined = QTStr(
  246. "Basic.PropertiesWindow.AutoSelectFormat");
  247. combo->setItemText(idx,
  248. combined.arg(selected).arg(actual));
  249. }
  250. }
  251. QAbstractItemModel *model = combo->model();
  252. warning = idx != -1 &&
  253. model->flags(model->index(idx, 0)) == Qt::NoItemFlags;
  254. WidgetInfo *info = new WidgetInfo(this, prop, combo);
  255. connect(combo, SIGNAL(currentIndexChanged(int)), info,
  256. SLOT(ControlChanged()));
  257. children.push_back(std::move(unique_ptr<WidgetInfo>(info)));
  258. /* trigger a settings update if the index was not found */
  259. if (idx == -1)
  260. info->ControlChanged();
  261. return combo;
  262. }
  263. QWidget *OBSPropertiesView::AddButton(obs_property_t *prop)
  264. {
  265. const char *desc = obs_property_description(prop);
  266. QPushButton *button = new QPushButton(QT_UTF8(desc));
  267. button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
  268. return NewWidget(prop, button, SIGNAL(clicked()));
  269. }
  270. void OBSPropertiesView::AddColor(obs_property_t *prop, QFormLayout *layout,
  271. QLabel *&label)
  272. {
  273. QPushButton *button = new QPushButton;
  274. QLabel *colorLabel = new QLabel;
  275. const char *name = obs_property_name(prop);
  276. long long val = obs_data_get_int(settings, name);
  277. QColor color = color_from_int(val);
  278. button->setText(QTStr("Basic.PropertiesWindow.SelectColor"));
  279. colorLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
  280. colorLabel->setText(color.name(QColor::HexArgb));
  281. colorLabel->setPalette(QPalette(color));
  282. colorLabel->setAutoFillBackground(true);
  283. colorLabel->setAlignment(Qt::AlignCenter);
  284. QHBoxLayout *subLayout = new QHBoxLayout;
  285. subLayout->setContentsMargins(0, 0, 0, 0);
  286. subLayout->addWidget(colorLabel);
  287. subLayout->addWidget(button);
  288. WidgetInfo *info = new WidgetInfo(this, prop, colorLabel);
  289. connect(button, SIGNAL(clicked()), info, SLOT(ControlChanged()));
  290. children.emplace_back(info);
  291. label = new QLabel(QT_UTF8(obs_property_description(prop)));
  292. layout->addRow(label, subLayout);
  293. }
  294. static void MakeQFont(obs_data_t *font_obj, QFont &font)
  295. {
  296. const char *face = obs_data_get_string(font_obj, "face");
  297. const char *style = obs_data_get_string(font_obj, "style");
  298. int size = (int)obs_data_get_int(font_obj, "size");
  299. uint32_t flags = (uint32_t)obs_data_get_int(font_obj, "flags");
  300. if (face) {
  301. font.setFamily(face);
  302. font.setStyleName(style);
  303. }
  304. if (size)
  305. font.setPointSize(size);
  306. if (flags & OBS_FONT_BOLD) font.setBold(true);
  307. if (flags & OBS_FONT_ITALIC) font.setItalic(true);
  308. if (flags & OBS_FONT_UNDERLINE) font.setUnderline(true);
  309. if (flags & OBS_FONT_STRIKEOUT) font.setStrikeOut(true);
  310. }
  311. void OBSPropertiesView::AddFont(obs_property_t *prop, QFormLayout *layout,
  312. QLabel *&label)
  313. {
  314. const char *name = obs_property_name(prop);
  315. obs_data_t *font_obj = obs_data_get_obj(settings, name);
  316. const char *face = obs_data_get_string(font_obj, "face");
  317. const char *style = obs_data_get_string(font_obj, "style");
  318. QPushButton *button = new QPushButton;
  319. QLabel *fontLabel = new QLabel;
  320. QFont font;
  321. font = fontLabel->font();
  322. MakeQFont(font_obj, font);
  323. button->setText(QTStr("Basic.PropertiesWindow.SelectFont"));
  324. fontLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
  325. fontLabel->setFont(font);
  326. fontLabel->setText(QString("%1 %2").arg(face, style));
  327. fontLabel->setAlignment(Qt::AlignCenter);
  328. QHBoxLayout *subLayout = new QHBoxLayout;
  329. subLayout->setContentsMargins(0, 0, 0, 0);
  330. subLayout->addWidget(fontLabel);
  331. subLayout->addWidget(button);
  332. WidgetInfo *info = new WidgetInfo(this, prop, fontLabel);
  333. connect(button, SIGNAL(clicked()), info, SLOT(ControlChanged()));
  334. children.emplace_back(info);
  335. label = new QLabel(QT_UTF8(obs_property_description(prop)));
  336. layout->addRow(label, subLayout);
  337. obs_data_release(font_obj);
  338. }
  339. void OBSPropertiesView::AddProperty(obs_property_t *property,
  340. QFormLayout *layout)
  341. {
  342. const char *name = obs_property_name(property);
  343. obs_property_type type = obs_property_get_type(property);
  344. if (!obs_property_visible(property))
  345. return;
  346. QLabel *label = nullptr;
  347. QWidget *widget = nullptr;
  348. bool warning = false;
  349. switch (type) {
  350. case OBS_PROPERTY_INVALID:
  351. return;
  352. case OBS_PROPERTY_BOOL:
  353. widget = AddCheckbox(property);
  354. break;
  355. case OBS_PROPERTY_INT:
  356. widget = AddInt(property);
  357. break;
  358. case OBS_PROPERTY_FLOAT:
  359. widget = AddFloat(property);
  360. break;
  361. case OBS_PROPERTY_TEXT:
  362. widget = AddText(property);
  363. break;
  364. case OBS_PROPERTY_PATH:
  365. AddPath(property, layout, &label);
  366. break;
  367. case OBS_PROPERTY_LIST:
  368. widget = AddList(property, warning);
  369. break;
  370. case OBS_PROPERTY_COLOR:
  371. AddColor(property, layout, label);
  372. break;
  373. case OBS_PROPERTY_FONT:
  374. AddFont(property, layout, label);
  375. break;
  376. case OBS_PROPERTY_BUTTON:
  377. widget = AddButton(property);
  378. break;
  379. }
  380. if (widget && !obs_property_enabled(property))
  381. widget->setEnabled(false);
  382. if (!label &&
  383. type != OBS_PROPERTY_BOOL &&
  384. type != OBS_PROPERTY_BUTTON)
  385. label = new QLabel(QT_UTF8(obs_property_description(property)));
  386. if (warning && label) //TODO: select color based on background color
  387. label->setStyleSheet("QLabel { color: red; }");
  388. if (label && minSize) {
  389. label->setMinimumWidth(minSize);
  390. label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
  391. }
  392. if (!widget)
  393. return;
  394. layout->addRow(label, widget);
  395. if (!lastFocused.empty())
  396. if (lastFocused.compare(name) == 0)
  397. lastWidget = widget;
  398. }
  399. void WidgetInfo::BoolChanged(const char *setting)
  400. {
  401. QCheckBox *checkbox = static_cast<QCheckBox*>(widget);
  402. obs_data_set_bool(view->settings, setting,
  403. checkbox->checkState() == Qt::Checked);
  404. }
  405. void WidgetInfo::IntChanged(const char *setting)
  406. {
  407. QSpinBox *spin = static_cast<QSpinBox*>(widget);
  408. obs_data_set_int(view->settings, setting, spin->value());
  409. }
  410. void WidgetInfo::FloatChanged(const char *setting)
  411. {
  412. QDoubleSpinBox *spin = static_cast<QDoubleSpinBox*>(widget);
  413. obs_data_set_double(view->settings, setting, spin->value());
  414. }
  415. void WidgetInfo::TextChanged(const char *setting)
  416. {
  417. obs_text_type type = obs_proprety_text_type(property);
  418. if (type == OBS_TEXT_MULTILINE) {
  419. QPlainTextEdit *edit = static_cast<QPlainTextEdit*>(widget);
  420. obs_data_set_string(view->settings, setting,
  421. QT_TO_UTF8(edit->toPlainText()));
  422. return;
  423. }
  424. QLineEdit *edit = static_cast<QLineEdit*>(widget);
  425. obs_data_set_string(view->settings, setting, QT_TO_UTF8(edit->text()));
  426. }
  427. bool WidgetInfo::PathChanged(const char *setting)
  428. {
  429. const char *desc = obs_property_description(property);
  430. obs_path_type type = obs_property_path_type(property);
  431. const char *filter = obs_property_path_filter(property);
  432. const char *default_path = obs_property_path_default_path(property);
  433. QString path;
  434. if (type == OBS_PATH_DIRECTORY)
  435. path = QFileDialog::getExistingDirectory(view,
  436. QT_UTF8(desc), QT_UTF8(default_path),
  437. QFileDialog::ShowDirsOnly |
  438. QFileDialog::DontResolveSymlinks);
  439. else if (type == OBS_PATH_FILE)
  440. path = QFileDialog::getOpenFileName(view,
  441. QT_UTF8(desc), QT_UTF8(default_path),
  442. QT_UTF8(filter));
  443. if (path.isEmpty())
  444. return false;
  445. QLineEdit *edit = static_cast<QLineEdit*>(widget);
  446. edit->setText(path);
  447. obs_data_set_string(view->settings, setting, QT_TO_UTF8(path));
  448. return true;
  449. }
  450. void WidgetInfo::ListChanged(const char *setting)
  451. {
  452. QComboBox *combo = static_cast<QComboBox*>(widget);
  453. obs_combo_format format = obs_property_list_format(property);
  454. obs_combo_type type = obs_property_list_type(property);
  455. QVariant data;
  456. if (type == OBS_COMBO_TYPE_EDITABLE) {
  457. data = combo->currentText();
  458. } else {
  459. int index = combo->currentIndex();
  460. if (index != -1)
  461. data = combo->itemData(index);
  462. else
  463. return;
  464. }
  465. switch (format) {
  466. case OBS_COMBO_FORMAT_INVALID:
  467. return;
  468. case OBS_COMBO_FORMAT_INT:
  469. obs_data_set_int(view->settings, setting,
  470. data.value<long long>());
  471. break;
  472. case OBS_COMBO_FORMAT_FLOAT:
  473. obs_data_set_double(view->settings, setting,
  474. data.value<double>());
  475. break;
  476. case OBS_COMBO_FORMAT_STRING:
  477. obs_data_set_string(view->settings, setting,
  478. QT_TO_UTF8(data.toString()));
  479. break;
  480. }
  481. }
  482. bool WidgetInfo::ColorChanged(const char *setting)
  483. {
  484. const char *desc = obs_property_description(property);
  485. long long val = obs_data_get_int(view->settings, setting);
  486. QColor color = color_from_int(val);
  487. QColorDialog::ColorDialogOptions options =
  488. QColorDialog::ShowAlphaChannel;
  489. /* The native dialog on OSX has all kinds of problems, like closing
  490. * other open QDialogs on exit, and
  491. * https://bugreports.qt-project.org/browse/QTBUG-34532
  492. */
  493. #ifdef __APPLE__
  494. options |= QColorDialog::DontUseNativeDialog;
  495. #endif
  496. color = QColorDialog::getColor(color, view, QT_UTF8(desc), options);
  497. if (!color.isValid())
  498. return false;
  499. QLabel *label = static_cast<QLabel*>(widget);
  500. label->setText(color.name(QColor::HexArgb));
  501. label->setPalette(QPalette(color));
  502. obs_data_set_int(view->settings, setting, color_to_int(color));
  503. return true;
  504. }
  505. bool WidgetInfo::FontChanged(const char *setting)
  506. {
  507. obs_data_t *font_obj = obs_data_get_obj(view->settings, setting);
  508. bool success;
  509. uint32_t flags;
  510. QFont font;
  511. if (!font_obj) {
  512. font = QFontDialog::getFont(&success, view);
  513. } else {
  514. MakeQFont(font_obj, font);
  515. font = QFontDialog::getFont(&success, font, view);
  516. obs_data_release(font_obj);
  517. }
  518. if (!success)
  519. return false;
  520. 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. QLabel *label = static_cast<QLabel*>(widget);
  530. label->setFont(font);
  531. label->setText(QString("%1 %2").arg(font.family(), font.styleName()));
  532. obs_data_set_obj(view->settings, setting, font_obj);
  533. obs_data_release(font_obj);
  534. return true;
  535. }
  536. void WidgetInfo::ButtonClicked()
  537. {
  538. obs_property_button_clicked(property, view->obj);
  539. }
  540. void WidgetInfo::ControlChanged()
  541. {
  542. const char *setting = obs_property_name(property);
  543. obs_property_type type = obs_property_get_type(property);
  544. switch (type) {
  545. case OBS_PROPERTY_INVALID: return;
  546. case OBS_PROPERTY_BOOL: BoolChanged(setting); break;
  547. case OBS_PROPERTY_INT: IntChanged(setting); break;
  548. case OBS_PROPERTY_FLOAT: FloatChanged(setting); break;
  549. case OBS_PROPERTY_TEXT: TextChanged(setting); break;
  550. case OBS_PROPERTY_LIST: ListChanged(setting); break;
  551. case OBS_PROPERTY_BUTTON: ButtonClicked(); return;
  552. case OBS_PROPERTY_COLOR:
  553. if (!ColorChanged(setting))
  554. return;
  555. break;
  556. case OBS_PROPERTY_FONT:
  557. if (!FontChanged(setting))
  558. return;
  559. break;
  560. case OBS_PROPERTY_PATH:
  561. if (!PathChanged(setting))
  562. return;
  563. }
  564. view->callback(view->obj, view->settings);
  565. if (obs_property_modified(property, view->settings)) {
  566. view->lastFocused = setting;
  567. QMetaObject::invokeMethod(view, "RefreshProperties",
  568. Qt::QueuedConnection);
  569. }
  570. }