*/
const int LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
+const int WALK_DISTANCE = 5; ///< Walk distance limit for distance icon
+const int CAR_DISTANCE = 500; ///< Car distance limit for distance icon
+const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
+
FriendListItem::FriendListItem(QWidget *parent)
: QWidget(parent)
, m_expanded(false)
topLayout->setMargin(0);
topLayout->setSpacing(0);
+ QVBoxLayout *distanceLayout = new QVBoxLayout();
+ distanceLayout->setMargin(0);
+ distanceLayout->setSpacing(0);
+
QHBoxLayout *bottomLayout = new QHBoxLayout();
bottomLayout->setMargin(0);
bottomLayout->setSpacing(0);
m_nameLabel = new QLabel();
m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
- m_distanceLabel = new QLabel();
- m_distanceLabel->setFixedHeight(IMAGE_HEIGHT);
+ m_distanceTextLabel = new QLabel();
+ m_distanceTextLabel->setFixedHeight(ICON_HEIGHT);
+
+ m_distanceImageLabel = new QLabel();
+ m_distanceImageLabel->setFixedSize(ICON_WIDTH, ICON_HEIGHT);
m_findButton = new ImageButton(this, ":/res/images/show_position.png",
":/res/images/show_position_s.png");
m_locationLabel = new QLabel();
m_locationLabel->setWordWrap(true);
+ distanceLayout->addWidget(m_distanceImageLabel, 0, Qt::AlignRight);
+ distanceLayout->addWidget(m_distanceTextLabel, 0, Qt::AlignRight);
+
infoLayout->addRow(envelopeLabel, m_statusTextLabel);
infoLayout->addRow(compassLabel, m_locationLabel);
infoLayout->addRow(clockLabel, m_updatedLabel);
topLayout->addWidget(m_imageLabel);
topLayout->addWidget(m_nameLabel, 1);
- topLayout->addWidget(m_distanceLabel);
+ topLayout->addLayout(distanceLayout);
bottomLayout->addWidget(m_findButton, 0, Qt::AlignTop);
bottomLayout->addLayout(infoLayout);
QString unit;
double value;
user->distance(value, unit);
- m_distanceLabel->setText(QString::number(value) + " " + unit);
+ m_distanceTextLabel->setText(QString::number(value) + " " + unit);
+ setDistanceIcon(value);
shortenTexts();
setText(false);
}
+void FriendListItem::setDistanceIcon(double value)
+{
+ QPixmap distanceImage;
+
+ if (value < WALK_DISTANCE)
+ distanceImage.load(":/res/images/walk_icon_gray.png");
+ else if (value < CAR_DISTANCE)
+ distanceImage.load(":/res/images/car_icon_gray.png");
+ else if (value < AEROPLANE_DISTANCE)
+ distanceImage.load(":/res/images/aeroplane_icon_gray.png");
+ else
+ distanceImage.load(":/res/images/rocket_icon_gray.png");
+
+ m_distanceImageLabel->setPixmap(distanceImage);
+}
+
void FriendListItem::shortenTexts()
{
qDebug() << __PRETTY_FUNCTION__;
location.append("...");
}
- int distanceLabelWidth = otherLabelsMetrics.width(m_distanceLabel->text());
+ int distanceLabelWidth = otherLabelsMetrics.width(m_distanceTextLabel->text());
m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, NAME_LABEL_MAX_WIDTH
- distanceLabelWidth);
m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
private:
/**
- * @brief Set shortened texts from User data.
+ * @brief Set distance icon.
*
- * Text length is defined by MAXIMUM_CHARS.
+ * Icon is selected by distance.
+ *
+ * @param value distance value
*/
- void shortenTexts();
+ void setDistanceIcon(double value);
/**
* @brief Set shortened or full-length text to labels.
*/
void setText(bool expanded);
+ /**
+ * @brief Set shortened texts from User data.
+ *
+ * Text length is defined by MAXIMUM_CHARS.
+ */
+ void shortenTexts();
+
private slots:
/**
* @brief Slot for find button click
QPixmap m_backgroundMiddleImage; ///< Middle background image
QPixmap m_backgroundBottomImage; ///< Bottom background image
bool m_expanded; ///< Item expanded state
- QLabel *m_distanceLabel; ///< Distance to friend label
+ QLabel *m_distanceImageLabel; ///< Distance image for friend label
+ QLabel *m_distanceTextLabel; ///< Distance text for friend label
ImageButton *m_findButton; ///< Friend find button
QLabel *m_imageLabel; ///< Image label
QLabel *m_locationLabel; ///< Location label