39 lines
806 B
C++
39 lines
806 B
C++
#include "mapitemimage.h"
|
|
|
|
|
|
MapItemImage::MapItemImage(const QPixmap & p) {
|
|
setPixmap(p);
|
|
}
|
|
|
|
|
|
void MapItemImage::setPixmap(const QPixmap & p) {
|
|
m_pixmap = p;
|
|
updateParent();
|
|
}
|
|
|
|
|
|
void MapItemImage::setAlignment(Qt::Alignment a) {
|
|
m_alignment = a;
|
|
updateParent();
|
|
}
|
|
|
|
|
|
void MapItemImage::draw(QPainter * p) {
|
|
if (m_pixmap.isNull()) return;
|
|
QRectF pr(QPointF(0, 0), QSizeF(m_pixmap.size()));
|
|
if (m_alignment.testFlag(Qt::AlignHCenter)) {
|
|
pr.translate(-pr.center().x(), 0.);
|
|
}
|
|
if (m_alignment.testFlag(Qt::AlignRight)) {
|
|
pr.translate(-pr.width(), 0.);
|
|
}
|
|
if (m_alignment.testFlag(Qt::AlignVCenter)) {
|
|
pr.translate(0., -pr.center().y());
|
|
}
|
|
if (m_alignment.testFlag(Qt::AlignBottom)) {
|
|
pr.translate(0., -pr.height());
|
|
}
|
|
p->drawPixmap(pr, m_pixmap, m_pixmap.rect());
|
|
setBoundingRect(pr);
|
|
}
|