ui: Use QStyledItemDelegate for all delegates

This commit is contained in:
Oleg Shparber
2018-01-14 02:49:13 +02:00
parent 132619f1f6
commit 44e0289c35
4 changed files with 29 additions and 13 deletions
+20 -4
View File
@@ -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);
+2 -2
View File
@@ -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:
+4 -4
View File
@@ -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);
}
+2 -2
View File
@@ -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: