Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made error dialog with "Show Details" so wide, that there are no unnecessary line breaks. #4738

Merged
merged 11 commits into from
May 29, 2022
Merged
44 changes: 43 additions & 1 deletion src/errordialoghandler.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#include "errordialoghandler.h"

#include <QCoreApplication>
#include <QGuiApplication>
#include <QScopedPointer>
#include <QScreen>
#include <QThread>
#include <QtDebug>

#include "moc_errordialoghandler.cpp"
#include "util/assert.h"
#include "util/compatibility/qmutex.h"
#include "util/versionstore.h"
#include "util/widgethelper.h"

namespace {
// Gross estimated dimensions for the size of the error dialog,
// with Show Details expanded.
constexpr int kEstimatedShowDetailedDialogWidth = 1000; // px
constexpr int kEstimatedShowDetailedDialogHeight = 500; // px
constexpr int kEstimatedDialogPadding = 50; // px
// used to push the dialog away from screen borders to not cover taskbars
constexpr int kMinimumDialogMargin = 40; // px
} // namespace

ErrorDialogProperties::ErrorDialogProperties()
: m_title(VersionStore::applicationName()),
Expand Down Expand Up @@ -149,7 +162,36 @@ void ErrorDialogHandler::errorDialog(ErrorDialogProperties* pProps) {
if (!props->m_details.isEmpty()) {
pMsgBox->setDetailedText(props->m_details);
if (props->m_detailsUseMonospaceFont) {
pMsgBox->setStyleSheet("QTextEdit { font-family: monospace; }");
// There is no event to respond on the Show Details button of QMessagBox.
// Therefore we must consider the expanded size for positioning the dialog initially.
auto* pScreen =
mixxx::widgethelper::getScreen(*pMsgBox);
ronso0 marked this conversation as resolved.
Show resolved Hide resolved
if (!pScreen) {
// Fallback to obtain the primary screen when mixxx::widgethelper::getScreen can't
// determine the screen. This happens always with Qt <5.14
pScreen = qGuiApp->primaryScreen();
}
DEBUG_ASSERT(pScreen);
int dialogWidth = kEstimatedShowDetailedDialogWidth;
ronso0 marked this conversation as resolved.
Show resolved Hide resolved
int dialogHeight = kEstimatedShowDetailedDialogHeight;

// Limit dialog size to screen size, for the case of devices with very small display - like Raspberry Pi.
if (dialogWidth > pScreen->geometry().width() - 2 * kMinimumDialogMargin) {
dialogWidth = pScreen->geometry().width() - 2 * kMinimumDialogMargin;
}
if (dialogHeight > pScreen->geometry().height() - 2 * kMinimumDialogMargin) {
dialogHeight = pScreen->geometry().height() - 2 * kMinimumDialogMargin;
}
pMsgBox->setGeometry(QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
QSize(dialogWidth, dialogHeight),
pScreen->geometry()));
pMsgBox->setStyleSheet(
QString("QTextEdit { min-width: %1px ; max-height: %2px; "
"font-family: monospace;}")
.arg(dialogWidth - kEstimatedDialogPadding)
.arg(dialogHeight));
}
}

Expand Down