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

📄 evachatwindow.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 "evachatwindow.h"#include "customfaceselector.h"#include "evafontselecter.h"#include "evaresource.h"#include "../evamain.h"#include "evauser.h"#include "evausersetting.h"#include "evafriendlist.h"#include "evatextedit.h"#include "evahtmlparser.h"#include "evachatview.h"#include "evaipseeker.h"#include "evafilepanel.h"#include "evafilestatusuibase.h"#include "regiongrabber.h"#include <qtextcodec.h>#include <qrect.h>#include <qlabel.h>#include <qlayout.h>#include <qiconset.h>#include <qpixmap.h>#include <qhostaddress.h>#include <qevent.h>#include <qpushbutton.h>#include <qtoolbutton.h>#include <qlineedit.h>#include <qpopupmenu.h>#include <qtooltip.h>#include <qregexp.h>#include <qdir.h>#include <qfileinfo.h>#include <qimage.h>#include <quuid.h>#include <qtimer.h>#include <klocale.h>#include <kurl.h>#include <kfiledialog.h>#include <kmessagebox.h>#include <kapplication.h>#ifndef QQ_MSG_IM_MAX#define QQ_MSG_IM_MAX 15000#endifint EvaChatWindow::myQQ=0;QString EvaChatWindow::myName ="";EvaImageResource *EvaChatWindow::images = NULL;bool EvaChatWindow::isSentByEnter = false;std::list<QString> EvaChatWindow::quickList;	EvaChatWindow::EvaChatWindow(QQFriend * frd, QWidget* parent, const char* name, WFlags fl)	: EvaChatUIBase(parent, name, fl), smileyPopup(NULL), quickMenu(NULL), fontSelecter(NULL),	m_NumImages(0), grabber(NULL){	//buddy = new QQFriend(*frd);	buddy = frd;	codec = QTextCodec::codecForName("GB18030");	initObjects();	initInformation();	initConnection();	graphicChanged();	kteInput->setFocus();}EvaChatWindow::~EvaChatWindow(){	//delete buddy;}void EvaChatWindow::setupImages(EvaImageResource *res){	if(!res) return;	images = res;}void EvaChatWindow::setQuickReplyMessages(const std::list<QString> &list) { 	quickList = list; }const unsigned int EvaChatWindow::getBuddyQQ(){	return buddy->getQQ();}void EvaChatWindow::graphicChanged(){	QStringList imageDirList;	imageDirList.append(images->getSmileyPath());	imageDirList.append(EvaMain::user->getSetting()->getPictureCacheDir());	kteInput->mimeSourceFactory()->setFilePath(imageDirList);		tbSmiley->setIconSet(*(images->getIcon("SMILEY")));	tbFont->setIconSet(*(images->getIcon("FONT")));	tbFile->setIconSet(*(images->getIcon("FILE_TRANSFER")));	tbB->setIconSet(*(images->getIcon("FONT_B")));	tbU->setIconSet(*(images->getIcon("FONT_U")));	tbI->setIconSet(*(images->getIcon("FONT_I")));	tbAddImage->setIconSet(*(images->getIcon("SEND_IMAGE")));	tbScreenShot->setIconSet(*(images->getIcon("SCREEN_SHOT")));	tbQuickReply->setIconSet(*(images->getIcon("QUICK_REPLY")));	tbHideShows->setIconSet(*(images->getIcon("HIDE_PORTRAIT")));	slotBuddyQQShowReady(getBuddyQQ());	slotMyQQShowReady();}void EvaChatWindow::initObjects(){	if(fontSelecter) delete fontSelecter;	fontSelecter = new EvaFontSelecter(this);	if(smileyPopup) delete smileyPopup;	smileyPopup = new CustomFaceSelector();		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); 	kteInput->setEnterSendEnabled(isSentByEnter);}void EvaChatWindow::initInformation(){	if(!buddy) return;	QString nick = codec->toUnicode(buddy->getNick().c_str());	QString title = QString(i18n("Chatting with %1")).arg(nick);	setCaption(title);	QString status =i18n("(offline)");	QIconSet face;	int faceId = buddy->getFace();	QPixmap *faceOnPic=NULL, *faceOffPic=NULL;	if(buddy->hasUserHead()){		faceOnPic = images->getUserHeadPixmap(buddy->getQQ());		faceOffPic = images->getUserHeadPixmap(buddy->getQQ(), true); // true means grayscale true	}	if(!faceOnPic || !faceOffPic){		faceOnPic = images->getFace(images->getFaceFileIndex(faceId));		faceOffPic = images->getFace(images->getFaceFileIndex(faceId), false); // false means on-line off	}	setIcon(*faceOnPic);		face.setPixmap(*faceOffPic,QIconSet::Large);	tbBuddy->setIconSet(face);	switch(buddy->getStatus()){	case 10:		status = i18n("(online)");		face.setPixmap(*faceOnPic,QIconSet::Large);		tbBuddy->setIconSet(face);		break;	case 20:		//status = i18n("(offline)");		//face.setPixmap(*(images->getFace(images->getFaceFileIndex(faceId), false)),QIconSet::Large);		//tbBuddy->setIconSet(face);		break;	case 30:{		status = i18n("(leave)");		QPixmap pixleave(*faceOnPic);		QPixmap pixna(*(images->getIcon("NA")));		copyBlt(&pixleave, pixleave.width()-pixna.width(),pixleave.height()-pixna.height(), 			&pixna,0,0, pixna.width(), pixna.height());		face.setPixmap(pixleave, QIconSet::Large);		tbBuddy->setIconSet(face);		}		break;	case 40:		status = i18n("(invisible)");		face.setPixmap(*faceOffPic, QIconSet::Large);		tbBuddy->setIconSet(face);		break;	}	tbBuddy->setTextLabel(nick);	QToolTip::add(tbBuddy, nick + "("+QString::number(buddy->getQQ()) +") " + status);		QString ip = QHostAddress(buddy->getIP()).toString();	EvaIPSeeker ipAddr(EvaGlobal::getDirPath().latin1());	QString addr = codec->toUnicode(ipAddr.getIPLocation(ip.latin1()).c_str());	leIP->setText(addr);		QString sig = codec->toUnicode(buddy->getSignature().c_str());	lblSignature->setText("  " + sig);		//QString port = QString::number(((int)(buddy->getPort()))==-1?0:(unsigned int)(buddy->getPort()));	QToolTip::add(leIP, ip + " : " + QString::number(buddy->getPort()));	}void EvaChatWindow::initConnection(){	if(smileyPopup) {		connect(smileyPopup, SIGNAL(selectSysFace(int)), this, SLOT(slotSmileySelected(int)));		// we might need the following later on		//connect(smileyPopup, SIGNAL(selectCustomFace(const QString &)), this, SLOT(slotAddImageToInputEdit(const QString &)));	}	QObject::connect(tbBuddy, SIGNAL(clicked()), this, SLOT(slotTbBuddyClick()));	QObject::connect(tbSmiley, SIGNAL(clicked()), this, SLOT(slotSmileyClick()));	QObject::connect(tbFont, SIGNAL(clicked()), this, SLOT(slotFontClick()));	QObject::connect(tbFile, SIGNAL(clicked()), this, SLOT(slotFileClick()));	QObject::connect(tbAddImage, SIGNAL(clicked()), this, SLOT(slotAddImageClick()));	QObject::connect(tbScreenShot, SIGNAL(clicked()), this, SLOT(slotScreenShotClick()));	QObject::connect(tbQuickReply, SIGNAL(clicked()), this, SLOT(slotQuickReplyClick()));	QObject::connect(tbHideShows, SIGNAL(clicked()), this, SLOT(slotHideShowsClick()));	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(tbShowBuddy, SIGNAL(clicked()), this, SLOT(slotTbShowBuddyClick()));	QObject::connect(tbShowMe, SIGNAL(clicked()), this, SLOT(slotTbShowMeClick()));	QObject::connect(kteInput, SIGNAL(keyPressed(QKeyEvent *)), this, SLOT(slotInputKeyPress(QKeyEvent *)));	if(fontSelecter)		QObject::connect(fontSelecter, SIGNAL( fontChanged(QColor, int)), this, SLOT(slotFontChanged( QColor, int )));	QObject::connect(pbClose, SIGNAL(clicked()), this, SLOT(slotPbCloseClick()));	QObject::connect(chatDisplay, SIGNAL(fileTransferAcceptRequest(const unsigned int)), 						SLOT(slotFileTransferAcceptClicked(const unsigned int)));	QObject::connect(chatDisplay, SIGNAL(fileTransferSaveAsRequest(const unsigned int)), 						SLOT(slotFileTransferSaveAsClicked(const unsigned int)));	QObject::connect(chatDisplay, SIGNAL(fileTransferCancelRequest(const unsigned int)), 						SLOT(slotFileTransferCancelClicked(const unsigned int)));	QObject::connect(chatDisplay, SIGNAL(fileTransferResume(const unsigned int, const bool)), 						SLOT(slotFileTransferResume(const unsigned int, const bool)));	QObject::connect(m_FilePanel, SIGNAL(closeSession(const unsigned int)),					SLOT(slotFilePanelCloseClicked( const unsigned int )));}void EvaChatWindow::displaySendingMessage(){	EvaHtmlParser parser;	parser.setAbsImagePath(images->getSmileyPath());	QString text = kteInput->text();	QString tmp;	parser.convertToPlainTxt(text, tmp);	parser.convertToHtml(text,true, true);		QColor chatColor(buddy->getChatFontColor());	int chatSize =  buddy->getChatFontSize();	chatDisplay->append( myName, sendtime, Qt::darkCyan, true, chatColor, (char)chatSize, 				tbU->isOn(), tbI->isOn(), tbB->isOn(), text);	showMessages();	//kteInput->setText("");}void EvaChatWindow::slotReceivedMessage(unsigned int sender, 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(sender != buddy->getQQ()) return;	QString nick = codec->toUnicode(buddy->getNick().c_str());	EvaHtmlParser parser;	parser.setAbsImagePath(images->getSmileyPath());	parser.convertToHtml(message, true, true);	chatDisplay->append(nick, time, Qt::blue, isNormal,				QColor((Q_UINT8)red, (Q_UINT8)green,(Q_UINT8)blue),				size, u, i, b, message);}void EvaChatWindow::showMessages(){	chatDisplay->showContents();}void EvaChatWindow::slotAddMessage(unsigned int , QString sNick, int , QString , bool isNormal, 				QString message, QDateTime time, const char , 				const bool , const bool , const bool , 				const char , const char , const char ){		if(!kteInput->isEnabled()) return;	EvaHtmlParser parser;	parser.convertToHtml(message, false, false, true);	QString msg = sNick + (isNormal?(""):i18n("(Auto-Reply)")) + " " + time.toString("yyyy-MM-dd hh:mm:ss") + "<br />" + message;	kteInput->append(msg);}void EvaChatWindow::slotSendResult(bool ok){	if(!ok) {		KMessageBox::information(this, i18n("message sent failed"), i18n("Message"));	} else		kteInput->setText("");	pbSend->setEnabled(true);	kteInput->setEnabled(true);	//kteInput->setParagraphBackgroundColor(0, Qt::white);	kteInput->setFocus();}void EvaChatWindow::slotBuddyQQShowReady(const unsigned int id){	if(id!= getBuddyQQ()) return;	QPixmap *pix = images->getQQShow(id);	if(pix){ 		QImage img = pix->convertToImage();		tbShowBuddy->setIconSet(QPixmap(img.smoothScale(tbShowBuddy->width()-8, tbShowBuddy->height() -2)));	}}void EvaChatWindow::slotMyQQShowReady(){	QPixmap *pix = images->getQQShow(myQQ);	if(pix){		QImage img = pix->convertToImage();		tbShowMe->setIconSet(QPixmap(img.smoothScale(tbShowMe->width()-8, tbShowMe->height() -2)));	}}void EvaChatWindow::slotSmileySelected(int fid){	if(!kteInput->isEnabled()) return;	QString smiley = "<img src=\"" + QString::number(fid) + ".gif\"> ";		int para;	int index;	QFont saveFont = kteInput->font();	QColor saveColor = kteInput->color();	// determine the current position of the cursor	kteInput->insert("\255", false, true, true);		kteInput->getCursorPosition(&para,&index);	QString txt = kteInput->text();	txt.replace(QRegExp("\255"),smiley);	kteInput->setText(txt);	kteInput->setCursorPosition(para, index);	kteInput->setCurrentFont(saveFont);	kteInput->setColor(saveColor);}void EvaChatWindow::slotTbBuddyClick(){	emit requestDetails(buddy->getQQ());}void EvaChatWindow::slotSmileyClick(){	if(smileyPopup){		QPoint p = kteInput->mapToGlobal(QPoint(0,0));		smileyPopup->setGeometry(p.x() + tbSmiley->x() , p.y(), smileyPopup->width(), smileyPopup->height());		smileyPopup->show();	}	}void EvaChatWindow::slotFontClick(){	if(!fontSelecter) return;	if(fontSelecter->isVisible()) 		fontSelecter->hide();	else{		QPoint p = kteInput->mapToGlobal(QPoint(0,0));		fontSelecter->setColor( QColor(buddy->getChatFontColor()));		fontSelecter->setSize( buddy->getChatFontSize());		fontSelecter->setGeometry(p.x() + tbFont->x() , p.y(), fontSelecter->width(), fontSelecter->height());		fontSelecter->show(); 	}}void EvaChatWindow::slotQuickReplyClick(){	//tbQuickReply->openPopup();	//quickMenu->exec();}void EvaChatWindow::slotQuickReplyActivated(int id){	if(!kteInput->isEnabled()) return;	std::list<QString>::iterator iter;	int index = 0;	for(iter=quickList.begin(); iter!=quickList.end(); ++iter){		if(index == id) break;			index++;	}	QString message = *iter;	EvaHtmlParser parser;	parser.convertToHtml(message, false);	kteInput->append(message);		slotSend();}void EvaChatWindow::slotHideShowsClick(){	if(m_ShowFrame->isVisible()){		//m_FilePanel->hide();		m_FilePanelFrame->hide();		m_ShowFrame->hide();		//lblBuddyShow->hide();		//tbShowBuddy->hide();		//lblMeShow->hide();		//tbShowMe->hide();		EvaChatUIBaseLayout->removeItem(layout19);		tbHideShows->setIconSet(*(images->getIcon("SHOW_PORTRAIT")));		QValueList<int> list;		list.append(150);		list.append(100);		splitter->setSizes(list);		resize( QSize(320, 367).expandedTo(minimumSizeHint()) );	}else{		//m_FilePanel->show();		m_FilePanelFrame->show();		m_ShowFrame->show();		//lblBuddyShow->show();		//tbShowBuddy->show();		//lblMeShow->show();		//tbShowMe->show();		EvaChatUIBaseLayout->addLayout(layout19);		tbHideShows->setIconSet(*(images->getIcon("HIDE_PORTRAIT")));		QValueList<int> list;		list.append(150);		list.append(100);		splitter->setSizes(list);		resize( QSize(450, 422).expandedTo(minimumSizeHint()) );	}}void EvaChatWindow::slotHistoryClick(){	emit requestHistory(getBuddyQQ());}void EvaChatWindow::slotSendKeyClick(){

⌨️ 快捷键说明

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