1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #8 from F1ynn/master

Add mouse hover effect for friend list
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-06-27 20:32:26 +02:00
commit 84b3e4f395
5 changed files with 101 additions and 1 deletions

View File

@ -940,7 +940,7 @@
<property name="autoFillBackground">
<bool>true</bool>
</property>
<widget class="QLabel" name="label">
<widget class="QLabel" name="profilePicture">
<property name="geometry">
<rect>
<x>10</x>

View File

@ -16,6 +16,7 @@ FriendWidget::FriendWidget(int FriendId, QString id)
avatar.setPixmap(QPixmap("img/contact list icons/contact.png"));
name.setText(id);
//statusPic.setAlignment(Qt::AlignHCenter);
statusPic.setPixmap(QPixmap("img/status/dot_away.png"));
QFont small;
small.setPixelSize(10);
@ -37,6 +38,8 @@ FriendWidget::FriendWidget(int FriendId, QString id)
layout.addSpacing(5);
layout.addWidget(&statusPic);
layout.addSpacing(5);
isActiveWidget = 0;
}
void FriendWidget::mouseReleaseEvent (QMouseEvent*)
@ -62,8 +65,51 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
}
}
void FriendWidget::mousePressEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton)
{
if (isActiveWidget)
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(250,250,250,255));
this->setPalette(pal);
}
else
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(85,85,85,255));
this->setPalette(pal);
}
}
}
void FriendWidget::enterEvent(QEvent*)
{
if (isActiveWidget != 1)
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(75,75,75,255));
lastColor = this->palette().background().color();
this->setPalette(pal);
}
}
void FriendWidget::leaveEvent(QEvent*)
{
if (isActiveWidget != 1)
{
QPalette pal;
pal.setColor(QPalette::Background, lastColor);
this->setPalette(pal);
}
}
void FriendWidget::setAsActiveChatroom()
{
isActiveWidget = 1;
QFont small;
small.setPixelSize(10);
statusMessage.setFont(small);
@ -81,6 +127,8 @@ void FriendWidget::setAsActiveChatroom()
void FriendWidget::setAsInactiveChatroom()
{
isActiveWidget = 0;
QFont small;
small.setPixelSize(10);
statusMessage.setFont(small);

View File

@ -12,7 +12,10 @@ struct FriendWidget : public QWidget
public:
FriendWidget(int FriendId, QString id);
void mouseReleaseEvent (QMouseEvent* event);
void mousePressEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent * event);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
void setAsActiveChatroom();
void setAsInactiveChatroom();
@ -25,6 +28,10 @@ public:
QLabel avatar, name, statusMessage, statusPic;
QHBoxLayout layout;
QVBoxLayout textLayout;
private:
QColor lastColor;
int isActiveWidget;
};
#endif // FRIENDWIDGET_H

View File

@ -41,6 +41,8 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
layout.addSpacing(5);
layout.addLayout(&textLayout);
layout.addStretch();
isActiveWidget = 0;
}
void GroupWidget::mouseReleaseEvent (QMouseEvent*)
@ -66,6 +68,37 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
}
}
void GroupWidget::mousePressEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton)
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(85,85,85,255));
this->setPalette(pal);
}
}
void GroupWidget::enterEvent(QEvent*)
{
if (isActiveWidget != 1)
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(75,75,75,255));
lastColor = this->palette().background().color();
this->setPalette(pal);
}
}
void GroupWidget::leaveEvent(QEvent*)
{
if (isActiveWidget != 1)
{
QPalette pal;
pal.setColor(QPalette::Background, lastColor);
this->setPalette(pal);
}
}
void GroupWidget::onUserListChanged()
{
Group* g = GroupList::findGroup(groupId);
@ -77,6 +110,8 @@ void GroupWidget::onUserListChanged()
void GroupWidget::setAsActiveChatroom()
{
isActiveWidget = 1;
QFont small;
small.setPixelSize(10);
nusers.setFont(small);
@ -94,6 +129,8 @@ void GroupWidget::setAsActiveChatroom()
void GroupWidget::setAsInactiveChatroom()
{
isActiveWidget = 0;
QFont small;
small.setPixelSize(10);
nusers.setFont(small);

View File

@ -13,7 +13,11 @@ public:
GroupWidget(int GroupId, QString Name);
void onUserListChanged();
void mouseReleaseEvent (QMouseEvent* event);
void mousePressEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent * event);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
signals:
void groupWidgetClicked(GroupWidget* widget);
@ -26,6 +30,10 @@ public:
QVBoxLayout textLayout;
void setAsInactiveChatroom();
void setAsActiveChatroom();
private:
QColor lastColor;
int isActiveWidget;
};
#endif // GROUPWIDGET_H