summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
blob: 839b2c3aa20083b3fb42ae77398f246b11471b2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QResizeEvent>

MainWindow::MainWindow(const QStringList &filePaths, QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow) {
  ui->setupUi(this);

  connect(ui->actionQuit, &QAction::triggered, qApp, &QApplication::quit);

  if (!filePaths.isEmpty()) {
    current.load(filePaths.first());
    setWindowTitle(title_format.arg(filePaths.first()));
    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) {
  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));
}