Commit 645e4c37 authored by Edric Milaret's avatar Edric Milaret

ui: hide non-displayable character in smartlist

- Also move the video button to the right

Change-Id: Ib1f862ca923a6600457248d672f0b973e3834366
Tuleap: #148
parent a13b48c3
......@@ -24,9 +24,6 @@ ComBar::ComBar(QWidget* parent) :
ui(new Ui::ComBar)
{
ui->setupUi(this);
// [jn] these buttons are for further uses
ui->btncontactinfo->hide();
}
ComBar::~ComBar()
......@@ -37,6 +34,6 @@ ComBar::~ComBar()
void
ComBar::moveToRow(const QRect& rect)
{
move(rect.right() - width(),
move(rect.right() - width() - 5,
rect.bottom() - height() - (rect.height()/4));
}
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>116</width>
<height>37</height>
<width>30</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -16,12 +16,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>116</width>
<height>37</height>
</size>
</property>
<property name="windowTitle">
<string/>
</property>
......@@ -33,13 +27,13 @@
<number>0</number>
</property>
<property name="topMargin">
<number>7</number>
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>7</number>
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btnvideo">
......@@ -66,25 +60,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btncontactinfo">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
......@@ -41,9 +41,11 @@ SmartListDelegate::paint(QPainter* painter
{
QStyleOptionViewItem opt(option);
painter->setRenderHint(QPainter::Antialiasing);
opt.decorationSize = QSize(sizeImage_, sizeImage_);
opt.decorationPosition = QStyleOptionViewItem::Left;
opt.decorationAlignment = Qt::AlignCenter;
if (opt.state & QStyle::State_HasFocus)
opt.state ^= QStyle::State_HasFocus;
......@@ -53,12 +55,15 @@ SmartListDelegate::paint(QPainter* painter
QRect rect = opt.rect;
rect.setLeft(0);
QRect rectTexts(16 + rect.left() + dx_+sizeImage_, rect.top(), rect.width(), rect.height()/2);
QRect rectTexts(16 + rect.left() + dx_ + sizeImage_,
rect.top(),
rect.width(),
rect.height() / 2);
QRect rectAvatar(16 + rect.left(), rect.top() + dy_, sizeImage_, sizeImage_);
drawDecoration(painter, opt, rectAvatar, QPixmap::fromImage(index.data(Qt::DecorationRole).value<QImage>()));
drawDecoration(painter, opt, rectAvatar,
QPixmap::fromImage(index.data(Qt::DecorationRole).value<QImage>()));
const int currentRow = index.row();
if (currentRow == rowHighlighted_)
emit rowSelected(opt.rect);
......@@ -85,7 +90,16 @@ SmartListDelegate::paint(QPainter* painter
painter->setPen(pen);
font.setBold(true);
painter->setFont(font);
painter->drawText(rectTexts, Qt::AlignBottom | Qt::AlignLeft, name.toString());
QFontMetrics fontMetrics(font);
QString nameStr = name.toString();
auto realRect = fontMetrics.boundingRect(rect, Qt::AlignBottom | Qt::AlignLeft, nameStr);
if (realRect.width() > (rect.width() - rectTexts.left() - 30)) {
/* 30 here is the size of the video button */
auto charToChop = (realRect.width() - (rect.width() - rectTexts.left())) / fontMetrics.averageCharWidth();
nameStr.chop(charToChop + 8);
nameStr.append(QStringLiteral("..."));
}
painter->drawText(rectTexts, Qt::AlignBottom | Qt::AlignLeft, nameStr);
}
QVariant state = index.data(static_cast<int>(Ring::Role::FormattedState));
......@@ -126,6 +140,5 @@ SmartListDelegate::sizeHint(const QStyleOptionViewItem& option
{
QSize size = QItemDelegate::sizeHint(option, index);
size.setHeight(cellHeight_);
size.setWidth(cellWidth_);
return size;
}
......@@ -37,7 +37,6 @@ protected:
private:
constexpr static int sizeImage_ = 48;
constexpr static int cellHeight_ = 60;
constexpr static int cellWidth_ = 324;
constexpr static int dy_ = 6;
constexpr static int dx_ = 12;
constexpr static int fontSize_ = 10;
......
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