Commit 3f9c6602 authored by Andreas Traczyk's avatar Andreas Traczyk

smartlist/contact request list: fix selection highlighting

- calls QItemDelegate::drawDecoration for the avatar with options
  that ignore the selection state of the index to avoid an overlay
  on the avatar for selected item
- changes the highlight/selection colors for smartlist and
  contact request items

Change-Id: I486ee2270784f39bacba0230fd5082dacd44c124
parent 52733392
......@@ -52,6 +52,16 @@ ContactRequestItemDelegate::paint(QPainter* painter
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
bool selected = false;
if (option.state & QStyle::State_Selected) {
selected = true;
opt.state ^= QStyle::State_Selected;
painter->fillRect(option.rect, RingTheme::smartlistSelection_);
}
else if (option.state & QStyle::State_MouseOver) {
painter->fillRect(option.rect, RingTheme::smartlistHighlight_);
}
// Then, we print the text
QFont font(painter->font());
font.setPointSize(10);
......@@ -80,16 +90,6 @@ ContactRequestItemDelegate::paint(QPainter* painter
auto cr = index.data(static_cast<int>(Ring::Role::Object)).value<ContactRequest*>();
auto photo = GlobalInstances::pixmapManipulator().contactPhoto(cr->peer(), QSize(sizeImage_, sizeImage_), false);
drawDecoration(painter, opt, rectPic, QPixmap::fromImage(photo.value<QImage>()));
// Draw separator when item is not selected
if (not (opt.state & QStyle::State_Selected)) {
QRect rect(opt.rect);
pen.setColor(RingTheme::lightGrey_);
painter->setPen(pen);
painter->drawLine(rect.left() + separatorYPadding_, rect.bottom(),
rect.right() - separatorYPadding_,
rect.bottom());
}
}
QSize
......
......@@ -31,6 +31,8 @@ static const QColor red_ {251, 72, 71};
static const QColor lightRed_ {252, 91, 90};
static const QColor darkRed_ {219, 55, 54};
static const QColor green_ {127, 255, 0};
static const QColor smartlistSelection_ { 237, 237, 237 };
static const QColor smartlistHighlight_ { 242, 242, 242 };
static const QColor avatarColors_[] {
{"#fff44336"}, //Red
......
......@@ -58,6 +58,16 @@ SmartListDelegate::paint(QPainter* painter
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
bool selected = false;
if (option.state & QStyle::State_Selected) {
selected = true;
opt.state ^= QStyle::State_Selected;
painter->fillRect(option.rect, RingTheme::smartlistSelection_);
}
else if (option.state & QStyle::State_MouseOver) {
painter->fillRect(option.rect, RingTheme::smartlistHighlight_);
}
QRect &rect = opt.rect;
// Avatar drawing
......@@ -116,83 +126,84 @@ SmartListDelegate::paint(QPainter* painter
font.setPointSize(fontSize_);
QPen pen(painter->pen());
if (index.column() == 0)
{
painter->setPen(pen);
if (index.column() != 0) {
if (selected) {
opt.state ^= QStyle::State_Selected;
}
QItemDelegate::paint(painter, opt, index);
return;
}
QRect rectTexts(16 + rect.left() + dx_ + sizeImage_,
rect.top(),
rect.width(),
rect.height() / 2);
painter->setPen(pen);
// The name is displayed at the avatar's right
QVariant name = index.data(static_cast<int>(Ring::Role::Name));
if (name.isValid())
{
pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen);
font.setBold(true);
painter->setFont(font);
QFontMetrics fontMetrics(font);
QString nameStr = fontMetrics.elidedText(name.toString(), Qt::ElideRight
, rectTexts.width()- sizeImage_ - effectiveComBarSize_ - dx_);
painter->drawText(rectTexts, Qt::AlignVCenter | Qt::AlignLeft, nameStr);
}
QRect rectTexts(16 + rect.left() + dx_ + sizeImage_,
rect.top(),
rect.width(),
rect.height() / 2);
// Display the ID under the name
QString idStr = index.data(static_cast<int>(Ring::Role::Number)).value<QString>();
if (idStr != name.toString()){
pen.setColor(RingTheme::grey_);
painter->setPen(pen);
font.setItalic(true);
font.setBold(false);
painter->setFont(font);
QFontMetrics fontMetrics(font);
if (!idStr.isNull()){
idStr = fontMetrics.elidedText(idStr, Qt::ElideRight, rectTexts.width()- sizeImage_ - effectiveComBarSize_ - dx_);
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/7,
rect.width(),
rect.height()/2),
Qt::AlignBottom | Qt::AlignLeft, idStr);
} else {
qDebug() << "This is not a Person";
}
}
// The name is displayed at the avatar's right
QVariant name = index.data(static_cast<int>(Ring::Role::Name));
if (name.isValid())
{
pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen);
font.setBold(true);
painter->setFont(font);
QFontMetrics fontMetrics(font);
QString nameStr = fontMetrics.elidedText(name.toString(), Qt::ElideRight
, rectTexts.width()- sizeImage_ - effectiveComBarSize_ - dx_);
painter->drawText(rectTexts, Qt::AlignVCenter | Qt::AlignLeft, nameStr);
}
// Finally, either last interaction date or call state is displayed
QVariant state = index.data(static_cast<int>(Ring::Role::FormattedState));
// Display the ID under the name
QString idStr = index.data(static_cast<int>(Ring::Role::Number)).value<QString>();
if (idStr != name.toString()){
pen.setColor(RingTheme::grey_);
painter->setPen(pen);
font.setItalic(false);
font.setItalic(true);
font.setBold(false);
painter->setFont(font);
rectTexts.moveTop(cellHeight_/2);
if (state.isValid() && RecentModel::instance().getActiveCall(RecentModel::instance().peopleProxy()->mapToSource(index)))
{
QFontMetrics fontMetrics(font);
if (!idStr.isNull()){
idStr = fontMetrics.elidedText(idStr, Qt::ElideRight, rectTexts.width()- sizeImage_ - effectiveComBarSize_ - dx_);
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/2,
rect.top() + rect.height()/7,
rect.width(),
rect.height()/2),
Qt::AlignLeft | Qt::AlignVCenter, state.toString());
}
else
{
QVariant lastUsed = index.data(static_cast<int>(Ring::Role::FormattedLastUsed));
if (lastUsed.isValid())
{
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/2,
rect.width(),
rect.height()/2),
Qt::AlignLeft | Qt::AlignVCenter, lastUsed.toString());
}
Qt::AlignBottom | Qt::AlignLeft, idStr);
} else {
qDebug() << "This is not a Person";
}
}
// Finally, either last interaction date or call state is displayed
QVariant state = index.data(static_cast<int>(Ring::Role::FormattedState));
pen.setColor(RingTheme::grey_);
painter->setPen(pen);
font.setItalic(false);
font.setBold(false);
painter->setFont(font);
rectTexts.moveTop(cellHeight_/2);
if (state.isValid() && RecentModel::instance().getActiveCall(RecentModel::instance().peopleProxy()->mapToSource(index)))
{
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/2,
rect.width(),
rect.height()/2),
Qt::AlignLeft | Qt::AlignVCenter, state.toString());
}
else
{
QItemDelegate::paint(painter, opt, index);
QVariant lastUsed = index.data(static_cast<int>(Ring::Role::FormattedLastUsed));
if (lastUsed.isValid())
{
painter->drawText(QRect(16 + rect.left() + dx_ + sizeImage_,
rect.top() + rect.height()/2,
rect.width(),
rect.height()/2),
Qt::AlignLeft | Qt::AlignVCenter, lastUsed.toString());
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment