From a54bb37700beaf4654368244daa51dad5fef229d Mon Sep 17 00:00:00 2001 From: Kevin Flynn Date: Fri, 27 Jun 2014 11:11:32 -0700 Subject: [PATCH 1/2] Add mouse hover effect for friends --- widget.ui | 2 +- widget/friendwidget.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ widget/friendwidget.h | 6 ++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/widget.ui b/widget.ui index cfb35d613..1bfc8e5a5 100644 --- a/widget.ui +++ b/widget.ui @@ -940,7 +940,7 @@ true - + 10 diff --git a/widget/friendwidget.cpp b/widget/friendwidget.cpp index 58a06ab62..30ea5e9a3 100644 --- a/widget/friendwidget.cpp +++ b/widget/friendwidget.cpp @@ -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,9 @@ FriendWidget::FriendWidget(int FriendId, QString id) layout.addSpacing(5); layout.addWidget(&statusPic); layout.addSpacing(5); + + int isActiveWidget = 0; + int isCursorOver = 0; } void FriendWidget::mouseReleaseEvent (QMouseEvent*) @@ -62,8 +66,43 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) } } +void FriendWidget::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 FriendWidget::enterEvent(QEvent*) +{ + isCursorOver = 1; + 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 +120,8 @@ void FriendWidget::setAsActiveChatroom() void FriendWidget::setAsInactiveChatroom() { + isActiveWidget = 0; + QFont small; small.setPixelSize(10); statusMessage.setFont(small); diff --git a/widget/friendwidget.h b/widget/friendwidget.h index 3d733c63d..d8ed69d73 100644 --- a/widget/friendwidget.h +++ b/widget/friendwidget.h @@ -13,6 +13,8 @@ public: FriendWidget(int FriendId, QString id); void mouseReleaseEvent (QMouseEvent* event); void contextMenuEvent(QContextMenuEvent * event); + void enterEvent(QEvent* event); + void leaveEvent(QEvent* event); void setAsActiveChatroom(); void setAsInactiveChatroom(); @@ -25,6 +27,10 @@ public: QLabel avatar, name, statusMessage, statusPic; QHBoxLayout layout; QVBoxLayout textLayout; + +private: + void mousePressEvent(QMouseEvent *event); + int isActiveWidget, isCursorOver; }; #endif // FRIENDWIDGET_H From a52e51e1cb7619ae68d1e47bd8aae4ede6c7d6a6 Mon Sep 17 00:00:00 2001 From: Kevin Flynn Date: Fri, 27 Jun 2014 11:22:53 -0700 Subject: [PATCH 2/2] Fixed friend hover highlighting --- widget/friendwidget.cpp | 19 +++++++++++++------ widget/friendwidget.h | 5 +++-- widget/groupwidget.cpp | 37 +++++++++++++++++++++++++++++++++++++ widget/groupwidget.h | 8 ++++++++ 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/widget/friendwidget.cpp b/widget/friendwidget.cpp index 30ea5e9a3..a676f4dd5 100644 --- a/widget/friendwidget.cpp +++ b/widget/friendwidget.cpp @@ -39,8 +39,7 @@ FriendWidget::FriendWidget(int FriendId, QString id) layout.addWidget(&statusPic); layout.addSpacing(5); - int isActiveWidget = 0; - int isCursorOver = 0; + isActiveWidget = 0; } void FriendWidget::mouseReleaseEvent (QMouseEvent*) @@ -70,15 +69,23 @@ void FriendWidget::mousePressEvent(QMouseEvent *event) { if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton) { - QPalette pal; - pal.setColor(QPalette::Background, QColor(85,85,85,255)); - this->setPalette(pal); + 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*) { - isCursorOver = 1; if (isActiveWidget != 1) { QPalette pal; diff --git a/widget/friendwidget.h b/widget/friendwidget.h index d8ed69d73..14ac0a3c7 100644 --- a/widget/friendwidget.h +++ b/widget/friendwidget.h @@ -12,6 +12,7 @@ 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); @@ -29,8 +30,8 @@ public: QVBoxLayout textLayout; private: - void mousePressEvent(QMouseEvent *event); - int isActiveWidget, isCursorOver; + QColor lastColor; + int isActiveWidget; }; #endif // FRIENDWIDGET_H diff --git a/widget/groupwidget.cpp b/widget/groupwidget.cpp index 21337e37a..333131ada 100644 --- a/widget/groupwidget.cpp +++ b/widget/groupwidget.cpp @@ -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); diff --git a/widget/groupwidget.h b/widget/groupwidget.h index b88262f02..19be90bfa 100644 --- a/widget/groupwidget.h +++ b/widget/groupwidget.h @@ -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