1
0

OBSDock.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "OBSDock.hpp"
  2. #include <widgets/OBSBasic.hpp>
  3. #include <QCheckBox>
  4. #include <QMessageBox>
  5. #include "moc_OBSDock.cpp"
  6. void OBSDock::closeEvent(QCloseEvent *event)
  7. {
  8. auto msgBox = []() {
  9. QMessageBox msgbox(App()->GetMainWindow());
  10. msgbox.setWindowTitle(QTStr("DockCloseWarning.Title"));
  11. msgbox.setText(QTStr("DockCloseWarning.Text"));
  12. msgbox.setIcon(QMessageBox::Icon::Information);
  13. msgbox.addButton(QMessageBox::Ok);
  14. QCheckBox *cb = new QCheckBox(QTStr("DoNotShowAgain"));
  15. msgbox.setCheckBox(cb);
  16. msgbox.exec();
  17. if (cb->isChecked()) {
  18. config_set_bool(App()->GetUserConfig(), "General", "WarnedAboutClosingDocks", true);
  19. config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
  20. }
  21. };
  22. bool warned = config_get_bool(App()->GetUserConfig(), "General", "WarnedAboutClosingDocks");
  23. if (!OBSBasic::Get()->Closing() && !warned) {
  24. QMetaObject::invokeMethod(App(), "Exec", Qt::QueuedConnection, Q_ARG(VoidFunc, msgBox));
  25. }
  26. QDockWidget::closeEvent(event);
  27. if (widget() && event->isAccepted()) {
  28. QEvent widgetEvent(QEvent::Type(QEvent::User + QEvent::Close));
  29. qApp->sendEvent(widget(), &widgetEvent);
  30. }
  31. }
  32. void OBSDock::showEvent(QShowEvent *event)
  33. {
  34. QDockWidget::showEvent(event);
  35. }