/**
* Copyright (C) 2007 Rafael Fernández López <ereslibre@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "item.h"
#include <kdebug.h>
#include <QDebug>
#include <QPainter>
#include <QTransform>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene>
#include <QPointF>
#include <QRectF>
Item::Item(Triplet<int, int, int> coordinates,
int angleRotation, View *view,
QGraphicsItem *parent)
: QGraphicsItem(parent)
, m_view(view)
, angleRotation(angleRotation)
, acceleration(0)
, speed(0)
, coordinates(coordinates)
{
rotateX = 0;
rotateY = 0;
rotateZ = 0;
setFlag(ItemIsMovable);
setFlag( ItemIsSelectable);
setPos(QPointF(coordinates.first, coordinates.second));
// rect = scene()->sceneRect();
}
Item::~Item()
{
}
QRectF Item::boundingRect() const
{
return QRectF(0,
0,
128,
128);
}
void Item::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
painter->setRenderHints(QPainter::Antialiasing |
QPainter::TextAntialiasing |
QPainter::SmoothPixmapTransform);
QTransform transformTranslate;
QTransform transformRotateX;
QTransform transformRotateY;
QTransform transformRotateZ;
QTransform transformResult;
transformTranslate.translate(
pos().x(),
pos().y());
transformRotateX.rotate(rotateX, Qt::XAxis);
transformRotateY.rotate(rotateY, Qt::YAxis);
transformRotateZ.rotate(rotateX, Qt::ZAxis);
transformResult =
transformRotateX *
transformRotateY *
transformRotateZ *
transformTranslate;
painter->save();
painter->setTransform(transformResult, false);
painter->drawImage(QPoint(0, 0), QImage("logo.png"));
painter->restore();
}
bool Item::advance()
{
kDebug() << "avance" <<endl;
if (newPos == pos())
return false;
setPos(newPos);
return false;
}
void Item::calculatePos()
{
QRectF sceneRect = m_view->scene()->sceneRect();
newPos = pos();
}
QVariant Item::itemChange(GraphicsItemChange change, const QVariant &value)
{
if(change == ItemPositionChange){
kDebug() << "ItemPositionChange" << endl;
}
return value;
}
void Item::setRotateX(int value)
{
this->rotateX = value;
}
void Item::setRotateY(int value)
{
this->rotateY = value;
}
void Item::setRotateZ(int value)
{
this->rotateZ = value;
}
void Item::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
kDebug() << "press event" << endl;
setSelected(true);
// emit selected();
// update();
// QGraphicsItem::mousePressEvent(event);
}
void Item::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
kDebug() << "release event" << endl;
// update();
// QGraphicsItem::mouseReleaseEvent(event);
}
//#include "item.moc"