summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build6
-rw-r--r--src/mainwindow.cpp16
-rw-r--r--src/mainwindow.h8
-rw-r--r--src/mainwindow.ui50
-rw-r--r--src/scaleform.cpp22
-rw-r--r--src/scaleform.h23
-rw-r--r--src/scaleform.ui84
7 files changed, 144 insertions, 65 deletions
diff --git a/meson.build b/meson.build
index 86acf5b..fde2360 100644
--- a/meson.build
+++ b/meson.build
@@ -22,13 +22,13 @@ mod_qt5 = import('qt5')
dep_qt5 = dependency('qt5', modules: [ 'Core', 'Widgets' ], include_type: 'system')
moc = mod_qt5.preprocess(
- moc_headers: [ 'src/mainwindow.h' ],
- ui_files: [ 'src/mainwindow.ui' ],
+ moc_headers: [ 'src/mainwindow.h', 'src/scaleform.h' ],
+ ui_files: [ 'src/mainwindow.ui', 'src/scaleform.ui' ],
dependencies: dep_qt5
)
exe = executable('qimv',
- sources: [ 'src/main.cpp', 'src/mainwindow.cpp', moc ],
+ sources: [ 'src/main.cpp', 'src/mainwindow.cpp', 'src/scaleform.cpp', moc ],
dependencies: dep_qt5,
install: true)
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 447cf0c..eacd486 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,12 +1,17 @@
#include "mainwindow.h"
+#include "scaleform.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QResizeEvent>
+ScaleForm *scaleForm = nullptr;
+
MainWindow::MainWindow(const QStringList &filePaths, QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
+ scaleForm = new ScaleForm(this);
ui->setupUi(this);
+ ui->menubar->setCornerWidget(scaleForm);
connect(ui->actionQuit, &QAction::triggered, qApp, &QApplication::quit);
@@ -16,11 +21,6 @@ MainWindow::MainWindow(const QStringList &filePaths, QWidget *parent)
fit();
}
- connect(ui->ori_toolButton, &QToolButton::clicked, [this]() { scale(1.0); });
- connect(ui->fit_toolButton, &QToolButton::clicked, [this]() { fit(); });
-
- connect(ui->scale_slider, &QSlider::sliderMoved,
- [this](int value) { scale(static_cast<double>(value) / 100.0f); });
}
MainWindow::~MainWindow() { delete ui; }
@@ -40,14 +40,12 @@ void MainWindow::fit() {
ui->label->setPixmap(
current.scaled(scaleSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
- ui->scale_slider->setValue(scale);
- ui->scale_label->setText(scale_format.arg(scale));
+ scaleForm->setScale(scale);
}
void MainWindow::scale(double scale) {
const auto scaleSize = current.size() * scale;
ui->label->setPixmap(
current.scaled(scaleSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
- ui->scale_slider->setValue(scale * 100);
- ui->scale_label->setText(scale_format.arg(scale * 100));
+ scaleForm->setScale(scale * 100);
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index f6b8c32..5ef586b 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -14,15 +14,15 @@ public:
explicit MainWindow(const QStringList &filePaths, QWidget *parent = nullptr);
~MainWindow() override;
+public slots:
+ void fit();
+ void scale(double scale);
+
protected:
void resizeEvent(QResizeEvent *event) override;
private:
- 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 2676638..56105ca 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -41,7 +41,7 @@
<x>0</x>
<y>0</y>
<width>798</width>
- <height>552</height>
+ <height>578</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -74,54 +74,6 @@
</widget>
</widget>
</item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QToolButton" name="ori_toolButton">
- <property name="text">
- <string>original</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="fit_toolButton">
- <property name="text">
- <string>fit</string>
- </property>
- </widget>
- </item>
- <item>
- <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>
</widget>
<widget class="QMenuBar" name="menubar">
diff --git a/src/scaleform.cpp b/src/scaleform.cpp
new file mode 100644
index 0000000..e9bf740
--- /dev/null
+++ b/src/scaleform.cpp
@@ -0,0 +1,22 @@
+#include "scaleform.h"
+#include "mainwindow.h"
+#include "ui_scaleform.h"
+
+ScaleForm::ScaleForm(MainWindow *parent)
+ : QWidget(parent), ui(new Ui::ScaleForm) {
+ ui->setupUi(this);
+
+ connect(ui->ori_toolButton, &QToolButton::clicked, parent,
+ [parent]() { parent->scale(1.0); });
+ connect(ui->fit_toolButton, &QToolButton::clicked, parent, &MainWindow::fit);
+ connect(ui->scale_slider, &QSlider::sliderMoved, parent, [parent](int value) {
+ parent->scale(static_cast<double>(value) / 100.0);
+ });
+}
+
+ScaleForm::~ScaleForm() { delete ui; }
+
+void ScaleForm::setScale(int scale) {
+ ui->scale_slider->setValue(scale);
+ ui->scale_label->setText(scale_format.arg(scale));
+}
diff --git a/src/scaleform.h b/src/scaleform.h
new file mode 100644
index 0000000..8ba8c8c
--- /dev/null
+++ b/src/scaleform.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <QWidget>
+
+namespace Ui {
+class ScaleForm;
+}
+
+class MainWindow;
+class ScaleForm final : public QWidget {
+ Q_OBJECT
+
+public:
+ explicit ScaleForm(MainWindow *parent = nullptr);
+ ~ScaleForm() override;
+
+public slots:
+ void setScale(int scale);
+
+private:
+ Ui::ScaleForm *ui;
+ const QString scale_format{"%1%"};
+};
diff --git a/src/scaleform.ui b/src/scaleform.ui
new file mode 100644
index 0000000..886aa61
--- /dev/null
+++ b/src/scaleform.ui
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ScaleForm</class>
+ <widget class="QWidget" name="ScaleForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>345</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="spacing">
+ <number>2</number>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QToolButton" name="ori_toolButton">
+ <property name="text">
+ <string>original</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="fit_toolButton">
+ <property name="text">
+ <string>fit</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="toolButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>width</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="toolButton_2">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>height</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="scale_label">
+ <property name="text">
+ <string>0%</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSlider" name="scale_slider">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>