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

📄 kurllabel.cpp

📁 一种效率高
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		setPalette(m_nsp);	}	else	/* if we are in "glow" mode, turn off the selected palette */	if (m_glow)		setPalette(m_nsp);} void KURLLabel::mousePressEvent(QMouseEvent *event){	if (m_inRegion)	{		/* set the palette to "selected"*/		setPalette(m_sp);		/* select the pixmap only if there is one */		if (!m_pixmap.isNull())		{			/* save the original pixmap */			m_unselPixmap = m_pixmap;			/* select the pixmap */			QBrush b(m_sc, Dense4Pattern);			QPainter p(&m_pixmap);			p.fillRect(0, 0, m_pixmap.width(), m_pixmap.height(), b);		}		/**		 * set the timer for 1/2 second.  this allows time		 * to show that this is selected		 */		startTimer(500);		/**		 * emit the proper signal based on which button the		 * user clicked		 */		switch (event->button())		{			case LeftButton:				emit(leftClickedURL(m_url));				emit(leftClickedURL());				break;			case RightButton:				emit(rightClickedURL(m_url));				emit(rightClickedURL());				break;			case MidButton:				emit(middleClickedURL(m_url));				emit(middleClickedURL());				break;		}	}}void KURLLabel::timerEvent(QTimerEvent *event){	/* reset the the palette to normal */	setPalette(m_nsp);	if (!m_unselPixmap.isNull())	{		/* redraw the original pixmap */		QPainter p(&m_pixmap);		p.drawPixmap(0, 0, m_unselPixmap);	}	/* kill the timer */	killTimer(event->timerId());}void KURLLabel::m_resetPalette(){	/* reset the palette with any colors that have changed */	m_nsp.setNormal(		QColorGroup(			m_hc,			m_bc,			palette().normal().light(),			palette().normal().dark(),			palette().normal().mid(),			m_hc,			palette().normal().base()		)	);	m_sp.setNormal(		QColorGroup(			m_sc,			m_bc,			palette().normal().light(),			palette().normal().dark(),			palette().normal().mid(),			m_sc,			palette().normal().base()		)	);}QRect KURLLabel::m_textRect() const{	int x_min = 0, y_min = 0;	int pixmap_width = 0, pixmap_height = 0;	/* get the pixmap info if it exists */	if (!m_pixmap.isNull())	{		pixmap_height = m_pixmap.height();		pixmap_width = m_pixmap.width();	}	/* return 0 if there is no text */	if (m_text.isEmpty())		return QRect(0, 0, 0, 0);	/**	 * calculate the boundry rect for the text based on the	 * text metrics and the current alignment	 */	QFontMetrics fm(font());	if (alignment() & AlignHCenter)	{		switch (m_textAlign)		{			case Bottom:			case Top:				if (autoResize())					x_min = (pixmap_width > fm.width(m_text)) ? 						         (pixmap_width - fm.width(m_text)) / 2 : 0;				else					x_min = (width() - fm.width(m_text)) / 2;				break;			case Left:				if (autoResize())					x_min = 0;				else					x_min = (width() - fm.width(m_text) - pixmap_width) / 2;				break;			case Right:				if (autoResize())					x_min = pixmap_width;				else					x_min = (width() - fm.width(m_text) + pixmap_width) / 2;				break;		}	}	if (alignment() & AlignVCenter)	{		switch (m_textAlign)		{			case Bottom:				if (autoResize())					y_min = pixmap_height;				else					y_min = (height() + pixmap_height - fm.height()) / 2;				break;			case Top:				if (autoResize())					y_min = 0;				else					y_min = ((height() - pixmap_height - fm.height()) / 2) + 3;				break;			case Left:			case Right:				y_min = (height() - fm.height()) / 2;				break;		}	}	if (alignment() & AlignLeft)	{		switch (m_textAlign)		{			case Top:			case Bottom:			case Left:				x_min = 0;				break;			case Right:				x_min = pixmap_width;				break;		}	}		if (alignment() & AlignTop)	{		switch (m_textAlign)		{			case Top:			case Left:			case Right:				y_min = 0;				break;			case Bottom:				y_min = pixmap_height;				break;		}	}	if (alignment() & AlignRight)	{		switch (m_textAlign)		{			case Top:			case Bottom:			case Right:				x_min = width() - fm.width(m_text);				break;			case Left:				x_min = width() - pixmap_width - fm.width(m_text);				break;		}	}	if (alignment() & AlignBottom)	{		switch (m_textAlign)		{			case Top:				y_min = height() - pixmap_height - fm.height();				break;			case Bottom:			case Right:			case Left:				y_min = height() - fm.height();				break;		}	}	/* construct the bounding rectangle */	return QRect(x_min, y_min, fm.width(m_text), fm.height());}QRect KURLLabel::m_pixmapRect() const{	int x_min = 0, y_min = 0;	int text_width = 0, text_height = 0;	/* get the text info if necessary */	if (!m_text.isEmpty())	{		QFontMetrics metrics(font());		text_height = metrics.height();		text_width = metrics.width(m_text);	}	/* return now if there is no pixmap */	if (m_pixmap.isNull())		return QRect(0, 0, 0, 0);	/**	 * calculate the boundry rect for the pixmap based on its	 * size and the current alignment	 */	if (alignment() & AlignHCenter)	{		switch (m_textAlign)		{			case Bottom:			case Top:				if (autoResize())					x_min = m_pixmap.width() > text_width ? 					            0 : (text_width - m_pixmap.width()) / 2;				else					x_min = (width() - m_pixmap.width()) / 2;				break;			case Left:				if (autoResize())					x_min = text_width;				else					x_min = (width() - m_pixmap.width() + text_width) / 2;				break;			case Right:				if (autoResize())					x_min = 0;				else					x_min = (width() - m_pixmap.width() - text_width) / 2;				break;		}	}	if (alignment() & AlignVCenter)	{		switch (m_textAlign)		{			case Bottom:				if (autoResize())					y_min = 0;				else					y_min = (height() - m_pixmap.height() - text_height) / 2;				break;			case Top:				if (autoResize())					y_min = text_height;				else					y_min = (height() - m_pixmap.height() + text_height) / 2;				break;			case Left:			case Right:				if (autoResize())					y_min = 0;				else					y_min = (height() - m_pixmap.height()) / 2;				break;		}	}	if (alignment() & AlignLeft)	{		switch (m_textAlign)		{			case Left:				x_min = text_width;				break;			case Right:			case Top:			case Bottom:				x_min = 0;		}	}	if (alignment() & AlignTop)	{		switch (m_textAlign)		{			case Top:				y_min = text_height;				break;			case Left:			case Right:			case Bottom:				y_min = 0;				break;		}	}	if (alignment() & AlignRight)	{		switch (m_textAlign)		{			case Bottom:			case Top:			case Left:				x_min = width() - m_pixmap.width();				break;			case Right:				x_min = width() - m_pixmap.width() - text_width;				break;		}	}	if (alignment() & AlignBottom)	{		switch (m_textAlign)		{			case Top:			case Left:			case Right:				y_min = height() - m_pixmap.height();				break;			case Bottom:				y_min = height() - m_pixmap.height() - text_height;				break;		}	}	/* construct the bounding rectangle */	return QRect(x_min, y_min, m_pixmap.width(), m_pixmap.height());}void KURLLabel::drawContents(QPainter* p){	/* get the bounding rectangles for both the text and pixmap */	QRect text_rect = m_textRect();	QRect pixmap_rect = m_pixmapRect();	/* draw the text only if it is not null */	if (!m_text.isEmpty())		p->drawText(text_rect.bottomLeft().x(), text_rect.bottomLeft().y()-3,		            m_text);	/* draw the pixmap only if it is not null */	if (!m_pixmap.isNull())	{		p->drawPixmap(pixmap_rect.topLeft().x(), pixmap_rect.topLeft().y(),		              m_pixmap);	}}void KURLLabel::setTransparentMode(bool state){	m_transparent = state;	setBackgroundMode(state ? NoBackground : PaletteBackground); }void KURLLabel::paintEvent(QPaintEvent*){ // Mirko Sucker, 1998/11/16:	QPen pen;	QPainter paint(this);	// -----	if(m_transparent && parentWidget()!=0)	{		QPixmap bg(width(), height());		// -----		bg.fill(parentWidget(), mapToParent(QPoint(0, 0)));		paint.drawPixmap(0, 0, bg);	}	drawFrame(&paint);	drawContents(&paint);	paint.end();}#include "kurllabel.moc"

⌨️ 快捷键说明

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