USA.
*/
+#include <QFormLayout>
+#include <QLabel>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QSettings>
+#include <QVBoxLayout>
+
#include "common.h"
#include "imagebutton.h"
-#include "../user/user.h"
+#include "user/user.h"
+
#include "userinfo.h"
-const int BACKGROUND_WIDTH = 240; ///< Width for item
-const int BACKGROUND_TOP_HEIGHT = 16; ///< Height for item top
-const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Height for item bottom
-const int ICON_HEIGHT = 24; ///< Icon height
-const int ICON_WIDTH = 24; ///< Icon width
-const int MARGIN = 5; ///< Icon margin
-const int LINE_LENGTH = 17; ///< Line length
-const int MOUSE_PRESS_AREA_WIDTH = 20; ///< Area width for item height toggling
-const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
-
-/**
-* @var LABEL_MAX_WIDTH
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - ICON_WIDTH + 130;
+const int BACKGROUND_BOTTOM_HEIGHT = 15;
+const int BACKGROUND_TOP_HEIGHT = 20;
+const int BACKGROUND_WIDTH = 368;
+const int ICON_HEIGHT = 24;
+const int ICON_WIDTH = 24;
+const int LABEL_MAX_WIDTH = 300;
+const int MARGIN = 5;
UserInfo::UserInfo(QWidget *parent)
: QWidget(parent),
m_expanded(false),
- m_messageUpdateVerified(false),
m_updateLocation(0)
{
qDebug() << __PRETTY_FUNCTION__;
clockLabel->setContentsMargins(0, 0, MARGIN, 0);
clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
- m_findButton = new ImageButton();
+ m_avatar = new ImageButton();
m_nameLabel = new QLabel();
- m_nameLabel->setWordWrap(true);
m_statusTextLabel = new QLabel();
m_statusTextLabel->setWordWrap(true);
m_updatedLabel = new QLabel();
m_updatedLabel->setWordWrap(true);
- ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
- ":/res/images/refresh_s.png");
- ImageButton *updateStatusMessageButton = new ImageButton(this, ":/res/images/send_position.png",
- ":/res/images/send_position_s.png");
+ ImageButton *updateFriendsButton = new ImageButton(":/res/images/refresh.png",
+ ":/res/images/refresh_s.png",
+ "", this);
+ ImageButton *updateStatusMessageButton = new ImageButton(":/res/images/send_position.png",
+ ":/res/images/send_position_s.png",
+ "", this);
buttonLayout->addWidget(updateFriendsButton);
buttonLayout->addWidget(updateStatusMessageButton);
infoLayout->addRow(compassLabel, m_locationLabel);
infoLayout->addRow(clockLabel, m_updatedLabel);
- verticalLayout->addWidget(m_findButton, 0, Qt::AlignHCenter);
+ verticalLayout->addWidget(m_avatar, 0, Qt::AlignHCenter);
verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
verticalLayout->addLayout(infoLayout);
verticalLayout->addLayout(buttonLayout);
connect(updateFriendsButton,SIGNAL(clicked()),
this, SIGNAL(refreshUserData()));
- connect(m_findButton, SIGNAL(clicked()),
+ connect(m_avatar, SIGNAL(clicked()),
this, SLOT(findButtonClicked()));
setFixedWidth(BACKGROUND_WIDTH);
namePalette.setColor(QPalette::Foreground, Qt::white);
m_nameLabel->setPalette(namePalette);
- m_backgroundTopImage.load(":/res/images/user_info_item_top.png");
- m_backgroundMiddleImage.load(":/res/images/user_info_item_middle.png");
- m_backgroundBottomImage.load(":/res/images/user_info_item_bottom.png");
+ m_backgroundTopImage.load(":/res/images/list_item_top.png");
+ m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
+ m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
restoreUnsendMessage();
}
QSettings settings(DIRECTORY_NAME, FILE_NAME);
- if (!m_backupMessage.isEmpty()) {
+ if (!m_backupMessage.isEmpty()) {
settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
} else {
}
}
-void UserInfo::setAddress(const QString &address)
+void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
{
qDebug() << __PRETTY_FUNCTION__;
- m_locationLabel->setText(address);
+ m_backupMessage = status;
+ m_backupFacebookPublishPolicity = publish;
}
-void UserInfo::setCoordinates(const QPointF &coordinates)
+void UserInfo::clearUpdateLocationDialogData()
{
qDebug() << __PRETTY_FUNCTION__;
- m_coordinates = coordinates;
+ m_backupMessage.clear();
+ m_backupFacebookPublishPolicity = false;
}
-void UserInfo::setMessageText(const QString &text)
+void UserInfo::collapse()
{
qDebug() << __PRETTY_FUNCTION__;
- m_messageText = text;
- m_expandedMessageText = text;
- int textWidth = fontMetrics().width(m_expandedMessageText);
-
- if (textWidth > 150){
- QStringList words = m_expandedMessageText.split(" ");
-
- for (int i = 0; i < words.count();i++){
- QString temp = words.at(i);
-
- if(temp.length() >= LINE_LENGTH) {
- temp.insert(LINE_LENGTH,QString("\n"));
- words.replace(i,temp);
- }
- }
- m_expandedMessageText = words.join(" ");
- }
-
- setText(false);
+ setExpanded(false);
}
-void UserInfo::setProfileImage(const QPixmap &image)
+void UserInfo::findButtonClicked()
{
qDebug() << __PRETTY_FUNCTION__;
- m_findButton->setButtonIcon(image);
+ emit findUser(m_coordinates);
}
-void UserInfo::setTime(const QString &time)
+void UserInfo::messageUpdate()
{
qDebug() << __PRETTY_FUNCTION__;
- m_updatedLabel->setText(time);
+ delete m_updateLocation;
+ m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
+ this);
+
+ connect(this, SIGNAL(reverseGeoReady(QString)),
+ m_updateLocation, SLOT(setAddress(QString)));
+
+ connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
+ this, SIGNAL(statusUpdate(QString, bool)));
+
+ connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
+ this, SLOT(backupUpdateLocationDialogData(QString, bool)));
+
+ connect(m_updateLocation, SIGNAL(finished(int)),
+ this, SLOT(updateLocationDialogFinished(int)));
+
+ m_updateLocation->show();
+
+ emit requestReverseGeo();
}
-void UserInfo::setUserName(const QString &name)
+void UserInfo::mousePressEvent(QMouseEvent *event)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
- m_userName = name;
- setText(false);
+ m_mousePosition = event->pos();
}
-void UserInfo::setText(bool expanded)
+void UserInfo::mouseReleaseEvent(QMouseEvent *event)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
- if (expanded) {
- m_statusTextLabel->setText(m_expandedMessageText);
- }
- else {
- m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
- m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
- LABEL_MAX_WIDTH));
+ const int MOUSE_PRESS_AREA_HEIGHT = 20;
+ const int MOUSE_PRESS_AREA_WIDTH = 20;
+
+ 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) {
+ setExpanded(false);
+ m_expanded = false;
+ }
+ else {
+ setExpanded(true);
+ m_expanded = true;
+ }
}
}
-void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
+void UserInfo::paintEvent(QPaintEvent *event)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
- m_backupMessage = status;
- m_backupFacebookPublishPolicity = publish;
+ QPainter painter(this);
- m_messageUpdateVerified = false;
-}
+ QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
-void UserInfo::clearUpdateLocationDialogData()
-{
- qDebug() << __PRETTY_FUNCTION__;
+ QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_WIDTH,
+ this->height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
- m_backupMessage.clear();
- m_backupFacebookPublishPolicity = false;
+ QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_WIDTH,
+ BACKGROUND_BOTTOM_HEIGHT);
+
+ painter.drawPixmap(topRect, m_backgroundTopImage);
+ painter.drawPixmap(middleRect, m_backgroundMiddleImage);
+ painter.drawPixmap(bottomRect, m_backgroundBottomImage);
}
-void UserInfo::findButtonClicked()
+void UserInfo::restoreUnsendMessage()
{
qDebug() << __PRETTY_FUNCTION__;
- emit findUser(m_coordinates);
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
+ m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
}
-void UserInfo::mouseReleaseEvent(QMouseEvent *event)
+void UserInfo::setAddress(const QString &address)
{
- qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+ qDebug() << __PRETTY_FUNCTION__;
- 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;
- }
- }
+ m_locationLabel->setText(address);
}
-void UserInfo::mousePressEvent(QMouseEvent *event)
+void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
{
- qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+ qDebug() << __PRETTY_FUNCTION__;
- m_mousePosition = event->pos();
+ m_coordinates = coordinates;
}
-void UserInfo::messageUpdate()
+void UserInfo::setMessageText(const QString &text)
{
qDebug() << __PRETTY_FUNCTION__;
- emit requestReverseGeo();
-
- delete m_updateLocation;
- m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
- this);
+ QStringList list;
+ list = text.split(' ');
- connect(this, SIGNAL(reverseGeoReady(QString)),
- m_updateLocation, SLOT(setAddress(QString)));
+ for (int i = 0; i < list.count(); i++) {
+ if (fontMetrics().width(list.at(i)) > LABEL_MAX_WIDTH)
+ list.replace(i, splitWord(list.at(i)));
+ }
- connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
- this, SIGNAL(statusUpdate(QString,bool)));
+ m_messageText = list.join(" ");
- connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
- this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+ setExpanded(false);
+}
- connect(m_updateLocation, SIGNAL(finished(int)),
- this, SLOT(updateLocationDialogFinished(int)));
+void UserInfo::setProfileImage(const QPixmap &image)
+{
+ qDebug() << __PRETTY_FUNCTION__;
- m_updateLocation->show();
+ if(!image.isNull())
+ m_avatar->setButtonIcon(image);
}
-void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
+void UserInfo::setExpanded(bool expanded)
{
- qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
+ qDebug() << __PRETTY_FUNCTION__;
- QPainter painter(this);
+ if (expanded)
+ m_statusTextLabel->setText(m_messageText);
+ else
+ m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText, LABEL_MAX_WIDTH));
+}
- QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
- QRect middleRect = QRect(0, topRect.bottom(), BACKGROUND_WIDTH,
- height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
- QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
- BACKGROUND_BOTTOM_HEIGHT);
+void UserInfo::setTime(const QString &time)
+{
+ qDebug() << __PRETTY_FUNCTION__;
- painter.drawPixmap(topRect, m_backgroundTopImage);
- painter.drawPixmap(middleRect, m_backgroundMiddleImage);
- painter.drawPixmap(bottomRect, m_backgroundBottomImage);
+ m_updatedLabel->setText(time);
}
-void UserInfo::restoreUnsendMessage()
+void UserInfo::setUserName(const QString &name)
{
qDebug() << __PRETTY_FUNCTION__;
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
- m_backupFacebookPublishPolicity =
- settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
+ m_userName = name;
+
+ m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
}
QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
qDebug() << __PRETTY_FUNCTION__;
QFontMetrics labelMetrics = label->fontMetrics();
- QString textParam = text;
- int index = textParam.indexOf('\n');
- int textWidth = fontMetrics().width(textParam);
+ QString copiedText = text;
+ int index = copiedText.indexOf('\n');
- if (index > 0) {
- textParam.truncate(index);
- textParam.append("...");
- }
- if (textWidth > 150)
- textParam.insert(LINE_LENGTH, QString("\n"));
+ if (index >= 0) {
+ copiedText.truncate(index);
+ copiedText.append("...");
+ }
- return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
+ return labelMetrics.elidedText(copiedText, Qt::ElideRight, textMaxWidth);
}
-void UserInfo::verifyMessageUpdateFailure(const int error)
+QString UserInfo::splitWord(const QString &word) const
{
qDebug() << __PRETTY_FUNCTION__;
- Q_UNUSED(error);
+ QString result;
+ QString temp;
- if (!m_messageUpdateVerified) {
-
- if (m_messageText != m_backupMessage && !m_backupMessage.isEmpty())
- emit notificateUpdateFailing(tr("Location update failed, please try again"), false);
+ for (int i = 0; i < word.length(); i++) {
+ if (fontMetrics().width(temp.append(word.at(i))) > LABEL_MAX_WIDTH) {
+ result.append(temp.left(temp.length() - 1));
+ result.append(" ");
+ temp.remove(0, temp.length() - 1);
+ }
}
- m_messageUpdateVerified = true;
+ result.append(temp);
+
+ return result;
}
void UserInfo::updateLocationDialogFinished(int reason)
m_updateLocation->deleteLater();
m_updateLocation = 0;
}
-
}