Skip to content

Commit

Permalink
minor big fixes
Browse files Browse the repository at this point in the history
- refactored helper functions from custommessageboxes to misc
- close all other message boxes before opening a new one
- don't lock diary when lock timeout is 0ms
- upped minor version
  • Loading branch information
someretical committed Jan 10, 2022
1 parent dc5ef97 commit 45a3a72
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
Expand Down
31 changes: 12 additions & 19 deletions src/util/custommessageboxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -82,21 +73,23 @@ 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);
QPushButton cancel_button(reject_text.data(), &msgbox);
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);
Expand Down
1 change: 1 addition & 0 deletions src/util/custommessageboxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CUSTOMMESSAGEBOXES_H

#include "../core/internalmanager.h"
#include "misc.h"

#include <QtWidgets>
#include <string>
Expand Down
3 changes: 2 additions & 1 deletion src/util/eventfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
22 changes: 22 additions & 0 deletions src/util/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/util/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef MISC_H
#define MISC_H

#include "../core/internalmanager.h"

#include <QtWidgets>
#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion text/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.1.1

0 comments on commit 45a3a72

Please sign in to comment.