From 246615f946a8063bcd68ba7c008e3cd0d3e6b615 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 1 Nov 2020 21:02:13 +0200 Subject: Add original size and fit buttons --- src/mainwindow.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9eba572..839b2c3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -13,17 +13,26 @@ MainWindow::MainWindow(const QStringList &filePaths, QWidget *parent) if (!filePaths.isEmpty()) { current.load(filePaths.first()); setWindowTitle(title_format.arg(filePaths.first())); - ui->label->setPixmap(current); + resizePixmap(); } + + connect(ui->original_toolButton, &QToolButton::clicked, this, + [this]() { ui->label->setPixmap(current); }); + + connect(ui->fit_toolButton, &QToolButton::clicked, this, + [this]() { resizePixmap(); }); } MainWindow::~MainWindow() { delete ui; } void MainWindow::resizeEvent(QResizeEvent *event) { - const auto width = ui->label->width(); - const auto height = ui->label->height(); - - ui->label->setPixmap(current.scaled(width, height, Qt::KeepAspectRatio)); - + resizePixmap(); QMainWindow::resizeEvent(event); } + +void MainWindow::resizePixmap() { + const auto size = + ui->scrollArea->viewport()->size().boundedTo(current.size()); + ui->label->setPixmap( + current.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} -- cgit v1.2.1