properties-view.cpp 19 KB

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