mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 18:53:28 +01:00
Implement richtext_item_delegate
And use it in pkg_install_dialog
This commit is contained in:
parent
270d602a26
commit
eb77495d5f
@ -2430,6 +2430,7 @@
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug - LLVM|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_WINEXTRAS_LIB -DQT_CONCURRENT_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\flatbuffers\include" "-I.\..\3rdparty\wolfssl" "-I.\..\3rdparty\curl\include" "-I.\..\3rdparty\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\XAudio2Redist\include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" "-I$(QTDIR)\include\QtConcurrent"</Command>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="rpcs3qt\numbered_widget_item.h" />
|
||||
<ClInclude Include="rpcs3qt\richtext_item_delegate.h" />
|
||||
<ClInclude Include="rpcs3qt\stylesheets.h" />
|
||||
<CustomBuild Include="rpcs3qt\skylander_dialog.h">
|
||||
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release - LLVM|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
|
||||
|
@ -1218,6 +1218,9 @@
|
||||
<ClInclude Include="rpcs3qt\table_item_delegate.h">
|
||||
<Filter>Gui\custom items</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="rpcs3qt\richtext_item_delegate.h">
|
||||
<Filter>Gui\custom items</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="rpcs3qt\numbered_widget_item.h">
|
||||
<Filter>Gui\custom items</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "pkg_install_dialog.h"
|
||||
#include "game_compatibility.h"
|
||||
#include "numbered_widget_item.h"
|
||||
#include "richtext_item_delegate.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
@ -22,6 +23,7 @@ pkg_install_dialog::pkg_install_dialog(const QStringList& paths, game_compatibil
|
||||
: QDialog(parent)
|
||||
{
|
||||
m_dir_list = new QListWidget(this);
|
||||
m_dir_list->setItemDelegate(new richtext_item_delegate(m_dir_list->itemDelegate()));
|
||||
|
||||
for (const QString& path : paths)
|
||||
{
|
||||
|
66
rpcs3/rpcs3qt/richtext_item_delegate.h
Normal file
66
rpcs3/rpcs3qt/richtext_item_delegate.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QApplication>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTextDocument>
|
||||
|
||||
class richtext_item_delegate : public QStyledItemDelegate
|
||||
{
|
||||
private:
|
||||
QTextDocument* m_document;
|
||||
|
||||
public:
|
||||
explicit richtext_item_delegate(QObject* parent = 0)
|
||||
: QStyledItemDelegate(parent)
|
||||
, m_document(new QTextDocument(this))
|
||||
{
|
||||
}
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
|
||||
{
|
||||
painter->save();
|
||||
|
||||
// Initialize style option
|
||||
QStyleOptionViewItem opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
|
||||
// Setup the QTextDocument with our HTML
|
||||
m_document->setHtml(opt.text);
|
||||
opt.text.clear();
|
||||
|
||||
// Get the available style
|
||||
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
|
||||
|
||||
// Draw our widget if available
|
||||
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
|
||||
|
||||
// Adjust our painter parameters with some magic that looks good.
|
||||
// This is necessary so that we don't draw on top of the optional widget.
|
||||
const int margin = (option.rect.height() - opt.fontMetrics.height() - 4);
|
||||
QRect text_rect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, nullptr);
|
||||
|
||||
if (index.column() != 0)
|
||||
{
|
||||
text_rect.adjust(5, 0, 0, 0);
|
||||
}
|
||||
|
||||
text_rect.setTop(text_rect.top() + margin);
|
||||
|
||||
painter->translate(text_rect.topLeft());
|
||||
painter->setClipRect(text_rect.translated(-text_rect.topLeft()));
|
||||
|
||||
// Create a context for our painter
|
||||
QAbstractTextDocumentLayout::PaintContext context;
|
||||
|
||||
// We can change the text color based on state (Unused because it didn't look good)
|
||||
//context.palette.setColor(QPalette::Text, option.palette.color(QPalette::Active, (option.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text));
|
||||
|
||||
// Draw the text
|
||||
m_document->documentLayout()->draw(painter, context);
|
||||
|
||||
painter->restore();
|
||||
|
||||
//QStyledItemDelegate::paint(painter, opt, index); // Unused
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user