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

Chatroom: common parts moved to the parent class

This commit is contained in:
apprb 2014-09-01 22:02:26 +07:00
parent c54cfd6ff3
commit 35b7ad3a58
7 changed files with 132 additions and 111 deletions

View File

@ -97,7 +97,8 @@ HEADERS += widget/form/addfriendform.h \
style.h \ style.h \
widget/adjustingscrollarea.h \ widget/adjustingscrollarea.h \
widget/croppinglabel.h \ widget/croppinglabel.h \
widget/friendlistwidget.h widget/friendlistwidget.h \
widget/genericchatroomwidget.h
SOURCES += \ SOURCES += \
widget/form/addfriendform.cpp \ widget/form/addfriendform.cpp \
@ -134,4 +135,5 @@ SOURCES += \
widget/adjustingscrollarea.cpp \ widget/adjustingscrollarea.cpp \
widget/croppinglabel.cpp \ widget/croppinglabel.cpp \
widget/friendlistwidget.cpp \ widget/friendlistwidget.cpp \
coreav.cpp coreav.cpp \
widget/genericchatroomwidget.cpp

View File

@ -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() void FriendWidget::setAsActiveChatroom()
{ {
isActiveWidget = 1; isActiveWidget = 1;
@ -201,11 +160,6 @@ void FriendWidget::setAsInactiveChatroom()
avatar.setPixmap(QPixmap(":img/contact.png")); avatar.setPixmap(QPixmap(":img/contact.png"));
} }
int FriendWidget::isActive()
{
return isActiveWidget;
}
void FriendWidget::updateStatusLight() void FriendWidget::updateStatusLight()
{ {
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);

View File

@ -22,21 +22,18 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include "genericchatroomwidget.h"
#include "croppinglabel.h" #include "croppinglabel.h"
struct FriendWidget : public QWidget struct FriendWidget : public GenericChatroomWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
FriendWidget(int FriendId, QString id); FriendWidget(int FriendId, QString id);
void mouseReleaseEvent (QMouseEvent* event); void mouseReleaseEvent (QMouseEvent* event);
void mousePressEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent * event); void contextMenuEvent(QContextMenuEvent * event);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
void setAsActiveChatroom(); void setAsActiveChatroom();
void setAsInactiveChatroom(); void setAsInactiveChatroom();
int isActive();
void updateStatusLight(); void updateStatusLight();
signals: signals:
@ -48,12 +45,6 @@ public:
int friendId; int friendId;
QLabel avatar, statusPic; QLabel avatar, statusPic;
CroppingLabel name, statusMessage; CroppingLabel name, statusMessage;
QHBoxLayout layout;
QVBoxLayout textLayout;
private:
QColor lastColor;
int isActiveWidget;
}; };
#endif // FRIENDWIDGET_H #endif // FRIENDWIDGET_H

View File

@ -0,0 +1,68 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
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 <QMouseEvent>
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);
}
}

View File

@ -0,0 +1,50 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
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 <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
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

View File

@ -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() void GroupWidget::onUserListChanged()
{ {
Group* g = GroupList::findGroup(groupId); Group* g = GroupList::findGroup(groupId);
@ -180,3 +140,8 @@ void GroupWidget::setAsInactiveChatroom()
this->setPalette(pal3); this->setPalette(pal3);
avatar.setPixmap(QPixmap(":img/group.png")); avatar.setPixmap(QPixmap(":img/group.png"));
} }
void GroupWidget::updateStatusLight()
{
}

View File

@ -19,22 +19,19 @@
#include <QWidget> #include <QWidget>
#include <QLabel> #include <QLabel>
#include <QHBoxLayout> #include "genericchatroomwidget.h"
#include <QVBoxLayout>
class GroupWidget : public QWidget class GroupWidget : public GenericChatroomWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
GroupWidget(int GroupId, QString Name); GroupWidget(int GroupId, QString Name);
void onUserListChanged(); void onUserListChanged();
void mouseReleaseEvent (QMouseEvent* event); void mouseReleaseEvent (QMouseEvent* event);
void mousePressEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent * event); void contextMenuEvent(QContextMenuEvent * event);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
void setAsInactiveChatroom(); void setAsInactiveChatroom();
void setAsActiveChatroom(); void setAsActiveChatroom();
void updateStatusLight();
signals: signals:
void groupWidgetClicked(GroupWidget* widget); void groupWidgetClicked(GroupWidget* widget);
@ -43,12 +40,6 @@ signals:
public: public:
int groupId; int groupId;
QLabel avatar, name, nusers, statusPic; QLabel avatar, name, nusers, statusPic;
QHBoxLayout layout;
QVBoxLayout textLayout;
private:
QColor lastColor;
int isActiveWidget;
}; };
#endif // GROUPWIDGET_H #endif // GROUPWIDGET_H