- Add a verbose flag and put debugging output being it ("-v" || " --verbose")

- In verbose mode draw a thumbnail of the source image in the bottom left of the window
- Add support for long options in the command line parsing
- Add a "stretch" argument that will stretch the aspect axis to fit the window when set. For example, in landscape mode the drawn picture will be as wide as the window, cropping the top and bottom
This commit is contained in:
Alfred Reynolds
2021-07-29 13:13:38 +12:00
parent bee9a78986
commit a0089db75b
7 changed files with 116 additions and 13 deletions

View File

@@ -109,6 +109,11 @@ void MainWindow::updateImage(bool immediately)
}
QPixmap p( currentImage.c_str() );
if(_debugMode)
{
std::cout << "size:" << p.width() << "x" << p.height() << std::endl;
}
QPixmap rotated = getRotatedPixmap(p);
QPixmap scaled = getScaledPixmap(rotated);
QPixmap background = getBlurredBackground(rotated, scaled);
@@ -120,6 +125,21 @@ void MainWindow::updateImage(bool immediately)
drawText(background, overlay->getMarginTopRight(), overlay->getFontsizeTopRight(), overlay->getRenderedTopRight(currentImage).c_str(), Qt::AlignTop|Qt::AlignRight);
drawText(background, overlay->getMarginBottomLeft(), overlay->getFontsizeBottomLeft(), overlay->getRenderedBottomLeft(currentImage).c_str(), Qt::AlignBottom|Qt::AlignLeft);
drawText(background, overlay->getMarginBottomRight(), overlay->getFontsizeBottomRight(), overlay->getRenderedBottomRight(currentImage).c_str(), Qt::AlignBottom|Qt::AlignRight);
if (_debugMode)
{
// draw a thumbnail version of the source image in the bottom left, to check for cropping issues
QPainter pt(&background);
QBrush brush(QColor(255, 255, 255, 255));
int margin = 10;
QPixmap thumbNail = p.scaledToWidth(200, Qt::SmoothTransformation);
pt.fillRect(background.width() - thumbNail.width() - 2*margin,
background.height()-thumbNail.height() - 2*margin,
thumbNail.width() +2*margin, thumbNail.height()+2*margin, brush);
pt.drawPixmap( background.width() - thumbNail.width() - margin,
background.height()-thumbNail.height() - margin,
thumbNail);
}
}
label->setPixmap(background);
@@ -164,13 +184,19 @@ void MainWindow::setOverlay(Overlay* o)
overlay = o;
}
void MainWindow::setAspect(char aspect)
{
_aspect = aspect;
}
QPixmap MainWindow::getBlurredBackground(const QPixmap& originalSize, const QPixmap& scaled)
{
if (scaled.width() < width()) {
if (scaled.width() < width() || _aspect == 'l') {
QPixmap background = blur(originalSize.scaledToWidth(width(), Qt::SmoothTransformation));
QRect rect(0, (background.height() - height())/2, width(), height());
return background.copy(rect);
} else {
// aspect 'p' or the image is not as wide as the screen
QPixmap background = blur(originalSize.scaledToHeight(height(), Qt::SmoothTransformation));
QRect rect((background.width() - width())/2, 0, width(), height());
return background.copy(rect);
@@ -186,9 +212,28 @@ QPixmap MainWindow::getRotatedPixmap(const QPixmap& p)
QPixmap MainWindow::getScaledPixmap(const QPixmap& p)
{
int w = width();
int h = height();
return p.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (_fitAspectAxisToWindow)
{
if ( _aspect == 'p')
{
// potrait mode, make height of image fit screen and crop top/bottom
QPixmap pTemp = p.scaledToHeight(height(), Qt::SmoothTransformation);
return pTemp.copy(0,0,width(),height());
}
else if ( _aspect == 'l')
{
// landscape mode, make width of image fit screen and crop top/bottom
QPixmap pTemp = p.scaledToWidth(width(), Qt::SmoothTransformation);
//int imageTempWidth = pTemp.width();
//int imageTempHeight = pTemp.height();
return pTemp.copy(0,0,width(),height());
}
}
// just scale the best we can for the given photo
int w = width();
int h = height();
return p.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
void MainWindow::drawBackground(const QPixmap& originalSize, const QPixmap& scaled)