资源简介

Qt实现的连连看游戏,可自行设计关卡。目前只能在Windows下编译,因为mid播放使用的是Windows库。

资源截图

代码片段和文件信息

#include “CardWidget.h“
#include 

CardWidget::CardWidget(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);

m_bSelected = false;
m_dOpacity = 1; // 默认为完全不透明

m_pFadeOutTimer = new QTimer(this);
connect(m_pFadeOutTimer SIGNAL(timeout()) this SLOT(FadeOutTimeout()));

m_clBack = QColor(248 220 144);
m_clframe = QColor(100 200 100);
}

CardWidget::~CardWidget()
{

}

void CardWidget::SetSelected(bool bSelected)
{
m_bSelected = bSelected;
repaint();
}

void CardWidget::mousePressEvent(QMouseEvent* pEvent)
{
if (pEvent->button() == Qt::LeftButton)
{
if (!m_pFadeOutTimer->isActive())
{
emit onclicked(this);
}
}
}

void CardWidget::mouseDoubleClickEvent(QMouseEvent* pEvent)
{
if (pEvent->button() == Qt::LeftButton)
{
OnDoubleClicked(this);
}
}

void CardWidget::paintEvent(QPaintEvent* pEvent)
{
QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

m_clBack.setAlpha(int(m_dOpacity * 255));
QPen pen(m_clBack);
QBrush brush(m_clBack);
painter.setPen(pen);
painter.setBrush(brush);
painter.drawRoundedRect(rect() 5 5);
//painter.fillRect(rect() m_clBack);

QPixmap temp(m_pic.size());
temp.fill(Qt::transparent);
QPainter p(&temp);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.drawPixmap(0 0 m_pic);
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.fillRect(temp.rect() QColor(0 0 0 int(m_dOpacity * 255)));
painter.drawPixmap(rect() temp);

if (m_bSelected)
{
QPen pen(m_clframe);
pen.setWidth(5);
painter.setPen(pen);
painter.setBrush(QBrush(Qt::NoBrush));
painter.drawRect(rect());
}
}

void CardWidget::SetCardOpacity(qreal dOpacity)
{
m_dOpacity = dOpacity;
repaint();
}

qreal CardWidget::GetCardOpacity()
{
return m_dOpacity;
}

void CardWidget::FadeOut()
{
if (!m_pFadeOutTimer->isActive())
{
m_pFadeOutTimer->start(50);
}
}

void CardWidget::FadeOutTimeout()
{
m_dOpacity -= 0.25;
repaint();

if (m_dOpacity <= 0)
{
m_pFadeOutTimer->stop();
hide();
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         536  2012-06-04 21:37  CardWidget.ui
     文件          51  2012-07-01 23:03  MatchGame.rc
     文件       99678  2012-07-01 23:05  game.ico
     文件         366  2012-07-02 23:04  main.cpp
     文件        1271  2012-07-04 13:03  EditWidget.ui
     文件        1976  2012-07-04 19:32  EditWidget.cpp
     文件        5453  2012-07-04 19:51  zh.ts
     文件         635  2012-07-06 12:59  EditWidget.h
     文件        1251  2012-07-06 21:13  MatchGameframe.h
     文件        1101  2012-07-06 23:08  CardWidget.h
     文件        2072  2012-07-07 00:27  SoundPlayer.cpp
     文件         758  2012-07-07 00:27  SoundPlayer.h
     文件        2549  2012-07-08 22:36  GamePanel.h
     文件        2118  2012-07-08 22:36  GameStructure.h
     文件        6074  2012-07-08 22:41  MatchGameframe.ui
     文件       10344  2012-07-08 22:45  GamePanel.cpp
     文件       10887  2012-07-08 22:51  GameStructure.cpp
     文件        9176  2012-12-13 20:38  MatchGameframe.cpp
     文件        2141  2012-12-29 00:08  CardWidget.cpp
     文件         683  2012-12-29 00:10  MatchGame.pro
     目录           0  2012-12-29 00:18  bin\
     目录           0  2012-12-29 00:16  bin\build\
     文件       33793  2012-12-29 00:16  bin\build\CardWidget.obj
     文件       48961  2012-12-29 00:16  bin\build\EditWidget.obj
     文件       86402  2012-12-29 00:16  bin\build\GamePanel.obj
     文件       92181  2012-12-29 00:16  bin\build\GameStructure.obj
     文件       12043  2012-12-29 00:16  bin\build\main.obj
     文件         873  2012-12-29 00:16  bin\build\MatchGame.intermediate.manifest
     文件       99908  2012-12-29 00:16  bin\build\MatchGame.res
     文件       98558  2012-12-29 00:16  bin\build\MatchGameframe.obj
     文件        9935  2012-12-29 00:16  bin\build\moc_CardWidget.obj
............此处省略55个文件信息

评论

共有 条评论