mirror of
https://github.com/zealdocs/zeal.git
synced 2026-08-29 08:34:50 +08:00
ui: Use QStyledItemDelegate for all delegates
This commit is contained in:
@@ -31,14 +31,14 @@ using namespace Zeal;
|
||||
using namespace Zeal::WidgetUi;
|
||||
|
||||
DocsetListItemDelegate::DocsetListItemDelegate(QObject *parent) :
|
||||
QItemDelegate(parent)
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void DocsetListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (!index.model()->data(index, Registry::ItemDataRole::UpdateAvailableRole).toBool())
|
||||
return;
|
||||
@@ -55,8 +55,24 @@ void DocsetListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||
|
||||
painter->save();
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
painter->setPen(QPen(option.palette.highlightedText(), 1));
|
||||
QPalette palette = option.palette;
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
// QWindowsVistaStyle overrides highlight colour.
|
||||
if (option.widget->style()->objectName() == QLatin1String("windowsvista")) {
|
||||
palette.setColor(QPalette::All, QPalette::HighlightedText,
|
||||
palette.color(QPalette::Active, QPalette::Text));
|
||||
}
|
||||
#endif
|
||||
|
||||
const QPalette::ColorGroup cg = (option.state & QStyle::State_Active)
|
||||
? QPalette::Normal : QPalette::Inactive;
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->setPen(palette.color(cg, QPalette::HighlightedText));
|
||||
} else {
|
||||
painter->setPen(palette.color(cg, QPalette::Text));
|
||||
}
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(textRect, text);
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
#ifndef ZEAL_WIDGETUI_DOCSETLISTITEMDELEGATE_H
|
||||
#define ZEAL_WIDGETUI_DOCSETLISTITEMDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace Zeal {
|
||||
namespace WidgetUi {
|
||||
|
||||
class DocsetListItemDelegate : public QItemDelegate
|
||||
class DocsetListItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
using namespace Zeal::WidgetUi;
|
||||
|
||||
ProgressItemDelegate::ProgressItemDelegate(QObject *parent) :
|
||||
QItemDelegate(parent)
|
||||
QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
if (!index.model()->data(index, ShowProgressRole).toBool()) {
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||
const int value = index.model()->data(index, ValueRole).toInt(&ok);
|
||||
|
||||
if (!ok) {
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,5 +71,5 @@ void ProgressItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||
|
||||
painter->restore();
|
||||
|
||||
QItemDelegate::paint(painter, styleOption, index);
|
||||
QStyledItemDelegate::paint(painter, styleOption, index);
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
#ifndef ZEAL_WIDGETUI_PROGRESSITEMDELEGATE_H
|
||||
#define ZEAL_WIDGETUI_PROGRESSITEMDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace Zeal {
|
||||
namespace WidgetUi {
|
||||
|
||||
class ProgressItemDelegate : public QItemDelegate
|
||||
class ProgressItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user