diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-11-01 21:02:13 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-11-01 21:02:13 +0200 |
commit | 246615f946a8063bcd68ba7c008e3cd0d3e6b615 (patch) | |
tree | 473580ef74697835e04dcee25586464410c79732 /src/mainwindow.cpp | |
parent | Initial commit (diff) | |
download | qimv-246615f946a8063bcd68ba7c008e3cd0d3e6b615.tar.xz |
Add original size and fit buttons
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r-- | src/mainwindow.cpp | 21 |
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)); +} |