void LayerListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = setOptions(index, option); painter->save(); drawBackground(painter, option, index); QRect textrect = opt.rect; const net::LayerListItem &layer = index.data().value<net::LayerListItem>(); const QSize locksize = _lockicon.size(); // Draw layer opacity glyph QRect stylerect(opt.rect.topLeft() + QPoint(0, opt.rect.height()/2-12), QSize(24,24)); drawOpacityGlyph(stylerect, painter, layer.opacity, layer.hidden); // Draw layer name textrect.setLeft(stylerect.right()); textrect.setWidth(textrect.width() - locksize.width()); drawDisplay(painter, opt, textrect, layer.title); // Draw lock button if(layer.isLockedFor(_client->myId())) painter->drawPixmap( opt.rect.topRight()-QPoint(locksize.width(), -opt.rect.height()/2+locksize.height()/2), _lockicon ); painter->restore(); }
void LayerListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = setOptions(index, option); painter->save(); const auto &layer = index.data().value<paintcore::LayerInfo>(); const int myId = static_cast<const canvas::LayerListModel*>(index.model())->myId(); if(layer.isLockedFor(myId)) opt.state &= ~QStyle::State_Enabled; drawBackground(painter, option, index); QRect textrect = opt.rect; // Draw layer opacity glyph QRect stylerect(opt.rect.topLeft() + QPoint(0, opt.rect.height()/2-12), QSize(24,24)); drawOpacityGlyph(stylerect, painter, layer.opacity, layer.hidden); // Draw layer name textrect.setLeft(stylerect.right()); QString title; if(m_showNumbers) title = QString("%1 - %2").arg(index.model()->rowCount() - index.row() - 1).arg(layer.title); else title = layer.title; drawDisplay(painter, opt, textrect, title); painter->restore(); }