diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-29 13:11:51 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-29 13:11:51 -0400 |
| commit | 6781e2bcd051ace8da25dbd9e6950c87045753ef (patch) | |
| tree | 734cdbd2ddf05f0af9c5e3ada807d2780a5f3387 /sigmodr/widgets/TileItem.cpp | |
| parent | 7da85e52c1a0015213c0e905d7dbc5631a0b0904 (diff) | |
| download | sigen-6781e2bcd051ace8da25dbd9e6950c87045753ef.tar.gz sigen-6781e2bcd051ace8da25dbd9e6950c87045753ef.tar.xz sigen-6781e2bcd051ace8da25dbd9e6950c87045753ef.zip | |
Move the map editing classes to a subdirectory
Diffstat (limited to 'sigmodr/widgets/TileItem.cpp')
| -rw-r--r-- | sigmodr/widgets/TileItem.cpp | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/sigmodr/widgets/TileItem.cpp b/sigmodr/widgets/TileItem.cpp deleted file mode 100644 index 6f7e2484..00000000 --- a/sigmodr/widgets/TileItem.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel <MathStuf@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 3 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, see <http://www.gnu.org/licenses/>. - */ - -// Header include -#include "TileItem.h" - -// Sigmod includes -#include <sigmod/Game.h> -#include <sigmod/MapTile.h> -#include <sigmod/Sprite.h> -#include <sigmod/Tile.h> - -// KDE includes -#include <KColorScheme> - -// Qt includes -#include <QtGui/QPainter> - -// Standard includes -#include <climits> - -using namespace Sigmod; -using namespace Sigmodr::Widgets; - -TileItem::TileItem(MapTile* tile, QGraphicsScene* parent) : - MapItem(parent), - m_tile(tile), - m_tileIndex(INT_MIN) -{ - connect(m_tile, SIGNAL(changed()), this, SLOT(tileChanged())); - connect(m_tile, SIGNAL(error(QString)), this, SLOT(tileChanged())); - setZValue(m_tile->zIndex()); - m_tag->setText(QString::number(m_tile->id())); - tileChanged(); -} - -QRectF TileItem::boundingRect() const -{ - return QRect(m_tile->position(), m_pixmap.isNull() ? QSize(32, 32) : m_pixmap.size()); -} - -void TileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) -{ - if (m_pixmap.isNull()) - { - QPainterPath path; - path.moveTo(8, 24); - path.lineTo(24, 8); - path.moveTo(8, 8); - path.lineTo(24, 24); - painter->setPen(QPen(Qt::red, 5)); - painter->setBrush(Qt::NoBrush); - painter->drawPath(path); - } - else - painter->drawPixmap(0, 0, m_pixmap); - painter->setBrush(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active)); - painter->setOpacity(.25); - MapItem::paint(painter, option, widget); -} - -void TileItem::setZIndex(const int zIndex) -{ - m_tile->setZIndex(zIndex); -} - -void TileItem::setSprite(const int spriteId) -{ - if (spriteId == m_tileIndex) - return; - const Sprite* sprite = m_tile->game()->spriteById(spriteId); - if (!sprite || !m_pixmap.loadFromData(sprite->sprite())) - m_pixmap = QPixmap(); - prepareGeometryChange(); - m_tileIndex = spriteId; -} - -void TileItem::moveTo(const QPoint& point) -{ - m_tile->setPosition(point); -} - -void TileItem::tileChanged() -{ - const Tile* tile = m_tile->game()->tileById(m_tile->tile()); - if (tile) - setSprite(tile->preview()); - setPos(m_tile->position()); - setZValue(m_tile->zIndex()); - resetLabel(); - update(); -} - -void TileItem::resetLabel() -{ - const Tile* tile = m_tile->game()->tileById(m_tile->tile()); - if (tile) - { - m_label->setText(tile->name()); - QSizeF size = m_label->boundingRect().size() / 2 - (m_pixmap.isNull() ? QSize(32, 32) : m_pixmap.size()) / 2; - m_label->setPos(-size.width(), -size.height()); - } -} |
