m_nameLabel = new QLabel();
m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
-
-
m_updatedLabel = new QLabel();
m_updatedLabel->setWordWrap(true);
m_statusTextLabel = new QLabel();
void UserInfo::setAvatar(const QPixmap &image)
{
-// m_avatar = image;
-// // m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
-// //m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
-// m_imageLabel->setPixmap(m_avatar);
+ m_avatar = image;
+ // m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
+ //m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
+ m_imageLabel->setPixmap(m_avatar);
}
void UserInfo::setAddress(const QString &addr)
{
- if(m_address == addr)
- return;
- m_address = addr;
- m_locationLabel->setText(m_address);
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_locationLabel->setText(addr);
// shortenTexts();
}
return;
m_time = tim;
m_updatedLabel->setText(m_time);
-// shortenTexts();
+ shortenTexts();
}
-//void UserInfo::shortenTexts()
-//{
-// qDebug() << __PRETTY_FUNCTION__;
-//
-// QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
-// QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
-//
-// QString name = m_userName;
-// QString updated = m_time;
-// QString statusText = m_messageText;
-// QString location = m_address;
-//
-// int nameIndex = name.indexOf('\n');
-// int updatedIndex = updated.indexOf('\n');
-// int statusTextIndex = statusText.indexOf('\n');
-// int locationIndex = location.indexOf('\n');
-//
-// if (nameIndex > 0) {
-// name.truncate(nameIndex);
-// name.append("...");
-// }
-// if (updatedIndex > 0) {
-// updated.truncate(updatedIndex);
-// updated.append("...");
-// }
-// if (statusTextIndex > 0) {
-// statusText.truncate(statusTextIndex);
-// statusText.append("...");
-// }
-// if (locationIndex > 0) {
-// location.truncate(locationIndex);
-// location.append("...");
-// }
-//
-// m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, LABEL_MAX_WIDTH + 30);
-// m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
-// m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
-// LABEL_MAX_WIDTH);
-// m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
-//}
-//
-//void UserInfo::setText(bool expanded)
-//{
-// qDebug() << __PRETTY_FUNCTION__;
-//
-// if (expanded) {
-// m_nameLabel->setText(m_userName);
-// m_updatedLabel->setText(m_time);
-// m_statusTextLabel->setText(m_messageText);
-// m_locationLabel->setText(m_address);
-// }
-// else {
-// m_nameLabel->setText(m_shortenedName);
-// m_updatedLabel->setText(m_shortenedUpdated);
-// m_statusTextLabel->setText(m_shortenedStatusText);
-// m_locationLabel->setText(m_shortenedLocation);
-// }
-//}
-
-//void UserInfo::mouseReleaseEvent(QMouseEvent *event)
-//{
-// qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
-//
-// if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
-// (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
-// if (m_expanded) {
-// setText(false);
-// m_expanded = false;
-// }
-// else {
-// setText(true);
-// m_expanded = true;
-// }
-// }
-//}
+void UserInfo::shortenTexts()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
+ QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
+
+ QString name = m_userName;
+ QString updated = m_time;
+ QString statusText = m_messageText;
+ QString location = m_address;
+
+ int nameIndex = name.indexOf('\n');
+ int updatedIndex = updated.indexOf('\n');
+ int statusTextIndex = statusText.indexOf('\n');
+ int locationIndex = location.indexOf('\n');
+
+ if (nameIndex > 0) {
+ name.truncate(nameIndex);
+ name.append("...");
+ }
+ if (updatedIndex > 0) {
+ updated.truncate(updatedIndex);
+ updated.append("...");
+ }
+ if (statusTextIndex > 0) {
+ statusText.truncate(statusTextIndex);
+ statusText.append("...");
+ }
+ if (locationIndex > 0) {
+ location.truncate(locationIndex);
+ location.append("...");
+ }
+
+ m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, LABEL_MAX_WIDTH + 30);
+ m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
+ m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
+ LABEL_MAX_WIDTH);
+ m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
+}
+
+void UserInfo::setText(bool expanded)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (expanded) {
+ m_nameLabel->setText(m_userName);
+ m_updatedLabel->setText(m_time);
+ m_statusTextLabel->setText(m_messageText);
+ m_locationLabel->setText(m_address);
+ }
+ else {
+ m_nameLabel->setText(m_shortenedName);
+ m_updatedLabel->setText(m_shortenedUpdated);
+ m_statusTextLabel->setText(m_shortenedStatusText);
+ m_locationLabel->setText(m_shortenedLocation);
+ }
+}
+
+void UserInfo::mouseReleaseEvent(QMouseEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+
+ if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
+ (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
+ if (m_expanded) {
+ setText(false);
+ m_expanded = false;
+ }
+ else {
+ setText(true);
+ m_expanded = true;
+ }
+ }
+}
void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
{
// Q_UNUSED(aPaintEvent);
qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
QPainter painter(this);
+
QRect topRect = QRect(0, 0, ITEM_MIN_WIDTH, BACKGROUND_TOP_HEIGHT);
QRect middleRect = QRect(0, topRect.bottom(), ITEM_MIN_WIDTH,
height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
* @param event QMouseEvent mouse press event
*/
void mousePressEvent(QMouseEvent *event);
-// /**
-// * @brief Call toggleHeight if mouse position is unchanged.
-// *
-// * Check if current mouse position is same as mouse release position.
-// * @param event QMouseEvent mouse release event
-// */
-// void mouseReleaseEvent(QMouseEvent *event);
+ /**
+ * @brief Call toggleHeight if mouse position is unchanged.
+ *
+ * Check if current mouse position is same as mouse release position.
+ * @param event QMouseEvent mouse release event
+ */
+ void mouseReleaseEvent(QMouseEvent *event);
/******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
* @param tim Reference to time when message was sent.
*/
void setTime(const QString &tim);
- /**
+ /**
* @brief Sets the user name
*
* @param usernam Reference to user name
*
*/
void messageUpdate();
-// /**
-// * @brief Set shortened or full-length text to labels.
-// *
-// * @param expanded true if full-length text is set, false otherwise
-// */
-// void setText(bool expanded);
-// /**
-// * @brief Set shortened texts from User data.
-// *
-// * Text length is defined by MAXIMUM_CHARS.
-// */
-// void shortenTexts();
+ /**
+ * @brief Set shortened or full-length text to labels.
+ *
+ * @param expanded true if full-length text is set, false otherwise
+ */
+ void setText(bool expanded);
+ /**
+ * @brief Set shortened texts from User data.
+ *
+ * Text length is defined by MAXIMUM_CHARS.
+ */
+ void shortenTexts();
/**
* @brief Slot function to forward friends status update signal
*
QString m_address;
QString m_time;
QString m_messageText;
- QString m_avatar;
+ QPixmap m_avatar;
QString m_shortenedLocation; ///< Shortened location text
QString m_shortenedName; ///< Shortened name text
QString m_shortenedStatusText; ///< Shortened status text