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

📄 choice.cpp

📁 爱可视605看PDF程式源代码, 基于APDF
💻 CPP
字号:
#include "choice.h"#include "style.h"#include <qpainter.h>#include <qapplication.h>Choice::Choice(const QString &label, QWidget *parent)	: QWidget(parent)	, m_label(label) {	if(s_larrow == NULL) {		s_larrow= new QPixmap(AStyle::iconpath + "general/choice_left_arrow.png");		s_rarrow= new QPixmap(AStyle::iconpath + "general/choice_right_arrow.png");	}	QFont font = qApp->font();	font.setPointSize(14);	setFont(font);}void Choice::setLabel(const QString &label){	m_label = label;}void Choice::paintEvent(QPaintEvent *){	QPainter p(this);	int yofs = arrowBaseLinePos();	p.setBrush(QColor(255, 255, 255));	p.setPen(QColor(255, 255, 255));	p.drawRect(rect());	p.drawPixmap(0, yofs, *s_larrow);	p.drawPixmap(rArrowXPos(), yofs, *s_rarrow);	p.setPen(QColor(0, 0, 0));	p.drawText(rect(), AlignCenter, m_label);}int Choice::arrowBaseLinePos(){	return (height() - s_rarrow->height())/ 2;}int Choice::rArrowXPos(){	return width() - s_rarrow->width();}QPixmap *Choice::s_larrow= NULL;QPixmap *Choice::s_rarrow= NULL;XofYChoice::XofYChoice(int x, int y, QWidget *parent)	: Choice(QString("%1/%2").arg(x).arg(y), parent)	, m_x(x)	, m_y(y){	connect(&mousepress_timer, SIGNAL(timeout()), this, SLOT(updateX()));}void XofYChoice::updateX(){	if (timer_direction == left) {		decX();	}	else if (timer_direction == right) {		incX();	}}void XofYChoice::incX(){	if (m_x < m_y) {		emit valueChanged(++m_x);		setLabel(QString("%1/%2").arg(m_x).arg(m_y));		update();	}}void XofYChoice::setValues(int x, int y){		m_x = x;		m_y = y;		setLabel(QString("%1/%2").arg(m_x).arg(m_y));}void XofYChoice::decX(){	if (m_x > 1) {		emit valueChanged(--m_x);		setLabel(QString("%1/%2").arg(m_x).arg(m_y));		update();	}}int XofYChoice::getX(){	return m_x;}void XofYChoice::keyReleaseEvent(QKeyEvent *e){	switch(e->key()) {		case Key_Left:			decX();			break;		case Key_Right:			incX();			break;		default:			e->ignore();			break;	}}QRect XofYChoice::leftArrowRect(){	return QRect(0, arrowBaseLinePos(), s_larrow->width(), s_larrow->height());}QRect XofYChoice::rightArrowRect(){	return QRect(rArrowXPos(), arrowBaseLinePos(), s_rarrow->width(), s_rarrow->height());}void XofYChoice::mousePressEvent(QMouseEvent *e){	if (leftArrowRect().contains(e->pos())) {		timer_direction = left;		mousepress_timer.start(500);	}	else if (rightArrowRect().contains(e->pos())) {		timer_direction = right;		mousepress_timer.start(500);	}}void XofYChoice::mouseMoveEvent(QMouseEvent *e){	if (!leftArrowRect().contains(e->pos()) && !rightArrowRect().contains(e->pos())) {		mousepress_timer.stop();	}}void XofYChoice::mouseReleaseEvent(QMouseEvent *e){	if (mousepress_timer.isActive()) {		mousepress_timer.stop();	} 	if (leftArrowRect().contains(e->pos())) {		decX();	}	else if (rightArrowRect().contains(e->pos())) {		incX();	}}

⌨️ 快捷键说明

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