diff --git a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp index 955c134724..e0d34d74f8 100644 --- a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp @@ -3,9 +3,13 @@ #include "DolphinQt/Debugger/BreakpointWidget.h" +#include #include #include +#include #include +#include +#include #include #include #include @@ -36,6 +40,39 @@ enum CustomRole }; } +// Fix icons not centering properly in a QTableWidget. +class CustomDelegate : public QStyledItemDelegate +{ +public: + CustomDelegate(BreakpointWidget* parent) : QStyledItemDelegate(parent) {} + +private: + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const + { + Q_ASSERT(index.isValid()); + + // Fetch normal drawing logic. + QStyleOptionViewItem opt = option; + initStyleOption(&opt, index); + + // Disable drawing icon the normal way. + opt.icon = QIcon(); + opt.decorationSize = QSize(0, 0); + + // Default draw command for paint. + QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0); + + // Draw pixmap at the center of the tablewidget cell + QPixmap pix = qvariant_cast(index.data(Qt::DecorationRole)); + if (!pix.isNull()) + { + const QRect r = option.rect; + const QPoint p = QPoint((r.width() - pix.width()) / 2, (r.height() - pix.height()) / 2); + painter->drawPixmap(r.topLeft() + p, pix); + } + } +}; + BreakpointWidget::BreakpointWidget(QWidget* parent) : QDockWidget(parent), m_system(Core::System::GetInstance()) { @@ -88,6 +125,7 @@ void BreakpointWidget::CreateWidgets() m_toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); m_table = new QTableWidget; + m_table->setItemDelegate(new CustomDelegate(this)); m_table->setTabKeyNavigation(false); m_table->setContentsMargins(0, 0, 0, 0); m_table->setColumnCount(6); diff --git a/Source/Core/DolphinQt/Debugger/BreakpointWidget.h b/Source/Core/DolphinQt/Debugger/BreakpointWidget.h index 2ef8359289..b29bc8eb16 100644 --- a/Source/Core/DolphinQt/Debugger/BreakpointWidget.h +++ b/Source/Core/DolphinQt/Debugger/BreakpointWidget.h @@ -17,6 +17,8 @@ namespace Core class System; } +class CustomDelegate; + class BreakpointWidget : public QDockWidget { Q_OBJECT