window-dock.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "moc_window-dock.cpp"
  2. #include "obs-app.hpp"
  3. #include "window-basic-main.hpp"
  4. #include <QMessageBox>
  5. #include <QCheckBox>
  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",
  19. "WarnedAboutClosingDocks", true);
  20. config_save_safe(App()->GetUserConfig(), "tmp",
  21. nullptr);
  22. }
  23. };
  24. bool warned = config_get_bool(App()->GetUserConfig(), "General",
  25. "WarnedAboutClosingDocks");
  26. if (!OBSBasic::Get()->Closing() && !warned) {
  27. QMetaObject::invokeMethod(App(), "Exec", Qt::QueuedConnection,
  28. Q_ARG(VoidFunc, msgBox));
  29. }
  30. QDockWidget::closeEvent(event);
  31. if (widget() && event->isAccepted()) {
  32. QEvent widgetEvent(QEvent::Type(QEvent::User + QEvent::Close));
  33. qApp->sendEvent(widget(), &widgetEvent);
  34. }
  35. }
  36. void OBSDock::showEvent(QShowEvent *event)
  37. {
  38. QDockWidget::showEvent(event);
  39. }