diff --git a/qtox.pro b/qtox.pro index 6060257cc..043086e8c 100644 --- a/qtox.pro +++ b/qtox.pro @@ -97,7 +97,8 @@ HEADERS += widget/form/addfriendform.h \ style.h \ widget/adjustingscrollarea.h \ widget/croppinglabel.h \ - widget/friendlistwidget.h + widget/friendlistwidget.h \ + widget/genericchatroomwidget.h SOURCES += \ widget/form/addfriendform.cpp \ @@ -134,4 +135,5 @@ SOURCES += \ widget/adjustingscrollarea.cpp \ widget/croppinglabel.cpp \ widget/friendlistwidget.cpp \ - coreav.cpp + coreav.cpp \ + widget/genericchatroomwidget.cpp diff --git a/widget/friendwidget.cpp b/widget/friendwidget.cpp index d41f3f52c..d703bfd60 100644 --- a/widget/friendwidget.cpp +++ b/widget/friendwidget.cpp @@ -122,47 +122,6 @@ 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; @@ -201,11 +160,6 @@ void FriendWidget::setAsInactiveChatroom() avatar.setPixmap(QPixmap(":img/contact.png")); } -int FriendWidget::isActive() -{ - return isActiveWidget; -} - void FriendWidget::updateStatusLight() { Friend* f = FriendList::findFriend(friendId); diff --git a/widget/friendwidget.h b/widget/friendwidget.h index b174c2914..aae226bab 100644 --- a/widget/friendwidget.h +++ b/widget/friendwidget.h @@ -22,21 +22,18 @@ #include #include +#include "genericchatroomwidget.h" #include "croppinglabel.h" -struct FriendWidget : public QWidget +struct FriendWidget : public GenericChatroomWidget { Q_OBJECT 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(); - int isActive(); void updateStatusLight(); signals: @@ -48,12 +45,6 @@ public: int friendId; QLabel avatar, statusPic; CroppingLabel name, statusMessage; - QHBoxLayout layout; - QVBoxLayout textLayout; - -private: - QColor lastColor; - int isActiveWidget; }; #endif // FRIENDWIDGET_H diff --git a/widget/genericchatroomwidget.cpp b/widget/genericchatroomwidget.cpp new file mode 100644 index 000000000..339fa125e --- /dev/null +++ b/widget/genericchatroomwidget.cpp @@ -0,0 +1,68 @@ +/* + Copyright (C) 2014 by Project Tox + + This file is part of qTox, a Qt-based graphical interface for Tox. + + This program is libre 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. +*/ + +#include "genericchatroomwidget.h" +#include + +GenericChatroomWidget::GenericChatroomWidget(QWidget *parent) : + QWidget(parent) +{ +} + +int GenericChatroomWidget::isActive() +{ + return isActiveWidget; +} + +void GenericChatroomWidget::mousePressEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton) + { + if (isActive()) + { + 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 GenericChatroomWidget::leaveEvent(QEvent *) +{ + if (isActive() != 1) + { + QPalette pal; + pal.setColor(QPalette::Background, lastColor); + this->setPalette(pal); + } +} + +void GenericChatroomWidget::enterEvent(QEvent *) +{ + if (isActive() != 1) + { + QPalette pal; + pal.setColor(QPalette::Background, QColor(75,75,75,255)); + lastColor = this->palette().background().color(); + this->setPalette(pal); + } +} diff --git a/widget/genericchatroomwidget.h b/widget/genericchatroomwidget.h new file mode 100644 index 000000000..7960dd099 --- /dev/null +++ b/widget/genericchatroomwidget.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2014 by Project Tox + + This file is part of qTox, a Qt-based graphical interface for Tox. + + This program is libre 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. +*/ + +#ifndef GENERICCHATROOMWIDGET_H +#define GENERICCHATROOMWIDGET_H + +#include +#include +#include + +class GenericChatroomWidget : public QWidget +{ + Q_OBJECT +public: + GenericChatroomWidget(QWidget *parent = 0); + void mousePressEvent(QMouseEvent *event); + void leaveEvent(QEvent *); + void enterEvent(QEvent *); + + virtual void setAsActiveChatroom(){;} + virtual void setAsInactiveChatroom(){;} + virtual void updateStatusLight(){;} + int isActive(); + +signals: + void chatroomWidgetClicked(GenericChatroomWidget* widget); + +public slots: + +protected: + int isActiveWidget; + QColor lastColor; + QHBoxLayout layout; + QVBoxLayout textLayout; +}; + +#endif // GENERICCHATROOMWIDGET_H diff --git a/widget/groupwidget.cpp b/widget/groupwidget.cpp index ac0608b1b..1f3e695a6 100644 --- a/widget/groupwidget.cpp +++ b/widget/groupwidget.cpp @@ -94,46 +94,6 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent * event) } } -void GroupWidget::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 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); @@ -180,3 +140,8 @@ void GroupWidget::setAsInactiveChatroom() this->setPalette(pal3); avatar.setPixmap(QPixmap(":img/group.png")); } + +void GroupWidget::updateStatusLight() +{ + +} diff --git a/widget/groupwidget.h b/widget/groupwidget.h index ab2cf8929..ef21cda11 100644 --- a/widget/groupwidget.h +++ b/widget/groupwidget.h @@ -19,22 +19,19 @@ #include #include -#include -#include +#include "genericchatroomwidget.h" -class GroupWidget : public QWidget +class GroupWidget : public GenericChatroomWidget { Q_OBJECT 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); void setAsInactiveChatroom(); void setAsActiveChatroom(); + void updateStatusLight(); signals: void groupWidgetClicked(GroupWidget* widget); @@ -43,12 +40,6 @@ signals: public: int groupId; QLabel avatar, name, nusers, statusPic; - QHBoxLayout layout; - QVBoxLayout textLayout; - -private: - QColor lastColor; - int isActiveWidget; }; #endif // GROUPWIDGET_H