From 87ecb28558347c01d2d4e23820f1f726937cfe1b Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 10 Apr 2017 01:34:53 +0300 Subject: [PATCH] Sanitize room info for display --- src/RoomInfoListItem.cc | 25 ++++++++++++------------- src/RoomList.cc | 5 +++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/RoomInfoListItem.cc b/src/RoomInfoListItem.cc index 25daad63..f803ce2e 100644 --- a/src/RoomInfoListItem.cc +++ b/src/RoomInfoListItem.cc @@ -26,7 +26,7 @@ RoomInfoListItem::RoomInfoListItem(RoomInfo info, QWidget *parent) : QWidget(parent) , info_(info) , is_pressed_(false) - , max_height_(65) + , max_height_(60) { normal_style_ = "QWidget { background-color: #5d6565; color: #ebebeb;" @@ -62,19 +62,18 @@ RoomInfoListItem::RoomInfoListItem(RoomInfo info, QWidget *parent) roomAvatar_ = new Avatar(avatarWidget_); roomAvatar_->setLetter(QChar(info_.name()[0])); + roomAvatar_->setSize(max_height_ - 20); avatarLayout_->addWidget(roomAvatar_); - roomName_ = new QLabel(textWidget_); - roomName_->setText(info_.name()); - roomName_->setMaximumSize(230, max_height_ / 2); - roomName_->setStyleSheet("font-weight: 500; font-size: 11.5pt"); - roomName_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + roomName_ = new QLabel(info_.name(), textWidget_); + roomName_->setMaximumSize(parent->width() - 10, 20); + roomName_->setStyleSheet("font-weight: 500; font-size: 14px;"); + roomName_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - roomTopic_ = new QLabel(textWidget_); - roomTopic_->setText(info_.topic()); - roomTopic_->setMaximumSize(230, max_height_ / 2); - roomTopic_->setStyleSheet("color: #c9c9c9; font-size: 10pt"); - roomTopic_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + roomTopic_ = new QLabel(info_.topic(), textWidget_); + roomTopic_->setMaximumSize(parent->width() - 10, 20); + roomTopic_->setStyleSheet("color: #c9c9c9; font-size: 12px"); + roomTopic_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); textLayout_->addWidget(roomName_); textLayout_->addWidget(roomTopic_); @@ -82,8 +81,8 @@ RoomInfoListItem::RoomInfoListItem(RoomInfo info, QWidget *parent) topLayout_->addWidget(avatarWidget_); topLayout_->addWidget(textWidget_); - setElidedText(roomName_, info_.name(), 220); - setElidedText(roomTopic_, info_.topic(), 220); + setElidedText(roomName_, info_.name(), parent->width() - 10); + setElidedText(roomTopic_, info_.topic(), parent->width() - 10); QPainterPath path; path.addRoundedRect(rect(), 0, 0); diff --git a/src/RoomList.cc b/src/RoomList.cc index 4d0b9713..c56ea9b9 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "RoomInfoListItem.h" #include "RoomList.h" @@ -65,6 +66,10 @@ RoomInfo RoomList::extractRoomInfo(const State &room_state) } } + // Sanitize info for print. + info.setTopic(info.topic().replace(QRegularExpression("[\\s\\n\\r]+"), " ")); + info.setName(info.name().replace(QRegularExpression("[\\s\\n\\r]+"), " ")); + return info; }