⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evaqunchatwindow.cpp

📁 linux下的eva源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** *   Copyright (C) 2005 by yunfan                                          * *   yunfan_zg@163.com                                                     * *                                                                         * *   This program is free 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 2 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         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/ #include "evaqunchatwindow.h"#include "customfaceselector.h"#include "evafontselecter.h"#include "evaresource.h"#include "../evamain.h"#include "evauser.h"#include "evausersetting.h"#include "evatextedit.h"#include "evachatview.h"#include "evaqunlist.h"#include "evaqunlistview.h"#include "evafriend.h"#include "evaqtutil.h"#include "regiongrabber.h"#include "createsmileywindow.h"#include <qtextcodec.h>#include <qiconset.h>#include <qpixmap.h>#include <qimage.h>#include <qevent.h>#include <qpushbutton.h>#include <qtoolbutton.h>#include <qpopupmenu.h>#include <qmessagebox.h>#include <qtooltip.h>#include <qregexp.h>#include <qlistview.h>#include <qtimer.h>#include <qstringlist.h>#include <qfile.h>#include <qfileinfo.h>#include <quuid.h>#include <qapplication.h>#include <klocale.h>#include <kurl.h>#include <kfiledialog.h>#include <kapplication.h>#ifndef QQ_MSG_IM_MAX#define QQ_MSG_IM_MAX 15000#endifunsigned int EvaQunChatWindow::myQQ=0;QString EvaQunChatWindow::myName ="";EvaImageResource *EvaQunChatWindow::images = NULL;bool EvaQunChatWindow::isSentByEnter = false;std::list<QString> EvaQunChatWindow::quickList;EvaQunChatWindow::EvaQunChatWindow( Qun * qun, QWidget * parent, const char * name, WFlags fl )	: EvaQunChatUIBase(parent, name, fl), smileyPopup(NULL), fontSelecter(NULL), quickMenu(NULL),	mQun(qun), grabber(NULL){	codec = QTextCodec::codecForName("GB18030");	initObjects();	initInformation();	initConnection();	graphicChanged();	slotDisplayMembers();	timer = new QTimer();	QObject::connect(timer, SIGNAL(timeout()), SLOT(slotTimeout()));	teInput->setFocus();	if(mQun)		QTimer::singleShot(200, this, SLOT(slotRequestQunRealNames()));}EvaQunChatWindow::~ EvaQunChatWindow( ){	if(timer->isActive())		timer->stop();}void EvaQunChatWindow::setupImages( EvaImageResource * res ){	if(!res) return;	images = res;}void EvaQunChatWindow::setQuickReplyMessages( const std::list< QString > & list ){	quickList = list;}void EvaQunChatWindow::setQuickReplyMenu( ){}const unsigned int EvaQunChatWindow::getQunID( ){	if(mQun)		return mQun->getQunID();	else		return 0;}void EvaQunChatWindow::graphicChanged( ){	if(!images) return;	QStringList imageDirList;	imageDirList.append(images->getSmileyPath());	imageDirList.append(EvaMain::user->getSetting()->getPictureCacheDir());	teInput->mimeSourceFactory()->setFilePath(imageDirList);		tbSmiley->setIconSet(*(images->getIcon("SMILEY")));	tbFont->setIconSet(*(images->getIcon("FONT")));	tbB->setIconSet(*(images->getIcon("FONT_B")));	tbU->setIconSet(*(images->getIcon("FONT_U")));	tbI->setIconSet(*(images->getIcon("FONT_I")));	tbImageFile->setIconSet(*(images->getIcon("CUSTOM_SMILEY")));	tbScreenShot->setIconSet(*(images->getIcon("SCREEN_SHOT")));	tbQuickReply->setIconSet(*(images->getIcon("QUICK_REPLY")));}void EvaQunChatWindow::slotReceivedMessage( unsigned int qunID, unsigned int senderQQ, QString message, QDateTime time, const char size, 					const bool u, const bool i, const bool b, 					const char blue, const char green, const char red ){	if(qunID != mQun->getQunID()) return;	if(senderQQ == myQQ) return;	QString nick = getSenderName(senderQQ) + " (" + QString::number(senderQQ) + ")";	EvaHtmlParser parser;	QString cachesPath = EvaMain::user->getSetting()->getPictureCacheDir();	parser.setAbsImagePath(images->getSmileyPath(), cachesPath);	std::list<CustomizedPic> picList = parser.convertToHtml(message, true, true);	if(picList.size()){		EvaAskForCustomizedPicEvent *event = new EvaAskForCustomizedPicEvent();		event->setPicList(picList);		event->setQunID(qunID);		QApplication::postEvent((QObject *)EvaMain::picManager, event);	}	chatDisplay->append(nick, time, Qt::blue, true, QColor((Q_UINT8)red, (Q_UINT8)green,(Q_UINT8)blue), size, u, i, b, message);}void EvaQunChatWindow::showMessages(){	chatDisplay->showContents();}void EvaQunChatWindow::slotAddMessage(unsigned int sender, QString sNick, unsigned int /*receiver*/, 					QString /*rNick*/, bool isNormal, QString message, 					QDateTime time, const char /*size*/, const bool /*u*/, const bool /*i*/, const bool /*b*/, 					const char /*blue*/, const char /*green*/, const char /*red*/){	if(!teInput->isEnabled()) return;	EvaHtmlParser parser;	parser.convertToHtml(message, false, false, true);	QString msg = QString::number(sender) + "(" +sNick + ")" + (isNormal?(""):i18n("(Auto-Reply)")) + " " + time.toString("yyyy-MM-dd hh:mm:ss") + "<br />" + message;	teInput->append(msg);}void EvaQunChatWindow::slotAddInformation(const QString &info){	chatDisplay->showInfomation(info);}void EvaQunChatWindow::slotSendResult( bool ok ){	if(!ok) {		QMessageBox::information(this, i18n("Message"), i18n("message sent failed"));	} else		teInput->setText("");	pbSend->setEnabled(true);	teInput->setEnabled(true);	teInput->setFocus();}void EvaQunChatWindow::slotDisplayMembers(){	memberList->clear();	std::list<FriendItem>::iterator iter;	std::list<FriendItem> list = mQun->getMembers();		int creator = mQun->getDetails().getCreator();	int id;	short faceID;	QString nick;	for(iter= list.begin(); iter != list.end(); ++iter){		id = iter->getQQ();		faceID = iter->getFace();		nick = EvaTextFilter::filter(codec->toUnicode(iter->getQunRealName().c_str())); // by henry 		// by henry first, use isEmpty is always better then length() == 0 ;P		if(nick.isEmpty())			nick = EvaTextFilter::filter(codec->toUnicode(iter->getNick().c_str()));		QPixmap *pixOn = images->getFace(images->getFaceFileIndex(faceID), true);		QPixmap *pixOff = images->getFace(images->getFaceFileIndex(faceID), false);		const QQFriend *frd = EvaMain::user->getFriendList().getFriend(id);		if(frd && frd->hasUserHead()){			QPixmap *uhPic = images->getUserHeadPixmap(frd->getQQ());			QPixmap *uhPicOff = images->getUserHeadPixmap(frd->getQQ(), true);			if(uhPic) pixOn = uhPic;			if(uhPicOff) pixOff = uhPicOff;		}		EvaQunBuddyItem * item = memberList->addQunBuddy(nick, id, pixOn, pixOff);		if(id == creator){			item->setCreator(true);		}		if(iter->isAdmin())			item->setAdmin(true);		if(iter->isShareHolder())			item->setShareHolder();	}		memberList->setColumnWidth(0, 20);	memberList->setColumnWidth(1, 200);	slotTimeout(); // ask for online member manually}void EvaQunChatWindow::slotUpdateOnlineMembers(){	std::list<unsigned int> onlineList;	std::list<FriendItem>::iterator iter;	std::list<FriendItem> members = mQun->getMembers();	for(iter=members.begin(); iter!=members.end(); ++iter){		if(iter->isOnline()){			if(iter->getQQ() != EvaMain::user->getQQ()){				onlineList.push_back(iter->getQQ());			}else{				if(EvaMain::user->getStatus() == EvaUser::Eva_Online || EvaMain::user->getStatus() == EvaUser::Eva_Leave)					 onlineList.push_back(iter->getQQ());			}			}		}		memberList->updateOnlineMembers(onlineList);}void EvaQunChatWindow::initObjects( ){	fontSelecter = new EvaFontSelecter(this);	fontSelecter->setColor(Qt::black);	if(smileyPopup) delete smileyPopup;	smileyPopup = new CustomFaceSelector(false);			quickMenu = new QPopupMenu(tbQuickReply);	if(quickList.size()){			std::list<QString>::iterator iter;		int index = 0;		for(iter=quickList.begin(); iter!=quickList.end(); ++iter)			quickMenu->insertItem(*iter, index++);		tbQuickReply->setPopup(quickMenu);		tbQuickReply->setPopupDelay(10);		QObject::connect(quickMenu, SIGNAL(activated(int)), this,  SLOT(slotQuickReplyActivated(int)));	}		sendKey = new QPopupMenu();	sendKey->setCheckable(true);	sendKey->insertItem(i18n("Press \"Enter\" to Send"),this,SLOT(setEnterSend()),SHIFT+ALT+Key_Enter,1);  	sendKey->insertItem(i18n("Press \"Ctrl+Enter\" to Send"),this, SLOT(setCtrlEnterSend()),SHIFT+CTRL+ALT+Key_Enter,2);	if(isSentByEnter)		sendKey->setItemChecked(1,true);	else		sendKey->setItemChecked(2,true);	pbSendKey->setPopup(sendKey); 	teInput->setEnterSendEnabled(isSentByEnter);		tbtnNotice->setIconSet(QIconSet(*(images->getIcon("SYSTEM_MSG"))));	}void EvaQunChatWindow::initInformation( ){	if(!mQun) return;	//QString nick = codec->toUnicode(buddy->getNick().c_str());	QString name = codec->toUnicode(mQun->getDetails().getName().c_str());	QString title = i18n("Qun") + QString(" - %1").arg(name);	setCaption(title);	QIconSet face;	setIcon(*(images->getIcon("QUN")));	face.setPixmap(*(images->getIcon("QUN")),QIconSet::Large);	tbQunDetails->setIconSet(face);	tbQunDetails->setTextLabel(name + " ("+QString::number(mQun->getDetails().getExtID()) +")");		QToolTip::add(tbQunDetails, name + "("+QString::number(mQun->getDetails().getExtID()) +") ");		QString notice = codec->toUnicode(mQun->getDetails().getNotice().c_str());	lblNotice->setText(notice);	//lblNotice->adjustSize();}void EvaQunChatWindow::initConnection( ){	if(smileyPopup){		connect(smileyPopup, SIGNAL(selectSysFace(int)), this, SLOT(slotSmileySelected(int)));		connect(smileyPopup, SIGNAL(selectCustomFace(const QString &)), this, SLOT(slotAddImageToInputEdit(const QString &)));		connect(smileyPopup, SIGNAL(addSmileyClicked()), this, SLOT(slotManageCustomSmileys()));	}	QObject::connect(tbQunDetails, SIGNAL(clicked()), this, SLOT(slotTbQunDetailsClick()));	QObject::connect(tbSmiley, SIGNAL(clicked()), this, SLOT(slotSmileyClick()));	QObject::connect(tbFont, SIGNAL(clicked()), this, SLOT(slotFontClick()));	QObject::connect(tbImageFile, SIGNAL(clicked()), this, SLOT(slotImageFileClick()));	QObject::connect(tbScreenShot, SIGNAL(clicked()), this, SLOT(slotScreenShotClick()));	QObject::connect(tbQuickReply, SIGNAL(clicked()), this, SLOT(slotQuickReplyClick()));	QObject::connect(pbHistory, SIGNAL(clicked()), this, SLOT(slotHistoryClick()));	QObject::connect(pbSendKey, SIGNAL(clicked()), this, SLOT(slotSendKeyClick()));	QObject::connect(pbSend, SIGNAL(clicked()), this, SLOT(slotSend()));	QObject::connect(tbtnNotice, SIGNAL(clicked()), this, SLOT(slotNoticeClick()));	//QObject::connect(tbShowBuddy, SIGNAL(clicked()), this, SLOT(slotTbShowBuddyClick()));	//QObject::connect(tbShowMe, SIGNAL(clicked()), this, SLOT(slotTbShowMeClick()));	QObject::connect(teInput, SIGNAL(keyPressed(QKeyEvent *)), this, SLOT(slotInputKeyPress(QKeyEvent *)));		QObject::connect(fontSelecter, SIGNAL(fontChanged(QColor, int)), this, SLOT(slotFontChanged(QColor, int)));	QObject::connect(pbClose, SIGNAL(clicked()), this, SLOT(slotPbCloseClick()));		QObject::connect(memberList, SIGNAL(requestBuddyInfo(const unsigned int)), this, SIGNAL(requestDetails(const unsigned int)));	QObject::connect(memberList, SIGNAL(requestQunCard(const unsigned int)), this, SLOT(slotRequestQunCard(const unsigned int)));	QObject::connect(memberList, SIGNAL(requestQunMembers()), this, SLOT(slotRequestQunMembers()));	connect(chatDisplay, SIGNAL(saveAsCustomSmiley(QString )), this, SLOT(slotSaveAsCustomSmiley(QString)) );}void EvaQunChatWindow::displaySendingMessage( ){	EvaHtmlParser parser;	parser.setAbsImagePath(images->getSmileyPath());	QString text = teInput->text();	QString tmp;	parser.convertToPlainTxt(text, tmp);	parser.convertToHtml(text,true, true);	QString name = getSenderName( myQQ);	int fontSize = mQun->getChatFontSize();	QColor fontColor(mQun->getChatFontColor());	chatDisplay->append( name, sendtime, Qt::darkCyan, true, fontColor, (char)fontSize, 				tbU->isOn(), tbI->isOn(), tbB->isOn(), text);	showMessages();	//teInput->setText("");}void EvaQunChatWindow::slotSmileySelected( int fid){	if(!teInput->isEnabled()) return;	QString smiley = "<img src=\"" + QString::number(fid) + ".gif\">";		int para;	int index;	QFont saveFont = teInput->font();	QColor saveColor = teInput->color();	// determine the current position of the cursor	teInput->insert("\255", false, true, true);		teInput->getCursorPosition(&para,&index);	QString txt = teInput->text();	txt.replace(QRegExp("\255"),smiley);	teInput->setText(txt);	teInput->setCursorPosition(para, index);	teInput->setCurrentFont(saveFont);	teInput->setColor(saveColor);}void EvaQunChatWindow::slotTbQunDetailsClick( ){	emit requestQunDetails(mQun->getQunID());}void EvaQunChatWindow::slotSmileyClick( ){	if(smileyPopup){		QPoint p = teInput->mapToGlobal(QPoint(0,0));		smileyPopup->setGeometry(p.x() + tbSmiley->x() , p.y(), smileyPopup->width(), smileyPopup->height());		smileyPopup->show();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -