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 --- meson.build | 2 +- src/mainwindow.cpp | 21 +++++++++---- src/mainwindow.h | 2 ++ src/mainwindow.ui | 87 +++++++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 97 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index 7c3aac3..3907431 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('qimv', 'cpp', version : '0.1', - default_options : ['warning_level=3', 'cpp_std=c++14']) + default_options : ['warning_level=3', 'cpp_std=c++17']) summary({ 'prefix': get_option('prefix'), 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)); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index a270fd8..dfd704b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -18,6 +18,8 @@ protected: void resizeEvent(QResizeEvent *event) override; private: + void resizePixmap(); + Ui::MainWindow *ui; QPixmap current; const QString title_format{"qimv [%1]"}; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 5ea19df..733b06e 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -14,7 +14,7 @@ qimv - + 0 @@ -28,15 +28,87 @@ 0 - - - [ no data ] - - - Qt::AlignCenter + + + true + + + + 0 + 0 + 798 + 548 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + [ no data ] + + + Qt::AlignCenter + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + orig + + + + + + + fit + + + + + + + Qt::Horizontal + + + + + @@ -56,7 +128,6 @@ - Quit -- cgit v1.2.1