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

📄 qmybuttongroup.cpp

📁 linux 下的 仿联众版俄罗斯方块游戏。qt3 实现。 具有 人机交互功能。 具有 对战模式。 喜欢玩俄罗斯方块的朋友们
💻 CPP
字号:
/*********************************************************************** * * *    linux版仿联众俄罗斯方块 v1.0 *    该软件在GPL(GNU通用公共许可证)下发布 * *    Copyright (C)   <codeky@126.com> * *   This source code is licensed under the GNU General Public License * ************************************************************************//* * 用布局器效果可能也不错,但是还是自己定制一下 */#include <qapplication.h>#include <qpainter.h>#include "config.h"#include "qmybuttongroup.h"QmyButtonGroup::QmyButtonGroup(QWidget *parent, const char *name):QWidget(parent, name ){	counts=0; span = 0;	direction = vertical;	//backgroundFile[0]='\0';	fX=fY=0;	for(int i=0;i<MAX_BUTTONS;i++)		pButtons[i]=NULL;	setPalette( QPalette( black ));}QmyButtonGroup::~QmyButtonGroup(){}void QmyButtonGroup::paintEvent( QPaintEvent * ){	painter_lock();	QPainter p( this );	p.drawTiledPixmap(rect(), pix);	painter_unlock();}QWidget* QmyButtonGroup::addButtons(const QString &fileName, const char *name){	if(counts==MAX_BUTTONS) return NULL;	pButtons[counts++]=new QGameButton(fileName,this,name);	if(!pButtons[ counts -1] ){		counts--; //		return NULL;	}	return pButtons[counts-1];}void QmyButtonGroup::setBackground(char * const fileName){	pix.load(fileName);}void QmyButtonGroup::setGroupAttr(int nDirection, int nSpan){	direction = nDirection;	span = (nSpan>0)?nSpan:0;}void QmyButtonGroup::resizeEvent ( QResizeEvent * ){	int x=0,y=0,w=0,h=0;	if(counts<1) return;	if(vertical==direction){ // 垂直方向 才 自动调整高度		w = width();		for(int i=0;i<counts;i++){			h+=pButtons[i]->height()+span;		}		x = (w-pButtons[0]->width())/2; // 居中		if(x < 0) x = 0;		resize(w,h); // 垂直方向才调整窗口		fX = x;		fY = y;		adjustButtons();	}}void QmyButtonGroup::adjustButtons(void){	int x=0,y=0,w=0,h=0;	if(counts<1) return;	if(direction==vertical){ // 垂直方向		w = pButtons[0]->width();		h = pButtons[0]->height();		pButtons[0]->setGeometry(fX,fY,w,h);		for(int i = 1;i <counts;i++){			pButtons[i]->setGeometry(fX, h+span,1, 1);			h+=pButtons[i-1]->height()+span;		}	}else if(direction==horizontal){ // 水平方向的调整方案		w = width();		h = height();		y = (h-pButtons[0]->height())/2;		if(y<0)y=0;  // 计算第一个按钮的y坐标		if(span>0){			for(int i = 1;i <counts;i++)				x+=pButtons[i-1]->width(); // 临时用一下x			x += span*(counts-1);			x = (w-x)/2;			if(x<0)x=0;			h = span; // 和下面格式匹配		}else{ // span<=0时,自动计算span			// 临时用h,h不再被使用,h被当作自动计算的span			for(int i=0;i <counts;i++){				w -= pButtons[0]->width();			}			h = w/(counts+1);			if(h<0)h=0;			x = h;		}		pButtons[0]->setGeometry(x, y,1, 1);		w =h+pButtons[0]->width();		for(int i = 1;i <counts;i++){			pButtons[i]->setGeometry(w+h, y,1, 1);			w += h+pButtons[i]->width();		}	} // horizontal}

⌨️ 快捷键说明

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