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:
parent
c54cfd6ff3
commit
35b7ad3a58
6
qtox.pro
6
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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -22,21 +22,18 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#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
|
||||
|
|
68
widget/genericchatroomwidget.cpp
Normal file
68
widget/genericchatroomwidget.cpp
Normal 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);
|
||||
}
|
||||
}
|
50
widget/genericchatroomwidget.h
Normal file
50
widget/genericchatroomwidget.h
Normal 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
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -19,22 +19,19 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#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
|
||||
|
|
Loading…
Reference in New Issue
Block a user