/* * Copyright 2008-2009 Ben Boeckel * * 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 . */ // Header include #include "WarpItem.h" // Sigmod includes #include // Qt includes #include // Standard includes #include using namespace Sigmod; using namespace Sigmodr::Widgets; WarpItem::WarpItem(MapWarp* warp, QGraphicsScene* parent) : MapItem(parent), m_warp(warp) { connect(m_warp, SIGNAL(changed()), this, SLOT(warpChanged())); connect(m_warp, SIGNAL(error(QString)), this, SLOT(tileChanged())); setOpacity(.5); setZValue(INT_MAX); m_tag->setText(QString::number(m_warp->id())); warpChanged(); } QRectF WarpItem::boundingRect() const { QRectF rect = m_warp->area().boundingRect(); rect.moveTo(m_warp->position()); return rect; } void WarpItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { painter->setBrush(QBrush(Qt::green)); painter->setPen(QPen(Qt::black, 2)); painter->drawPath(m_warp->area()); MapItem::paint(painter, option, widget); } void WarpItem::moveTo(const QPoint& point) { m_warp->setPosition(point); } void WarpItem::warpChanged() { setPos(m_warp->position()); resetLabel(); update(); } void WarpItem::resetLabel() { m_label->setText(m_warp->name()); QSizeF size = m_label->boundingRect().size() / 2 - m_warp->area().boundingRect().size() / 2; m_label->setPos(-size.width(), -size.height()); }