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

📄 evalistview.cpp

📁 linux下的eva源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************** *   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 "evalistview.h"#include "evaqunlistview.h"#include "evauser.h"#include "../evamain.h"#include "evaresource.h"#include "evaipseeker.h"#include "evahtmlparser.h"#include "evaqtutil.h"#include "evautil.h"#include "evauhmanager.h"#include "evausersetting.h"#include <qheader.h>#include <qpixmap.h>#include <qimage.h>#include <qtimer.h>#include <qdragobject.h>#include <qtextcodec.h>#include <qpoint.h>#include <qrect.h>#include <qtooltip.h>#include <qpainter.h>#include <qpalette.h>#include <qstyle.h>#include <qsimplerichtext.h>//#include <qapplication.h>#include <klocale.h>EvaToolTip::EvaToolTip(QListView *listView, QToolTipGroup *group)	: QToolTip(static_cast<QWidget *>(listView->viewport()), group),	mListView(listView){	//setPalette( QPalette(Qt::yellow, QColor(20,190,255)));}EvaToolTip::~EvaToolTip(){}void EvaToolTip::maybeTip(const QPoint &p){	QListViewItem *item = dynamic_cast<QListViewItem *>(mListView->itemAt(p));	if(!item) return;	int section = mListView->header()->sectionAt(p.x());	QRect itemRect = mListView->itemRect(item);	QRect headerRect = mListView->header()->sectionRect(section);	QRect destRect(headerRect.left(), itemRect.top(), headerRect.width(), itemRect.height());		EvaBuddyItem *buddy = dynamic_cast<EvaBuddyItem *>(mListView->itemAt(p));	if(buddy){		switch(section){		case 0:			tip(destRect, buddy->tip());			break;		default:			tip(destRect, i18n("Double click to chat"));			break;		}	}else{		EvaGroupItem *group = dynamic_cast<EvaGroupItem *>(mListView->itemAt(p));		if(group){			switch(section){			case 0:				tip(destRect, group->tip());				break;			default:				tip(destRect, i18n("Click to display all members"));				break;			}				}else{			EvaQunItem *qun = dynamic_cast<EvaQunItem *>(mListView->itemAt(p));			if(qun){				switch(section){				case 0:					tip(destRect, qun->tip());					break;				default:					tip(destRect, i18n("Double click to chat"));					break;				}			}else{				EvaQunBuddyItem *qunBuddy = dynamic_cast<EvaQunBuddyItem *>(mListView->itemAt(p));				if(qunBuddy){					switch(section){					case 1:						tip(destRect, qunBuddy->tip());						break;					default:						tip(destRect, i18n("Right click to see more"));						break;					}				}			}		}	}	}QPixmap *EvaBuddyItem::pixNA =0; QPixmap *EvaBuddyItem::pixMsg =0; QSize EvaBuddyItem::faceSize = QSize(16, 16); EvaBuddyItem::EvaBuddyItem( QListViewItem *parent, const QString &nick, const int id, const QString signature,			QPixmap *on, QPixmap *off, EvaBuddyItem::Status s )		: QListViewItem( parent, " "+nick), 		hasMessage(false), status(s),		pixOnline(on), pixOffline(off),nickName(nick), mSignature(signature), qqNum(id),		numOfMessages(0), m_RichText(0), m_Icon(0) //, isMsgShown(false){		setDragEnabled(true);	updateText();	refreshFace(true);}EvaBuddyItem::~EvaBuddyItem(){}void EvaBuddyItem::updateNick(const QString &nick){	nickName = nick;	updateText();}void EvaBuddyItem::updateSignature(const QString &sig){	mSignature = sig;	updateText();}void EvaBuddyItem::updateText(){		EvaUserSetting * setting = EvaMain::user->getSetting();	QString htmlName = nickName;	if(setting->isShowSmileyInNickName()){		EvaHtmlParser parser;		parser.setAbsImagePath(EvaMain::images->getSmileyPath());		parser.convertToHtml(htmlName, false, true);	}	QColor showColor = Qt::black;	if(hasMessage){		if(setting->isBuddyFlashBold())			htmlName = ("<b>" + htmlName + "</b>");		if(setting->isBuddyFlashUnderline())			htmlName = ("<u>" + htmlName + "</u>");		if(setting->isBuddyFlashItalic())			htmlName = ("<i>" + htmlName + "</i>");		showColor = setting->getBuddyFlashColor();	} else {		if(setting->isBuddyNameBold())			htmlName = ("<b>" + htmlName + "</b>");		if(setting->isBuddyNameUnderline())			htmlName = ("<u>" + htmlName + "</u>");		if(setting->isBuddyNameItalic())			htmlName = ("<i>" + htmlName + "</i>");		showColor = setting->getBuddyNameColor();	}	//printf("html name: %s\n", htmlName.ascii());	QString showName = "<nobr><font color=\"" + showColor.name() + "\">&nbsp;" + htmlName + "</font></nobr>";	QString showSig = mSignature;	if( !mSignature.isEmpty() ){		if(setting->isShowSignatureInSeperateLine())			showName += "<br>";		if(setting->isBuddySigBold())			showSig = ("<b>" + showSig + "</b>");		if(setting->isBuddySigUnderline())			showSig = ("<u>" + showSig + "</u>");		if(setting->isBuddySigItalic())			showSig = ("<i>" + showSig + "</i>");		showName += ("<nobr><font color=\"" + setting->getBuddySigColor().name() + "\">&nbsp;[" + showSig + "]</font></nobr>");	} else {		if(setting->isShowSignatureInSeperateLine())  // just to make sure each item has the same height			showName += "<br>&nbsp;";	}	if(m_RichText) delete m_RichText;	m_RichText = new QSimpleRichText( "<qt>" + showName + "</qt>",                                   listView()->viewport()->font(), QString::null, 0/*, mimeFactory_*/ );	if(listView() && isVisible())		listView()->repaintItem(this);}void EvaBuddyItem::updateFacePixmaps(QPixmap *on, QPixmap *off){	if(on)		pixOnline = on;	if(off)		pixOffline = off;	refreshFace(true);}const QPixmap *EvaBuddyItem::pixmapOnline() const { return pixOnline; }const QPixmap *EvaBuddyItem::pixmapOffline() const { return pixOffline; }QPixmap *EvaBuddyItem::pixmapNA() { return pixNA; }void EvaBuddyItem::setPixmapNA(QPixmap *p) { pixNA = p; }QPixmap *EvaBuddyItem::pixmapMsg() { return pixMsg; }void EvaBuddyItem::setPixmapMsg(QPixmap *p) { pixMsg = p; }const int EvaBuddyItem::getQQ() const { return qqNum; }const EvaBuddyItem::Status EvaBuddyItem::getStatus() const { return status; }const int EvaBuddyItem::numOfUnreadMsgs() const { return numOfMessages; }const bool EvaBuddyItem::hasMessages() const{	return hasMessage;}void EvaBuddyItem::refreshFace(bool isForcedToChange){	switch(status){	case Online:		slotChangeToOnline(isForcedToChange);		break;	case Offline:		slotChangeToOffline(isForcedToChange);		break;	case Leave:		slotChangeToLeave(isForcedToChange);		break;	case Invisible:		slotChangeToInvisible(isForcedToChange);		break;	default:		slotChangeToOffline(isForcedToChange);	}}QString EvaBuddyItem::tip(){	const QQFriend *frd = (EvaMain::user->getFriendList()).getFriend(qqNum); 	QString tip = "<qt>";	if(frd){		EvaIPSeeker ipAddr(EvaGlobal::getDirPath().latin1());		QTextCodec *codec = QTextCodec::codecForName("GB18030");		QString addr = codec->toUnicode(ipAddr.getIPLocation(frd->getIP()).c_str());		if(addr.length()<4) addr = "0.0.0.0";				QString htmlName = nickName;		EvaHtmlParser parser;		parser.setAbsImagePath(EvaMain::images->getSmileyPath());		parser.convertToHtml(htmlName, false, true);		QString signature = codec->toUnicode(frd->getSignature().c_str());		if(signature.length() > 40)			signature = signature.left(37) + "...";		if(!signature.isEmpty())			signature = "[" + signature + "]";		QString facePath = "<img src=\"" + EvaMain::images->getFacePath() + "/" +				QString::number(EvaMain::images->getFaceFileIndex(frd->getFace())) + 				".png\"></img>";		if(frd->hasUserHead() && EvaMain::uhManager){			QString uhFileName = EvaMain::uhManager->getFileName(frd->getQQ());			if(!uhFileName.isEmpty())				facePath = "<img src=\"" + uhFileName + "\"></img>";		}		int suns, moons, stars;		EvaUtil::calcSuns(frd->getLevel(), &suns, &moons, &stars);		QString strSun =  "<img src=\"" + EvaMain::images->getIconFullPath("TIME_SUN") + "\"></img>";		QString strMoon = "<img src=\"" + EvaMain::images->getIconFullPath("TIME_MOON") + "\"></img>";		QString strStar = "<img src=\"" + EvaMain::images->getIconFullPath("TIME_STAR") + "\"></img>";		QString level;		for(int i=0; i<suns; i++){			level += strSun;		}		for(int i=0; i<moons; i++){			level += strMoon;		}		for(int i=0; i<stars; i++){			level += strStar;		}				tip += "<table width = 200><tr><td width=50 align = center valign = middle>" + facePath + 			"</td><td align = left valign = middle><b><font color = blue>"+			i18n("QQ") +": </font></b>"+ QString::number(qqNum) +"<br><nobr><b><font color = blue>"+			i18n("Nickname:") + " </font></b>"+htmlName +"</nobr><br>"+ signature + "<br><b><font color = blue>"+ 			i18n("Level") +": </font></b>"+ level + "  (" + QString::number(frd->getLevel()) +")<br><b><font color = blue>"+			i18n("IP:") +" </font></b>"+ addr + "</td></tr></table>";	} else		tip += "<b><font color = blue>" + 			i18n("QQ") +": </font></b><br>"+ QString::number(qqNum) +			i18n("Nickname:") +" </font></b>"+ nickName +"<br><b><font color = blue>";	tip += "</qt>";	return tip;}void EvaBuddyItem::paintCell( QPainter * painter, const QColorGroup & colourGroup, int column, int width, int align ){	if( ! isVisible() ) return;	if ( column == 0){		QBrush *brush;		QPalette palette;				EvaListView *lv = dynamic_cast<EvaListView *> (listView());		if( !lv ) return;				palette = lv->viewport()->palette();		brush   = 0;				const BackgroundMode bgmode = lv->viewport()->backgroundMode();		const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode );		if ( colourGroup.brush( crole ) != lv->colorGroup().brush( crole ) )			painter->fillRect( 0, 0, width, height(), colourGroup.brush( crole ) );		else			lv->paintEmptyArea( painter, QRect( 0, 0, width, height() ) );		if ( isSelected() ) {			brush = new QBrush( palette.color(QPalette::Active, QColorGroup::Highlight) );			// painter->setPen( palette.color(QPalette::Active, QColorGroup::Text) );		} else {			// painter->setPen( palette.color(QPalette::Normal, QColorGroup::Text) );			}				int icon_width = 0;		if(m_Icon){			icon_width = lv->itemMargin() + m_Icon->width();		}		// TODO: Change the font for highlighted text		m_RichText->draw( painter, lv->itemMargin() + icon_width, 0, 					QRect( icon_width, 0, width, height() ), colourGroup, brush );		//setHeight( m_RichText->height() );		if(m_Icon){			int xo = lv->itemMargin();			int yo = ( height() - m_Icon->height() ) / 2;			painter->drawPixmap( xo, yo, *m_Icon );		}		int height = m_RichText->height();		if(m_Icon && m_Icon->height() > m_RichText->height()){			height = m_Icon->height();		}		height += 4;		setHeight( height );		widthChanged( 0 );		delete brush;	} else {		QListViewItem::paintCell( painter, colourGroup, column, width, align );	}}void EvaBuddyItem::slotChangeToOnline(bool isForcedToChange){	if(!isForcedToChange && status == Online) return;	status = Online;	if(!pixOnline) return ;	runScaleImageThread(pixOnline);	//updateFace(pixOnline);}void EvaBuddyItem::slotChangeToLeave(bool isForcedToChange){	if(!isForcedToChange && status == Leave) return;	status = Leave;	if(!pixOnline) return;	QPixmap *leave = new QPixmap(*pixOnline);	copyBlt(leave, leave->width() - pixNA->width(), leave->height()- pixNA->height(), 		pixNA, 0, 0, pixNA->width(), pixNA->height());			runScaleImageThread(leave);	//updateFace(leave);	delete leave;}void EvaBuddyItem::slotChangeToOffline(bool isForcedToChange){	if(!isForcedToChange && status == Offline) return;	status = Offline;	if(!pixOffline) return ;	runScaleImageThread(pixOffline);	//updateFace(pixOffline);}void EvaBuddyItem::slotChangeToInvisible(bool isForcedToChange){	slotChangeToOffline(isForcedToChange);   }void EvaBuddyItem::slotStartFlash(){	if(!pixMsg) return;	hasMessage = true;	updateText();	}void EvaBuddyItem::slotStopFlash(){	hasMessage = false;	updateText();}void EvaBuddyItem::runScaleImageThread(QPixmap *p){	if(!p) return;	EvaMain::helper->setCategory(EvaHelper::ScaleImage,this);	EvaMain::helper->setScaleArgs(*p, faceSize);	EvaMain::helper->run();}void EvaBuddyItem::customEvent( QCustomEvent *e){	if(e->type() == EvaScaleImageEvent){		EvaScaleEvent *se = (EvaScaleEvent *)e;		if(m_Icon) delete m_Icon;		m_Icon = new QPixmap(se->pixmap());		updateText();	}}void EvaBuddyItem::updateFace(QPixmap *pix){	if(!pix) return;	//QImage img(pix->convertToImage().smoothScale(faceSize));	//QPixmap p(img);	//setPixmap(0, *pix);}QString EvaBuddyItem::key( int, bool ) const{	QString prefix="";	switch(status){	case Online:		prefix = "0";		break;	case Leave:		prefix = "1";		break;	case Invisible:		prefix = "2";		break;	case Offline:	default: 		prefix = "3";	}	if(hasMessage) prefix += "0";	return prefix + nickName;}/* ---------------------------------------------------------------------------------       */QPixmap *EvaGroupItem::pixOpened = 0;QPixmap *EvaGroupItem::pixClosed = 0;QPixmap *EvaGroupItem::pixMsg =0; EvaGroupItem::EvaGroupItem(QListView *parent, const QString &name, int index)		: QListViewItem( parent, " " + name),		groupName(name), groupIndex(index), hasMessage(false),		numOnlineFriends(0), type(Normal), m_RichText(0){	updateGroupTitle();}EvaGroupItem::EvaGroupItem(QListViewItem *parent, const QString &name, Type t)		: QListViewItem( parent, " " + name),		groupName(name), groupIndex(-1), hasMessage(false),		numOnlineFriends(0), type(t), m_RichText(0){		updateGroupTitle();}void EvaGroupItem::setOpen(bool o){	if(o){		if(pixOpened) setPixmap(0, *pixOpened);	}else{		if(pixClosed) setPixmap(0, *pixClosed);	}	QListViewItem::setOpen(o);}const int EvaGroupItem::getGroupIndex() const { return groupIndex;}const QString &EvaGroupItem::getGroupName() const { return groupName; }void EvaGroupItem::setPixmapOpen(QPixmap *p) { pixOpened = p ;}void EvaGroupItem::setPixmapClose(QPixmap *p) { pixClosed = p ;}void EvaGroupItem::setPixmapMsg(QPixmap *p) { pixMsg = p; }QPixmap *EvaGroupItem::pixmapOpen() { return pixOpened; }QPixmap *EvaGroupItem::pixmapClose() { return pixClosed; }QPixmap *EvaGroupItem::pixmapMsg() { return pixMsg; }void EvaGroupItem::setGroupName(const QString name){	groupName = name;	updateGroupTitle();}void EvaGroupItem::addBuddy(EvaBuddyItem *item){	insertItem(item);	updateGroupTitle();}EvaBuddyItem * EvaGroupItem::addBuddy(const QString &nick, const int id, const QString signature, QPixmap *on, 				QPixmap *off, EvaBuddyItem::Status status ){	EvaBuddyItem *buddy = new EvaBuddyItem(this, nick, id, signature, on, off, status);	updateGroupTitle();	return buddy;}void EvaGroupItem::updateNick(const int id, const QString &nick){	EvaBuddyItem *item = findBuddy(id);	if(item)		item->updateNick(nick);}void EvaGroupItem::updateSignature(const int id, const QString &sig){	EvaBuddyItem *item = findBuddy(id);	if(item)		item->updateSignature(sig);}

⌨️ 快捷键说明

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