Display resources in shader viewer tooltips properly

This commit is contained in:
baldurk
2020-04-23 18:23:40 +01:00
parent 9b9a7abb47
commit 97665b2c30
3 changed files with 31 additions and 5 deletions
+12
View File
@@ -812,6 +812,18 @@ bool RichResourceTextMouseEvent(const QWidget *owner, const QVariant &var, QRect
return false;
}
QString RichResourceTextFormat(ICaptureContext &ctx, QVariant var)
{
RichResourceTextInitialise(var);
if(var.userType() == qMetaTypeId<ResourceId>())
return GetTruncatedResourceName(ctx, var.value<ResourceId>());
// either it's something else and wasn't rich resource, in which case just return the string
// representation, or it's a fully formatted rich resource document, where the cached text will do
// the trick with ResIdTextToString.
return var.toString();
}
RichTextViewDelegate::RichTextViewDelegate(QAbstractItemView *parent)
: m_widget(parent), ForwardingDelegate(parent)
{
+4
View File
@@ -204,6 +204,10 @@ int RichResourceTextWidthHint(const QWidget *owner, const QFont &font, const QVa
bool RichResourceTextMouseEvent(const QWidget *owner, const QVariant &var, QRect rect,
const QFont &font, QMouseEvent *event);
// immediately format a variant that may contain rich resource text. For use in places where we
// can't paint rich resource text but we still want to display the string nicely
QString RichResourceTextFormat(ICaptureContext &ctx, QVariant var);
// Register runtime conversions for custom Qt metatypes
void RegisterMetatypeConversions();
+15 -5
View File
@@ -3902,11 +3902,21 @@ void ShaderViewer::updateVariableTooltip()
if(var.type != VarType::Unknown)
{
QString tooltip = QFormatStr("<pre>%1: %2\n").arg(var.name).arg(RowString(var, 0));
QString spacing = QString(var.name.count(), QLatin1Char(' '));
for(int i = 1; i < var.rows; i++)
tooltip += QFormatStr("%1 %2\n").arg(spacing).arg(RowString(var, i));
tooltip += lit("</pre>");
QString tooltip;
if(var.type == VarType::ReadOnlyResource || var.type == VarType::ReadWriteResource)
{
tooltip = RichResourceTextFormat(m_Ctx, stringRep(var, 0));
}
else
{
tooltip = QFormatStr("<pre>%1: %2\n").arg(var.name).arg(RowString(var, 0));
QString spacing = QString(var.name.count(), QLatin1Char(' '));
for(int i = 1; i < var.rows; i++)
tooltip += QFormatStr("%1 %2\n").arg(spacing).arg(RowString(var, i));
tooltip += lit("</pre>");
}
QToolTip::showText(m_TooltipPos, tooltip);
return;
}