properties-view.cpp 19 KB

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