ui: hide non-displayable character in smartlist
- Also move the video button to the right
Change-Id: Ib1f862ca923a6600457248d672f0b973e3834366
Tuleap: #148
diff --git a/combar.cpp b/combar.cpp
index 74dad89..d21c145 100644
--- a/combar.cpp
+++ b/combar.cpp
@@ -24,9 +24,6 @@
ui(new Ui::ComBar)
{
ui->setupUi(this);
-
- // [jn] these buttons are for further uses
- ui->btncontactinfo->hide();
}
ComBar::~ComBar()
@@ -37,6 +34,6 @@
void
ComBar::moveToRow(const QRect& rect)
{
- move(rect.right() - width(),
+ move(rect.right() - width() - 5,
rect.bottom() - height() - (rect.height()/4));
}
diff --git a/combar.ui b/combar.ui
index b05cd4e..bdbb202 100644
--- a/combar.ui
+++ b/combar.ui
@@ -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/>
diff --git a/smartlistdelegate.cpp b/smartlistdelegate.cpp
index 8e742ab..755c261 100644
--- a/smartlistdelegate.cpp
+++ b/smartlistdelegate.cpp
@@ -41,9 +41,11 @@
{
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 @@
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 @@
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 @@
{
QSize size = QItemDelegate::sizeHint(option, index);
size.setHeight(cellHeight_);
- size.setWidth(cellWidth_);
return size;
}
diff --git a/smartlistdelegate.h b/smartlistdelegate.h
index 7a9494a..a3f0d7f 100644
--- a/smartlistdelegate.h
+++ b/smartlistdelegate.h
@@ -37,7 +37,6 @@
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;