| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2011 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #include "object.hpp" |
| 17 | #include <QPainter> |
| 18 | |
| 19 | Object::Object(QString category, QString role, QSizeF size, QPixmap pixmap) |
| 20 | : ObjectBase(category, role) |
| 21 | , m_size(size) |
| 22 | , m_pixmap(pixmap) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | Object::Object(const Object & other) |
| 27 | : QGraphicsItem() |
| 28 | , ObjectBase(other.category(), other.role()) |
| 29 | , m_size(other.m_size) |
| 30 | , m_pixmap(other.m_pixmap) |
| 31 | { |
| 32 | setLocation(other.location()); |
| 33 | setRotation(other.rotation()); |
| 34 | setForceStationary(other.forceStationary()); |
| 35 | } |
| 36 | |
| 37 | Object::Object(std::unique_ptr<Object> other) |
| 38 | : Object(*other) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | QRectF Object::boundingRect() const |
| 43 | { |
| 44 | return QRectF(-m_size.width() / 2, -m_size.height() / 2, m_size.width(), m_size.height()); |
| 45 | } |
| 46 | |
| 47 | void Object::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) |
| 48 | { |
| 49 | Q_UNUSED(widget) |
| 50 | Q_UNUSED(option) |
| 51 | |
| 52 | painter->save(); |
| 53 | painter->drawPixmap(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height(), m_pixmap); |
| 54 | painter->restore(); |
| 55 | } |
| 56 | |
| 57 | void Object::setLocation(QPointF newLocation) |
| 58 | { |
| 59 | ObjectBase::setLocation(newLocation); |
| 60 | setPos(newLocation); |
| 61 | } |