QT 络通讯软件群聊源码

QT 络通讯软件群聊源码

xteam.h————————————————————-

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “ui_teamchat.h”
//#include “xselectface1.h”
class Team:public QMainWindow, public Ui::MainWindow
{
 Q_OBJECT
 public:
   Team(int,int,QString,QStringList);
   void messagefirmx(int ,QString ,QString );
 private:
   int id;
   int userid;
   QString sname;
   QStringList nlist;
   void list_init();  
   //selectfacemm *ssselectface;
   
   //QString pic;
   quint16 tcpport;
   quint16 udpport;
   //QTcpServer *server;
   QTcpSocket *clientsocket; 
   QUdpSocket *udpsocket;
   QHostAddress address;
   QPixmap screenshot;
   void writeDate(int flag);
   
   void closeEvent(QCloseEvent *event);
   
   
 private slots:
   void setFontColor();
   void setBoldFont(bool flag);
   void setFontxx();
   void windowshot();
   //void sendFileSlot();
   //void sendImageSlot();
   //void showEmotionSlot();
   //void showfaceSlot(QString);
   void sendMessageSlot();
   //void readMessageSlot();
   void requestconnectSlot();
   //void messagefirmSlot(int,QString,QString);
   //void appendpushbuttonSlot();
   //void messangeconfirm();
   
 signals:
   void closebutton(int);
   //void friendmessage(QString,int);
   
};

team.cpp————————————————————————-

#include”xteam.h”
Team::Team(int userid,int id,QString sname,QStringList nlist)
{
 setupUi(this);
 this->userid=userid;
 this->id=id;
 this->sname=sname;
 this->nlist=nlist;
 list_init();
 label->setNum(id);
 textEdit->setReadOnly(true);
 //ssselectface = new selectfacemm();
 
 
 // 络设定
 tcpport = 60001;
 address = “192.168.2.231”; 
 udpport = 45454;
 clientsocket = new QTcpSocket(this);
 udpsocket = new QUdpSocket(this);
 udpsocket->bind(QHostAddress::Any, udpport);
 //工具按钮状态
 toolButton_Font_3->setCheckable(true);
 toolButton_Font_4->setCheckable(true);
 toolButton_Font_2->setCheckable(true);
 //信 和槽
 connect(pushButton_3, SIGNAL(clicked()), this, SLOT(close()));
 connect(toolButton_Font_5, SIGNAL(clicked()), this, SLOT(setFontColor()));
 connect(toolButton_Font_3, SIGNAL(toggled(bool)), textEdit_2, SLOT(setFontItalic(bool)));
 connect(toolButton_Font_4, SIGNAL(toggled(bool)), textEdit_2, SLOT(setFontUnderline(bool)));
 connect(toolButton_Font_2, SIGNAL(toggled(bool)), this, SLOT(setBoldFont(bool)));
 connect(toolButton_Font, SIGNAL(clicked()), this, SLOT(setFontxx()));
 connect(toolButton_Font_7, SIGNAL(clicked()), this, SLOT(windowshot()));
 //connect(toolButton_Font_6, SIGNAL(clicked()), this, SLOT(showEmotionSlot()));
 //connect(ssselectface, SIGNAL(showiconSignal( QString )), this, SLOT(showfaceSlot(QString))); 
 connect(pushButton, SIGNAL(clicked()),this, SLOT(requestconnectSlot()));
 connect(clientsocket, SIGNAL(connected()), this, SLOT(sendMessageSlot()));
 
}
void Team::list_init()
{
 QTreeWidgetItem *a[50]; 
 int d=0;
 treeWidget->clear();
 treeWidget->setColumnCount(2);
 treeWidget->setColumnHidden (1,true );
 QTreeWidgetItem *teamheadItem = new QTreeWidgetItem();
 treeWidget->setHeaderItem(teamheadItem);
 teamheadItem->setText(0, nlist.at(0));
 teamheadItem->setText(1, nlist.at(1));
 teamheadItem->setTextColor(0,QColor::QColor(255,255,0)); 
 for(int i=2 ; i {
  a[d] = new QTreeWidgetItem();
  treeWidget->addTopLevelItem(a[d]);
  a[d]->setText(0,tr(“%1(%2)”)
     .arg(nlist.at(i))
     .arg(nlist.at(i+1)));
  a[d]->setText(1,nlist.at(i+1));
  i++;
  d++;
 }
}
//槽函数,设置字体颜色
void Team::setFontColor()
{
 QColor col = QColorDialog::getColor(textEdit_2->textColor(), this);
 if (!col.isValid())
 {
  return;
 }
 textEdit_2->setTextColor(col);
 
 QPixmap pix(16, 16);
 pix.fill(col);
 toolButton_Font_5->setIcon(pix);
 this->setStatusTip(tr(“set FontColor”));
}
//槽函数,设置输入字体为粗体
void Team::setBoldFont(bool flag)
{
 if(flag == true)
 {
  textEdit_2->setFontWeight(QFont::Bold);
 }
 else
  textEdit_2->setFontWeight(QFont::Normal);
 this->setStatusTip(tr(“set BoldFont”));
}
//槽函数,设置字体大小+选择字体
void Team::setFontxx()
{
  bool ok;
     QFont font = QFontDialog::getFont(&ok, QFont(“Times”, 12), this);
     if (!ok)
  {
   return;
  }
 textEdit_2->setFont(font);
 this->setStatusTip(tr(“set FontSize”));
}
//槽函数,添加表情图片
/*
void Team::showEmotionSlot()
{
 
 ssselectface->show();
 this->setStatusTip(tr(“add Facepic”));
}*/
//槽函数,快速抓屏
void Team::windowshot()
{
 screenshot = QPixmap::grabWindow(QApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height());
 QString format = “png”;
        QString picName = QFileDialog::getSaveFileName(this, tr(“Save As”),
                                   “temp-image/”,
                                   tr(“%1 Files (*.%2);;All Files (*)”)
                                   .arg(format.toUpper())
                                   .arg(format));
       
 
        if (!picName.isEmpty())
  screenshot.save(picName, format.toAscii());
 textEdit_2->append(“

《转 为亲身验证 分析代码没有问题》

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2015年8月11日
下一篇 2015年8月11日

相关推荐