added elevator support

This commit is contained in:
2016-09-10 15:13:49 +02:00
parent fa06320219
commit 674f79c150
13 changed files with 353 additions and 14 deletions

View File

@@ -15,6 +15,8 @@ class MV2DElementFloorUnderlay : public MV2DElement {
private:
QImage img;
QImage imgScaled;
std::string tmpFile;
Floorplan::UnderlayImage* underlay;
BBox2 bbox;
@@ -58,9 +60,8 @@ public:
if (tmpFile != underlay->filename) {
img = QImage(underlay->filename.c_str());
if (img.size().width() == 0) {
missing();
}
if (img.size().width() == 0) { missing(); }
img = img.convertToFormat(QImage::Format_Grayscale8); // saves a huge amount of memory and should suffice
tmpFile = underlay->filename;
}
@@ -79,17 +80,39 @@ public:
float sy1 = p.s.yms(my1);
float sx2 = p.s.xms(mx2);
float sy2 = p.s.yms(my2);
float sw = std::abs(sx1-sx2);
float sh = std::abs(sy1-sy2);
float sw = std::round(std::abs(sx1-sx2));
float sh = std::round(std::abs(sy1-sy2));
const float origArea = img.width() * img.height();
const float scaledArea = sw*sh;
bbox = BBox2();
bbox.add(Point2(mx1, my1));
bbox.add(Point2(mx2, my2));
// if the to-be-displayed image is smaller than the input-one, use a pre-computed downscaled version
if (scaledArea < origArea) {
// does the cached downscaled image needs rebuild? (size changed)
if (imgScaled.width() != sw || imgScaled.height() != sh) {
imgScaled = img.scaled(sw, sh, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
} else {
imgScaled = QImage();
}
float opacity = p.p->opacity();
p.p->setOpacity(0.50f);
p.p->drawImage(QRectF(sx1, sy1-sh, sw, sh), img, QRectF(0,0,img.width(),img.height()));
// render downscaled image from cache? or use live-upscaling (faster, eats up less memory, ...)
if (imgScaled.width() > 0) {
p.p->drawImage(sx1, sy1-sh, imgScaled);
} else {
p.p->setRenderHint(QPainter::SmoothPixmapTransform, true);
p.p->drawImage(QRectF(sx1, sy1-sh, sw, sh), img, QRectF(0,0,img.width(),img.height()));
}
p.p->setOpacity(opacity);
// selected endpoint(s)?