summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp35
-rw-r--r--src/mainwindow.h4
-rw-r--r--src/mainwindow.ui21
3 files changed, 45 insertions, 15 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 839b2c3..447cf0c 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -13,26 +13,41 @@ MainWindow::MainWindow(const QStringList &filePaths, QWidget *parent)
if (!filePaths.isEmpty()) {
current.load(filePaths.first());
setWindowTitle(title_format.arg(filePaths.first()));
- resizePixmap();
+ fit();
}
- connect(ui->original_toolButton, &QToolButton::clicked, this,
- [this]() { ui->label->setPixmap(current); });
+ connect(ui->ori_toolButton, &QToolButton::clicked, [this]() { scale(1.0); });
+ connect(ui->fit_toolButton, &QToolButton::clicked, [this]() { fit(); });
- connect(ui->fit_toolButton, &QToolButton::clicked, this,
- [this]() { resizePixmap(); });
+ connect(ui->scale_slider, &QSlider::sliderMoved,
+ [this](int value) { scale(static_cast<double>(value) / 100.0f); });
}
MainWindow::~MainWindow() { delete ui; }
void MainWindow::resizeEvent(QResizeEvent *event) {
- resizePixmap();
+ fit();
QMainWindow::resizeEvent(event);
}
-void MainWindow::resizePixmap() {
- const auto size =
- ui->scrollArea->viewport()->size().boundedTo(current.size());
+void MainWindow::fit() {
+ const auto pixmpSize = current.size();
+ const auto scaleSize =
+ pixmpSize.scaled(ui->scrollArea->viewport()->size(), Qt::KeepAspectRatio);
+
+ const int scale = std::min(scaleSize.width() * 100 / pixmpSize.width(),
+ scaleSize.height() * 100 / pixmpSize.height());
+
+ ui->label->setPixmap(
+ current.scaled(scaleSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ ui->scale_slider->setValue(scale);
+ ui->scale_label->setText(scale_format.arg(scale));
+}
+
+void MainWindow::scale(double scale) {
+ const auto scaleSize = current.size() * scale;
ui->label->setPixmap(
- current.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ current.scaled(scaleSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ ui->scale_slider->setValue(scale * 100);
+ ui->scale_label->setText(scale_format.arg(scale * 100));
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index dfd704b..f6b8c32 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -18,9 +18,11 @@ protected:
void resizeEvent(QResizeEvent *event) override;
private:
- void resizePixmap();
+ void fit();
+ void scale(double scale);
Ui::MainWindow *ui;
QPixmap current;
const QString title_format{"qimv [%1]"};
+ const QString scale_format{"%1%"};
};
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 733b06e..2676638 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -15,6 +15,9 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
+ <property name="spacing">
+ <number>2</number>
+ </property>
<property name="leftMargin">
<number>0</number>
</property>
@@ -38,7 +41,7 @@
<x>0</x>
<y>0</y>
<width>798</width>
- <height>548</height>
+ <height>552</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -87,9 +90,9 @@
</spacer>
</item>
<item>
- <widget class="QToolButton" name="original_toolButton">
+ <widget class="QToolButton" name="ori_toolButton">
<property name="text">
- <string>orig</string>
+ <string>original</string>
</property>
</widget>
</item>
@@ -101,12 +104,22 @@
</widget>
</item>
<item>
- <widget class="QSlider" name="horizontalSlider">
+ <widget class="QSlider" name="scale_slider">
+ <property name="maximum">
+ <number>100</number>
+ </property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
+ <item>
+ <widget class="QLabel" name="scale_label">
+ <property name="text">
+ <string>0%</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>