00001 #include "GUITabList.h"
00002 #include <QEvent>
00003 #include <QMouseEvent>
00004 #include <QTabBar>
00005
00006 GUITabList::GUITabList(QWidget *parent, QHostAddress broadcast,
00007 QString sm, QString um, QString bc): QTabWidget(parent)
00008 {
00009 this->sm = sm;
00010 this->um = um;
00011 this->bc = bc;
00012
00013 this->addTab(broadcast ,QString("Public Chat"),
00014 false,"icon/Chat/user_group.png");
00015 connect(this, SIGNAL(currentChanged(int)),this,SLOT(checkCBC(int)));
00016 connect(this, SIGNAL(currentChanged(int)),this,SLOT(checkOnline(int)));
00017 connect(this, SIGNAL(currentChanged(int)),this,SLOT(setDefaultIconAndColor(int)));
00018
00019 }
00020
00021 void GUITabList::setTabTextColor(int index, QColor col)
00022 {
00023 ((QTabBar*)(this->tabBar()))->setTabTextColor(index,col);
00024 }
00025
00026 void GUITabList::addTab(QHostAddress ip,QString name,bool can_be_closed = true,
00027 QString icon = "icon/Chat/user.png")
00028 {
00029 int i=isCreate(ip);
00030 if(!i)
00031 {
00032 this->QTabWidget::addTab(new GUITab(this,ip,name,can_be_closed,sm,um,bc),QIcon(icon),name);
00033 setActiveTab(ip);
00034 }
00035 else
00036 {
00037 setCurrentIndex(i);
00038 }
00039 }
00040
00041 void GUITabList::delTab(QHostAddress ip)
00042 {
00043
00044 }
00045
00046
00047 void GUITabList::hideTab(QHostAddress ip)
00048 {
00049
00050 }
00051
00052 void GUITabList::showTab(QHostAddress ip)
00053 {
00054
00055 }
00056
00057 void GUITabList::setActiveTab (QHostAddress ip)
00058 {
00059 int index = getTabNumber(ip);
00060 if(index != 0)
00061 {
00062 setCurrentIndex(index);
00063 }
00064 }
00065
00066
00067 GUITab* GUITabList::getActiveTab()
00068 {
00069 return((GUITab*)this->currentWidget());
00070 }
00071
00072 GUITab* GUITabList::publicChat()
00073 {
00074 return tab(0);
00075 }
00076
00077 GUITab* GUITabList::tab(int index)
00078 {
00079 return((GUITab*)this->widget(index));
00080 }
00081
00082 void GUITabList::closeTab(GUITab *tab)
00083 {
00084 if(tab->getCBC())
00085 {
00086 this->removeTab(this->getTabNumber(tab->getIp()));
00087 }
00088 }
00089
00090 int GUITabList::isCreate(QHostAddress ip)
00091 {
00092 for(int i=0; i<this->count();i++)
00093 {
00094 QHostAddress tmp = ((GUITab*)this->widget(i))->getIp();
00095 if(tmp == ip )
00096 {
00097 return i;
00098 }
00099 }
00100 return 0;
00101 }
00102
00103 void GUITabList::closeActiveTab()
00104 {
00105 closeTab(getActiveTab());
00106 }
00107
00108 int GUITabList::getTabNumber(QHostAddress ip)
00109 {
00110 int tab_num = this->isCreate(ip);
00111 if(tab_num != 0)
00112 {
00113 return tab_num;
00114 }
00115 else
00116 {
00117 return 0;
00118 }
00119 }
00120
00121 void GUITabList::checkCBC(int index)
00122 {
00123 if (((GUITab*)this->widget(index))->getCBC() == false)
00124 {
00125 emit tabCanNotBeClose();
00126 }
00127 else
00128 {
00129 emit tabCanBeClose();
00130 }
00131 }
00132
00133 void GUITabList::checkOnline(int index)
00134 {
00135 if (((GUITab*)this->widget(index))->getOnline() == false)
00136 {
00137 emit isNotOnline();
00138 }
00139 else
00140 {
00141 emit isOnline();
00142 }
00143
00144 }
00145
00146 void GUITabList::setUnactiveUser(QHostAddress host)
00147 {
00148 if(isCreate(host))
00149 {
00150 this->setTabIcon(getTabNumber(host),QIcon("icon/Chat/offline_user.png"));
00151 this->setTabTextColor(getTabNumber(host),Qt::black);
00152 tab(getTabNumber(host))->setOnline(false);
00153 emit setDisableInputText();
00154 }
00155 }
00156
00157 void GUITabList::closeAllPrivChat()
00158 {
00159 int tabs = this->count();
00160 for(int i=1; i < tabs;i++)
00161 {
00162 this->setTabIcon(i,QIcon("icon/Chat/offline_user.png"));
00163 tab(i)->setOnline(false);
00164 }
00165 }
00166
00167 void GUITabList::setDefaultIconAndColor(int index)
00168 {
00169 if(index != 0)
00170 {
00171 if(tab(index)->getOnline())
00172 {
00173 this->setTabIcon(index,QIcon("icon/Chat/user.png"));
00174 }
00175 else
00176 {
00177 this->setTabIcon(index,QIcon("icon/Chat/offline_user.png"));
00178 }
00179 ((QTabBar*)(this->tabBar()))->setTabTextColor(index,Qt::black);
00180 }
00181 else
00182 {
00183 this->setTabIcon(index,QIcon("icon/Chat/user_group.png"));
00184 ((QTabBar*)(this->tabBar()))->setTabTextColor(index,Qt::black);
00185 }
00186 }
00187