diff --git a/src/lib/tools/globalfunctions.cpp b/src/lib/tools/globalfunctions.cpp index 62063cbb4..d1f66fd01 100644 --- a/src/lib/tools/globalfunctions.cpp +++ b/src/lib/tools/globalfunctions.cpp @@ -233,6 +233,34 @@ QString qz_filterCharsFromFilename(const QString &name) return value; } +QString qz_alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width) +{ + int pos = 0; + QString returnString; + + while (pos <= string.size()) { + QString part = string.mid(pos); + QString elidedLine = metrics.elidedText(part, Qt::ElideRight, width); + + if (elidedLine.isEmpty()) { + break; + } + + if (elidedLine.size() != part.size()) { + elidedLine = elidedLine.mid(0, elidedLine.size() - 3); + } + + if (!returnString.isEmpty()) { + returnString += text; + } + + returnString += elidedLine; + pos += elidedLine.size(); + } + + return returnString; +} + QString qz_buildSystem() { #ifdef Q_OS_LINUX diff --git a/src/lib/tools/globalfunctions.h b/src/lib/tools/globalfunctions.h index 2154b8e41..9ee17528f 100644 --- a/src/lib/tools/globalfunctions.h +++ b/src/lib/tools/globalfunctions.h @@ -20,6 +20,7 @@ #include "qz_namespace.h" +class QFontMetrics; class QPixmap; class QWidget; class QUrl; @@ -41,9 +42,10 @@ QString QT_QUPZILLA_EXPORT qz_urlEncodeQueryString(const QUrl &url); QString QT_QUPZILLA_EXPORT qz_ensureUniqueFilename(const QString &name); QString QT_QUPZILLA_EXPORT qz_getFileNameFromUrl(const QUrl &url); - QString QT_QUPZILLA_EXPORT qz_filterCharsFromFilename(const QString &name); +QString QT_QUPZILLA_EXPORT qz_alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width); + QString QT_QUPZILLA_EXPORT qz_buildSystem(); #endif // GLOBALFUNCTIONS_H diff --git a/src/lib/webview/webpage.cpp b/src/lib/webview/webpage.cpp index 5f860a471..d9513afa9 100644 --- a/src/lib/webview/webpage.cpp +++ b/src/lib/webview/webpage.cpp @@ -297,10 +297,13 @@ void WebPage::handleUnknownProtocol(const QUrl &url) return; } + CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, view()); + + const QString &wrappedUrl = qz_alignTextToWidth(url.toString(), "
", dialog.fontMetrics(), 450); const QString &text = tr("QupZilla cannot handle %1: links. The requested link " "is Do you want QupZilla to try " - "open this link in system application?").arg(protocol, url.toString()); - CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, view()); + "open this link in system application?").arg(protocol, wrappedUrl); + dialog.setText(text); dialog.setCheckBoxText(tr("Remember my choice for this protocol")); dialog.setWindowTitle(tr("External Protocol Request"));