window-dock.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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", "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. }