summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp21
1 files changed, 15 insertions, 6 deletions
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));
+}