diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index f698a84..b8b4d51 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -200,6 +200,11 @@ void MainWindow::closeEvent(QCloseEvent *event) QCoreApplication::exit(1); break; case QMessageBox::RejectRole: + // There is a situation where the operation completes before the user can answer the messagebox. In this + // case, the app becomes softlocked as the dialog relocks the window after completing. + // TODO somehow fix this? + // One possible fix is to make all dialogs that can interrupt this one close all other dialogs before they + // appear. However, that is not very maintenance friendly so I will not be doing that. InternalManager::instance()->start_busy_mode(__LINE__, __func__, __FILE__); qDebug() << "Ignored close request due to app being busy."; } diff --git a/src/util/custommessageboxes.cpp b/src/util/custommessageboxes.cpp index 5f3b242..5d084ea 100644 --- a/src/util/custommessageboxes.cpp +++ b/src/util/custommessageboxes.cpp @@ -18,24 +18,13 @@ #include "custommessageboxes.h" -int const MAX_LINE_LENGTH = 100; - -void extend_top_line(std::string &top) -{ - if (top.size() < MAX_LINE_LENGTH) - top.append(MAX_LINE_LENGTH - top.size(), ' '); -} - -QString get_danger_stylesheet() -{ - QFile file(QString(":/%1/dangerbutton.qss").arg(InternalManager::instance()->get_theme_str())); - file.open(QIODevice::ReadOnly); - return QString(file.readAll()); -} +long unsigned int const MAX_LINE_LENGTH = 100; namespace td { int ok_messagebox(QWidget *parent, std::string &&top, std::string const &&bottom) { + misc::clear_message_boxes(); + QMessageBox msgbox(parent); QPushButton ok_button("OK", &msgbox); ok_button.setFlat(true); @@ -44,7 +33,7 @@ int ok_messagebox(QWidget *parent, std::string &&top, std::string const &&bottom ok_button.setFont(f); msgbox.setFont(f); - extend_top_line(top); + misc::extend_top_line(top, MAX_LINE_LENGTH); msgbox.setText(top.data()); msgbox.setInformativeText(bottom.data()); msgbox.addButton(&ok_button, QMessageBox::AcceptRole); @@ -56,19 +45,21 @@ int ok_messagebox(QWidget *parent, std::string &&top, std::string const &&bottom int yn_messagebox(QWidget *parent, std::string &&top, std::string const &&bottom) { + misc::clear_message_boxes(); + QMessageBox msgbox(parent); QPushButton yes("YES", &msgbox); QFont f = yes.font(); f.setPointSize(11); yes.setFont(f); - yes.setStyleSheet(get_danger_stylesheet()); + yes.setStyleSheet(misc::get_danger_stylesheet()); QPushButton no("NO", &msgbox); no.setFlat(true); no.setFont(f); msgbox.setFont(f); - extend_top_line(top); + misc::extend_top_line(top, MAX_LINE_LENGTH); msgbox.setText(top.data()); msgbox.setInformativeText(bottom.data()); msgbox.addButton(&yes, QMessageBox::AcceptRole); @@ -82,13 +73,15 @@ int yn_messagebox(QWidget *parent, std::string &&top, std::string const &&bottom int ync_messagebox(QWidget *parent, std::string const &&accept_text, std::string const &&reject_text, std::string const &&destroy_text, std::string &&top, std::string const &&bottom) { + misc::clear_message_boxes(); + QMessageBox msgbox(parent); QPushButton destroy_button(destroy_text.data(), &msgbox); QFont f = destroy_button.font(); f.setPointSize(11); destroy_button.setFont(f); - destroy_button.setStyleSheet(get_danger_stylesheet()); + destroy_button.setStyleSheet(misc::get_danger_stylesheet()); QPushButton accept_button(accept_text.data(), &msgbox); accept_button.setFont(f); @@ -96,7 +89,7 @@ int ync_messagebox(QWidget *parent, std::string const &&accept_text, std::string cancel_button.setFlat(true); cancel_button.setFont(f); msgbox.setFont(f); - extend_top_line(top); + misc::extend_top_line(top, MAX_LINE_LENGTH); msgbox.setText(top.data()); msgbox.setInformativeText(bottom.data()); msgbox.addButton(&accept_button, QMessageBox::AcceptRole); diff --git a/src/util/custommessageboxes.h b/src/util/custommessageboxes.h index 7f5805b..bca8c5b 100644 --- a/src/util/custommessageboxes.h +++ b/src/util/custommessageboxes.h @@ -20,6 +20,7 @@ #define CUSTOMMESSAGEBOXES_H #include "../core/internalmanager.h" +#include "misc.h" #include #include diff --git a/src/util/eventfilters.cpp b/src/util/eventfilters.cpp index db0ab46..19aa4c6 100644 --- a/src/util/eventfilters.cpp +++ b/src/util/eventfilters.cpp @@ -112,5 +112,6 @@ bool InactiveFilter::eventFilter(QObject *obj, QEvent *event) void InactiveFilter::slot_inactive_timeout() { - emit sig_inactive_timeout(); + if (0 != interval) + emit sig_inactive_timeout(); } diff --git a/src/util/misc.cpp b/src/util/misc.cpp index ae4234c..c5463c9 100644 --- a/src/util/misc.cpp +++ b/src/util/misc.cpp @@ -70,4 +70,26 @@ std::string get_trunc_first_line(std::string input, int max_line_len) return first_line; } + +void extend_top_line(std::string &top, long unsigned int const max_line_len) +{ + if (top.size() < max_line_len) + top.append(max_line_len - top.size(), ' '); +} + +QString get_danger_stylesheet() +{ + QFile file(QString(":/%1/dangerbutton.qss").arg(InternalManager::instance()->get_theme_str())); + file.open(QIODevice::ReadOnly); + return QString(file.readAll()); +} + +void clear_message_boxes() +{ + QWidget *w; + while ((w = QApplication::activeModalWidget())) { + qDebug() << "Removing message_box:" << w; + w->close(); + } +} } // namespace misc diff --git a/src/util/misc.h b/src/util/misc.h index 78592a1..14b8187 100644 --- a/src/util/misc.h +++ b/src/util/misc.h @@ -19,6 +19,8 @@ #ifndef MISC_H #define MISC_H +#include "../core/internalmanager.h" + #include #include #include @@ -49,6 +51,10 @@ inline std::string &trim(std::string &s) { return ltrim(rtrim(s)); } + +void extend_top_line(std::string &top, long unsigned int const max_line_len); +QString get_danger_stylesheet(); +void clear_message_boxes(); } // namespace misc #endif // MISC_H diff --git a/text/VERSION.txt b/text/VERSION.txt index 7ec1d6d..3e3c2f1 100644 --- a/text/VERSION.txt +++ b/text/VERSION.txt @@ -1 +1 @@ -2.1.0 +2.1.1