summaryrefslogtreecommitdiff
path: root/src/lockwidget.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-10-31 01:47:08 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-11-06 07:44:57 -0500
commit0cea4833eb48400feb652e883c70d8a2907701c3 (patch)
tree2a1e0a4354cabae66415e5db817e33c589d98341 /src/lockwidget.cpp
parentdb0b92776b5c9a34ebb1a5ce5c3f0b105844ee16 (diff)
explicit refresh parameter for setWaitForCompletion(), some parts of the ui will crash if things refresh unexpectedly
removed runFile() fixed crash when unlocking if some widgets were destroyed in the meantime lock widget will now pick the active window and disable all top levels
Diffstat (limited to 'src/lockwidget.cpp')
-rw-r--r--src/lockwidget.cpp73
1 files changed, 47 insertions, 26 deletions
diff --git a/src/lockwidget.cpp b/src/lockwidget.cpp
index 720cac36..ad9aefe3 100644
--- a/src/lockwidget.cpp
+++ b/src/lockwidget.cpp
@@ -59,17 +59,22 @@ LockWidget::Results LockWidget::result() const
void LockWidget::createUi(Reasons reason)
{
- if (m_parent) {
- m_overlay.reset(createTransparentWidget(m_parent));
+ QWidget* overlayTarget = m_parent;
+ if (auto* w = qApp->activeWindow()) {
+ overlayTarget = w;
+ }
+
+ if (overlayTarget) {
+ m_overlay.reset(createTransparentWidget(overlayTarget));
m_overlay->setWindowFlags(m_overlay->windowFlags() & Qt::FramelessWindowHint);
- m_overlay->setGeometry(m_parent->rect());
+ m_overlay->setGeometry(overlayTarget->rect());
} else {
m_overlay.reset(new QDialog);
}
auto* center = new QFrame;
- if (m_parent) {
+ if (overlayTarget) {
center->setFrameStyle(QFrame::StyledPanel);
center->setLineWidth(1);
center->setAutoFillBackground(true);
@@ -86,7 +91,7 @@ void LockWidget::createUi(Reasons reason)
auto* ly = new QVBoxLayout(center);
- if (!m_parent) {
+ if (!overlayTarget) {
ly->setContentsMargins(0, 0, 0, 0);
}
@@ -115,7 +120,7 @@ void LockWidget::createUi(Reasons reason)
case OutputRequired:
{
message->setText(QObject::tr(
- "The executable must run to completion because a its output is "
+ "The executable must run to completion because its output is "
"required."));
auto* unlockButton = new QPushButton(QObject::tr("Unlock"));
@@ -149,7 +154,7 @@ void LockWidget::createUi(Reasons reason)
grid->addWidget(createTransparentWidget(), 1, 2);
grid->addWidget(center, 1, 1);
- if (!m_parent) {
+ if (!overlayTarget) {
grid->setContentsMargins(0, 0, 0, 0);
}
@@ -160,10 +165,10 @@ void LockWidget::createUi(Reasons reason)
disableAll();
- if (m_parent) {
+ if (overlayTarget) {
m_filter.reset(new Filter);
- m_filter->resized = [=]{ m_overlay->setGeometry(m_parent->rect()); };
- m_parent->installEventFilter(m_filter.get());
+ m_filter->resized = [=]{ m_overlay->setGeometry(overlayTarget->rect()); };
+ overlayTarget->installEventFilter(m_filter.get());
}
m_overlay->setFocusPolicy(Qt::TabFocus);
@@ -184,32 +189,48 @@ void LockWidget::onCancel()
unlock();
}
+template <class T>
+QList<T> findChildrenImmediate(QWidget* parent)
+{
+ return parent->findChildren<T>(QString(), Qt::FindDirectChildrenOnly);
+}
+
void LockWidget::disableAll()
{
- if (!m_parent) {
- // nothing to disable without a main window
- return;
- }
+ const auto topLevels = QApplication::topLevelWidgets();
- if (auto* mw=dynamic_cast<QMainWindow*>(m_parent)) {
- disable(mw->centralWidget());
- disable(mw->menuBar());
- disable(mw->statusBar());
- }
+ for (auto* w : topLevels) {
+ if (auto* mw=dynamic_cast<QMainWindow*>(w)) {
+ disable(mw->centralWidget());
+ disable(mw->menuBar());
+ disable(mw->statusBar());
- for (auto* tb : m_parent->findChildren<QToolBar*>()) {
- disable(tb);
- }
+ for (auto* tb : findChildrenImmediate<QToolBar*>(w)) {
+ disable(tb);
+ }
+
+ for (auto* d : findChildrenImmediate<QDockWidget*>(w)) {
+ disable(d);
+ }
+ }
- for (auto* d : m_parent->findChildren<QDockWidget*>()) {
- disable(d);
+ if (auto* d=dynamic_cast<QDialog*>(w)) {
+ // no central widget, just disable the children, except for the overlay
+ for (auto* child : findChildrenImmediate<QWidget*>(d)) {
+ if (child != m_overlay.get()) {
+ disable(child);
+ }
+ }
+ }
}
}
void LockWidget::enableAll()
{
- for (auto* w : m_disabled) {
- w->setEnabled(true);
+ for (auto w : m_disabled) {
+ if (w) {
+ w->setEnabled(true);
+ }
}
m_disabled.clear();