Expand Up
@@ -20,13 +20,13 @@ QgsFeatureListViewDelegate::QgsFeatureListViewDelegate( QgsFeatureListModel *lis
QgsFeatureListViewDelegate::Element QgsFeatureListViewDelegate::positionToElement ( const QPoint &pos )
{
if ( pos.x () < sIconSize )
if ( pos.x () > sIconSize )
{
return EditButtonElement ;
return EditElement ;
}
else
{
return TextElement ;
return SelectionElement ;
}
}
Expand All
@@ -45,46 +45,48 @@ void QgsFeatureListViewDelegate::paint( QPainter *painter, const QStyleOptionVie
{
QString text = index .model ()->data ( index , Qt::EditRole ).toString ();
QgsFeatureListModel::FeatureInfo featInfo = index .model ()->data ( index , Qt::UserRole ).value <QgsFeatureListModel::FeatureInfo>();
bool isEdited = mEditSelectionModel ->isSelected ( mListModel ->mapToMaster ( index ) );
// Edit button state
bool checked = mEditSelectionModel -> isSelected ( mListModel -> mapToMaster ( index ) ) ;
// Icon layout options
QStyleOptionViewItem iconOption ;
QStyleOptionButton pbn1Opts ;
QRect iconLayoutBounds ( option. rect . x (), option. rect . y (), option. rect . height (), option. rect . height () ) ;
pbn1Opts. iconSize = QSize ( sIconSize , sIconSize ) ;
QPixmap icon ;
pbn1Opts.state |= QStyle::State_Enabled;
if ( checked )
if ( option.state .testFlag ( QStyle::State_Selected ) )
{
pbn1Opts. icon = QgsApplication::getThemeIcon ( " /mIconEditableEdits.png " );
pbn1Opts. state |= QStyle::State_On ;
// Item is selected
icon = QgsApplication::getThemePixmap ( " /mIconSelected.svg " ) ;
}
else
{
pbn1Opts.icon = QgsApplication::getThemeIcon ( " /mIconEditable.png" );
pbn1Opts.state |= QStyle::State_Off;
icon = QgsApplication::getThemePixmap ( " /mIconDeselected.svg" );
}
QRect pbn1Rect ( option. rect . x (), option. rect . y (), option. rect . height (), option. rect . height () );
pbn1Opts. rect = pbn1Rect ;
// Text layout options
QRect textLayoutBounds ( iconLayoutBounds. x () + iconLayoutBounds. width (), option. rect . y (), option. rect . width () - ( iconLayoutBounds. x () + iconLayoutBounds. width () ), option. rect . height () ) ;
QApplication::style ()->drawControl ( QStyle::CE_PushButton, &pbn1Opts, painter );
QRect textLayoutBounds ( pbn1Rect.x () + pbn1Rect.width (), option.rect .y (), option.rect .width () - ( pbn1Rect.x () + pbn1Rect.width () ), option.rect .height () );
QStyleOptionViewItem textOption = option;
QStyleOptionViewItem textOption;
textOption.state |= QStyle::State_Enabled;
if ( isEdited )
{
textOption.state |= QStyle::State_Selected;
}
if ( featInfo.isNew )
{
textOption.font .setStyle ( QFont::StyleItalic );
textOption.palette .setColor ( QPalette::Text, Qt::darkGreen );
textOption.palette .setColor ( QPalette::HighlightedText, Qt::darkGreen );
}
else if ( featInfo.isEdited || checked )
else if ( featInfo.isEdited || isEdited )
{
textOption.font .setStyle ( QFont::StyleItalic );
textOption.palette .setColor ( QPalette::Text, Qt::red );
textOption.palette .setColor ( QPalette::HighlightedText, Qt::red );
}
drawDisplay ( painter, textOption, textLayoutBounds, text );
drawDecoration ( painter, iconOption, iconLayoutBounds, icon );
}