#include "GraphicItem.h"
GraphicItem
::GraphicItem(QPixmap image
){
// TODO Auto-generated constructor stub
myWidth = 150;
myHeight =150;
m_Selected = false;
Org = image;
makePhoto(Org);
makeReflection();
}
GraphicItem::GraphicItem()
{
myWidth = 150;
myHeight =150;
m_Selected = false;
Org = NULL;
makePhoto(Org);
makeReflection();
}
GraphicItem::~GraphicItem() {
// TODO Auto-generated destructor stub
}
QRectF GraphicItem
::boundingRect() const {
return QRectF(0.0f,0.0f,myWidth,myHeight
);
}
void GraphicItem::SelectedStatus(bool Selected)
{
m_Selected = Selected;
makePhoto(Org);
makeReflection();
}
void GraphicItem::MoveLeft()
{
SetRightPlace(pos().x()+200,pos().y());
}
void GraphicItem::MoveRight()
{
SetRightPlace(pos().x()-200,pos().y());
}
void GraphicItem::SetRightPlace(int x,int y)
{
RightX = x;
RightY = y;
}
bool GraphicItem::IsRightPlace()
{
return(RightX == pos().x()) && (RightY == pos().y());
}
void GraphicItem::Animate()
{
int x = pos().x();
int y = pos().y();
int dx = 6;
int dy = 6;
if(pos().x() < RightX)
{
if((pos().x() + dx >= RightX))
x = RightX;
else
x = pos().x() + dx;
}
else if(pos().x() > RightX)
{
if((pos().x() - dx <= RightX))
x = RightX;
else
x = pos().x() - dx;
}
if(pos().y() < RightY)
{
if((pos().y() + dy >= RightY))
y = RightY;
else
y = pos().y() + dy;
}
else if(pos().y() > RightY)
{
if((pos().y() - dy <= RightY))
y = RightY;
else
y = pos().y() - dy;
}
setPos(x,y);
}
void GraphicItem
::ChangePixmap(QPixmap pixmap
) {
Org = pixmap;
makePhoto(Org);
makeReflection();
}
{
printf("void GraphicItem::paint\n");
painter->drawPixmap(0,0,item);
painter->drawPixmap(0,static_cast<int>(myHeight*0.5f),itemMirror);
}
void GraphicItem
::makePhoto(QPixmap image
) {
item
= QPixmap(myWidth,static_cast<int>
(myHeight
*0.5f
));
if((image.width() > myWidth - 2) || (image.height() > myHeight*0.5f-2))
image = image.scaled(myWidth-2,static_cast<int>(myHeight*0.5f-2),
Qt::KeepAspectRatio,Qt::SmoothTransformation);
if(m_Selected)
pen.setBrush(Qt::red);
else
pen.setBrush(Qt::darkGray);
pen.setWidth(5);
painter->setPen(pen);
gradient.
setColorAt(0.0f,
QColor(175,
175,
175));
gradient.
setColorAt(0.5f,
QColor(215,
215,
215));
gradient.
setColorAt(1.0f,
QColor(175,
175,
175));
painter
->setBrush
(QBrush(gradient
));
painter->drawRect(0,0,myWidth,static_cast<int>(myHeight*0.5f));
painter->drawPixmap(static_cast<int>(myWidth*0.5f-(image.width()*0.5f)),
static_cast<int>(myHeight*0.25f-(image.height()*0.5f)),
image);
delete painter;
}
void GraphicItem::makeReflection()
{
itemMirror
= QPixmap(myWidth,static_cast<int>
(myHeight
*0.5f
));
painter
->drawPixmap
(0,
0,
QPixmap::fromImage(item.
toImage() .mirrored(false,true)));
painter->resetTransform();
QPen pen
(Qt
::transparent);
painter->setPen(pen);
gradient.
setColorAt(0.0f,
QColor(0,
15,
15,
155));
gradient.
setColorAt(1.0f,
QColor(0,
15,
15,
255));
painter
->setBrush
(QBrush(gradient
));
painter->drawRect(0,0,myWidth,static_cast<int>(myHeight*0.5f));
delete painter;
}