@@ -20,13 +20,13 @@ QgsFeatureListViewDelegate::QgsFeatureListViewDelegate( QgsFeatureListModel *lis
20
20
21
21
QgsFeatureListViewDelegate::Element QgsFeatureListViewDelegate::positionToElement ( const QPoint &pos )
22
22
{
23
- if ( pos.x () < sIconSize )
23
+ if ( pos.x () > sIconSize )
24
24
{
25
- return EditButtonElement ;
25
+ return EditElement ;
26
26
}
27
27
else
28
28
{
29
- return TextElement ;
29
+ return SelectionElement ;
30
30
}
31
31
}
32
32
@@ -45,46 +45,48 @@ void QgsFeatureListViewDelegate::paint( QPainter *painter, const QStyleOptionVie
45
45
{
46
46
QString text = index.model ()->data ( index, Qt::EditRole ).toString ();
47
47
QgsFeatureListModel::FeatureInfo featInfo = index.model ()->data ( index, Qt::UserRole ).value <QgsFeatureListModel::FeatureInfo>();
48
+ bool isEdited = mEditSelectionModel ->isSelected ( mListModel ->mapToMaster ( index ) );
48
49
49
- // Edit button state
50
- bool checked = mEditSelectionModel -> isSelected ( mListModel -> mapToMaster ( index ) ) ;
50
+ // Icon layout options
51
+ QStyleOptionViewItem iconOption ;
51
52
52
- QStyleOptionButton pbn1Opts ;
53
+ QRect iconLayoutBounds ( option. rect . x (), option. rect . y (), option. rect . height (), option. rect . height () ) ;
53
54
54
- pbn1Opts. iconSize = QSize ( sIconSize , sIconSize ) ;
55
+ QPixmap icon ;
55
56
56
- pbn1Opts.state |= QStyle::State_Enabled;
57
- if ( checked )
57
+ if ( option.state .testFlag ( QStyle::State_Selected ) )
58
58
{
59
- pbn1Opts. icon = QgsApplication::getThemeIcon ( " /mIconEditableEdits.png " );
60
- pbn1Opts. state |= QStyle::State_On ;
59
+ // Item is selected
60
+ icon = QgsApplication::getThemePixmap ( " /mIconSelected.svg " ) ;
61
61
}
62
62
else
63
63
{
64
- pbn1Opts.icon = QgsApplication::getThemeIcon ( " /mIconEditable.png" );
65
- pbn1Opts.state |= QStyle::State_Off;
64
+ icon = QgsApplication::getThemePixmap ( " /mIconDeselected.svg" );
66
65
}
67
66
68
- QRect pbn1Rect ( option. rect . x (), option. rect . y (), option. rect . height (), option. rect . height () );
69
- pbn1Opts. rect = pbn1Rect ;
67
+ // Text layout options
68
+ QRect textLayoutBounds ( iconLayoutBounds. x () + iconLayoutBounds. width (), option. rect . y (), option. rect . width () - ( iconLayoutBounds. x () + iconLayoutBounds. width () ), option. rect . height () ) ;
70
69
71
- QApplication::style ()->drawControl ( QStyle::CE_PushButton, &pbn1Opts, painter );
72
-
73
- QRect textLayoutBounds ( pbn1Rect.x () + pbn1Rect.width (), option.rect .y (), option.rect .width () - ( pbn1Rect.x () + pbn1Rect.width () ), option.rect .height () );
74
-
75
- QStyleOptionViewItem textOption = option;
70
+ QStyleOptionViewItem textOption;
71
+ textOption.state |= QStyle::State_Enabled;
72
+ if ( isEdited )
73
+ {
74
+ textOption.state |= QStyle::State_Selected;
75
+ }
76
76
77
77
if ( featInfo.isNew )
78
78
{
79
79
textOption.font .setStyle ( QFont::StyleItalic );
80
80
textOption.palette .setColor ( QPalette::Text, Qt::darkGreen );
81
81
textOption.palette .setColor ( QPalette::HighlightedText, Qt::darkGreen );
82
82
}
83
- else if ( featInfo.isEdited || checked )
83
+ else if ( featInfo.isEdited || isEdited )
84
84
{
85
85
textOption.font .setStyle ( QFont::StyleItalic );
86
86
textOption.palette .setColor ( QPalette::Text, Qt::red );
87
87
textOption.palette .setColor ( QPalette::HighlightedText, Qt::red );
88
88
}
89
+
89
90
drawDisplay ( painter, textOption, textLayoutBounds, text );
91
+ drawDecoration ( painter, iconOption, iconLayoutBounds, icon );
90
92
}
0 commit comments