Debian Codegraph @

src/librssguard/gui/reusable/styleditemdelegatewithoutfocus.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "gui/reusable/styleditemdelegatewithoutfocus.h"
4
5 #include "definitions/definitions.h"
6 #include "definitions/globals.h"
7
8 StyledItemDelegateWithoutFocus::StyledItemDelegateWithoutFocus(int height_row, int padding_row, QObject* parent)
9 : QStyledItemDelegate(parent), m_rowHeight(height_row), m_rowPadding(padding_row) {}
10
11 void StyledItemDelegateWithoutFocus::paint(QPainter* painter,
12 const QStyleOptionViewItem& option,
13 const QModelIndex& index) const {
14 QStyleOptionViewItem item_option(option);
15
16 if (Globals::hasFlag(item_option.state, QStyle::StateFlag::State_HasFocus)) {
17 item_option.state = item_option.state ^ QStyle::StateFlag::State_HasFocus;
18 }
19
20 bool rtl = index.data(TEXT_DIRECTION_ROLE).value<Qt::LayoutDirection>() == Qt::LayoutDirection::RightToLeft;
21
22 if (rtl) {
23 item_option.direction = Qt::LayoutDirection::RightToLeft;
24 }
25
26 if (Globals::hasFlag(item_option.state, QStyle::StateFlag::State_Selected) &&
27 index.data(Qt::ItemDataRole::ForegroundRole).isValid()) {
28 item_option.palette.setColor(QPalette::ColorRole::HighlightedText,
29 index.data(HIGHLIGHTED_FOREGROUND_TITLE_ROLE).value<QColor>());
30 }
31
32 QStyledItemDelegate::paint(painter, item_option, index);
33 }
34
35 QSize StyledItemDelegateWithoutFocus::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const {
36 auto original_hint = QStyledItemDelegate::sizeHint(option, index);
37 QSize new_hint;
38
39 if (m_rowHeight <= 0) {
40 new_hint = original_hint;
41 }
42 else {
43 new_hint = QSize(original_hint.width(), m_rowHeight);
44 }
45
46 if (m_rowPadding > 0) {
47 new_hint.setHeight(new_hint.height() + (2 * m_rowPadding));
48 }
49
50 return new_hint;
51 }