Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Status dot icon #126

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added resources/icons/buddy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/away_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/away_small_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/busy_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/busy_small_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/offline_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/offline_small_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/online_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/status/online_small_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/icons/status_away.png
Binary file not shown.
Binary file removed resources/icons/status_busy.png
Binary file not shown.
Binary file removed resources/icons/status_offline.png
Binary file not shown.
Binary file removed resources/icons/status_online.png
Binary file not shown.
13 changes: 9 additions & 4 deletions resources/resources.qrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<RCC>
<qresource prefix="/">
<file>icons/user_add.png</file>
<file>icons/status_offline.png</file>
<file>icons/status_online.png</file>
<file>icons/page_copy.png</file>
<file>icons/textfield_rename.png</file>
<file>icons/user_delete.png</file>
Expand All @@ -28,8 +26,6 @@
<file>icons/emoticons/emotion_doubt.png</file>
<file>icons/emoticons/emotion_evilgrin.png</file>
<file>icons/error.png</file>
<file>icons/status_away.png</file>
<file>icons/status_busy.png</file>
<file>icons/application_side_list.png</file>
<file>icons/cut.png</file>
<file>icons/paste_plain.png</file>
Expand All @@ -44,5 +40,14 @@
<file>icons/find.png</file>
<file>icons/text_uppercase.png</file>
<file>icons/eye.png</file>
<file>icons/buddy.png</file>
<file>icons/status/offline_small.png</file>
<file>icons/status/offline_small_active.png</file>
<file>icons/status/online_small_active.png</file>
<file>icons/status/online_small.png</file>
<file>icons/status/away_small_active.png</file>
<file>icons/status/away_small.png</file>
<file>icons/status/busy_small_active.png</file>
<file>icons/status/busy_small.png</file>
</qresource>
</RCC>
92 changes: 62 additions & 30 deletions src/frienditemdelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
Copyright (C) 2013 by Maxim Biro <[email protected]>

This file is part of Tox Qt GUI.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the COPYING file for more details.
*/

Expand All @@ -29,57 +29,84 @@ FriendItemDelegate::FriendItemDelegate(QObject* parent) :

QSize FriendItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QIcon statusIcon = QIcon(StatusHelper::getInfo(getStatus(index)).iconPath);
QSize statusIconSize = statusIcon.actualSize(option.decorationSize);
QIcon avatarIcon = QIcon(":/icons/buddy.png");
QSize avatarIconSize = avatarIcon.actualSize(option.decorationSize);

static const int VERTICAL_PADDING = 2;

return QSize(statusIconSize.width(), VERTICAL_PADDING + statusIconSize.height() + VERTICAL_PADDING);
return QSize(avatarIconSize.width(), VERTICAL_PADDING + avatarIconSize.height() + VERTICAL_PADDING);
}

void FriendItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyledItemDelegate::paint(painter, option, index);

painter->save();

QSize hint = sizeHint(option, index);
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
opt.state |= QStyle::State_Active;
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();

//Status Icon
QIcon statusIcon = QIcon(StatusHelper::getInfo(getStatus(index)).iconPath);
QSize statusIconSize = statusIcon.actualSize(option.decorationSize);
// Background
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

static const int ICON_X_OFFSET = 0;
// Avatar Icon
QIcon avatarIcon = QIcon(":/icons/buddy.png");
QSize avatarIconSize = avatarIcon.actualSize(opt.decorationSize);

painter->drawPixmap(ICON_X_OFFSET, option.rect.top() + (hint.height() - statusIconSize.height())/2, statusIcon.pixmap(statusIconSize.width(), statusIconSize.height()));
static const int AVATAR_ICON_X_OFFSET = 0;

QRect avatarRect = QRect(opt.rect.left() + AVATAR_ICON_X_OFFSET, opt.rect.top() + (opt.rect.height() - avatarIconSize.height())/2, avatarIconSize.width(), avatarIconSize.height());
style->drawItemPixmap(painter, avatarRect, opt.displayAlignment, avatarIcon.pixmap(avatarIconSize));

//Username
QString username = index.data(UsernameRole).toString();
// Status dot
QIcon dot;
dot.addFile(StatusHelper::getInfo(getStatus(index)).iconPathSmall, QSize(16,16), QIcon::Normal);
dot.addFile(StatusHelper::getInfo(getStatus(index)).iconPathSmallActive, QSize(16,16), QIcon::Active);
QSize dotSize = dot.actualSize(opt.decorationSize);

static const int DOT_X_OFFSET = 2;

QRect dotRect = QRect(opt.rect.right() - DOT_X_OFFSET - dotSize.width(), opt.rect.top() + (opt.rect.height() - dotSize.height())/2, dotSize.width(), dotSize.height());
style->drawItemPixmap(painter, dotRect, opt.decorationAlignment, dot.pixmap(dotSize.width(), dotSize.height(), getUnreadMessages(index) ? QIcon::Active : QIcon::Normal));

// Username
QString username = index.data(UsernameRole).toString();
QString statusMessage = index.data(StatusMessageRole).toString();
const bool statusMessageIsVisible = statusMessage.trimmed().length() != 0;

QFont usernameFont = QApplication::font();

static const int USERNAME_X_OFFSET = 2;
static const int USERNAME_Y_OFFSET = -3;
static const int STATUS_Y_OFFSET = 2;



QRect nameRect = QRect(AVATAR_ICON_X_OFFSET + avatarIconSize.width() + USERNAME_X_OFFSET,
opt.rect.top() + (opt.rect.height() - opt.fontMetrics.height())/2 - (statusMessageIsVisible ? (opt.fontMetrics.height() + STATUS_Y_OFFSET)/2 : 0),
opt.rect.width() - AVATAR_ICON_X_OFFSET - avatarIconSize.width() - USERNAME_X_OFFSET - DOT_X_OFFSET - dotSize.width() - DOT_X_OFFSET,
opt.fontMetrics.height());
QString elidedUsername = opt.fontMetrics.elidedText(username, Qt::ElideRight, nameRect.width());

painter->setFont(usernameFont);
QString elidedUsername = painter->fontMetrics().elidedText(username, Qt::ElideRight, option.rect.right() - (ICON_X_OFFSET + statusIconSize.width() + USERNAME_X_OFFSET));
painter->drawText(ICON_X_OFFSET + statusIconSize.width() + USERNAME_X_OFFSET, option.rect.top() + hint.height()/2 + ((statusMessageIsVisible ? 0 : painter->fontMetrics().ascent()) - painter->fontMetrics().descent())/2 + (statusMessageIsVisible ? USERNAME_Y_OFFSET : 0), elidedUsername);

if (statusMessageIsVisible) {
//Status Message
QFont statusMessageFont = QApplication::font();

painter->setPen(Qt::gray);
// I fonud no way, to get a styled active item text color :(
QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active))
cg = QPalette::Inactive;
painter->setPen(opt.palette.color(cg, (opt.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text));

static const int STATUSMESSAGE_X_OFFSET = USERNAME_X_OFFSET;
style->drawItemText(painter, nameRect, opt.displayAlignment, opt.palette, (opt.state & QStyle::State_Enabled) ? true : false, elidedUsername);

painter->setFont(statusMessageFont);
QString elidedStatuseMessage = painter->fontMetrics().elidedText(statusMessage, Qt::ElideRight, option.rect.right() - (ICON_X_OFFSET + statusIconSize.width() + STATUSMESSAGE_X_OFFSET));
painter->drawText(ICON_X_OFFSET + statusIconSize.width() + STATUSMESSAGE_X_OFFSET, option.rect.top() + hint.height()/2 + painter->fontMetrics().ascent(), elidedStatuseMessage);
// StatusMessage
if (statusMessageIsVisible) {
QColor color = painter->pen().color();
color.setAlpha(128);
painter->setPen(color);

QRect statusRect = QRect(nameRect.left(),
nameRect.top() + opt.fontMetrics.height() + STATUS_Y_OFFSET,
nameRect.width(),
nameRect.height());
QString elidedStatus = opt.fontMetrics.elidedText(statusMessage, Qt::ElideRight, statusRect.width());
style->drawItemText(painter, statusRect, opt.displayAlignment, opt.palette, (opt.state & QStyle::State_Enabled) ? true : false, elidedStatus);
}

painter->restore();
Expand All @@ -99,3 +126,8 @@ QString FriendItemDelegate::getUsername(const QModelIndex& index)
{
return index.data(UsernameRole).toString();
}

bool FriendItemDelegate::getUnreadMessages(const QModelIndex &index)
{
return index.data(UnreadMessagesRole).toBool();
}
17 changes: 13 additions & 4 deletions src/frienditemdelegate.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
Copyright (C) 2013 by Maxim Biro <[email protected]>

This file is part of Tox Qt GUI.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the COPYING file for more details.
*/

Expand All @@ -25,10 +25,19 @@ class FriendItemDelegate : public QStyledItemDelegate
public:
FriendItemDelegate(QObject *parent = 0);

enum {UsernameRole = Qt::UserRole, StatusRole, StatusMessageRole, UserIdRole, FriendIdRole, LastSeenRole};
enum {
UsernameRole = Qt::UserRole,
StatusRole,
StatusMessageRole,
UserIdRole,
FriendIdRole,
LastSeenRole,
UnreadMessagesRole,
};

static Status getStatus(const QModelIndex& index);
static QString getUsername(const QModelIndex& index);
static bool getUnreadMessages(const QModelIndex& index);

protected:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
Expand Down
4 changes: 2 additions & 2 deletions src/frienditemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FriendItemWidget::FriendItemWidget(QWidget* parent) :
{
statusLabel = new QLabel(this);
statusLabel->setScaledContents(true);
statusLabel->setFixedSize(24, 24);
statusLabel->setFixedSize(16, 16);
setStatus(Status::Offline);

usernameLabel = new CopyableElideLabel(this);
Expand Down Expand Up @@ -63,7 +63,7 @@ FriendItemWidget::FriendItemWidget(QWidget* parent) :

void FriendItemWidget::setStatus(Status status)
{
statusLabel->setPixmap(QPixmap(StatusHelper::getInfo(status).iconPath));
statusLabel->setPixmap(QPixmap(StatusHelper::getInfo(status).iconPathSmall));
}

void FriendItemWidget::setUsername(const QString& username)
Expand Down
18 changes: 18 additions & 0 deletions src/friendswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void FriendsWidget::addFriend(int friendId, const QString& userId)
item->setData(userId, FriendItemDelegate::UserIdRole);
item->setData(friendId, FriendItemDelegate::FriendIdRole);
item->setData(QVariant::fromValue(Status::Offline), FriendItemDelegate::StatusRole);
item->setData(false, FriendItemDelegate::UnreadMessagesRole);
item->setFlags(item->flags() & ~Qt::ItemIsEditable);

friendModel->appendRow(item);
Expand Down Expand Up @@ -175,6 +176,7 @@ void FriendsWidget::onFriendSelectionChanged(const QModelIndex& current, const Q
QStandardItem* item = friendModel->itemFromIndex(friendProxyModel->mapToSource(current));
if (item != nullptr) {
emit friendSelectionChanged(item->data(FriendItemDelegate::FriendIdRole).toInt());
item->setData(false, FriendItemDelegate::UnreadMessagesRole);
}
}

Expand All @@ -201,6 +203,22 @@ void FriendsWidget::setLastSeen(int friendId, const QDateTime &dateTime) {
updateToolTip(friendItem);
}

void FriendsWidget::setUnreadMessage(int friendId, const QString &message)
{
Q_UNUSED(message)

if (friendView->currentIndex().data(FriendItemDelegate::FriendIdRole) == friendId) {
return;
}

QStandardItem* friendItem = findFriendItem(friendId);
if (friendItem == nullptr) {
return;
}

friendItem->setData(true, FriendItemDelegate::UnreadMessagesRole);
}

void FriendsWidget::updateToolTip(QStandardItem* friendItem) const
{
const Status status = FriendItemDelegate::getStatus(friendItem->index());
Expand Down
1 change: 1 addition & 0 deletions src/friendswidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public slots:
void setStatus(int friendId, Status status);
void setStatusMessage(int friendId, const QString& statusMessage);
void setLastSeen(int friendId, const QDateTime& dateTime);
void setUnreadMessage(int friendId, const QString &message);

signals:
void friendAdded(int friendId, const QString& userId);
Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ MainWindow::MainWindow(QWidget* parent)
connect(core, &Core::friendAdded, pages, &PagesWidget::addPage);
connect(core, &Core::friendAdded, friendsWidget, &FriendsWidget::addFriend);
connect(core, &Core::friendMessageReceived, pages, &PagesWidget::messageReceived);
connect(core, &Core::friendMessageReceived,friendsWidget, &FriendsWidget::setUnreadMessage);
connect(core, &Core::actionReceived, pages, &PagesWidget::actionReceived);
connect(core, &Core::friendUsernameChanged, friendsWidget, &FriendsWidget::setUsername);
connect(core, &Core::friendUsernameLoaded, friendsWidget, &FriendsWidget::setUsername);
Expand Down Expand Up @@ -184,7 +185,7 @@ MainWindow::MainWindow(QWidget* parent)
trayMenu->addSeparator();
for (int i = 0; i <= StatusHelper::MAX_STATUS; i ++) {
StatusHelper::Info statusInfo = StatusHelper::getInfo(i);
QAction* statusAction = new QAction(QIcon(statusInfo.iconPath), statusInfo.name, trayMenu);
QAction* statusAction = new QAction(QIcon(statusInfo.iconPathSmall), statusInfo.name, trayMenu);
statusAction->setData(i);
connect(statusAction, &QAction::triggered, this, &MainWindow::onTrayMenuStatusActionTriggered);
trayMenuStatusActions << statusAction;
Expand Down
6 changes: 3 additions & 3 deletions src/ouruseritemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
OurUserItemWidget::OurUserItemWidget(QWidget* parent) :
QWidget(parent)
{
statusButton = createToolButton(QIcon(StatusHelper::getInfo(Status::Offline).iconPath), QSize(24, 24), "Change Status");
statusButton = createToolButton(QIcon(StatusHelper::getInfo(Status::Offline).iconPathSmall), QSize(24, 24), "Change Status");
statusButton->setPopupMode(QToolButton::InstantPopup);
QHBoxLayout* statusButtonLayout = new QHBoxLayout();
statusButtonLayout->setContentsMargins(0, 1, 0, 0);
Expand All @@ -43,7 +43,7 @@ OurUserItemWidget::OurUserItemWidget(QWidget* parent) :
QList<QAction*> statusActions;
for (int i = 0; i <= StatusHelper::MAX_STATUS; i ++) {
StatusHelper::Info statusInfo = StatusHelper::getInfo(i);
QAction* statusAction = new QAction(QIcon(statusInfo.iconPath), statusInfo.name, statusMenu);
QAction* statusAction = new QAction(QIcon(statusInfo.iconPathSmall), statusInfo.name, statusMenu);
statusAction->setData(i);
connect(statusAction, &QAction::triggered, this, &OurUserItemWidget::onStatusActionTriggered);
statusActions << statusAction;
Expand Down Expand Up @@ -156,5 +156,5 @@ void OurUserItemWidget::setFriendAddress(const QString &friendAddress)

void OurUserItemWidget::setStatus(Status status)
{
statusButton->setIcon(QIcon(StatusHelper::getInfo(status).iconPath));
statusButton->setIcon(QIcon(StatusHelper::getInfo(status).iconPathSmall));
}
8 changes: 4 additions & 4 deletions src/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

const QList<StatusHelper::Info> StatusHelper::info =
{
{"Online", ":/icons/status_online.png"},
{"Away", ":/icons/status_away.png"},
{"Busy", ":/icons/status_busy.png"},
{"Offline", ":/icons/status_offline.png"}
{"Online", ":/icons/status/online_small.png", ":/icons/status/online_small_active.png"},
{"Away", ":/icons/status/away_small.png", ":/icons/status/away_small_active.png"},
{"Busy", ":/icons/status/busy_small.png", ":/icons/status/busy_small_active.png"},
{"Offline", ":/icons/status/offline_small.png", ":/icons/status/offline_small_active.png"}
};

StatusHelper::Info StatusHelper::getInfo(int status)
Expand Down
3 changes: 2 additions & 1 deletion src/status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class StatusHelper

struct Info {
QString name;
QString iconPath;
QString iconPathSmall;
QString iconPathSmallActive;
};

static Info getInfo(int status);
Expand Down