1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
//
// C++ Implementation: FlagGraphicsItem
//
// Description:
//
//
// Author: Thibaut GRIDEL <tgridel@free.fr>
//
// Copyright (c) 2009 Thibaut GRIDEL
//
// 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/>.
//
//
#include "flag.h"
#include "commontypes.h"
#include "situationscene.h"
FlagGraphicsItem::FlagGraphicsItem(QGraphicsItem *parent)
: QGraphicsItem(parent) {
}
FlagGraphicsItem::~FlagGraphicsItem() {}
QRectF FlagGraphicsItem::boundingRect() const {
return m_rect;
}
QPainterPath FlagGraphicsItem::shape() const {
QPainterPath path;
path.addRect(m_rect);
return path;
}
void FlagGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) {
Q_UNUSED(option);
Q_UNUSED(widget);
switch (m_flag) {
case Boats::Y: {
painter->setBrush(Qt::red);
painter->drawRect(m_rect);
painter->translate(m_rect.left(), m_rect.top());
QPolygonF polygon;
qreal sixth = m_rect.width() / 6;
qreal height = m_rect.height();
polygon << QPointF(0, 0) << QPointF(sixth, 0) << QPointF(-3*sixth, height) << QPointF(-4*sixth, height);
painter->setPen(Qt::transparent);
painter->setBrush(Qt::yellow);
for (int i=0; i<5; i++) {
painter->drawPolygon(polygon.intersected(QPolygonF(QRectF(0, 0, m_rect.width(), m_rect.height()))));
polygon.translate(2*sixth, 0);
}
break;
}
case Boats::Red:
painter->setBrush(Qt::red);
painter->drawRect(m_rect);
break;
case Boats::Yellow:
painter->setBrush(Qt::yellow);
painter->drawRect(m_rect);
break;
case Boats::Blue:
painter->setBrush(Qt::blue);
painter->drawRect(m_rect);
break;
case Boats::Green: {
painter->setBrush(Qt::white);
painter->drawRect(m_rect);
painter->translate(m_rect.left(), m_rect.top());
QPolygonF polygon;
qreal halfw = m_rect.width() / 2;
qreal halfh = m_rect.height() / 2;
polygon << QPointF(0, 0) << QPointF(halfw, 0) << QPointF(halfw, halfh) << QPointF(0, halfh);
painter->setBrush(Qt::green);
painter->drawPolygon(polygon);
polygon.translate(halfw, halfh);
painter->drawPolygon(polygon);
break;
}
default:
break;
}
}
|