properties-view.cpp 19 KB

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