1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

Fixed too big "External Protocol Request" dialog when URL is very long

- it will now align URL to multi line text
This commit is contained in:
nowrep 2012-05-13 17:01:35 +02:00
parent 659e0ed3ba
commit 330b35f8db
3 changed files with 36 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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(), "<br/>", dialog.fontMetrics(), 450);
const QString &text = tr("QupZilla cannot handle <b>%1:</b> links. The requested link "
"is <ul><li>%2</li></ul>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"));