Merge pull request #6705 from aws-lumberyard-dev/3495_preferences_panel_update
3495 Preferences panel update: fix richtext elision and allow html links
This commit is contained in:
@@ -28,7 +28,7 @@ void CEditorPreferencesPage_AWS::Reflect(AZ::SerializeContext& serialize)
|
||||
if (editContext)
|
||||
{
|
||||
editContext->Class<UsageOptions>("Options", "")
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &UsageOptions::m_awsAttributionEnabled, "Allow O3DE to send information about your use of AWS Core Gem to AWS",
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &UsageOptions::m_awsAttributionEnabled, "Allow <a href=\"https://aws.amazon.com/privacy/\">O3DE</a> to send information about your use of AWS Core Gem to AWS",
|
||||
"");
|
||||
|
||||
editContext->Class<CEditorPreferencesPage_AWS>("AWS Preferences", "AWS Preferences")
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
#include <QStyle>
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace AzQtComponents
|
||||
{
|
||||
@@ -35,6 +37,7 @@ namespace AzQtComponents
|
||||
|
||||
m_text = text;
|
||||
m_metricsLabel->setText(m_text);
|
||||
|
||||
m_elidedText.clear();
|
||||
elide();
|
||||
updateGeometry();
|
||||
@@ -65,7 +68,62 @@ namespace AzQtComponents
|
||||
void ElidingLabel::elide()
|
||||
{
|
||||
ensurePolished();
|
||||
m_elidedText = fontMetrics().elidedText(m_text, m_elideMode, TextRect().width());
|
||||
|
||||
if (Qt::mightBeRichText(m_text))
|
||||
{
|
||||
// If RichText tags are elided using fontMetrics.elidedText(), they will break.
|
||||
// A TextDocument is used to produce elided text that takes this into account.
|
||||
const QString ellipsis("...");
|
||||
const int maxLineWidth = TextRect().width();
|
||||
|
||||
QTextDocument doc;
|
||||
doc.setHtml(m_text);
|
||||
doc.setDefaultFont(font());
|
||||
doc.setDocumentMargin(0.0);
|
||||
|
||||
// Turn off wrapping so the document uses a single line.
|
||||
QTextOption option = doc.defaultTextOption();
|
||||
option.setWrapMode(QTextOption::WrapMode::NoWrap);
|
||||
doc.setDefaultTextOption(option);
|
||||
doc.adjustSize();
|
||||
|
||||
if (doc.size().width() <= maxLineWidth)
|
||||
{
|
||||
m_elidedText = m_text;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextCursor textCursor(&doc);
|
||||
textCursor.movePosition(QTextCursor::End);
|
||||
|
||||
int ellipsisWidth = 0;
|
||||
|
||||
// At the moment only ElideRight and ElideNone are ever used. This will need expanding if other elision modes are used.
|
||||
if (m_elideMode == Qt::ElideRight)
|
||||
{
|
||||
ellipsisWidth = fontMetrics().horizontalAdvance(ellipsis);
|
||||
}
|
||||
|
||||
// Move the cursor back until the text fits or the start of the text is reached.
|
||||
while (doc.size().width() + ellipsisWidth > maxLineWidth && !textCursor.atStart())
|
||||
{
|
||||
textCursor.deletePreviousChar();
|
||||
doc.adjustSize();
|
||||
}
|
||||
|
||||
if (m_elideMode == Qt::ElideRight)
|
||||
{
|
||||
textCursor.insertText(ellipsis);
|
||||
}
|
||||
|
||||
m_elidedText = doc.toHtml();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_elidedText = fontMetrics().elidedText(m_text, m_elideMode, TextRect().width());
|
||||
}
|
||||
|
||||
QLabel::setText(m_elidedText);
|
||||
|
||||
if (m_elidedText != m_text)
|
||||
|
||||
+1
@@ -421,6 +421,7 @@ namespace AzToolsFramework
|
||||
{
|
||||
QString label{ text };
|
||||
m_nameLabel->setText(label);
|
||||
m_nameLabel->setOpenExternalLinks(true);
|
||||
m_nameLabel->setVisible(!label.isEmpty());
|
||||
// setting the stretches to 0 in case of an empty label really hides the label (i.e. even the reserved space)
|
||||
m_mainLayout->setStretch(0, label.isEmpty() ? 0 : LabelColumnStretch);
|
||||
|
||||
Reference in New Issue
Block a user